diff --git a/sources/net.sf.j2s.core/dist/build-site.xml b/sources/net.sf.j2s.core/dist/build-site.xml index b2d88e2b1..9d013b90b 100644 --- a/sources/net.sf.j2s.core/dist/build-site.xml +++ b/sources/net.sf.j2s.core/dist/build-site.xml @@ -28,9 +28,12 @@ - + + + + @@ -75,6 +78,14 @@ + Copying ${site-resource.dir} files into ${site.dir} + + + + + + + diff --git a/sources/net.sf.j2s.core/dist/resources/README.txt b/sources/net.sf.j2s.core/dist/resources/README.txt index d11b26bad..9c540809b 100644 --- a/sources/net.sf.j2s.core/dist/resources/README.txt +++ b/sources/net.sf.j2s.core/dist/resources/README.txt @@ -2,5 +2,5 @@ SwingJS distribution -- resources directory This directory can be used to hold non-Java files that your program needs to run -- data files, for instance. Files in it will be copied to -the site/ directory by build-site.xml. +the site/swingjs/j2s directory by build-site.xml. diff --git a/sources/net.sf.j2s.core/dist/site-resources/README.txt b/sources/net.sf.j2s.core/dist/site-resources/README.txt new file mode 100644 index 000000000..f43548c13 --- /dev/null +++ b/sources/net.sf.j2s.core/dist/site-resources/README.txt @@ -0,0 +1,6 @@ +SwingJS distribution -- site-resources directory + +This directory can be used to hold non-Java files that your program +needs to run -- data files, for instance. Files in it will be copied to +the site/ directory by build-site.xml. + diff --git a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip index 8e8dca0dc..27d665022 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp index 62f00c015..34c45791d 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20190323074004 +20190326062559 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip index 8e8dca0dc..27d665022 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp index 62f00c015..34c45791d 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp @@ -1 +1 @@ -20190323074004 +20190326062559 diff --git a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java index 01ee29857..456e619f3 100644 --- a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java +++ b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java @@ -67,6 +67,8 @@ class Java2ScriptCompiler { private String siteFolder; + private boolean testing; + private List lstExcludedPaths; private boolean isCleanBuild; @@ -187,6 +189,8 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant lstExcludedPaths = null; } + testing = "true".equals(getProperty("j2s.testing")); + String prop = getProperty("j2s.compiler.nonqualified.packages"); // older version of the name String nonqualifiedPackages = getProperty("j2s.compiler.nonqualified.classes"); @@ -249,7 +253,7 @@ boolean compileToJavaScript(IFile javaSource) { CompilationUnit root = (CompilationUnit) astParser.createAST(null); // If the Java2ScriptVisitor is ever extended, it is important to set the project. // Java2ScriptVisitor#addClassOrInterface uses getClass().newInstance().setproject(project). - Java2ScriptVisitor visitor = new Java2ScriptVisitor().setProject(project); + Java2ScriptVisitor visitor = new Java2ScriptVisitor().setProject(project, testing); try { diff --git a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java index f7428edc1..65761a2fa 100644 --- a/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java +++ b/sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java @@ -198,6 +198,21 @@ public class Java2ScriptVisitor extends ASTVisitor { private IJavaProject global_project; + /** + * multipurpose flag for testing development ideas. + * + */ + private boolean global_testing; + // make private fields properties of p1$ ? + // the problem only shows up with a2s subclasses of Swing components + // because they could declare the same private variable and not get + // caught by the compiler, since they do not subclass that class. + // + // possible issues: + // 1) We may have changed some awt, sun, and javax fields from private to public + // 2) Is there an issue with inner classes referencing outer-class private fields? + + private String package_name; private int package_blockLevel = 0; private int package_currentBlockForVisit = -1; @@ -305,6 +320,7 @@ private Java2ScriptVisitor setInnerGlobals(Java2ScriptVisitor parent, ASTNode no */ private boolean haveDefaultConstructor; + private static IType appletType; public Java2ScriptVisitor() { @@ -318,7 +334,8 @@ public Java2ScriptVisitor() { // } } - public Java2ScriptVisitor setProject(IJavaProject project) { + public Java2ScriptVisitor setProject(IJavaProject project, boolean testing) { + this.global_testing = testing; this.global_project = project; return this; } @@ -1626,7 +1643,7 @@ private void addClassOrInterface(ASTNode node, ITypeBinding binding, List bod Java2ScriptVisitor tempVisitor = null; try { - tempVisitor = getClass().newInstance().setProject(global_project).setInnerGlobals(this, node); + tempVisitor = getClass().newInstance().setProject(global_project, global_testing).setInnerGlobals(this, node); } catch (@SuppressWarnings("unused") Exception e) { // impossible } diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip index 8e8dca0dc..27d665022 100644 Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java b/sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java index 757a7248b..0b3f609cf 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java @@ -180,7 +180,7 @@ public boolean selfOrChildIsPainted() { } - private Insets tempInsets; + private Insets _tempInsets; public JSGraphics2D _gtemp; // indicates that we are painting, so that g.setBackground() should also be set public JSComponent() { @@ -203,11 +203,11 @@ public Graphics getGraphics() { if (frameViewer != null) { g = frameViewer.getGraphics().create(); if (isContentPane) { - if (tempInsets == null) - tempInsets = new Insets(0,0,0,0); - ((JComponent) this).getRootPane().getInsets(tempInsets); - if (tempInsets.left != 0 || tempInsets.top != 0) - g.translate(tempInsets.left, tempInsets.top); + if (_tempInsets == null) + _tempInsets = new Insets(0,0,0,0); + ((JComponent) this).getRootPane().getInsets(_tempInsets); + if (_tempInsets.left != 0 || _tempInsets.top != 0) + g.translate(_tempInsets.left, _tempInsets.top); // when user has inset the applet -- should clip? } return g; diff --git a/sources/net.sf.j2s.java.core/src/java/lang/Thread.java b/sources/net.sf.j2s.java.core/src/java/lang/Thread.java index 747470eee..7fbf9ddd3 100644 --- a/sources/net.sf.j2s.java.core/src/java/lang/Thread.java +++ b/sources/net.sf.j2s.java.core/src/java/lang/Thread.java @@ -1476,7 +1476,13 @@ public String toString() { */ public ClassLoader getContextClassLoader() { // here if a static call during load - return JSUtil.class.getClassLoader(); + ClassLoader cl = JSUtil.class.getClassLoader(); + /** + * @j2sNative + * + * cl.baseClass = {getName$:function(){return "swingjs"}}; + */ + return cl; } /** diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java b/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java index 6e3a3c038..0f26e9c3a 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java @@ -201,11 +201,13 @@ public abstract class JComponent extends Container { /* * The following fields support set methods for the corresponding * java.awt.Component properties. + * + * SwingJS */ - private boolean isAlignmentXSet; - private float alignmentX; - private boolean isAlignmentYSet; - private float alignmentY; + private boolean _isAlignmentXSet; + private float _alignmentX; + private boolean _isAlignmentYSet; + private float _alignmentY; /** * Backing store for JComponent properties and listeners @@ -220,9 +222,9 @@ public abstract class JComponent extends Container { /** * Whether or not autoscroll has been enabled. */ - private boolean autoscrolls; - private Border border; - private int flags; + private boolean _autoscrolls; + private Border _border; + private int _flags; /* Input verifier for this component */ // private InputVerifier inputVerifier = null; @@ -285,7 +287,7 @@ public abstract class JComponent extends Container { /** * JPopupMenu assigned to this component and all of its childrens */ - private JPopupMenu popupMenu; + private JPopupMenu _popupMenu; /** Private flags **/ private static final int IS_DOUBLE_BUFFERED = 0; @@ -323,7 +325,7 @@ public abstract class JComponent extends Container { /** * Temporary rectangles. */ - private static Lst tempRectangles = new Lst(); + private static Lst _tempRect = new Lst(); /** Used for WHEN_FOCUSED bindings. */ private InputMap focusInputMap; @@ -420,11 +422,11 @@ static Set getManagingFocusBackwardTraversalKeys() { } private static Rectangle fetchRectangle() { - synchronized (tempRectangles) { + synchronized (_tempRect) { Rectangle rect; - int size = tempRectangles.size(); + int size = _tempRect.size(); if (size > 0) { - rect = (Rectangle) tempRectangles.removeItemAt(size - 1); + rect = (Rectangle) _tempRect.removeItemAt(size - 1); } else { rect = new Rectangle(0, 0, 0, 0); } @@ -433,8 +435,8 @@ private static Rectangle fetchRectangle() { } private static void recycleRectangle(Rectangle rect) { - synchronized (tempRectangles) { - tempRectangles.addLast(rect); + synchronized (_tempRect) { + _tempRect.addLast(rect); } } @@ -496,8 +498,8 @@ public void setComponentPopupMenu(JPopupMenu popup) { if (popup != null) { enableEvents(AWTEvent.MOUSE_EVENT_MASK); } - JPopupMenu oldPopup = this.popupMenu; - this.popupMenu = popup; + JPopupMenu oldPopup = this._popupMenu; + this._popupMenu = popup; firePropertyChange("componentPopupMenu", oldPopup, popup); } @@ -516,10 +518,10 @@ public void setComponentPopupMenu(JPopupMenu popup) { public JPopupMenu getComponentPopupMenu() { if (!getInheritsPopupMenu()) { - return popupMenu; + return _popupMenu; } - if (popupMenu == null) { + if (_popupMenu == null) { // Search parents for its popup Container parent = getParent(); while (parent != null) { @@ -535,7 +537,7 @@ public JPopupMenu getComponentPopupMenu() { return null; } - return popupMenu; + return _popupMenu; } /** @@ -1588,9 +1590,9 @@ public boolean contains(int x, int y) { * description: The component's border. */ public void setBorder(Border border) { - Border oldBorder = this.border; + Border oldBorder = this._border; - this.border = border; + this._border = border; firePropertyChange("border", oldBorder, border); if (border != oldBorder) { if (border == null @@ -1611,7 +1613,7 @@ public void setBorder(Border border) { * @see #setBorder */ public Border getBorder() { - return border; + return _border; } /** @@ -1623,8 +1625,8 @@ public Border getBorder() { */ @Override public Insets getInsets() { - if (border != null) { - return border.getBorderInsets(this); + if (_border != null) { + return _border.getBorderInsets(this); } return super.getInsets(); } @@ -1651,17 +1653,17 @@ public Insets getInsets(Insets insets) { // because AWT components do not have this method in = getInsets(); } else { - if (border == null) { + if (_border == null) { // super.getInsets() always returns an Insets object with // all of its value zeroed. No need for a new object here. insets.left = insets.top = insets.right = insets.bottom = 0; } else { - if (border instanceof AbstractBorder) { - in = ((AbstractBorder) border).getBorderInsets(this, insets); + if (_border instanceof AbstractBorder) { + in = ((AbstractBorder) _border).getBorderInsets(this, insets); } // Can't reuse border insets because the Border interface // can't be enhanced. - in = border.getBorderInsets(this); + in = _border.getBorderInsets(this); } } if (in != null) { @@ -1683,8 +1685,8 @@ public Insets getInsets(Insets insets) { */ @Override public float getAlignmentY() { - if (isAlignmentYSet) { - return alignmentY; + if (_isAlignmentYSet) { + return _alignmentY; } return super.getAlignmentY(); } @@ -1698,9 +1700,9 @@ public float getAlignmentY() { * @beaninfo description: The preferred vertical alignment of the component. */ public void setAlignmentY(float alignmentY) { - this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f + this._alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY; - isAlignmentYSet = true; + _isAlignmentYSet = true; } /** @@ -1713,8 +1715,8 @@ public void setAlignmentY(float alignmentY) { */ @Override public float getAlignmentX() { - if (isAlignmentXSet) { - return alignmentX; + if (_isAlignmentXSet) { + return _alignmentX; } return super.getAlignmentX(); } @@ -1728,9 +1730,9 @@ public float getAlignmentX() { * @beaninfo description: The preferred horizontal alignment of the component. */ public void setAlignmentX(float alignmentX) { - this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f + this._alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX; - isAlignmentXSet = true; + _isAlignmentXSet = true; } /** @@ -2958,8 +2960,8 @@ public void scrollRectToVisible(Rectangle aRect) { */ public void setAutoscrolls(boolean autoscrolls) { setFlag(AUTOSCROLLS_SET, true); - if (this.autoscrolls != autoscrolls) { - this.autoscrolls = autoscrolls; + if (this._autoscrolls != autoscrolls) { + this._autoscrolls = autoscrolls; if (autoscrolls) { enableEvents(AWTEvent.MOUSE_EVENT_MASK); enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); @@ -2977,7 +2979,7 @@ public void setAutoscrolls(boolean autoscrolls) { * @see #setAutoscrolls */ public boolean getAutoscrolls() { - return autoscrolls; + return _autoscrolls; } /** @@ -2993,7 +2995,7 @@ public boolean getAutoscrolls() { */ @Override protected void processMouseEvent(MouseEvent e) { - if (autoscrolls && e.getID() == MouseEvent.MOUSE_RELEASED) { + if (_autoscrolls && e.getID() == MouseEvent.MOUSE_RELEASED) { Autoscroller.stop(this); } super.processMouseEvent(e); @@ -3009,7 +3011,7 @@ protected void processMouseEvent(MouseEvent e) { @Override protected void processMouseMotionEvent(MouseEvent e) { boolean dispatch = true; - if (autoscrolls && e.getID() == MouseEvent.MOUSE_DRAGGED) { + if (_autoscrolls && e.getID() == MouseEvent.MOUSE_DRAGGED) { // We don't want to do the drags when the mouse moves if we're // autoscrolling. It makes it feel spastic. dispatch = !Autoscroller.isRunning(this); @@ -4164,7 +4166,7 @@ public void removeNotify() { RepaintManager.currentManager(this).resetDoubleBuffer(); setCreatedDoubleBuffer(false); } - if (autoscrolls) { + if (_autoscrolls) { Autoscroller.stop(this); } } @@ -4680,15 +4682,15 @@ boolean checkIfChildObscuredBySibling() { private void setFlag(int aFlag, boolean aValue) { if (aValue) { - flags |= (1 << aFlag); + _flags |= (1 << aFlag); } else { - flags &= ~(1 << aFlag); + _flags &= ~(1 << aFlag); } } private boolean getFlag(int aFlag) { int mask = (1 << aFlag); - return ((flags & mask) == mask); + return ((_flags & mask) == mask); } // // These functions must be static so that they can be called from @@ -4754,11 +4756,11 @@ protected String paramString() { .toString() : ""); String maximumSizeString = (isMaximumSizeSet() ? getMaximumSize() .toString() : ""); - String borderString = (border == null ? "" : (border == this ? "this" - : border.toString())); + String borderString = (_border == null ? "" : (_border == this ? "this" + : _border.toString())); - return super.paramString() + ",alignmentX=" + alignmentX + ",alignmentY=" - + alignmentY + ",border=" + borderString + ",flags=" + flags + return super.paramString() + ",alignmentX=" + _alignmentX + ",alignmentY=" + + _alignmentY + ",border=" + borderString + ",flags=" + _flags + // should beef this up a bit ",maximumSize=" + maximumSizeString + ",minimumSize=" + minimumSizeString + ",preferredSize=" + preferredSizeString; diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java b/sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java index 5739327a6..a3255e772 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java @@ -27,25 +27,22 @@ */ package javax.swing; -import java.awt.HeadlessException; - import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; -import java.awt.JSFrame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; +import java.awt.HeadlessException; import java.awt.Image; +import java.awt.JSFrame; import java.awt.LayoutManager; import java.awt.event.WindowEvent; // -import swingjs.JSUtil; -import swingjs.plaf.JSComponentUI; - //BH: Added rootPane.addNotify(); // builds a peer for the root pane +//BH: Added ability to embed the frame in a div of the web page. /** * An extended version of java.awt.Frame that adds support for @@ -153,7 +150,8 @@ public class JFrame extends JSFrame implements WindowConstants, */ protected JRootPane rootPane; - public void add(Component comp, Object constraints) { + @Override + public void add(Component comp, Object constraints) { if (comp instanceof JApplet) { isAppletFrame = true; ((JApplet) comp).getLayeredPane().isFramedApplet = true; @@ -172,6 +170,8 @@ public void add(Component comp, Object constraints) { */ protected boolean rootPaneCheckingEnabled = false; + private boolean _boundsFrozen; + /** * Constructs a new frame that is initially invisible. *

