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 59db2cab0..7f0d3a74c 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 b06e62268..ec9d260fc 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20190814182015 +20190817161814 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 59db2cab0..7f0d3a74c 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 b06e62268..ec9d260fc 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 @@ -20190814182015 +20190817161814 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 59db2cab0..7f0d3a74c 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/JSDialog.java b/sources/net.sf.j2s.java.core/src/java/awt/JSDialog.java index 9953fbbdf..eb929675a 100644 --- a/sources/net.sf.j2s.java.core/src/java/awt/JSDialog.java +++ b/sources/net.sf.j2s.java.core/src/java/awt/JSDialog.java @@ -690,10 +690,9 @@ protected String constructComponentName() { public void addNotify() { synchronized (getTreeLock()) { getOrCreatePeer(); - if (parent != null) { - parent.addNotify(); - } - super.addNotify(); + if (parent != null && parent.getPeer() == null) + parent.addNotify(); + super.addNotify(); } } diff --git a/sources/net.sf.j2s.java.core/src/java/lang/Class.java b/sources/net.sf.j2s.java.core/src/java/lang/Class.java index 63a71c5cc..c8dfba2f9 100644 --- a/sources/net.sf.j2s.java.core/src/java/lang/Class.java +++ b/sources/net.sf.j2s.java.core/src/java/lang/Class.java @@ -115,7 +115,7 @@ private static class JSClass { public String __CLASS_NAME__; } private JSClass $clazz$; // BH SwingJS - private String[] $methodList$; // BH SwingJS for proxy interfaces + public String[] $methodList$; // BH see j2sClazz.js Clazz.getClass, from interface parameters // private static native void registerNatives(); // @@ -139,6 +139,7 @@ private Class() { * * @return a string representation of this class object. */ + @Override public String toString() { return (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) + getName(); } @@ -769,7 +770,7 @@ ClassLoader getClassLoader0() { * Specification, 3rd edition * @since 1.5 */ - @SuppressWarnings("unchecked") + @Override public TypeVariable>[] getTypeParameters() { // if (getGenericSignature() != null) // return (TypeVariable>[]) getGenericInfo().getTypeParameters(); @@ -1811,7 +1812,7 @@ private void addField(Field[] fields, String m, int modifiers) { * * @param name * the name of the method - * @param parameterTypes + * @param paramTypes * the list of parameters * @return the {@code Method} object that matches the specified {@code name} * and {@code parameterTypes} @@ -1852,7 +1853,7 @@ public Method getMethod(String name, Class... paramTypes) throws NoSuchMethod Method m = new Method(this, name, paramTypes, null, null, 0); if (!isInterface()) { Object o = null; - String qname = name + argumentTypesToString(paramTypes); + String qname = m.getSignature(); /** * @j2sNative * @@ -1925,15 +1926,11 @@ public Method getMethod(String name, Class... paramTypes) throws NoSuchMethod * * @since JDK1.1 */ - @SuppressWarnings("unchecked") public Constructor getConstructor(Class... parameterTypes) throws NoSuchMethodException, SecurityException { // be very careful not to change the stack depth of this // checkMemberAccess call for security reasons // see java.lang.SecurityManager.checkMemberAccess // checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader()); - Class[] x = parameterTypes; - if (parameterTypes == null) - parameterTypes = new Class[0]; return new Constructor(this, parameterTypes, new Class[0], Member.PUBLIC); // return getConstructor0(parameterTypes, Member.PUBLIC); } @@ -3218,6 +3215,8 @@ public static String argumentTypesToString(Class[] parameterTypes) { // */ // private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; + public static final Class[] NO_PARAMETERS = new Class[0]; + // /** // * Returns the assertion status that would be assigned to this class if it // * were to be initialized at the time this method is invoked. If this class @@ -3295,7 +3294,7 @@ public boolean isEnum() { // private static ReflectionFactory reflectionFactory; // // To be able to query system properties as soon as they're available - private static boolean initted = false; +// private static boolean initted = false; // private static void checkInitted() { // if (initted) @@ -3558,8 +3557,9 @@ public boolean equals(Object o) { /** * A SwingJS method for Constructor and Method * - * @param parameterTypes + * @param types * @param args + * @param isProxy * @return */ public static Object[] getArgumentArray(Class[] types, Object[] args, boolean isProxy) { diff --git a/sources/net.sf.j2s.java.core/src/java/lang/reflect/Constructor.java b/sources/net.sf.j2s.java.core/src/java/lang/reflect/Constructor.java index 24505d620..1ef59ab0e 100644 --- a/sources/net.sf.j2s.java.core/src/java/lang/reflect/Constructor.java +++ b/sources/net.sf.j2s.java.core/src/java/lang/reflect/Constructor.java @@ -46,7 +46,10 @@ public Constructor(Class declaringClass, Class[] parameterTypes, Class[ // NO!! wrong: all of the SwingJS primitive classes run without parameterization //if (";Integer;Long;Short;Byte;Float;Double;".indexOf(";" + declaringClass.getName() + ";") >= 0) //parameterTypes = null; - this.parameterTypes = parameterTypes; + // Special case - constructors with parameters have c$$, not just c$. For whatever reason! + // This signals NOT to add "$" if there are no parameters. + if (parameterTypes == null) + parameterTypes = Class.NO_PARAMETERS; this.signature = "c$" + Class.argumentTypesToString(parameterTypes); constr = /** @j2sNative this.Class_.$clazz$[this.signature] || */ null; } diff --git a/sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java b/sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java index 5285747d4..1ba96c54b 100644 --- a/sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java +++ b/sources/net.sf.j2s.java.core/src/java/lang/reflect/Method.java @@ -46,11 +46,14 @@ public Method(Class declaringClass, String name, Class[] parameterTypes, C Class[] checkedExceptions, int modifiers) { this.Class_ = declaringClass; this.name = name; - this.parameterTypes = parameterTypes; + this.parameterTypes = (parameterTypes == null ? Class.NO_PARAMETERS : parameterTypes); this.returnType = returnType; this.exceptionTypes = checkedExceptions; this.modifiers = modifiers; - this.signature = name + Class.argumentTypesToString(parameterTypes); + // modifier PUBLIC means this is from Class.java getMethods + if (parameterTypes != null && parameterTypes.length == 0) + parameterTypes = null; + this.signature = (declaringClass.$methodList$ == null ? name + Class.argumentTypesToString(parameterTypes) : name); } /** diff --git a/sources/net.sf.j2s.java.core/src/javax/xml/stream/Location.java b/sources/net.sf.j2s.java.core/src/javax/xml/stream/Location.java new file mode 100644 index 000000000..fd5c8c6d7 --- /dev/null +++ b/sources/net.sf.j2s.java.core/src/javax/xml/stream/Location.java @@ -0,0 +1,77 @@ +/* + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * Copyright (c) 2009 by Oracle Corporation. All Rights Reserved. + */ + +package javax.xml.stream; + +/** + * Provides information on the location of an event. + * + * All the information provided by a Location is optional. For example + * an application may only report line numbers. + * + * @version 1.0 + * @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved. + * @since 1.6 + */ +public interface Location { + /** + * Return the line number where the current event ends, + * returns -1 if none is available. + * @return the current line number + */ + int getLineNumber(); + + /** + * Return the column number where the current event ends, + * returns -1 if none is available. + * @return the current column number + */ + int getColumnNumber(); + + /** + * Return the byte or character offset into the input source this location + * is pointing to. If the input source is a file or a byte stream then + * this is the byte offset into that stream, but if the input source is + * a character media then the offset is the character offset. + * Returns -1 if there is no offset available. + * @return the current offset + */ + int getCharacterOffset(); + + /** + * Returns the public ID of the XML + * @return the public ID, or null if not available + */ + public String getPublicId(); + + /** + * Returns the system ID of the XML + * @return the system ID, or null if not available + */ + public String getSystemId(); +} diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSGraphicsConfiguration.java b/sources/net.sf.j2s.java.core/src/swingjs/JSGraphicsConfiguration.java index ccd9076cc..80f6510d8 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSGraphicsConfiguration.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSGraphicsConfiguration.java @@ -56,9 +56,9 @@ protected BufferedImage newBufferedImage(ColorModel cm, WritableRaster wr, boolean alphaPremultiplied, Hashtable properties) { return (BufferedImage) Interface.getInstanceWithParams( "java.awt.image.BufferedImage", new Class[] { ColorModel.class, - WritableRaster.class, Boolean.class, Hashtable.class }, + WritableRaster.class, boolean.class, Hashtable.class }, new Object[] { cm, wr, - alphaPremultiplied ? Boolean.TRUE : Boolean.FALSE, properties }); + alphaPremultiplied, properties }); } @Override diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java b/sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java index 363ccb2cc..729a8a997 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java @@ -467,7 +467,7 @@ public static void checkConsume(InputEvent e) { public static JComponent getJ2SEventTarget(MouseEvent e) { - return /** @j2sNative e.bdata.source || */null; + return /** @j2sNative e.bdata && e.bdata.source || */null; } private static boolean isPopupTrigger(int id, int mods, boolean isWin) { @@ -495,8 +495,8 @@ private static boolean isPopupTrigger(int id, int mods, boolean isWin) { private boolean keyAction(int id, Object jqevent, long time) { JComponent c = /** @j2sNative - jqevent.target["data-shadowkeycomponent"] || jqevent.target["data-keycomponent"] - */null; + jqevent.target["data-shadowkeycomponent"] || jqevent.target["data-keycomponent"] || + */null; return JSKeyEvent.dispatchKeyEvent(c, id, jqevent, time); } 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 8459dea73..571d54439 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java @@ -964,12 +964,13 @@ public static void consumeEvent(Object e) { // SwingJS stop any further processing at all within the browser Object jqevent = null; if (e instanceof InputEvent) { - jqevent = /** @j2sNative e.bdata.jqevent || */null; + jqevent = /** @j2sNative e.bdata && e.bdata.jqevent || */null; } else { jqevent = e; } if (jqevent == null) return; + /** * @j2sNative * jqevent.stopPropagation(); 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 07a563393..4a13ceedb 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 @@ -1103,6 +1103,18 @@ protected void bindJSKeyEvents(DOMNode node, boolean addFocus) { } } + + + /** + * Signal to swingjs2 to ignore the event, as it has been handled already. + * + * @param jqevent + */ + void setIgnoreEvent(Object jqevent) { + /** + * @j2sNative jqevent.originalEvent.xhandled = true; + */ + } /** * Allows mouse and keyboard handling via an overridden method * diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java index 286a1da9a..e1eada088 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java @@ -949,6 +949,7 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) { * jQueryEvent.preventDefault(); * jQueryEvent.stopPropagation(); */ + setIgnoreEvent(jQueryEvent); return HANDLED; } } 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 0e18779ef..d7b21d723 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 @@ -3542,4 +3542,5 @@ public void setCaretFromJS() { setJavaMarkAndDot(pt); } + } diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java index 20569864f..73467c25b 100644 --- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java +++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/TextListener.java @@ -160,6 +160,7 @@ void handleJSTextEvent(JSTextUI ui, int eventType, Object jqevent) { lastKeyEvent = eventType; if (setCaret) ui.setJavaMarkAndDot(markDot); + ui.setIgnoreEvent(jqevent); } @SuppressWarnings("unused") 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 bd782dfe1..08471bcb2 100644 --- a/sources/net.sf.j2s.java.core/src/test/TApp2.java +++ b/sources/net.sf.j2s.java.core/src/test/TApp2.java @@ -29,6 +29,8 @@ import java.awt.event.AdjustmentListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; @@ -120,6 +122,25 @@ public void focusLost(FocusEvent e) { 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.addKeyListener(new KeyListener() { + + @Override + public void keyTyped(KeyEvent e) { + System.out.println("keyTyped"); + } + + @Override + public void keyPressed(KeyEvent e) { + System.out.println("keypressed"); + } + + @Override + public void keyReleased(KeyEvent e) { + System.out.println("keyReleased"); + + } + + }); ta.addFocusListener(new FocusListener() { @Override diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Class.java b/sources/net.sf.j2s.java.core/src/test/Test_Class.java index ed47c792b..d5adfc13b 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Class.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Class.java @@ -63,11 +63,11 @@ public void propertyChange(PropertyChangeEvent event) { @Override public void mouseClicked(MouseEvent e) { - System.out.println("!!!"); + System.out.println("mouseClicked1"); Test_Class.this.showt(); showt(); assert(Test_Class.this == me); - System.out.println("!!!"); + System.out.println("mouseClicked2"); } @Override diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Editor.java b/sources/net.sf.j2s.java.core/src/test/Test_Editor.java index fa571f49c..7721ab21c 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Editor.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Editor.java @@ -56,7 +56,6 @@ import javax.swing.Timer; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; -import javax.swing.text.BadLocationException; import javax.swing.text.DefaultCaret; import javax.swing.text.Document; import javax.swing.text.Element; @@ -68,7 +67,7 @@ public class Test_Editor extends JFrame implements DropTargetListener { - String test = " 345\n67890\n1234567890\n 345\n "; + String test = " 345567890112345678903 345\n "; // private static void logClass(String name) { // ConsoleHandler consoleHandler = new ConsoleHandler(); @@ -132,13 +131,14 @@ public Test_Editor() { // js.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JTextArea area = getArea(); + area.addKeyListener(ka); JScrollPane js2 = new JScrollPane(area); js2.setPreferredSize(new Dimension(300, 300)); js2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);//_AS_NEEDED); js2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);//NEVER);//VERTICAL_SCROLLBAR_AS_NEEDED); - JTextField field = getField("field1"); - JTextField field2 = getField("field2"); + JTextField field = getField(); + JTextField field2 = getField(); JMenuBar mb = getMenuBar(ptop); @@ -219,12 +219,12 @@ public void mouseExited(MouseEvent e) { KeyStroke[] a = ((JComponent) mb.getComponent(0)).getRegisteredKeyStrokes(); - ////System.out.println("menubar menu registration: " + a.length); + System.out.println("menubar menu registration: " + a.length); main.setJMenuBar(mb); a = ((JComponent) mb.getComponent(0)).getRegisteredKeyStrokes(); - ////System.out.println("menubar menu registration: " + a.length); + System.out.println("menubar menu registration: " + a.length); main.add(full); main.addFocusListener(fl); @@ -303,7 +303,7 @@ private JPanel getButtonPanel(JTextPane editor, JTextArea area, JTextArea area1, @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); editor.setCaretPosition(0); area.setCaretPosition(0); area.requestFocus(); @@ -321,7 +321,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); editor.setText(""); // btop.setEnabled(!btop.isEnabled()); } @@ -335,7 +335,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); editor.getCaret().setDot(editor.getCaret().getDot() + 1); editor.requestFocus(); } @@ -348,7 +348,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); area.getCaret().setDot(area.getCaret().getDot() + 1); area.requestFocus(); } @@ -362,7 +362,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); editor.getCaret().setDot(7); editor.getCaret().moveDot(10); editor.getCaret().setSelectionVisible(true); @@ -382,7 +382,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); // editor.setCaretPosition(editor.getDocument().getLength()); area.setCaretPosition(area.getDocument().getLength()); area.requestFocus(); @@ -398,7 +398,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); area1.setCaretPosition(area1.getText().length()); area1.requestFocus(); } @@ -412,7 +412,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); area.getCaret().setDot(7); area.getCaret().moveDot(10); area.getCaret().setSelectionVisible(true); @@ -429,7 +429,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); area.append("\ntesting" + ++n); // area.requestFocus(); } @@ -443,7 +443,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); area1.requestFocus(); area1.append("\ntesting" + ++n); } @@ -460,7 +460,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); field.setCaretPosition(3); field.getCaret().moveDot(5); field.getCaret().setSelectionVisible(true); @@ -479,15 +479,13 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { + System.out.println("Test_Editor action " + getID(e.getSource())); int start = editor.getSelectionStart(); int end = editor.getSelectionEnd(); if (end == start) return; - ////System.out.println("Test_Editor BOLD action " + start + " " + end + " " + getID(e.getSource())); Element ch = editor.getStyledDocument().getCharacterElement(start); - boolean isBold = !StyleConstants.isBold(ch.getAttributes()); - ////System.out.println("Test_Editor BOLD action " + isBold + " " + ch); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setForeground(attrs, isBold ? Color.red : Color.black); StyleConstants.setBold(attrs, isBold); @@ -507,7 +505,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); int start = editor.getSelectionStart(); int end = editor.getSelectionEnd(); if (end == start) @@ -525,20 +523,14 @@ public void actionPerformed(ActionEvent e) { return panel; } - private JTextField getField(String name) { + private JTextField getField() { - JTextField field = new JTextField("testing" + name); + JTextField field = new JTextField("testing"); field.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor field insert action " + getID(e.getSource())); - try { - editor.getDocument().insertString(3, field.getText(), null); - } catch (BadLocationException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + System.out.println("Test_Editor action " + getID(e.getSource())); } }); @@ -547,7 +539,7 @@ public void actionPerformed(ActionEvent e) { @Override public void caretUpdate(CaretEvent e) { - ////System.out.println("Test_Editor JTextField caret:" + e); + System.out.println("Test_Editor JTextField caret:" + e); } }); @@ -557,7 +549,7 @@ public void caretUpdate(CaretEvent e) { private JTextArea getArea() { JTextArea area = new JTextArea() { public void setCarentPosition(int i) { - ////System.out.println("Test_Editor JTextArea setCP " + i); + System.out.println("Test_Editor JTextArea setCP " + i); super.setCaretPosition(i); } }; @@ -566,7 +558,7 @@ public void setCarentPosition(int i) { DefaultCaret c = new DefaultCaret() { @Override protected void fireStateChanged() { - ////System.out.println("Test_Editor area caret firestatechanged " + area.getCaretPosition()); + System.out.println("Test_Editor area caret firestatechanged " + area.getCaretPosition()); super.fireStateChanged(); } @@ -582,7 +574,7 @@ protected void fireStateChanged() { @Override public void caretUpdate(CaretEvent e) { - ////System.out.println("Test_Editor JTextArea caret:" + e); + System.out.println("Test_Editor JTextArea caret:" + e); } }); @@ -592,19 +584,11 @@ public void caretUpdate(CaretEvent e) { return area; } - JTextPane editor; - private JTextPane getEditor() { - editor = new JTextPane() { - }; - - ActionListener xxxx = editor.getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false)); - ////System.out.println(xxxx); - - editor.addKeyListener(ka); + JTextPane editor = new JTextPane(); editor.setPreferredSize(new Dimension(400, 300)); - ////System.out.println("Test_Editor " + editor.getDocument()); - ////System.out.println("Test_Editor " + editor.getEditorKit()); + System.out.println("Test_Editor " + editor.getDocument()); + System.out.println("Test_Editor " + editor.getEditorKit()); editor.setText(test); // editor.setEditable(false); @@ -612,7 +596,7 @@ private JTextPane getEditor() { .println("Test_Editor Element count = " + editor.getDocument().getRootElements()[0].getElementCount()); editor.setBackground(new Color(200, 200, 200)); editor.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16)); - ////System.out.println("Test_Editor editor pref size " + editor.getPreferredSize()); + System.out.println("Test_Editor editor pref size " + editor.getPreferredSize()); Style style = editor.addStyle("Red", null); StyleConstants.setForeground(style, Color.red); @@ -621,7 +605,7 @@ private JTextPane getEditor() { @Override public void propertyChange(PropertyChangeEvent evt) { - ////System.out.println("Test_Editor prop change " + evt.getPropertyName() + " " + evt); + System.out.println("Test_Editor prop change " + evt.getPropertyName() + " " + evt); } }); @@ -630,7 +614,7 @@ public void propertyChange(PropertyChangeEvent evt) { @Override public void caretUpdate(CaretEvent e) { - ////System.out.println("Test_Editor JTextPane caret:" + e + " len="+ editor.getDocument().getLength() + "\n");// + editor.getText()); + System.out.println("Test_Editor JTextPane caret:" + e); // dumpRoot(editor.getDocument()); } @@ -649,17 +633,23 @@ public void caretUpdate(CaretEvent e) { KeyListener ka = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { + System.out.println("ok1"); showKeyEvent(e); + System.out.println("ok2"); } @Override public void keyTyped(KeyEvent e) { + System.out.println("ok3"); showKeyEvent(e); + System.out.println("ok4"); } @Override public void keyReleased(KeyEvent e) { + System.out.println("ok5"); showKeyEvent(e); + System.out.println("ok6"); } }; @@ -676,14 +666,14 @@ public void mousePressed(MouseEvent e) { Component c = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); -// System.out.println("Test_Editor " + e.getSource() + " mouse pressed " + e.getX() + " " + e.getY() -// + " focus owner is " + (c == null ? null : c.getClass().getName())); + System.out.println("Test_Editor " + e.getSource() + " mouse pressed " + e.getX() + " " + e.getY() + + " focus owner is " + (c == null ? null : c.getClass().getName())); } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub - ////System.out.println("Test_Editor mouse released" + e.getX() + " " + e.getY()); + System.out.println("Test_Editor mouse released" + e.getX() + " " + e.getY()); } @@ -705,15 +695,15 @@ public void mouseExited(MouseEvent e) { @Override public void focusGained(FocusEvent e) { -// System.out.println( -// "Test_Editor focus GAINED " + getID(e.getSource()) + " opp:" + getID(e.getOppositeComponent())); + System.out.println( + "Test_Editor focus GAINED " + getID(e.getSource()) + " opp:" + getID(e.getOppositeComponent())); // ptop.setBackground(Color.LIGHT_GRAY); } @Override public void focusLost(FocusEvent e) { -// System.out.println( -// "Test_Editor focus LOST " + getID(e.getSource()) + " opp:" + getID(e.getOppositeComponent())); + System.out.println( + "Test_Editor focus LOST " + getID(e.getSource()) + " opp:" + getID(e.getOppositeComponent())); // ptop.setBackground(Color.MAGENTA); } @@ -723,20 +713,20 @@ private JMenuBar getMenuBar(JPanel ptop) { JMenuBar mb = new JMenuBar() { @Override public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager m) { - ////System.out.println("Test_Editor path length=" + path.length); + System.out.println("Test_Editor path length=" + path.length); super.processKeyEvent(e, path, m); } }; JMenu mb1 = new JMenu("Test") { @Override public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager m) { - ////System.out.println("Test_Editor JMenu path length=" + path.length); + System.out.println("Test_Editor JMenu path length=" + path.length); super.processKeyEvent(e, path, m); } @Override public void addNotify() { - ////System.out.println("Test_Editor JMenu addNotify"); + System.out.println("Test_Editor JMenu addNotify"); super.addNotify(); } @@ -764,20 +754,20 @@ public void addNotify() { mb1.add(mb1e); KeyStroke[] a = mb1.getRegisteredKeyStrokes(); - ////System.out.println("menubar menu registration: " + a.length); -// for (int i = 0; i < a.length; i++) -// System.out.println(a[i]); + System.out.println("menubar menu registration: " + a.length); + for (int i = 0; i < a.length; i++) + System.out.println(a[i]); mb.add(mb1); a = mb1.getRegisteredKeyStrokes(); - //System.out.println("menubar menu registration: " + a.length); + System.out.println("menubar menu registration: " + a.length); ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); ptop.setBackground(Color.cyan); } @@ -789,7 +779,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); ptop.setBackground(Color.YELLOW); } @@ -799,7 +789,7 @@ public void actionPerformed(ActionEvent e) { @Override public void actionPerformed(ActionEvent e) { - ////System.out.println("Test_Editor action " + getID(e.getSource())); + System.out.println("Test_Editor action " + getID(e.getSource())); ptop.setBackground(Color.white); } @@ -840,18 +830,18 @@ private JPanel getTopPanel() { protected void updateTitle() { Component c = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - ////System.out.println("Test_Editor focus owner is " + (c == null ? null : c.getClass().getName())); + System.out.println("Test_Editor focus owner is " + (c == null ? null : c.getClass().getName())); setTitle((++n) + " " + (c == null ? null : c.getClass().getName())); } protected void showKeyEvent(KeyEvent e) { String source = /** @j2sNative (xxx = e).bdata.jqevent.originalEvent.target.id || */ ""; -// System.out.println( -// "Test_Editor keyEvent id=" + e.getID() + " " + ((JComponent) e.getSource()).getClass().getName() + " " -// + source + " char=" + e.getKeyChar() + " code=" + e.getKeyCode() + " loc=" + e.getKeyLocation() -// + "\n mod=" + e.getModifiers() + " " + KeyEvent.getKeyModifiersText(e.getModifiers()) + " modx=" -// + e.getModifiersEx() + " " + KeyEvent.getKeyModifiersText(e.getModifiersEx())); + System.out.println( + "Test_Editor keyEvent id=" + e.getID() + " " + ((JComponent) e.getSource()).getClass().getName() + " " + + source + " char=" + e.getKeyChar() + " code=" + e.getKeyCode() + " loc=" + e.getKeyLocation() + + "\n mod=" + e.getModifiers() + " " + KeyEvent.getKeyModifiersText(e.getModifiers()) + " modx=" + + e.getModifiersEx() + " " + KeyEvent.getKeyModifiersText(e.getModifiersEx())); } protected void dumpRoot(Document document) { @@ -859,7 +849,7 @@ protected void dumpRoot(Document document) { } private void dumpElement(int index, Element element) { - ////System.out.println("Test_Editor i=" + index + " e=" + element.toString()); + System.out.println("Test_Editor i=" + index + " e=" + element.toString()); for (int i = 0, n = element.getElementCount(); i < n; i++) dumpElement((index + 1) * 100, element.getElement(i)); diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Editor0.java b/sources/net.sf.j2s.java.core/src/test/Test_Editor0.java index 1013ecf93..32462e984 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Editor0.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Editor0.java @@ -1,21 +1,10 @@ package test; -import java.awt.BorderLayout; //import java.awt.Button; import java.awt.Color; import java.awt.Component; import java.awt.DefaultKeyboardFocusManager; -import java.awt.Dimension; import java.awt.Font; -//import java.awt.TextArea; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTarget; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; @@ -25,489 +14,60 @@ import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; - -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; + +import javax.swing.JApplet; import javax.swing.JComponent; -import javax.swing.JDesktopPane; import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.JTextPane; -import javax.swing.KeyStroke; -import javax.swing.MenuElement; -import javax.swing.MenuSelectionManager; -import javax.swing.Timer; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; -import javax.swing.text.DefaultCaret; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.JTextComponent; -import javax.swing.text.MutableAttributeSet; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; - -public class Test_Editor0 extends JFrame implements DropTargetListener { - - String test = "1234567890"; - -// private static void logClass(String name) { -// ConsoleHandler consoleHandler = new ConsoleHandler(); -// consoleHandler.setLevel(Level.ALL); -// Logger logger = Logger.getLogger(name); -// logger.setLevel(Level.ALL); -// logger.addHandler(consoleHandler); -// } -// -// private static boolean allowLogging = false; -// private static boolean allowEventInfo = false; -// -// private void setLogging() { -// if ((/** @j2sNative false || */ -// allowLogging)) { -// -// Logger rootLogger = Logger.getLogger(""); -// rootLogger.setLevel(Level.ALL); -// logClass("java.awt.EventDispatchThread"); -// logClass("java.awt.EventQueue"); -// logClass("java.awt.Component"); -// logClass("java.awt.focus.Component"); -// logClass("java.awt.focus.DefaultKeyboardFocusManager"); -// -// } -// -// } - - public static void main(String[] args) { -// KeyboardFocusManager.setCurrentKeyboardFocusManager(new DefaultKeyboardFocusManager() { -// @Override -// public boolean dispatchEvent(AWTEvent e) { -// if (allowEventInfo && e.getID() != MouseEvent.MOUSE_MOVED) { -// if (e.getID() == MouseEvent.MOUSE_PRESSED) { // -// System.out.println("FocusMan mousepreseed event"); -// } -// System.out.println( -// "FocusMan dispatching activeElement=" + (/** @j2sNative document.activeElement.id || */ -// null)); -// System.out.println("FocusMan dispatching event Source " + e.getSource()); -// System.out.println("FocusMan dispatching event " + e); -// } -// return super.dispatchEvent(e); -// } -// }); - new Test_Editor0(); - } - public Test_Editor0() { - -// setLogging(); - - setTitle("testing editor"); - setLocation(100, 100); +public class Test_Editor0 extends JApplet { -// JPanel ptop = getTopPanel(); - // ptop.setFocusable(false); + static String test = "1234567890"; -// JTextPane editor = getEditor(); -// JScrollPane js = new JScrollPane(editor); - // js.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + public static void main(String[] args) { + new Test_EditorFrame(); + } - JTextArea area = getArea(); - JScrollPane js2 = new JScrollPane(area); - js2.setPreferredSize(new Dimension(300, 300)); - js2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - js2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + static class Test_EditorFrame extends JFrame { + Test_EditorFrame() { JTextField field = getField(); - -// JMenuBar mb = getMenuBar(ptop); - - JTextArea area1 = new JTextArea(); - // area1.setPreferredSize(new Dimension(300, 300)); - -// JPanel panel = getButtonPanel(editor, area, area1, field); - -// new DropTarget(editor, this); - new DropTarget(area, this); - - Box box = Box.createHorizontalBox(); -// box.add(js); - box.add(Box.createHorizontalStrut(1)); - box.add(js2); -// box.add(Box.createHorizontalStrut(1)); -// box.add(area1); - - JPanel full = new JPanel(new BorderLayout()); - // full.add(ptop, BorderLayout.NORTH); - full.add(box); - // full.add(panel, BorderLayout.SOUTH); - -// full.addKeyListener(ka); -// full.addFocusListener(fl); -// -// this.getRootPane().addKeyListener(ka); -// this.addKeyListener(ka); -// this.getContentPane().addKeyListener(ka); -// -// ptop.addKeyListener(ka); -// ptop.addFocusListener(fl); -// editor.addFocusListener(fl); -// area.addFocusListener(fl); - -// boolean asInternalFrame = false; -// -// if (asInternalFrame) { -// JDesktopPane d = new JDesktopPane(); -// d.setPreferredSize(new Dimension(1210, 600)); -// -// JInternalFrame main = new JInternalFrame(); -// -// main.addMouseListener(new MouseListener() { -// -// @Override -// public void mouseClicked(MouseEvent e) { -// // TODO Auto-generated method stub -// -// } -// -// @Override -// public void mousePressed(MouseEvent e) { -//// main.requestFocus(); -// } -// -// @Override -// public void mouseReleased(MouseEvent e) { -// // TODO Auto-generated method stub -// -// } -// -// @Override -// public void mouseEntered(MouseEvent e) { -// // TODO Auto-generated method stub -// -// } -// -// @Override -// public void mouseExited(MouseEvent e) { -// // TODO Auto-generated method stub -// -// } -// -// }); -// main.addKeyListener(ka); -// -// -// KeyStroke[] a = ((JComponent) mb.getComponent(0)).getRegisteredKeyStrokes(); -// System.out.println("menubar menu registration: " + a.length); -// -// main.setJMenuBar(mb); -// -// a = ((JComponent) mb.getComponent(0)).getRegisteredKeyStrokes(); -// System.out.println("menubar menu registration: " + a.length); -// -// main.add(full); -// main.addFocusListener(fl); -// main.setTitle("main"); -// main.pack(); -// main.setVisible(true); -// d.add(main); -// -// JInternalFrame main2 = new JInternalFrame(); -// main.add(new JPanel() { -// public Dimension getPreferredSize() { -// return new Dimension(100,300); -// } -// }); -// -// main2.setTitle("main2"); -// main2.pack(); -// main2.setVisible(true); -// d.add(main2); -// -// -// setContentPane(d); -// // these next two allow floating frames outside the JDesktopPane -// getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); -// pack(); -// setVisible(true); -// -// main.getRootPane().addKeyListener(ka); -// main.addKeyListener(ka); -// main.getContentPane().addKeyListener(ka); -// ptop.addKeyListener(ka); -// // ptop.setFocusable(false); -// -// } else { -// setJMenuBar(mb); - add(full); +JTextArea area = getArea(); + add(area); pack(); setVisible(true); -//// ptop.setFocusable(false); -// } - -// showFocusTimer(); + field.addKeyListener(ka); + //getContentPane().addKeyListener(ka); + } } + + + + public Test_Editor0() { - private void showFocusTimer() { - Timer t = new Timer(100, new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String s = /** @j2sNative document.activeElement.id || */ - null; - - s += " " + (++n); - -// System.out.println(s); - /** @j2sNative document.title = s; */ - } + // setTitle("testing editor"); + setLocation(100, 100); + //JTextArea area = getArea(); + +// JScrollPane js2 = new JScrollPane(area); +// js2.setPreferredSize(new Dimension(300, 300)); +// js2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); +// js2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - }); + JTextField field = getField(); - t.setRepeats(true); - if (/** @j2sNative true || */ - false) - t.start(); + add(field); + // pack(); + setVisible(true); + field.addKeyListener(ka); } int n; -// private JPanel getButtonPanel(JTextPane editor, JTextArea area, JTextArea area1, JTextField field) { -// JPanel panel = new JPanel(); -// -// panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); -// -// JButton btop = new JButton("top"); -// btop.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// editor.setCaretPosition(0); -// area.setCaretPosition(0); -// area.requestFocus(); -// editor.requestFocus(); -// area1.setCaretPosition(0); -// area1.requestFocus(); -// } -// -// }); -// -// JButton b; -// -// b = new JButton("clear"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// editor.setText(""); -//// btop.setEnabled(!btop.isEnabled()); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("caret+1"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// editor.getCaret().setDot(editor.getCaret().getDot() + 1); -// editor.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("sel7-10"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// editor.getCaret().setDot(7); -// editor.getCaret().moveDot(10); -// editor.getCaret().setSelectionVisible(true); -// editor.setSelectionColor(Color.red); -// editor.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// btop.addFocusListener(fl); -// panel.add(btop); -// -// b = new JButton("end1"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -//// editor.setCaretPosition(editor.getDocument().getLength()); -// area.setCaretPosition(area.getDocument().getLength()); -// area.requestFocus(); -//// editor.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("end2"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// area1.setCaretPosition(area1.getText().length()); -// area1.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("sel7-10-area"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// area.getCaret().setDot(7); -// area.getCaret().moveDot(10); -// area.getCaret().setSelectionVisible(true); -// area.setSelectionColor(Color.blue); -// area.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("app1"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// area.append("\ntesting" + ++n); -//// area.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("app2"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// area1.requestFocus(); -// area1.append("\ntesting" + ++n); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// -// -// -// b = new JButton("sel3-5-field"); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// field.setCaretPosition(3); -// field.getCaret().moveDot(5); -// field.getCaret().setSelectionVisible(true); -// field.setSelectionColor(Color.blue); -// field.requestFocus(); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("bold"); -// b.setMnemonic('b'); -// -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// int start = editor.getSelectionStart(); -// int end = editor.getSelectionEnd(); -// if (end == start) -// return; -// Element ch = editor.getStyledDocument().getCharacterElement(start); -// boolean isBold = !StyleConstants.isBold(ch.getAttributes()); -// MutableAttributeSet attrs = new SimpleAttributeSet(); -// StyleConstants.setForeground(attrs, isBold ? Color.red : Color.black); -// StyleConstants.setBold(attrs, isBold); -// editor.getStyledDocument().setCharacterAttributes(start, end - start, attrs, false); -// // note that text selection now disappears -// System.out -// .println("Test_Editor caret now " + editor.getCaretPosition() + " " + editor.getSelectedText()); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// -// b = new JButton("ital"); -// b.setMnemonic('i'); -// b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// int start = editor.getSelectionStart(); -// int end = editor.getSelectionEnd(); -// if (end == start) -// return; -// MutableAttributeSet attrs = new SimpleAttributeSet(); -// Element ch = editor.getStyledDocument().getCharacterElement(start); -// StyleConstants.setItalic(attrs, !StyleConstants.isItalic(ch.getAttributes())); -// editor.getStyledDocument().setCharacterAttributes(start, end - start, attrs, false); -// } -// -// }); -// b.addFocusListener(fl); -// panel.add(b); -// panel.add(field); -// return panel; -// } - - private JTextField getField() { + static private JTextField getField() { JTextField field = new JTextField("testing"); field.addActionListener(new ActionListener() { @@ -530,103 +90,56 @@ public void caretUpdate(CaretEvent e) { return field; } - private JTextArea getArea() { + private static JTextArea getArea() { JTextArea area = new JTextArea() { -// public void setCarentPosition(int i) { -// System.out.println("Test_Editor JTextArea setCP " + i); -// super.setCaretPosition(i); -// } }; - DefaultCaret c = new DefaultCaret() { - @Override - protected void fireStateChanged() { - System.out.println("Test_Editor area caret firestatechanged " + area.getCaretPosition()); - super.fireStateChanged(); - } - - }; - c.install(area); - area.setCaret(c); - System.out.println(area.getCaret().getClass().getName()); +// DefaultCaret c = new DefaultCaret() { +// @Override +// protected void fireStateChanged() { +// System.out.println("Test_Editor area caret firestatechanged " + area.getCaretPosition()); +// super.fireStateChanged(); +// } +// +// }; +// c.install(area); +// area.setCaret(c); +// System.out.println(area.getCaret().getClass().getName()); area.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 16)); area.setText(test); area.setBackground(new Color(200, 200, 180)); - // area.setEditable(false); - area.addCaretListener(new CaretListener() { - - @Override - public void caretUpdate(CaretEvent e) { - System.out.println("Test_Editor JTextArea caret:" + e); - } - - }); - - area.addMouseListener(ml); +// // area.setEditable(false); +// area.addCaretListener(new CaretListener() { +// +// @Override +// public void caretUpdate(CaretEvent e) { +// System.out.println("Test_Editor JTextArea caret:" + e); +// } +// +// }); +// +// area.addMouseListener(ml); return area; } - private JTextPane getEditor() { - JTextPane editor = new JTextPane(); - editor.setPreferredSize(new Dimension(400, 300)); - System.out.println("Test_Editor " + editor.getDocument()); - System.out.println("Test_Editor " + editor.getEditorKit()); - editor.setText(test); - // editor.setEditable(false); - - System.out - .println("Test_Editor Element count = " + editor.getDocument().getRootElements()[0].getElementCount()); - editor.setBackground(new Color(200, 200, 200)); - editor.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16)); - System.out.println("Test_Editor editor pref size " + editor.getPreferredSize()); - - Style style = editor.addStyle("Red", null); - StyleConstants.setForeground(style, Color.red); - - editor.addPropertyChangeListener(new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - System.out.println("Test_Editor prop change " + evt.getPropertyName() + " " + evt); - } - - }); - - editor.addCaretListener(new CaretListener() { - - @Override - public void caretUpdate(CaretEvent e) { - System.out.println("Test_Editor JTextPane caret:" + e); - // dumpRoot(editor.getDocument()); - } - - }); - - editor.addMouseListener(ml); - - DefaultCaret c = new DefaultCaret() { - }; - c.install(editor); - editor.setCaret(c); - - return editor; - } - - KeyListener ka = new KeyAdapter() { + static KeyListener ka = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { + //e.consume(); showKeyEvent(e); } @Override public void keyTyped(KeyEvent e) { + //e.consume(); showKeyEvent(e); } @Override public void keyReleased(KeyEvent e) { + //e.consume(); showKeyEvent(e); } }; @@ -687,132 +200,12 @@ public void focusLost(FocusEvent e) { }; -// private JMenuBar getMenuBar(JPanel ptop) { -// JMenuBar mb = new JMenuBar() { -// @Override -// public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager m) { -// System.out.println("Test_Editor path length=" + path.length); -// super.processKeyEvent(e, path, m); -// } -// }; -// JMenu mb1 = new JMenu("Test") { -// @Override -// public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager m) { -// System.out.println("Test_Editor JMenu path length=" + path.length); -// super.processKeyEvent(e, path, m); -// } -// -// @Override -// public void addNotify() { -// System.out.println("Test_Editor JMenu addNotify"); -// super.addNotify(); -// } -// -// }; -// -// JMenuItem mb1a = new JMenuItem("test-1"); -// JMenuItem mb1b = new JMenuItem("test-2"); -// JMenuItem mb1c = new JMenuItem("test-3"); -// JMenuItem mb1d = new JMenuItem("test-4"); -// JMenuItem mb1e = new JMenuItem("test-5"); -// -// mb1.setMnemonic('t'); -// mb1a.setMnemonic('1'); -// mb1b.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_MASK)); -// mb1c.setMnemonic('3'); -// mb1d.setMnemonic('4'); -// mb1d.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK)); -// mb1e.setMnemonic('5'); -// mb1e.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_MASK)); -// -// mb1.add(mb1a); -// mb1.add(mb1b); -// mb1.add(mb1c); -// mb1.add(mb1d); -// mb1.add(mb1e); -// -// KeyStroke[] a = mb1.getRegisteredKeyStrokes(); -// System.out.println("menubar menu registration: " + a.length); -// for (int i = 0; i < a.length; i++) -// System.out.println(a[i]); -// -// mb.add(mb1); -// -// a = mb1.getRegisteredKeyStrokes(); -// System.out.println("menubar menu registration: " + a.length); -// -// ActionListener al = new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// ptop.setBackground(Color.cyan); -// } -// -// }; -// -// mb1a.addActionListener(al); -// -// mb1b.addActionListener(new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// ptop.setBackground(Color.YELLOW); -// } -// -// }); -// -// ActionListener a2 = new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// System.out.println("Test_Editor action " + getID(e.getSource())); -// ptop.setBackground(Color.white); -// } -// -// }; -// -// mb1c.addActionListener(al); -// mb1d.addActionListener(al); -// mb1e.addActionListener(a2); -// -// return mb; -// } -// - protected String getID(Object jc) { + static protected String getID(Object jc) { return (jc == null ? null : jc instanceof JComponent ? /** @j2sNative jc.ui.id || */ ((JComponent) jc).getUIClassID() : jc.getClass().getName()); } -// -// private JPanel getTopPanel() { -// JPanel ptop = new JPanel(); -// ptop.setPreferredSize(new Dimension(300, 100)); -// ptop.setMaximumSize(new Dimension(400, 100)); -// ptop.setBackground(Color.LIGHT_GRAY); -// ptop.setOpaque(true); -//// -//// ptop.addMouseListener(new MouseAdapter() { -//// @Override -//// public void mousePressed(MouseEvent e) { -//// System.out.println("Test_Editor ptop mouse pressed"); -//// ptop.requestFocusInWindow(); -//// updateTitle(); -//// } -//// -//// }); -//// -// return ptop; -// } - - protected void updateTitle() { - Component c = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - - System.out.println("Test_Editor focus owner is " + (c == null ? null : c.getClass().getName())); - setTitle((++n) + " " + (c == null ? null : c.getClass().getName())); - } - protected void showKeyEvent(KeyEvent e) { + protected static void showKeyEvent(KeyEvent e) { String source = /** @j2sNative (xxx = e).bdata.jqevent.originalEvent.target.id || */ ""; System.out.println( @@ -822,102 +215,5 @@ protected void showKeyEvent(KeyEvent e) { + e.getModifiersEx() + " " + KeyEvent.getKeyModifiersText(e.getModifiersEx())); } - protected void dumpRoot(Document document) { - dumpElement(0, document.getRootElements()[0]); - } - - private void dumpElement(int index, Element element) { - System.out.println("Test_Editor i=" + index + " e=" + element.toString()); - for (int i = 0, n = element.getElementCount(); i < n; i++) - dumpElement((index + 1) * 100, element.getElement(i)); - - } - - @Override - public void dragEnter(DropTargetDragEvent dtde) { - // TODO Auto-generated method stub - - } - - @Override - public void dragOver(DropTargetDragEvent dtde) { - // TODO Auto-generated method stub - - } - - @Override - public void dropActionChanged(DropTargetDragEvent dtde) { - // TODO Auto-generated method stub - - } - - @Override - public void dragExit(DropTargetEvent dte) { - // TODO Auto-generated method stub - - } - - @Override - public void drop(DropTargetDropEvent dtde) { - // TODO Auto-generated method stub - - try { - Transferable tr = dtde.getTransferable(); - DataFlavor[] flavors = tr.getTransferDataFlavors(); - for (int i = 0; i < flavors.length; i++) { - if (flavors[i].isFlavorJavaFileListType()) { - dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); - List list = (List) tr.getTransferData(flavors[i]); - for (int j = 0; j < list.size(); j++) { - File file = (File) list.get(j); - byte[] data = getDroppedFileBytes(file); - JTextComponent target = (JTextComponent) ((DropTarget) dtde.getSource()).getComponent(); - target.setText(new String(data)); - break; // just first indicated file - } - dtde.dropComplete(true); - return; - } else if (flavors[i].isFlavorTextType()) { - dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); - String data = (String) tr.getTransferData(flavors[i]); - JTextComponent target = (JTextComponent) ((DropTarget) dtde.getSource()).getComponent(); - target.setText(data); - dtde.dropComplete(true); - } - } - dtde.rejectDrop(); - } catch (Exception e) { - e.printStackTrace(); - dtde.rejectDrop(); - } - - } - - private byte[] getDroppedFileBytes(File file) { - Path p = file.toPath(); - - try { - return (byte[]) getStreamAsBytes(new BufferedInputStream(new FileInputStream(file))); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public static byte[] getStreamAsBytes(BufferedInputStream bis) throws IOException { - byte[] buf = new byte[1024]; - byte[] bytes = new byte[4096]; - int len = 0; - int totalLen = 0; - while ((len = bis.read(buf, 0, 1024)) > 0) { - totalLen += len; - if (totalLen >= bytes.length) - bytes = Arrays.copyOf(bytes, totalLen * 2); - System.arraycopy(buf, 0, bytes, totalLen - len, len); - } - bis.close(); - return (totalLen < bytes.length ? Arrays.copyOf(bytes, totalLen) : bytes); - } } diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Reflect.java b/sources/net.sf.j2s.java.core/src/test/Test_Reflect.java index 3dcc552d6..6c46cddb5 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Reflect.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Reflect.java @@ -5,6 +5,7 @@ class Test_Reflect extends Test_ { + static long ltime = System.currentTimeMillis(); public String s = "field s"; public void test(char i, String s) { @@ -71,6 +72,8 @@ public void test(String s, float[][] aaf) { public static void main(String[] args) { + + new Test_Reflect().test("int[]", new int[] {1,2,3}); String name = ""; try { Test_Path tp = (Test_Path) Class.forName(name = "Test_Path", true, Test_Reflect.class.getClassLoader()).newInstance(); @@ -87,6 +90,20 @@ public static void main(String[] args) { } Test_Reflect tr = new Test_Reflect(); + + new Test_Char(); + assert(tr instanceof Test_); + assert(tr instanceof Test_); + assert(!(((Test_)tr) instanceof Test_Char)); + + long l = System.currentTimeMillis(); + System.out.println(l - ltime); + for (int i = 0; i < 10000; i++) { + assert(!(((Test_)tr) instanceof Test_Char)); + } + System.out.println(l - System.currentTimeMillis()); + + // Field is not implemented // Field f = Test_Reflect.class.getDeclaredField("s"); // System.out.println(f.getDeclaringClass()); 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 8b7136c4d..b441e6df3 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js @@ -9,6 +9,7 @@ // TODO: still a lot of references to window[...] +// BH 2019.08.16 adds cache for instanceof // BH 2019.07.27 fixes array(intArray).clone // BH 2019.07.09 adds Java String.trim() // BH 2019.05.21 changes Clazz.isClassDefined to Clazz._isClassDefined for compression @@ -351,11 +352,14 @@ Clazz.instanceOf = function (obj, clazz) { if (typeof clazz == "string") { clazz = window[clazz]; } + if (obj == null || !clazz) return false; // check for object being a java.lang.Class and the other not if (obj.$clazz$ && !clazz.$clazz$) return false; obj.$clazz$ && (obj = obj.$clazz$); + if (clazz == String) + return typeof obj == "string"; clazz.$clazz$ && (clazz = clazz.$clazz$); if (obj == clazz) return true; @@ -1396,11 +1400,7 @@ var extendPrototype = function(clazz, isPrimitive, addAll) { } -Clazz.saemCount0 = 0 // methods defined 5400 (Ripple.js) -Clazz.saemCount1 = 0 // delegates created 937 -Clazz.saemCount2 = 0 // delegates bound 397 -Clazz.saemCount3 = 0 // isInstanceOfs started -Clazz.saemCount4 = 0 // isInstanceOfs checked +Clazz.saemCount0 = 0 // methods defined var NullObject = function () {}; @@ -1457,14 +1457,16 @@ var equalsOrExtendsLevel = function (clazzThis, clazzAncestor) { return false; }; +var knownInst = {}; + var isInstanceOf = function (clazzTarget, clazzBase, isTgtStr, isBaseStr) { if (clazzTarget === clazzBase) return true; - clazzBase.$clinit$ && clazzBase.$clinit$(); if (isTgtStr && ("void" == clazzTarget || "unknown" == clazzTarget)) return false; if (isBaseStr && ("void" == clazzBase || "unknown" == clazzBase)) return false; + clazzBase.$clinit$ && clazzBase.$clinit$(); if (clazzTarget === (isTgtStr ? "NullObject" : NullObject)) { switch (clazzBase) { case "n": @@ -1477,15 +1479,27 @@ var isInstanceOf = function (clazzTarget, clazzBase, isTgtStr, isBaseStr) { default: return true; } - } - isTgtStr && (clazzTarget = evalType(clazzTarget)); - isBaseStr && (clazzBase = evalType(clazzBase)); - return (clazzBase && clazzTarget && ( + } + var t = (isTgtStr ? clazzTarget : clazzTarget.__CLASS_NAME__ || clazzTarget.type); + var b = (isBaseStr ? clazzBase : clazzBase.__CLASS_NAME__ || clazzBase.type); + if (t && t == b) + return true; + var key = t + "|" + b; + var val = knownInst[key]; + if (val) + return (val == 1 ? true : false); + + isTgtStr && (clazzTarget = window[clazzTarget]); + isBaseStr && (clazzBase = window[clazzBase]); + var ret = (clazzBase && clazzTarget && ( clazzTarget == clazzBase || clazzBase === Object || clazzBase === Clazz._O || equalsOrExtendsLevel(clazzTarget, clazzBase) )); +if (t && b) + knownInst[key] = (ret ? 1 : -1); + return ret; }; diff --git a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js index 4b5dd5acd..e4cfee668 100644 --- a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js +++ b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js @@ -13731,6 +13731,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) { // TODO: still a lot of references to window[...] +// BH 2019.08.16 adds cache for instanceof // BH 2019.07.27 fixes array(intArray).clone // BH 2019.07.09 adds Java String.trim() // BH 2019.05.21 changes Clazz.isClassDefined to Clazz._isClassDefined for compression @@ -14073,11 +14074,14 @@ Clazz.instanceOf = function (obj, clazz) { if (typeof clazz == "string") { clazz = window[clazz]; } + if (obj == null || !clazz) return false; // check for object being a java.lang.Class and the other not if (obj.$clazz$ && !clazz.$clazz$) return false; obj.$clazz$ && (obj = obj.$clazz$); + if (clazz == String) + return typeof obj == "string"; clazz.$clazz$ && (clazz = clazz.$clazz$); if (obj == clazz) return true; @@ -15118,11 +15122,7 @@ var extendPrototype = function(clazz, isPrimitive, addAll) { } -Clazz.saemCount0 = 0 // methods defined 5400 (Ripple.js) -Clazz.saemCount1 = 0 // delegates created 937 -Clazz.saemCount2 = 0 // delegates bound 397 -Clazz.saemCount3 = 0 // isInstanceOfs started -Clazz.saemCount4 = 0 // isInstanceOfs checked +Clazz.saemCount0 = 0 // methods defined var NullObject = function () {}; @@ -15179,14 +15179,16 @@ var equalsOrExtendsLevel = function (clazzThis, clazzAncestor) { return false; }; +var knownInst = {}; + var isInstanceOf = function (clazzTarget, clazzBase, isTgtStr, isBaseStr) { if (clazzTarget === clazzBase) return true; - clazzBase.$clinit$ && clazzBase.$clinit$(); if (isTgtStr && ("void" == clazzTarget || "unknown" == clazzTarget)) return false; if (isBaseStr && ("void" == clazzBase || "unknown" == clazzBase)) return false; + clazzBase.$clinit$ && clazzBase.$clinit$(); if (clazzTarget === (isTgtStr ? "NullObject" : NullObject)) { switch (clazzBase) { case "n": @@ -15199,15 +15201,27 @@ var isInstanceOf = function (clazzTarget, clazzBase, isTgtStr, isBaseStr) { default: return true; } - } - isTgtStr && (clazzTarget = evalType(clazzTarget)); - isBaseStr && (clazzBase = evalType(clazzBase)); - return (clazzBase && clazzTarget && ( + } + var t = (isTgtStr ? clazzTarget : clazzTarget.__CLASS_NAME__ || clazzTarget.type); + var b = (isBaseStr ? clazzBase : clazzBase.__CLASS_NAME__ || clazzBase.type); + if (t && t == b) + return true; + var key = t + "|" + b; + var val = knownInst[key]; + if (val) + return (val == 1 ? true : false); + + isTgtStr && (clazzTarget = window[clazzTarget]); + isBaseStr && (clazzBase = window[clazzBase]); + var ret = (clazzBase && clazzTarget && ( clazzTarget == clazzBase || clazzBase === Object || clazzBase === Clazz._O || equalsOrExtendsLevel(clazzTarget, clazzBase) )); +if (t && b) + knownInst[key] = (ret ? 1 : -1); + return ret; };