Skip to content

Commit 82ab72c

Browse files
committed
modal dialogs
background translucent modal plane added to modal dialogs.
1 parent 00fbabb commit 82ab72c

7 files changed

Lines changed: 62 additions & 48 deletions

File tree

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,13 @@
2727
*/
2828
package java.awt;
2929

30-
//import java.awt.event.ComponentEvent;
31-
//import java.awt.event.HierarchyEvent;
32-
import java.awt.HeadlessException;
33-
import java.util.ArrayList;
34-
import java.util.Iterator;
35-
import java.util.LinkedList;
36-
3730
import java.awt.event.ComponentEvent;
3831
import java.awt.event.HierarchyEvent;
3932
import java.awt.event.WindowEvent;
4033
import java.awt.peer.ComponentPeer;
4134
import java.awt.peer.DialogPeer;
42-
import sun.awt.AppContext;
43-
import sun.awt.PeerEvent;
44-
//import sun.awt.AppContext;
35+
import java.util.ArrayList;
36+
import java.util.Iterator;
4537

4638
/**
4739
* A Dialog is a top-level window with a title and a border
@@ -791,8 +783,7 @@ public boolean isModal() {
791783
return isModal_NoClientCode();
792784
}
793785
final boolean isModal_NoClientCode() {
794-
return dialogCallback != null;
795-
// return modalityType != ModalityType.MODELESS;
786+
return modalityType != ModalityType.MODELESS;
796787
}
797788

798789
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,7 @@ public static void showMessageDialog(Component parentComponent,
720720
*/
721721
public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType,
722722
Icon icon) {
723-
724-
JSComponent.AsynchronousDialogCaller dialogCaller = getDialogCaller(parentComponent, message, false);
723+
JSComponent.AsynchronousDialogCaller dialogCaller = getDialogCaller(parentComponent, message, true);
725724

726725
if (dialogCaller == null) {
727726
/**

sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ public boolean isModalExclusionTypeSupported(
172172

173173
@Override
174174
public boolean isModalityTypeSupported(ModalityType modalityType) {
175-
// TODO Auto-generated method stub
176-
return false;
175+
return true;
177176
}
178177

179178
@Override

sources/net.sf.j2s.java.core/src/swingjs/api/js/DOMNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class DOMNode {
2222
public abstract Rectangle getBoundingClientRect();
2323

2424

25-
public static DOMNode createElement(String key, String id, Object... attrs) {
25+
public static DOMNode createElement(String key, String id) {
2626
DOMNode node = null;
2727
/**
2828
* adding __CLASS_NAME__ allows a node to be used as a parameter in an overloaded method
@@ -34,7 +34,7 @@ public static DOMNode createElement(String key, String id, Object... attrs) {
3434
*/
3535
{
3636
}
37-
return setAttrs(node, attrs);
37+
return node;
3838
}
3939

4040
public static DOMNode createTextNode(String text) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,21 +1959,22 @@ public void notifyFocus(boolean focusGained) {
19591959

19601960
public int getZIndex(String what) {
19611961
@SuppressWarnings("unused")
1962-
Component c = this.c;
1962+
DOMNode node = domNode;
19631963
int z = 0;
19641964
/**
1965-
* looking for high-level content pane
1965+
* looking for high-level content pane or frame
19661966
*
19671967
* @j2sNative
19681968
*
19691969
* if (what) return this.applet._z[what];
1970-
*
1971-
* while (c && c.style && c.style["z-index"]) { z =
1972-
* c.style["z-index"]; c = c.parentNode; }
1973-
*
1970+
*
1971+
* while (node && !node.style["z-index"])
1972+
* node = node.parentElement;
1973+
* z = parseInt(node.style["z-index"]);
1974+
* return(!z || isNaN(z) ? 100000 : z);
19741975
*/
19751976
{
1976-
return (z == 0 ? 100000 : z);
1977+
return z;
19771978
}
19781979
}
19791980

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@
66
import java.awt.peer.DialogPeer;
77

88
import javax.swing.JComponent;
9+
import javax.swing.JDialog;
910
import javax.swing.JFrame;
1011
import javax.swing.LookAndFeel;
1112

1213

1314
public class JSDialogUI extends JSFrameUI implements DialogPeer {
1415

15-
// These dialogs are not modal.
16-
// Someday, perhaps, HTML5 will implement broadly the <dialog> element,
17-
// but for now that is not the case, and we can only do modal dialogs
18-
// using alert(), prompt(), and confirm(). For these we use JOptionPane
19-
// and no peer or ui.
2016
//
2117
// a frame without min/max buttons
2218

2319
// uses Frame.updateDOMNode()
2420

25-
private boolean isModal;
26-
2721
public JSDialogUI() {
28-
isModal = true;
2922
z = frameZ + 500;
23+
zModal = z - 1;
3024
isFrame = true;
3125
isDialog = true;
3226
defaultWidth = 500;
@@ -37,6 +31,7 @@ public JSDialogUI() {
3731
@Override
3832
public void installUI(JComponent jc) {
3933
frame = (JFrame) c;
34+
isModal = ((JDialog) c).isModal();
4035
LookAndFeel.installColors(jc,
4136
"Frame.background",
4237
"Frame.foreground");

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

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package swingjs.plaf;
22

33
import javajs.api.JSFunction;
4+
5+
import java.awt.Color;
6+
import java.awt.Dimension;
47
import java.awt.Insets;
58
import java.awt.Rectangle;
69
import java.awt.Toolkit;
@@ -12,6 +15,7 @@
1215
import javax.swing.JComponent;
1316
import javax.swing.JFrame;
1417
import javax.swing.LookAndFeel;
18+
import javax.swing.SwingUtilities;
1519

1620
import swingjs.JSUtil;
1721
import swingjs.api.js.DOMNode;
@@ -40,6 +44,11 @@ public class JSFrameUI extends JSWindowUI implements FramePeer {
4044
private int state;
4145
private boolean resizeable;
4246
private DOMNode closerWrap;
47+
protected boolean isModal;
48+
private DOMNode modalNode;
49+
protected int zModal;
50+
51+
4352

4453
public JSFrameUI() {
4554
frameZ += 1000;
@@ -58,11 +67,11 @@ public JSFrameUI() {
5867
@Override
5968
protected DOMNode updateDOMNode() {
6069
if (domNode == null) {
61-
// we have to give it some sort of border, or it blends in with the page too much.
70+
// we have to give it some sort of border, or it blends in with the
71+
// page too much.
6272
// a Windows applet has a sort of fuzzy shadowy border
6373
domNode = frameNode = newDOMObject("div", id + "_frame");
64-
DOMNode.setStyles(frameNode, "box-shadow",
65-
"0px 0px 10px gray", "box-sizing", "content-box");
74+
DOMNode.setStyles(frameNode, "box-shadow", "0px 0px 10px gray", "box-sizing", "content-box");
6675
setWindowClass(frameNode);
6776
int w = c.getWidth();
6877
int h = c.getHeight();
@@ -76,37 +85,43 @@ protected DOMNode updateDOMNode() {
7685
setJ2sMouseHandler(frameNode);
7786
titleBarNode = newDOMObject("div", id + "_titlebar");
7887
DOMNode.setPositionAbsolute(titleBarNode, 0, 0);
79-
DOMNode.setStyles(titleBarNode, "background-color", "#E0E0E0", "height",
80-
"20px", "font-size", "14px", "font-family", "sans-serif",
81-
"font-weight", "bold"// ,
88+
DOMNode.setStyles(titleBarNode, "background-color", "#E0E0E0", "height", "20px", "font-size", "14px",
89+
"font-family", "sans-serif", "font-weight", "bold"// ,
8290
// "border-style", "solid",
8391
// "border-width", "1px"
84-
);
92+
);
8593

8694
titleNode = newDOMObject("label", id + "_title");
8795
DOMNode.setPositionAbsolute(titleNode, 2, 4);
8896
DOMNode.setStyles(titleNode, "height", "20px");
8997

90-
9198
closerWrap = newDOMObject("div", id + "_closerwrap");
9299
DOMNode.setPositionAbsolute(closerWrap, 0, 0);
93100
DOMNode.setStyles(closerWrap, "text-align", "right");
94101

95102
closerNode = newDOMObject("label", id + "_closer", "innerHTML", "X");
96-
DOMNode.setStyles(closerNode, "width", "20px", "height", "20px",
97-
"position", "absolute", "text-align", "center", "right", "0px");
98-
DOMNode.addJqueryHandledEvent(this, closerNode,
99-
"click mouseenter mouseout");
103+
DOMNode.setStyles(closerNode, "width", "20px", "height", "20px", "position", "absolute", "text-align",
104+
"center", "right", "0px");
105+
DOMNode.addJqueryHandledEvent(this, closerNode, "click mouseenter mouseout");
100106

101107
frameNode.appendChild(titleBarNode);
102108

109+
if (isModal) {
110+
modalNode = DOMNode.createElement("div", id + "_modaldiv");
111+
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
112+
DOMNode.setStyles(modalNode, "background", toCSSString(new Color(100, 100, 100, 100)));
113+
DOMNode.setPositionAbsolute(modalNode, 0, 0);
114+
DOMNode.setSize(modalNode, screen.width, screen.height);
115+
}
103116
// we have to wait until the frame is wrapped.
104117
@SuppressWarnings("unused")
105118
DOMNode fnode = frameNode;
119+
106120
JSFunction fGetFrameParent = null;
107121
/**
108122
* @j2sNative var me = this; fGetFrameParent =
109-
* function(){me.notifyFrameMoved();return $(fnode).parent()}
123+
* function(){me.notifyFrameMoved();return
124+
* $(fnode).parent()}
110125
*/
111126
{
112127
}
@@ -116,8 +131,8 @@ protected DOMNode updateDOMNode() {
116131
closerWrap.appendChild(closerNode);
117132
Insets s = getInsets();
118133
DOMNode.setPositionAbsolute(frameNode, 0, 0);
119-
DOMNode.setAttrs(frameNode, "width", "" + frame.getWidth() + s.left
120-
+ s.right, "height", "" + frame.getHeight() + s.top + s.bottom);
134+
DOMNode.setAttrs(frameNode, "width", "" + frame.getWidth() + s.left + s.right, "height",
135+
"" + frame.getHeight() + s.top + s.bottom);
121136
containerNode = frameNode;
122137
}
123138
String strColor = toCSSString(c.getBackground());
@@ -272,4 +287,18 @@ public void propertyChange(PropertyChangeEvent e) {
272287
}
273288

274289

290+
@Override
291+
public void setVisible(boolean b) {
292+
super.setVisible(b);
293+
if (isModal) {
294+
if (b) {
295+
$(body).after(modalNode);
296+
int z = getZIndex(null) - 1;
297+
DOMNode.setStyles(modalNode, "z-index", "" + z);
298+
}
299+
DOMNode.setVisible(modalNode, b);
300+
}
301+
302+
}
303+
275304
}

0 commit comments

Comments
 (0)