resize fixed

This commit is contained in:
Radek Davidek 2026-03-02 18:24:13 +01:00
parent df70ce0584
commit f1875e5343
2 changed files with 56 additions and 31 deletions

View File

@ -15,7 +15,7 @@ import java.io.InputStreamReader;
*/
public class MainApp {
public static final String APP_VERSION = "1.1.9";
public static final String APP_VERSION = "1.2.0";
public enum OS {
WINDOWS, LINUX, MACOS, UNKNOWN

View File

@ -34,7 +34,8 @@ public class MainWindow extends JFrame {
private JLabel cmdLabel;
private AppConfig config;
private Timer autoRefreshTimer;
private boolean isWindowResizing = false;
private int lastMainPanelExtent = -1;
private boolean applyingSavedDividerLocation = false;
private boolean wildcardDialogOpen = false;
public MainWindow() {
@ -112,7 +113,7 @@ public class MainWindow extends JFrame {
mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
mainPanel.setContinuousLayout(true);
// 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
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 {
// If it was saved as absolute pixels (historically), use as int
mainPanel.setDividerLocation((int) savedPosition);
persistDividerPosition();
}
updateDividerTooltip(mainPanel);
});
mainPanel.setOneTouchExpandable(true);
lastMainPanelExtent = getMainPanelExtent();
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 -> {
// Only update saved position and resizeWeight if the change was NOT caused by a window resize.
// This prevents the ratio from "drifting" when panels hit their minimum sizes during window resize.
if (!isWindowResizing) {
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);
}
int currentExtent = getMainPanelExtent();
if (!applyingSavedDividerLocation && currentExtent > 0 && currentExtent == lastMainPanelExtent) {
persistDividerPosition();
}
lastMainPanelExtent = currentExtent;
updateDividerTooltip(mainPanel);
// Immediately show tooltip during drag if possible
@ -206,22 +201,12 @@ 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
public void componentResized(java.awt.event.ComponentEvent e) {
isWindowResizing = true;
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);
}
public void componentResized(ComponentEvent e) {
SwingUtilities.invokeLater(() -> applySavedDividerLocation());
}
});
@ -3061,6 +3046,7 @@ public class MainWindow extends JFrame {
@Override
public void mouseReleased(MouseEvent e) {
tooltipWindow.setVisible(false);
persistDividerPosition();
}
@Override
@ -3084,6 +3070,44 @@ public class MainWindow extends JFrame {
tooltipWindow.setLocation(p.x + 15, p.y + 15);
}
}
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
@ -3092,6 +3116,7 @@ public class MainWindow extends JFrame {
if (autoRefreshTimer != null) {
autoRefreshTimer.stop();
}
persistDividerPosition();
// Save window state
config.saveWindowState(this);