resize fixed
This commit is contained in:
parent
df70ce0584
commit
f1875e5343
@ -15,7 +15,7 @@ import java.io.InputStreamReader;
|
|||||||
*/
|
*/
|
||||||
public class MainApp {
|
public class MainApp {
|
||||||
|
|
||||||
public static final String APP_VERSION = "1.1.9";
|
public static final String APP_VERSION = "1.2.0";
|
||||||
|
|
||||||
public enum OS {
|
public enum OS {
|
||||||
WINDOWS, LINUX, MACOS, UNKNOWN
|
WINDOWS, LINUX, MACOS, UNKNOWN
|
||||||
|
|||||||
@ -34,7 +34,8 @@ public class MainWindow extends JFrame {
|
|||||||
private JLabel cmdLabel;
|
private JLabel cmdLabel;
|
||||||
private AppConfig config;
|
private AppConfig config;
|
||||||
private Timer autoRefreshTimer;
|
private Timer autoRefreshTimer;
|
||||||
private boolean isWindowResizing = false;
|
private int lastMainPanelExtent = -1;
|
||||||
|
private boolean applyingSavedDividerLocation = false;
|
||||||
private boolean wildcardDialogOpen = false;
|
private boolean wildcardDialogOpen = false;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
@ -112,7 +113,7 @@ public class MainWindow extends JFrame {
|
|||||||
mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
||||||
mainPanel.setContinuousLayout(true);
|
mainPanel.setContinuousLayout(true);
|
||||||
// Initially set resize weight based on saved proportion to maintain it during first layout/resize
|
// Initially set resize weight based on saved proportion to maintain it during first layout/resize
|
||||||
mainPanel.setResizeWeight(config.getDividerPosition());
|
mainPanel.setResizeWeight(getConfiguredDividerRatio());
|
||||||
|
|
||||||
// Disable default JSplitPane F6/Shift+F6 bindings which interfere with our Move/Rename actions
|
// Disable default JSplitPane F6/Shift+F6 bindings which interfere with our Move/Rename actions
|
||||||
mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none");
|
mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none");
|
||||||
@ -174,28 +175,22 @@ public class MainWindow extends JFrame {
|
|||||||
} else {
|
} else {
|
||||||
// If it was saved as absolute pixels (historically), use as int
|
// If it was saved as absolute pixels (historically), use as int
|
||||||
mainPanel.setDividerLocation((int) savedPosition);
|
mainPanel.setDividerLocation((int) savedPosition);
|
||||||
|
persistDividerPosition();
|
||||||
}
|
}
|
||||||
updateDividerTooltip(mainPanel);
|
updateDividerTooltip(mainPanel);
|
||||||
});
|
});
|
||||||
|
|
||||||
mainPanel.setOneTouchExpandable(true);
|
mainPanel.setOneTouchExpandable(true);
|
||||||
|
lastMainPanelExtent = getMainPanelExtent();
|
||||||
updateDividerTooltip(mainPanel);
|
updateDividerTooltip(mainPanel);
|
||||||
|
|
||||||
// Listen for divider position changes to update saved position and tooltip
|
// Listen for divider position changes to update tooltip
|
||||||
mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
|
mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
|
||||||
// Only update saved position and resizeWeight if the change was NOT caused by a window resize.
|
int currentExtent = getMainPanelExtent();
|
||||||
// This prevents the ratio from "drifting" when panels hit their minimum sizes during window resize.
|
if (!applyingSavedDividerLocation && currentExtent > 0 && currentExtent == lastMainPanelExtent) {
|
||||||
if (!isWindowResizing) {
|
persistDividerPosition();
|
||||||
int location = mainPanel.getDividerLocation();
|
|
||||||
int width = mainPanel.getWidth();
|
|
||||||
int dividerSize = mainPanel.getDividerSize();
|
|
||||||
if (width > dividerSize) {
|
|
||||||
double proportionalPosition = (double) location / (width - dividerSize);
|
|
||||||
config.setDividerPosition(proportionalPosition);
|
|
||||||
// Dynamically update resizeWeight to maintain current proportion during future window resizes
|
|
||||||
mainPanel.setResizeWeight(proportionalPosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
lastMainPanelExtent = currentExtent;
|
||||||
updateDividerTooltip(mainPanel);
|
updateDividerTooltip(mainPanel);
|
||||||
|
|
||||||
// Immediately show tooltip during drag if possible
|
// Immediately show tooltip during drag if possible
|
||||||
@ -207,21 +202,11 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
// Re-apply configured ratio after each resize (Linux can otherwise keep absolute pixels).
|
||||||
|
mainPanel.addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(java.awt.event.ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
isWindowResizing = true;
|
SwingUtilities.invokeLater(() -> applySavedDividerLocation());
|
||||||
try {
|
|
||||||
// Keep proportional divider position when window or splitpane is resized
|
|
||||||
double proportionalPosition = config.getDividerPosition();
|
|
||||||
if (proportionalPosition >= 0.0 && proportionalPosition <= 1.0) {
|
|
||||||
mainPanel.setDividerLocation(proportionalPosition);
|
|
||||||
}
|
|
||||||
updateDividerTooltip(mainPanel);
|
|
||||||
} finally {
|
|
||||||
// Reset flag after layout has likely happened
|
|
||||||
SwingUtilities.invokeLater(() -> isWindowResizing = false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -3061,6 +3046,7 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
tooltipWindow.setVisible(false);
|
tooltipWindow.setVisible(false);
|
||||||
|
persistDividerPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -3085,6 +3071,44 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void persistDividerPosition() {
|
||||||
|
if (mainPanel == null || config == null) return;
|
||||||
|
int location = mainPanel.getDividerLocation();
|
||||||
|
int extent = getMainPanelExtent();
|
||||||
|
if (extent <= 0) return;
|
||||||
|
|
||||||
|
double proportionalPosition = (double) location / extent;
|
||||||
|
proportionalPosition = Math.max(0.0, Math.min(1.0, proportionalPosition));
|
||||||
|
config.setDividerPosition(proportionalPosition);
|
||||||
|
mainPanel.setResizeWeight(proportionalPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applySavedDividerLocation() {
|
||||||
|
if (mainPanel == null || config == null) return;
|
||||||
|
double ratio = getConfiguredDividerRatio();
|
||||||
|
applyingSavedDividerLocation = true;
|
||||||
|
try {
|
||||||
|
mainPanel.setResizeWeight(ratio);
|
||||||
|
mainPanel.setDividerLocation(ratio);
|
||||||
|
updateDividerTooltip(mainPanel);
|
||||||
|
} finally {
|
||||||
|
applyingSavedDividerLocation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getConfiguredDividerRatio() {
|
||||||
|
if (config == null) return 0.5;
|
||||||
|
double savedPosition = config.getDividerPosition();
|
||||||
|
if (savedPosition >= 0.0 && savedPosition <= 1.0) return savedPosition;
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMainPanelExtent() {
|
||||||
|
if (mainPanel == null) return -1;
|
||||||
|
int totalSize = mainPanel.getOrientation() == JSplitPane.HORIZONTAL_SPLIT ? mainPanel.getWidth() : mainPanel.getHeight();
|
||||||
|
return totalSize - mainPanel.getDividerSize();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save configuration and exit application
|
* Save configuration and exit application
|
||||||
*/
|
*/
|
||||||
@ -3092,6 +3116,7 @@ public class MainWindow extends JFrame {
|
|||||||
if (autoRefreshTimer != null) {
|
if (autoRefreshTimer != null) {
|
||||||
autoRefreshTimer.stop();
|
autoRefreshTimer.stop();
|
||||||
}
|
}
|
||||||
|
persistDividerPosition();
|
||||||
// Save window state
|
// Save window state
|
||||||
config.saveWindowState(this);
|
config.saveWindowState(this);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user