Skip to content

Commit 844bd92

Browse files
hansonrhansonr
authored andcommitted
revising getMinimumSize/getPreferredSize/getMaximumSize defaults and use
1 parent 58efdd9 commit 844bd92

File tree

14 files changed

+69
-86
lines changed

14 files changed

+69
-86
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ public Dimension getPreferredSize() {
14741474

14751475
public Dimension getPrefSizeJComp() {
14761476
Dimension size = (isPreferredSizeSet() || ui == null ? null : ui
1477-
.getPreferredSize());
1477+
.getPreferredSize(this));
14781478
return (size == null ? preferredSize() : size);
14791479
}
14801480

@@ -1512,7 +1512,7 @@ public Dimension getMaximumSize() {
15121512
}
15131513
Dimension size = null;
15141514
if (ui != null) {
1515-
size = ui.getMaximumSize();
1515+
size = ui.getMaximumSize(this);
15161516
}
15171517
return (size != null) ? size : super.getMaximumSize();
15181518
}
@@ -1550,7 +1550,7 @@ public Dimension getMinimumSize() {
15501550
}
15511551
Dimension size = null;
15521552
if (ui != null) {
1553-
size = ui.getMinimumSize();
1553+
size = ui.getMinimumSize(this);
15541554
}
15551555
return (size != null) ? size : super.getMinimumSize();
15561556
}

