Skip to content

Commit f8d2b2e

Browse files
committed
JSSplitPaneUI fix for undispose not resetting drag event handler
1 parent 9f10d71 commit f8d2b2e

File tree

1 file changed

+61
-64
lines changed

1 file changed

+61
-64
lines changed

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import javax.swing.LookAndFeel;
5454
import javax.swing.UIManager;
5555

56+
import swingjs.api.js.DOMNode;
5657
import swingjs.api.js.JSFunction;
5758
import swingjs.JSToolkit;
5859
import swingjs.api.js.JSInterface;
@@ -66,33 +67,13 @@
6667
*/
6768
public class JSSplitPaneUI extends JSPanelUI {
6869

69-
private class SplitPaneDivider extends JLabel {
70-
71-
private JSSplitPaneUI paneui;
72-
73-
/**
74-
* Returns dividerSize x dividerSize
75-
*/
76-
@Override
77-
public Dimension getPreferredSize() {
78-
// Ideally this would return the size from the layout manager,
79-
// but that could result in the layed out size being different from
80-
// the dividerSize, which may break developers as well as
81-
// BasicSplitPaneUI.
82-
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
83-
return new Dimension(paneui.splitPane.getDividerSize(), 1);
84-
}
85-
return new Dimension(1, paneui.splitPane.getDividerSize());
86-
}
87-
88-
SplitPaneDivider(JSSplitPaneUI ui) {
89-
super(" ");
90-
paneui = ui;
91-
setOpaque(true);
92-
}
9370

71+
@Override
72+
public DOMNode updateDOMNode() {
73+
return super.updateDOMNode();
9474
}
9575

76+
9677
/**
9778
* The divider used for non-continuous layout is added to the split pane with
9879
* this object.
@@ -267,7 +248,11 @@ private Cursor getCursor() {
267248
}
268249

269250
private void setupDivider() {
270-
divider = new SplitPaneDivider(this);
251+
divider = new SplitPaneDivider(this);
252+
enableDragging();
253+
}
254+
255+
private void enableDragging() {
271256
JSFunction fDrag = null;
272257
@SuppressWarnings("unused")
273258
JSSplitPaneUI me = this;
@@ -279,8 +264,9 @@ private void setupDivider() {
279264
*
280265
*/
281266
// note that this "JSFunction" is actually an array
282-
((JSComponentUI) divider.getUI()).setDraggable(fDrag);
267+
setDraggable(fDrag);
283268
}
269+
284270
/**
285271
* Installs the UI defaults.
286272
*/
@@ -1260,10 +1246,8 @@ public Dimension minimumLayoutSize(Container container) {
12601246
minSecondary += getSizeForSecondaryAxis(insets, true)
12611247
+ getSizeForSecondaryAxis(insets, false);
12621248
}
1263-
if (axis == 0) {
1264-
return new Dimension(minPrimary, minSecondary);
1265-
}
1266-
return new Dimension(minSecondary, minPrimary);
1249+
return (axis == JSplitPane.VERTICAL_SPLIT ? new Dimension(minPrimary, minSecondary)
1250+
: new Dimension(minSecondary, minPrimary));
12671251
}
12681252

12691253
/**
@@ -1293,10 +1277,9 @@ public Dimension preferredLayoutSize(Container container) {
12931277
preSecondary += getSizeForSecondaryAxis(insets, true)
12941278
+ getSizeForSecondaryAxis(insets, false);
12951279
}
1296-
if (axis == 0) {
1297-
return new Dimension(prePrimary, preSecondary);
1298-
}
1299-
return new Dimension(preSecondary, prePrimary);
1280+
return (axis == JSplitPane.VERTICAL_SPLIT ?
1281+
new Dimension(prePrimary, preSecondary)
1282+
: new Dimension(preSecondary, prePrimary));
13001283
}
13011284

13021285
/**
@@ -1463,15 +1446,15 @@ protected int getInitialLocation(Insets insets) {
14631446
protected void setComponentToSize(Component c, int size, int location,
14641447
Insets insets, Dimension containerSize) {
14651448
if (insets != null) {
1466-
if (axis == 0) {
1449+
if (axis == JSplitPane.VERTICAL_SPLIT) {
14671450
c.setBounds(location, insets.top, size, containerSize.height
14681451
- (insets.top + insets.bottom));
14691452
} else {
14701453
c.setBounds(insets.left, location, containerSize.width
14711454
- (insets.left + insets.right), size);
14721455
}
14731456
} else {
1474-
if (axis == 0) {
1457+
if (axis == JSplitPane.VERTICAL_SPLIT) {
14751458
c.setBounds(location, 0, size, containerSize.height);
14761459
} else {
14771460
c.setBounds(0, location, containerSize.width, size);
@@ -1483,20 +1466,14 @@ protected void setComponentToSize(Component c, int size, int location,
14831466
* If the axis == 0, the width is returned, otherwise the height.
14841467
*/
14851468
int getSizeForPrimaryAxis(Dimension size) {
1486-
if (axis == 0) {
1487-
return size.width;
1488-
}
1489-
return size.height;
1469+
return (axis == JSplitPane.VERTICAL_SPLIT ? size.width : size.height);
14901470
}
14911471

