JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / site / j2s / swingjs / plaf / TextListener.java
index 9bce1b1..0371042 100644 (file)
-/*
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package swingjs.plaf;
-
-import jsjava.awt.event.FocusEvent;
-import jsjava.awt.event.FocusListener;
-import jsjava.awt.event.KeyEvent;
-import jsjava.awt.event.MouseEvent;
-import jsjava.awt.event.MouseListener;
-import jsjava.awt.event.MouseMotionListener;
-import jsjava.beans.PropertyChangeEvent;
-import jsjava.beans.PropertyChangeListener;
-import jsjavax.swing.SwingUtilities;
-import jsjavax.swing.event.ChangeEvent;
-import jsjavax.swing.event.ChangeListener;
-import jsjavax.swing.event.DocumentEvent;
-import jsjavax.swing.event.DocumentListener;
-import jsjavax.swing.text.JTextComponent;
-
-public class TextListener implements MouseListener, MouseMotionListener,
-                                   FocusListener, ChangeListener, PropertyChangeListener, DocumentListener, JSEventHandler
-{
-
-    private JTextComponent txtComp;
-    
-    boolean haveDocument;
-
-               private JSTextUI ui;
-
-               public TextListener(JSTextUI ui, JTextComponent txtComp) {
-       this.txtComp = txtComp;
-       this.ui = ui;
-    }
-
-  void checkDocument() {
-       if (!haveDocument && txtComp.getDocument() != null) {
-               haveDocument = true;
-               txtComp.getDocument().addDocumentListener(this);
-       }
-  }
-       public void propertyChange(PropertyChangeEvent e) {
-               String prop = e.getPropertyName();
-               System.out.println("JSTextListener property change: " + prop + " " + e.getSource());
-               if ("font" == prop || "foreground" == prop || "preferredSize" == prop) {
-                       JTextComponent txtComp = (JTextComponent) e.getSource();
-                       ((JSComponentUI) (Object) txtComp.getUI()).notifyPropertyChanged(prop);
-               }
-               if ("editable" == prop)
-                       ui.setEditable(((Boolean) e.getNewValue()).booleanValue());
-       }
-
-  public void stateChanged(ChangeEvent e) {
-        JTextComponent txtComp = (JTextComponent) e.getSource();
-        txtComp.repaint();
-    }
-
-    public void focusGained(FocusEvent e) {
-    }
-
-    public void focusLost(FocusEvent e) {
-//        JTextComponent b = (JTextComponent) e.getSource();
-    }
-
-    public void mouseMoved(MouseEvent e) {
-    }
-
-
-    public void mouseDragged(MouseEvent e) {
-    }
-
-    public void mouseClicked(MouseEvent e) {
-    }
-
-       public void mousePressed(MouseEvent e) {
-               if (SwingUtilities.isLeftMouseButton(e)) {
-                       JTextComponent txtComp = (JTextComponent) e.getSource();
-                       if (!txtComp.contains(e.getX(), e.getY()))
-                               return;
-                       if (!txtComp.hasFocus() && txtComp.isRequestFocusEnabled()) {
-                               txtComp.requestFocus();
-                       }
-               }
-       };
-
-    public void mouseReleased(MouseEvent e) {
-    };
-
-    public void mouseEntered(MouseEvent e) {
-    };
-
-    public void mouseExited(MouseEvent e) {
-//        JTextComponent b = (JTextComponent) e.getSource();
-//        ButtonModel model = b.getModel();
-//        if(b.isRolloverEnabled()) {
-//            model.setRollover(false);
-//        }
-//        model.setArmed(false);
-    };
-
-
-       @Override
-       public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
-               JSTextUI ui = (JSTextUI) target;
-               int dot = 0, mark = 0;
-               String evType = null;
-               int keyCode = 0;
-               /**
-                * @j2sNative
-                * 
-                *            mark = jQueryEvent.target.selectionStart; 
-                *            dot = jQueryEvent.target.selectionEnd; 
-                *            evType = jQueryEvent.type;
-                *            keyCode = jQueryEvent.keyCode;
-                *            if (keyCode == 13) keyCode = 10; 
-                */
-               {
-               }
-
-               // HTML5 selection is always mark....dot
-               // but Java can be oldDot....oldMark
-
-               int oldDot = ui.editor.getCaret().getDot();
-               int oldMark = ui.editor.getCaret().getMark();
-               if (dot != mark && oldMark == dot) {
-                       dot = mark;
-                       mark = oldMark;
-               }
-               switch (eventType) {
-               case MouseEvent.MOUSE_PRESSED:
-               case MouseEvent.MOUSE_RELEASED:
-               case MouseEvent.MOUSE_CLICKED:
-                       break;
-               case KeyEvent.KEY_PRESSED:
-               case KeyEvent.KEY_RELEASED:
-               case KeyEvent.KEY_TYPED:
-                       if (keyCode == KeyEvent.VK_ENTER && ui.handleEnter(eventType))
-                               break;
-                       String val = ui.getJSTextValue();
-                       if (!val.equals(ui.currentText)) {
-                               String oldval = ui.currentText;
-                               ui.editor.setText(val);
-                               // the text may have been filtered, but we should not change it yet
-                               //val = ui.getComponentText();
-                               ui.editor.firePropertyChangeObject("text", oldval, val);
-                               ui.domNode.setSelectionRange(dot, dot);
-                       }
-                       break;
-               }
-               if (dot != oldDot || mark != oldMark) {
-                       ui.editor.getCaret().setDot(dot);
-                       if (dot != mark)
-                               ui.editor.getCaret().moveDot(mark);
-                       ui.editor.caretEvent.fire();
-               }
-               System.out.println(ui.id + " TextListener handling event " + evType + " " + eventType
-                               + " " + ui.editor.getCaret() + " " + ui.getComponentText().length());
-               return true;
-       }
-
-       @Override
-       public void insertUpdate(DocumentEvent e) {
-               setText();
-       }
-
-       @Override
-       public void removeUpdate(DocumentEvent e) {
-               setText();
-       }
-
-       @Override
-       public void changedUpdate(DocumentEvent e) {
-       }
-
-       private void setText() {
-               // this method will only be run in JavaScript; so as not to 
-               // have to modify the actual javax.swing code so much, we use
-               // the double qualification to prevent Java compilation errors.
-               // Not a great idea in general....
-       
-               ((JSComponentUI) (Object) txtComp.getUI()).notifyPropertyChanged("text");       
-       }
-}
+/*\r
+ * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.\r
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\r
+ *\r
+ * This code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 only, as\r
+ * published by the Free Software Foundation.  Oracle designates this\r
+ * particular file as subject to the "Classpath" exception as provided\r
+ * by Oracle in the LICENSE file that accompanied this code.\r
+ *\r
+ * This code is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
+ * version 2 for more details (a copy is included in the LICENSE file that\r
+ * accompanied this code).\r
+ *\r
+ * You should have received a copy of the GNU General Public License version\r
+ * 2 along with this work; if not, write to the Free Software Foundation,\r
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\r
+ * or visit www.oracle.com if you need additional information or have any\r
+ * questions.\r
+ */\r
+\r
+package swingjs.plaf;\r
+\r
+import jsjava.awt.event.FocusEvent;\r
+import jsjava.awt.event.FocusListener;\r
+import jsjava.awt.event.KeyEvent;\r
+import jsjava.awt.event.MouseEvent;\r
+import jsjava.awt.event.MouseListener;\r
+import jsjava.awt.event.MouseMotionListener;\r
+import jsjava.beans.PropertyChangeEvent;\r
+import jsjava.beans.PropertyChangeListener;\r
+import jsjavax.swing.SwingUtilities;\r
+import jsjavax.swing.event.ChangeEvent;\r
+import jsjavax.swing.event.ChangeListener;\r
+import jsjavax.swing.event.DocumentEvent;\r
+import jsjavax.swing.event.DocumentListener;\r
+import jsjavax.swing.text.JTextComponent;\r
+\r
+public class TextListener implements MouseListener, MouseMotionListener,\r
+                                   FocusListener, ChangeListener, PropertyChangeListener, DocumentListener, JSEventHandler\r
+{\r
+\r
+    private JTextComponent txtComp;\r
+    \r
+    boolean haveDocument;\r
+\r
+               private JSTextUI ui;\r
+\r
+               public TextListener(JSTextUI ui, JTextComponent txtComp) {\r
+       this.txtComp = txtComp;\r
+       this.ui = ui;\r
+    }\r
+\r
+  void checkDocument() {\r
+       if (!haveDocument && txtComp.getDocument() != null) {\r
+               haveDocument = true;\r
+               txtComp.getDocument().addDocumentListener(this);\r
+       }\r
+  }\r
+       public void propertyChange(PropertyChangeEvent e) {\r
+               String prop = e.getPropertyName();\r
+               System.out.println("JSTextListener property change: " + prop + " " + e.getSource());\r
+               if ("font" == prop || "foreground" == prop || "preferredSize" == prop) {\r
+                       JTextComponent txtComp = (JTextComponent) e.getSource();\r
+                       ((JSComponentUI) (Object) txtComp.getUI()).notifyPropertyChanged(prop);\r
+               }\r
+               if ("editable" == prop)\r
+                       ui.setEditable(((Boolean) e.getNewValue()).booleanValue());\r
+       }\r
+\r
+  public void stateChanged(ChangeEvent e) {\r
+        JTextComponent txtComp = (JTextComponent) e.getSource();\r
+        txtComp.repaint();\r
+    }\r
+\r
+    public void focusGained(FocusEvent e) {\r
+    }\r
+\r
+    public void focusLost(FocusEvent e) {\r
+//        JTextComponent b = (JTextComponent) e.getSource();\r
+    }\r
+\r
+    public void mouseMoved(MouseEvent e) {\r
+    }\r
+\r
+\r
+    public void mouseDragged(MouseEvent e) {\r
+    }\r
+\r
+    public void mouseClicked(MouseEvent e) {\r
+    }\r
+\r
+       public void mousePressed(MouseEvent e) {\r
+               if (SwingUtilities.isLeftMouseButton(e)) {\r
+                       JTextComponent txtComp = (JTextComponent) e.getSource();\r
+                       if (!txtComp.contains(e.getX(), e.getY()))\r
+                               return;\r
+                       if (!txtComp.hasFocus() && txtComp.isRequestFocusEnabled()) {\r
+                               txtComp.requestFocus();\r
+                       }\r
+               }\r
+       };\r
+\r
+    public void mouseReleased(MouseEvent e) {\r
+    };\r
+\r
+    public void mouseEntered(MouseEvent e) {\r
+    };\r
+\r
+    public void mouseExited(MouseEvent e) {\r
+//        JTextComponent b = (JTextComponent) e.getSource();\r
+//        ButtonModel model = b.getModel();\r
+//        if(b.isRolloverEnabled()) {\r
+//            model.setRollover(false);\r
+//        }\r
+//        model.setArmed(false);\r
+    };\r
+\r
+\r
+       @Override\r
+       public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {\r
+               JSTextUI ui = (JSTextUI) target;\r
+               int dot = 0, mark = 0;\r
+               String evType = null;\r
+               int keyCode = 0;\r
+               /**\r
+                * @j2sNative\r
+                * \r
+                *            mark = jQueryEvent.target.selectionStart; \r
+                *            dot = jQueryEvent.target.selectionEnd; \r
+                *            evType = jQueryEvent.type;\r
+                *            keyCode = jQueryEvent.keyCode;\r
+                *            if (keyCode == 13) keyCode = 10; \r
+                */\r
+               {\r
+               }\r
+\r
+               // HTML5 selection is always mark....dot\r
+               // but Java can be oldDot....oldMark\r
+\r
+               int oldDot = ui.editor.getCaret().getDot();\r
+               int oldMark = ui.editor.getCaret().getMark();\r
+               if (dot != mark && oldMark == dot) {\r
+                       dot = mark;\r
+                       mark = oldMark;\r
+               }\r
+               switch (eventType) {\r
+               case MouseEvent.MOUSE_PRESSED:\r
+               case MouseEvent.MOUSE_RELEASED:\r
+               case MouseEvent.MOUSE_CLICKED:\r
+                       break;\r
+               case KeyEvent.KEY_PRESSED:\r
+               case KeyEvent.KEY_RELEASED:\r
+               case KeyEvent.KEY_TYPED:\r
+                       if (keyCode == KeyEvent.VK_ENTER && ui.handleEnter(eventType))\r
+                               break;\r
+                       String val = ui.getJSTextValue();\r
+                       if (!val.equals(ui.currentText)) {\r
+                               String oldval = ui.currentText;\r
+                               ui.editor.setText(val);\r
+                               // the text may have been filtered, but we should not change it yet\r
+                               //val = ui.getComponentText();\r
+                               ui.editor.firePropertyChangeObject("text", oldval, val);\r
+                               ui.domNode.setSelectionRange(dot, dot);\r
+                       }\r
+                       break;\r
+               }\r
+               if (dot != oldDot || mark != oldMark) {\r
+                       ui.editor.getCaret().setDot(dot);\r
+                       if (dot != mark)\r
+                               ui.editor.getCaret().moveDot(mark);\r
+                       ui.editor.caretEvent.fire();\r
+               }\r
+               System.out.println(ui.id + " TextListener handling event " + evType + " " + eventType\r
+                               + " " + ui.editor.getCaret() + " " + ui.getComponentText().length());\r
+               return true;\r
+       }\r
+\r
+       @Override\r
+       public void insertUpdate(DocumentEvent e) {\r
+               setText();\r
+       }\r
+\r
+       @Override\r
+       public void removeUpdate(DocumentEvent e) {\r
+               setText();\r
+       }\r
+\r
+       @Override\r
+       public void changedUpdate(DocumentEvent e) {\r
+       }\r
+\r
+       private void setText() {\r
+               // this method will only be run in JavaScript; so as not to \r
+               // have to modify the actual javax.swing code so much, we use\r
+               // the double qualification to prevent Java compilation errors.\r
+               // Not a great idea in general....\r
+       \r
+               ((JSComponentUI) (Object) txtComp.getUI()).notifyPropertyChanged("text");       \r
+       }\r
+}\r
   
\ No newline at end of file