panel divider ron resize fixed
This commit is contained in:
parent
8a86dda3dc
commit
a2dc165944
@ -15,7 +15,7 @@ import java.io.InputStreamReader;
|
|||||||
*/
|
*/
|
||||||
public class MainApp {
|
public class MainApp {
|
||||||
|
|
||||||
public static final String APP_VERSION = "1.1.5";
|
public static final String APP_VERSION = "1.1.6";
|
||||||
|
|
||||||
public enum OS {
|
public enum OS {
|
||||||
WINDOWS, LINUX, MACOS, UNKNOWN
|
WINDOWS, LINUX, MACOS, UNKNOWN
|
||||||
|
|||||||
@ -34,6 +34,7 @@ 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;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
|
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
|
||||||
@ -109,6 +110,8 @@ public class MainWindow extends JFrame {
|
|||||||
// Panel containing the two file panels with resizable divider
|
// Panel containing the two file panels with resizable divider
|
||||||
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
|
||||||
|
mainPanel.setResizeWeight(config.getDividerPosition());
|
||||||
|
|
||||||
// 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");
|
||||||
@ -162,6 +165,8 @@ public class MainWindow extends JFrame {
|
|||||||
double savedPosition = config.getDividerPosition();
|
double savedPosition = config.getDividerPosition();
|
||||||
if (savedPosition >= 0.0 && savedPosition <= 1.0) {
|
if (savedPosition >= 0.0 && savedPosition <= 1.0) {
|
||||||
mainPanel.setDividerLocation(savedPosition);
|
mainPanel.setDividerLocation(savedPosition);
|
||||||
|
// Dynamically update resizeWeight to maintain current proportion during future window resizes
|
||||||
|
mainPanel.setResizeWeight(savedPosition);
|
||||||
} 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);
|
||||||
@ -174,12 +179,18 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
// Listen for divider position changes to update saved position and tooltip
|
// Listen for divider position changes to update saved position and tooltip
|
||||||
mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
|
mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
|
||||||
int location = mainPanel.getDividerLocation();
|
// Only update saved position and resizeWeight if the change was NOT caused by a window resize.
|
||||||
int width = mainPanel.getWidth();
|
// This prevents the ratio from "drifting" when panels hit their minimum sizes during window resize.
|
||||||
int dividerSize = mainPanel.getDividerSize();
|
if (!isWindowResizing) {
|
||||||
if (width > dividerSize) {
|
int location = mainPanel.getDividerLocation();
|
||||||
double proportionalPosition = (double) location / (width - dividerSize);
|
int width = mainPanel.getWidth();
|
||||||
config.setDividerPosition(proportionalPosition);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateDividerTooltip(mainPanel);
|
updateDividerTooltip(mainPanel);
|
||||||
|
|
||||||
@ -195,7 +206,18 @@ public class MainWindow extends JFrame {
|
|||||||
mainPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
mainPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(java.awt.event.ComponentEvent e) {
|
public void componentResized(java.awt.event.ComponentEvent e) {
|
||||||
updateDividerTooltip(mainPanel);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user