Skip to content

Commit 8b564dd

Browse files
committed
Window as JSComponent
1 parent 753f1e0 commit 8b564dd

File tree

8 files changed

+60
-27
lines changed

8 files changed

+60
-27
lines changed
-119 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/doc/Differences.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Notes
22
=====
3+
updaetd 6/28/18 -- arrays do not inherit Object
34
updated 2/26/18
45
updated 6/5/17 -- reserved package name "window"
56
updated 3/11/17 -- myClass.getField
67
updated 3/7/17 -- overloading of JSplitPane.setDividerLocation
78
updated 3/2/17 -- more indication of classes not implemented (KeyListener)
89

910
=============================================================================
10-
SwingJS and JDK 1.6
11+
SwingJS and JDK 1.6+
1112
=============================================================================
1213

1314
SwingJS implements a wide range of the Java language in JavaScript. The base
@@ -56,12 +57,21 @@ Threads
5657
Although there is only a single thread in JavaScript, meaning Thread.wait(), Thread.sleep(int) and
5758
Thread.notify() cannot be reproduced, we have found that this is not a serious limitation.
5859
For example, javax.swing.Timer() works perfectly in JavaScript. All it means is that threads
59-
that use sleep(int) or notify() must be refectored to allow Timer-like callbacks. That is,
60+
that use sleep(int) or notify() must be refactored to allow Timer-like callbacks. That is,
6061
they must allow full exit and re-entry of Thread.run(), not the typical while/sleep motif.
6162

6263
The key is to create a state-based run() that can be exited and re-entered in JavaScript.
6364

6465

66+
Modal Dialogs
67+
-------------
68+
69+
Although true modal dialogs are not possible with only one thread, a functional equivalent --
70+
asynchronous modal dialogs -- is relatively easy to set up. All the JOptionPane dialogs will
71+
return PropertyChangeEvents to signal that they have been disposed of and containing the results.
72+
More on this later....
73+
74+
6575

6676
No Non-Swing AWT Components
6777
---------------------------
@@ -163,13 +173,14 @@ JTabbedPane (in development, NEM)
163173
MINOR ISSUES--required some rewriting/refactoring by Bob and Udo
164174
================================================================
165175

166-
java.util.BitSet must be 16-bit
176+
java.util.BitSet is implemented using 16-bit integers, not 32
167177
Thread.currentThread() == dispatchThread
168178

169179

170180
MINOR ISSUES--requiring some rewriting/refactoring outside of SwingJS
171181
=====================================================================
172182

183+
array.equals(Object) not present -- arrays do not subclass Object
173184
ArrayIndexOutOfBounds
174185
java.awt.Color
175186
native methods
@@ -195,8 +206,9 @@ MAJOR ISSUES--to be resolved by implementers
195206
fonts
196207
specific AWT components not implemented
197208
threads
209+
modal dialogs
198210
image loading
199-
no BigInteger; no BigDecimal
211+
no BigInteger; no BigDecimal
200212
no format internationalization
201213
no winding rules
202214
text-related field implementation
@@ -220,6 +232,12 @@ as it is used to key for AppContexts. We will see if that use useful or not.
220232
PROGRESS
221233
========
222234

235+
6/28/2018
236+
237+
Major bug fixing session in Dundee, Scotland, is finding subtle issues and some missing
238+
classes, mostly because this group is using Java 7+. Generally running very well.
239+
240+
223241
2/26/2018
224242