sources/net.sf.j2s.java.core/src/javax/swing/plaf/ComponentUI.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ public void update(Graphics g, JComponent c) {
186186
* @see javax.swing.JComponent#getPreferredSize
187187
* @see java.awt.LayoutManager#preferredLayoutSize
188188
*/
189-
@Override
190-
public Dimension getPreferredSize() {
191-
return null;
189+
public Dimension getPreferredSize(JComponent c) {
190+
return getPreferredSize();
192191
}
193192

194193
/**
@@ -205,8 +204,7 @@ public Dimension getPreferredSize() {
205204
* @see java.awt.LayoutManager#minimumLayoutSize
206205
* @see #getPreferredSize
207206
*/
208-
@Override
209-
public Dimension getMinimumSize() {
207+
public Dimension getMinimumSize(JComponent c) {
210208
return getPreferredSize();
211209
}
212210

@@ -223,8 +221,8 @@ public Dimension getMinimumSize() {
223221
* @see javax.swing.JComponent#getMaximumSize
224222
* @see java.awt.LayoutManager2#maximumLayoutSize
225223
*/
226-
public Dimension getMaximumSize() {
227-
return null;// getPreferredSize(c);
224+
public Dimension getMaximumSize(JComponent c) {
225+
return getPreferredSize();
228226
}
229227

230228
/**

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,8 @@ protected void setInnerComponentBounds(int width, int height) {
748748
}
749749

750750
@Override
751-
public Dimension getMaximumSize(JComponent c) {
752-
Dimension d = getPreferredSize(c);
753-
return d;
751+
protected Dimension getMaximumSize() {
752+
return getPreferredSize();
754753
}
755754

756755
@Override

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

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,8 @@ protected void addJQueryFocusCallbacks() {
710710
* @j2sNative
711711
*
712712
* node.focus(function() {me.notifyFocus$Z(true)});
713-
* node.blur(function() {me.notifyFocus$Z(false)});
713+
* node.blur(function() {try{me.notifyFocus$Z(false)}catch(e){}});
714714
*/
715-
{
716-
}
717715
}
718716

719717
/**
@@ -1085,12 +1083,11 @@ private void updateCell(int width, int height) {
10851083
protected DOMNode setCssFont(DOMNode obj, Font font) {
10861084
if (font != null) {
10871085
int istyle = font.getStyle();
1088-
String name = font.getFamily();
1089-
if (name == "Dialog" || name == "SansSerif")
1090-
name = "Arial";
1091-
DOMNode.setStyles(obj, "font-family", name, "font-size", font.getSize() + "px", "font-style",
1092-
((istyle & Font.ITALIC) == 0 ? "normal" : "italic"), "font-weight",
1093-
((istyle & Font.BOLD) == 0 ? "normal" : "bold"));
1086+
DOMNode.setStyles(obj,
1087+
"font-family", JSToolkit.getCSSFontFamilyName(font.getFamily()),
1088+
"font-size", font.getSize() + "px",
1089+
"font-style", ((istyle & Font.ITALIC) == 0 ? "normal" : "italic"),
1090+
"font-weight", ((istyle & Font.BOLD) == 0 ? "normal" : "bold"));
10941091
}
10951092

10961093
// if (c.isBackgroundSet())
@@ -1502,13 +1499,23 @@ public void print(Graphics g) {
15021499

15031500
@Override
15041501
public Dimension getMinimumSize() {
1505-
return getMinimumSize(jc);
1502+
return getPreferredSize();
15061503
}
15071504

1508-
@Override
1509-
public Dimension getMaximumSize() {
1505+
protected Dimension getMaximumSize() {
15101506
return getMaximumSize(jc);
15111507
}
1508+
1509+
@Override
1510+
public Dimension getMaximumSize(JComponent jc) {
1511+
if (isToolbarFixed) { // default is true
1512+
Container parent = jc.getParent();
1513+
String parentClass = (parent == null ? null : parent.getUIClassID());
1514+
if ("ToolBarUI" == parentClass)
1515+
return getPreferredSize();
1516+
}
1517+
return getPreferredSize();
1518+
}
15121519

15131520
/**
15141521
* getPreferredSize reports to a LayoutManager what the size is for this
@@ -1520,40 +1527,12 @@ public Dimension getMaximumSize() {
15201527
* Later, the LayoutManager will make a call to setBounds in order to complete
15211528
* the transaction, after taking everything into consideration.
15221529
*
1523-
* SwingJS: Do not override this method.
1524-
*
15251530
*/
15261531
@Override
15271532
public Dimension getPreferredSize() {
1528-
return getPreferredSize(jc);
1529-
}
1530-
1531-
// the following are likely to be called in the original BasicXXXUI classes
1532-
1533-
Dimension getMinimumSize(JComponent jc) {
1534-
return getPreferredSize(jc);
1535-
}
1536-
1537-
/**
1538-
* SwingJS: Override this method to set preferred sizes
1539-
*
1540-
* @param jc
1541-
* @return
1542-
*/
1543-
Dimension getPreferredSize(JComponent jc) {
15441533
return getHTMLSizePreferred(updateDOMNode(), false);
15451534
}
15461535

1547-
Dimension getMaximumSize(JComponent jc) {
1548-
if (isToolbarFixed) { // default is true
1549-
Container parent = jc.getParent();
1550-
String parentClass = (parent == null ? null : parent.getUIClassID());
1551-
if ("ToolBarUI" == parentClass)
1552-
return getPreferredSize();
1553-
}
1554-
return null;
1555-
}
1556-
15571536
/**
15581537
*
15591538
* Returns <code>true</code> if the specified <i>x,y</i> location is contained

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ protected int getChildCount() {
102102
}
103103

104104

105-
@Override
106-
public Dimension getMaximumSize() {
107-
return super.getPreferredSize();
108-
}
109-
110-
@Override
111-
public Dimension getPreferredSize() {
112-
return super.getPreferredSize();
113-
}
105+
// @Override
106+
// public Dimension getMaximumSize(JComponent jc) {
107+
// return super.getPreferredSize(jc);
108+
// }
109+
//
110+
// @Override
111+
// public Dimension getPreferredSize(JComponent jc) {
112+
// return super.getPreferredSize(jc);
113+
// }
114114

115115
@Override
116116
protected String getPropertyPrefix() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ public Dimension getMinimumOptionPaneSize() {
245245
* <code>getMinimumOptionPaneSize</code>.
246246
*/
247247
@Override
248-
public Dimension getPreferredSize(JComponent c) {
249-
if (c == optionPane) {
248+
public Dimension getPreferredSize() {
249+
if (jc == optionPane) {
250250
Dimension ourMin = getMinimumOptionPaneSize();
251-
LayoutManager lm = c.getLayout();
251+
LayoutManager lm = jc.getLayout();
252252

253253
if (lm != null) {
254-
Dimension lmSize = lm.preferredLayoutSize(c);
254+
Dimension lmSize = lm.preferredLayoutSize(jc);
255255

256256
if (ourMin != null)
257257
return new Dimension

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void uninstallUI(JComponent jc) {
5252

5353
@Override
5454
public Dimension getPreferredSize() {
55-
return null;
55+
return null;
5656
}
5757

5858
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.Dimension;
44
import java.beans.PropertyChangeEvent;
55

6+
import javax.swing.JComponent;
67
import javax.swing.JScrollBar;
78
import javax.swing.event.ChangeEvent;
89
import swingjs.api.js.DOMNode;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private void checkTextAreaHeight() {
262262
* @return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)
263263
*/
264264
@Override
265-
public Dimension getMaximumSize(JComponent c) {
265+
protected Dimension getMaximumSize() {
266266
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
267267
}
268268

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ public void paint(Graphics g, JComponent jc) {
901901
* to the current layoutmanager.
902902
*/
903903
@Override
904-
public Dimension getPreferredSize(JComponent jc) {
904+
public Dimension getPreferredSize() {
905905
if (splitPane != null)
906906
return layoutManager.preferredLayoutSize(splitPane);
907907
return new Dimension(0, 0);
@@ -912,7 +912,7 @@ public Dimension getPreferredSize(JComponent jc) {
912912
* the current layoutmanager.
913913
*/
914914
@Override
915-
public Dimension getMinimumSize(JComponent jc) {
915+
public Dimension getMinimumSize() {
916916
if (splitPane != null)
917917
return layoutManager.minimumLayoutSize(splitPane);
918918
return new Dimension(0, 0);
@@ -923,7 +923,7 @@ public Dimension getMinimumSize(JComponent jc) {
923923
* the current layoutmanager.
924924
*/
925925
@Override
926-
public Dimension getMaximumSize(JComponent jc) {
926+
protected Dimension getMaximumSize() {
927927
if (splitPane != null)
928928
return layoutManager.maximumLayoutSize(splitPane);
929929
return new Dimension(0, 0);

0 commit comments

Comments
 (0)