Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ protected void paintChildren(Graphics g) {


JSGraphics2D jsg = (JSGraphics2D) (Object) sg.create(tmpRect.x,
(/*isContentPane ? 0 : */tmpRect.y), vr.width, vr.height);
(jc.isContentPane ? 0 : tmpRect.y), vr.width, vr.height);
jsg.setColor(jc.getForeground());
jsg.setFont(jc.getFont());
boolean shouldSetFlagBack = false;
Expand Down
142 changes: 82 additions & 60 deletions sources/net.sf.j2s.java.core/src/javax/swing/SwingUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.applet.JSApplet;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FontMetrics;
import java.awt.JSFrame;
Expand Down Expand Up @@ -62,6 +63,8 @@
import swingjs.JSAppletViewer;
import swingjs.JSUtil;
import swingjs.api.Interface;
import swingjs.api.js.DOMNode;
import swingjs.plaf.JSComponentUI;

/**
* A collection of utility methods for Swing.
Expand Down Expand Up @@ -858,39 +861,43 @@ public static String layoutCompoundLabel(JComponent c,
Rectangle textR,
int textIconGap)
{
boolean orientationIsLeftToRight = true;
int hAlign = horizontalAlignment;
int hTextPos = horizontalTextPosition;

if (c != null) {
if (!(c.getComponentOrientation().isLeftToRight())) {
orientationIsLeftToRight = false;
}
}

// Translate LEADING/TRAILING values in horizontalAlignment
// to LEFT/RIGHT values depending on the components orientation
switch (horizontalAlignment) {
case LEADING:
hAlign = (orientationIsLeftToRight) ? LEFT : RIGHT;
break;
case TRAILING:
hAlign = (orientationIsLeftToRight) ? RIGHT : LEFT;
break;
}

// Translate LEADING/TRAILING values in horizontalTextPosition
// to LEFT/RIGHT values depending on the components orientation
switch (horizontalTextPosition) {
case LEADING:
hTextPos = (orientationIsLeftToRight) ? LEFT : RIGHT;
break;
case TRAILING:
hTextPos = (orientationIsLeftToRight) ? RIGHT : LEFT;
break;
}

return layoutCompoundLabelImpl(c,

JSComponentUI ui = (JSComponentUI) c.getUI();

boolean ltr = (c == null || c.getComponentOrientation().isLeftToRight());
int hAlign, hTextPos;

if (ui.menuAnchorNode == null) {
// Translate LEADING/TRAILING values in horizontalAlignment
// to LEFT/RIGHT values depending on the components orientation
switch (horizontalAlignment) {
case LEADING:
hAlign = (ltr) ? LEFT : RIGHT;
break;
case TRAILING:
hAlign = (ltr) ? RIGHT : LEFT;
break;
default:
hAlign = horizontalAlignment;
break;
}
switch (horizontalTextPosition) {
case LEADING:
hTextPos = (ltr) ? LEFT : RIGHT;
break;
case TRAILING:
hTextPos = (ltr) ? RIGHT : LEFT;
break;
default:
hTextPos = horizontalTextPosition;
break;
}
} else {
// menus are far simpler!
hAlign = hTextPos = (ltr ? LEFT : RIGHT);
}

return layoutCompoundLabelImpl(c, ui,
fm,
text,
icon,
Expand Down Expand Up @@ -927,7 +934,7 @@ public static String layoutCompoundLabel(
Rectangle textR,
int textIconGap)
{
return layoutCompoundLabelImpl(null, fm, text, icon,
return layoutCompoundLabelImpl(null, null, fm, text, icon,
verticalAlignment,
horizontalAlignment,
verticalTextPosition,
Expand All @@ -947,6 +954,7 @@ public static String layoutCompoundLabel(
*/
private static String layoutCompoundLabelImpl(
JComponent c,
JSComponentUI ui,
FontMetrics fm,
String text,
Icon icon,
Expand All @@ -962,12 +970,16 @@ private static String layoutCompoundLabelImpl(
/* Initialize the icon bounds rectangle iconR.
*/

System.out.println("SwingUtil tiv0 " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n"
+ fm.getDescent() + " " + fm.getAscent() + " " + fm.getHeight() + " " + fm.getMaxAscent());

if (icon != null) {
iconR.width = icon.getIconWidth();
iconR.height = icon.getIconHeight();
}
else {
iconR.width = iconR.height = 0;
// }
// else {
// SwingJS -- we allow passing in the radio button
// iconR.width = iconR.height = 0;
}

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

if (horizontalTextPosition == CENTER) {
availTextWidth = viewR.width;
Expand All @@ -1005,8 +1017,10 @@ private static String layoutCompoundLabelImpl(
(int) v.getPreferredSpan(View.X_AXIS));
textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
} else {
textR.width = SwingUtilities2.stringWidth(c, fm, text);

Dimension d = ui.getHTMLSize(ui.textNode);
textR.width = d.width;
textR.height = d.height;
System.out.println("swingutil " + text + " " + d + " " + fm.getHeight());
// Take into account the left and right side bearings.
// This gives more space than it is actually needed,
// but there are two reasons:
Expand All @@ -1015,21 +1029,21 @@ private static String layoutCompoundLabelImpl(
// themselves. NOTE: all pref size calculations don't do it.
// 2. You can do a drawString at the returned location
// and the text won't be clipped.
lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
if (lsb < 0) {
textR.width -= lsb;
}
rsb = SwingUtilities2.getRightSideBearing(c, fm, text);
if (rsb > 0) {
textR.width += rsb;
}
// SwingJS lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
// if (lsb < 0) {
// textR.width -= lsb;
// }
// rsb = SwingUtilities2.getRightSideBearing(c, fm, text);
// if (rsb > 0) {
// textR.width += rsb;
// }

if (textR.width > availTextWidth) {
text = SwingUtilities2.clipString(c, fm, text,
availTextWidth);
textR.width = SwingUtilities2.stringWidth(c, fm, text);
}
textR.height = fm.getHeight();
// textR.height = fm.getHeight();
}
}

Expand All @@ -1041,13 +1055,14 @@ private static String layoutCompoundLabelImpl(
if (verticalTextPosition == TOP) {
if (horizontalTextPosition != CENTER) {
textR.y = 0;
// textR.y = iconR.height - textR.height;//(int) (4 * textR.height/54f);//- textR.height;
}
else {
textR.y = -(textR.height + gap);
}
}
else if (verticalTextPosition == CENTER) {
textR.y = (iconR.height / 2) - (textR.height / 2);
else if (verticalTextPosition == CENTER) { // 16 pt max; height is 18, ascent is 12, actually
textR.y = (iconR.height/2) - (textR.height / 2);
}
else { // (verticalTextPosition == BOTTOM)
if (horizontalTextPosition != CENTER) {
Expand Down Expand Up @@ -1118,17 +1133,24 @@ else if (horizontalAlignment == RIGHT) {
iconR.x += dx;
iconR.y += dy;

if (lsb < 0) {
// lsb is negative. Shift the x location so that the text is
// visually drawn at the right location.
textR.x -= lsb;
//SwingJS if (lsb < 0) {
// // lsb is negative. Shift the x location so that the text is
// // visually drawn at the right location.
// textR.x -= lsb;
//
// textR.width += lsb;
// }
// if (rsb > 0) {
// textR.width -= rsb;
// }

textR.width += lsb;
if (viewR.width == Short.MAX_VALUE) {
// SwingJS, for JSGraphicsUtil setting preferred button size;
viewR.width = labelR_width;
viewR.height = labelR_height;
}
if (rsb > 0) {
textR.width -= rsb;
}


System.out.println("SwingUtil tiv " + text + "\n" + textR + "\n" + iconR + "\n" + viewR + "\n");
return text;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int he
inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
}
else {
outer = new Rectangle2D.Float(x, y, width, height);
inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
outer = new Rectangle2D.Float(x-0.5f, y-0.5f, width+1, height+1);
inner = new Rectangle2D.Float(x + offs-0.5f, y + offs-0.5f, width - size+1, height - size+1);
}
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
path.append(outer, false);
Expand Down
Loading