@@ -284,6 +284,7 @@ public JFrame(String title, GraphicsConfiguration gc) { } public JFrame(Object object, Object object2, Object object3, Object object4) { + // For SwingJS JInternalFrame constructor } @Override @@ -463,6 +464,7 @@ public int getDefaultCloseOperation() { * @beaninfo bound: true hidden: true description: Mechanism for transfer of * data into the component */ + @Override public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = transferHandler; transferHandler = newHandler; @@ -479,6 +481,7 @@ public void setTransferHandler(TransferHandler newHandler) { * @see #setTransferHandler * @since 1.6 */ + @Override public TransferHandler getTransferHandler() { return transferHandler; } @@ -914,4 +917,18 @@ protected String paramString() { + defaultCloseOperationString + ",rootPane=" + rootPaneString + ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString; } + + public void _freezeBounds(int w, int h) { + setSize(w, h); + _boundsFrozen = true; + resizable = false; + } + + @Override + public void reshape(int x, int y, int width, int height) { + if (!_boundsFrozen) + super.reshape(x, y, width, height); + } + + } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java index 0e9ea128b..522277dda 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java @@ -56,16 +56,16 @@ public JSUtil() { private static Map getFileCache() { - if (JSUtil.fileCache == null && (JSUtil.fileCache = JSUtil.J2S.getSetJavaFileCache(null)) == null) { - JSUtil.fileCache = new Hashtable(); - JSUtil.J2S.getSetJavaFileCache(JSUtil.fileCache); + if (fileCache == null && (fileCache = J2S.getSetJavaFileCache(null)) == null) { + fileCache = new Hashtable(); + J2S.getSetJavaFileCache(fileCache); } - return JSUtil.fileCache; + return fileCache; } private static Object getCachedFileData(String path) { - return (JSUtil.useCache && JSUtil.fileCache != null ? - JSUtil.fileCache.get(path) : null); + return (useCache && fileCache != null ? + fileCache.get(path) : null); } /** @@ -105,7 +105,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes) { data = (asBytes ? Rdr.getStreamAsBytes(stream, null) : Rdr.streamToUTF8String(stream)); } catch (Exception e) { // bypasses AjaxURLConnection - data = JSUtil.J2S.getFileData(uri, null, false, asBytes); + data = J2S.getFileData(uri, null, false, asBytes); } } return data; @@ -120,7 +120,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes) { */ public static String getFileAsString(String filename) { Object data = getFileContents(filename, false); - return JSUtil.ensureString(data); + return ensureString(data); } public static byte[] getFileAsBytes(Object file, boolean checkNotFound) { @@ -167,7 +167,7 @@ else if (data instanceof InputStream) } public static boolean haveCachedResource(String resourceName, boolean isJavaPath) { - String path = JSUtil.J2S.getResourcePath(resourceName, isJavaPath); + String path = J2S.getResourcePath(resourceName, isJavaPath); return (path != null && getCachedFileData(path) != null); } @@ -192,14 +192,14 @@ public static String getJavaResource(String resourceName, boolean isJavaPath, if (data == null && (data = J2S.getFileData(path, null, false, false)) != null && useCache && doCache) - JSUtil.cacheFileData(path, data); - String sdata = JSUtil.ensureString(data); + cacheFileData(path, data); + String sdata = ensureString(data); boolean ok = (sdata != null && sdata.indexOf("[Exception") != 0); System.out.println("Processing " + path + " [" + (ok ? "" + sdata.length() : sdata) + "]"); return (!ok ? null : !doProcess ? sdata - : path.endsWith(".css") ? JSUtil.processCSS(sdata, path) : path - .endsWith(".js") ? JSUtil.processJS(sdata, resourceName) : sdata); + : path.endsWith(".css") ? processCSS(sdata, path) : path + .endsWith(".js") ? processJS(sdata, resourceName) : sdata); } static void cacheFileData(String path, Object data) { @@ -224,7 +224,7 @@ public static void loadJavaResourcesFromZip(ClassLoader cl, String zipFileName, try { BufferedInputStream bis = new BufferedInputStream(cl.getResourceAsStream(zipFileName)); String prefix = J2S.getResourcePath(null, true); // will end with / - fileList = JSUtil.getZipTools().cacheZipContentsStatic(bis, prefix, mapByteData, false); + fileList = getZipTools().cacheZipContentsStatic(bis, prefix, mapByteData, false); } catch (Exception e) { System.out.println("JSUtil could not cache files from " + zipFileName); return; @@ -260,7 +260,7 @@ static String processCSS(String css, String path) { path = path.substring(0, path.lastIndexOf("/") + 1) + "images/"; css = PT.rep(css, "images/", path); } - JSUtil.jQuery.$("head").append(JSUtil.jQuery.$("")); + jQuery.$("head").append(jQuery.$("")); return css; } @@ -276,7 +276,7 @@ static String processJS(String js, String resourceName) { */ {} } catch (Throwable e) { - JSUtil.alert("error processing " + js); + alert("error processing " + js); return null; } return js; @@ -348,8 +348,8 @@ public static String getStackTrace() { */ public static void notImplemented(String msg) { String s = null; - if (JSUtil.mapNotImpl == null) - JSUtil.mapNotImpl = new Hashtable(); + if (mapNotImpl == null) + mapNotImpl = new Hashtable(); /** * @j2sNative * @@ -360,9 +360,9 @@ public static void notImplemented(String msg) { */ { } - if (JSUtil.mapNotImpl.containsKey(s)) + if (mapNotImpl.containsKey(s)) return; - JSUtil.mapNotImpl.put(s, Boolean.TRUE); + mapNotImpl.put(s, Boolean.TRUE); System.out.println(s + " has not been implemented in SwingJS. " + (msg == "" ? "" : (msg == null ? "" : msg) + getStackTrace(-5))); @@ -509,7 +509,7 @@ public static void showWebPage(URL url, Object target) { * @param msg */ public static void warn(String msg) { - JSUtil.alert(msg); + alert(msg); } /** diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java index 8779f3210..9c7f33b9e 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java @@ -1347,6 +1347,7 @@ protected void setMnemonic(int newValue) { private boolean ignoreFocus; + protected DOMNode embeddingNode; /** * we can allow frames -- particularly JInternalFrames in a JDesktopFrame -- to overflow. @@ -1704,7 +1705,7 @@ protected DOMNode setHTMLElementCUI() { // If the applet's root pane, we insert it into the applet's // content DOMNode cdiv = swingjs.JSToolkit.getHTML5Applet(jc)._getContentLayer(); - DOMNode.appendChildSafely(cdiv, outerNode); + DOMNode.appendChildSafely(cdiv, outerNode); } } } @@ -1716,6 +1717,9 @@ protected DOMNode setHTMLElementCUI() { } } isTainted = false; + + if (embeddingNode != null) + DOMNode.appendChildSafely(embeddingNode, outerNode); return outerNode; } @@ -1763,7 +1767,8 @@ protected void addChildrenToDOM(Component[] children, int n) { } else { if (ui.domNode != ui.outerNode && DOMNode.getParent(ui.domNode) == null) appendChild(ui.outerNode, ui.domNode); - DOMNode.appendChildSafely(containerNode, ui.outerNode); + if (ui.embeddingNode == null) + DOMNode.appendChildSafely(containerNode, ui.outerNode); } } } @@ -2128,7 +2133,7 @@ public void setBounds(int x, int y, int width, int height, int op) { case SET_LOCATION: x = c.getX(); y = c.getY(); - if (this.x != x || this.y != y) { + if (embeddingNode == null && (this.x != x || this.y != y)) { this.x = x; this.y = y; } @@ -2192,15 +2197,17 @@ private ImageIcon getIcon(JSComponent c, Icon icon) { /** * remove 0x0000 and replace space with nonbreaking space if not a textarea + * * @param t * @return */ protected String fixText(String t) { - t = (t != null && t.indexOf("\u0000") >= 0 ? PT.rep(t, "\u0000", "") : t); - if (isHTML) { - // - } else if (valueNode == null) { - t = t.replace(' ', '\u00A0'); + if (t != null) { + if (isHTML) { + // + } else if (valueNode == null) { + t = (t.indexOf("\u0000") >= 0 ? PT.rep(t, "\u0000", "") : t).replace(' ', '\u00A0'); + } } return t; } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java index 13e562e1a..3730fe860 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java @@ -17,6 +17,33 @@ import javajs.api.JSFunction; import swingjs.api.js.DOMNode; +/** + * New! Frame, JFrame, and JInternalFrame embedding on a web page: + * + * 1) In the constructor, set the frame to be undecorated: + * + * + * this.setUndecorated(true); + * + * 2) In the constructor, give the frame a name of your choice + * + * this.setName("myframe"); + * + * + * 3) On the web page somewhere, create a div with id (name + "-div") + * and styles position:absolute, left, and right. If you wish, you can + * set the width and height, but that is optional. All four of these + * values override whatever is given in the constructor. + * + * <div id="myframe-div" +style="position:absolute;left:100px;top:200px;width:400px;height:300px" +></div> + * + * That's all there is to it! The frame will not be sizable. + * + * @author hansonr + * + */ public class JSFrameUI extends JSWindowUI implements FramePeer { private static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0); @@ -41,7 +68,6 @@ public class JSFrameUI extends JSWindowUI implements FramePeer { protected JFrame frame; // private String title; private int state; -// private boolean resizeable; private DOMNode closerWrap; protected boolean isModal; protected int zModal; @@ -72,10 +98,9 @@ public DOMNode updateDOMNode() { // a Windows applet has a sort of fuzzy shadowy border containerNode = frameNode = domNode = newDOMObject("div", id + "_frame"); if (isDummyFrame) { - DOMNode.setVisible(domNode, false); + DOMNode.setVisible(domNode, false); return domNode; } - DOMNode.setStyles(frameNode, "box-shadow", "0px 0px 10px gray", "box-sizing", "content-box"); setWindowClass(); int w = c.getWidth(); int h = c.getHeight(); @@ -85,27 +110,45 @@ public DOMNode updateDOMNode() { h = defaultHeight; DOMNode.setSize(frameNode, w, h); DOMNode.setTopLeftAbsolute(frameNode, 0, 0); - titleBarNode = newDOMObject("div", id + "_titlebar"); - DOMNode.setTopLeftAbsolute(titleBarNode, 0, 0); - DOMNode.setStyles(titleBarNode, "background-color", "#E0E0E0", "height", "20px", "font-size", "14px", - "font-family", "sans-serif", "font-weight", "bold"// , - // "border-style", "solid", - // "border-width", "1px" - ); - - titleNode = newDOMObject("label", id + "_title"); - DOMNode.setTopLeftAbsolute(titleNode, 2, 4); - DOMNode.setStyles(titleNode, "background-color", "#E0E0E0", "height", "20px", "overflow", "hidden"); - - closerWrap = newDOMObject("div", id + "_closerwrap"); - DOMNode.setTopLeftAbsolute(closerWrap, 0, 0); - DOMNode.setStyles(closerWrap, "text-align", "right"); - + if (frame.getName() != null) { + DOMNode node = DOMNode.getElement(frame.getName() + "-div"); + if (node != null) { + frame.setUndecorated(true); + frame.setLocation(0, 0); + embeddingNode = node; + int ew = DOMNode.getWidth(node); + int eh = DOMNode.getHeight(node); + if (ew > 0 && eh > 0) { + frame._freezeBounds(ew, eh); + } + } + } if (!frame.isUndecorated()) { + DOMNode.setStyles(frameNode, "box-shadow", "0px 0px 10px gray", "box-sizing", "content-box"); + titleBarNode = newDOMObject("div", id + "_titlebar"); + DOMNode.setTopLeftAbsolute(titleBarNode, 0, 0); + DOMNode.setStyles(titleBarNode, "background-color", "#E0E0E0", "height", "20px", "font-size", "14px", + "font-family", "sans-serif", "font-weight", "bold"// , + // "border-style", "solid", + // "border-width", "1px" + ); + + titleNode = newDOMObject("label", id + "_title"); + DOMNode.setTopLeftAbsolute(titleNode, 2, 4); + DOMNode.setStyles(titleNode, "background-color", "#E0E0E0", "height", "20px", "overflow", "hidden"); + + closerWrap = newDOMObject("div", id + "_closerwrap"); + DOMNode.setTopLeftAbsolute(closerWrap, 0, 0); + DOMNode.setStyles(closerWrap, "text-align", "right"); + closerNode = newDOMObject("label", id + "_closer", "innerHTML", "X"); DOMNode.setStyles(closerNode, "width", "20px", "height", "20px", "position", "absolute", "text-align", "center", "right", "0px"); frameNode.appendChild(titleBarNode); + titleBarNode.appendChild(titleNode); + titleBarNode.appendChild(closerWrap); + closerWrap.appendChild(closerNode); + DOMNode.setStyles(closerNode, "background-color", "#DDD");// strColor); } bindWindowEvents(); if (isModal) { @@ -115,33 +158,29 @@ public DOMNode updateDOMNode() { DOMNode.setTopLeftAbsolute(modalNode, 0, 0); DOMNode.setSize(modalNode, screen.width, screen.height); } - setDraggableEvents(); - titleBarNode.appendChild(titleNode); - titleBarNode.appendChild(closerWrap); - closerWrap.appendChild(closerNode); Insets s = getInsets(); DOMNode.setTopLeftAbsolute(frameNode, 0, 0); DOMNode.setAttrs(frameNode, "width", "" + frame.getWidth() + s.left + s.right, "height", "" + frame.getHeight() + s.top + s.bottom); - + addFocusHandler(); } String strColor = toCSSString(c.getBackground()); DOMNode.setStyles(domNode, "background-color", strColor); - DOMNode.setStyles(frameNode, "background", "#DDD");//strColor); + DOMNode.setStyles(frameNode, "background", "#DDD");// strColor); DOMNode.setStyles(frameNode, "color", toCSSString(c.getForeground())); - DOMNode.setStyles(closerNode, "background-color", "#DDD");//strColor); setInnerComponentBounds(width, height); setTitle(frame.getTitle()); if (!isDummyFrame) { - DOMNode.setVisible(domNode, jc.isVisible()); - + DOMNode.setVisible(domNode, jc.isVisible()); } return domNode; } @Override protected void setDraggableEvents() { + if (embeddingNode != null || frame.isUndecorated()) + return; @SuppressWarnings("unused") DOMNode fnode = frameNode; JSFunction fGetFrameParent = null; @@ -289,7 +328,6 @@ public void setMenuBar(Object mb) { @Override public void setResizable(boolean resizeable) { -// this.resizeable = resizeable; } @Override diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSInternalFrameUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSInternalFrameUI.java index 4ff333d0a..48705e425 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSInternalFrameUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSInternalFrameUI.java @@ -35,14 +35,6 @@ public JSInternalFrameUI() { } - @Override - public DOMNode updateDOMNode() { - super.updateDOMNode(); - - return domNode; - - } - @Override protected void frameCloserAction() { JInternalFrame jif = (JInternalFrame) iframe; diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollPaneUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollPaneUI.java index 6f09cbd1f..081f64b40 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollPaneUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollPaneUI.java @@ -55,13 +55,15 @@ public class JSScrollPaneUI extends JSLightweightUI implements private JSScrollBarUI horizBarUI; private JSScrollBarUI vertBarUI; + @SuppressWarnings("unused") @Override public DOMNode updateDOMNode() { scrollpane = (JScrollPane) jc; isContainer = true; if (domNode == null) { domNode = newDOMObject("div", id); - DOMNode.setStyles(domNode, "border", "solid black 1px", "box-sizing", "border-box"); + if (scrolledComponent != null && (/** @j2sNative this.scrolledComponent.isAWT$ || */false)) + DOMNode.setStyles(domNode, "border", "solid black 1px", "box-sizing", "border-box"); } // add code here for adjustments when changes in bounds or other properties // occur. diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Event.java b/sources/net.sf.j2s.java.core/src/test/Test_Event.java index 145494c4d..d54a5f1d8 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Event.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Event.java @@ -117,7 +117,6 @@ public void eventDispatched(AWTEvent event) { setLogging(); - this.setName("Test_Event_Frame"); setTitle("testing editor"); setLocation(100, 100); @@ -141,10 +140,10 @@ public void eventDispatched(AWTEvent event) { // this next allows floating frames outside the JDesktopPane in SwingJS getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); - d.setPreferredSize(new Dimension(800, 600)); + d.setPreferredSize(new Dimension(800, 1)); JInternalFrame main = new JInternalFrame(); - + main.setName("main-frame"); main.setContentPane(new JPanel() { }); @@ -207,16 +206,16 @@ public void mouseExited(MouseEvent e) { main.setVisible(true); d.add(main); - JInternalFrame main2 = new JInternalFrame(); - JPanel p = new JPanel(); - p.setPreferredSize(new Dimension(100, 300)); - p.setMinimumSize(new Dimension(100, 300)); - - main2.add(p); - main2.setTitle("main2"); - main2.pack(); - main2.setVisible(true); - d.add(main2); +// JInternalFrame main2 = new JInternalFrame(); +// JPanel p = new JPanel(); +// p.setPreferredSize(new Dimension(100, 300)); +// p.setMinimumSize(new Dimension(100, 300)); +// +// main2.add(p); +// main2.setTitle("main2"); +// main2.pack(); +// main2.setVisible(true); +// d.add(main2); add(d); pack(); @@ -232,7 +231,7 @@ public void mouseExited(MouseEvent e) { setVisible(true); } - showFocusTimer(); + //showFocusTimer(); } private void showFocusTimer() { diff --git a/sources/net.sf.j2s.java.core/srcjs/js/SwingJSApplet.js b/sources/net.sf.j2s.java.core/srcjs/js/SwingJSApplet.js index 019b3bf50..342bc3f7f 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/SwingJSApplet.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/SwingJSApplet.js @@ -231,13 +231,13 @@ if (typeof(SwingJS) == "undefined") { } proto._addCoreFiles = function() { - if (this.__Info.core != "NONE" && this.__Info.core != "none") + if (this.__Info.core != "NONE" && this.__Info.core != "none" && !J2S._debugCode) J2S._addCoreFile((this.__Info.core || "swingjs"), this._j2sPath, this.__Info.preloadCore); - if (J2S._debugCode) { - // no min package for that - J2S._addExec([this, null, "swingjs.JSAppletViewer", "load " + this.__Info.code]); - - } +// if (J2S._debugCode) { +// // no min package for that +// J2S._addExec([this, null, "swingjs.JSAppletViewer", "load " + this.__Info.code]); +// +// } } proto._create = function(id, Info){ diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js index c9b557000..6f8b10bdf 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js @@ -5538,16 +5538,15 @@ var newMethodNotFoundException = function (clazz, method) { //Clazz._Loader.loadZJar(Clazz._Loader.getJ2SLibBase() + "core/coreswingjs.z.js", "swingjs.JSUtil"); //if (!J2S._isAsync) { - if (!Clazz._loadcore || J2S._coreFiles.length == 0) { +if (!Clazz._loadcore || J2S._coreFiles.length == 0) { if (!Clazz._quiet)System.out.println("Clazz: No core files to load -- check Info.core"); - } - +} else { J2S.onClazzLoaded && J2S.onClazzLoaded(1, "Clazz loaded; loading J2S._coreFiles " + J2S._coreFiles.length); for (var i = 0; i < J2S._coreFiles.length; i++) { Clazz.loadScript(J2S._coreFiles[i]); } J2S.onClazzLoaded && J2S.onClazzLoaded(2, "Clazz loaded; core files loaded"); - +} })(Clazz, J2S); }; // called by external application diff --git a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js index 8deb7dff3..977b1c6ab 100644 --- a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js +++ b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js @@ -19179,16 +19179,15 @@ var newMethodNotFoundException = function (clazz, method) { //Clazz._Loader.loadZJar(Clazz._Loader.getJ2SLibBase() + "core/coreswingjs.z.js", "swingjs.JSUtil"); //if (!J2S._isAsync) { - if (!Clazz._loadcore || J2S._coreFiles.length == 0) { +if (!Clazz._loadcore || J2S._coreFiles.length == 0) { if (!Clazz._quiet)System.out.println("Clazz: No core files to load -- check Info.core"); - } - +} else { J2S.onClazzLoaded && J2S.onClazzLoaded(1, "Clazz loaded; loading J2S._coreFiles " + J2S._coreFiles.length); for (var i = 0; i < J2S._coreFiles.length; i++) { Clazz.loadScript(J2S._coreFiles[i]); } J2S.onClazzLoaded && J2S.onClazzLoaded(2, "Clazz loaded; core files loaded"); - +} })(Clazz, J2S); }; // called by external application @@ -19426,13 +19425,13 @@ if (typeof(SwingJS) == "undefined") { } proto._addCoreFiles = function() { - if (this.__Info.core != "NONE" && this.__Info.core != "none") + if (this.__Info.core != "NONE" && this.__Info.core != "none" && !J2S._debugCode) J2S._addCoreFile((this.__Info.core || "swingjs"), this._j2sPath, this.__Info.preloadCore); - if (J2S._debugCode) { - // no min package for that - J2S._addExec([this, null, "swingjs.JSAppletViewer", "load " + this.__Info.code]); - - } +// if (J2S._debugCode) { +// // no min package for that +// J2S._addExec([this, null, "swingjs.JSAppletViewer", "load " + this.__Info.code]); +// +// } } proto._create = function(id, Info){