Skip to content

Commit 4db990d

Browse files
authored
Merge pull request #75 from BobHanson/hanson1
label, button work.
2 parents 946bf83 + e437de3 commit 4db990d

File tree

14 files changed

+979
-857
lines changed

14 files changed

+979
-857
lines changed
-68.8 KB
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ protected void paintChildren(Graphics g) {
694694

695695

696696
JSGraphics2D jsg = (JSGraphics2D) (Object) sg.create(tmpRect.x,
697-
(/*isContentPane ? 0 : */tmpRect.y), vr.width, vr.height);
697+
(jc.isContentPane ? 0 : tmpRect.y), vr.width, vr.height);
698698
jsg.setColor(jc.getForeground());
699699
jsg.setFont(jc.getFont());
700700
boolean shouldSetFlagBack = false;

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

Lines changed: 82 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.applet.JSApplet;
3131
import java.awt.Component;
3232
import java.awt.Container;
33+
import java.awt.Dimension;
3334
import java.awt.EventQueue;
3435
import java.awt.FontMetrics;
3536
import java.awt.JSFrame;
@@ -62,6 +63,8 @@
6263
import swingjs.JSAppletViewer;
6364
import swingjs.JSUtil;
6465
import swingjs.api.Interface;
66+
import swingjs.api.js.DOMNode;
67+
import swingjs.plaf.JSComponentUI;
6568

