Skip to content

Commit c2482a0

Browse files
hansonrhansonr
authored andcommitted
menu/button HTML5 look and feel fixes
1 parent f282d15 commit c2482a0

File tree

9 files changed

+56
-32
lines changed

9 files changed

+56
-32
lines changed
-1.08 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181220060434
1+
20181220124136
-1.08 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181220060434
1+
20181220124136

sources/net.sf.j2s.java.core/src/sun/swing/SwingLazyValue.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public SwingLazyValue(String c) {
5353
this(c, null, null);
5454
}
5555
public SwingLazyValue(String c, String m) {
56-
// new class.method()
56+
// new class.method() or $innerClass
5757
this(c, m, null);
5858
}
5959
public SwingLazyValue(String c, Object[] o) {
@@ -72,7 +72,14 @@ public SwingLazyValue(String c, String m, Object[] o) {
7272
@Override
7373
public Object createValue(final UIDefaults table) {
7474
try {
75-
// Object cl;
75+
if (className.indexOf("$") > 0) {
76+
// SwingJS preload inner classes
77+
/**
78+
* @j2sNative
79+
*
80+
* Clazz.load(className.split("$"));
81+
*/
82+
}
7683
Class c = Class.forName(className, true, null);
7784
if (methodName != null) {
7885
Class[] types = getClassArray(args);

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ protected void initComponentDefaults(UIDefaults table) {
557557
InsetsUIResource threeInsets = new InsetsUIResource(3, 3, 3, 3);
558558

559559
// // *** Shared Borders
560-
// Object marginBorder = new SwingLazyValue(
561-
// "javax.swing.plaf.basic.BasicBorders$MarginBorder");
560+
Object marginBorder = new SwingLazyValue("javax.swing.plaf.basic.BasicBorders$MarginBorder");
562561
Object etchedBorder = new BorderUIResource.EtchedBorderUIResource();
563562
Object loweredBevelBorder = new SwingLazyValue(
564563
"javax.swing.plaf.BorderUIResource",
@@ -1168,8 +1167,8 @@ public Object createValue(UIDefaults table) {
11681167
// "MenuItem.acceleratorForeground", menuText,
11691168
// "MenuItem.acceleratorSelectionForeground", textHighlightText,
11701169
// "MenuItem.acceleratorDelimiter", menuItemAcceleratorDelimiter,
1171-
// "MenuItem.border", marginBorder,
1172-
// "MenuItem.borderPainted", Boolean.FALSE,
1170+
"MenuItem.border", marginBorder,
1171+
"MenuItem.borderPainted", Boolean.FALSE,
11731172
"MenuItem.margin",
11741173
twoInsets,
11751174
// "MenuItem.checkIcon", menuItemCheckIcon,
@@ -1188,7 +1187,7 @@ public Object createValue(UIDefaults table) {
11881187
// "RadioButtonMenuItem.acceleratorForeground", menuText,
11891188
// "RadioButtonMenuItem.acceleratorSelectionForeground",
11901189
// textHighlightText,
1191-
// "RadioButtonMenuItem.border", marginBorder,
1190+
"RadioButtonMenuItem.border", marginBorder,
11921191
// "RadioButtonMenuItem.borderPainted", Boolean.FALSE,
11931192
"RadioButtonMenuItem.margin",
11941193
twoInsets,
@@ -1207,8 +1206,8 @@ public Object createValue(UIDefaults table) {
12071206
// "CheckBoxMenuItem.disabledForeground", null,
12081207
// "CheckBoxMenuItem.acceleratorForeground", menuText,
12091208
// "CheckBoxMenuItem.acceleratorSelectionForeground", textHighlightText,
1210-
// "CheckBoxMenuItem.border", marginBorder,
1211-
// "CheckBoxMenuItem.borderPainted", Boolean.FALSE,
1209+
"CheckBoxMenuItem.border", marginBorder,
1210+
"CheckBoxMenuItem.borderPainted", Boolean.FALSE,
12121211
"CheckBoxMenuItem.margin",
12131212
twoInsets,
12141213
// "CheckBoxMenuItem.checkIcon", checkBoxMenuItemIcon,
@@ -1226,8 +1225,8 @@ public Object createValue(UIDefaults table) {
12261225
// "Menu.disabledForeground", null,
12271226
// "Menu.acceleratorForeground", menuText,
12281227
// "Menu.acceleratorSelectionForeground", textHighlightText,
1229-
// "Menu.border", marginBorder,
1230-
// "Menu.borderPainted", Boolean.FALSE,
1228+
"Menu.border", marginBorder,
1229+
"Menu.borderPainted", Boolean.FALSE,
12311230
"Menu.margin",
12321231
twoInsets,
12331232
// "Menu.checkIcon", menuItemCheckIcon,

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,17 @@ public Dimension getHTMLSize(DOMNode obj) {
11431143
return setHTMLSize1(obj, false, false);
11441144
}
11451145

1146+
private Dimension getIconSize(AbstractButton b) {
1147+
return (iconNode == null || imageNode == null || b.getIcon() == null ? null
1148+
: getHTMLSize(iconNode));
1149+
}
1150+
1151+
private Dimension getTextSize(AbstractButton b) {
1152+
String t;
1153+
return (textNode == null || (t = b.getText()) == null
1154+
|| t == "" ? null : getHTMLSize(textNode));
1155+
}
1156+
11461157
/**
11471158
* also called by JSRadioButtonUI so that it can calculate subset dimensions
11481159
*
@@ -2002,11 +2013,11 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
20022013

20032014
getJSInsets();
20042015

2005-
Dimension dimIcon = setHTMLSize1(iconNode, false, false);
2016+
Dimension dimIcon = getIconSize(b);
2017+
Dimension dimText = getTextSize(b);
20062018
int wIcon = (actionNode != null ? (isMenuItem ? 15 : 20)
2007-
: iconNode == null ? 0 : imageNode == null ? 0 : Math.max(0, dimIcon.width));
2008-
Dimension dimText = setHTMLSize1(textNode, false, false);
2009-
int wText = dimText.width;
2019+
: dimIcon == null ? 0 : Math.max(0, dimIcon.width));
2020+
int wText = (dimText == null ? 0 : dimText.width);
20102021
int gap = (wText == 0 || wIcon == 0 ? 0 : b.getIconTextGap());
20112022
int w = cellComponent != null ? cellWidth : $(domNode).width();
20122023

@@ -2065,16 +2076,16 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
20652076
textRight = ltr;
20662077
}
20672078
boolean alignVCenter = (vAlign == SwingConstants.CENTER);
2068-
//
20692079
Insets margins = (isLabel ? insets : b.getMargin());
2070-
2080+
int h = (dimText == null ? 0 : dimText.height);
2081+
int ih = (dimIcon == null ? 0 : dimIcon.height);
2082+
int hCtr = Math.max(h, ih);
20712083
int wCtr = wIcon + gap + wText;
2072-
int hCtr = Math.max(dimText.height, dimIcon.height);
20732084
if (alignHCenter) {
20742085
switch (hTextPos) {
20752086
case SwingConstants.TOP:
20762087
case SwingConstants.BOTTOM:
2077-
hCtr = dimIcon.height + gap + dimText.height;
2088+
hCtr = ih + gap + h;
20782089
/* fall through */
20792090
case SwingConstants.CENTER:
20802091
wCtr = Math.max(wIcon, wText);
@@ -2151,19 +2162,19 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
21512162
if (alignRight) {
21522163
DOMNode.setStyles(itemNode, "text-align", "right");
21532164
DOMNode.setStyles(centeringNode, "right", "0px");
2154-
DOMNode.setStyles(textNode, "right", "28px");
2165+
DOMNode.setStyles(textNode, "right", "23px");
21552166
DOMNode.setStyles(iconNode, "right", "3px");
21562167
} else {
21572168
DOMNode.setStyles(itemNode, "text-align", "left");
21582169
DOMNode.setStyles(centeringNode, "left", "0px");
2159-
DOMNode.setStyles(iconNode, "left", "-3px");
2160-
DOMNode.setStyles(textNode, "left", "25px");
2170+
DOMNode.setStyles(iconNode, "left", "3px");
2171+
DOMNode.setStyles(textNode, "left", "23px");
21612172
}
21622173
}
21632174

21642175
int top = margins.top;
21652176

2166-
int h = c.getHeight();
2177+
h = c.getHeight();
21672178
if (h == 0) {
21682179
h = 16;
21692180
}
@@ -2206,7 +2217,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
22062217
DOMNode.setSize(menuAnchorNode, wCtr + margins.left + margins.right, h);
22072218
if (actionNode != null) {
22082219
DOMNode.setStyles(textNode, "top", "50%", "transform", "translateY(-80%)");
2209-
DOMNode.setStyles(iconNode, "top", "50%", "transform", "translateY(-90%) scale(0.6,0.6)");
2220+
DOMNode.setStyles(iconNode, "top", "50%", "transform", "translateY(-100%) scale(0.6,0.6)");
22102221
}
22112222
}
22122223
}
@@ -2760,8 +2771,4 @@ public void reinstallUI(JComponent oldC, JComponent newC) {
27602771
}
27612772
}
27622773

2763-
public int getTextWidth() {
2764-
return (textNode == null ? 0 : getHTMLSize(textNode).width);
2765-
}
2766-
27672774
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected Dimension getCSSAdjustment(boolean addingCSS) {
5454
public void installUI(JComponent jc) {
5555
menuItem = (JMenuItem) jc;
5656
super.installUI(jc);
57-
LookAndFeel.installColorsAndFont(jc, "MenuItem.background", "MenuItem.foreground",
58-
"MenuItem.font");
57+
// LookAndFeel.installColorsAndFont(jc, "MenuItem.background", "MenuItem.foreground",
58+
// "MenuItem.font");
5959
}
6060

6161
@Override
@@ -71,4 +71,9 @@ public void propertyChange(PropertyChangeEvent e) {
7171
}
7272
}
7373

74+
@Override
75+
protected String getPropertyPrefix() {
76+
return "MenuItem.";
77+
}
78+
7479
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ public Dimension getMaximumSize() {
107107
return getPreferredSize();
108108
}
109109

110+
@Override
111+
protected String getPropertyPrefix() {
112+
return "Menu.";
113+
}
114+
115+
110116
}

0 commit comments

Comments
 (0)