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 a8f5c839b..8e8dca0dc 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 f7ba85533..62f00c015 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20190319211418 +20190323074004 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 a8f5c839b..8e8dca0dc 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 f7ba85533..62f00c015 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 @@ -20190319211418 +20190323074004 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 a8f5c839b..8e8dca0dc 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/Container.java b/sources/net.sf.j2s.java.core/src/java/awt/Container.java index d4e1ea279..dfb50fbe9 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/Container.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/Container.java @@ -1076,6 +1076,7 @@ protected void addImplCont(Component comp, Object constraints, int index) { if (/** @j2sNative comp.getWrap$ && !this.isWrapper$ || */ false) { comp = ((A2SWrappedComponent) comp).getWrap$(); + comp.background = comp.foreground = null; // this parent should not set the background color } // SwingJS used for all add methods 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 e9b418bde..757a7248b 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 @@ -262,6 +262,15 @@ public String getUIClassID() { return (uiClassID == null ? uiClassID = "ComponentUI" : uiClassID); } + /** + * for JSToolkit use only + * @param id + */ + public void setUIClassID(String id) { + uiClassID = id; + } + + /** * required by Container, but not actually ever called, * because all Containers are JComponents in SwingJS diff --git a/sources/net.sf.j2s.java.core/src/java/awt/Window.java b/sources/net.sf.j2s.java.core/src/java/awt/Window.java index 9c4e600cb..c3fd23d38 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/Window.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/Window.java @@ -1168,6 +1168,12 @@ final void toFront_NoClientCode() { if (isModalBlocked()) { modalBlocker.toFront_NoClientCode(); } + + for (int i = 0; i < ownedWindowList.size(); i++) { + if (ownedWindowList.get(i).isVisible()) + ownedWindowList.get(i).toFront(); + } + } } diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/DefaultComboBoxModel.java b/sources/net.sf.j2s.java.core/src/javax/swing/DefaultComboBoxModel.java index 4fbcbc9ad..bde90e05c 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/DefaultComboBoxModel.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/DefaultComboBoxModel.java @@ -40,6 +40,7 @@ public class DefaultComboBoxModel extends AbstractListModel implements MutableComboBoxModel { Vector objects; Object selectedObject; + private boolean _isQuiet; /** * Constructs an empty DefaultComboBoxModel object. @@ -92,7 +93,8 @@ public void setSelectedItem(Object anObject) { if ((selectedObject != null && !selectedObject.equals( anObject )) || selectedObject == null && anObject != null) { selectedObject = anObject; - fireContentsChanged(this, -1, -1); + if (!_isQuiet) + fireContentsChanged(this, -1, -1); } } @@ -134,10 +136,11 @@ public void addElement(E anObject) { objects.addElement(anObject); fireIntervalAdded(this,objects.size()-1, objects.size()-1); if ( objects.size() == 1 && selectedObject == null && anObject != null ) { - setSelectedItem( anObject ); + _setSelectedItemQuiet(anObject); } } + // implements javax.swing.MutableComboBoxModel @Override public void insertElementAt(E anObject,int index) { @@ -148,14 +151,9 @@ public void insertElementAt(E anObject,int index) { // implements javax.swing.MutableComboBoxModel @Override public void removeElementAt(int index) { - if ( getElementAt( index ) == selectedObject ) { - if ( index == 0 ) { - setSelectedItem( getSize() == 1 ? null : getElementAt( index + 1 ) ); - } - else { - setSelectedItem( getElementAt( index - 1 ) ); - } - } + if ( getElementAt( index ) == selectedObject ) + _setSelectedItemQuiet(index > 0 ? getElementAt( index - 1 ) + : getSize() == 1 ? null : getElementAt( index + 1 ) ); objects.removeElementAt(index); @@ -185,4 +183,10 @@ public void removeAllElements() { selectedObject = null; } } + + void _setSelectedItemQuiet(Object o) { + _isQuiet = (/**@j2sNative !!this.isAWT$ || */false); + setSelectedItem( o ); + _isQuiet = false; + } } diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JComboBox.java b/sources/net.sf.j2s.java.core/src/javax/swing/JComboBox.java index 497e16bbc..6634b4bc4 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JComboBox.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JComboBox.java @@ -305,6 +305,9 @@ public void setModel(ComboBoxModel aModel) { } dataModel = aModel; dataModel.addListDataListener(this); + /** @j2sNative + * aModel.isAWT$ = this.isAWT$ + */ // set the current selected item. selectedItemReminder = dataModel.getSelectedItem(); @@ -544,7 +547,8 @@ public ComboBoxEditor getEditor() { * preferred: true * description: Sets the selected item in the JComboBox. */ - public void setSelectedItem(Object anObject) { + @SuppressWarnings("unused") + public void setSelectedItem(Object anObject) { Object oldSelection = selectedItemReminder; Object objectToSelect = anObject; if (oldSelection == null || !oldSelection.equals(anObject)) { @@ -569,7 +573,11 @@ public void setSelectedItem(Object anObject) { // Must toggle the state of this flag since this method // call may result in ListDataEvents being fired. selectingItem = true; - dataModel.setSelectedItem(objectToSelect); + if (_trigger || /** @j2sNative !this.isAWT$ &&*/true) { + dataModel.setSelectedItem(objectToSelect); + } else { + ((DefaultComboBoxModel)dataModel)._setSelectedItemQuiet(objectToSelect); + } selectingItem = false; if (selectedItemReminder != dataModel.getSelectedItem()) { @@ -1025,6 +1033,7 @@ public String getActionCommand() { private Action action; private PropertyChangeListener actionPropertyChangeListener; + protected boolean _trigger; /** * Sets the Action for the ActionEvent source. @@ -1268,7 +1277,7 @@ protected void fireActionEvent() { * or override. */ protected void selectedItemChanged() { - if (selectedItemReminder != null ) { + if (selectedItemReminder != null && /** @j2sNative !this.isAWT$ && */true) { fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED, selectedItemReminder, ItemEvent.DESELECTED)); @@ -1587,6 +1596,10 @@ protected String paramString() { ",selectedItemReminder=" + selectedItemReminderString; } + public void _setTrigger(boolean b) { + _trigger = b; + } + /////////////////// // Accessibility support 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 efa667dc8..6e3a3c038 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 @@ -30,7 +30,6 @@ import static javax.swing.ClientPropertyKey.JComponent_ANCESTOR_NOTIFIER; import static javax.swing.ClientPropertyKey.JComponent_INPUT_VERIFIER; -import java.applet.JSApplet; import java.awt.AWTEvent; import java.awt.AWTKeyStroke; import java.awt.Color; @@ -70,9 +69,7 @@ import javajs.util.Lst; import sun.font.FontDesignMetrics; -import swingjs.JSFocusPeer; import swingjs.JSGraphics2D; -import swingjs.JSToolkit; import swingjs.JSUtil; import swingjs.plaf.JSComponentUI; diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JDialog.java b/sources/net.sf.j2s.java.core/src/javax/swing/JDialog.java index a2e731e1a..e2b7d6bc5 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JDialog.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JDialog.java @@ -33,11 +33,11 @@ import java.awt.Container; import java.awt.Dialog; import java.awt.Frame; -import java.awt.JSDialog; -import java.awt.JSFrame; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.HeadlessException; +import java.awt.JSDialog; +import java.awt.JSFrame; import java.awt.LayoutManager; import java.awt.Window; import java.awt.event.WindowEvent; @@ -45,9 +45,6 @@ import javax.swing.plaf.UIResource; -import swingjs.JSUtil; -import swingjs.plaf.JSComponentUI; - // BH: Added rootPane.addNotify(); // builds a peer for the root pane /** diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JScrollPane.java b/sources/net.sf.j2s.java.core/src/javax/swing/JScrollPane.java index 71b7665a0..dd1cca85c 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JScrollPane.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JScrollPane.java @@ -297,6 +297,7 @@ public JScrollPane(Component view, int vsbPolicy, int hsbPolicy) } setUIProperty("opaque",true); updateUI(); + System.out.println("jscrollpanecolor " + getBackground()); } @Override diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java b/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java index 78259815c..ef71f159f 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java @@ -560,7 +560,7 @@ public void setRows(int rows) { protected int getRowHeight() { if (rowHeight == 0) { FontMetrics metrics = getFontMetrics(getFont()); - rowHeight = metrics.getHeight() + 2; // SwingJS adds +2 here + rowHeight = metrics.getHeight();// + 2; // SwingJS adds +2 here } return rowHeight; } @@ -640,7 +640,7 @@ public Dimension getSizeJS(Dimension d, int n, int rows, int columns) { } if (rows != 0) { Insets insets = getInsets(); - d.height = Math.max(h, (rows + 1) * getRowHeight() + insets.top + insets.bottom); + d.height = Math.max(h, rows * getRowHeight() + insets.top + insets.bottom); } return d; } diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java b/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java index 562bb1a39..e4057220c 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java @@ -443,7 +443,10 @@ protected Dimension getPrefSizeJTF() { } protected Dimension getPrefSizeJTF(int columns) { - Dimension size = getPrefSizeJComp(); + Dimension size = (!isPreferredSizeSet() && ui != null ? ui + .getPreferredSize(this) : null); + if (size == null) + size = super.preferredSize(); if (columns != 0) { size.width = getJ2SWidth(columns); } diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java b/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java index 20519f197..2f2d9f1d5 100644 --- a/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java +++ b/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java @@ -28,7 +28,6 @@ package javax.swing; -import java.applet.JSApplet; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; @@ -39,14 +38,15 @@ import java.awt.LayoutManager; import java.awt.Point; import java.awt.Rectangle; -import java.awt.Window; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; + import javax.swing.border.Border; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; + import swingjs.JSGraphics2D; @@ -118,6 +118,7 @@ public class JViewport extends JComponent implements JSComponent.A2SComponentWra { // BH for SwingJS + @Override public void isWrapper$() {}; @@ -574,7 +575,7 @@ public final void setBorder(Border border) { */ @Override public final Insets getInsets() { - return Container.NULL_INSETS; + return new Insets(1, 1, 1, 1);//Container.NULL_INSETS; } /** diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java index 006680ee6..d00d5cfa0 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java @@ -128,6 +128,7 @@ public static void exit() { // ////// java.awt.Toolkit ///////// public static void getScreenSize(Dimension d) { + @SuppressWarnings("unused") JQuery jq = JSUtil.jQuery; d.width = /** @j2sNative jq.$(window).width() || */0; d.height = /** @j2sNative jq.$(window).height() || */0; @@ -285,8 +286,9 @@ public static UIDefaults getLookAndFeelDefaults() { } public static JSComponentUI getComponentUI(JComponent target) { + String id = ((JSComponent) target).getUIClassID(); JSComponentUI ui = (JSComponentUI) Interface.getInstance("swingjs.plaf.JS" - + ((JSComponent) target).getUIClassID(), true); + + id, true); if (ui != null) ui.set(target); return ui; @@ -536,7 +538,7 @@ public WindowPeer createWindow(Window target) { public static JSComponentUI getUI(Component c, boolean isQuiet) { JSComponentUI ui = /** @2sNative !!c.getUI$ &&*/(JSComponentUI)((JComponent) c).getUI(); - if (ui == null && ((JComponent) c).getUIClassID() != "ComponentUI") { + if (ui == null) { ((JComponent) c).updateUI(); ui = (JSComponentUI) ((JComponent) c).getUI(); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/a2s/Choice.java b/sources/net.sf.j2s.java.core/src/swingjs/a2s/Choice.java index ae5e534e4..2bd1cdea2 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/a2s/Choice.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/a2s/Choice.java @@ -3,6 +3,7 @@ import java.awt.Color; import java.awt.event.ItemEvent; +import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; public class Choice extends JComboBox { @@ -69,6 +70,8 @@ protected void fireActionEvent() { @Override protected void fireItemStateChanged(ItemEvent event) { + if (!_trigger) + return; A2SEvent.addListener(this); super.fireItemStateChanged(event); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextArea.java b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextArea.java index 506506bdb..7b52d9fbc 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextArea.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextArea.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.event.TextListener; import java.awt.im.InputMethodRequests; @@ -27,6 +28,106 @@ public void isAWT() { private int verticalScrollBarPolicy; + /** + * Create and display both vertical and horizontal scrollbars. + * + * @since JDK1.1 + */ + public static final int SCROLLBARS_BOTH = 0; + + /** + * Create and display vertical scrollbar only. + * + * @since JDK1.1 + */ + public static final int SCROLLBARS_VERTICAL_ONLY = 1; + + /** + * Create and display horizontal scrollbar only. + * + * @since JDK1.1 + */ + public static final int SCROLLBARS_HORIZONTAL_ONLY = 2; + + /** + * Do not create or display any scrollbars for the text area. + * + * @since JDK1.1 + */ + public static final int SCROLLBARS_NONE = 3; + + public TextArea(int rows, int cols) { + this(null, rows, cols, SCROLLBARS_BOTH); + } + + public TextArea() { + this(null, 0, 0, SCROLLBARS_BOTH); + } + + public TextArea(String text) { + this(text, 0, 0, SCROLLBARS_BOTH); + } + + public TextArea(String text, int rows, int cols) { + this(text, rows, cols, SCROLLBARS_BOTH); + } + + public TextArea(String text, int rows, int columns, int scrollbars) { + super(text, rows < 0 ? 0 : rows, columns < 0 ? 0 : columns); + setWrapStyleWord(false); + setLineWrap(false); + switch (scrollbars) { + case SCROLLBARS_BOTH: + setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + break; + case SCROLLBARS_VERTICAL_ONLY: + setLineWrap(true); + setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + break; + case SCROLLBARS_HORIZONTAL_ONLY: + setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + break; + case SCROLLBARS_NONE: + setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + break; + } + } + + public int getVerticalScrollBarPolicy() { + return verticalScrollBarPolicy; + } + + private void setVerticalScrollBarPolicy(int policy) { + int old = verticalScrollBarPolicy; + verticalScrollBarPolicy = policy; + firePropertyChange("verticalScrollBarPolicy", old, policy); + revalidate(); + repaint(); + } + + public int getHorizontalScrollBarPolicy() { + return horizontalScrollBarPolicy; + } + + private void setHorizontalScrollBarPolicy(int policy) { + int old = horizontalScrollBarPolicy; + horizontalScrollBarPolicy = policy; + firePropertyChange("horizontalScrollBarPolicy", old, policy); + revalidate(); + repaint(); + } + + public int getScrollbarVisibility() { + boolean v = (getVerticalScrollBarPolicy() != ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + boolean h = (getHorizontalScrollBarPolicy() != ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + return (v && h ? SCROLLBARS_BOTH + : v ? SCROLLBARS_VERTICAL_ONLY : h ? SCROLLBARS_HORIZONTAL_ONLY : SCROLLBARS_NONE); + } + public synchronized void addTextListener(TextListener l) { if (l == null) { return; @@ -67,11 +168,24 @@ public Dimension getPreferredSize() { @Override @Deprecated public Dimension preferredSize() { - synchronized (getTreeLock()) { +// synchronized (getTreeLock()) { return ((super.rows > 0) && (super.columns > 0)) ? preferredSize(super.rows, super.columns) : super.preferredSize(); } - } +// } + @Override + protected int getColumnWidth() { + + //A column is an approximate average character width that is platform-dependent. + // + // We will call that "n" -- it is pretty close + // + if (columnWidth == 0) { + FontMetrics metrics = getFontMetrics(getFont()); + columnWidth = metrics.charWidth('n'); + } + return columnWidth; + } /** * Determines the minimum size of a text area with the specified number of rows * and columns. @@ -185,159 +299,6 @@ public InputMethodRequests getInputMethodRequests() { // return super.getCaretPosition(); // } // - /** - * Create and display both vertical and horizontal scrollbars. - * - * @since JDK1.1 - */ - public static final int SCROLLBARS_BOTH = 0; - - /** - * Create and display vertical scrollbar only. - * - * @since JDK1.1 - */ - public static final int SCROLLBARS_VERTICAL_ONLY = 1; - - /** - * Create and display horizontal scrollbar only. - * - * @since JDK1.1 - */ - public static final int SCROLLBARS_HORIZONTAL_ONLY = 2; - - /** - * Do not create or display any scrollbars for the text area. - * - * @since JDK1.1 - */ - public static final int SCROLLBARS_NONE = 3; - - public TextArea(int rows, int cols) { - this(null, rows, cols, SCROLLBARS_BOTH); - } - - public TextArea() { - this(null, 0, 0, SCROLLBARS_BOTH); - } - - public TextArea(String text) { - this(text, 0, 0, SCROLLBARS_BOTH); - } - - public TextArea(String text, int rows, int cols) { - this(text, rows, cols, SCROLLBARS_BOTH); - } - - public TextArea(String text, int rows, int columns, int scrollbars) { - super(text, rows < 0 ? 0 : rows, columns < 0 ? 0 : columns); - switch (scrollbars) { - case SCROLLBARS_BOTH: - setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - break; - case SCROLLBARS_VERTICAL_ONLY: - setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - break; - case SCROLLBARS_HORIZONTAL_ONLY: - setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - break; - case SCROLLBARS_NONE: - setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - break; - } - } - - /** - * Returns the vertical scroll bar policy value. - * @return the verticalScrollBarPolicy property - * @see #setVerticalScrollBarPolicy - */ - public int getVerticalScrollBarPolicy() { - return verticalScrollBarPolicy; - } - - - /** - * Determines when the vertical scrollbar appears in the scrollpane. - * Legal values are: - *
    - *
  • ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED - *
  • ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER - *
  • ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS - *
- * - * @param policy one of the three values listed above - * @exception IllegalArgumentException if policy - * is not one of the legal values shown above - * @see #getVerticalScrollBarPolicy - * - * @beaninfo - * preferred: true - * bound: true - * description: The scrollpane vertical scrollbar policy - * enum: VERTICAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED - * VERTICAL_SCROLLBAR_NEVER ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER - * VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS - */ - private void setVerticalScrollBarPolicy(int policy) { - int old = verticalScrollBarPolicy; - verticalScrollBarPolicy = policy; - firePropertyChange("verticalScrollBarPolicy", old, policy); - revalidate(); - repaint(); - } - - - /** - * Returns the horizontal scroll bar policy value. - * @return the horizontalScrollBarPolicy property - * @see #setHorizontalScrollBarPolicy - */ - public int getHorizontalScrollBarPolicy() { - return horizontalScrollBarPolicy; - } - - - /** - * Determines when the horizontal scrollbar appears in the scrollpane. - * The options are:
    - *
  • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED - *
  • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER - *
  • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS - *
- * - * @param policy one of the three values listed above - * @exception IllegalArgumentException if policy - * is not one of the legal values shown above - * @see #getHorizontalScrollBarPolicy - * - * @beaninfo - * preferred: true - * bound: true - * description: The scrollpane scrollbar policy - * enum: HORIZONTAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED - * HORIZONTAL_SCROLLBAR_NEVER ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER - * HORIZONTAL_SCROLLBAR_ALWAYS ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS - */ - private void setHorizontalScrollBarPolicy(int policy) { - int old = horizontalScrollBarPolicy; - horizontalScrollBarPolicy = policy; - firePropertyChange("horizontalScrollBarPolicy", old, policy); - revalidate(); - repaint(); - } - - public int getScrollbarVisibility() { - boolean v = (getVerticalScrollBarPolicy() != ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); - boolean h = (getHorizontalScrollBarPolicy() != ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - return (v && h ? SCROLLBARS_BOTH - : v ? SCROLLBARS_VERTICAL_ONLY : h ? SCROLLBARS_HORIZONTAL_ONLY : SCROLLBARS_NONE); - } - @Override public void setCaretPosition(int pos) { super.setCaretPosition(pos); diff --git a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java index 7d1eea76f..0c505baee 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java @@ -67,7 +67,7 @@ public Dimension getPreferredSize() { @Override @Deprecated public Dimension preferredSize() { - return getPreferredSize(columns); + return preferredSize(columns); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java b/sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java index ebf4315fe..865cca334 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java @@ -13,10 +13,10 @@ */ public class JQueryUI { public JQueryUI() { + int j = 1; } static { - int i = 2; /** * * diff --git a/sources/net.sf.j2s.java.core/src/swingjs/jquery/jquery-ui-j2sslider.js b/sources/net.sf.j2s.java.core/src/swingjs/jquery/jquery-ui-j2sslider.js index e32d85eb4..f9e62eec7 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/jquery/jquery-ui-j2sslider.js +++ b/sources/net.sf.j2s.java.core/src/swingjs/jquery/jquery-ui-j2sslider.js @@ -3,6 +3,7 @@ * Includes: jquery.ui.slider.js * Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ +// BH 3/23/2019 adds timer for mouse down for track and end // BH 2/10/2019 fix for AWT scrollbar differences from Swing // BH 7/21/2018 fix for ScrollPane scroll bars not clicking on tracks // note -- still no support for unit (deprecated anyway) or block increments @@ -24,9 +25,41 @@ // (how many times can you page 3/down to go through the whole range) var numPages = 5; - var closestHandle, index, allowed, offset; + var closestHandle, index, allowed, offset, dir; - var clearEnds = function(e) { + var actionTimer, actionTimer2; + var actionDelay = 60, actionDelay0 = 200; + var startAction = function(me, dir) { + if (actionTimer) + return; + me.jslider.ui.scrollByUnit$I(dir) + actionTimer = setTimeout(function(){ + actionTimer = setInterval(function() { + me.jslider.ui.scrollByUnit$I(dir) + }, actionDelay); + }, actionDelay0); + } + + var startAction2 = function(me, dir, val) { + me.jslider.ui.scrollDueToClickInTrack$I$I(dir, val); + if (!me.isScrollBar) + return; + actionTimer2 = + setTimeout(function(){ + actionTimer2 = setInterval(function() { + me.jslider.ui.scrollDueToClickInTrack$I$I(dir); + }, actionDelay); + }, actionDelay0); + } + + var clearEnds = function(me) { + var e = me.element; + if (actionTimer) + clearInterval(actionTimer); + if (actionTimer2) + clearInterval(actionTimer2); + actionTimer = 0; + actionTimer2 = 0; e.removeClass("ui-j2sslider-at-top"); e.removeClass("ui-j2sslider-at-bottom"); e.removeClass("ui-j2sslider-at-left"); @@ -38,7 +71,7 @@ var OBJ_HANDLE = 2; var doMouseCapture = function(me, event, obj, isEndCheck) { - + var that = me, o = me.options; if (o.disabled || event.type == "mousemove" && event.buttons == 0) { @@ -68,14 +101,13 @@ if (allowed === false) { return false; } + me._mouseSliding = true; me._handleIndex = index; if (obj == OBJ_HANDLE) - closestHandle.addClass("ui-state-active") - .focus(); - + closestHandle.addClass("ui-state-active").focus(); offset = closestHandle.offset(); var mouseOverHandle = (obj == OBJ_HANDLE) && $(event.target).parents() @@ -105,23 +137,22 @@ var pixmouse = getPixelMouse(me, position, false); var isAtEnd = !mouseOverHandle && (!me.isScrollBar ? 0 : - pixmouse < 5 ? -1 : pixmouse > getPixelTotal(me) - 5 ? 1 : 0); + pixmouse < 5 ? -1 : pixmouse > length(me) + 5 ? 1 : 0); + var dir = Math.signum(!isAtEnd ? val - me.jslider.getValue$() : isAtEnd); if (isAtEnd) { me.element.addClass(me.orientation === "horizontal" ? (isAtEnd == 1 ? "ui-j2sslider-at-right" : "ui-j2sslider-at-left") : (isAtEnd == 1 ? "ui-j2sslider-at-bottom" : "ui-j2sslider-at-top")); + startAction(me, dir); } else { - clearEnds(me.element); - } - if (isEndCheck) { - return; - } - var dir = Math.signum(!isAtEnd ? val - me.jslider.getValue$() : isAtEnd); - if (!me.handles.hasClass("ui-state-hover")) { - if (isAtEnd) { - me.jslider.ui.scrollByUnit$I(dir); - } else if (obj != OBJ_HANDLE) { - me.jslider.ui.scrollDueToClickInTrack$I$I(dir, val); + clearEnds(me); + if (isEndCheck) { + return; + } +// if (!me.handles.hasClass("ui-state-hover")) { + if (obj != OBJ_HANDLE) { + startAction2(me, dir, val); +// } } } me._animateOff = true; @@ -161,8 +192,12 @@ return p - (offsetHandle ? me.handleSize / 2 : 0); } + var length = function(me) { + return (me.orientation == "horizontal" ? width(me) : height(me)) + } + var getPixelTotal = function(me) { - return (me.orientation == "horizontal" ? width(me) : height(me)) - me.visibleAdjust || 100; + return length(me) - me.visibleAdjust || 100; } var postMouseEvent = function(me, xye, id) { @@ -182,7 +217,8 @@ } var width = function(me) { - return Math.max(0, me.element.width() || me.element.parent().width() - me.marginX || 0); + var w = Math.max(0, me.element.width() || me.element.parent().width() - me.marginX || 0); + return w; } var height = function(me) { @@ -293,6 +329,7 @@ var fUpTrack = function(event, id) { //me._stop(event, me._handleIndex); me._change(event, me._handleIndex); + clearEnds(me); }; var fDownWrap = function(event, id) { @@ -325,7 +362,7 @@ }; var fOutTrack = function(event, id) { - clearEnds(me.element); + clearEnds(me); }; var fMoveTrack = function(event, id) { @@ -609,7 +646,7 @@ if (f < 0.1) f = 0.1; this.handleFraction = f; - var hw = (this.orientation === "horizontal" ? width(this) : height(this)); + var hw = length(this); if (this.orientation === "horizontal") $(this.handles[0]).width(this.handleSize = f * hw); else diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComboBoxUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComboBoxUI.java index 0a9fa48ff..8c823d7f4 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComboBoxUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComboBoxUI.java @@ -62,9 +62,11 @@ public void setEnabled(boolean b) { @Override public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) { switch (eventType) { - case -1: + case SOME_MOUSE_EVENT: int index = PT.parseInt("" + DOMNode.getAttr(domNode, "selectedIndex")); + comboBox._setTrigger(true); comboBox.setSelectedIndex(index); + comboBox._setTrigger(false); break; } return HANDLED; 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 1a90765fa..8779f3210 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 @@ -15,7 +15,6 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; -import java.awt.Window; import java.awt.dnd.DropTarget; import java.awt.dnd.peer.DropTargetPeer; import java.awt.event.KeyEvent; @@ -38,7 +37,6 @@ import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JRootPane; -import javax.swing.JTable; import javax.swing.JTable.BooleanRenderer; import javax.swing.KeyStroke; import javax.swing.SwingConstants; @@ -552,7 +550,7 @@ public void setDraggable(JSFunction f) { private DOMNode waitImage; - private final Color colorUNKNOWN = new Color(); + protected final Color colorUNKNOWN = new Color(); protected Color inactiveForeground = colorUNKNOWN, inactiveBackground = colorUNKNOWN; @@ -643,8 +641,6 @@ public void installJS() { */ private void uninstallJS() { - //System.out.println("uninstallJS " + id); - // window closing will fire this with c == null /** @@ -1168,9 +1164,7 @@ public void propertyChange(PropertyChangeEvent e) { } private Container awttop; - protected Color awtPeerBG; - - private Color awtPeerFG; + protected Color awtPeerBG, awtPeerFG; /** * AWT component background, foreground, and font are all set at the @@ -1292,7 +1286,6 @@ protected void setMnemonic(int newValue) { mnemonic = newValue; } - private String createMsgs = ""; /** * set to TRUE by Container.validateTree at the beginning of its laying out and @@ -1386,16 +1379,13 @@ public DOMNode getDOMNode() { * @return the DOM element's node and, if the DOM element already exists, */ public DOMNode updateDOMNode() { - if (notImplemented) { - String msg = "Swingjs WARNING: default JSComponentUI.updateDOMNode() is being used for " - + getClass().getName(); - if (debugging && createMsgs.indexOf(msg) < 0) { - createMsgs += msg; - JSUtil.alert(msg); + if (domNode == null) { + if (notImplemented) { + String msg = "Swingjs WARNING: default JSComponentUI.updateDOMNode() is being used for " + + getClass().getName(); + System.out.println(msg); } - System.out.println(msg); - if (domNode != null) - domNode = DOMNode.createElement("div", id); + domNode = DOMNode.createElement("div", id); } return domNode; } @@ -2294,7 +2284,6 @@ protected void setIconAndText(String prop, Icon icon, int gap, String text) { DOMNode.setVisible(obj, text != null); } if (obj != null) { -// System.out.println("JSCUI setText " + id + " " + prop + " " + text); setJSText(obj, prop, text); } if (valueNode != null) { @@ -2393,6 +2382,10 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { int wText = (dimText == null ? 0 : dimText.width); int gap = (wText == 0 || wIcon == 0 ? 0 : b.getIconTextGap()); int w = cellComponent != null ? cellWidth : $(domNode).width(); + if (w < wIcon + wText) { + // jQuery method can fail that may not have worked. + w = wIcon + wText; + } boolean alignVCenter = (vAlign == SwingConstants.CENTER); Insets margins = (isLabel ? (isAWT ? b.getInsets() : insets) : b.getMargin()); if (margins == null) @@ -2502,14 +2495,18 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { return; } preferredDim = null; - String yoff = "-50%"; DOMNode.setStyles(centeringNode, "position", "absolute", "top", null, "left", null, "transform", null); DOMNode.setStyles(centeringNode, "width", wCtr + "px", "height", hCtr + "px"); if (alignHCenter && alignVCenter && wIcon == 0 || wText == 0 && margins.left == margins.right && margins.top == margins.bottom) { // simple totally centered label or button - DOMNode.setStyles(centeringNode, "top", "50%", "left", "50%", "transform", - "translateX(-50%)translateY("+ yoff + ")"); + // can't have width or height here --- let the browser figure that out + DOMNode.setStyles(centeringNode, "width",null,"top", "50%", "left", "50%", "transform", + "translateX(-50%)translateY(-50%)", "position", "absolute"); + DOMNode.setStyles(iconNode, "top", "50%", "left", "50%", "transform", + "translateX(-50%)translateY(-50%)", "position", "absolute"); + DOMNode.setStyles(textNode, "top", "50%", "left", "50%", "transform", + "translateX(-50%)translateY(-50%)", "position", "absolute"); return; } @@ -2596,11 +2593,14 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { } DOMNode.setStyles(centeringNode, "top", top + "px"); int itop; + String yoff = null; String iscale = null; switch (vTextPos) { case SwingConstants.TOP: top = itop = 0; - yoff = null; + break; + case SwingConstants.BOTTOM: + top = itop = 100; break; default: case SwingConstants.CENTER: @@ -2609,12 +2609,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) { itop = 70; iscale = "scale(0.8,0.8)"; } - // +3 here is a fudge factor for the AWT applets - yoff = "-50%";//(wIcon == 0 && false ? "-" + ((getFont().getFontMetrics().getAscent()>>1) + (isAWT ? 0 : 0)) + "px" : "-50%"); - break; - case SwingConstants.BOTTOM: - top = itop = 100; - yoff = null; + yoff = "-50%"; break; } DOMNode.setStyles(textNode, "top", top + "%", "transform", "translateY(" + (yoff == null ? "-" + top + "%" : yoff + ")")); @@ -2691,7 +2686,6 @@ public FontMetrics getFontMetrics(Font font) { @Override public void dispose() { - //System.out.println("JSCUI dispose " + id); if (isUIDisabled) return; if (cellComponent != null) { @@ -2726,7 +2720,6 @@ protected void undisposeUI(DOMNode node) { // cell renderers will set their domNode to null; if (outerNode != null && domNode != null && domNode != outerNode) { appendChild(outerNode, domNode); - //System.out.println("JSCUI undispose reattached"); } isDisposed = false; } 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 75aadcedc..13e562e1a 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 @@ -253,7 +253,7 @@ protected void closeFrame() { @Override protected void setInnerComponentBounds(int width, int height) { DOMNode.setStyles(closerWrap, "text-align", "right", "width", width + "px"); - DOMNode.setStyles(titleNode, "width", width + "px", "height", "20px"); + DOMNode.setStyles(titleNode, "width", (width-4) + "px", "height", "20px"); } @Override diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java index 00eeb3b4f..c4391bcda 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java @@ -2680,7 +2680,9 @@ public void valueChanged(ListSelectionEvent e) { int lastIndex = Math.min(size - 1, Math.max(e.getLastIndex(), 0)); Rectangle bounds = getCellBounds(list, firstIndex, lastIndex); - + list.ensureIndexIsVisible(firstIndex); + if (lastIndex != firstIndex) + list.ensureIndexIsVisible(lastIndex); if (bounds != null) { list.repaint(bounds.x, bounds.y, bounds.width, bounds.height); } @@ -2946,38 +2948,36 @@ static int adjustIndex(int index, JList list) { // ListPeer public void makeVisible(int index) { - System.out.println("JSListUI makeVisible "+ index); - - +// System.out.println("JSListUI makeVisible "+ index); } public int[] getSelectedIndexes() { - System.out.println("JSListUI getselected"); +// System.out.println("JSListUI getselected"); return new int[] {}; } public void add(String item, int index) { - System.out.println("JSListUI add item " + item + " at "+ index); +// System.out.println("JSListUI add item " + item + " at "+ index); } public void delItems(int start, int end) { - System.out.println("JSListUI delItems " + start + " " + end); +// System.out.println("JSListUI delItems " + start + " " + end); } public void removeAll() { - System.out.println("JSListUI removeAll"); +// System.out.println("JSListUI removeAll"); } public void select(int index) { - System.out.println("JSListUI select " + index); +// System.out.println("JSListUI select " + index); } public void deselect(int index) { - System.out.println("JSListUI deselect " + index); +// System.out.println("JSListUI deselect " + index); } public void setMultipleMode(boolean m) { - System.out.println("JSListUI setMultipleMode " + m); +// System.out.println("JSListUI setMultipleMode " + m); } /** diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollBarUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollBarUI.java index e7e9615ed..afd9b1313 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollBarUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSScrollBarUI.java @@ -8,7 +8,6 @@ import javax.swing.JScrollBar; import javax.swing.event.ChangeEvent; -import swingjs.JSToolkit; import swingjs.api.js.DOMNode; /** @@ -46,26 +45,26 @@ public DOMNode updateDOMNode() { if (isAWT && !jc.isBackgroundSet()) { jc.setBackground(Color.LIGHT_GRAY); } - return domNode; - } +// String bgcolor = null; +// //if (myScrollPaneUI == null) { +// bgcolor = toCSSString(getBackground()); +//// +//// } else { +//// +//// } +// DOMNode.setStyles(sliderTrack, "background", bgcolor); + return domNode; + } @Override public void propertyChange(PropertyChangeEvent e) { super.propertyChange(e); - if (debugging) - System.out.println(id + " propertyChange " + dumpEvent(e)); } @Override public void stateChanged(ChangeEvent e) { -// if (!isAdjusting) { -// isAdjusting = true; super.stateChanged(e); setScrollBarExtentAndCSS(); -// isAdjusting = false; - if (debugging) - System.out.println(id + " stateChange " + dumpEvent(e)); -// } } @Override @@ -92,7 +91,7 @@ protected void setValueIsAdjusting(boolean b) { @Override public Dimension getPreferredSize(JComponent jc) { // thin because we are implementing jquery slider here - int wh = (myScrollPaneUI == null ? 15 : myScrollPaneUI.scrollBarUIDisabled ? 0 : 15); + int wh = (myScrollPaneUI == null ? 15 : myScrollPaneUI.scrollBarUIDisabled ? 0 : 13); // just used for width or height, but not both. I think.... return new Dimension(wh, wh); } @@ -117,11 +116,6 @@ void setScrollBarExtentAndCSS() { String left, top, thickness, transform, leftt; JScrollBar sb = (JScrollBar) jc; int extent = sb.getVisibleAmount(); -// int max = sb.getMaximum(); -// int min = sb.getMinimum(); -// -// float f = (extent > 0 && min + extent <= max -// ? extent * 1f / (max - min) : 0.1f); setSliderAttr("visibleAmount", extent); boolean isVertical = (orientation == "vertical"); if (myScrollPaneUI == null) { @@ -134,17 +128,19 @@ void setScrollBarExtentAndCSS() { transform = "translate(" + (isVertical ? "X":"Y") + ")"; } else { left = "0px"; - leftt = "0px"; + // 2 here and 2 for top is to allow for scrollpane to have a + // 1-pixel border. Better would be to reduce the viewport + leftt = "0px"; top = (isAWT ? "4px" : "0px"); thickness = "12px"; transform = null; } if (isVertical) { - DOMNode.setStyles(sliderTrack, "transform", transform, "left", left, "width", thickness);//, "background", toCSSString(getBackground())); - DOMNode.setStyles(sliderHandle, "box-sizing", "border-box", "left", leftt, "margin-bottom", "0px"); + DOMNode.setStyles(sliderTrack, "transform", transform, "left", left, "width", thickness); + DOMNode.setStyles(sliderHandle, "border", "none", "left", leftt, "margin-bottom", "0px","width", thickness); } else { - DOMNode.setStyles(sliderTrack, "top", top, "height", thickness);//, "background", toCSSString(getBackground())); - DOMNode.setStyles(sliderHandle, "box-sizing", "border-box", "top", leftt, "margin-left", "0px"); + DOMNode.setStyles(sliderTrack, "top", top, "height", thickness); + DOMNode.setStyles(sliderHandle, "border", "none", "top", leftt, "margin-left", "0px","height", thickness); } } 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 70ca2a881..6f09cbd1f 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 @@ -61,6 +61,7 @@ public DOMNode updateDOMNode() { isContainer = true; if (domNode == null) { domNode = newDOMObject("div", id); + DOMNode.setStyles(domNode, "border", "solid black 1px", "box-sizing", "border-box"); } // add code here for adjustments when changes in bounds or other properties // occur. @@ -197,16 +198,13 @@ private void updateScrollBarExtents() { JViewport vp = scrollpane.getViewport(); if (vp == null) return; - JComponent sc = (JComponent) vp.getView(); JScrollBar vsb = scrollpane.getVerticalScrollBar(); JScrollBar hsb = scrollpane.getHorizontalScrollBar(); if (vsb != null) { vsb.setVisibleAmount(vp.getHeight()); -// ((JSScrollBarUI) vsb.getUI()).setScrollBarExtentAndCSS(); } if (hsb != null) { vsb.setVisibleAmount(vp.getWidth()); -// ((JSScrollBarUI) hsb.getUI()).setScrollBarExtentAndCSS(); } } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java index 508039c21..891b09ba8 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java @@ -125,14 +125,22 @@ public DOMNode updateDOMNode() { @Override public void setBackground(Color background) { - if (awtPeerBG != null && !jc.isDisplayable() && !awtPeerBG.equals(background)) + if (awtPeerBG != null + // not for scrollbar && !jc.isDisplayable() + && !awtPeerBG.equals(background)) awtPeerBG = null; - if (isScrollBar ? background != null : jc.isOpaque()) - DOMNode.setStyles(myScrollPaneUI == null && !paintTicks ? jqSlider : sliderTrack, "background-color", JSToolkit.getCSSColor(background)); + if (isScrollBar ? background != null : jc.isOpaque()) { + DOMNode node = (myScrollPaneUI == null && !paintTicks ? jqSlider : sliderTrack); + DOMNode.setStyles(node, "background-color", JSToolkit.getCSSColor(background)); + if (isScrollBar && Color.WHITE.equals(background)) + DOMNode.setStyles(sliderHandle, "background", "#ccc"); + + } if (paintTicks) DOMNode.setStyles(jqSlider, "background-color", "black"); } + @Override protected void setBackgroundFor(DOMNode node, Color color) { setBackground(color); } @@ -281,6 +289,8 @@ protected void setSliderAttr(String key, float val) { public void setSlider() { setSliderAttr("min", min); + // hack is for list to not show bottom line + int max = this.max;//(myScrollPaneUI == null ? this.max : this.max - 1); setSliderAttr("max", max); setSliderAttr("value", val); diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java index 9587cecb1..889acbdff 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java @@ -1,5 +1,6 @@ package swingjs.plaf; +import java.awt.Color; import java.awt.Dimension; import java.awt.Insets; import java.beans.PropertyChangeEvent; @@ -25,25 +26,22 @@ public class JSTextAreaUI extends JSTextViewUI { @Override public DOMNode updateDOMNode() { - -// /** -// * @j2sNative -// * -// * System.out.println("updateDOM textarea xxt");xxt = this; -// */ - + if (domNode == null) { - valueNode = domNode = newDOMObject("textarea", id, "spellcheck", FALSE, "autocomplete", "off"); + valueNode = domNode = newDOMObject("textarea", id, "spellcheck", FALSE, "autocomplete", "off"); setupViewNode(); } - if (((JTextArea) jc).getLineWrap()) - domNode.removeAttribute("wrap"); - else + JTextArea area = (JTextArea) jc; + if (isAWT && !area.isBackgroundSet()) + area.setBackground(new Color(240,240,240)); + DOMNode.setStyles(domNode, "white-space", null, "overflow-wrap", null); + if (area.getLineWrap()) { + DOMNode.setStyles(domNode, "overflow-wrap", area.getWrapStyleWord() ? null : "anywhere"); + } else { DOMNode.setStyles(domNode, "white-space", "pre"); + } textListener.checkDocument(); - setCssFont( - DOMNode.setAttr(domNode, "value", setCurrentText()), - c.getFont()); + setCssFont(DOMNode.setAttr(domNode, "value", setCurrentText()), c.getFont()); updateJSCursor("rewrite"); return super.updateDOMNode(); } @@ -51,8 +49,6 @@ public DOMNode updateDOMNode() { @Override public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); -// Object newValue = e.getNewValue(); -// Object oldValue = e.getOldValue(); switch(prop) { case "ancestor": setJ2sMouseHandler(); @@ -119,7 +115,7 @@ protected String getPropertyPrefix() { protected DOMNode setHTMLElement() { // handled by JScrollPane return DOMNode.setStyles(setHTMLElementCUI(), - "overflow", "hidden", +// "overflow", "hidden", "position", "absolute"); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java index fd9a764d9..8d28a914e 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java @@ -1039,7 +1039,8 @@ public void setEditable(boolean editable) { setEditableCSS(); if (jc.isOpaque()) { Color bg = getBackground(); - setBackgroundCUI(editable || !(bg instanceof UIResource) || inactiveBackground == null ? bg : inactiveBackground); + setBackgroundCUI(editable || !(bg instanceof UIResource) + || inactiveBackground == colorUNKNOWN ? bg : inactiveBackground); } } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextViewUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextViewUI.java index 2632ddab1..58f44d58b 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextViewUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextViewUI.java @@ -46,16 +46,15 @@ protected void undisposeUI(DOMNode node) { @Override protected void setOverflow() { Container parent = jc.getParent(); - if (jc instanceof java.awt.TextArea) { + if (isAWT) { parent = jc; } else if (!(parent instanceof JViewport) || !((parent = parent.getParent()) instanceof JScrollPane)) { - super.setOverflow(); + DOMNode.setStyles(domNode, "overflow", "hidden", "overflow-x", null, "overflow-y", null); return; - } + } JScrollPane sp = (JScrollPane) parent; DOMNode.setStyles(domNode, "overflow", null); - DOMNode.setStyles(domNode, "overflow-x", overflows[sp.getHorizontalScrollBarPolicy() % 10]); - //no - this turns entry of to , "white-space", "nowrap"); + DOMNode.setStyles(domNode, "overflow-x", overflows[sp.getHorizontalScrollBarPolicy() % 10]); DOMNode.setStyles(domNode, "overflow-y", overflows[sp.getVerticalScrollBarPolicy() % 10]); } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSViewportUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSViewportUI.java index 48682d540..c234e7a2a 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSViewportUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSViewportUI.java @@ -50,6 +50,7 @@ public class JSViewportUI extends JSLightweightUI implements PropertyChangeListe public DOMNode updateDOMNode() { if (domNode == null) { domNode = newDOMObject("div", id); + DOMNode.setStyles(domNode, "margin", "1px"); ignoreAllMouseEvents(domNode); } return updateDOMNodeCUI(); @@ -66,15 +67,13 @@ public void uninstallUI(JComponent jc) { @Override public Dimension getPreferredSize(JComponent jc) { - if (debugging) - System.out.println(id + " getPreferredSize"); return null; } - @Override protected DOMNode setHTMLElement() { - return DOMNode.setStyles(setHTMLElementCUI(), "overflow", "hidden"); + return DOMNode.setStyles(setHTMLElementCUI(), "overflow", "hidden", "margin", "1px" + ,"width", (width - 2) + "px", "height", (height-2) + "px"); } } diff --git a/sources/net.sf.j2s.java.core/src/test/TApp2.java b/sources/net.sf.j2s.java.core/src/test/TApp2.java index 0c92d315f..ce0125119 100644 --- a/sources/net.sf.j2s.java.core/src/test/TApp2.java +++ b/sources/net.sf.j2s.java.core/src/test/TApp2.java @@ -41,18 +41,18 @@ public class TApp2 extends Applet { TextArea ta; - - private void addButtonTest() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - Button b = new Button("XyX"); - Label l = new Label("XyX", Label.CENTER); - setLBBounds((Component) b, (Component) l, i, j); - } - } + + private void addButtonTest() { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + Button b = new Button("XyX"); + Label l = new Label("XyX", Label.CENTER); + setLBBounds((Component) b, (Component) l, i, j); + } + } } - private void setLBBounds(Component b, Component l, int i, int j) { + private void setLBBounds(Component b, Component l, int i, int j) { int x = 40 + i * 170; int y = 350 + j * 40; int w = 70 + i * 10; @@ -61,19 +61,21 @@ private void setLBBounds(Component b, Component l, int i, int j) { l.setBounds(x + 105, y, w - 30, h); b.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3)); l.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3)); - l.setBackground(Color.cyan); + l.setBackground(Color.cyan); add(b); add(l); } + long t; + public void init() { setSize(800, 600); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); setBackground(Color.yellow); setLayout(null); - + addButtonTest(); - + JPanel panel = new JPanel(); panel.setBounds(10, 10, 100, 150); add(panel); @@ -94,7 +96,7 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { System.out.println("tf " + e.paramString()); } - + }); panel.add(tf); // Label label = new Label("blue", Label.RIGHT); @@ -111,9 +113,11 @@ public void focusLost(FocusEvent e) { // // // the scrolling to the bottom is only with TextArea, not JTextArea // and then only if the append is AFTER the add - ta = new TextArea("A text\nwith some\nlines and\n no content."); + ta = new TextArea("Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n" + + "Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n" + + "A text\nwith some\nlines and\n no content.", 40, 40, TextArea.SCROLLBARS_VERTICAL_ONLY); add(ta); - ta.setBounds(200, 70, 200,200); + ta.setBounds(200, 70, 200, 200); ta.setFont(new Font(Font.DIALOG, Font.BOLD, 20)); ta.appendText("A text\nwith some\nlines and\n no content."); ta.addFocusListener(new FocusListener() { @@ -127,79 +131,113 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { System.out.println("ta " + e.paramString()); } - + }); - // TextArea ta = new TextArea("A text\nwith some\nlines and\n no content."); // JScrollPane sp = new JScrollPane(ta); // sp.setBounds(200, 70, 100, 80); // add(sp); - - // ta.getSelectionEnd(); + // ta.getSelectionEnd(); ta.setBackground(Color.red); Scrollbar sb = new Scrollbar(0, 30, 0, 0, 100); sb.setBounds(300, 20, 100, 20); add(sb); + sb.setBackground(Color.white); // can be set after! sb.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { - System.out.println("TApp2 sb value " + e.getValue()); + long time = System.currentTimeMillis(); + System.out.println("TApp2 sb value " + e.getValue() + " " + (time - t)); + t = time; } - + }); - sb.setBackground(Color.blue); sb.setForeground(Color.red); + + + + addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent e) { + System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } + + @Override + public void mouseReleased(MouseEvent e) { + System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } + + }); + new TestGraphic(this).testGraphic(); } - - static class TestGraphic{ - private TApp2 tApp2; - public TestGraphic(TApp2 tApp2) { - this.tApp2 = tApp2; + static class TestGraphic { + private TApp2 tApp2; + + public TestGraphic(TApp2 tApp2) { + this.tApp2 = tApp2; } - static { - ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); - } + static { + ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); + } - void testGraphic() { - Button b = new Button("g"); - b.setBounds(300,300,40,20); - // images are created only when a button is displayable - Image i1 = b.createImage(100, 100); - System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); - assert(i1 == null); - tApp2.add(b); - i1 = b.createImage(100, 100); - System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); - b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); - Graphics g = i1.getGraphics(); - Font f = g.getFont(); - System.out.println(f); - - // font/background/foreground are set when the graphic is created - Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30); - b.setFont(f0); - b.setBackground(Color.red); - b.setForeground(Color.green); - g = i1.getGraphics(); - b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); - b.setBackground(Color.white); - b.setForeground(Color.black); - System.out.println("img font=" + g.getFont()); - System.out.println("img bg=" + ((Graphics2D) g).getBackground()); - System.out.println("img fg=" + g.getColor()); - assert(g.getFont().equals(f0)); - assert(g.getColor() == Color.green); - assert(((Graphics2D) g).getBackground() == Color.red); - System.out.println("Tapp2 OK"); + void testGraphic() { + Button b = new Button("g"); + b.setBounds(300, 300, 40, 20); + // images are created only when a button is displayable + Image i1 = b.createImage(100, 100); + System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); + assert (i1 == null); + tApp2.add(b); + i1 = b.createImage(100, 100); + System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); + b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); + Graphics g = i1.getGraphics(); + Font f = g.getFont(); + System.out.println(f); + + // font/background/foreground are set when the graphic is created + Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30); + b.setFont(f0); + b.setBackground(Color.red); + b.setForeground(Color.green); + g = i1.getGraphics(); + b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); + b.setBackground(Color.white); + b.setForeground(Color.black); + System.out.println("img font=" + g.getFont()); + System.out.println("img bg=" + ((Graphics2D) g).getBackground()); + System.out.println("img fg=" + g.getColor()); + assert (g.getFont().equals(f0)); + assert (g.getColor() == Color.green); + assert (((Graphics2D) g).getBackground() == Color.red); + System.out.println("Tapp2 OK"); + } } - } public void paint(Graphics g) { super.paint(g); @@ -257,39 +295,6 @@ public void paint(Graphics g) { // g.drawString("SwingJS", 200, 30); // g.setColor(Color.white); // g.drawString("SwingJS", 200, 30); - - - addMouseListener(new MouseListener() { - - @Override - public void mouseClicked(MouseEvent e) { - System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - @Override - public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) { - System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - @Override - public void mouseReleased(MouseEvent e) { - System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - }); } } - diff --git a/sources/net.sf.j2s.java.core/src/test/TApp2_Swing.java b/sources/net.sf.j2s.java.core/src/test/TApp2_Swing.java index 00aca5348..20fd75e11 100644 --- a/sources/net.sf.j2s.java.core/src/test/TApp2_Swing.java +++ b/sources/net.sf.j2s.java.core/src/test/TApp2_Swing.java @@ -17,30 +17,33 @@ import java.awt.event.FocusListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.geom.Line2D; import javax.swing.JApplet; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollBar; +import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class TApp2_Swing extends JApplet { JTextArea ta; - - private void addButtonTest() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - JButton b = new JButton("XyX"); - JLabel l = new JLabel("XyX", JLabel.CENTER); - setLBBounds((Component) b, (Component) l, i, j); - } - } + + private void addButtonTest() { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + JButton b = new JButton("XyX"); + JLabel l = new JLabel("XyX", JLabel.CENTER); + setLBBounds((Component) b, (Component) l, i, j); + } + } } - private void setLBBounds(Component b, Component l, int i, int j) { + private void setLBBounds(Component b, Component l, int i, int j) { int x = 40 + i * 170; int y = 350 + j * 40; int w = 70 + i * 10; @@ -49,13 +52,12 @@ private void setLBBounds(Component b, Component l, int i, int j) { l.setBounds(x + 105, y, w - 30, h); b.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3)); l.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10 + i * 3)); - l.setBackground(Color.cyan); + l.setBackground(Color.cyan); add(b); add(l); } - - public void init() { + public void init() { setSize(800, 600); addButtonTest(); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); @@ -67,6 +69,24 @@ public void init() { panel.setLayout(null); panel.setBackground(Color.red); panel.setForeground(Color.green); + + JComponent jc = new JComponent() { + private static final long serialVersionUID = 1L; + + @Override + public void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.white); +// g2.setStroke(new BasicStroke(10)); + g2.draw(new Line2D.Float(30, 20, 80, 90)); + g2.fillRect(30, 20, 10, 100); + } + }; + jc.setBounds(50,50,150,150); + jc.setBackground(Color.blue); + jc.setOpaque(true); + panel.add(jc); + JTextField tf = new JTextField("Text"); tf.setBounds(5, 5, 50, 24); tf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); @@ -81,7 +101,7 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { System.out.println("tf " + e.paramString()); } - + }); panel.add(tf); // Label label = new Label("blue", Label.RIGHT); @@ -98,10 +118,19 @@ public void focusLost(FocusEvent e) { // // // the scrolling to the bottom is only with TextArea, not JTextArea // and then only if the append is AFTER the add - ta = new JTextArea("A text\nwith some\nlines and\n no content."); - add(ta); - ta.setBounds(200, 70, 200,200); + ta = new JTextArea("Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n" + + "Averyveryveryveryveryveryveryverylongword\n" + "Averyveryveryveryveryveryveryverylongword\n" + + "A text\nwith some\nlines and\n no content."); + JScrollPane jsp = new JScrollPane(ta); + add(jsp); + jsp.setBounds(200, 70, 200, 200); + ta.setWrapStyleWord(true); + // add(ta); + // ta.setBounds(200, 70, 200,200); ta.setFont(new Font(Font.DIALOG, Font.BOLD, 20)); + //ta.setLineWrap(true); + ta.setWrapStyleWord(false); + jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); ta.append("A text\nwith some\nlines and\n no content."); ta.addFocusListener(new FocusListener() { @@ -114,17 +143,15 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { System.out.println("ta " + e.paramString()); } - + }); - // TextArea ta = new TextArea("A text\nwith some\nlines and\n no content."); // JScrollPane sp = new JScrollPane(ta); // sp.setBounds(200, 70, 100, 80); // add(sp); - - // ta.getSelectionEnd(); + // ta.getSelectionEnd(); ta.setBackground(Color.red); JScrollBar sb = new JScrollBar(0, 30, 0, 0, 100); sb.setBounds(300, 20, 100, 20); @@ -135,56 +162,88 @@ public void focusLost(FocusEvent e) { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("TApp2 sb value " + e.getValue()); } + + }); + + addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent e) { + System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } + + @Override + public void mouseReleased(MouseEvent e) { + System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); + } }); + new TestGraphic2(this).testGraphic(); } - - static class TestGraphic2{ - private TApp2_Swing tApp2; - public TestGraphic2(TApp2_Swing tApp2) { - this.tApp2 = tApp2; + static class TestGraphic2 { + private TApp2_Swing tApp2; + + public TestGraphic2(TApp2_Swing tApp2) { + this.tApp2 = tApp2; } - static { - ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); - } + static { + ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); + } - void testGraphic() { - JButton b = new JButton("g"); - b.setBounds(300,300,40,20); - // images are created only when a button is displayable - Image i1 = b.createImage(100, 100); - System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); - - tApp2.add(b); - i1 = b.createImage(100, 100); - System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); - b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); - Graphics g = i1.getGraphics(); - Font f = g.getFont(); - System.out.println(f); - - // font/background/foreground are set when the graphic is created - Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30); - b.setFont(f0); - b.setBackground(Color.red); - b.setForeground(Color.green); - g = i1.getGraphics(); - b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); - b.setBackground(Color.white); - b.setForeground(Color.black); - System.out.println("img font=" + g.getFont()); - System.out.println("img bg=" + ((Graphics2D) g).getBackground()); - System.out.println("img fg=" + g.getColor()); - assert(g.getFont().equals(f0)); - assert(g.getColor() == Color.green); - assert(((Graphics2D) g).getBackground() == Color.red); - System.out.println("Tapp2 OK"); + void testGraphic() { + JButton b = new JButton("g"); + b.setBounds(300, 300, 40, 20); + // images are created only when a button is displayable + Image i1 = b.createImage(100, 100); + System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); + + tApp2.add(b); + i1 = b.createImage(100, 100); + System.out.println("b.isDisplayable " + b.isDisplayable() + " " + i1); + b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); + Graphics g = i1.getGraphics(); + Font f = g.getFont(); + System.out.println(f); + + // font/background/foreground are set when the graphic is created + Font f0 = new Font(Font.DIALOG, Font.PLAIN, 30); + b.setFont(f0); + b.setBackground(Color.red); + b.setForeground(Color.green); + g = i1.getGraphics(); + b.setFont(new Font(Font.SERIF, Font.BOLD, 10)); + b.setBackground(Color.white); + b.setForeground(Color.black); + System.out.println("img font=" + g.getFont()); + System.out.println("img bg=" + ((Graphics2D) g).getBackground()); + System.out.println("img fg=" + g.getColor()); + assert (g.getFont().equals(f0)); + assert (g.getColor() == Color.green); + assert (((Graphics2D) g).getBackground() == Color.red); + System.out.println("Tapp2 OK"); + } } - } public void paint(Graphics g) { super.paint(g); @@ -197,7 +256,7 @@ public void paint(Graphics g) { g.setColor(Color.blue); g.drawRoundRect(120, 200, 80, 150, 20, 20); - g.fillRoundRect(210, 200, 80, 150, 20, 20); + g.fillRoundRect(510, 200, 80, 150, 20, 20); // test AlphaComposite.Clear @@ -242,38 +301,6 @@ public void paint(Graphics g) { // g.drawString("SwingJS", 200, 30); // g.setColor(Color.white); // g.drawString("SwingJS", 200, 30); - - - addMouseListener(new MouseListener() { - - @Override - public void mouseClicked(MouseEvent e) { - System.out.println(">>>>mouseClicked: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - @Override - public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) { - System.out.println(">>>>mousePressed: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - @Override - public void mouseReleased(MouseEvent e) { - System.out.println(">>>>mouseReleased: " + e.getModifiers() + " " + e.getModifiersEx() + " " + e); - } - - }); } } \ No newline at end of file diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java index af09cf59e..d072ea551 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java @@ -10,6 +10,7 @@ //web_Features= graphics, AWT-to-Swing import java.awt.Adjustable; +import java.awt.Choice; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; @@ -33,6 +34,7 @@ import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JSlider; +import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JToggleButton; import javax.swing.JViewport; @@ -57,7 +59,7 @@ public class Test_Applet_Scroll extends JApplet implements ChangeListener { boolean preferred = true; private JScrollBar hsb; - + void setSize(JComponent c, int x, int y) { if (preferred) c.setPreferredSize(new Dimension(x, y)); @@ -78,8 +80,7 @@ public void test(Iterable i) { @Override public void init() { - BasicSliderUI ui; - + final JLabel label = new JLabel("hello"); // label.setBounds(0, 60, 200, 60); setSize(label, 80, 50); @@ -201,7 +202,22 @@ public void mouseMoved(MouseEvent e) { }); JPanel p = new JPanel(); + + JTextArea area = new JTextArea("testing", 10,20) { + protected int getColumnWidth() { + int i = super.getColumnWidth(); + System.out.println("colwidth is " + i + " " + p.getFontMetrics(p.getFont()).stringWidth("m")); + return i; + } + protected int getRowHeight() { + int i = super.getRowHeight(); + System.out.println("rowHeight is " + i + " " + p.getFontMetrics(p.getFont()).getHeight()); + return i; + } + }; + p.add(area); + // the first two buttons act like radio buttons; only one is ever ON JScrollBar hbar = mkBar(p, tf, Adjustable.VERTICAL, 20, 200); @@ -301,7 +317,9 @@ public void mouseMoved(MouseEvent e) { hbar.setToolTipText("this is scrollbar 1"); mkSlider(p, tf, Adjustable.VERTICAL, 20, 200).setToolTipText("this is slider 2"); - mkSlider(p, tf, Adjustable.VERTICAL, 20, 200).setInverted(true); + JSlider s = mkSlider(p, tf, Adjustable.VERTICAL, 20, 200); + s.setInverted(true); + s.setSnapToTicks(true); p.add(label); label.setToolTipText("this is label"); p.add(tf); diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java index 9f040fb99..8977e4b5f 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java @@ -20,6 +20,7 @@ import java.awt.Panel; import java.awt.ScrollPane; import java.awt.Scrollbar; +import java.awt.TextArea; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.AdjustmentEvent; @@ -33,6 +34,8 @@ import java.awt.event.MouseWheelListener; import java.text.DecimalFormat; +import javax.swing.JTextArea; + /** * Creates a ScrollPane with a mix of SwingJS and AWT components. * @@ -190,6 +193,22 @@ public void mouseMoved(MouseEvent e) { Panel p = new Panel(); + + + TextArea area = new TextArea("testing", 10,20) { + protected int getColumnWidth() { + int i = super.getColumnWidth(); + System.out.println("colwidth is " + i + " " + p.getFontMetrics(p.getFont()).stringWidth("m")); + return i; + } + protected int getRowHeight() { + int i = super.getRowHeight(); + System.out.println("rowHeight is " + i + " " + p.getFontMetrics(p.getFont()).getHeight()); + return i; + } + }; + p.add(area); + Scrollbar hbar = mkBar(p, tf, Adjustable.VERTICAL, 20, 200); // the first two buttons act like radio buttons; only one is ever ON @@ -280,15 +299,7 @@ public void mouseMoved(MouseEvent e) { sp.add(p); sp.setSize(500, 250); Dimension d = sp.getPreferredSize(); - System.out.println(sp.getPeer() + " " + sp.getLayout()); - System.out.println("sp pref size " + d); -// sp.getViewport().add(p); -// getContentPane().add(sp); add(sp); -// sp.getViewport().addChangeListener(this); -// hsb = sp.getHorizontalScrollBar(); -// hsb.setUnitIncrement(100); -// button2.setToolTipText("this is hsb"); mkSlider(p, tf, Adjustable.VERTICAL, 20, 200); @@ -309,7 +320,7 @@ public void mouseMoved(MouseEvent e) { // framesPerSecond.setForeground(Color.BLACK); // mkSlider(p, tf, Adjustable.HORIZONTAL, 100, 20); - repaint(); + System.out.println("tas " + area.getPreferredSize()); } Scrollbar mkBar(Panel p, final TextField tf, int orient, int x, int y) { diff --git a/sources/net.sf.j2s.java.core/src/test/components/ListDemo.java b/sources/net.sf.j2s.java.core/src/test/components/ListDemo.java index febd9ccfc..f5391182c 100644 --- a/sources/net.sf.j2s.java.core/src/test/components/ListDemo.java +++ b/sources/net.sf.j2s.java.core/src/test/components/ListDemo.java @@ -74,8 +74,8 @@ public ListDemo() { listModel.addElement("John Smith"); listModel.addElement("Kathy Green"); listModel.addElement("Rose Red"); - listModel.addElement("Negro Black"); - listModel.addElement("Blanco White"); + listModel.addElement("Nearly Black"); + listModel.addElement("Pearly White"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); diff --git a/sources/net.sf.j2s.java.core/src/test/components/ListDemoAWT.java b/sources/net.sf.j2s.java.core/src/test/components/ListDemoAWT.java index 1944c1a77..279a88567 100644 --- a/sources/net.sf.j2s.java.core/src/test/components/ListDemoAWT.java +++ b/sources/net.sf.j2s.java.core/src/test/components/ListDemoAWT.java @@ -58,7 +58,7 @@ public ListDemoAWT() { super(new BorderLayout()); String[] names = new String[] {"Jane Doe", "John Smith", - "Kathy Green", "Rose Red", "Negro Black", "Blanco White" }; + "Kathy Green", "Rose Red", "Nearly Black", "Pearly White" }; // Create the list and put it in a scroll pane. list = new List(5); for (int i = 0; i < names.length; i++) diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js index a881921d6..325710bb7 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js @@ -1546,7 +1546,10 @@ if (!target) { if (J2S._dmouseOwner) { - J2S._dmouseDrag(ev); + if (J2S._dmouseDrag) + J2S._dmouseDrag(ev); + else + J2S._dmouseOwner = null; } if (J2S._traceMouseMove) diff --git a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js index 4b2c86ec1..8deb7dff3 100644 --- a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js +++ b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js @@ -12211,7 +12211,10 @@ if (!target) { if (J2S._dmouseOwner) { - J2S._dmouseDrag(ev); + if (J2S._dmouseDrag) + J2S._dmouseDrag(ev); + else + J2S._dmouseOwner = null; } if (J2S._traceMouseMove)