Skip to content

Commit 0d2c6b3

Browse files
authored
Merge pull request #86 from BobHanson/hanson1
Hanson1 - AWT work, primarily
2 parents bfb0088 + 9c7409b commit 0d2c6b3

File tree

88 files changed

+2528
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2528
-757
lines changed
9.1 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190307200127
1+
20190315122942
9.1 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190307200127
1+
20190315122942
9.1 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.awt.HeadlessException;
3434
import java.awt.Image;
3535
import java.awt.JSPanel;
36+
import java.awt.Window;
37+
import java.awt.event.WindowListener;
3638
import java.net.MalformedURLException;
3739
import java.net.URL;
3840
import java.util.Locale;
@@ -94,15 +96,25 @@ public JSApplet() {
9496
* @return true
9597
*/
9698
public boolean isFocusableWindow() {
97-
// mascarading as Window here
99+
// masquerading as Window here
98100
return true;
99101
}
100102

101103
public Dialog getModalBlocker() {
102-
// mascarading as Window here
104+
// masquerading as Window here
103105
return null; //??
104106
}
105107

108+
109+
public void addWindowListener(WindowListener w) {
110+
// from popup
111+
}
112+
public void addOwnedWindow(Window w) {
113+
// from popup
114+
}
115+
116+
void removeOwnedWindow(Window weakWindow) {
117+
}
106118

107119
/**
108120
* Holds the reference to the component which last had focus in this window

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public abstract class Component implements ImageObserver/*
180180
*
181181
* @see #getParent
182182
*/
183-
protected transient Container parent;
183+
public transient Container parent;
184184

185185
/**
186186
* The <code>AppContext</code> of the component. Applets/Plugin may change the
@@ -2385,10 +2385,13 @@ protected Dimension prefSizeComp() {
23852385
Dimension dim = prefSize;
23862386
if (dim == null || !(isPreferredSizeSet() || isValid())) {
23872387
// synchronized (getTreeLock()) {
2388+
2389+
// SwingJS TODO: it is not clear that we should deliver getMinimumSize here.
2390+
//
23882391
prefSize = // (
23892392
// peer != null) ?
23902393
// peer.preferredSize() :
2391-
getMinimumSize();
2394+
(width == 0 && height == 0 ? getMinimumSize() : new Dimension(width, height));
23922395
dim = prefSize;
23932396
}
23942397
// }

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

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ public Insets insets() {
392392
*
393393
*/
394394
public Component add(Component comp) {
395-
return addImpl(comp, null, -1);
395+
addImpl(comp, null, -1);
396+
return comp;
396397
}
397398

398399
/**
@@ -406,7 +407,8 @@ public Component add(Component comp) {
406407
*
407408
*/
408409
public Component add(String name, Component comp) {
409-
return addImpl(comp, name, -1);
410+
addImpl(comp, name, -1);
411+
return comp;
410412
}
411413

412414
/**
@@ -435,7 +437,8 @@ public Component add(String name, Component comp) {
435437
*
436438
*/
437439
public Component add(Component comp, int index) {
438-
return addImpl(comp, null, index);
440+
addImpl(comp, null, index);
441+
return comp;
439442
}
440443

441444
/**
@@ -998,7 +1001,8 @@ public void add(Component comp, Object constraints) {
9981001
*/
9991002

10001003
public Component add(Component comp, Object constraints, int index) {
1001-
return addImpl(comp, constraints, index);
1004+
addImpl(comp, constraints, index);
1005+
return comp;
10021006
}
10031007

10041008
/**
@@ -1062,93 +1066,86 @@ public Component add(Component comp, Object constraints, int index) {
10621066
* @see LayoutManager2
10631067
* @since JDK1.1
10641068
*/
1065-
protected Component addImpl(Component comp, Object constraints, int index) {
1066-
return addImplCont(comp, constraints, index);
1069+
protected void addImpl(Component comp, Object constraints, int index) {
1070+
addImplCont(comp, constraints, index);
10671071
}
10681072

1069-
protected Component addImplCont(Component comp, Object constraints, int index) {
1070-
synchronized (getTreeLock()) {
1071-
1072-
//SwingJS used for all add methods
1073-
1074-
/* Check for correct arguments: index in bounds,
1075-
* comp cannot be one of this container's parents,
1076-
* and comp cannot be a window.
1077-
* comp and container must be on the same GraphicsDevice.
1078-
* if comp is container, all sub-components must be on
1079-
* same GraphicsDevice.
1080-
*/
1073+
protected void addImplCont(Component comp, Object constraints, int index) {
1074+
synchronized (getTreeLock()) {
1075+
1076+
// SwingJS used for all add methods
1077+
1078+
/*
1079+
* Check for correct arguments: index in bounds, comp cannot be one of this
1080+
* container's parents, and comp cannot be a window. comp and container must be
1081+
* on the same GraphicsDevice. if comp is container, all sub-components must be
1082+
* on same GraphicsDevice.
1083+
*/
10811084
// GraphicsConfiguration thisGC = this.getGraphicsConfiguration();
10821085

1083-
if (index > component.size() || (index < 0 && index != -1)) {
1084-
throw new IllegalArgumentException(
1085-
"illegal component position");
1086-
}
1087-
checkAddToSelf(comp);
1088-
// Here we do not allow JSApplet, but we do allow JInternalFrame, which is a JFrame now
1089-
if (comp.isJ2SWindowButNotJInternalFrame()) {
1090-
throw new IllegalArgumentException("adding a window to a container");
1091-
}
1086+
if (index > component.size() || (index < 0 && index != -1)) {
1087+
throw new IllegalArgumentException("illegal component position");
1088+
}
1089+
checkAddToSelf(comp);
1090+
// Here we do not allow JSApplet, but we do allow JInternalFrame, which is a
1091+
// JFrame now
1092+
if (comp.isJ2SWindowButNotJInternalFrame()) {
1093+
throw new IllegalArgumentException("adding a window to a container");
1094+
}
10921095

10931096
// checkNotAWindow(comp);
10941097
// if (thisGC != null) {
10951098
// comp.checkGD(thisGC.getDevice().getIDstring());
10961099
// }
10971100

1098-
/* Reparent the component and tidy up the tree's state. */
1099-
if (comp.parent != null) {
1100-
comp.parent.remove(comp);
1101-
if (index > component.size()) {
1102-
throw new IllegalArgumentException("illegal component position");
1103-
}
1104-
}
1105-
1106-
//index == -1 means add to the end.
1107-
if (index == -1) {
1108-
component.add(comp);
1109-
} else {
1110-
component.add(index, comp);
1111-
}
1112-
_childTainted = true;
1113-
comp.parent = this;
1114-
1115-
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
1116-
comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
1117-
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
1118-
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
1119-
adjustDescendants(comp.countHierarchyMembers());
1120-
1121-
invalidateIfValid();
1122-
if (peer != null) {
1123-
comp.addNotify();
1124-
}
1125-
1126-
/* Notify the layout manager of the added component. */
1127-
if (layoutMgr != null) {
1128-
if (layoutMgr instanceof LayoutManager2) {
1129-
((LayoutManager2)layoutMgr).addLayoutComponent(comp, constraints);
1130-
} else if (constraints instanceof String) {
1131-
layoutMgr.addLayoutComponent((String)constraints, comp);
1132-
}
1133-
}
1134-
if (containerListener != null ||
1135-
(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
1136-
Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
1137-
ContainerEvent e = new ContainerEvent(this,
1138-
ContainerEvent.COMPONENT_ADDED,
1139-
comp);
1140-
dispatchEvent(e);
1141-
}
1142-
1143-
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
1144-
this, HierarchyEvent.PARENT_CHANGED,
1145-
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1146-
if (peer != null && layoutMgr == null && isVisible()) {
1147-
updateCursorImmediately();
1148-
}
1149-
}
1150-
return comp;
1101+
/* Reparent the component and tidy up the tree's state. */
1102+
if (comp.parent != null) {
1103+
comp.parent.remove(comp);
1104+
if (index > component.size()) {
1105+
throw new IllegalArgumentException("illegal component position");
1106+
}
1107+
}
1108+
1109+
// index == -1 means add to the end.
1110+
if (index == -1) {
1111+
component.add(comp);
1112+
} else {
1113+
component.add(index, comp);
1114+
}
1115+
_childTainted = true;
1116+
comp.parent = this;
1117+
1118+
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
1119+
adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
1120+
comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
1121+
adjustDescendants(comp.countHierarchyMembers());
1122+
1123+
invalidateIfValid();
1124+
if (peer != null) {
1125+
comp.addNotify();
1126+
}
1127+
1128+
/* Notify the layout manager of the added component. */
1129+
if (layoutMgr != null) {
1130+
if (layoutMgr instanceof LayoutManager2) {
1131+
((LayoutManager2) layoutMgr).addLayoutComponent(comp, constraints);
1132+
} else if (constraints instanceof String) {
1133+
layoutMgr.addLayoutComponent((String) constraints, comp);
1134+
}
1135+
}
1136+
if (containerListener != null || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0
1137+
|| Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
1138+
ContainerEvent e = new ContainerEvent(this, ContainerEvent.COMPONENT_ADDED, comp);
1139+
dispatchEvent(e);
1140+
}
1141+
1142+
comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp, this, HierarchyEvent.PARENT_CHANGED,
1143+
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
1144+
if (peer != null && layoutMgr == null && isVisible()) {
1145+
updateCursorImmediately();
1146+
}
11511147
}
1148+
}
11521149

11531150

11541151

@@ -1716,9 +1713,9 @@ protected Dimension preferredSizeContainer() {
17161713
Dimension dim = prefSize;
17171714
if (dim == null || !(isPreferredSizeSet() || isValid())) {
17181715
synchronized (getTreeLock()) {
1719-
prefSize = (layoutMgr != null) ?
1716+
prefSize = (layoutMgr != null ?
17201717
layoutMgr.preferredLayoutSize(this) :
1721-
prefSizeComp();
1718+
prefSizeComp());
17221719
dim = prefSize;
17231720
}
17241721
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public class Menu extends swingjs.a2s.Menu {//MenuItem implements MenuContainer,
103103
// */
104104
// private static final long serialVersionUID = -8809584163345499784L;
105105

106-
/**
106+
public boolean isHelpMenu;
107+
108+
/**
107109
* Constructs a new menu with an empty label. This menu is not
108110
* a tear-off menu.
109111
* @exception HeadlessException if GraphicsEnvironment.isHeadless()

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,18 +1022,25 @@ public void dispose() {
10221022
*/
10231023
void disposeImpl() {
10241024
dispose();
1025-
// if (getPeer() != null) {
1026-
// doDispose();
1027-
// }
1025+
if (!_disposed && getPeer() != null) {
1026+
doDispose();
1027+
}
10281028
}
10291029

1030+
private boolean _disposed;
1031+
10301032
void doDispose() {
1031-
final JComponent me = this;
1033+
_disposed = true;
1034+
final Window me = this;
10321035

10331036
Runnable action = new Runnable() {
10341037
@Override
10351038
public void run() {
10361039

1040+
Window parent = getOwner();
1041+
if (parent != null) {
1042+
parent.removeOwnedWindow(me);
1043+
}
10371044
JSComponentUI ui = (JSComponentUI) me.getUI();
10381045
if (ui != null) {
10391046
ui.reinstallUI(me, null);
@@ -2588,8 +2595,6 @@ public void applyResourceBundle(String rbName) {
25882595
void addOwnedWindow(Window weakWindow) {
25892596
if (weakWindow != null) {
25902597
synchronized(ownedWindowList) {
2591-
// this if statement should really be an assert, but we don't
2592-
// have asserts...
25932598
if (!ownedWindowList.contains(weakWindow)) {
25942599
ownedWindowList.addElement(weakWindow);
25952600
}
@@ -3425,14 +3430,12 @@ public void setOpaque(boolean opaque) {
34253430
private static final Color TRANSPARENT_BACKGROUND_COLOR = new Color(0, 0, 0, 0);
34263431

34273432
private static void setLayersOpaque(Component component, boolean isOpaque) {
3428-
// Shouldn't use instanceof to avoid loading Swing classes
3429-
// if it's a pure AWT application.
34303433
if (component instanceof RootPaneContainer) {
34313434
RootPaneContainer rpc = (RootPaneContainer) component;
34323435
JRootPane root = rpc.getRootPane();
34333436
JLayeredPane lp = root.getLayeredPane();
34343437
Container c = root.getContentPane();
3435-
JComponent content = (c instanceof JComponent) ? (JComponent) c : null;
3438+
JComponent content = (c instanceof JComponent ? (JComponent) c : null);
34363439
// JComponent gp = (rpc.getGlassPane() instanceof JComponent) ? (JComponent) rpc
34373440
// .getGlassPane() : null;
34383441
// if (gp != null) {

0 commit comments

Comments
 (0)