Skip to content

Commit 7ee4fcf

Browse files
authored
Merge pull request #90 from BobHanson/hanson1
web page embedding of frames
2 parents dcd65de + c2133ab commit 7ee4fcf

File tree

13 files changed

+154
-91
lines changed

13 files changed

+154
-91
lines changed
839 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190323074004
1+
20190324055304
839 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190323074004
1+
20190324055304
839 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/lang/Thread.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,13 @@ public String toString() {
14761476
*/
14771477
public ClassLoader getContextClassLoader() {
14781478
// here if a static call during load
1479-
return JSUtil.class.getClassLoader();
1479+
ClassLoader cl = JSUtil.class.getClassLoader();
1480+
/**
1481+
* @j2sNative
1482+
*
1483+
* cl.baseClass = {getName$:function(){return "swingjs"}};
1484+
*/
1485+
return cl;
14801486
}
14811487

14821488
/**

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,22 @@
2727
*/
2828
package javax.swing;
2929

30-
import java.awt.HeadlessException;
31-
3230
import java.awt.AWTEvent;
3331
import java.awt.BorderLayout;
3432
import java.awt.Component;
3533
import java.awt.Container;
36-
import java.awt.JSFrame;
3734
import java.awt.Graphics;
3835
import java.awt.Graphics2D;
3936
import java.awt.GraphicsConfiguration;
37+
import java.awt.HeadlessException;
4038
import java.awt.Image;
39+
import java.awt.JSFrame;
4140
import java.awt.LayoutManager;
4241
import java.awt.event.WindowEvent;
4342
//
4443

45-
import swingjs.JSUtil;
46-
import swingjs.plaf.JSComponentUI;
47-
4844
//BH: Added rootPane.addNotify(); // builds a peer for the root pane
45+
//BH: Added ability to embed the frame in a div of the web page.
4946

5047
/**
5148
* An extended version of <code>java.awt.Frame</code> that adds support for
@@ -153,7 +150,8 @@ public class JFrame extends JSFrame implements WindowConstants,
153150
*/
154151
protected JRootPane rootPane;
155152

156-
public void add(Component comp, Object constraints) {
153+
@Override
154+
public void add(Component comp, Object constraints) {
157155
if (comp instanceof JApplet) {
158156
isAppletFrame = true;
159157
((JApplet) comp).getLayeredPane().isFramedApplet = true;
@@ -172,6 +170,8 @@ public void add(Component comp, Object constraints) {
172170
*/
173171
protected boolean rootPaneCheckingEnabled = false;
174172

173+
private boolean _boundsFrozen;
174+
175175
/**
176176
* Constructs a new frame that is initially invisible.
177177
* <p>
@@ -284,6 +284,7 @@ public JFrame(String title, GraphicsConfiguration gc) {
284284
}
285285

286286
public JFrame(Object object, Object object2, Object object3, Object object4) {
287+
// For SwingJS JInternalFrame constructor
287288
}
288289

289290
@Override
@@ -463,6 +464,7 @@ public int getDefaultCloseOperation() {
463464
* @beaninfo bound: true hidden: true description: Mechanism for transfer of
464465
* data into the component
465466
*/
467+
@Override
466468
public void setTransferHandler(TransferHandler newHandler) {
467469
TransferHandler oldHandler = transferHandler;
468470
transferHandler = newHandler;
@@ -479,6 +481,7 @@ public void setTransferHandler(TransferHandler newHandler) {
479481
* @see #setTransferHandler
480482
* @since 1.6
481483
*/
484+
@Override
482485
public TransferHandler getTransferHandler() {
483486
return transferHandler;
484487
}
@@ -914,4 +917,18 @@ protected String paramString() {
914917
+ defaultCloseOperationString + ",rootPane=" + rootPaneString
915918
+ ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
916919
}
920+
921+
public void _freezeBounds(int w, int h) {
922+
setSize(w, h);
923+
_boundsFrozen = true;
924+
resizable = false;
925+
}
926+
927+
@Override
928+
public void reshape(int x, int y, int width, int height) {
929+
if (!_boundsFrozen)
930+
super.reshape(x, y, width, height);
931+
}
932+
933+
917934
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ public JSUtil() {
5656

5757

5858
private static Map<String, Object> getFileCache() {
59-
if (JSUtil.fileCache == null && (JSUtil.fileCache = JSUtil.J2S.getSetJavaFileCache(null)) == null) {
60-
JSUtil.fileCache = new Hashtable<String, Object>();
61-
JSUtil.J2S.getSetJavaFileCache(JSUtil.fileCache);
59+
if (fileCache == null && (fileCache = J2S.getSetJavaFileCache(null)) == null) {
60+
fileCache = new Hashtable<String, Object>();
61+
J2S.getSetJavaFileCache(fileCache);
6262
}
63-
return JSUtil.fileCache;
63+
return fileCache;
6464
}
6565

6666
private static Object getCachedFileData(String path) {
67-
return (JSUtil.useCache && JSUtil.fileCache != null ?
68-
JSUtil.fileCache.get(path) : null);
67+
return (useCache && fileCache != null ?
68+
fileCache.get(path) : null);
6969
}
7070

7171
/**
@@ -105,7 +105,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes) {
105105
data = (asBytes ? Rdr.getStreamAsBytes(stream, null) : Rdr.streamToUTF8String(stream));
106106
} catch (Exception e) {
107107
// bypasses AjaxURLConnection
108-
data = JSUtil.J2S.getFileData(uri, null, false, asBytes);
108+
data = J2S.getFileData(uri, null, false, asBytes);
109109
}
110110
}
111111
return data;
@@ -120,7 +120,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes) {
120120
*/
121121
public static String getFileAsString(String filename) {
122122
Object data = getFileContents(filename, false);
123-
return JSUtil.ensureString(data);
123+
return ensureString(data);
124124
}
125125

126126
public static byte[] getFileAsBytes(Object file, boolean checkNotFound) {
@@ -167,7 +167,7 @@ else if (data instanceof InputStream)
167167
}
168168

169169
public static boolean haveCachedResource(String resourceName, boolean isJavaPath) {
170-
String path = JSUtil.J2S.getResourcePath(resourceName, isJavaPath);
170+
String path = J2S.getResourcePath(resourceName, isJavaPath);
171171
return (path != null && getCachedFileData(path) != null);
172172
}
173173

@@ -192,14 +192,14 @@ public static String getJavaResource(String resourceName, boolean isJavaPath,
192192
if (data == null
193193
&& (data = J2S.getFileData(path, null, false, false)) != null
194194
&& useCache && doCache)
195-
JSUtil.cacheFileData(path, data);
196-
String sdata = JSUtil.ensureString(data);
195+
cacheFileData(path, data);
196+
String sdata = ensureString(data);
197197
boolean ok = (sdata != null && sdata.indexOf("[Exception") != 0);
198198
System.out.println("Processing " + path + " ["
199199
+ (ok ? "" + sdata.length() : sdata) + "]");
200200
return (!ok ? null : !doProcess ? sdata
201-
: path.endsWith(".css") ? JSUtil.processCSS(sdata, path) : path
202-
.endsWith(".js") ? JSUtil.processJS(sdata, resourceName) : sdata);
201+
: path.endsWith(".css") ? processCSS(sdata, path) : path
202+
.endsWith(".js") ? processJS(sdata, resourceName) : sdata);
203203
}
204204

205205
static void cacheFileData(String path, Object data) {
@@ -224,7 +224,7 @@ public static void loadJavaResourcesFromZip(ClassLoader cl, String zipFileName,
224224
try {
225225
BufferedInputStream bis = new BufferedInputStream(cl.getResourceAsStream(zipFileName));
226226
String prefix = J2S.getResourcePath(null, true); // will end with /
227-
fileList = JSUtil.getZipTools().cacheZipContentsStatic(bis, prefix, mapByteData, false);
227+
fileList = getZipTools().cacheZipContentsStatic(bis, prefix, mapByteData, false);
228228
} catch (Exception e) {
229229
System.out.println("JSUtil could not cache files from " + zipFileName);
230230
return;
@@ -260,7 +260,7 @@ static String processCSS(String css, String path) {
260260
path = path.substring(0, path.lastIndexOf("/") + 1) + "images/";
261261
css = PT.rep(css, "images/", path);
262262
}
263-
JSUtil.jQuery.$("head").append(JSUtil.jQuery.$("<style type='text/css'>" + css + "</style>"));
263+
jQuery.$("head").append(jQuery.$("<style type='text/css'>" + css + "</style>"));
264264
return css;
265265
}
266266

@@ -276,7 +276,7 @@ static String processJS(String js, String resourceName) {
276276
*/
277277
{}
278278
} catch (Throwable e) {
279-
JSUtil.alert("error processing " + js);
279+
alert("error processing " + js);
280280
return null;
281281
}
282282
return js;
@@ -348,8 +348,8 @@ public static String getStackTrace() {
348348
*/
349349
public static void notImplemented(String msg) {
350350
String s = null;
351-
if (JSUtil.mapNotImpl == null)
352-
JSUtil.mapNotImpl = new Hashtable<String, Boolean>();
351+
if (mapNotImpl == null)
352+
mapNotImpl = new Hashtable<String, Boolean>();
353353
/**
354354
* @j2sNative
355355
*
@@ -360,9 +360,9 @@ public static void notImplemented(String msg) {
360360
*/
361361
{
362362
}
363-
if (JSUtil.mapNotImpl.containsKey(s))
363+
if (mapNotImpl.containsKey(s))
364364
return;
365-
JSUtil.mapNotImpl.put(s, Boolean.TRUE);
365+
mapNotImpl.put(s, Boolean.TRUE);
366366
System.out.println(s + " has not been implemented in SwingJS. "
367367
+ (msg == "" ? "" : (msg == null ? "" : msg) + getStackTrace(-5)));
368368

@@ -509,7 +509,7 @@ public static void showWebPage(URL url, Object target) {
509509
* @param msg
510510
*/
511511
public static void warn(String msg) {
512-
JSUtil.alert(msg);
512+
alert(msg);
513513
}
514514

515515
/**

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ protected void setMnemonic(int newValue) {
13471347

13481348
private boolean ignoreFocus;
13491349

1350+
protected DOMNode embeddingNode;
13501351

13511352
/**
13521353
* we can allow frames -- particularly JInternalFrames in a JDesktopFrame -- to overflow.
@@ -1704,7 +1705,7 @@ protected DOMNode setHTMLElementCUI() {
17041705
// If the applet's root pane, we insert it into the applet's
17051706
// content
17061707
DOMNode cdiv = swingjs.JSToolkit.getHTML5Applet(jc)._getContentLayer();
1707-
DOMNode.appendChildSafely(cdiv, outerNode);
1708+
DOMNode.appendChildSafely(cdiv, outerNode);
17081709
}
17091710
}
17101711
}
@@ -1716,6 +1717,9 @@ protected DOMNode setHTMLElementCUI() {
17161717
}
17171718
}
17181719
isTainted = false;
1720+
1721+
if (embeddingNode != null)
1722+
DOMNode.appendChildSafely(embeddingNode, outerNode);
17191723
return outerNode;
17201724
}
17211725

@@ -1763,7 +1767,8 @@ protected void addChildrenToDOM(Component[] children, int n) {
17631767
} else {
17641768
if (ui.domNode != ui.outerNode && DOMNode.getParent(ui.domNode) == null)
17651769
appendChild(ui.outerNode, ui.domNode);
1766-
DOMNode.appendChildSafely(containerNode, ui.outerNode);
1770+
if (ui.embeddingNode == null)
1771+
DOMNode.appendChildSafely(containerNode, ui.outerNode);
17671772
}
17681773
}
17691774
}
@@ -2128,7 +2133,7 @@ public void setBounds(int x, int y, int width, int height, int op) {
21282133
case SET_LOCATION:
21292134
x = c.getX();
21302135
y = c.getY();
2131-
if (this.x != x || this.y != y) {
2136+
if (embeddingNode == null && (this.x != x || this.y != y)) {
21322137
this.x = x;
21332138
this.y = y;
21342139
}
@@ -2192,15 +2197,17 @@ private ImageIcon getIcon(JSComponent c, Icon icon) {
21922197

21932198
/**
21942199
* remove 0x0000 and replace space with nonbreaking space if not a textarea
2200+
*
21952201
* @param t
21962202
* @return
21972203
*/
21982204
protected String fixText(String t) {
2199-
t = (t != null && t.indexOf("\u0000") >= 0 ? PT.rep(t, "\u0000", "") : t);
2200-
if (isHTML) {
2201-
//
2202-
} else if (valueNode == null) {
2203-
t = t.replace(' ', '\u00A0');
2205+
if (t != null) {
2206+
if (isHTML) {
2207+
//
2208+
} else if (valueNode == null) {
2209+
t = (t.indexOf("\u0000") >= 0 ? PT.rep(t, "\u0000", "") : t).replace(' ', '\u00A0');
2210+
}
22042211
}
22052212
return t;
22062213
}

0 commit comments

Comments
 (0)