Skip to content

Commit 667f8e2

Browse files
committed
JOptionPane, JColorChooser implemented
1 parent 82ab72c commit 667f8e2

16 files changed

Lines changed: 5445 additions & 1009 deletions

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,16 @@ public static enum ModalExclusionType {
299299
*/
300300
transient volatile boolean isInDispose = false;
301301

302-
private JSComponent.AsynchronousDialogCaller dialogCallback;
303-
304-
public void setDialogCallback(JSComponent.AsynchronousDialogCaller callback) {
305-
dialogCallback = callback;
306-
}
307-
308302
private static final String base = "dialog";
309303
private static int nameCounter = 0;
310304

305+
/**
306+
* in JavaScript, the initial return to indicate that the real return will go to caller.onDialogReturn(int)
307+
*/
308+
public static final int ASYNCHRONOUS_DEFERRED = Integer.MIN_VALUE;
309+
310+
311+
311312
/*
312313
* JDK 1.1 serialVersionUID
313314
*/

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

Lines changed: 113 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
package java.awt;
2929

3030
import java.awt.peer.ComponentPeer;
31+
import java.beans.PropertyChangeEvent;
32+
import java.beans.PropertyChangeListener;
3133

3234
import javax.swing.JComponent;
3335
import javax.swing.UIDefaults;
@@ -48,13 +50,24 @@
4850
*/
4951
public abstract class JSComponent extends Component {
5052

51-
public interface AsynchronousDialogCaller {
52-
public void onDialogReturn(Object value);
53-
public void onDialogReturn(int value);
54-
}
55-
56-
public interface AsynchronousDialogMessage {
57-
public AsynchronousDialogCaller getCaller(int value);
53+
/**
54+
* For modal dialogs, make sure the parent component, if there is one, is a
55+
* PropertyChangeListener for this component (JOptionPane, JFileChooser, or
56+
* JColorChooser)
57+
*
58+
* @param c
59+
* @param listener
60+
*/
61+
public static void ensurePropertyChangeListener(Component c, Component listener) {
62+
if (listener instanceof PropertyChangeListener) {
63+
// BH SwingJS: We remove, then add, the parentComponent.
64+
// If it is not really a listener, there will be a notification
65+
c.removePropertyChangeListener((PropertyChangeListener) listener);
66+
c.addPropertyChangeListener((PropertyChangeListener) listener);
67+
} else if (listener != null) {
68+
System.err.println(
69+
"JSComponent: " + listener + " is not a PropertyChangeListener -- modal dialog will fail.");
70+
}
5871
}
5972

6073
/**
@@ -63,31 +76,31 @@ public interface AsynchronousDialogMessage {
6376
*
6477
*/
6578

66-
public String htmlName;
79+
public String htmlName;
6780
protected int num;
6881
private static int incr;
6982

7083
public boolean isRootPane, isContentPane;
7184
public HTML5Canvas canvas;
7285
public JSAppletViewer appletViewer = ((JSAppletThread) Thread.currentThread()).appletViewer;
73-
private JSFrameViewer frameViewer;
86+
private JSFrameViewer frameViewer;
7487

75-
public JSComponent() {
76-
super();
77-
num = ++incr;
78-
}
88+
public JSComponent() {
89+
super();
90+
num = ++incr;
91+
}
7992

8093
/**
8194
*
8295
* For SwingJS, we have the graphics without needing to get it from a peer.
83-
* Creates a canvas and graphics context for this component's window or applet
84-
* at the Applet or Frame level.
96+
* Creates a canvas and graphics context for this component's window or
97+
* applet at the Applet or Frame level.
8598
*
8699
*/
87100
@Override
88101
public Graphics getGraphics() {
89102
if (width == 0 || height == 0 || !isVisible())
90-
return null;
103+
return null;
91104
if (frameViewer != null)
92105
return frameViewer.getGraphics(0, 0).create();
93106
if (parent == null) {
@@ -96,66 +109,58 @@ public Graphics getGraphics() {
96109
Graphics g = parent.getGraphics();
97110
if (g == null)
98111
return null;
99-
// if (g instanceof ConstrainableGraphics) {
100-
// ((ConstrainableGraphics) g).constrain(x, y, width, height);
101-
// } else {
102-
g.translate(x, (isContentPane ? 0 : y));
103-
g.setClip(0, 0, width, height);
104-
// }
112+
// if (g instanceof ConstrainableGraphics) {
113+
// ((ConstrainableGraphics) g).constrain(x, y, width, height);
114+
// } else {
115+
g.translate(x, (isContentPane ? 0 : y));
116+
g.setClip(0, 0, width, height);
117+
// }
105118
g.setFont(getFont());
106119
return g;
107120
}
108121

109-
public JSFrameViewer setFrameViewer(JSFrameViewer viewer) {
110-
return frameViewer = (viewer == null ? viewer = new JSFrameViewer()
111-
.setForWindow((Container) this) : viewer);
122+
public JSFrameViewer setFrameViewer(JSFrameViewer viewer) {
123+
return frameViewer = (viewer == null ? viewer = new JSFrameViewer().setForWindow((Container) this) : viewer);
112124
}
113-
125+
114126
private JSFrameViewer topFrameViewer;
115-
116-
public JSFrameViewer getFrameViewer() {
117-
JSComponent parent = null;
118-
return (topFrameViewer != null ? topFrameViewer
119-
: frameViewer != null ? topFrameViewer = frameViewer
120-
: (parent = getParent()) == null ? null
121-
: (topFrameViewer = parent.getFrameViewer()));
122-
}
123-
124-
public String getHTMLName(String uid) {
125-
return (htmlName == null ? htmlName = appContext.getThreadGroup().getName()
126-
+ "_" + uid + "_" + num : htmlName);
127-
}
127+
128+
public JSFrameViewer getFrameViewer() {
129+
JSComponent parent = null;
130+
return (topFrameViewer != null ? topFrameViewer
131+
: frameViewer != null ? topFrameViewer = frameViewer
132+
: (parent = getParent()) == null ? null : (topFrameViewer = parent.getFrameViewer()));
133+
}
134+
135+
public String getHTMLName(String uid) {
136+
return (htmlName == null ? htmlName = appContext.getThreadGroup().getName() + "_" + uid + "_" + num : htmlName);
137+
}
128138

129139
public ComponentUI ui;
130-
131-
132-
public String uiClassID = "ComponentUI";
133140

141+
public String uiClassID = "ComponentUI";
134142

135-
/**
136-
* Returns the <code>UIDefaults</code> key used to
137-
* look up the name of the <code>swing.plaf.ComponentUI</code>
138-
* class that defines the look and feel
139-
* for this component. Most applications will never need to
140-
* call this method. Subclasses of <code>JComponent</code> that support
141-
* pluggable look and feel should override this method to
142-
* return a <code>UIDefaults</code> key that maps to the
143-
* <code>ComponentUI</code> subclass that defines their look and feel.
144-
*
145-
* @return the <code>UIDefaults</code> key for a
146-
* <code>ComponentUI</code> subclass
147-
* @see UIDefaults#getUI
148-
* @beaninfo
149-
* expert: true
150-
* description: UIClassID
151-
*/
143+
/**
144+
* Returns the <code>UIDefaults</code> key used to look up the name of the
145+
* <code>swing.plaf.ComponentUI</code> class that defines the look and feel
146+
* for this component. Most applications will never need to call this
147+
* method. Subclasses of <code>JComponent</code> that support pluggable look
148+
* and feel should override this method to return a <code>UIDefaults</code>
149+
* key that maps to the <code>ComponentUI</code> subclass that defines their
150+
* look and feel.
151+
*
152+
* @return the <code>UIDefaults</code> key for a <code>ComponentUI</code>
153+
* subclass
154+
* @see UIDefaults#getUI
155+
* @beaninfo expert: true description: UIClassID
156+
*/
152157
public String getUIClassID() {
153-
return uiClassID;
154-
}
158+
return uiClassID;
159+
}
155160

156161
/**
157-
* a version of setUI for objects that are not JComponents
158-
* (JDialog, JFrame, JWindow).
162+
* a version of setUI for objects that are not JComponents (JDialog, JFrame,
163+
* JWindow).
159164
*
160165
* @param ui
161166
*/
@@ -169,47 +174,45 @@ public void setUI(ComponentUI ui) {
169174
}
170175

171176
public ComponentUI getUI() {
172-
return ui;
173-
}
174-
177+
return ui;
178+
}
179+
175180
Boolean peerVis;
176-
177-
@Override
181+
182+
@Override
178183
protected void updatePeerVisibility(boolean isVisible) {
179-
// check for visibility set prior to creation of ui.
180-
if (getOrCreatePeer() == null)
181-
peerVis = (isVisible ? Boolean.TRUE : Boolean.FALSE);
182-
else
183-
updatePeerVisibilityOrig(isVisible);
184-
}
184+
// check for visibility set prior to creation of ui.
185+
if (getOrCreatePeer() == null)
186+
peerVis = (isVisible ? Boolean.TRUE : Boolean.FALSE);
187+
else
188+
updatePeerVisibilityOrig(isVisible);
189+
}
185190

186-
/**
191+
/**
187192
* A peer in SwingJS can only be created after the ui is created.
188193
*/
189194
@Override
190195
protected ComponentPeer getOrCreatePeer() {
191-
return (ui == null ? null : ui == null ? null : peer == null ? (peer = getToolkit().createComponent(this)) : peer);
192-
}
196+
return (ui == null ? null
197+
: ui == null ? null : peer == null ? (peer = getToolkit().createComponent(this)) : peer);
198+
}
193199

194-
195-
/**
196-
* Run once for every component. Resets the UI property to a value from the current look and
197-
* feel.
198-
*
199-
* @see JComponent#updateUI
200-
*/
201-
public void updateUI() {
202-
if (ui == null)
203-
setUI(UIManager.getUI(this));
204-
}
205-
206-
/**
207-
* not totally successful;
208-
* triggered for images, background, and fillBox
209-
*
210-
*/
211-
public boolean isBackgroundPainted;
212-
200+
/**
201+
* Run once for every component. Resets the UI property to a value from the
202+
* current look and feel.
203+
*
204+
* @see JComponent#updateUI
205+
*/
206+
public void updateUI() {
207+
if (ui == null)
208+
setUI(UIManager.getUI(this));
209+
}
210+
211+
/**
212+
* not totally successful; triggered for images, background, and fillBox
213+
*
214+
*/
215+
public boolean isBackgroundPainted;
213216

214217
protected JSGraphics2D getJSGraphic2D(Graphics g) {
215218
/**
@@ -218,17 +221,17 @@ protected JSGraphics2D getJSGraphic2D(Graphics g) {
218221
* return (g.mark ? g : null);
219222
*/
220223
{
221-
return null;
224+
return null;
222225
}
223226
}
224227

225-
/**
226-
* This method is added to ensure that if a jpanel or other object's background
227-
* is painted to, that it becomes transparent -- since the actual painting is
228-
* not to this canvas but instead to the JRootPane canvas.
229-
*
230-
* @param jsg
231-
*/
228+
/**
229+
* This method is added to ensure that if a jpanel or other object's
230+
* background is painted to, that it becomes transparent -- since the actual
231+
* painting is not to this canvas but instead to the JRootPane canvas.
232+
*
233+
* @param jsg
234+
*/
232235
public void checkBackgroundPainted(JSGraphics2D jsg) {
233236
if (jsg == null) {
234237
isBackgroundPainted = false;
@@ -242,20 +245,21 @@ public void checkBackgroundPainted(JSGraphics2D jsg) {
242245
((JComponent) this).getRootPane().getUI().setBackgroundPainted();
243246
}
244247
}
245-
248+
246249
public boolean selfOrParentBackgroundPainted() {
247250
JSComponent c = this;
248251
while (c != null) {
249252
if (c.isBackgroundPainted)
250-
return true;
253+
return true;
251254
c = (JSComponent) c.getParent();
252255
}
253256
return false;
254257
}
255258

256-
@Override
259+
@Override
257260
public boolean isBackgroundSet() {
258-
return background != null;//false;// TODO (background != null && !isBackgroundPainted);
259-
}
261+
return background != null;// false;// TODO (background != null &&
262+
// !isBackgroundPainted);
263+
}
260264

261265
}

0 commit comments

Comments
 (0)