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 fe661bee8..3aa49df06 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 d16fe5853..a04c4689f 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20230301203155 +20230304111725 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip index fe661bee8..3aa49df06 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp index d16fe5853..a04c4689f 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp @@ -1 +1 @@ -20230301203155 +20230304111725 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 fe661bee8..3aa49df06 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/swingjs/plaf/JSButtonUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSButtonUI.java index 26f701699..9c4ccd3a3 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSButtonUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSButtonUI.java @@ -149,46 +149,17 @@ protected DOMNode createItem(String type, DOMNode buttonNode) { // separator masquerading as a menu item text = null; } - itemNode = newDOMObject("li", id); - if (text == null && icon == null) - return itemNode; - DOMNode.setStyle(itemNode, "outline", "none"); - menuAnchorNode = newDOMObject("div", id + "_a");// this needed? , "tabindex", "8"); - if (type != "_bar") { - addClass(menuAnchorNode, "a"); -// DOMNode.setStyles(menuAnchorNode, "margin", "1px 2px 1px 2px", "height", "1em"); - } - itemNode.appendChild(menuAnchorNode); - setDoPropagate(); - if (buttonNode == null) { - // not a radio or checkbox - addCentering(menuAnchorNode); - enableNode = itemNode; - setIconAndText("btn", icon, gap, text); - } else { - menuAnchorNode.appendChild(buttonNode); - setMenuItem(buttonNode); - } - setMenuItem(menuAnchorNode); - setMenuItem(); + if (createItemNode(type, icon, gap, text, buttonNode)) { // j2sMenu.js will set the mouse-up event for the tag with the // role=menuitem // attribute via j2sApplet.setMouse(). // That event will then fire handleJSEvent setDataComponent(menuAnchorNode); setDataComponent(itemNode); + } return itemNode; } - protected void setMenuItem() { - setMenuItem(itemNode); - setMenuItem(iconNode); - if (actionNode != null && actionNode != iconNode) - setMenuItem(actionNode); - setMenuItem(textNode); - setMenuItem(centeringNode); - } - @SuppressWarnings("unused") @Override protected void enableNode(DOMNode node, boolean b) { 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 64d7c8ab9..27701c76c 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 @@ -504,6 +504,8 @@ protected void restoreCellNodes(DOMNode td) { * */ protected boolean isSimpleButton, isLabel; + + protected boolean isMenuBarLabel; protected int x, y; @@ -1734,7 +1736,7 @@ public Dimension getHTMLSize(DOMNode obj) { } private Dimension getIconSize(AbstractButton b) { - + // return (iconNode == null || imageNode == null || b.getIcon() == null ? null : new Dimension(b.getIcon().getIconWidth(), b.getIcon().getIconHeight())); } @@ -3035,10 +3037,10 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { itop = 70; iscale = "scale(0.8,0.8)"; } - break; } if (itop >= 0) { + if (!isLabel || !isMenuBarLabel) addJSKeyVal(cssTxt, "top", top + "%", "transform", "translateY(" + (yoff == null ? "-" + top + "%" : yoff) + ")" + voff); addJSKeyVal(cssIcon, "top", top + "%", "transform", "translateY(-" + itop + "%)" + voff + iscale); @@ -3067,6 +3069,10 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { } private void setMenuAnchorAndAccelerator(AbstractButton b, int wCtr, boolean ltr, Insets margins) { + if (isLabel) { + // allowing label here -- not nec AbstractButton + return; + } int wAccel = 0; if (isMenu) { // Correct for dimText calc losing position:absolute @@ -3847,5 +3853,40 @@ public void setPasteHandler(JSFunction handler) { } } + public boolean createItemNode(String type, Icon icon, int gap, String text, DOMNode buttonNode) { + itemNode = newDOMObject("li", id); + if (text == null && icon == null) + return false; + DOMNode.setStyle(itemNode, "outline", "none"); + menuAnchorNode = newDOMObject("div", id + "_a");// this needed? , "tabindex", "8"); + if (type != "_bar") { + addClass(menuAnchorNode, "a"); +// DOMNode.setStyles(menuAnchorNode, "margin", "1px 2px 1px 2px", "height", "1em"); + } + itemNode.appendChild(menuAnchorNode); + setDoPropagate(); + if (buttonNode == null) { + // not a radio or checkbox + addCentering(menuAnchorNode); + enableNode = itemNode; + setIconAndText("btn", icon, gap, text); + } else { + menuAnchorNode.appendChild(buttonNode); + setMenuItem(buttonNode); + } + setMenuItem(menuAnchorNode); + setMenuItem(); + return true; + } + + protected void setMenuItem() { + setMenuItem(itemNode); + setMenuItem(iconNode); + if (actionNode != null && actionNode != iconNode) + setMenuItem(actionNode); + setMenuItem(textNode); + setMenuItem(centeringNode); + } + } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSLabelUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSLabelUI.java index c03b1b201..18ea768cf 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSLabelUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSLabelUI.java @@ -9,6 +9,8 @@ import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JMenuBar; +import javax.swing.JPopupMenu; import javax.swing.LookAndFeel; import swingjs.api.js.DOMNode; @@ -34,15 +36,26 @@ public JSLabelUI() { public DOMNode updateDOMNode() { // if (jc.getTopLevelAncestor() == null) // return domNode; + isMenuItem = jc.getParent() instanceof JPopupMenu; + isMenuBarLabel = jc.getParent() instanceof JMenuBar; if (domNode == null) { - enableNode = domNode = newDOMObject("label", id); - textNode = iconNode = null; - addCentering(domNode); + if (isMenuItem) { + createItemNode("_item", icon, 4, label.getText(), null); + domNode = itemNode; + // TODO -- still not positioned correctly + } else { + enableNode = domNode = newDOMObject("label", id); + textNode = iconNode = null; + addCentering(domNode); + } } getIconAndText(); // could be ToolTip setIconAndText("label", icon, gap, text); - DOMNode.setStyles(domNode, "position", "absolute", "width", c.getWidth() + "px", "height", - c.getHeight() + "px"); + if (isMenuItem) { + } else { + DOMNode.setStyles(domNode, "position", "absolute", "width", c.getWidth() + "px", "height", + c.getHeight() + "px"); + } updateCenteringNode(); if (allowTextAlignment) { // not for JToolTip diff --git a/sources/net.sf.j2s.java.core/src/test/Test_J8_Stream.java b/sources/net.sf.j2s.java.core/src/test/Test_J8_Stream.java index 59532389d..9257607fa 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_J8_Stream.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_J8_Stream.java @@ -40,9 +40,16 @@ public static void main(String[] args) { String st = "test\ning\r\nnow"; String[] lines = st.split("\n"); int[] ptr = new int[1]; + long n = 0; if (/** @j2sNative true || */ false) { // this is Java 11, so JavaScript-only test here + String s = "\u0000test"; + assert (s.trim().length() == 4); + n = (/** @j2sNative s.strip$().length || */0); + System.out.println("strip gives length " + n); + assert (n == 5); + Stream o = /** @j2sNative st.lines$() || */ null; if (o != null) { @@ -89,7 +96,6 @@ public void accept(String value) { Consumer cc = param::set; Supplier sup = param::get; - long n; StringBuffer sb = new StringBuffer("test"); System.out.println("below is 'test'? " + sb); sb.chars().mapToObj(i -> (char) i).forEach(System.out::print); diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Menu.java b/sources/net.sf.j2s.java.core/src/test/Test_Menu.java index 8dc4a2189..d64df2db1 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Menu.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Menu.java @@ -42,6 +42,7 @@ import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @@ -87,7 +88,7 @@ public Test_Menu() { private JMenuBar getMenuBar() { JMenuBar mb = new JMenuBar(); JMenu mb1 = new JMenu("Test1"); - JMenu mb2 = new JMenu("Test2"); + JMenu mb2 = new JMenu("Testing2"); JMenuItem mb1a = new JMenuItem("test-1"); mb1a.addActionListener((e)->{ System.out.println("test-1 clicked"); @@ -128,6 +129,10 @@ public void menuCanceled(MenuEvent e) { mb.add(mb1); mb.add(mb2); + JLabel l = new JLabel("label1"); + mb.add(l); + l = new JLabel("label2"); + mb1.add(l); ActionListener al = new ActionListener() {