14921472
/**
14931473
* If the axis == 0, the width is returned, otherwise the height.
14941474
*/
14951475
int getSizeForSecondaryAxis(Dimension size) {
1496-
if (axis == 0) {
1497-
return size.height;
1498-
}
1499-
return size.width;
1476+
return (axis == JSplitPane.HORIZONTAL_SPLIT ? size.width : size.height);
15001477
}
15011478

15021479
/**
@@ -1506,16 +1483,9 @@ int getSizeForSecondaryAxis(Dimension size) {
15061483
* axis isTop 0 true - left 0 false - right 1 true - top 1 false - bottom
15071484
*/
15081485
int getSizeForPrimaryAxis(Insets insets, boolean isTop) {
1509-
if (axis == 0) {
1510-
if (isTop) {
1511-
return insets.left;
1512-
}
1513-
return insets.right;
1514-
}
1515-
if (isTop) {
1516-
return insets.top;
1517-
}
1518-
return insets.bottom;
1486+
return (axis == JSplitPane.VERTICAL_SPLIT ?
1487+
(isTop ? insets.left : insets.right)
1488+
: isTop ? insets.top : insets.bottom);
15191489
}
15201490

15211491
/**
@@ -1525,16 +1495,8 @@ int getSizeForPrimaryAxis(Insets insets, boolean isTop) {
15251495
* axis isTop 0 true - left 0 false - right 1 true - top 1 false - bottom
15261496
*/
15271497
int getSizeForSecondaryAxis(Insets insets, boolean isTop) {
1528-
if (axis == 0) {
1529-
if (isTop) {
1530-
return insets.top;
1531-
}
1532-
return insets.bottom;
1533-
}
1534-
if (isTop) {
1535-
return insets.left;
1536-
}
1537-
return insets.right;
1498+
return (axis == JSplitPane.VERTICAL_SPLIT ? (isTop ? insets.top : insets.bottom)
1499+
: isTop ? insets.left : insets.right);
15381500
}
15391501

15401502
/**
@@ -2218,4 +2180,39 @@ public void setEnabled(boolean b) {
22182180
splitPane.setCursor(b ? getCursor() : null);
22192181
}
22202182

2183+
@Override
2184+
protected void undisposeUI(DOMNode node) {
2185+
if (!isDisposed)
2186+
return;
2187+
super.undisposeUI(node);
2188+
enableDragging();
2189+
}
2190+
2191+
private class SplitPaneDivider extends JLabel {
2192+
2193+
private JSSplitPaneUI paneui;
2194+
2195+
/**
2196+
* Returns dividerSize x dividerSize
2197+
*/
2198+
@Override
2199+
public Dimension getPreferredSize() {
2200+
// Ideally this would return the size from the layout manager,
2201+
// but that could result in the layed out size being different from
2202+
// the dividerSize, which may break developers as well as
2203+
// BasicSplitPaneUI.
2204+
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
2205+
return new Dimension(paneui.splitPane.getDividerSize(), 1);
2206+
}
2207+
return new Dimension(1, paneui.splitPane.getDividerSize());
2208+
}
2209+
2210+
SplitPaneDivider(JSSplitPaneUI ui) {
2211+
super(" ");
2212+
paneui = ui;
2213+
setOpaque(true);
2214+
}
2215+
2216+
}
2217+
22212218
}

0 commit comments

Comments
 (0)