6669
/**
6770
* A collection of utility methods for Swing.
@@ -858,39 +861,43 @@ public static String layoutCompoundLabel(JComponent c,
858861
Rectangle textR,
859862
int textIconGap)
860863
{
861-
boolean orientationIsLeftToRight = true;
862-
int hAlign = horizontalAlignment;
863-
int hTextPos = horizontalTextPosition;
864-
865-
if (c != null) {
866-
if (!(c.getComponentOrientation().isLeftToRight())) {
867-
orientationIsLeftToRight = false;
868-
}
869-
}
870-
871-
// Translate LEADING/TRAILING values in horizontalAlignment
872-
// to LEFT/RIGHT values depending on the components orientation
873-
switch (horizontalAlignment) {
874-
case LEADING:
875-
hAlign = (orientationIsLeftToRight) ? LEFT : RIGHT;
876-
break;
877-
case TRAILING:
878-
hAlign = (orientationIsLeftToRight) ? RIGHT : LEFT;
879-
break;
880-
}
881-
882-
// Translate LEADING/TRAILING values in horizontalTextPosition
883-
// to LEFT/RIGHT values depending on the components orientation
884-
switch (horizontalTextPosition) {
885-
case LEADING:
886-
hTextPos = (orientationIsLeftToRight) ? LEFT : RIGHT;
887-
break;
888-
case TRAILING:
889-
hTextPos = (orientationIsLeftToRight) ? RIGHT : LEFT;
890-
break;
891-
}
892-
893-
return layoutCompoundLabelImpl(c,
864+
865+
JSComponentUI ui = (JSComponentUI) c.getUI();
866+
867+
boolean ltr = (c == null || c.getComponentOrientation().isLeftToRight());
868+
int hAlign, hTextPos;
869+
870+
if (ui.menuAnchorNode == null) {
871+
// Translate LEADING/TRAILING values in horizontalAlignment
872+
// to LEFT/RIGHT values depending on the components orientation
873+
switch (horizontalAlignment) {
874+
case LEADING:
875+
hAlign = (ltr) ? LEFT : RIGHT;
876+
break;
877+
case TRAILING:
878+
hAlign = (ltr) ? RIGHT : LEFT;
879+
break;
880+
default:
881+
hAlign = horizontalAlignment;
882+
break;
883+
}
884+
switch (horizontalTextPosition) {
885+
case LEADING:
886+
hTextPos = (ltr) ? LEFT : RIGHT;
887+
break;
888+
case TRAILING:
889+
hTextPos = (ltr) ? RIGHT : LEFT;
890+
break;
891+
default:
892+
hTextPos = horizontalTextPosition;
893+
break;
894+
}
895+
} else {
896+
// menus are far simpler!
897+
hAlign = hTextPos = (ltr ? LEFT : RIGHT);
898+
}
899+
900+
return layoutCompoundLabelImpl(c, ui,
894901
fm,
895902
text,
896903
icon,
@@ -927,7 +934,7 @@ public static String layoutCompoundLabel(
927934
Rectangle textR,
928935
int textIconGap)
929936
{
930-
return layoutCompoundLabelImpl(null, fm, text, icon,
937+
return layoutCompoundLabelImpl(null, null, fm, text, icon,
931938
verticalAlignment,
932939
horizontalAlignment,
933940
verticalTextPosition,
@@ -947,6 +954,7 @@ public static String layoutCompoundLabel(
947954
*/
948955
private static String layoutCompoundLabelImpl(
949956
JComponent c,
957+
JSComponentUI ui,
950958
FontMetrics fm,
951959
String text,
952960
Icon icon,
@@ -962,12 +970,16 @@ private static String layoutCompoundLabelImpl(
962970
/* Initialize the icon bounds rectangle iconR.
963971
*/
964972

973+
System.out.println("SwingUtil tiv0 " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n"
974+
+ fm.getDescent() + " " + fm.getAscent() + " " + fm.getHeight() + " " + fm.getMaxAscent());
975+
965976
if (icon != null) {
966977
iconR.width = icon.getIconWidth();
967978
iconR.height = icon.getIconHeight();
968-
}
969-
else {
970-
iconR.width = iconR.height = 0;
979+
// }
980+
// else {
981+
// SwingJS -- we allow passing in the radio button
982+
// iconR.width = iconR.height = 0;
971983
}
972984

973985
/* Initialize the text bounds rectangle textR. If a null
@@ -991,7 +1003,7 @@ private static String layoutCompoundLabelImpl(
9911003
}
9921004
else {
9931005
int availTextWidth;
994-
gap = (icon == null) ? 0 : textIconGap;
1006+
gap = (iconR.width == 0) ? 0 : textIconGap;
9951007

9961008
if (horizontalTextPosition == CENTER) {
9971009
availTextWidth = viewR.width;
@@ -1005,8 +1017,10 @@ private static String layoutCompoundLabelImpl(
10051017
(int) v.getPreferredSpan(View.X_AXIS));
10061018
textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
10071019
} else {
1008-
textR.width = SwingUtilities2.stringWidth(c, fm, text);
1009-
1020+
Dimension d = ui.getHTMLSize(ui.textNode);
1021+
textR.width = d.width;
1022+
textR.height = d.height;
1023+
System.out.println("swingutil " + text + " " + d + " " + fm.getHeight());
10101024
// Take into account the left and right side bearings.
10111025
// This gives more space than it is actually needed,
10121026
// but there are two reasons:
@@ -1015,21 +1029,21 @@ private static String layoutCompoundLabelImpl(
10151029
// themselves. NOTE: all pref size calculations don't do it.
10161030
// 2. You can do a drawString at the returned location
10171031
// and the text won't be clipped.
1018-
lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
1019-
if (lsb < 0) {
1020-
textR.width -= lsb;
1021-
}
1022-
rsb = SwingUtilities2.getRightSideBearing(c, fm, text);
1023-
if (rsb > 0) {
1024-
textR.width += rsb;
1025-
}
1032+
// SwingJS lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
1033+
// if (lsb < 0) {
1034+
// textR.width -= lsb;
1035+
// }
1036+
// rsb = SwingUtilities2.getRightSideBearing(c, fm, text);
1037+
// if (rsb > 0) {
1038+
// textR.width += rsb;
1039+
// }
10261040

10271041
if (textR.width > availTextWidth) {
10281042
text = SwingUtilities2.clipString(c, fm, text,
10291043
availTextWidth);
10301044
textR.width = SwingUtilities2.stringWidth(c, fm, text);
10311045
}
1032-
textR.height = fm.getHeight();
1046+
// textR.height = fm.getHeight();
10331047
}
10341048
}
10351049

@@ -1041,13 +1055,14 @@ private static String layoutCompoundLabelImpl(
10411055
if (verticalTextPosition == TOP) {
10421056
if (horizontalTextPosition != CENTER) {
10431057
textR.y = 0;
1058+
// textR.y = iconR.height - textR.height;//(int) (4 * textR.height/54f);//- textR.height;
10441059
}
10451060
else {
10461061
textR.y = -(textR.height + gap);
10471062
}
10481063
}
1049-
else if (verticalTextPosition == CENTER) {
1050-
textR.y = (iconR.height / 2) - (textR.height / 2);
1064+
else if (verticalTextPosition == CENTER) { // 16 pt max; height is 18, ascent is 12, actually
1065+
textR.y = (iconR.height/2) - (textR.height / 2);
10511066
}
10521067
else { // (verticalTextPosition == BOTTOM)
10531068
if (horizontalTextPosition != CENTER) {
@@ -1118,17 +1133,24 @@ else if (horizontalAlignment == RIGHT) {
11181133
iconR.x += dx;
11191134
iconR.y += dy;
11201135

1121-
if (lsb < 0) {
1122-
// lsb is negative. Shift the x location so that the text is
1123-
// visually drawn at the right location.
1124-
textR.x -= lsb;
1136+
//SwingJS if (lsb < 0) {
1137+
// // lsb is negative. Shift the x location so that the text is
1138+
// // visually drawn at the right location.
1139+
// textR.x -= lsb;
1140+
//
1141+
// textR.width += lsb;
1142+
// }
1143+
// if (rsb > 0) {
1144+
// textR.width -= rsb;
1145+
// }
11251146

1126-
textR.width += lsb;
1147+
if (viewR.width == Short.MAX_VALUE) {
1148+
// SwingJS, for JSGraphicsUtil setting preferred button size;
1149+
viewR.width = labelR_width;
1150+
viewR.height = labelR_height;
11271151
}
1128-
if (rsb > 0) {
1129-
textR.width -= rsb;
1130-
}
1131-
1152+
1153+
System.out.println("SwingUtil tiv " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n");
11321154
return text;
11331155
}
11341156

sources/net.sf.j2s.java.core/src/javax/swing/border/LineBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int he
140140
inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
141141
}
142142
else {
143-
outer = new Rectangle2D.Float(x, y, width, height);
144-
inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
143+
outer = new Rectangle2D.Float(x-0.5f, y-0.5f, width+1, height+1);
144+
inner = new Rectangle2D.Float(x + offs-0.5f, y + offs-0.5f, width - size+1, height - size+1);
145145
}
146146
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
147147
path.append(outer, false);

0 commit comments

Comments
 (0)