225243
Relatively full implementation of Java in JavaScript is complete, with all methods

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,8 @@ public synchronized DropTarget getDropTarget() {
962962

963963
public GraphicsConfiguration graphicsConfig;
964964

965+
protected boolean isWindow;
966+
965967
/**
966968
* Gets the <code>GraphicsConfiguration</code> associated with this
967969
* <code>Component</code>. If the <code>Component</code> has not been
@@ -1559,7 +1561,7 @@ public void hide() {
15591561
}
15601562
}
15611563
Container parent = this.parent;
1562-
if (parent != null) {
1564+
if (!isWindow && parent != null) {
15631565
parent.invalidate();
15641566
}
15651567
// }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public Window(Window owner) {
473473
public Window(Window owner, GraphicsConfiguration gc) {
474474
// everything will pass through here, even Window(gc);
475475
// We just adjust for the 1-parameter issue here
476-
initWinGC(owner, gc);
476+
initWinGC(owner, gc);
477477
}
478478

479479
/**
@@ -484,7 +484,8 @@ public Window(Window owner, GraphicsConfiguration gc) {
484484
* @param gc
485485
*/
486486
protected void initWinGC(Window owner, GraphicsConfiguration gc) {
487-
setAppContext();
487+
setAppContext();
488+
isWindow = true;
488489
parent = owner;
489490
if (owner != null)
490491
owner.addOwnedWindow(this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public static Object showInputDialog(Component parentComponent, Object message,
644644

645645
if (!(message instanceof String)) {
646646
warnJSDeveloper();
647-
message = "?";
647+
message = "non-string messages require a PropertyChangeListener in SwingJS";
648648
}
649649

650650
if (!(initialSelectionValue instanceof String)) {

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public synchronized void addInvalidComponent(JComponent invalidComponent) {
350350
//System.out.println("RM noParent");
351351
return;
352352
}
353-
if ((c instanceof JComponent) && (((JComponent) c).isValidateRoot())) {
353+
if (isStandardJComponent(c) && (((JComponent) c).isValidateRoot())) {
354354
validateRoot = c;
355355
break;
356356
}
@@ -412,6 +412,17 @@ public synchronized void addInvalidComponent(JComponent invalidComponent) {
412412
scheduleProcessingRunnable(root);
413413
}
414414

415+
/**
416+
* The deal here is that I added Window to subclass JComponent so that
417+
* JInternalFrame could subclass Frame and still be a JComponent
418+
*
419+
* @param c
420+
* @return
421+
*/
422+
private boolean isStandardJComponent(Component c) {
423+
return (c instanceof JComponent && !(c instanceof Window));
424+
}
425+
415426
/**
416427
* Remove a component from the list of invalid components.
417428
*
@@ -847,7 +858,7 @@ private void paintDirtyRegions1(
847858
int localBoundsW = dirtyComponent.getWidth();
848859
SwingUtilities.computeIntersection(0, 0, localBoundsW, localBoundsH,
849860
rect);
850-
if (dirtyComponent instanceof JComponent && ! (dirtyComponent instanceof Window)) {
861+
if (isStandardJComponent(dirtyComponent)) {
851862
((JComponent) dirtyComponent).paintImmediately(rect.x, rect.y,
852863
rect.width, rect.height);
853864
} else if (dirtyComponent.isShowing()) {
@@ -896,7 +907,7 @@ private void adjustRoots(JComponent root, Lst<Component> roots,
896907
for (int i = roots.size() - 1; i >= index; i--) {
897908
Component c = roots.get(i);
898909
for (;;) {
899-
if (c == root || c == null || !(c instanceof JComponent)) {
910+
if (c == root || c == null || !isStandardJComponent(c)) {
900911
break;
901912
}
902913
c = c.getParent();
@@ -939,7 +950,7 @@ void collectDirtyComponents(Map<Component, Rectangle> dirtyComponents,
939950
}
940951

941952
for (;;) {
942-
if (!(component instanceof JComponent))
953+
if (!isStandardJComponent(component))
943954
break;
944955

945956
parent = component.getParent();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public class JSButtonUI extends JSLightweightUI {
7474
/**
7575
* a wrapper if this is not a menu item
7676
*/
77-
protected DOMNode label;
78-
protected DOMNode itemNode;
77+
protected DOMNode btnLabel;
78+
protected DOMNode itemNode;
7979
protected JMenuItem menuItem;
8080
protected AbstractButton button;
8181

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,23 @@ protected DOMNode updateButton(String myType) {
4848
// if (isNew)
4949
// groupNames.put(bg, name);
5050
// }
51-
domBtn = enableNode = newDOMObject("input", id, "type", myType, "name",
51+
domBtn = newDOMObject("input", id, "type", myType, "name",
5252
name);
5353
iconNode = newDOMObject("span", id + "_icon");
5454
textNode = newDOMObject("label", id + "l1");
55-
label = newDOMObject("label", id + "l2", "htmlFor", id);
56-
setDataComponent(label);
55+
btnLabel = newDOMObject("label", id + "l2", "htmlFor", id);
56+
enableNodes = new DOMNode[] { domBtn, btnLabel };
57+
setDataComponent(btnLabel);
5758
setDataComponent(iconNode); // needed for mac safari/chrome
5859
setDataComponent(domBtn);
5960
setDataComponent(textNode); // needed for mac safari/chrome
6061
setEnabled(c.isEnabled());
6162
if (isMenuItem) {
62-
domNode = createItem("_item", label);
63+
domNode = createItem("_item", btnLabel);
6364
} else {
6465
domNode = newDOMObject("div", id + "_0");
6566
centeringNode = newDOMObject("div", id + "_ctr");
66-
centeringNode.appendChild(label);
67+
centeringNode.appendChild(btnLabel);
6768
domNode.appendChild(centeringNode);
6869
}
6970
}
@@ -104,17 +105,17 @@ protected DOMNode updateButton(String myType) {
104105
DOMNode.setPositionAbsolute(domBtn, Integer.MIN_VALUE, 0);
105106
DOMNode.setPositionAbsolute(iconNode, Integer.MIN_VALUE, 0);
106107
DOMNode.setPositionAbsolute(textNode, Integer.MIN_VALUE, 0);
107-
DOMNode.setPositionAbsolute(label, Integer.MIN_VALUE, 0);
108+
DOMNode.setPositionAbsolute(btnLabel, Integer.MIN_VALUE, 0);
108109

109110
// (Re)create label.
110111
}
111-
label.appendChild(iconNode);
112-
label.appendChild(domBtn);
113-
label.appendChild(textNode);
112+
btnLabel.appendChild(iconNode);
113+
btnLabel.appendChild(domBtn);
114+
btnLabel.appendChild(textNode);
114115
if (doAll && !isMenuItem)
115116
DOMNode.setPositionAbsolute(domNode, Integer.MIN_VALUE, 0);
116117
if (!isMenuItem) {
117-
DOMNode.setSize(label, dobj.width, dobj.height);
118+
DOMNode.setSize(btnLabel, dobj.width, dobj.height);
118119
DOMNode.setSize(centeringNode, dobj.width, dobj.height);
119120
}
120121
return domNode;
@@ -124,7 +125,7 @@ protected DOMNode updateButton(String myType) {
124125
protected Dimension setHTMLSize(DOMNode obj, boolean addCSS) {
125126
// "absolute" is required for positioning of button, but must not be there
126127
// for setting the size.
127-
DOMNode.setStyles(label, "position", null, "width", null, "height", null);
128+
DOMNode.setStyles(btnLabel, "position", null, "width", null, "height", null);
128129
DOMNode.setStyles(domBtn, "position", null, "width", null, "height", null);
129130
DOMNode
130131
.setStyles(textNode, "position", null, "width", null, "height", null);
@@ -135,10 +136,10 @@ protected Dimension setHTMLSize(DOMNode obj, boolean addCSS) {
135136
d = setHTMLSize1(obj, addCSS, false);
136137
DOMNode.setPositionAbsolute(domBtn, Integer.MIN_VALUE, 0);
137138
DOMNode.setPositionAbsolute(textNode, Integer.MIN_VALUE, 0);
138-
DOMNode.setPositionAbsolute(label, Integer.MIN_VALUE, 0);
139+
DOMNode.setPositionAbsolute(btnLabel, Integer.MIN_VALUE, 0);
139140
if (centeringNode != null)
140141
DOMNode.setPositionAbsolute(centeringNode, Integer.MIN_VALUE, 0);
141-
DOMNode.setStyles(label, "width", d.width + "px", "height", d.height
142+
DOMNode.setStyles(btnLabel, "width", d.width + "px", "height", d.height
142143
+ "px");
143144
}
144145
return d;

0 commit comments

Comments
 (0)