Skip to content

Commit 636e51b

Browse files
hansonrhansonr
authored andcommitted
forcing use of getInsets(), not getInsets(insets) for AWT components
1 parent e60b27f commit 636e51b

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static Component[] getChildArray(Container c) {
135135
*/
136136
public boolean _isBackgroundPainted;
137137

138-
138+
private Insets tempInsets;
139139

140140
public JSComponent() {
141141
super();
@@ -153,12 +153,23 @@ public JSComponent() {
153153
public Graphics getGraphics() {
154154
if (width == 0 || height == 0 || !isVisible())
155155
return null;
156-
if (frameViewer != null)
157-
return frameViewer.getGraphics().create();
156+
Graphics g;
157+
if (frameViewer != null) {
158+
g = frameViewer.getGraphics().create();
159+
if (isContentPane) {
160+
if (tempInsets == null)
161+
tempInsets = new Insets(0,0,0,0);
162+
((JComponent) this).getRootPane().getInsets(tempInsets);
163+
if (tempInsets.left != 0 || tempInsets.top != 0)
164+
g.translate(tempInsets.left, tempInsets.top);
165+
// when user has inset the applet -- should clip?
166+
}
167+
return g;
168+
}
158169
if (parent == null) {
159170
return null;
160171
}
161-
Graphics g = parent.getGraphics();
172+
g = parent.getGraphics();
162173
if (g == null)
163174
return null;
164175
// if (g instanceof ConstrainableGraphics) {

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import sun.font.FontDesignMetrics;
7373
import swingjs.JSFocusPeer;
7474
import swingjs.JSGraphics2D;
75+
import swingjs.JSToolkit;
7576
import swingjs.JSUtil;
7677
import swingjs.plaf.JSComponentUI;
7778

@@ -1636,35 +1637,46 @@ public Insets getInsets() {
16361637

16371638
/**
16381639
* Returns an <code>Insets</code> object containing this component's inset
1639-
* values. The passed-in <code>Insets</code> object will be reused if
1640-
* possible. Calling methods cannot assume that the same object will be
1641-
* returned, however. All existing values within this object are overwritten.
1642-
* If <code>insets</code> is null, this will allocate a new one.
1640+
* values. The passed-in <code>Insets</code> object will be reused if possible.
1641+
* Calling methods cannot assume that the same object will be returned, however.
1642+
* All existing values within this object are overwritten. If
1643+
* <code>insets</code> is null, this will allocate a new one.
16431644
*
1644-
* @param insets
1645-
* the <code>Insets</code> object, which can be reused
1645+
* @param insets the <code>Insets</code> object, which can be reused
16461646
* @return the <code>Insets</code> object
16471647
* @see #getInsets
16481648
* @beaninfo expert: true
16491649
*/
1650+
@SuppressWarnings("unused")
16501651
public Insets getInsets(Insets insets) {
1652+
Insets in = null;
16511653
if (insets == null) {
16521654
insets = new Insets(0, 0, 0, 0);
16531655
}
1654-
if (border != null) {
1655-
if (border instanceof AbstractBorder) {
1656-
return ((AbstractBorder) border).getBorderInsets(this, insets);
1656+
if (/** @j2sNative this.isAWT || this.isAWTApplet || */false) {
1657+
// because AWT components do not have this method
1658+
in = getInsets();
1659+
} else {
1660+
if (border == null) {
1661+
// super.getInsets() always returns an Insets object with
1662+
// all of its value zeroed. No need for a new object here.
1663+
insets.left = insets.top = insets.right = insets.bottom = 0;
16571664
} else {
1665+
if (border instanceof AbstractBorder) {
1666+
in = ((AbstractBorder) border).getBorderInsets(this, insets);
1667+
}
16581668
// Can't reuse border insets because the Border interface
16591669
// can't be enhanced.
1660-
return border.getBorderInsets(this);
1670+
in = border.getBorderInsets(this);
16611671
}
1662-
} else {
1663-
// super.getInsets() always returns an Insets object with
1664-
// all of its value zeroed. No need for a new object here.
1665-
insets.left = insets.top = insets.right = insets.bottom = 0;
1666-
return insets;
16671672
}
1673+
if (in != null) {
1674+
insets.left = in.left;
1675+
insets.right = in.right;
1676+
insets.top = in.top;
1677+
insets.bottom = in.bottom;
1678+
}
1679+
return insets;
16681680
}
16691681

16701682
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,11 +1034,12 @@ protected String paramString() {
10341034
return super.paramString();
10351035
}
10361036

1037+
public boolean isAWTApplet = false;
1038+
10371039
@Override
10381040
public Insets getInsets() {
1039-
Container top = getTopLevelAncestor();
1040-
if (top instanceof java.applet.Applet) {
1041-
return top.getInsets();
1041+
if (isAWTApplet) {
1042+
return getTopLevelAncestor().getInsets();
10421043
}
10431044
return super.getInsets();
10441045
}

sources/net.sf.j2s.java.core/src/swingjs/a2s/Applet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public class Applet extends JApplet implements A2SContainer {
1616

1717
public Applet() throws HeadlessException {
1818
super();
19+
getRootPane().isAWTApplet = true;
20+
/**@j2sNative
21+
* this.getContentPane$().isAWTApplet = true;
22+
*/
1923
// Note: applet.paint(g) needs to include super.paint(g), or buttons will not
2024
// show. So we do that in fixAppletPaint().
2125
fixAppletPaint();

0 commit comments

Comments
 (0)