JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / site / j2s / swingjs / plaf / JSTextUI.java
index 2cff100..4049f26 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 swingjs.JSToolkit;
-import swingjs.api.DOMNode;
-import swingjs.api.JQueryObject;
-import swingjs.api.JSFunction;
-import jsjava.awt.Dimension;
-import jsjava.awt.Insets;
-import jsjava.awt.LayoutManager;
-import jsjava.awt.event.ActionEvent;
-import jsjavax.swing.AbstractAction;
-import jsjavax.swing.Action;
-import jsjavax.swing.ActionMap;
-import jsjavax.swing.InputMap;
-import jsjavax.swing.JComponent;
-import jsjavax.swing.SwingUtilities;
-import jsjavax.swing.UIManager;
-import jsjavax.swing.plaf.ActionMapUIResource;
-import jsjavax.swing.plaf.ComponentUI;
-import jsjavax.swing.plaf.InputMapUIResource;
-import jsjavax.swing.plaf.TextUI;
-import jsjavax.swing.plaf.UIResource;
-import jsjavax.swing.text.Caret;
-import jsjavax.swing.text.DefaultEditorKit;
-import jsjavax.swing.text.EditorKit;
-import jsjavax.swing.text.JTextComponent;
-import jsjavax.swing.text.TextAction;
-//import jsjava.awt.KeyboardFocusManager;
-//import jsjava.awt.datatransfer.DataFlavor;
-//import jsjava.awt.datatransfer.Transferable;
-//import jsjava.awt.datatransfer.UnsupportedFlavorException;
-//import jsjava.awt.im.InputContext;
-//import jsjava.io.IOException;
-//import jsjava.io.InputStream;
-//import jsjava.io.Reader;
-//import jsjava.io.StringBufferInputStream;
-//import jsjava.io.StringReader;
-//import jsjava.io.StringWriter;
-//import jsjavax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
-
-/**
- * <p>
- * Basis of a text components look-and-feel. This provides the basic editor view
- * and controller services that may be useful when creating a look-and-feel for
- * an extension of <code>JTextComponent</code>.
- * <p>
- * Most state is held in the associated <code>JTextComponent</code> as bound
- * properties, and the UI installs default values for the various properties.
- * This default will install something for all of the properties. Typically, a
- * LAF implementation will do more however. At a minimum, a LAF would generally
- * install key bindings.
- * <p>
- * This class also provides some concurrency support if the
- * <code>Document</code> associated with the JTextComponent is a subclass of
- * <code>AbstractDocument</code>. Access to the View (or View hierarchy) is
- * serialized between any thread mutating the model and the Swing event thread
- * (which is expected to render, do model/view coordinate translation, etc).
- * <em>Any access to the root view should first
- * acquire a read-lock on the AbstractDocument and release that lock
- * in a finally block.</em>
- * <p>
- * An important method to define is the {@link #getPropertyPrefix} method which
- * is used as the basis of the keys used to fetch defaults from the UIManager.
- * The string should reflect the type of TextUI (eg. TextField, TextArea, etc)
- * without the particular LAF part of the name (eg Metal, Motif, etc).
- * <p>
- * To build a view of the model, one of the following strategies can be
- * employed.
- * <ol>
- * <li>
- * One strategy is to simply redefine the ViewFactory interface in the UI. By
- * default, this UI itself acts as the factory for View implementations. This is
- * useful for simple factories. To do this reimplement the {@link #create}
- * method.
- * <li>
- * A common strategy for creating more complex types of documents is to have the
- * EditorKit implementation return a factory. Since the EditorKit ties all of
- * the pieces necessary to maintain a type of document, the factory is typically
- * an important part of that and should be produced by the EditorKit
- * implementation.
- * </ol>
- * <p>
- * <strong>Warning:</strong> Serialized objects of this class will not be
- * compatible with future Swing releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running the
- * same version of Swing. As of 1.4, support for long term storage of all
- * JavaBeans<sup><font size="-2">TM</font></sup> has been added to the
- * <code>java.beans</code> package. Please see {@link jsjava.beans.XMLEncoder}.
- * 
- * @author Timothy Prinzing
- * @author Shannon Hickey (drag and drop)
- */
-public abstract class JSTextUI extends JSComponentUI {// implements {ViewFactory
-                                                                                                                                                                                                                       // {
-       @SuppressWarnings("unused")
-       protected void setFocusable() {
-               JQueryObject node = $(focusNode);
-               Object me = this;
-
-               /**
-                * @j2sNative
-                * 
-                * node.focus(function() {me.notifyFocus(true)});
-                * node.blur(function() {me.notifyFocus(false)});
-                */
-               {}
-       }
-       
-
-       protected String getComponentText() {
-               return currentText = ((JTextComponent) c).getText();
-       }
-
-       protected void bindKeys(DOMNode domNode) {
-               JSFunction f = null;
-               JSEventHandler me = this;
-               if (!((JTextComponent) c).isEditable())
-                       return;
-               /**
-                * @j2sNative
-                * 
-                *            f = function(event) { me.handleJSEvent(me.domNode, 401, event)
-                *            }
-                */
-               {
-                       System.out.println(me);
-               }
-               $(domNode).bind("keydown keypress keyup", f);
-
-               // TODO Auto-generated method stub
-
-       }
-
-       /**
-        * Initializes component properties, e.g. font, foreground, background, caret
-        * color, selection color, selected text color, disabled text color, and
-        * border color. The font, foreground, and background properties are only set
-        * if their current value is either null or a UIResource, other properties are
-        * set if the current value is null.
-        * 
-        * @see #uninstallDefaults
-        * @see #installUI
-        */
-       protected void installDefaults() {
-               // String prefix = getPropertyPrefix();
-               // Font f = editor.getFont();
-               // if ((f == null) || (f instanceof UIResource)) {
-               // editor.setFont(UIManager.getFont(prefix + ".font"));
-               // }
-               //
-               // Color bg = editor.getBackground();
-               // if ((bg == null) || (bg instanceof UIResource)) {
-               // editor.setBackground(UIManager.getColor(prefix + ".background"));
-               // }
-               //
-               // Color fg = editor.getForeground();
-               // if ((fg == null) || (fg instanceof UIResource)) {
-               // editor.setForeground(UIManager.getColor(prefix + ".foreground"));
-               // }
-               //
-               // Color color = editor.getCaretColor();
-               // if ((color == null) || (color instanceof UIResource)) {
-               // editor.setCaretColor(UIManager.getColor(prefix + ".caretForeground"));
-               // }
-               //
-               // Color s = editor.getSelectionColor();
-               // if ((s == null) || (s instanceof UIResource)) {
-               // editor.setSelectionColor(UIManager.getColor(prefix +
-               // ".selectionBackground"));
-               // }
-               //
-               // Color sfg = editor.getSelectedTextColor();
-               // if ((sfg == null) || (sfg instanceof UIResource)) {
-               // editor.setSelectedTextColor(UIManager.getColor(prefix +
-               // ".selectionForeground"));
-               // }
-               //
-               // Color dfg = editor.getDisabledTextColor();
-               // if ((dfg == null) || (dfg instanceof UIResource)) {
-               // editor.setDisabledTextColor(UIManager.getColor(prefix +
-               // ".inactiveForeground"));
-               // }
-               //
-               // Border b = editor.getBorder();
-               // if ((b == null) || (b instanceof UIResource)) {
-               // editor.setBorder(UIManager.getBorder(prefix + ".border"));
-               // }
-               //
-               // Insets margin = editor.getMargin();
-               // if (margin == null || margin instanceof UIResource) {
-               // editor.setMargin(UIManager.getInsets(prefix + ".margin"));
-               // }
-               //
-               // updateCursor();
-       }
-
-       private void installDefaults2() {
-               // editor.addMouseListener(dragListener);
-               // editor.addMouseMotionListener(dragListener);
-               //
-               // String prefix = getPropertyPrefix();
-
-               Caret caret = editor.getCaret();
-               if (caret == null || caret instanceof UIResource) {
-                       editor.setCaret(new JSCaret());
-               }
-               //
-               // Highlighter highlighter = editor.getHighlighter();
-               // if (highlighter == null || highlighter instanceof UIResource) {
-               // editor.setHighlighter(createHighlighter());
-               // }
-               //
-               // TransferHandler th = editor.getTransferHandler();
-               // if (th == null || th instanceof UIResource) {
-               // editor.setTransferHandler(getTransferHandler());
-               // }
-       }
-
-       /**
-        * called by JmolCore.js
-        * 
-        * @return handled
-        */
-       public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
-               System.out.println("Handling for " + id + " " + eventType + " "
-                               + jQueryEvent);
-               return updateHandler.handleJSEvent(this, eventType, jQueryEvent);
-       }
-
-       /**
-        * Sets the component properties that haven't been explicitly overridden to
-        * null. A property is considered overridden if its current value is not a
-        * UIResource.
-        * 
-        * @see #installDefaults
-        * @see #uninstallUI
-        */
-       protected void uninstallDefaults() {
-               // editor.removeMouseListener(dragListener);
-               // editor.removeMouseMotionListener(dragListener);
-               //
-               if (editor.getCaretColor() instanceof UIResource) {
-                       editor.setCaretColor(null);
-               }
-
-               if (editor.getSelectionColor() instanceof UIResource) {
-                       editor.setSelectionColor(null);
-               }
-
-               if (editor.getDisabledTextColor() instanceof UIResource) {
-                       editor.setDisabledTextColor(null);
-               }
-
-               if (editor.getSelectedTextColor() instanceof UIResource) {
-                       editor.setSelectedTextColor(null);
-               }
-
-               if (editor.getBorder() instanceof UIResource) {
-                       editor.setBorder(null);
-               }
-
-               if (editor.getMargin() instanceof UIResource) {
-                       editor.setMargin(null);
-               }
-
-               // if (editor.getCaret() instanceof UIResource) {
-               // editor.setCaret(null);
-               // }
-               //
-               // if (editor.getHighlighter() instanceof UIResource) {
-               // editor.setHighlighter(null);
-               // }
-               //
-               // if (editor.getTransferHandler() instanceof UIResource) {
-               // editor.setTransferHandler(null);
-               // }
-               //
-               // if (editor.getCursor() instanceof UIResource) {
-               // editor.setCursor(null);
-               // }
-       }
-
-       protected void installKeyboardActions() {
-               // backward compatibility support... keymaps for the UI
-               // are now installed in the more friendly input map.
-               // editor.setKeymap(createKeymap());
-
-               InputMap km = getInputMap();
-               if (km != null) {
-                       SwingUtilities.replaceUIInputMap(editor, JComponent.WHEN_FOCUSED, km);
-               }
-
-               ActionMap map = getActionMap();
-               if (map != null) {
-                       SwingUtilities.replaceUIActionMap(editor, map);
-               }
-
-               // updateFocusAcceleratorBinding(false);
-       }
-
-       /**
-        * Get the InputMap to use for the UI.
-        */
-       InputMap getInputMap() {
-               InputMap map = new InputMapUIResource();
-
-               // InputMap shared =
-               // (InputMap)DefaultLookup.get(editor, this,
-               // getPropertyPrefix() + ".focusInputMap");
-               // if (shared != null) {
-               // map.setParent(shared);
-               // }
-               return map;
-       }
-
-       // /**
-       // * Invoked when the focus accelerator changes, this will update the
-       // * key bindings as necessary.
-       // */
-       // void updateFocusAcceleratorBinding(boolean changed) {
-       // char accelerator = editor.getFocusAccelerator();
-       //
-       // if (changed || accelerator != '\0') {
-       // InputMap km = SwingUtilities.getUIInputMap
-       // (editor, JComponent.WHEN_IN_FOCUSED_WINDOW);
-       //
-       // if (km == null && accelerator != '\0') {
-       // km = new ComponentInputMapUIResource(editor);
-       // SwingUtilities.replaceUIInputMap(editor, JComponent.
-       // WHEN_IN_FOCUSED_WINDOW, km);
-       // ActionMap am = getActionMap();
-       // SwingUtilities.replaceUIActionMap(editor, am);
-       // }
-       // if (km != null) {
-       // km.clear();
-       // if (accelerator != '\0') {
-       // km.put(KeyStroke.getKeyStroke(accelerator,
-       // ActionEvent.ALT_MASK),
-       // "requestFocus");
-       // }
-       // }
-       // }
-       // }
-       //
-       //
-       // /**
-       // * Invoked when editable property is changed.
-       // *
-       // * removing 'TAB' and 'SHIFT-TAB' from traversalKeysSet in case
-       // * editor is editable
-       // * adding 'TAB' and 'SHIFT-TAB' to traversalKeysSet in case
-       // * editor is non editable
-       // */
-       //
-       // void updateFocusTraversalKeys() {
-       // /*
-       // * Fix for 4514331 Non-editable JTextArea and similar
-       // * should allow Tab to keyboard - accessibility
-       // */
-       // EditorKit editorKit = getEditorKit(editor);
-       // if ( editorKit != null
-       // && editorKit instanceof DefaultEditorKit) {
-       // Set storedForwardTraversalKeys = editor.
-       // getFocusTraversalKeys(KeyboardFocusManager.
-       // FORWARD_TRAVERSAL_KEYS);
-       // Set storedBackwardTraversalKeys = editor.
-       // getFocusTraversalKeys(KeyboardFocusManager.
-       // BACKWARD_TRAVERSAL_KEYS);
-       // Set forwardTraversalKeys =
-       // new HashSet(storedForwardTraversalKeys);
-       // Set backwardTraversalKeys =
-       // new HashSet(storedBackwardTraversalKeys);
-       // if (editor.isEditable()) {
-       // forwardTraversalKeys.
-       // remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
-       // backwardTraversalKeys.
-       // remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
-       // InputEvent.SHIFT_MASK));
-       // } else {
-       // forwardTraversalKeys.add(KeyStroke.
-       // getKeyStroke(KeyEvent.VK_TAB, 0));
-       // backwardTraversalKeys.
-       // add(KeyStroke.
-       // getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
-       // }
-       // LookAndFeel.installProperty(editor,
-       // "focusTraversalKeysForward",
-       // forwardTraversalKeys);
-       // LookAndFeel.installProperty(editor,
-       // "focusTraversalKeysBackward",
-       // backwardTraversalKeys);
-       // }
-       //
-       // }
-
-       // /**
-       // * As needed updates cursor for the target editor.
-       // */
-       // private void updateCursor() {
-       // if ((! editor.isCursorSet())
-       // || editor.getCursor() instanceof UIResource) {
-       // Cursor cursor = (editor.isEditable()) ? textCursor : null;
-       // editor.setCursor(cursor);
-       // }
-       // }
-       //
-       // /**
-       // * Returns the <code>TransferHandler</code> that will be installed if
-       // * their isn't one installed on the <code>JTextComponent</code>.
-       // */
-       // TransferHandler getTransferHandler() {
-       // return defaultTransferHandler;
-       // }
-       //
-       /**
-        * Fetch an action map to use.
-        */
-       ActionMap getActionMap() {
-               String mapName = classID + ".actionMap";
-               ActionMap map = (ActionMap) UIManager.get(mapName);
-               if (map == null) {
-                       map = createActionMap();
-                       if (map != null) {
-                               UIManager.getLookAndFeelDefaults().put(mapName, map); 
-                       }
-               }
-               return map;
-       }
-       // ActionMap componentMap = new ActionMapUIResource();
-       // componentMap.put("requestFocus", new FocusAction());
-       // /*
-       // * fix for bug 4515750
-       // * JTextField & non-editable JTextArea bind return key - default btn not
-       // accessible
-       // *
-       // * Wrap the return action so that it is only enabled when the
-       // * component is editable. This allows the default button to be
-       // * processed when the text component has focus and isn't editable.
-       // *
-       // */
-       // if (getEditorKit(editor) instanceof DefaultEditorKit) {
-       // if (map != null) {
-       // Object obj = map.get(DefaultEditorKit.insertBreakAction);
-       // if (obj != null
-       // && obj instanceof DefaultEditorKit.InsertBreakAction) {
-       // Action action = new TextActionWrapper((TextAction)obj);
-       // componentMap.put(action.getValue(Action.NAME),action);
-       // }
-       // }
-       // }
-       // if (map != null) {
-       // componentMap.setParent(map);
-       // }
-       // return componentMap;
-       // }
-       //
-       /**
-        * Create a default action map. This is basically the set of actions found
-        * exported by the component.
-        */
-       /**
-        * @return
-        */
-       ActionMap createActionMap() {
-               ActionMap map = new ActionMapUIResource();
-               Action[] actions = editor.getActions();//defaultKit.getActions(); // SwingJS was editor.getEditorKit().getActions()
-               // System.out.println("building map for UI: " + getPropertyPrefix());
-               int n = actions.length;
-               for (int i = 0; i < n; i++) {
-                       Action a = actions[i];
-                       map.put(a.getValue(Action.NAME), a);
-                       // System.out.println("  " + a.getValue(Action.NAME));
-               }
-               // map.put(TransferHandler.getCutAction().getValue(Action.NAME),
-               // TransferHandler.getCutAction());
-               // map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
-               // TransferHandler.getCopyAction());
-               // map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
-               // TransferHandler.getPasteAction());
-               return map;
-       }
-
-       protected void uninstallKeyboardActions() {
-               editor.setKeymap(null);
-               SwingUtilities.replaceUIInputMap(editor, JComponent.WHEN_IN_FOCUSED_WINDOW,
-                               null);
-               SwingUtilities.replaceUIActionMap(editor, null);
-       }
-
-       // /**
-       // * Paints a background for the view. This will only be
-       // * called if isOpaque() on the associated component is
-       // * true. The default is to paint the background color
-       // * of the component.
-       // *
-       // * @param g the graphics context
-       // */
-       // protected void paintBackground(Graphics g) {
-       // g.setColor(editor.getBackground());
-       // g.fillRect(0, 0, editor.getWidth(), editor.getHeight());
-       // }
-       //
-       /**
-        * Fetches the text component associated with this UI implementation. This
-        * will be null until the ui has been installed.
-        * 
-        * @return the editor component
-        */
-       protected final JTextComponent getComponent() {
-               return editor;
-       }
-
-       // /**
-       // * Flags model changes.
-       // * This is called whenever the model has changed.
-       // * It is implemented to rebuild the view hierarchy
-       // * to represent the default root element of the
-       // * associated model.
-       // */
-       // protected void modelChanged() {
-       // // create a view hierarchy
-       // ViewFactory f = rootView.getViewFactory();
-       // Document doc = editor.getDocument();
-       // Element elem = doc.getDefaultRootElement();
-       // setView(f.create(elem));
-       // }
-       //
-       // /**
-       // * Sets the current root of the view hierarchy and calls invalidate().
-       // * If there were any child components, they will be removed (i.e.
-       // * there are assumed to have come from components embedded in views).
-       // *
-       // * @param v the root view
-       // */
-       // protected final void setView(View v) {
-       // rootView.setView(v);
-       // painted = false;
-       // editor.revalidate();
-       // editor.repaint();
-       // }
-       //
-       // /**
-       // * Paints the interface safely with a guarantee that
-       // * the model won't change from the view of this thread.
-       // * This does the following things, rendering from
-       // * back to front.
-       // * <ol>
-       // * <li>
-       // * If the component is marked as opaque, the background
-       // * is painted in the current background color of the
-       // * component.
-       // * <li>
-       // * The highlights (if any) are painted.
-       // * <li>
-       // * The view hierarchy is painted.
-       // * <li>
-       // * The caret is painted.
-       // * </ol>
-       // *
-       // * @param g the graphics context
-       // */
-       // protected void paintSafely(Graphics g) {
-       // painted = true;
-       // Highlighter highlighter = editor.getHighlighter();
-       // Caret caret = editor.getCaret();
-       //
-       // // paint the background
-       // if (editor.isOpaque()) {
-       // paintBackground(g);
-       // }
-       //
-       // // paint the highlights
-       // if (highlighter != null) {
-       // highlighter.paint(g);
-       // }
-       //
-       // // paint the view hierarchy
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // rootView.paint(g, alloc);
-       // }
-       //
-       // // paint the caret
-       // if (caret != null) {
-       // caret.paint(g);
-       // }
-       //
-       // if (dropCaret != null) {
-       // dropCaret.paint(g);
-       // }
-       // }
-
-       // --- ComponentUI methods --------------------------------------------
-
-       TextListener updateHandler;
-
-       /**
-        * Installs the UI for a component. This does the following things.
-        * <ol>
-        * <li>
-        * Set the associated component to opaque (can be changed easily by a subclass
-        * or on JTextComponent directly), which is the most common case. This will
-        * cause the component's background color to be painted.
-        * <li>
-        * Install the default caret and highlighter into the associated component.
-        * <li>
-        * Attach to the editor and model. If there is no model, a default one is
-        * created.
-        * <li>
-        * create the view factory and the view hierarchy used to represent the model.
-        * </ol>
-        * 
-        * @param c
-        *          the editor component
-        * @see ComponentUI#installUI
-        */
-       protected void installJSUI() {
-               editor = (JTextComponent) c;
-               updateHandler = new TextListener(this, editor);
-
-               // install defaults
-               installDefaults();
-               installDefaults2();
-
-               // // This is a workaround as these should not override what synth has
-               // // set them to
-               // if (!(this instanceof sun.swing.plaf.synth.SynthUI)){
-               // // common case is background painted... this can
-               // // easily be changed by subclasses or from outside
-               // // of the component.
-               // LookAndFeel.installProperty(editor, "opaque", Boolean.TRUE);
-               // LookAndFeel.installProperty(editor, "autoscrolls", Boolean.TRUE);
-               // }
-               //
-               // attach to the model and editor
-               // Document doc = editor.getDocument();
-               // if (doc == null) {
-               // // no model, create a default one. This will
-               // // fire a notification to the updateHandler
-               // // which takes care of the rest.
-               // editor.setDocument(getEditorKit(editor).createDefaultDocument());
-               // } else {
-               // // doc.addDocumentListener(updateHandler);
-               // // modelChanged();
-               // }
-
-               // install keymap
-               installListeners(editor);
-               installKeyboardActions();
-
-               // LayoutManager oldLayout = editor.getLayout();
-               // if ((oldLayout == null) || (oldLayout instanceof UIResource)) {
-               // // by default, use default LayoutManger implementation that
-               // // will position the components associated with a View object.
-               // editor.setLayout(updateHandler);
-               // }
-               //
-               // updateBackground(editor);
-       }
-
-       /**
-        * Deinstalls the UI for a component. This removes the listeners, uninstalls
-        * the highlighter, removes views, and nulls out the keymap.
-        * 
-        * @param c
-        *          the editor component
-        * @see ComponentUI#uninstallUI
-        */
-       public void uninstallJSUI() {
-               // detach from the model
-               // editor.removePropertyChangeListener(updateHandler);
-               // editor.getDocument().removeDocumentListener(updateHandler);
-
-               // view part
-               // painted = false;
-               uninstallDefaults();
-               // rootView.setView(null);
-               c.removeAll();
-               LayoutManager lm = c.getLayout();
-               if (lm instanceof UIResource) {
-                       c.setLayout(null);
-               }
-
-               // controller part
-               uninstallKeyboardActions();
-               uninstallListeners(editor);
-
-               editor = null;
-               updateHandler = null;
-       }
-
-       protected void installListeners(JTextComponent b) {
-               TextListener listener = updateHandler;
-               b.addMouseListener(listener);
-               b.addMouseMotionListener(listener);
-               b.addFocusListener(listener);
-               b.addPropertyChangeListener(listener);
-               // SwingJS there won't be a document yet; this is in constructor
-               // b.getDocument().addDocumentListener(listener);
-       }
-
-       protected void uninstallListeners(JTextComponent b) {
-               TextListener listener = updateHandler;
-               b.removeMouseListener(listener);
-               b.removeMouseMotionListener(listener);
-               b.removeFocusListener(listener);
-               b.removePropertyChangeListener(listener);
-               b.getDocument().removeDocumentListener(listener);
-       }
-
-       // /**
-       // * Superclass paints background in an uncontrollable way
-       // * (i.e. one might want an image tiled into the background).
-       // * To prevent this from happening twice, this method is
-       // * reimplemented to simply paint.
-       // * <p>
-       // * <em>NOTE:</em> Superclass is also not thread-safe in
-       // * it's rendering of the background, although that's not
-       // * an issue with the default rendering.
-       // */
-       // public void update(Graphics g, JComponent c) {
-       // paint(g, c);
-       // }
-       //
-       // /**
-       // * Paints the interface. This is routed to the
-       // * paintSafely method under the guarantee that
-       // * the model won't change from the view of this thread
-       // * while it's rendering (if the associated model is
-       // * derived from AbstractDocument). This enables the
-       // * model to potentially be updated asynchronously.
-       // *
-       // * @param g the graphics context
-       // * @param c the editor component
-       // */
-       // public final void paint(Graphics g, JComponent c) {
-       // if ((rootView.getViewCount() > 0) && (rootView.getView(0) != null)) {
-       // Document doc = editor.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // paintSafely(g);
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // }
-       // }
-
-       // /**
-       // * Gets the preferred size for the editor component. If the component
-       // * has been given a size prior to receiving this request, it will
-       // * set the size of the view hierarchy to reflect the size of the component
-       // * before requesting the preferred size of the view hierarchy. This
-       // * allows formatted views to format to the current component size before
-       // * answering the request. Other views don't care about currently formatted
-       // * size and give the same answer either way.
-       // *
-       // * @param c the editor component
-       // * @return the size
-       // */
-       // public Dimension getPreferredSize(JComponent c) {
-       // Dimension d = c.getSize();
-       // // Document doc = editor.getDocument();
-       // // Insets i = c.getInsets();
-       // //
-       // // if (doc instanceof AbstractDocument) {
-       // // ((AbstractDocument)doc).readLock();
-       // // }
-       // // try {
-       // // if ((d.width > (i.left + i.right)) && (d.height > (i.top + i.bottom))) {
-       // // rootView.setSize(d.width - i.left - i.right, d.height - i.top -
-       // i.bottom);
-       // // }
-       // // else if (d.width == 0 && d.height == 0) {
-       // // // Probably haven't been layed out yet, force some sort of
-       // // // initial sizing.
-       // // rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
-       // // }
-       // // d.width = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) +
-       // // (long) i.left + (long) i.right, Integer.MAX_VALUE);
-       // // d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS)
-       // +
-       // // (long) i.top + (long) i.bottom, Integer.MAX_VALUE);
-       // // } finally {
-       // // if (doc instanceof AbstractDocument) {
-       // // ((AbstractDocument)doc).readUnlock();
-       // // }
-       // // }
-       // return d;
-       // }
-
-       /**
-        * Gets the minimum size for the editor component.
-        * 
-        * @param c
-        *          the editor component
-        * @return the size
-        */
-       public Dimension getMinimumSize(JComponent c) {
-               Dimension d = getPreferredSize();// new Dimension();
-               // Document doc = editor.getDocument();
-               Insets i = c.getInsets();
-               // if (doc instanceof AbstractDocument) {
-               // ((AbstractDocument)doc).readLock();
-               // }
-               // try {
-
-               d.width += i.left + i.right;
-               d.height += i.top + i.bottom;
-
-               // d.width = (int) rootView.getMinimumSpan(View.X_AXIS) + i.left + i.right;
-               // d.height = (int) rootView.getMinimumSpan(View.Y_AXIS) + i.top + i.bottom;
-               // } finally {
-               // if (doc instanceof AbstractDocument) {
-               // ((AbstractDocument)doc).readUnlock();
-               // }
-               // }
-               return d;
-       }
-
-       /**
-        * Gets the maximum size for the editor component.
-        * 
-        * @param c
-        *          the editor component
-        * @return the size
-        */
-       public Dimension getMaximumSize(JComponent c) {
-               // SwingJS TODO
-               return getMinimumSize(c);
-
-               // Document doc = editor.getDocument();
-               // Insets i = c.getInsets();
-               // Dimension d = new Dimension();
-               // if (doc instanceof AbstractDocument) {
-               // ((AbstractDocument)doc).readLock();
-               // }
-               // try {
-               // d.width = (int) Math.min((long) rootView.getMaximumSpan(View.X_AXIS) +
-               // (long) i.left + (long) i.right, Integer.MAX_VALUE);
-               // d.height = (int) Math.min((long) rootView.getMaximumSpan(View.Y_AXIS) +
-               // (long) i.top + (long) i.bottom, Integer.MAX_VALUE);
-               // } finally {
-               // if (doc instanceof AbstractDocument) {
-               // ((AbstractDocument)doc).readUnlock();
-               // }
-               // }
-               // return d;
-       }
-
-       // ---- TextUI methods -------------------------------------------
-
-       //
-       // /**
-       // * Gets the allocation to give the root View. Due
-       // * to an unfortunate set of historical events this
-       // * method is inappropriately named. The Rectangle
-       // * returned has nothing to do with visibility.
-       // * The component must have a non-zero positive size for
-       // * this translation to be computed.
-       // *
-       // * @return the bounding box for the root view
-       // */
-       // protected Rectangle getVisibleEditorRect() {
-       // Rectangle alloc = editor.getBounds();
-       // if ((alloc.width > 0) && (alloc.height > 0)) {
-       // alloc.x = alloc.y = 0;
-       // Insets insets = editor.getInsets();
-       // alloc.x += insets.left;
-       // alloc.y += insets.top;
-       // alloc.width -= insets.left + insets.right;
-       // alloc.height -= insets.top + insets.bottom;
-       // return alloc;
-       // }
-       // return null;
-       // }
-       //
-       // /**
-       // * Converts the given location in the model to a place in
-       // * the view coordinate system.
-       // * The component must have a non-zero positive size for
-       // * this translation to be computed.
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @param pos the local location in the model to translate >= 0
-       // * @return the coordinates as a rectangle, null if the model is not painted
-       // * @exception BadLocationException if the given position does not
-       // * represent a valid location in the associated document
-       // * @see TextUI#modelToView
-       // */
-       // public Rectangle modelToView(JTextComponent tc, int pos) throws
-       // BadLocationException {
-       // return modelToView(tc, pos, Position.Bias.Forward);
-       // }
-       //
-       // /**
-       // * Converts the given location in the model to a place in
-       // * the view coordinate system.
-       // * The component must have a non-zero positive size for
-       // * this translation to be computed.
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @param pos the local location in the model to translate >= 0
-       // * @return the coordinates as a rectangle, null if the model is not painted
-       // * @exception BadLocationException if the given position does not
-       // * represent a valid location in the associated document
-       // * @see TextUI#modelToView
-       // */
-       // public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias
-       // bias) throws BadLocationException {
-       // Document doc = editor.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // rootView.setSize(alloc.width, alloc.height);
-       // Shape s = rootView.modelToView(pos, alloc, bias);
-       // if (s != null) {
-       // return s.getBounds();
-       // }
-       // }
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // return null;
-       // }
-       //
-       // /**
-       // * Converts the given place in the view coordinate system
-       // * to the nearest representative location in the model.
-       // * The component must have a non-zero positive size for
-       // * this translation to be computed.
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @param pt the location in the view to translate. This
-       // * should be in the same coordinate system as the mouse events.
-       // * @return the offset from the start of the document >= 0,
-       // * -1 if not painted
-       // * @see TextUI#viewToModel
-       // */
-       // public int viewToModel(JTextComponent tc, Point pt) {
-       // return viewToModel(tc, pt, discardBias);
-       // }
-       //
-       // /**
-       // * Converts the given place in the view coordinate system
-       // * to the nearest representative location in the model.
-       // * The component must have a non-zero positive size for
-       // * this translation to be computed.
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @param pt the location in the view to translate. This
-       // * should be in the same coordinate system as the mouse events.
-       // * @return the offset from the start of the document >= 0,
-       // * -1 if the component doesn't yet have a positive size.
-       // * @see TextUI#viewToModel
-       // */
-       // public int viewToModel(JTextComponent tc, Point pt,
-       // Position.Bias[] biasReturn) {
-       // int offs = -1;
-       // Document doc = editor.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // rootView.setSize(alloc.width, alloc.height);
-       // offs = rootView.viewToModel(pt.x, pt.y, alloc, biasReturn);
-       // }
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // return offs;
-       // }
-
-       // /**
-       // * {@inheritDoc}
-       // */
-       // public int getNextVisualPositionFrom(JTextComponent t, int pos,
-       // Position.Bias b, int direction, Position.Bias[] biasRet)
-       // throws BadLocationException{
-       // Document doc = editor.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // if (painted) {
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // rootView.setSize(alloc.width, alloc.height);
-       // }
-       // return rootView.getNextVisualPositionFrom(pos, b, alloc, direction,
-       // biasRet);
-       // }
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // return -1;
-       // }
-       //
-       // /**
-       // * Causes the portion of the view responsible for the
-       // * given part of the model to be repainted. Does nothing if
-       // * the view is not currently painted.
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @param p0 the beginning of the range >= 0
-       // * @param p1 the end of the range >= p0
-       // * @see TextUI#damageRange
-       // */
-       // public void damageRange(JTextComponent tc, int p0, int p1) {
-       // damageRange(tc, p0, p1, Position.Bias.Forward, Position.Bias.Backward);
-       // }
-       //
-       // /**
-       // * Causes the portion of the view responsible for the
-       // * given part of the model to be repainted.
-       // *
-       // * @param p0 the beginning of the range >= 0
-       // * @param p1 the end of the range >= p0
-       // */
-       // public void damageRange(JTextComponent t, int p0, int p1,
-       // Position.Bias p0Bias, Position.Bias p1Bias) {
-       // if (painted) {
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // Document doc = t.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // rootView.setSize(alloc.width, alloc.height);
-       // Shape toDamage = rootView.modelToView(p0, p0Bias,
-       // p1, p1Bias, alloc);
-       // Rectangle rect = (toDamage instanceof Rectangle) ?
-       // (Rectangle)toDamage : toDamage.getBounds();
-       // editor.repaint(rect.x, rect.y, rect.width, rect.height);
-       // } catch (BadLocationException e) {
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // }
-       // }
-       // }
-
-       /**
-        * Fetches the EditorKit for the UI.
-        * 
-        * @param tc
-        *          the text component for which this UI is installed
-        * @return the editor capabilities
-        * @see TextUI#getEditorKit
-        */
-       public EditorKit getEditorKit(JTextComponent tc) {
-               return defaultKit;
-       }
-
-       // /**
-       // * Fetches a View with the allocation of the associated
-       // * text component (i.e. the root of the hierarchy) that
-       // * can be traversed to determine how the model is being
-       // * represented spatially.
-       // * <p>
-       // * <font color=red><b>NOTE:</b>The View hierarchy can
-       // * be traversed from the root view, and other things
-       // * can be done as well. Things done in this way cannot
-       // * be protected like simple method calls through the TextUI.
-       // * Therefore, proper operation in the presence of concurrency
-       // * must be arranged by any logic that calls this method!
-       // * </font>
-       // *
-       // * @param tc the text component for which this UI is installed
-       // * @return the view
-       // * @see TextUI#getRootView
-       // */
-       // public View getRootView(JTextComponent tc) {
-       // return rootView;
-       // }
-
-       // /**
-       // * Returns the string to be used as the tooltip at the passed in location.
-       // * This forwards the method onto the root View.
-       // *
-       // * @see jsjavax.swing.text.JTextComponent#getToolTipText
-       // * @see jsjavax.swing.text.View#getToolTipText
-       // * @since 1.4
-       // */
-       // public String getToolTipText(JTextComponent t, Point pt) {
-       // if (!painted) {
-       // return null;
-       // }
-       // Document doc = editor.getDocument();
-       // String tt = null;
-       // Rectangle alloc = getVisibleEditorRect();
-       //
-       // if (alloc != null) {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // tt = rootView.getToolTipText(pt.x, pt.y, alloc);
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // }
-       // return tt;
-       // }
-       //
-       // --- ViewFactory methods ------------------------------
-       //
-       // /**
-       // * Creates a view for an element.
-       // * If a subclass wishes to directly implement the factory
-       // * producing the view(s), it should reimplement this
-       // * method. By default it simply returns null indicating
-       // * it is unable to represent the element.
-       // *
-       // * @param elem the element
-       // * @return the view
-       // */
-       // public View create(Element elem) {
-       // return null;
-       // }
-       //
-       // /**
-       // * Creates a view for an element.
-       // * If a subclass wishes to directly implement the factory
-       // * producing the view(s), it should reimplement this
-       // * method. By default it simply returns null indicating
-       // * it is unable to represent the part of the element.
-       // *
-       // * @param elem the element
-       // * @param p0 the starting offset >= 0
-       // * @param p1 the ending offset >= p0
-       // * @return the view
-       // */
-       // public View create(Element elem, int p0, int p1) {
-       // return null;
-       // }
-       //
-       // public static class BasicCaret extends DefaultCaret implements UIResource
-       // {}
-       //
-       // public static class BasicHighlighter extends DefaultHighlighter implements
-       // UIResource {}
-       //
-       // static class BasicCursor extends Cursor implements UIResource {
-       // BasicCursor(int type) {
-       // super(type);
-       // }
-       //
-       // BasicCursor(String name) {
-       // super(name);
-       // }
-       // }
-       //
-       // private static BasicCursor textCursor = new
-       // BasicCursor(Cursor.TEXT_CURSOR);
-       // ----- member variables ---------------------------------------
-
-       private static final EditorKit defaultKit = new DefaultEditorKit();
-       transient JTextComponent editor;
-       protected boolean editable = true;
-
-       // transient boolean painted;
-       // transient RootView rootView = new RootView();
-       // transient UpdateHandler updateHandler = new UpdateHandler();
-       // private static final TransferHandler defaultTransferHandler = new
-       // TextTransferHandler();
-       // private final DragListener dragListener = getDragListener();
-       // private static final Position.Bias[] discardBias = new Position.Bias[1];
-       // private DefaultCaret dropCaret;
-
-       // /**
-       // * Root view that acts as a gateway between the component
-       // * and the View hierarchy.
-       // */
-       // class RootView extends View {
-       //
-       // RootView() {
-       // super(null);
-       // }
-       //
-       // void setView(View v) {
-       // View oldView = view;
-       // view = null;
-       // if (oldView != null) {
-       // // get rid of back reference so that the old
-       // // hierarchy can be garbage collected.
-       // oldView.setParent(null);
-       // }
-       // if (v != null) {
-       // v.setParent(this);
-       // }
-       // view = v;
-       // }
-       //
-       // /**
-       // * Fetches the attributes to use when rendering. At the root
-       // * level there are no attributes. If an attribute is resolved
-       // * up the view hierarchy this is the end of the line.
-       // */
-       // public AttributeSet getAttributes() {
-       // return null;
-       // }
-       //
-       // /**
-       // * Determines the preferred span for this view along an axis.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @return the span the view would like to be rendered into.
-       // * Typically the view is told to render into the span
-       // * that is returned, although there is no guarantee.
-       // * The parent may choose to resize or break the view.
-       // */
-       // public float getPreferredSpan(int axis) {
-       // if (view != null) {
-       // return view.getPreferredSpan(axis);
-       // }
-       // return 10;
-       // }
-       //
-       // /**
-       // * Determines the minimum span for this view along an axis.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @return the span the view would like to be rendered into.
-       // * Typically the view is told to render into the span
-       // * that is returned, although there is no guarantee.
-       // * The parent may choose to resize or break the view.
-       // */
-       // public float getMinimumSpan(int axis) {
-       // if (view != null) {
-       // return view.getMinimumSpan(axis);
-       // }
-       // return 10;
-       // }
-       //
-       // /**
-       // * Determines the maximum span for this view along an axis.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @return the span the view would like to be rendered into.
-       // * Typically the view is told to render into the span
-       // * that is returned, although there is no guarantee.
-       // * The parent may choose to resize or break the view.
-       // */
-       // public float getMaximumSpan(int axis) {
-       // return Integer.MAX_VALUE;
-       // }
-       //
-       // /**
-       // * Specifies that a preference has changed.
-       // * Child views can call this on the parent to indicate that
-       // * the preference has changed. The root view routes this to
-       // * invalidate on the hosting component.
-       // * <p>
-       // * This can be called on a different thread from the
-       // * event dispatching thread and is basically unsafe to
-       // * propagate into the component. To make this safe,
-       // * the operation is transferred over to the event dispatching
-       // * thread for completion. It is a design goal that all view
-       // * methods be safe to call without concern for concurrency,
-       // * and this behavior helps make that true.
-       // *
-       // * @param child the child view
-       // * @param width true if the width preference has changed
-       // * @param height true if the height preference has changed
-       // */
-       // public void preferenceChanged(View child, boolean width, boolean height) {
-       // editor.revalidate();
-       // }
-       //
-       // /**
-       // * Determines the desired alignment for this view along an axis.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @return the desired alignment, where 0.0 indicates the origin
-       // * and 1.0 the full span away from the origin
-       // */
-       // public float getAlignment(int axis) {
-       // if (view != null) {
-       // return view.getAlignment(axis);
-       // }
-       // return 0;
-       // }
-       //
-       // /**
-       // * Renders the view.
-       // *
-       // * @param g the graphics context
-       // * @param allocation the region to render into
-       // */
-       // public void paint(Graphics g, Shape allocation) {
-       // if (view != null) {
-       // Rectangle alloc = (allocation instanceof Rectangle) ?
-       // (Rectangle)allocation : allocation.getBounds();
-       // setSize(alloc.width, alloc.height);
-       // view.paint(g, allocation);
-       // }
-       // }
-       //
-       // /**
-       // * Sets the view parent.
-       // *
-       // * @param parent the parent view
-       // */
-       // public void setParent(View parent) {
-       // throw new Error("Can't set parent on root view");
-       // }
-       //
-       // /**
-       // * Returns the number of views in this view. Since
-       // * this view simply wraps the root of the view hierarchy
-       // * it has exactly one child.
-       // *
-       // * @return the number of views
-       // * @see #getView
-       // */
-       // public int getViewCount() {
-       // return 1;
-       // }
-       //
-       // /**
-       // * Gets the n-th view in this container.
-       // *
-       // * @param n the number of the view to get
-       // * @return the view
-       // */
-       // public View getView(int n) {
-       // return view;
-       // }
-       //
-       // /**
-       // * Returns the child view index representing the given position in
-       // * the model. This is implemented to return the index of the only
-       // * child.
-       // *
-       // * @param pos the position >= 0
-       // * @return index of the view representing the given position, or
-       // * -1 if no view represents that position
-       // * @since 1.3
-       // */
-       // public int getViewIndex(int pos, Position.Bias b) {
-       // return 0;
-       // }
-       //
-       // /**
-       // * Fetches the allocation for the given child view.
-       // * This enables finding out where various views
-       // * are located, without assuming the views store
-       // * their location. This returns the given allocation
-       // * since this view simply acts as a gateway between
-       // * the view hierarchy and the associated component.
-       // *
-       // * @param index the index of the child
-       // * @param a the allocation to this view.
-       // * @return the allocation to the child
-       // */
-       // public Shape getChildAllocation(int index, Shape a) {
-       // return a;
-       // }
-       //
-       // /**
-       // * Provides a mapping from the document model coordinate space
-       // * to the coordinate space of the view mapped to it.
-       // *
-       // * @param pos the position to convert
-       // * @param a the allocated region to render into
-       // * @return the bounding box of the given position
-       // */
-       // public Shape modelToView(int pos, Shape a, Position.Bias b) throws
-       // BadLocationException {
-       // if (view != null) {
-       // return view.modelToView(pos, a, b);
-       // }
-       // return null;
-       // }
-       //
-       // /**
-       // * Provides a mapping from the document model coordinate space
-       // * to the coordinate space of the view mapped to it.
-       // *
-       // * @param p0 the position to convert >= 0
-       // * @param b0 the bias toward the previous character or the
-       // * next character represented by p0, in case the
-       // * position is a boundary of two views.
-       // * @param p1 the position to convert >= 0
-       // * @param b1 the bias toward the previous character or the
-       // * next character represented by p1, in case the
-       // * position is a boundary of two views.
-       // * @param a the allocated region to render into
-       // * @return the bounding box of the given position is returned
-       // * @exception BadLocationException if the given position does
-       // * not represent a valid location in the associated document
-       // * @exception IllegalArgumentException for an invalid bias argument
-       // * @see View#viewToModel
-       // */
-       // public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias
-       // b1, Shape a) throws BadLocationException {
-       // if (view != null) {
-       // return view.modelToView(p0, b0, p1, b1, a);
-       // }
-       // return null;
-       // }
-       //
-       // /**
-       // * Provides a mapping from the view coordinate space to the logical
-       // * coordinate space of the model.
-       // *
-       // * @param x x coordinate of the view location to convert
-       // * @param y y coordinate of the view location to convert
-       // * @param a the allocated region to render into
-       // * @return the location within the model that best represents the
-       // * given point in the view
-       // */
-       // public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
-       // if (view != null) {
-       // int retValue = view.viewToModel(x, y, a, bias);
-       // return retValue;
-       // }
-       // return -1;
-       // }
-       //
-       // /**
-       // * Provides a way to determine the next visually represented model
-       // * location that one might place a caret. Some views may not be visible,
-       // * they might not be in the same order found in the model, or they just
-       // * might not allow access to some of the locations in the model.
-       // *
-       // * @param pos the position to convert >= 0
-       // * @param a the allocated region to render into
-       // * @param direction the direction from the current position that can
-       // * be thought of as the arrow keys typically found on a keyboard.
-       // * This may be SwingConstants.WEST, SwingConstants.EAST,
-       // * SwingConstants.NORTH, or SwingConstants.SOUTH.
-       // * @return the location within the model that best represents the next
-       // * location visual position.
-       // * @exception BadLocationException
-       // * @exception IllegalArgumentException for an invalid direction
-       // */
-       // public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
-       // int direction,
-       // Position.Bias[] biasRet)
-       // throws BadLocationException {
-       // if( view != null ) {
-       // int nextPos = view.getNextVisualPositionFrom(pos, b, a,
-       // direction, biasRet);
-       // if(nextPos != -1) {
-       // pos = nextPos;
-       // }
-       // else {
-       // biasRet[0] = b;
-       // }
-       // }
-       // return pos;
-       // }
-       //
-       // /**
-       // * Gives notification that something was inserted into the document
-       // * in a location that this view is responsible for.
-       // *
-       // * @param e the change information from the associated document
-       // * @param a the current allocation of the view
-       // * @param f the factory to use to rebuild if the view has children
-       // */
-       // public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
-       // if (view != null) {
-       // view.insertUpdate(e, a, f);
-       // }
-       // }
-       //
-       // /**
-       // * Gives notification that something was removed from the document
-       // * in a location that this view is responsible for.
-       // *
-       // * @param e the change information from the associated document
-       // * @param a the current allocation of the view
-       // * @param f the factory to use to rebuild if the view has children
-       // */
-       // public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
-       // if (view != null) {
-       // view.removeUpdate(e, a, f);
-       // }
-       // }
-       //
-       // /**
-       // * Gives notification from the document that attributes were changed
-       // * in a location that this view is responsible for.
-       // *
-       // * @param e the change information from the associated document
-       // * @param a the current allocation of the view
-       // * @param f the factory to use to rebuild if the view has children
-       // */
-       // public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
-       // if (view != null) {
-       // view.changedUpdate(e, a, f);
-       // }
-       // }
-       //
-       // /**
-       // * Returns the document model underlying the view.
-       // *
-       // * @return the model
-       // */
-       // public Document getDocument() {
-       // return editor.getDocument();
-       // }
-       //
-       // /**
-       // * Returns the starting offset into the model for this view.
-       // *
-       // * @return the starting offset
-       // */
-       // public int getStartOffset() {
-       // if (view != null) {
-       // return view.getStartOffset();
-       // }
-       // return getElement().getStartOffset();
-       // }
-       //
-       // /**
-       // * Returns the ending offset into the model for this view.
-       // *
-       // * @return the ending offset
-       // */
-       // public int getEndOffset() {
-       // if (view != null) {
-       // return view.getEndOffset();
-       // }
-       // return getElement().getEndOffset();
-       // }
-       //
-       // /**
-       // * Gets the element that this view is mapped to.
-       // *
-       // * @return the view
-       // */
-       // public Element getElement() {
-       // if (view != null) {
-       // return view.getElement();
-       // }
-       // return editor.getDocument().getDefaultRootElement();
-       // }
-       //
-       // /**
-       // * Breaks this view on the given axis at the given length.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @param len specifies where a break is desired in the span
-       // * @param the current allocation of the view
-       // * @return the fragment of the view that represents the given span
-       // * if the view can be broken, otherwise null
-       // */
-       // public View breakView(int axis, float len, Shape a) {
-       // throw new Error("Can't break root view");
-       // }
-       //
-       // /**
-       // * Determines the resizability of the view along the
-       // * given axis. A value of 0 or less is not resizable.
-       // *
-       // * @param axis may be either X_AXIS or Y_AXIS
-       // * @return the weight
-       // */
-       // public int getResizeWeight(int axis) {
-       // if (view != null) {
-       // return view.getResizeWeight(axis);
-       // }
-       // return 0;
-       // }
-       //
-       // /**
-       // * Sets the view size.
-       // *
-       // * @param width the width
-       // * @param height the height
-       // */
-       // public void setSize(float width, float height) {
-       // if (view != null) {
-       // view.setSize(width, height);
-       // }
-       // }
-       //
-       // /**
-       // * Fetches the container hosting the view. This is useful for
-       // * things like scheduling a repaint, finding out the host
-       // * components font, etc. The default implementation
-       // * of this is to forward the query to the parent view.
-       // *
-       // * @return the container
-       // */
-       // public Container getContainer() {
-       // return editor;
-       // }
-       //
-       // /**
-       // * Fetches the factory to be used for building the
-       // * various view fragments that make up the view that
-       // * represents the model. This is what determines
-       // * how the model will be represented. This is implemented
-       // * to fetch the factory provided by the associated
-       // * EditorKit unless that is null, in which case this
-       // * simply returns the BasicTextUI itself which allows
-       // * subclasses to implement a simple factory directly without
-       // * creating extra objects.
-       // *
-       // * @return the factory
-       // */
-       // public ViewFactory getViewFactory() {
-       // EditorKit kit = getEditorKit(editor);
-       // ViewFactory f = kit.getViewFactory();
-       // if (f != null) {
-       // return f;
-       // }
-       // return BasicTextUI.this;
-       // }
-       //
-       // private View view;
-       //
-       // }
-
-       // /**
-       // * Handles updates from various places. If the model is changed,
-       // * this class unregisters as a listener to the old model and
-       // * registers with the new model. If the document model changes,
-       // * the change is forwarded to the root view. If the focus
-       // * accelerator changes, a new keystroke is registered to request
-       // * focus.
-       // */
-       // class UpdateHandler implements PropertyChangeListener, DocumentListener,
-       // LayoutManager2, UIResource {
-       //
-       // // --- PropertyChangeListener methods -----------------------
-       //
-       // /**
-       // * This method gets called when a bound property is changed.
-       // * We are looking for document changes on the editor.
-       // */
-       // public final void propertyChange(PropertyChangeEvent evt) {
-       // Object oldValue = evt.getOldValue();
-       // Object newValue = evt.getNewValue();
-       // String propertyName = evt.getPropertyName();
-       // if ((oldValue instanceof Document) || (newValue instanceof Document)) {
-       // if (oldValue != null) {
-       // ((Document)oldValue).removeDocumentListener(this);
-       // i18nView = false;
-       // }
-       // if (newValue != null) {
-       // ((Document)newValue).addDocumentListener(this);
-       // if ("document" == propertyName) {
-       // setView(null);
-       // BasicTextUI.this.propertyChange(evt);
-       // modelChanged();
-       // return;
-       // }
-       // }
-       // modelChanged();
-       // }
-       // if ("focusAccelerator" == propertyName) {
-       // updateFocusAcceleratorBinding(true);
-       // } else if ("componentOrientation" == propertyName) {
-       // // Changes in ComponentOrientation require the views to be
-       // // rebuilt.
-       // modelChanged();
-       // } else if ("font" == propertyName) {
-       // modelChanged();
-       // } else if ("dropLocation" == propertyName) {
-       // dropIndexChanged();
-       // } else if ("editable" == propertyName) {
-       // updateCursor();
-       // modelChanged();
-       // }
-       // BasicTextUI.this.propertyChange(evt);
-       // }
-       //
-       // private void dropIndexChanged() {
-       // if (editor.getDropMode() == DropMode.USE_SELECTION) {
-       // return;
-       // }
-       //
-       // JTextComponent.DropLocation dropLocation = editor.getDropLocation();
-       //
-       // if (dropLocation == null) {
-       // if (dropCaret != null) {
-       // dropCaret.deinstall(editor);
-       // editor.repaint(dropCaret);
-       // dropCaret = null;
-       // }
-       // } else {
-       // if (dropCaret == null) {
-       // dropCaret = new BasicCaret();
-       // dropCaret.install(editor);
-       // dropCaret.setVisible(true);
-       // }
-       //
-       // dropCaret.setDot(dropLocation.getIndex(),
-       // dropLocation.getBias());
-       // }
-       // }
-       //
-       // // --- DocumentListener methods -----------------------
-       //
-       // /**
-       // * The insert notification. Gets sent to the root of the view structure
-       // * that represents the portion of the model being represented by the
-       // * editor. The factory is added as an argument to the update so that
-       // * the views can update themselves in a dynamic (not hardcoded) way.
-       // *
-       // * @param e The change notification from the currently associated
-       // * document.
-       // * @see DocumentListener#insertUpdate
-       // */
-       // public final void insertUpdate(DocumentEvent e) {
-       // Document doc = e.getDocument();
-       // Object o = doc.getProperty("i18n");
-       // if (o instanceof Boolean) {
-       // Boolean i18nFlag = (Boolean) o;
-       // if (i18nFlag.booleanValue() != i18nView) {
-       // // i18n flag changed, rebuild the view
-       // i18nView = i18nFlag.booleanValue();
-       // modelChanged();
-       // return;
-       // }
-       // }
-       //
-       // // normal insert update
-       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;
-       // rootView.insertUpdate(e, alloc, rootView.getViewFactory());
-       // }
-       //
-       // /**
-       // * The remove notification. Gets sent to the root of the view structure
-       // * that represents the portion of the model being represented by the
-       // * editor. The factory is added as an argument to the update so that
-       // * the views can update themselves in a dynamic (not hardcoded) way.
-       // *
-       // * @param e The change notification from the currently associated
-       // * document.
-       // * @see DocumentListener#removeUpdate
-       // */
-       // public final void removeUpdate(DocumentEvent e) {
-       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;
-       // rootView.removeUpdate(e, alloc, rootView.getViewFactory());
-       // }
-       //
-       // /**
-       // * The change notification. Gets sent to the root of the view structure
-       // * that represents the portion of the model being represented by the
-       // * editor. The factory is added as an argument to the update so that
-       // * the views can update themselves in a dynamic (not hardcoded) way.
-       // *
-       // * @param e The change notification from the currently associated
-       // * document.
-       // * @see DocumentListener#changeUpdate
-       // */
-       // public final void changedUpdate(DocumentEvent e) {
-       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;
-       // rootView.changedUpdate(e, alloc, rootView.getViewFactory());
-       // }
-       //
-       // // --- LayoutManager2 methods --------------------------------
-       //
-       // /**
-       // * Adds the specified component with the specified name to
-       // * the layout.
-       // * @param name the component name
-       // * @param comp the component to be added
-       // */
-       // public void addLayoutComponent(String name, Component comp) {
-       // // not supported
-       // }
-       //
-       // /**
-       // * Removes the specified component from the layout.
-       // * @param comp the component to be removed
-       // */
-       // public void removeLayoutComponent(Component comp) {
-       // if (constraints != null) {
-       // // remove the constraint record
-       // constraints.remove(comp);
-       // }
-       // }
-       //
-       // /**
-       // * Calculates the preferred size dimensions for the specified
-       // * panel given the components in the specified parent container.
-       // * @param parent the component to be laid out
-       // *
-       // * @see #minimumLayoutSize
-       // */
-       // public Dimension preferredLayoutSize(Container parent) {
-       // // should not be called (JComponent uses UI instead)
-       // return null;
-       // }
-       //
-       // /**
-       // * Calculates the minimum size dimensions for the specified
-       // * panel given the components in the specified parent container.
-       // * @param parent the component to be laid out
-       // * @see #preferredLayoutSize
-       // */
-       // public Dimension minimumLayoutSize(Container parent) {
-       // // should not be called (JComponent uses UI instead)
-       // return null;
-       // }
-       //
-       // /**
-       // * Lays out the container in the specified panel. This is
-       // * implemented to position all components that were added
-       // * with a View object as a constraint. The current allocation
-       // * of the associated View is used as the location of the
-       // * component.
-       // * <p>
-       // * A read-lock is acquired on the document to prevent the
-       // * view tree from being modified while the layout process
-       // * is active.
-       // *
-       // * @param parent the component which needs to be laid out
-       // */
-       // public void layoutContainer(Container parent) {
-       // if ((constraints != null) && (! constraints.isEmpty())) {
-       // Rectangle alloc = getVisibleEditorRect();
-       // if (alloc != null) {
-       // Document doc = editor.getDocument();
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readLock();
-       // }
-       // try {
-       // rootView.setSize(alloc.width, alloc.height);
-       // Enumeration components = constraints.keys();
-       // while (components.hasMoreElements()) {
-       // Component comp = (Component) components.nextElement();
-       // View v = (View) constraints.get(comp);
-       // Shape ca = calculateViewPosition(alloc, v);
-       // if (ca != null) {
-       // Rectangle compAlloc = (ca instanceof Rectangle) ?
-       // (Rectangle) ca : ca.getBounds();
-       // comp.setBounds(compAlloc);
-       // }
-       // }
-       // } finally {
-       // if (doc instanceof AbstractDocument) {
-       // ((AbstractDocument)doc).readUnlock();
-       // }
-       // }
-       // }
-       // }
-       // }
-       //
-       // /**
-       // * Find the Shape representing the given view.
-       // */
-       // Shape calculateViewPosition(Shape alloc, View v) {
-       // int pos = v.getStartOffset();
-       // View child = null;
-       // for (View parent = rootView; (parent != null) && (parent != v); parent =
-       // child) {
-       // int index = parent.getViewIndex(pos, Position.Bias.Forward);
-       // alloc = parent.getChildAllocation(index, alloc);
-       // child = parent.getView(index);
-       // }
-       // return (child != null) ? alloc : null;
-       // }
-       //
-       // /**
-       // * Adds the specified component to the layout, using the specified
-       // * constraint object. We only store those components that were added
-       // * with a constraint that is of type View.
-       // *
-       // * @param comp the component to be added
-       // * @param constraint where/how the component is added to the layout.
-       // */
-       // public void addLayoutComponent(Component comp, Object constraint) {
-       // if (constraint instanceof View) {
-       // if (constraints == null) {
-       // constraints = new Hashtable(7);
-       // }
-       // constraints.put(comp, constraint);
-       // }
-       // }
-       //
-       // /**
-       // * Returns the maximum size of this component.
-       // * @see jsjava.awt.Component#getMinimumSize()
-       // * @see jsjava.awt.Component#getPreferredSize()
-       // * @see LayoutManager
-       // */
-       // public Dimension maximumLayoutSize(Container target) {
-       // // should not be called (JComponent uses UI instead)
-       // return null;
-       // }
-       //
-       // /**
-       // * Returns the alignment along the x axis. This specifies how
-       // * the component would like to be aligned relative to other
-       // * components. The value should be a number between 0 and 1
-       // * where 0 represents alignment along the origin, 1 is aligned
-       // * the furthest away from the origin, 0.5 is centered, etc.
-       // */
-       // public float getLayoutAlignmentX(Container target) {
-       // return 0.5f;
-       // }
-       //
-       // /**
-       // * Returns the alignment along the y axis. This specifies how
-       // * the component would like to be aligned relative to other
-       // * components. The value should be a number between 0 and 1
-       // * where 0 represents alignment along the origin, 1 is aligned
-       // * the furthest away from the origin, 0.5 is centered, etc.
-       // */
-       // public float getLayoutAlignmentY(Container target) {
-       // return 0.5f;
-       // }
-       //
-       // /**
-       // * Invalidates the layout, indicating that if the layout manager
-       // * has cached information it should be discarded.
-       // */
-       // public void invalidateLayout(Container target) {
-       // }
-       //
-       // /**
-       // * The "layout constraints" for the LayoutManager2 implementation.
-       // * These are View objects for those components that are represented
-       // * by a View in the View tree.
-       // */
-       // private Hashtable constraints;
-       //
-       // private boolean i18nView = false;
-       // }
-
-       /**
-        * Wrapper for text actions to return isEnabled false in case editor is non
-        * editable
-        */
-       class TextActionWrapper extends TextAction {
-               public TextActionWrapper(TextAction action) {
-                       super((String) action.getValue(Action.NAME));
-                       this.action = action;
-               }
-
-               /**
-                * The operation to perform when this action is triggered.
-                * 
-                * @param e
-                *          the action event
-                */
-               public void actionPerformed(ActionEvent e) {
-                       action.actionPerformed(e);
-               }
-
-               public boolean isEnabled() {
-                       return (editor == null || editor.isEditable()) ? action.isEnabled()
-                                       : false;
-               }
-
-               TextAction action = null;
-       }
-
-       /**
-        * Registered in the ActionMap.
-        */
-       class FocusAction extends AbstractAction {
-
-               public void actionPerformed(ActionEvent e) {
-                       editor.requestFocus();
-               }
-
-               public boolean isEnabled() {
-                       return editor.isEditable();
-               }
-       }
-
-       boolean handleEnter(int eventType) {
-               return false;
-       }
-
-       String bgcolor0;
-       
-       public void setEditable(boolean editable) {
-               
-               this.editable = editable;
-               if (domNode == null)
-                       return;
-               if (c.isBackgroundSet())
-                       bgcolor0 = JSToolkit.getCSSColor(c.getBackground());
-               if (editable) {
-                       domNode.removeAttribute("readOnly");
-                       if (bgcolor0 != null)
-                               DOMNode.setStyles(domNode, "background-color", bgcolor0);
-               } else {
-                       DOMNode.setAttr(domNode, "readOnly", "true");
-                       if (c.isBackgroundSet()) {
-                               bgcolor0 = JSToolkit.getCSSColor(c.getBackground());
-                       } else {
-                               if (bgcolor0 == null)
-                                       bgcolor0 = domNode.getStyle("background-color");
-                       }
-                       DOMNode.setStyles(domNode, "background-color", "rgba(0,0,0,0)");
-               }
-
-       }
-
-       // private static DragListener getDragListener() {
-       // synchronized(DragListener.class) {
-       // DragListener listener =
-       // (DragListener)AppContext.getAppContext().
-       // get(DragListener.class);
-       //
-       // if (listener == null) {
-       // listener = new DragListener();
-       // AppContext.getAppContext().put(DragListener.class, listener);
-       // }
-       //
-       // return listener;
-       // }
-       // }
-       //
-       // /**
-       // * Listens for mouse events for the purposes of detecting drag gestures.
-       // * BasicTextUI will maintain one of these per AppContext.
-       // */
-       // static class DragListener extends MouseInputAdapter
-       // implements BeforeDrag {
-       //
-       // private boolean dragStarted;
-       //
-       // public void dragStarting(MouseEvent me) {
-       // dragStarted = true;
-       // }
-       //
-       // public void mousePressed(MouseEvent e) {
-       // JTextComponent c = (JTextComponent)e.getSource();
-       // if (c.getDragEnabled()) {
-       // dragStarted = false;
-       // if (isDragPossible(e) && DragRecognitionSupport.mousePressed(e)) {
-       // e.consume();
-       // }
-       // }
-       // }
-       //
-       // public void mouseReleased(MouseEvent e) {
-       // JTextComponent c = (JTextComponent)e.getSource();
-       // if (c.getDragEnabled()) {
-       // if (dragStarted) {
-       // e.consume();
-       // }
-       //
-       // DragRecognitionSupport.mouseReleased(e);
-       // }
-       // }
-       //
-       // public void mouseDragged(MouseEvent e) {
-       // JTextComponent c = (JTextComponent)e.getSource();
-       // if (c.getDragEnabled()) {
-       // if (dragStarted || DragRecognitionSupport.mouseDragged(e, this)) {
-       // e.consume();
-       // }
-       // }
-       // }
-       //
-       // /**
-       // * Determines if the following are true:
-       // * <ul>
-       // * <li>the component is enabled
-       // * <li>the press event is located over a selection
-       // * </ul>
-       // */
-       // protected boolean isDragPossible(MouseEvent e) {
-       // JTextComponent c = (JTextComponent)e.getSource();
-       // if (c.isEnabled()) {
-       // Caret caret = c.getCaret();
-       // int dot = caret.getDot();
-       // int mark = caret.getMark();
-       // if (dot != mark) {
-       // Point p = new Point(e.getX(), e.getY());
-       // int pos = c.viewToModel(p);
-       //
-       // int p0 = Math.min(dot, mark);
-       // int p1 = Math.max(dot, mark);
-       // if ((pos >= p0) && (pos < p1)) {
-       // return true;
-       // }
-       // }
-       // }
-       // return false;
-       // }
-       // }
-
-       // static class TextTransferHandler extends TransferHandler implements
-       // UIResource {
-       //
-       // private JTextComponent exportComp;
-       // private boolean shouldRemove;
-       // private int p0;
-       // private int p1;
-       //
-       // /**
-       // * Whether or not this is a drop using
-       // * <code>DropMode.INSERT</code>.
-       // */
-       // private boolean modeBetween = false;
-       //
-       // /**
-       // * Whether or not this is a drop.
-       // */
-       // private boolean isDrop = false;
-       //
-       // /**
-       // * The drop action.
-       // */
-       // private int dropAction = MOVE;
-       //
-       // /**
-       // * The drop bias.
-       // */
-       // private Position.Bias dropBias;
-       //
-       // /**
-       // * Try to find a flavor that can be used to import a Transferable.
-       // * The set of usable flavors are tried in the following order:
-       // * <ol>
-       // * <li>First, an attempt is made to find a flavor matching the content type
-       // * of the EditorKit for the component.
-       // * <li>Second, an attempt to find a text/plain flavor is made.
-       // * <li>Third, an attempt to find a flavor representing a String reference
-       // * in the same VM is made.
-       // * <li>Lastly, DataFlavor.stringFlavor is searched for.
-       // * </ol>
-       // */
-       // protected DataFlavor getImportFlavor(DataFlavor[] flavors, JTextComponent
-       // c) {
-       // DataFlavor plainFlavor = null;
-       // DataFlavor refFlavor = null;
-       // DataFlavor stringFlavor = null;
-       //
-       // if (c instanceof JEditorPane) {
-       // for (int i = 0; i < flavors.length; i++) {
-       // String mime = flavors[i].getMimeType();
-       // if (mime.startsWith(((JEditorPane)c).getEditorKit().getContentType())) {
-       // return flavors[i];
-       // } else if (plainFlavor == null && mime.startsWith("text/plain")) {
-       // plainFlavor = flavors[i];
-       // } else if (refFlavor == null &&
-       // mime.startsWith("application/x-java-jvm-local-objectref")
-       // && flavors[i].getRepresentationClass() == jsjava.lang.String.class) {
-       // refFlavor = flavors[i];
-       // } else if (stringFlavor == null &&
-       // flavors[i].equals(DataFlavor.stringFlavor)) {
-       // stringFlavor = flavors[i];
-       // }
-       // }
-       // if (plainFlavor != null) {
-       // return plainFlavor;
-       // } else if (refFlavor != null) {
-       // return refFlavor;
-       // } else if (stringFlavor != null) {
-       // return stringFlavor;
-       // }
-       // return null;
-       // }
-       //
-       //
-       // for (int i = 0; i < flavors.length; i++) {
-       // String mime = flavors[i].getMimeType();
-       // if (mime.startsWith("text/plain")) {
-       // return flavors[i];
-       // } else if (refFlavor == null &&
-       // mime.startsWith("application/x-java-jvm-local-objectref")
-       // && flavors[i].getRepresentationClass() == jsjava.lang.String.class) {
-       // refFlavor = flavors[i];
-       // } else if (stringFlavor == null &&
-       // flavors[i].equals(DataFlavor.stringFlavor)) {
-       // stringFlavor = flavors[i];
-       // }
-       // }
-       // if (refFlavor != null) {
-       // return refFlavor;
-       // } else if (stringFlavor != null) {
-       // return stringFlavor;
-       // }
-       // return null;
-       // }
-       //
-       // /**
-       // * Import the given stream data into the text component.
-       // */
-       // protected void handleReaderImport(Reader in, JTextComponent c, boolean
-       // useRead)
-       // throws BadLocationException, IOException {
-       // if (useRead) {
-       // int startPosition = c.getSelectionStart();
-       // int endPosition = c.getSelectionEnd();
-       // int length = endPosition - startPosition;
-       // EditorKit kit = c.getUI().getEditorKit(c);
-       // Document doc = c.getDocument();
-       // if (length > 0) {
-       // doc.remove(startPosition, length);
-       // }
-       // kit.read(in, doc, startPosition);
-       // } else {
-       // char[] buff = new char[1024];
-       // int nch;
-       // boolean lastWasCR = false;
-       // int last;
-       // StringBuffer sbuff = null;
-       //
-       // // Read in a block at a time, mapping \r\n to \n, as well as single
-       // // \r to \n.
-       // while ((nch = in.read(buff, 0, buff.length)) != -1) {
-       // if (sbuff == null) {
-       // sbuff = new StringBuffer(nch);
-       // }
-       // last = 0;
-       // for(int counter = 0; counter < nch; counter++) {
-       // switch(buff[counter]) {
-       // case '\r':
-       // if (lastWasCR) {
-       // if (counter == 0) {
-       // sbuff.append('\n');
-       // } else {
-       // buff[counter - 1] = '\n';
-       // }
-       // } else {
-       // lastWasCR = true;
-       // }
-       // break;
-       // case '\n':
-       // if (lastWasCR) {
-       // if (counter > (last + 1)) {
-       // sbuff.append(buff, last, counter - last - 1);
-       // }
-       // // else nothing to do, can skip \r, next write will
-       // // write \n
-       // lastWasCR = false;
-       // last = counter;
-       // }
-       // break;
-       // default:
-       // if (lastWasCR) {
-       // if (counter == 0) {
-       // sbuff.append('\n');
-       // } else {
-       // buff[counter - 1] = '\n';
-       // }
-       // lastWasCR = false;
-       // }
-       // break;
-       // }
-       // }
-       // if (last < nch) {
-       // if (lastWasCR) {
-       // if (last < (nch - 1)) {
-       // sbuff.append(buff, last, nch - last - 1);
-       // }
-       // } else {
-       // sbuff.append(buff, last, nch - last);
-       // }
-       // }
-       // }
-       // if (lastWasCR) {
-       // sbuff.append('\n');
-       // }
-       // c.replaceSelection(sbuff != null ? sbuff.toString() : "");
-       // }
-       // }
-       //
-       // // --- TransferHandler methods ------------------------------------
-       //
-       // /**
-       // * This is the type of transfer actions supported by the source. Some models
-       // are
-       // * not mutable, so a transfer operation of COPY only should
-       // * be advertised in that case.
-       // *
-       // * @param c The component holding the data to be transfered. This
-       // * argument is provided to enable sharing of TransferHandlers by
-       // * multiple components.
-       // * @return This is implemented to return NONE if the component is a
-       // JPasswordField
-       // * since exporting data via user gestures is not allowed. If the text
-       // component is
-       // * editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.
-       // */
-       // public int getSourceActions(JComponent c) {
-       // if (c instanceof JPasswordField &&
-       // c.getClientProperty("JPasswordField.cutCopyAllowed") !=
-       // Boolean.TRUE) {
-       // return NONE;
-       // }
-       //
-       // return ((JTextComponent)c).isEditable() ? COPY_OR_MOVE : COPY;
-       // }
-       //
-       // /**
-       // * Create a Transferable to use as the source for a data transfer.
-       // *
-       // * @param comp The component holding the data to be transfered. This
-       // * argument is provided to enable sharing of TransferHandlers by
-       // * multiple components.
-       // * @return The representation of the data to be transfered.
-       // *
-       // */
-       // protected Transferable createTransferable(JComponent comp) {
-       // exportComp = (JTextComponent)comp;
-       // shouldRemove = true;
-       // p0 = exportComp.getSelectionStart();
-       // p1 = exportComp.getSelectionEnd();
-       // return (p0 != p1) ? (new TextTransferable(exportComp, p0, p1)) : null;
-       // }
-       //
-       // /**
-       // * This method is called after data has been exported. This method should
-       // remove
-       // * the data that was transfered if the action was MOVE.
-       // *
-       // * @param source The component that was the source of the data.
-       // * @param data The data that was transferred or possibly null
-       // * if the action is <code>NONE</code>.
-       // * @param action The actual action that was performed.
-       // */
-       // protected void exportDone(JComponent source, Transferable data, int action)
-       // {
-       // // only remove the text if shouldRemove has not been set to
-       // // false by importData and only if the action is a move
-       // if (shouldRemove && action == MOVE) {
-       // TextTransferable t = (TextTransferable)data;
-       // t.removeText();
-       // }
-       //
-       // exportComp = null;
-       // }
-       //
-       // public boolean importData(TransferSupport support) {
-       // isDrop = support.isDrop();
-       //
-       // if (isDrop) {
-       // modeBetween =
-       // ((JTextComponent)support.getComponent()).getDropMode() == DropMode.INSERT;
-       //
-       // dropBias =
-       // ((JTextComponent.DropLocation)support.getDropLocation()).getBias();
-       //
-       // dropAction = support.getDropAction();
-       // }
-       //
-       // try {
-       // return super.importData(support);
-       // } finally {
-       // isDrop = false;
-       // modeBetween = false;
-       // dropBias = null;
-       // dropAction = MOVE;
-       // }
-       // }
-       //
-       // /**
-       // * This method causes a transfer to a component from a clipboard or a
-       // * DND drop operation. The Transferable represents the data to be
-       // * imported into the component.
-       // *
-       // * @param comp The component to receive the transfer. This
-       // * argument is provided to enable sharing of TransferHandlers by
-       // * multiple components.
-       // * @param t The data to import
-       // * @return true if the data was inserted into the component, false
-       // otherwise.
-       // */
-       // public boolean importData(JComponent comp, Transferable t) {
-       // JTextComponent c = (JTextComponent)comp;
-       //
-       // int pos = modeBetween
-       // ? ((JTextComponent.DropLocation)c.getDropLocation()).getIndex()
-       // : c.getCaretPosition();
-       //
-       // // if we are importing to the same component that we exported from
-       // // then don't actually do anything if the drop location is inside
-       // // the drag location and set shouldRemove to false so that exportDone
-       // // knows not to remove any data
-       // if (dropAction == MOVE && c == exportComp && pos >= p0 && pos <= p1) {
-       // shouldRemove = false;
-       // return true;
-       // }
-       //
-       // boolean imported = false;
-       // DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
-       // if (importFlavor != null) {
-       // try {
-       // boolean useRead = false;
-       // if (comp instanceof JEditorPane) {
-       // JEditorPane ep = (JEditorPane)comp;
-       // if (!ep.getContentType().startsWith("text/plain") &&
-       // importFlavor.getMimeType().startsWith(ep.getContentType())) {
-       // useRead = true;
-       // }
-       // }
-       // InputContext ic = c.getInputContext();
-       // if (ic != null) {
-       // ic.endComposition();
-       // }
-       // Reader r = importFlavor.getReaderForText(t);
-       //
-       // if (modeBetween) {
-       // Caret caret = c.getCaret();
-       // if (caret instanceof DefaultCaret) {
-       // ((DefaultCaret)caret).setDot(pos, dropBias);
-       // } else {
-       // c.setCaretPosition(pos);
-       // }
-       // }
-       //
-       // handleReaderImport(r, c, useRead);
-       //
-       // if (isDrop) {
-       // c.requestFocus();
-       // Caret caret = c.getCaret();
-       // if (caret instanceof DefaultCaret) {
-       // int newPos = caret.getDot();
-       // Position.Bias newBias = ((DefaultCaret)caret).getDotBias();
-       //
-       // ((DefaultCaret)caret).setDot(pos, dropBias);
-       // ((DefaultCaret)caret).moveDot(newPos, newBias);
-       // } else {
-       // c.select(pos, c.getCaretPosition());
-       // }
-       // }
-       //
-       // imported = true;
-       // } catch (UnsupportedFlavorException ufe) {
-       // } catch (BadLocationException ble) {
-       // } catch (IOException ioe) {
-       // }
-       // }
-       // return imported;
-       // }
-       //
-       // /**
-       // * This method indicates if a component would accept an import of the given
-       // * set of data flavors prior to actually attempting to import it.
-       // *
-       // * @param comp The component to receive the transfer. This
-       // * argument is provided to enable sharing of TransferHandlers by
-       // * multiple components.
-       // * @param flavors The data formats available
-       // * @return true if the data can be inserted into the component, false
-       // otherwise.
-       // */
-       // public boolean canImport(JComponent comp, DataFlavor[] flavors) {
-       // JTextComponent c = (JTextComponent)comp;
-       // if (!(c.isEditable() && c.isEnabled())) {
-       // return false;
-       // }
-       // return (getImportFlavor(flavors, c) != null);
-       // }
-       //
-       // /**
-       // * A possible implementation of the Transferable interface
-       // * for text components. For a JEditorPane with a rich set
-       // * of EditorKit implementations, conversions could be made
-       // * giving a wider set of formats. This is implemented to
-       // * offer up only the active content type and text/plain
-       // * (if that is not the active format) since that can be
-       // * extracted from other formats.
-       // */
-       // static class TextTransferable extends BasicTransferable {
-       //
-       // TextTransferable(JTextComponent c, int start, int end) {
-       // super(null, null);
-       //
-       // this.c = c;
-       //
-       // Document doc = c.getDocument();
-       //
-       // try {
-       // p0 = doc.createPosition(start);
-       // p1 = doc.createPosition(end);
-       //
-       // plainData = c.getSelectedText();
-       //
-       // if (c instanceof JEditorPane) {
-       // JEditorPane ep = (JEditorPane)c;
-       //
-       // mimeType = ep.getContentType();
-       //
-       // if (mimeType.startsWith("text/plain")) {
-       // return;
-       // }
-       //
-       // StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
-       // ep.getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() -
-       // p0.getOffset());
-       //
-       // if (mimeType.startsWith("text/html")) {
-       // htmlData = sw.toString();
-       // } else {
-       // richText = sw.toString();
-       // }
-       // }
-       // } catch (BadLocationException ble) {
-       // } catch (IOException ioe) {
-       // }
-       // }
-       //
-       // void removeText() {
-       // if ((p0 != null) && (p1 != null) && (p0.getOffset() != p1.getOffset())) {
-       // try {
-       // Document doc = c.getDocument();
-       // doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());
-       // } catch (BadLocationException e) {
-       // }
-       // }
-       // }
-       //
-       // // ---- EditorKit other than plain or HTML text -----------------------
-       //
-       // /**
-       // * If the EditorKit is not for text/plain or text/html, that format
-       // * is supported through the "richer flavors" part of BasicTransferable.
-       // */
-       // protected DataFlavor[] getRicherFlavors() {
-       // if (richText == null) {
-       // return null;
-       // }
-       //
-       // try {
-       // DataFlavor[] flavors = new DataFlavor[3];
-       // flavors[0] = new DataFlavor(mimeType + ";class=java.lang.String");
-       // flavors[1] = new DataFlavor(mimeType + ";class=java.io.Reader");
-       // flavors[2] = new DataFlavor(mimeType +
-       // ";class=java.io.InputStream;charset=unicode");
-       // return flavors;
-       // } catch (ClassNotFoundException cle) {
-       // // fall through to unsupported (should not happen)
-       // }
-       //
-       // return null;
-       // }
-       //
-       // /**
-       // * The only richer format supported is the file list flavor
-       // */
-       // protected Object getRicherData(DataFlavor flavor) throws
-       // UnsupportedFlavorException {
-       // if (richText == null) {
-       // return null;
-       // }
-       //
-       // if (String.class.equals(flavor.getRepresentationClass())) {
-       // return richText;
-       // } else if (Reader.class.equals(flavor.getRepresentationClass())) {
-       // return new StringReader(richText);
-       // } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
-       // return new StringBufferInputStream(richText);
-       // }
-       // throw new UnsupportedFlavorException(flavor);
-       // }
-       //
-       // Position p0;
-       // Position p1;
-       // String mimeType;
-       // String richText;
-       // JTextComponent c;
-       // }
-       //
-       // }
-
-       // /**
-       // * Creates a new UI.
-       // */
-       // public JSTextUI() {
-       // // painted = false;
-       // }
-       //
-       // /**
-       // * Creates the object to use for a caret. By default an
-       // * instance of BasicCaret is created. This method
-       // * can be redefined to provide something else that implements
-       // * the InputPosition interface or a subclass of JCaret.
-       // *
-       // * @return the caret object
-       // */
-       // protected Caret createCaret() {
-       // return new BasicCaret();
-       // }
-       //
-       // /**
-       // * Creates the object to use for adding highlights. By default
-       // * an instance of BasicHighlighter is created. This method
-       // * can be redefined to provide something else that implements
-       // * the Highlighter interface or a subclass of DefaultHighlighter.
-       // *
-       // * @return the highlighter
-       // */
-       // protected Highlighter createHighlighter() {
-       // return new BasicHighlighter();
-       // }
-       //
-       // /**
-       // * Fetches the name of the keymap that will be installed/used
-       // * by default for this UI. This is implemented to create a
-       // * name based upon the classname. The name is the the name
-       // * of the class with the package prefix removed.
-       // *
-       // * @return the name
-       // */
-       // protected String getKeymapName() {
-       // String nm = getClass().getName();
-       // int index = nm.lastIndexOf('.');
-       // if (index >= 0) {
-       // nm = nm.substring(index+1, nm.length());
-       // }
-       // return nm;
-       // }
-       //
-       // /**
-       // * Creates the keymap to use for the text component, and installs
-       // * any necessary bindings into it. By default, the keymap is
-       // * shared between all instances of this type of TextUI. The
-       // * keymap has the name defined by the getKeymapName method. If the
-       // * keymap is not found, then DEFAULT_KEYMAP from JTextComponent is used.
-       // * <p>
-       // * The set of bindings used to create the keymap is fetched
-       // * from the UIManager using a key formed by combining the
-       // * {@link #getPropertyPrefix} method
-       // * and the string <code>.keyBindings</code>. The type is expected
-       // * to be <code>JTextComponent.KeyBinding[]</code>.
-       // *
-       // * @return the keymap
-       // * @see #getKeymapName
-       // * @see jsjavax.swing.text.JTextComponent
-       // */
-       // protected Keymap createKeymap() {
-       // String nm = getKeymapName();
-       // Keymap map = JTextComponent.getKeymap(nm);
-       // if (map == null) {
-       // Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
-       // map = JTextComponent.addKeymap(nm, parent);
-       // String prefix = getPropertyPrefix();
-       // Object o = DefaultLookup.get(editor, this,
-       // prefix + ".keyBindings");
-       // if ((o != null) && (o instanceof JTextComponent.KeyBinding[])) {
-       // JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) o;
-       // JTextComponent.loadKeymap(map, bindings, getComponent().getActions());
-       // }
-       // }
-       // return map;
-       // }
-       //
-       // /**
-       // * This method gets called when a bound property is changed
-       // * on the associated JTextComponent. This is a hook
-       // * which UI implementations may change to reflect how the
-       // * UI displays bound properties of JTextComponent subclasses.
-       // * This is implemented to do nothing (i.e. the response to
-       // * properties in JTextComponent itself are handled prior
-       // * to calling this method).
-       // *
-       // * This implementation updates the background of the text
-       // * component if the editable and/or enabled state changes.
-       // *
-       // * @param evt the property change event
-       // */
-       // protected void propertyChange(PropertyChangeEvent evt) {
-       // if (evt.getPropertyName().equals("editable") ||
-       // evt.getPropertyName().equals("enabled")) {
-       //
-       // updateBackground((JTextComponent)evt.getSource());
-       // }
-       // }
-       //
-       // /**
-       // * Updates the background of the text component based on whether the
-       // * text component is editable and/or enabled.
-       // *
-       // * @param c the JTextComponent that needs its background color updated
-       // */
-       // private void updateBackground(JTextComponent c) {
-       // // This is a temporary workaround.
-       // // This code does not correctly deal with Synth (Synth doesn't use
-       // // properties like this), nor does it deal with the situation where
-       // // the developer grabs the color from a JLabel and sets it as
-       // // the background for a JTextArea in all look and feels. The problem
-       // // scenario results if the Color obtained for the Label and TextArea
-       // // is ==, which is the case for the windows look and feel.
-       // // Until an appropriate solution is found, the code is being
-       // // reverted to what it was before the original fix.
-       // if (this instanceof sun.swing.plaf.synth.SynthUI ||
-       // (c instanceof JTextArea)) {
-       // return;
-       // }
-       // Color background = c.getBackground();
-       // if (background instanceof UIResource) {
-       // String prefix = getPropertyPrefix();
-       //
-       // Color disabledBG =
-       // DefaultLookup.getColor(c, this, prefix + ".disabledBackground", null);
-       // Color inactiveBG =
-       // DefaultLookup.getColor(c, this, prefix + ".inactiveBackground", null);
-       // Color bg =
-       // DefaultLookup.getColor(c, this, prefix + ".background", null);
-       //
-       // /* In an ideal situation, the following check would not be necessary
-       // * and we would replace the color any time the previous color was a
-       // * UIResouce. However, it turns out that there is existing code that
-       // * uses the following inadvisable pattern to turn a text area into
-       // * what appears to be a multi-line label:
-       // *
-       // * JLabel label = new JLabel();
-       // * JTextArea area = new JTextArea();
-       // * area.setBackground(label.getBackground());
-       // * area.setEditable(false);
-       // *
-       // * JLabel's default background is a UIResource. As such, just
-       // * checking for UIResource would have us always changing the
-       // * background away from what the developer wanted.
-       // *
-       // * Therefore, for JTextArea/JEditorPane, we'll additionally check
-       // * that the color we're about to replace matches one that was
-       // * installed by us from the UIDefaults.
-       // */
-       // if ((c instanceof JTextArea || c instanceof JEditorPane)
-       // && background != disabledBG
-       // && background != inactiveBG
-       // && background != bg) {
-       //
-       // return;
-       // }
-       //
-       // Color newColor = null;
-       // if (!c.isEnabled()) {
-       // newColor = disabledBG;
-       // }
-       // if (newColor == null && !c.isEditable()) {
-       // newColor = inactiveBG;
-       // }
-       // if (newColor == null) {
-       // newColor = bg;
-       // }
-       // if (newColor != null && newColor != background) {
-       // c.setBackground(newColor);
-       // }
-       // }
-       // }
-       //
-       // /**
-       // * Gets the name used as a key to look up properties through the
-       // * UIManager. This is used as a prefix to all the standard
-       // * text properties.
-       // *
-       // * @return the name
-       // */
-       // protected abstract String getPropertyPrefix();
-
-}
+/*\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
+package swingjs.plaf;\r
+\r
+import swingjs.JSToolkit;\r
+import swingjs.api.DOMNode;\r
+import swingjs.api.JQueryObject;\r
+import swingjs.api.JSFunction;\r
+import jsjava.awt.Dimension;\r
+import jsjava.awt.Insets;\r
+import jsjava.awt.LayoutManager;\r
+import jsjava.awt.event.ActionEvent;\r
+import jsjavax.swing.AbstractAction;\r
+import jsjavax.swing.Action;\r
+import jsjavax.swing.ActionMap;\r
+import jsjavax.swing.InputMap;\r
+import jsjavax.swing.JComponent;\r
+import jsjavax.swing.SwingUtilities;\r
+import jsjavax.swing.UIManager;\r
+import jsjavax.swing.plaf.ActionMapUIResource;\r
+import jsjavax.swing.plaf.ComponentUI;\r
+import jsjavax.swing.plaf.InputMapUIResource;\r
+import jsjavax.swing.plaf.TextUI;\r
+import jsjavax.swing.plaf.UIResource;\r
+import jsjavax.swing.text.Caret;\r
+import jsjavax.swing.text.DefaultEditorKit;\r
+import jsjavax.swing.text.EditorKit;\r
+import jsjavax.swing.text.JTextComponent;\r
+import jsjavax.swing.text.TextAction;\r
+//import jsjava.awt.KeyboardFocusManager;\r
+//import jsjava.awt.datatransfer.DataFlavor;\r
+//import jsjava.awt.datatransfer.Transferable;\r
+//import jsjava.awt.datatransfer.UnsupportedFlavorException;\r
+//import jsjava.awt.im.InputContext;\r
+//import jsjava.io.IOException;\r
+//import jsjava.io.InputStream;\r
+//import jsjava.io.Reader;\r
+//import jsjava.io.StringBufferInputStream;\r
+//import jsjava.io.StringReader;\r
+//import jsjava.io.StringWriter;\r
+//import jsjavax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;\r
+\r
+/**\r
+ * <p>\r
+ * Basis of a text components look-and-feel. This provides the basic editor view\r
+ * and controller services that may be useful when creating a look-and-feel for\r
+ * an extension of <code>JTextComponent</code>.\r
+ * <p>\r
+ * Most state is held in the associated <code>JTextComponent</code> as bound\r
+ * properties, and the UI installs default values for the various properties.\r
+ * This default will install something for all of the properties. Typically, a\r
+ * LAF implementation will do more however. At a minimum, a LAF would generally\r
+ * install key bindings.\r
+ * <p>\r
+ * This class also provides some concurrency support if the\r
+ * <code>Document</code> associated with the JTextComponent is a subclass of\r
+ * <code>AbstractDocument</code>. Access to the View (or View hierarchy) is\r
+ * serialized between any thread mutating the model and the Swing event thread\r
+ * (which is expected to render, do model/view coordinate translation, etc).\r
+ * <em>Any access to the root view should first\r
+ * acquire a read-lock on the AbstractDocument and release that lock\r
+ * in a finally block.</em>\r
+ * <p>\r
+ * An important method to define is the {@link #getPropertyPrefix} method which\r
+ * is used as the basis of the keys used to fetch defaults from the UIManager.\r
+ * The string should reflect the type of TextUI (eg. TextField, TextArea, etc)\r
+ * without the particular LAF part of the name (eg Metal, Motif, etc).\r
+ * <p>\r
+ * To build a view of the model, one of the following strategies can be\r
+ * employed.\r
+ * <ol>\r
+ * <li>\r
+ * One strategy is to simply redefine the ViewFactory interface in the UI. By\r
+ * default, this UI itself acts as the factory for View implementations. This is\r
+ * useful for simple factories. To do this reimplement the {@link #create}\r
+ * method.\r
+ * <li>\r
+ * A common strategy for creating more complex types of documents is to have the\r
+ * EditorKit implementation return a factory. Since the EditorKit ties all of\r
+ * the pieces necessary to maintain a type of document, the factory is typically\r
+ * an important part of that and should be produced by the EditorKit\r
+ * implementation.\r
+ * </ol>\r
+ * <p>\r
+ * <strong>Warning:</strong> Serialized objects of this class will not be\r
+ * compatible with future Swing releases. The current serialization support is\r
+ * appropriate for short term storage or RMI between applications running the\r
+ * same version of Swing. As of 1.4, support for long term storage of all\r
+ * JavaBeans<sup><font size="-2">TM</font></sup> has been added to the\r
+ * <code>java.beans</code> package. Please see {@link jsjava.beans.XMLEncoder}.\r
+ * \r
+ * @author Timothy Prinzing\r
+ * @author Shannon Hickey (drag and drop)\r
+ */\r
+public abstract class JSTextUI extends JSComponentUI {// implements {ViewFactory\r
+                                                                                                                                                                                                                       // {\r
+       @SuppressWarnings("unused")\r
+       protected void setFocusable() {\r
+               JQueryObject node = $(focusNode);\r
+               Object me = this;\r
+\r
+               /**\r
+                * @j2sNative\r
+                * \r
+                * node.focus(function() {me.notifyFocus(true)});\r
+                * node.blur(function() {me.notifyFocus(false)});\r
+                */\r
+               {}\r
+       }\r
+       \r
+\r
+       protected String getComponentText() {\r
+               return currentText = ((JTextComponent) c).getText();\r
+       }\r
+\r
+       protected void bindKeys(DOMNode domNode) {\r
+               JSFunction f = null;\r
+               JSEventHandler me = this;\r
+               if (!((JTextComponent) c).isEditable())\r
+                       return;\r
+               /**\r
+                * @j2sNative\r
+                * \r
+                *            f = function(event) { me.handleJSEvent(me.domNode, 401, event)\r
+                *            }\r
+                */\r
+               {\r
+                       System.out.println(me);\r
+               }\r
+               $(domNode).bind("keydown keypress keyup", f);\r
+\r
+               // TODO Auto-generated method stub\r
+\r
+       }\r
+\r
+       /**\r
+        * Initializes component properties, e.g. font, foreground, background, caret\r
+        * color, selection color, selected text color, disabled text color, and\r
+        * border color. The font, foreground, and background properties are only set\r
+        * if their current value is either null or a UIResource, other properties are\r
+        * set if the current value is null.\r
+        * \r
+        * @see #uninstallDefaults\r
+        * @see #installUI\r
+        */\r
+       protected void installDefaults() {\r
+               // String prefix = getPropertyPrefix();\r
+               // Font f = editor.getFont();\r
+               // if ((f == null) || (f instanceof UIResource)) {\r
+               // editor.setFont(UIManager.getFont(prefix + ".font"));\r
+               // }\r
+               //\r
+               // Color bg = editor.getBackground();\r
+               // if ((bg == null) || (bg instanceof UIResource)) {\r
+               // editor.setBackground(UIManager.getColor(prefix + ".background"));\r
+               // }\r
+               //\r
+               // Color fg = editor.getForeground();\r
+               // if ((fg == null) || (fg instanceof UIResource)) {\r
+               // editor.setForeground(UIManager.getColor(prefix + ".foreground"));\r
+               // }\r
+               //\r
+               // Color color = editor.getCaretColor();\r
+               // if ((color == null) || (color instanceof UIResource)) {\r
+               // editor.setCaretColor(UIManager.getColor(prefix + ".caretForeground"));\r
+               // }\r
+               //\r
+               // Color s = editor.getSelectionColor();\r
+               // if ((s == null) || (s instanceof UIResource)) {\r
+               // editor.setSelectionColor(UIManager.getColor(prefix +\r
+               // ".selectionBackground"));\r
+               // }\r
+               //\r
+               // Color sfg = editor.getSelectedTextColor();\r
+               // if ((sfg == null) || (sfg instanceof UIResource)) {\r
+               // editor.setSelectedTextColor(UIManager.getColor(prefix +\r
+               // ".selectionForeground"));\r
+               // }\r
+               //\r
+               // Color dfg = editor.getDisabledTextColor();\r
+               // if ((dfg == null) || (dfg instanceof UIResource)) {\r
+               // editor.setDisabledTextColor(UIManager.getColor(prefix +\r
+               // ".inactiveForeground"));\r
+               // }\r
+               //\r
+               // Border b = editor.getBorder();\r
+               // if ((b == null) || (b instanceof UIResource)) {\r
+               // editor.setBorder(UIManager.getBorder(prefix + ".border"));\r
+               // }\r
+               //\r
+               // Insets margin = editor.getMargin();\r
+               // if (margin == null || margin instanceof UIResource) {\r
+               // editor.setMargin(UIManager.getInsets(prefix + ".margin"));\r
+               // }\r
+               //\r
+               // updateCursor();\r
+       }\r
+\r
+       private void installDefaults2() {\r
+               // editor.addMouseListener(dragListener);\r
+               // editor.addMouseMotionListener(dragListener);\r
+               //\r
+               // String prefix = getPropertyPrefix();\r
+\r
+               Caret caret = editor.getCaret();\r
+               if (caret == null || caret instanceof UIResource) {\r
+                       editor.setCaret(new JSCaret());\r
+               }\r
+               //\r
+               // Highlighter highlighter = editor.getHighlighter();\r
+               // if (highlighter == null || highlighter instanceof UIResource) {\r
+               // editor.setHighlighter(createHighlighter());\r
+               // }\r
+               //\r
+               // TransferHandler th = editor.getTransferHandler();\r
+               // if (th == null || th instanceof UIResource) {\r
+               // editor.setTransferHandler(getTransferHandler());\r
+               // }\r
+       }\r
+\r
+       /**\r
+        * called by JmolCore.js\r
+        * \r
+        * @return handled\r
+        */\r
+       public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {\r
+               System.out.println("Handling for " + id + " " + eventType + " "\r
+                               + jQueryEvent);\r
+               return updateHandler.handleJSEvent(this, eventType, jQueryEvent);\r
+       }\r
+\r
+       /**\r
+        * Sets the component properties that haven't been explicitly overridden to\r
+        * null. A property is considered overridden if its current value is not a\r
+        * UIResource.\r
+        * \r
+        * @see #installDefaults\r
+        * @see #uninstallUI\r
+        */\r
+       protected void uninstallDefaults() {\r
+               // editor.removeMouseListener(dragListener);\r
+               // editor.removeMouseMotionListener(dragListener);\r
+               //\r
+               if (editor.getCaretColor() instanceof UIResource) {\r
+                       editor.setCaretColor(null);\r
+               }\r
+\r
+               if (editor.getSelectionColor() instanceof UIResource) {\r
+                       editor.setSelectionColor(null);\r
+               }\r
+\r
+               if (editor.getDisabledTextColor() instanceof UIResource) {\r
+                       editor.setDisabledTextColor(null);\r
+               }\r
+\r
+               if (editor.getSelectedTextColor() instanceof UIResource) {\r
+                       editor.setSelectedTextColor(null);\r
+               }\r
+\r
+               if (editor.getBorder() instanceof UIResource) {\r
+                       editor.setBorder(null);\r
+               }\r
+\r
+               if (editor.getMargin() instanceof UIResource) {\r
+                       editor.setMargin(null);\r
+               }\r
+\r
+               // if (editor.getCaret() instanceof UIResource) {\r
+               // editor.setCaret(null);\r
+               // }\r
+               //\r
+               // if (editor.getHighlighter() instanceof UIResource) {\r
+               // editor.setHighlighter(null);\r
+               // }\r
+               //\r
+               // if (editor.getTransferHandler() instanceof UIResource) {\r
+               // editor.setTransferHandler(null);\r
+               // }\r
+               //\r
+               // if (editor.getCursor() instanceof UIResource) {\r
+               // editor.setCursor(null);\r
+               // }\r
+       }\r
+\r
+       protected void installKeyboardActions() {\r
+               // backward compatibility support... keymaps for the UI\r
+               // are now installed in the more friendly input map.\r
+               // editor.setKeymap(createKeymap());\r
+\r
+               InputMap km = getInputMap();\r
+               if (km != null) {\r
+                       SwingUtilities.replaceUIInputMap(editor, JComponent.WHEN_FOCUSED, km);\r
+               }\r
+\r
+               ActionMap map = getActionMap();\r
+               if (map != null) {\r
+                       SwingUtilities.replaceUIActionMap(editor, map);\r
+               }\r
+\r
+               // updateFocusAcceleratorBinding(false);\r
+       }\r
+\r
+       /**\r
+        * Get the InputMap to use for the UI.\r
+        */\r
+       InputMap getInputMap() {\r
+               InputMap map = new InputMapUIResource();\r
+\r
+               // InputMap shared =\r
+               // (InputMap)DefaultLookup.get(editor, this,\r
+               // getPropertyPrefix() + ".focusInputMap");\r
+               // if (shared != null) {\r
+               // map.setParent(shared);\r
+               // }\r
+               return map;\r
+       }\r
+\r
+       // /**\r
+       // * Invoked when the focus accelerator changes, this will update the\r
+       // * key bindings as necessary.\r
+       // */\r
+       // void updateFocusAcceleratorBinding(boolean changed) {\r
+       // char accelerator = editor.getFocusAccelerator();\r
+       //\r
+       // if (changed || accelerator != '\0') {\r
+       // InputMap km = SwingUtilities.getUIInputMap\r
+       // (editor, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+       //\r
+       // if (km == null && accelerator != '\0') {\r
+       // km = new ComponentInputMapUIResource(editor);\r
+       // SwingUtilities.replaceUIInputMap(editor, JComponent.\r
+       // WHEN_IN_FOCUSED_WINDOW, km);\r
+       // ActionMap am = getActionMap();\r
+       // SwingUtilities.replaceUIActionMap(editor, am);\r
+       // }\r
+       // if (km != null) {\r
+       // km.clear();\r
+       // if (accelerator != '\0') {\r
+       // km.put(KeyStroke.getKeyStroke(accelerator,\r
+       // ActionEvent.ALT_MASK),\r
+       // "requestFocus");\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       //\r
+       // /**\r
+       // * Invoked when editable property is changed.\r
+       // *\r
+       // * removing 'TAB' and 'SHIFT-TAB' from traversalKeysSet in case\r
+       // * editor is editable\r
+       // * adding 'TAB' and 'SHIFT-TAB' to traversalKeysSet in case\r
+       // * editor is non editable\r
+       // */\r
+       //\r
+       // void updateFocusTraversalKeys() {\r
+       // /*\r
+       // * Fix for 4514331 Non-editable JTextArea and similar\r
+       // * should allow Tab to keyboard - accessibility\r
+       // */\r
+       // EditorKit editorKit = getEditorKit(editor);\r
+       // if ( editorKit != null\r
+       // && editorKit instanceof DefaultEditorKit) {\r
+       // Set storedForwardTraversalKeys = editor.\r
+       // getFocusTraversalKeys(KeyboardFocusManager.\r
+       // FORWARD_TRAVERSAL_KEYS);\r
+       // Set storedBackwardTraversalKeys = editor.\r
+       // getFocusTraversalKeys(KeyboardFocusManager.\r
+       // BACKWARD_TRAVERSAL_KEYS);\r
+       // Set forwardTraversalKeys =\r
+       // new HashSet(storedForwardTraversalKeys);\r
+       // Set backwardTraversalKeys =\r
+       // new HashSet(storedBackwardTraversalKeys);\r
+       // if (editor.isEditable()) {\r
+       // forwardTraversalKeys.\r
+       // remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));\r
+       // backwardTraversalKeys.\r
+       // remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,\r
+       // InputEvent.SHIFT_MASK));\r
+       // } else {\r
+       // forwardTraversalKeys.add(KeyStroke.\r
+       // getKeyStroke(KeyEvent.VK_TAB, 0));\r
+       // backwardTraversalKeys.\r
+       // add(KeyStroke.\r
+       // getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));\r
+       // }\r
+       // LookAndFeel.installProperty(editor,\r
+       // "focusTraversalKeysForward",\r
+       // forwardTraversalKeys);\r
+       // LookAndFeel.installProperty(editor,\r
+       // "focusTraversalKeysBackward",\r
+       // backwardTraversalKeys);\r
+       // }\r
+       //\r
+       // }\r
+\r
+       // /**\r
+       // * As needed updates cursor for the target editor.\r
+       // */\r
+       // private void updateCursor() {\r
+       // if ((! editor.isCursorSet())\r
+       // || editor.getCursor() instanceof UIResource) {\r
+       // Cursor cursor = (editor.isEditable()) ? textCursor : null;\r
+       // editor.setCursor(cursor);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the <code>TransferHandler</code> that will be installed if\r
+       // * their isn't one installed on the <code>JTextComponent</code>.\r
+       // */\r
+       // TransferHandler getTransferHandler() {\r
+       // return defaultTransferHandler;\r
+       // }\r
+       //\r
+       /**\r
+        * Fetch an action map to use.\r
+        */\r
+       ActionMap getActionMap() {\r
+               String mapName = classID + ".actionMap";\r
+               ActionMap map = (ActionMap) UIManager.get(mapName);\r
+               if (map == null) {\r
+                       map = createActionMap();\r
+                       if (map != null) {\r
+                               UIManager.getLookAndFeelDefaults().put(mapName, map); \r
+                       }\r
+               }\r
+               return map;\r
+       }\r
+       // ActionMap componentMap = new ActionMapUIResource();\r
+       // componentMap.put("requestFocus", new FocusAction());\r
+       // /*\r
+       // * fix for bug 4515750\r
+       // * JTextField & non-editable JTextArea bind return key - default btn not\r
+       // accessible\r
+       // *\r
+       // * Wrap the return action so that it is only enabled when the\r
+       // * component is editable. This allows the default button to be\r
+       // * processed when the text component has focus and isn't editable.\r
+       // *\r
+       // */\r
+       // if (getEditorKit(editor) instanceof DefaultEditorKit) {\r
+       // if (map != null) {\r
+       // Object obj = map.get(DefaultEditorKit.insertBreakAction);\r
+       // if (obj != null\r
+       // && obj instanceof DefaultEditorKit.InsertBreakAction) {\r
+       // Action action = new TextActionWrapper((TextAction)obj);\r
+       // componentMap.put(action.getValue(Action.NAME),action);\r
+       // }\r
+       // }\r
+       // }\r
+       // if (map != null) {\r
+       // componentMap.setParent(map);\r
+       // }\r
+       // return componentMap;\r
+       // }\r
+       //\r
+       /**\r
+        * Create a default action map. This is basically the set of actions found\r
+        * exported by the component.\r
+        */\r
+       /**\r
+        * @return\r
+        */\r
+       ActionMap createActionMap() {\r
+               ActionMap map = new ActionMapUIResource();\r
+               Action[] actions = editor.getActions();//defaultKit.getActions(); // SwingJS was editor.getEditorKit().getActions()\r
+               // System.out.println("building map for UI: " + getPropertyPrefix());\r
+               int n = actions.length;\r
+               for (int i = 0; i < n; i++) {\r
+                       Action a = actions[i];\r
+                       map.put(a.getValue(Action.NAME), a);\r
+                       // System.out.println("  " + a.getValue(Action.NAME));\r
+               }\r
+               // map.put(TransferHandler.getCutAction().getValue(Action.NAME),\r
+               // TransferHandler.getCutAction());\r
+               // map.put(TransferHandler.getCopyAction().getValue(Action.NAME),\r
+               // TransferHandler.getCopyAction());\r
+               // map.put(TransferHandler.getPasteAction().getValue(Action.NAME),\r
+               // TransferHandler.getPasteAction());\r
+               return map;\r
+       }\r
+\r
+       protected void uninstallKeyboardActions() {\r
+               editor.setKeymap(null);\r
+               SwingUtilities.replaceUIInputMap(editor, JComponent.WHEN_IN_FOCUSED_WINDOW,\r
+                               null);\r
+               SwingUtilities.replaceUIActionMap(editor, null);\r
+       }\r
+\r
+       // /**\r
+       // * Paints a background for the view. This will only be\r
+       // * called if isOpaque() on the associated component is\r
+       // * true. The default is to paint the background color\r
+       // * of the component.\r
+       // *\r
+       // * @param g the graphics context\r
+       // */\r
+       // protected void paintBackground(Graphics g) {\r
+       // g.setColor(editor.getBackground());\r
+       // g.fillRect(0, 0, editor.getWidth(), editor.getHeight());\r
+       // }\r
+       //\r
+       /**\r
+        * Fetches the text component associated with this UI implementation. This\r
+        * will be null until the ui has been installed.\r
+        * \r
+        * @return the editor component\r
+        */\r
+       protected final JTextComponent getComponent() {\r
+               return editor;\r
+       }\r
+\r
+       // /**\r
+       // * Flags model changes.\r
+       // * This is called whenever the model has changed.\r
+       // * It is implemented to rebuild the view hierarchy\r
+       // * to represent the default root element of the\r
+       // * associated model.\r
+       // */\r
+       // protected void modelChanged() {\r
+       // // create a view hierarchy\r
+       // ViewFactory f = rootView.getViewFactory();\r
+       // Document doc = editor.getDocument();\r
+       // Element elem = doc.getDefaultRootElement();\r
+       // setView(f.create(elem));\r
+       // }\r
+       //\r
+       // /**\r
+       // * Sets the current root of the view hierarchy and calls invalidate().\r
+       // * If there were any child components, they will be removed (i.e.\r
+       // * there are assumed to have come from components embedded in views).\r
+       // *\r
+       // * @param v the root view\r
+       // */\r
+       // protected final void setView(View v) {\r
+       // rootView.setView(v);\r
+       // painted = false;\r
+       // editor.revalidate();\r
+       // editor.repaint();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Paints the interface safely with a guarantee that\r
+       // * the model won't change from the view of this thread.\r
+       // * This does the following things, rendering from\r
+       // * back to front.\r
+       // * <ol>\r
+       // * <li>\r
+       // * If the component is marked as opaque, the background\r
+       // * is painted in the current background color of the\r
+       // * component.\r
+       // * <li>\r
+       // * The highlights (if any) are painted.\r
+       // * <li>\r
+       // * The view hierarchy is painted.\r
+       // * <li>\r
+       // * The caret is painted.\r
+       // * </ol>\r
+       // *\r
+       // * @param g the graphics context\r
+       // */\r
+       // protected void paintSafely(Graphics g) {\r
+       // painted = true;\r
+       // Highlighter highlighter = editor.getHighlighter();\r
+       // Caret caret = editor.getCaret();\r
+       //\r
+       // // paint the background\r
+       // if (editor.isOpaque()) {\r
+       // paintBackground(g);\r
+       // }\r
+       //\r
+       // // paint the highlights\r
+       // if (highlighter != null) {\r
+       // highlighter.paint(g);\r
+       // }\r
+       //\r
+       // // paint the view hierarchy\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // rootView.paint(g, alloc);\r
+       // }\r
+       //\r
+       // // paint the caret\r
+       // if (caret != null) {\r
+       // caret.paint(g);\r
+       // }\r
+       //\r
+       // if (dropCaret != null) {\r
+       // dropCaret.paint(g);\r
+       // }\r
+       // }\r
+\r
+       // --- ComponentUI methods --------------------------------------------\r
+\r
+       TextListener updateHandler;\r
+\r
+       /**\r
+        * Installs the UI for a component. This does the following things.\r
+        * <ol>\r
+        * <li>\r
+        * Set the associated component to opaque (can be changed easily by a subclass\r
+        * or on JTextComponent directly), which is the most common case. This will\r
+        * cause the component's background color to be painted.\r
+        * <li>\r
+        * Install the default caret and highlighter into the associated component.\r
+        * <li>\r
+        * Attach to the editor and model. If there is no model, a default one is\r
+        * created.\r
+        * <li>\r
+        * create the view factory and the view hierarchy used to represent the model.\r
+        * </ol>\r
+        * \r
+        * @param c\r
+        *          the editor component\r
+        * @see ComponentUI#installUI\r
+        */\r
+       protected void installJSUI() {\r
+               editor = (JTextComponent) c;\r
+               updateHandler = new TextListener(this, editor);\r
+\r
+               // install defaults\r
+               installDefaults();\r
+               installDefaults2();\r
+\r
+               // // This is a workaround as these should not override what synth has\r
+               // // set them to\r
+               // if (!(this instanceof sun.swing.plaf.synth.SynthUI)){\r
+               // // common case is background painted... this can\r
+               // // easily be changed by subclasses or from outside\r
+               // // of the component.\r
+               // LookAndFeel.installProperty(editor, "opaque", Boolean.TRUE);\r
+               // LookAndFeel.installProperty(editor, "autoscrolls", Boolean.TRUE);\r
+               // }\r
+               //\r
+               // attach to the model and editor\r
+               // Document doc = editor.getDocument();\r
+               // if (doc == null) {\r
+               // // no model, create a default one. This will\r
+               // // fire a notification to the updateHandler\r
+               // // which takes care of the rest.\r
+               // editor.setDocument(getEditorKit(editor).createDefaultDocument());\r
+               // } else {\r
+               // // doc.addDocumentListener(updateHandler);\r
+               // // modelChanged();\r
+               // }\r
+\r
+               // install keymap\r
+               installListeners(editor);\r
+               installKeyboardActions();\r
+\r
+               // LayoutManager oldLayout = editor.getLayout();\r
+               // if ((oldLayout == null) || (oldLayout instanceof UIResource)) {\r
+               // // by default, use default LayoutManger implementation that\r
+               // // will position the components associated with a View object.\r
+               // editor.setLayout(updateHandler);\r
+               // }\r
+               //\r
+               // updateBackground(editor);\r
+       }\r
+\r
+       /**\r
+        * Deinstalls the UI for a component. This removes the listeners, uninstalls\r
+        * the highlighter, removes views, and nulls out the keymap.\r
+        * \r
+        * @param c\r
+        *          the editor component\r
+        * @see ComponentUI#uninstallUI\r
+        */\r
+       public void uninstallJSUI() {\r
+               // detach from the model\r
+               // editor.removePropertyChangeListener(updateHandler);\r
+               // editor.getDocument().removeDocumentListener(updateHandler);\r
+\r
+               // view part\r
+               // painted = false;\r
+               uninstallDefaults();\r
+               // rootView.setView(null);\r
+               c.removeAll();\r
+               LayoutManager lm = c.getLayout();\r
+               if (lm instanceof UIResource) {\r
+                       c.setLayout(null);\r
+               }\r
+\r
+               // controller part\r
+               uninstallKeyboardActions();\r
+               uninstallListeners(editor);\r
+\r
+               editor = null;\r
+               updateHandler = null;\r
+       }\r
+\r
+       protected void installListeners(JTextComponent b) {\r
+               TextListener listener = updateHandler;\r
+               b.addMouseListener(listener);\r
+               b.addMouseMotionListener(listener);\r
+               b.addFocusListener(listener);\r
+               b.addPropertyChangeListener(listener);\r
+               // SwingJS there won't be a document yet; this is in constructor\r
+               // b.getDocument().addDocumentListener(listener);\r
+       }\r
+\r
+       protected void uninstallListeners(JTextComponent b) {\r
+               TextListener listener = updateHandler;\r
+               b.removeMouseListener(listener);\r
+               b.removeMouseMotionListener(listener);\r
+               b.removeFocusListener(listener);\r
+               b.removePropertyChangeListener(listener);\r
+               b.getDocument().removeDocumentListener(listener);\r
+       }\r
+\r
+       // /**\r
+       // * Superclass paints background in an uncontrollable way\r
+       // * (i.e. one might want an image tiled into the background).\r
+       // * To prevent this from happening twice, this method is\r
+       // * reimplemented to simply paint.\r
+       // * <p>\r
+       // * <em>NOTE:</em> Superclass is also not thread-safe in\r
+       // * it's rendering of the background, although that's not\r
+       // * an issue with the default rendering.\r
+       // */\r
+       // public void update(Graphics g, JComponent c) {\r
+       // paint(g, c);\r
+       // }\r
+       //\r
+       // /**\r
+       // * Paints the interface. This is routed to the\r
+       // * paintSafely method under the guarantee that\r
+       // * the model won't change from the view of this thread\r
+       // * while it's rendering (if the associated model is\r
+       // * derived from AbstractDocument). This enables the\r
+       // * model to potentially be updated asynchronously.\r
+       // *\r
+       // * @param g the graphics context\r
+       // * @param c the editor component\r
+       // */\r
+       // public final void paint(Graphics g, JComponent c) {\r
+       // if ((rootView.getViewCount() > 0) && (rootView.getView(0) != null)) {\r
+       // Document doc = editor.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // paintSafely(g);\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+\r
+       // /**\r
+       // * Gets the preferred size for the editor component. If the component\r
+       // * has been given a size prior to receiving this request, it will\r
+       // * set the size of the view hierarchy to reflect the size of the component\r
+       // * before requesting the preferred size of the view hierarchy. This\r
+       // * allows formatted views to format to the current component size before\r
+       // * answering the request. Other views don't care about currently formatted\r
+       // * size and give the same answer either way.\r
+       // *\r
+       // * @param c the editor component\r
+       // * @return the size\r
+       // */\r
+       // public Dimension getPreferredSize(JComponent c) {\r
+       // Dimension d = c.getSize();\r
+       // // Document doc = editor.getDocument();\r
+       // // Insets i = c.getInsets();\r
+       // //\r
+       // // if (doc instanceof AbstractDocument) {\r
+       // // ((AbstractDocument)doc).readLock();\r
+       // // }\r
+       // // try {\r
+       // // if ((d.width > (i.left + i.right)) && (d.height > (i.top + i.bottom))) {\r
+       // // rootView.setSize(d.width - i.left - i.right, d.height - i.top -\r
+       // i.bottom);\r
+       // // }\r
+       // // else if (d.width == 0 && d.height == 0) {\r
+       // // // Probably haven't been layed out yet, force some sort of\r
+       // // // initial sizing.\r
+       // // rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE);\r
+       // // }\r
+       // // d.width = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) +\r
+       // // (long) i.left + (long) i.right, Integer.MAX_VALUE);\r
+       // // d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS)\r
+       // +\r
+       // // (long) i.top + (long) i.bottom, Integer.MAX_VALUE);\r
+       // // } finally {\r
+       // // if (doc instanceof AbstractDocument) {\r
+       // // ((AbstractDocument)doc).readUnlock();\r
+       // // }\r
+       // // }\r
+       // return d;\r
+       // }\r
+\r
+       /**\r
+        * Gets the minimum size for the editor component.\r
+        * \r
+        * @param c\r
+        *          the editor component\r
+        * @return the size\r
+        */\r
+       public Dimension getMinimumSize(JComponent c) {\r
+               Dimension d = getPreferredSize();// new Dimension();\r
+               // Document doc = editor.getDocument();\r
+               Insets i = c.getInsets();\r
+               // if (doc instanceof AbstractDocument) {\r
+               // ((AbstractDocument)doc).readLock();\r
+               // }\r
+               // try {\r
+\r
+               d.width += i.left + i.right;\r
+               d.height += i.top + i.bottom;\r
+\r
+               // d.width = (int) rootView.getMinimumSpan(View.X_AXIS) + i.left + i.right;\r
+               // d.height = (int) rootView.getMinimumSpan(View.Y_AXIS) + i.top + i.bottom;\r
+               // } finally {\r
+               // if (doc instanceof AbstractDocument) {\r
+               // ((AbstractDocument)doc).readUnlock();\r
+               // }\r
+               // }\r
+               return d;\r
+       }\r
+\r
+       /**\r
+        * Gets the maximum size for the editor component.\r
+        * \r
+        * @param c\r
+        *          the editor component\r
+        * @return the size\r
+        */\r
+       public Dimension getMaximumSize(JComponent c) {\r
+               // SwingJS TODO\r
+               return getMinimumSize(c);\r
+\r
+               // Document doc = editor.getDocument();\r
+               // Insets i = c.getInsets();\r
+               // Dimension d = new Dimension();\r
+               // if (doc instanceof AbstractDocument) {\r
+               // ((AbstractDocument)doc).readLock();\r
+               // }\r
+               // try {\r
+               // d.width = (int) Math.min((long) rootView.getMaximumSpan(View.X_AXIS) +\r
+               // (long) i.left + (long) i.right, Integer.MAX_VALUE);\r
+               // d.height = (int) Math.min((long) rootView.getMaximumSpan(View.Y_AXIS) +\r
+               // (long) i.top + (long) i.bottom, Integer.MAX_VALUE);\r
+               // } finally {\r
+               // if (doc instanceof AbstractDocument) {\r
+               // ((AbstractDocument)doc).readUnlock();\r
+               // }\r
+               // }\r
+               // return d;\r
+       }\r
+\r
+       // ---- TextUI methods -------------------------------------------\r
+\r
+       //\r
+       // /**\r
+       // * Gets the allocation to give the root View. Due\r
+       // * to an unfortunate set of historical events this\r
+       // * method is inappropriately named. The Rectangle\r
+       // * returned has nothing to do with visibility.\r
+       // * The component must have a non-zero positive size for\r
+       // * this translation to be computed.\r
+       // *\r
+       // * @return the bounding box for the root view\r
+       // */\r
+       // protected Rectangle getVisibleEditorRect() {\r
+       // Rectangle alloc = editor.getBounds();\r
+       // if ((alloc.width > 0) && (alloc.height > 0)) {\r
+       // alloc.x = alloc.y = 0;\r
+       // Insets insets = editor.getInsets();\r
+       // alloc.x += insets.left;\r
+       // alloc.y += insets.top;\r
+       // alloc.width -= insets.left + insets.right;\r
+       // alloc.height -= insets.top + insets.bottom;\r
+       // return alloc;\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Converts the given location in the model to a place in\r
+       // * the view coordinate system.\r
+       // * The component must have a non-zero positive size for\r
+       // * this translation to be computed.\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @param pos the local location in the model to translate >= 0\r
+       // * @return the coordinates as a rectangle, null if the model is not painted\r
+       // * @exception BadLocationException if the given position does not\r
+       // * represent a valid location in the associated document\r
+       // * @see TextUI#modelToView\r
+       // */\r
+       // public Rectangle modelToView(JTextComponent tc, int pos) throws\r
+       // BadLocationException {\r
+       // return modelToView(tc, pos, Position.Bias.Forward);\r
+       // }\r
+       //\r
+       // /**\r
+       // * Converts the given location in the model to a place in\r
+       // * the view coordinate system.\r
+       // * The component must have a non-zero positive size for\r
+       // * this translation to be computed.\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @param pos the local location in the model to translate >= 0\r
+       // * @return the coordinates as a rectangle, null if the model is not painted\r
+       // * @exception BadLocationException if the given position does not\r
+       // * represent a valid location in the associated document\r
+       // * @see TextUI#modelToView\r
+       // */\r
+       // public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias\r
+       // bias) throws BadLocationException {\r
+       // Document doc = editor.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // rootView.setSize(alloc.width, alloc.height);\r
+       // Shape s = rootView.modelToView(pos, alloc, bias);\r
+       // if (s != null) {\r
+       // return s.getBounds();\r
+       // }\r
+       // }\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Converts the given place in the view coordinate system\r
+       // * to the nearest representative location in the model.\r
+       // * The component must have a non-zero positive size for\r
+       // * this translation to be computed.\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @param pt the location in the view to translate. This\r
+       // * should be in the same coordinate system as the mouse events.\r
+       // * @return the offset from the start of the document >= 0,\r
+       // * -1 if not painted\r
+       // * @see TextUI#viewToModel\r
+       // */\r
+       // public int viewToModel(JTextComponent tc, Point pt) {\r
+       // return viewToModel(tc, pt, discardBias);\r
+       // }\r
+       //\r
+       // /**\r
+       // * Converts the given place in the view coordinate system\r
+       // * to the nearest representative location in the model.\r
+       // * The component must have a non-zero positive size for\r
+       // * this translation to be computed.\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @param pt the location in the view to translate. This\r
+       // * should be in the same coordinate system as the mouse events.\r
+       // * @return the offset from the start of the document >= 0,\r
+       // * -1 if the component doesn't yet have a positive size.\r
+       // * @see TextUI#viewToModel\r
+       // */\r
+       // public int viewToModel(JTextComponent tc, Point pt,\r
+       // Position.Bias[] biasReturn) {\r
+       // int offs = -1;\r
+       // Document doc = editor.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // rootView.setSize(alloc.width, alloc.height);\r
+       // offs = rootView.viewToModel(pt.x, pt.y, alloc, biasReturn);\r
+       // }\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // return offs;\r
+       // }\r
+\r
+       // /**\r
+       // * {@inheritDoc}\r
+       // */\r
+       // public int getNextVisualPositionFrom(JTextComponent t, int pos,\r
+       // Position.Bias b, int direction, Position.Bias[] biasRet)\r
+       // throws BadLocationException{\r
+       // Document doc = editor.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // if (painted) {\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // rootView.setSize(alloc.width, alloc.height);\r
+       // }\r
+       // return rootView.getNextVisualPositionFrom(pos, b, alloc, direction,\r
+       // biasRet);\r
+       // }\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // return -1;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Causes the portion of the view responsible for the\r
+       // * given part of the model to be repainted. Does nothing if\r
+       // * the view is not currently painted.\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @param p0 the beginning of the range >= 0\r
+       // * @param p1 the end of the range >= p0\r
+       // * @see TextUI#damageRange\r
+       // */\r
+       // public void damageRange(JTextComponent tc, int p0, int p1) {\r
+       // damageRange(tc, p0, p1, Position.Bias.Forward, Position.Bias.Backward);\r
+       // }\r
+       //\r
+       // /**\r
+       // * Causes the portion of the view responsible for the\r
+       // * given part of the model to be repainted.\r
+       // *\r
+       // * @param p0 the beginning of the range >= 0\r
+       // * @param p1 the end of the range >= p0\r
+       // */\r
+       // public void damageRange(JTextComponent t, int p0, int p1,\r
+       // Position.Bias p0Bias, Position.Bias p1Bias) {\r
+       // if (painted) {\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // Document doc = t.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // rootView.setSize(alloc.width, alloc.height);\r
+       // Shape toDamage = rootView.modelToView(p0, p0Bias,\r
+       // p1, p1Bias, alloc);\r
+       // Rectangle rect = (toDamage instanceof Rectangle) ?\r
+       // (Rectangle)toDamage : toDamage.getBounds();\r
+       // editor.repaint(rect.x, rect.y, rect.width, rect.height);\r
+       // } catch (BadLocationException e) {\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+\r
+       /**\r
+        * Fetches the EditorKit for the UI.\r
+        * \r
+        * @param tc\r
+        *          the text component for which this UI is installed\r
+        * @return the editor capabilities\r
+        * @see TextUI#getEditorKit\r
+        */\r
+       public EditorKit getEditorKit(JTextComponent tc) {\r
+               return defaultKit;\r
+       }\r
+\r
+       // /**\r
+       // * Fetches a View with the allocation of the associated\r
+       // * text component (i.e. the root of the hierarchy) that\r
+       // * can be traversed to determine how the model is being\r
+       // * represented spatially.\r
+       // * <p>\r
+       // * <font color=red><b>NOTE:</b>The View hierarchy can\r
+       // * be traversed from the root view, and other things\r
+       // * can be done as well. Things done in this way cannot\r
+       // * be protected like simple method calls through the TextUI.\r
+       // * Therefore, proper operation in the presence of concurrency\r
+       // * must be arranged by any logic that calls this method!\r
+       // * </font>\r
+       // *\r
+       // * @param tc the text component for which this UI is installed\r
+       // * @return the view\r
+       // * @see TextUI#getRootView\r
+       // */\r
+       // public View getRootView(JTextComponent tc) {\r
+       // return rootView;\r
+       // }\r
+\r
+       // /**\r
+       // * Returns the string to be used as the tooltip at the passed in location.\r
+       // * This forwards the method onto the root View.\r
+       // *\r
+       // * @see jsjavax.swing.text.JTextComponent#getToolTipText\r
+       // * @see jsjavax.swing.text.View#getToolTipText\r
+       // * @since 1.4\r
+       // */\r
+       // public String getToolTipText(JTextComponent t, Point pt) {\r
+       // if (!painted) {\r
+       // return null;\r
+       // }\r
+       // Document doc = editor.getDocument();\r
+       // String tt = null;\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       //\r
+       // if (alloc != null) {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // tt = rootView.getToolTipText(pt.x, pt.y, alloc);\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // }\r
+       // return tt;\r
+       // }\r
+       //\r
+       // --- ViewFactory methods ------------------------------\r
+       //\r
+       // /**\r
+       // * Creates a view for an element.\r
+       // * If a subclass wishes to directly implement the factory\r
+       // * producing the view(s), it should reimplement this\r
+       // * method. By default it simply returns null indicating\r
+       // * it is unable to represent the element.\r
+       // *\r
+       // * @param elem the element\r
+       // * @return the view\r
+       // */\r
+       // public View create(Element elem) {\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Creates a view for an element.\r
+       // * If a subclass wishes to directly implement the factory\r
+       // * producing the view(s), it should reimplement this\r
+       // * method. By default it simply returns null indicating\r
+       // * it is unable to represent the part of the element.\r
+       // *\r
+       // * @param elem the element\r
+       // * @param p0 the starting offset >= 0\r
+       // * @param p1 the ending offset >= p0\r
+       // * @return the view\r
+       // */\r
+       // public View create(Element elem, int p0, int p1) {\r
+       // return null;\r
+       // }\r
+       //\r
+       // public static class BasicCaret extends DefaultCaret implements UIResource\r
+       // {}\r
+       //\r
+       // public static class BasicHighlighter extends DefaultHighlighter implements\r
+       // UIResource {}\r
+       //\r
+       // static class BasicCursor extends Cursor implements UIResource {\r
+       // BasicCursor(int type) {\r
+       // super(type);\r
+       // }\r
+       //\r
+       // BasicCursor(String name) {\r
+       // super(name);\r
+       // }\r
+       // }\r
+       //\r
+       // private static BasicCursor textCursor = new\r
+       // BasicCursor(Cursor.TEXT_CURSOR);\r
+       // ----- member variables ---------------------------------------\r
+\r
+       private static final EditorKit defaultKit = new DefaultEditorKit();\r
+       transient JTextComponent editor;\r
+       protected boolean editable = true;\r
+\r
+       // transient boolean painted;\r
+       // transient RootView rootView = new RootView();\r
+       // transient UpdateHandler updateHandler = new UpdateHandler();\r
+       // private static final TransferHandler defaultTransferHandler = new\r
+       // TextTransferHandler();\r
+       // private final DragListener dragListener = getDragListener();\r
+       // private static final Position.Bias[] discardBias = new Position.Bias[1];\r
+       // private DefaultCaret dropCaret;\r
+\r
+       // /**\r
+       // * Root view that acts as a gateway between the component\r
+       // * and the View hierarchy.\r
+       // */\r
+       // class RootView extends View {\r
+       //\r
+       // RootView() {\r
+       // super(null);\r
+       // }\r
+       //\r
+       // void setView(View v) {\r
+       // View oldView = view;\r
+       // view = null;\r
+       // if (oldView != null) {\r
+       // // get rid of back reference so that the old\r
+       // // hierarchy can be garbage collected.\r
+       // oldView.setParent(null);\r
+       // }\r
+       // if (v != null) {\r
+       // v.setParent(this);\r
+       // }\r
+       // view = v;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Fetches the attributes to use when rendering. At the root\r
+       // * level there are no attributes. If an attribute is resolved\r
+       // * up the view hierarchy this is the end of the line.\r
+       // */\r
+       // public AttributeSet getAttributes() {\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines the preferred span for this view along an axis.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @return the span the view would like to be rendered into.\r
+       // * Typically the view is told to render into the span\r
+       // * that is returned, although there is no guarantee.\r
+       // * The parent may choose to resize or break the view.\r
+       // */\r
+       // public float getPreferredSpan(int axis) {\r
+       // if (view != null) {\r
+       // return view.getPreferredSpan(axis);\r
+       // }\r
+       // return 10;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines the minimum span for this view along an axis.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @return the span the view would like to be rendered into.\r
+       // * Typically the view is told to render into the span\r
+       // * that is returned, although there is no guarantee.\r
+       // * The parent may choose to resize or break the view.\r
+       // */\r
+       // public float getMinimumSpan(int axis) {\r
+       // if (view != null) {\r
+       // return view.getMinimumSpan(axis);\r
+       // }\r
+       // return 10;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines the maximum span for this view along an axis.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @return the span the view would like to be rendered into.\r
+       // * Typically the view is told to render into the span\r
+       // * that is returned, although there is no guarantee.\r
+       // * The parent may choose to resize or break the view.\r
+       // */\r
+       // public float getMaximumSpan(int axis) {\r
+       // return Integer.MAX_VALUE;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Specifies that a preference has changed.\r
+       // * Child views can call this on the parent to indicate that\r
+       // * the preference has changed. The root view routes this to\r
+       // * invalidate on the hosting component.\r
+       // * <p>\r
+       // * This can be called on a different thread from the\r
+       // * event dispatching thread and is basically unsafe to\r
+       // * propagate into the component. To make this safe,\r
+       // * the operation is transferred over to the event dispatching\r
+       // * thread for completion. It is a design goal that all view\r
+       // * methods be safe to call without concern for concurrency,\r
+       // * and this behavior helps make that true.\r
+       // *\r
+       // * @param child the child view\r
+       // * @param width true if the width preference has changed\r
+       // * @param height true if the height preference has changed\r
+       // */\r
+       // public void preferenceChanged(View child, boolean width, boolean height) {\r
+       // editor.revalidate();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines the desired alignment for this view along an axis.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @return the desired alignment, where 0.0 indicates the origin\r
+       // * and 1.0 the full span away from the origin\r
+       // */\r
+       // public float getAlignment(int axis) {\r
+       // if (view != null) {\r
+       // return view.getAlignment(axis);\r
+       // }\r
+       // return 0;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Renders the view.\r
+       // *\r
+       // * @param g the graphics context\r
+       // * @param allocation the region to render into\r
+       // */\r
+       // public void paint(Graphics g, Shape allocation) {\r
+       // if (view != null) {\r
+       // Rectangle alloc = (allocation instanceof Rectangle) ?\r
+       // (Rectangle)allocation : allocation.getBounds();\r
+       // setSize(alloc.width, alloc.height);\r
+       // view.paint(g, allocation);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Sets the view parent.\r
+       // *\r
+       // * @param parent the parent view\r
+       // */\r
+       // public void setParent(View parent) {\r
+       // throw new Error("Can't set parent on root view");\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the number of views in this view. Since\r
+       // * this view simply wraps the root of the view hierarchy\r
+       // * it has exactly one child.\r
+       // *\r
+       // * @return the number of views\r
+       // * @see #getView\r
+       // */\r
+       // public int getViewCount() {\r
+       // return 1;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gets the n-th view in this container.\r
+       // *\r
+       // * @param n the number of the view to get\r
+       // * @return the view\r
+       // */\r
+       // public View getView(int n) {\r
+       // return view;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the child view index representing the given position in\r
+       // * the model. This is implemented to return the index of the only\r
+       // * child.\r
+       // *\r
+       // * @param pos the position >= 0\r
+       // * @return index of the view representing the given position, or\r
+       // * -1 if no view represents that position\r
+       // * @since 1.3\r
+       // */\r
+       // public int getViewIndex(int pos, Position.Bias b) {\r
+       // return 0;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Fetches the allocation for the given child view.\r
+       // * This enables finding out where various views\r
+       // * are located, without assuming the views store\r
+       // * their location. This returns the given allocation\r
+       // * since this view simply acts as a gateway between\r
+       // * the view hierarchy and the associated component.\r
+       // *\r
+       // * @param index the index of the child\r
+       // * @param a the allocation to this view.\r
+       // * @return the allocation to the child\r
+       // */\r
+       // public Shape getChildAllocation(int index, Shape a) {\r
+       // return a;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Provides a mapping from the document model coordinate space\r
+       // * to the coordinate space of the view mapped to it.\r
+       // *\r
+       // * @param pos the position to convert\r
+       // * @param a the allocated region to render into\r
+       // * @return the bounding box of the given position\r
+       // */\r
+       // public Shape modelToView(int pos, Shape a, Position.Bias b) throws\r
+       // BadLocationException {\r
+       // if (view != null) {\r
+       // return view.modelToView(pos, a, b);\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Provides a mapping from the document model coordinate space\r
+       // * to the coordinate space of the view mapped to it.\r
+       // *\r
+       // * @param p0 the position to convert >= 0\r
+       // * @param b0 the bias toward the previous character or the\r
+       // * next character represented by p0, in case the\r
+       // * position is a boundary of two views.\r
+       // * @param p1 the position to convert >= 0\r
+       // * @param b1 the bias toward the previous character or the\r
+       // * next character represented by p1, in case the\r
+       // * position is a boundary of two views.\r
+       // * @param a the allocated region to render into\r
+       // * @return the bounding box of the given position is returned\r
+       // * @exception BadLocationException if the given position does\r
+       // * not represent a valid location in the associated document\r
+       // * @exception IllegalArgumentException for an invalid bias argument\r
+       // * @see View#viewToModel\r
+       // */\r
+       // public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias\r
+       // b1, Shape a) throws BadLocationException {\r
+       // if (view != null) {\r
+       // return view.modelToView(p0, b0, p1, b1, a);\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Provides a mapping from the view coordinate space to the logical\r
+       // * coordinate space of the model.\r
+       // *\r
+       // * @param x x coordinate of the view location to convert\r
+       // * @param y y coordinate of the view location to convert\r
+       // * @param a the allocated region to render into\r
+       // * @return the location within the model that best represents the\r
+       // * given point in the view\r
+       // */\r
+       // public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {\r
+       // if (view != null) {\r
+       // int retValue = view.viewToModel(x, y, a, bias);\r
+       // return retValue;\r
+       // }\r
+       // return -1;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Provides a way to determine the next visually represented model\r
+       // * location that one might place a caret. Some views may not be visible,\r
+       // * they might not be in the same order found in the model, or they just\r
+       // * might not allow access to some of the locations in the model.\r
+       // *\r
+       // * @param pos the position to convert >= 0\r
+       // * @param a the allocated region to render into\r
+       // * @param direction the direction from the current position that can\r
+       // * be thought of as the arrow keys typically found on a keyboard.\r
+       // * This may be SwingConstants.WEST, SwingConstants.EAST,\r
+       // * SwingConstants.NORTH, or SwingConstants.SOUTH.\r
+       // * @return the location within the model that best represents the next\r
+       // * location visual position.\r
+       // * @exception BadLocationException\r
+       // * @exception IllegalArgumentException for an invalid direction\r
+       // */\r
+       // public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,\r
+       // int direction,\r
+       // Position.Bias[] biasRet)\r
+       // throws BadLocationException {\r
+       // if( view != null ) {\r
+       // int nextPos = view.getNextVisualPositionFrom(pos, b, a,\r
+       // direction, biasRet);\r
+       // if(nextPos != -1) {\r
+       // pos = nextPos;\r
+       // }\r
+       // else {\r
+       // biasRet[0] = b;\r
+       // }\r
+       // }\r
+       // return pos;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gives notification that something was inserted into the document\r
+       // * in a location that this view is responsible for.\r
+       // *\r
+       // * @param e the change information from the associated document\r
+       // * @param a the current allocation of the view\r
+       // * @param f the factory to use to rebuild if the view has children\r
+       // */\r
+       // public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {\r
+       // if (view != null) {\r
+       // view.insertUpdate(e, a, f);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gives notification that something was removed from the document\r
+       // * in a location that this view is responsible for.\r
+       // *\r
+       // * @param e the change information from the associated document\r
+       // * @param a the current allocation of the view\r
+       // * @param f the factory to use to rebuild if the view has children\r
+       // */\r
+       // public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {\r
+       // if (view != null) {\r
+       // view.removeUpdate(e, a, f);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gives notification from the document that attributes were changed\r
+       // * in a location that this view is responsible for.\r
+       // *\r
+       // * @param e the change information from the associated document\r
+       // * @param a the current allocation of the view\r
+       // * @param f the factory to use to rebuild if the view has children\r
+       // */\r
+       // public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {\r
+       // if (view != null) {\r
+       // view.changedUpdate(e, a, f);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the document model underlying the view.\r
+       // *\r
+       // * @return the model\r
+       // */\r
+       // public Document getDocument() {\r
+       // return editor.getDocument();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the starting offset into the model for this view.\r
+       // *\r
+       // * @return the starting offset\r
+       // */\r
+       // public int getStartOffset() {\r
+       // if (view != null) {\r
+       // return view.getStartOffset();\r
+       // }\r
+       // return getElement().getStartOffset();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the ending offset into the model for this view.\r
+       // *\r
+       // * @return the ending offset\r
+       // */\r
+       // public int getEndOffset() {\r
+       // if (view != null) {\r
+       // return view.getEndOffset();\r
+       // }\r
+       // return getElement().getEndOffset();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gets the element that this view is mapped to.\r
+       // *\r
+       // * @return the view\r
+       // */\r
+       // public Element getElement() {\r
+       // if (view != null) {\r
+       // return view.getElement();\r
+       // }\r
+       // return editor.getDocument().getDefaultRootElement();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Breaks this view on the given axis at the given length.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @param len specifies where a break is desired in the span\r
+       // * @param the current allocation of the view\r
+       // * @return the fragment of the view that represents the given span\r
+       // * if the view can be broken, otherwise null\r
+       // */\r
+       // public View breakView(int axis, float len, Shape a) {\r
+       // throw new Error("Can't break root view");\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines the resizability of the view along the\r
+       // * given axis. A value of 0 or less is not resizable.\r
+       // *\r
+       // * @param axis may be either X_AXIS or Y_AXIS\r
+       // * @return the weight\r
+       // */\r
+       // public int getResizeWeight(int axis) {\r
+       // if (view != null) {\r
+       // return view.getResizeWeight(axis);\r
+       // }\r
+       // return 0;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Sets the view size.\r
+       // *\r
+       // * @param width the width\r
+       // * @param height the height\r
+       // */\r
+       // public void setSize(float width, float height) {\r
+       // if (view != null) {\r
+       // view.setSize(width, height);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Fetches the container hosting the view. This is useful for\r
+       // * things like scheduling a repaint, finding out the host\r
+       // * components font, etc. The default implementation\r
+       // * of this is to forward the query to the parent view.\r
+       // *\r
+       // * @return the container\r
+       // */\r
+       // public Container getContainer() {\r
+       // return editor;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Fetches the factory to be used for building the\r
+       // * various view fragments that make up the view that\r
+       // * represents the model. This is what determines\r
+       // * how the model will be represented. This is implemented\r
+       // * to fetch the factory provided by the associated\r
+       // * EditorKit unless that is null, in which case this\r
+       // * simply returns the BasicTextUI itself which allows\r
+       // * subclasses to implement a simple factory directly without\r
+       // * creating extra objects.\r
+       // *\r
+       // * @return the factory\r
+       // */\r
+       // public ViewFactory getViewFactory() {\r
+       // EditorKit kit = getEditorKit(editor);\r
+       // ViewFactory f = kit.getViewFactory();\r
+       // if (f != null) {\r
+       // return f;\r
+       // }\r
+       // return BasicTextUI.this;\r
+       // }\r
+       //\r
+       // private View view;\r
+       //\r
+       // }\r
+\r
+       // /**\r
+       // * Handles updates from various places. If the model is changed,\r
+       // * this class unregisters as a listener to the old model and\r
+       // * registers with the new model. If the document model changes,\r
+       // * the change is forwarded to the root view. If the focus\r
+       // * accelerator changes, a new keystroke is registered to request\r
+       // * focus.\r
+       // */\r
+       // class UpdateHandler implements PropertyChangeListener, DocumentListener,\r
+       // LayoutManager2, UIResource {\r
+       //\r
+       // // --- PropertyChangeListener methods -----------------------\r
+       //\r
+       // /**\r
+       // * This method gets called when a bound property is changed.\r
+       // * We are looking for document changes on the editor.\r
+       // */\r
+       // public final void propertyChange(PropertyChangeEvent evt) {\r
+       // Object oldValue = evt.getOldValue();\r
+       // Object newValue = evt.getNewValue();\r
+       // String propertyName = evt.getPropertyName();\r
+       // if ((oldValue instanceof Document) || (newValue instanceof Document)) {\r
+       // if (oldValue != null) {\r
+       // ((Document)oldValue).removeDocumentListener(this);\r
+       // i18nView = false;\r
+       // }\r
+       // if (newValue != null) {\r
+       // ((Document)newValue).addDocumentListener(this);\r
+       // if ("document" == propertyName) {\r
+       // setView(null);\r
+       // BasicTextUI.this.propertyChange(evt);\r
+       // modelChanged();\r
+       // return;\r
+       // }\r
+       // }\r
+       // modelChanged();\r
+       // }\r
+       // if ("focusAccelerator" == propertyName) {\r
+       // updateFocusAcceleratorBinding(true);\r
+       // } else if ("componentOrientation" == propertyName) {\r
+       // // Changes in ComponentOrientation require the views to be\r
+       // // rebuilt.\r
+       // modelChanged();\r
+       // } else if ("font" == propertyName) {\r
+       // modelChanged();\r
+       // } else if ("dropLocation" == propertyName) {\r
+       // dropIndexChanged();\r
+       // } else if ("editable" == propertyName) {\r
+       // updateCursor();\r
+       // modelChanged();\r
+       // }\r
+       // BasicTextUI.this.propertyChange(evt);\r
+       // }\r
+       //\r
+       // private void dropIndexChanged() {\r
+       // if (editor.getDropMode() == DropMode.USE_SELECTION) {\r
+       // return;\r
+       // }\r
+       //\r
+       // JTextComponent.DropLocation dropLocation = editor.getDropLocation();\r
+       //\r
+       // if (dropLocation == null) {\r
+       // if (dropCaret != null) {\r
+       // dropCaret.deinstall(editor);\r
+       // editor.repaint(dropCaret);\r
+       // dropCaret = null;\r
+       // }\r
+       // } else {\r
+       // if (dropCaret == null) {\r
+       // dropCaret = new BasicCaret();\r
+       // dropCaret.install(editor);\r
+       // dropCaret.setVisible(true);\r
+       // }\r
+       //\r
+       // dropCaret.setDot(dropLocation.getIndex(),\r
+       // dropLocation.getBias());\r
+       // }\r
+       // }\r
+       //\r
+       // // --- DocumentListener methods -----------------------\r
+       //\r
+       // /**\r
+       // * The insert notification. Gets sent to the root of the view structure\r
+       // * that represents the portion of the model being represented by the\r
+       // * editor. The factory is added as an argument to the update so that\r
+       // * the views can update themselves in a dynamic (not hardcoded) way.\r
+       // *\r
+       // * @param e The change notification from the currently associated\r
+       // * document.\r
+       // * @see DocumentListener#insertUpdate\r
+       // */\r
+       // public final void insertUpdate(DocumentEvent e) {\r
+       // Document doc = e.getDocument();\r
+       // Object o = doc.getProperty("i18n");\r
+       // if (o instanceof Boolean) {\r
+       // Boolean i18nFlag = (Boolean) o;\r
+       // if (i18nFlag.booleanValue() != i18nView) {\r
+       // // i18n flag changed, rebuild the view\r
+       // i18nView = i18nFlag.booleanValue();\r
+       // modelChanged();\r
+       // return;\r
+       // }\r
+       // }\r
+       //\r
+       // // normal insert update\r
+       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;\r
+       // rootView.insertUpdate(e, alloc, rootView.getViewFactory());\r
+       // }\r
+       //\r
+       // /**\r
+       // * The remove notification. Gets sent to the root of the view structure\r
+       // * that represents the portion of the model being represented by the\r
+       // * editor. The factory is added as an argument to the update so that\r
+       // * the views can update themselves in a dynamic (not hardcoded) way.\r
+       // *\r
+       // * @param e The change notification from the currently associated\r
+       // * document.\r
+       // * @see DocumentListener#removeUpdate\r
+       // */\r
+       // public final void removeUpdate(DocumentEvent e) {\r
+       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;\r
+       // rootView.removeUpdate(e, alloc, rootView.getViewFactory());\r
+       // }\r
+       //\r
+       // /**\r
+       // * The change notification. Gets sent to the root of the view structure\r
+       // * that represents the portion of the model being represented by the\r
+       // * editor. The factory is added as an argument to the update so that\r
+       // * the views can update themselves in a dynamic (not hardcoded) way.\r
+       // *\r
+       // * @param e The change notification from the currently associated\r
+       // * document.\r
+       // * @see DocumentListener#changeUpdate\r
+       // */\r
+       // public final void changedUpdate(DocumentEvent e) {\r
+       // Rectangle alloc = (painted) ? getVisibleEditorRect() : null;\r
+       // rootView.changedUpdate(e, alloc, rootView.getViewFactory());\r
+       // }\r
+       //\r
+       // // --- LayoutManager2 methods --------------------------------\r
+       //\r
+       // /**\r
+       // * Adds the specified component with the specified name to\r
+       // * the layout.\r
+       // * @param name the component name\r
+       // * @param comp the component to be added\r
+       // */\r
+       // public void addLayoutComponent(String name, Component comp) {\r
+       // // not supported\r
+       // }\r
+       //\r
+       // /**\r
+       // * Removes the specified component from the layout.\r
+       // * @param comp the component to be removed\r
+       // */\r
+       // public void removeLayoutComponent(Component comp) {\r
+       // if (constraints != null) {\r
+       // // remove the constraint record\r
+       // constraints.remove(comp);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Calculates the preferred size dimensions for the specified\r
+       // * panel given the components in the specified parent container.\r
+       // * @param parent the component to be laid out\r
+       // *\r
+       // * @see #minimumLayoutSize\r
+       // */\r
+       // public Dimension preferredLayoutSize(Container parent) {\r
+       // // should not be called (JComponent uses UI instead)\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Calculates the minimum size dimensions for the specified\r
+       // * panel given the components in the specified parent container.\r
+       // * @param parent the component to be laid out\r
+       // * @see #preferredLayoutSize\r
+       // */\r
+       // public Dimension minimumLayoutSize(Container parent) {\r
+       // // should not be called (JComponent uses UI instead)\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Lays out the container in the specified panel. This is\r
+       // * implemented to position all components that were added\r
+       // * with a View object as a constraint. The current allocation\r
+       // * of the associated View is used as the location of the\r
+       // * component.\r
+       // * <p>\r
+       // * A read-lock is acquired on the document to prevent the\r
+       // * view tree from being modified while the layout process\r
+       // * is active.\r
+       // *\r
+       // * @param parent the component which needs to be laid out\r
+       // */\r
+       // public void layoutContainer(Container parent) {\r
+       // if ((constraints != null) && (! constraints.isEmpty())) {\r
+       // Rectangle alloc = getVisibleEditorRect();\r
+       // if (alloc != null) {\r
+       // Document doc = editor.getDocument();\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readLock();\r
+       // }\r
+       // try {\r
+       // rootView.setSize(alloc.width, alloc.height);\r
+       // Enumeration components = constraints.keys();\r
+       // while (components.hasMoreElements()) {\r
+       // Component comp = (Component) components.nextElement();\r
+       // View v = (View) constraints.get(comp);\r
+       // Shape ca = calculateViewPosition(alloc, v);\r
+       // if (ca != null) {\r
+       // Rectangle compAlloc = (ca instanceof Rectangle) ?\r
+       // (Rectangle) ca : ca.getBounds();\r
+       // comp.setBounds(compAlloc);\r
+       // }\r
+       // }\r
+       // } finally {\r
+       // if (doc instanceof AbstractDocument) {\r
+       // ((AbstractDocument)doc).readUnlock();\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Find the Shape representing the given view.\r
+       // */\r
+       // Shape calculateViewPosition(Shape alloc, View v) {\r
+       // int pos = v.getStartOffset();\r
+       // View child = null;\r
+       // for (View parent = rootView; (parent != null) && (parent != v); parent =\r
+       // child) {\r
+       // int index = parent.getViewIndex(pos, Position.Bias.Forward);\r
+       // alloc = parent.getChildAllocation(index, alloc);\r
+       // child = parent.getView(index);\r
+       // }\r
+       // return (child != null) ? alloc : null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Adds the specified component to the layout, using the specified\r
+       // * constraint object. We only store those components that were added\r
+       // * with a constraint that is of type View.\r
+       // *\r
+       // * @param comp the component to be added\r
+       // * @param constraint where/how the component is added to the layout.\r
+       // */\r
+       // public void addLayoutComponent(Component comp, Object constraint) {\r
+       // if (constraint instanceof View) {\r
+       // if (constraints == null) {\r
+       // constraints = new Hashtable(7);\r
+       // }\r
+       // constraints.put(comp, constraint);\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the maximum size of this component.\r
+       // * @see jsjava.awt.Component#getMinimumSize()\r
+       // * @see jsjava.awt.Component#getPreferredSize()\r
+       // * @see LayoutManager\r
+       // */\r
+       // public Dimension maximumLayoutSize(Container target) {\r
+       // // should not be called (JComponent uses UI instead)\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the alignment along the x axis. This specifies how\r
+       // * the component would like to be aligned relative to other\r
+       // * components. The value should be a number between 0 and 1\r
+       // * where 0 represents alignment along the origin, 1 is aligned\r
+       // * the furthest away from the origin, 0.5 is centered, etc.\r
+       // */\r
+       // public float getLayoutAlignmentX(Container target) {\r
+       // return 0.5f;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Returns the alignment along the y axis. This specifies how\r
+       // * the component would like to be aligned relative to other\r
+       // * components. The value should be a number between 0 and 1\r
+       // * where 0 represents alignment along the origin, 1 is aligned\r
+       // * the furthest away from the origin, 0.5 is centered, etc.\r
+       // */\r
+       // public float getLayoutAlignmentY(Container target) {\r
+       // return 0.5f;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Invalidates the layout, indicating that if the layout manager\r
+       // * has cached information it should be discarded.\r
+       // */\r
+       // public void invalidateLayout(Container target) {\r
+       // }\r
+       //\r
+       // /**\r
+       // * The "layout constraints" for the LayoutManager2 implementation.\r
+       // * These are View objects for those components that are represented\r
+       // * by a View in the View tree.\r
+       // */\r
+       // private Hashtable constraints;\r
+       //\r
+       // private boolean i18nView = false;\r
+       // }\r
+\r
+       /**\r
+        * Wrapper for text actions to return isEnabled false in case editor is non\r
+        * editable\r
+        */\r
+       class TextActionWrapper extends TextAction {\r
+               public TextActionWrapper(TextAction action) {\r
+                       super((String) action.getValue(Action.NAME));\r
+                       this.action = action;\r
+               }\r
+\r
+               /**\r
+                * The operation to perform when this action is triggered.\r
+                * \r
+                * @param e\r
+                *          the action event\r
+                */\r
+               public void actionPerformed(ActionEvent e) {\r
+                       action.actionPerformed(e);\r
+               }\r
+\r
+               public boolean isEnabled() {\r
+                       return (editor == null || editor.isEditable()) ? action.isEnabled()\r
+                                       : false;\r
+               }\r
+\r
+               TextAction action = null;\r
+       }\r
+\r
+       /**\r
+        * Registered in the ActionMap.\r
+        */\r
+       class FocusAction extends AbstractAction {\r
+\r
+               public void actionPerformed(ActionEvent e) {\r
+                       editor.requestFocus();\r
+               }\r
+\r
+               public boolean isEnabled() {\r
+                       return editor.isEditable();\r
+               }\r
+       }\r
+\r
+       boolean handleEnter(int eventType) {\r
+               return false;\r
+       }\r
+\r
+       String bgcolor0;\r
+       \r
+       public void setEditable(boolean editable) {\r
+               \r
+               this.editable = editable;\r
+               if (domNode == null)\r
+                       return;\r
+               if (c.isBackgroundSet())\r
+                       bgcolor0 = JSToolkit.getCSSColor(c.getBackground());\r
+               if (editable) {\r
+                       domNode.removeAttribute("readOnly");\r
+                       if (bgcolor0 != null)\r
+                               DOMNode.setStyles(domNode, "background-color", bgcolor0);\r
+               } else {\r
+                       DOMNode.setAttr(domNode, "readOnly", "true");\r
+                       if (c.isBackgroundSet()) {\r
+                               bgcolor0 = JSToolkit.getCSSColor(c.getBackground());\r
+                       } else {\r
+                               if (bgcolor0 == null)\r
+                                       bgcolor0 = domNode.getStyle("background-color");\r
+                       }\r
+                       DOMNode.setStyles(domNode, "background-color", "rgba(0,0,0,0)");\r
+               }\r
+\r
+       }\r
+\r
+       // private static DragListener getDragListener() {\r
+       // synchronized(DragListener.class) {\r
+       // DragListener listener =\r
+       // (DragListener)AppContext.getAppContext().\r
+       // get(DragListener.class);\r
+       //\r
+       // if (listener == null) {\r
+       // listener = new DragListener();\r
+       // AppContext.getAppContext().put(DragListener.class, listener);\r
+       // }\r
+       //\r
+       // return listener;\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Listens for mouse events for the purposes of detecting drag gestures.\r
+       // * BasicTextUI will maintain one of these per AppContext.\r
+       // */\r
+       // static class DragListener extends MouseInputAdapter\r
+       // implements BeforeDrag {\r
+       //\r
+       // private boolean dragStarted;\r
+       //\r
+       // public void dragStarting(MouseEvent me) {\r
+       // dragStarted = true;\r
+       // }\r
+       //\r
+       // public void mousePressed(MouseEvent e) {\r
+       // JTextComponent c = (JTextComponent)e.getSource();\r
+       // if (c.getDragEnabled()) {\r
+       // dragStarted = false;\r
+       // if (isDragPossible(e) && DragRecognitionSupport.mousePressed(e)) {\r
+       // e.consume();\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       // public void mouseReleased(MouseEvent e) {\r
+       // JTextComponent c = (JTextComponent)e.getSource();\r
+       // if (c.getDragEnabled()) {\r
+       // if (dragStarted) {\r
+       // e.consume();\r
+       // }\r
+       //\r
+       // DragRecognitionSupport.mouseReleased(e);\r
+       // }\r
+       // }\r
+       //\r
+       // public void mouseDragged(MouseEvent e) {\r
+       // JTextComponent c = (JTextComponent)e.getSource();\r
+       // if (c.getDragEnabled()) {\r
+       // if (dragStarted || DragRecognitionSupport.mouseDragged(e, this)) {\r
+       // e.consume();\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Determines if the following are true:\r
+       // * <ul>\r
+       // * <li>the component is enabled\r
+       // * <li>the press event is located over a selection\r
+       // * </ul>\r
+       // */\r
+       // protected boolean isDragPossible(MouseEvent e) {\r
+       // JTextComponent c = (JTextComponent)e.getSource();\r
+       // if (c.isEnabled()) {\r
+       // Caret caret = c.getCaret();\r
+       // int dot = caret.getDot();\r
+       // int mark = caret.getMark();\r
+       // if (dot != mark) {\r
+       // Point p = new Point(e.getX(), e.getY());\r
+       // int pos = c.viewToModel(p);\r
+       //\r
+       // int p0 = Math.min(dot, mark);\r
+       // int p1 = Math.max(dot, mark);\r
+       // if ((pos >= p0) && (pos < p1)) {\r
+       // return true;\r
+       // }\r
+       // }\r
+       // }\r
+       // return false;\r
+       // }\r
+       // }\r
+\r
+       // static class TextTransferHandler extends TransferHandler implements\r
+       // UIResource {\r
+       //\r
+       // private JTextComponent exportComp;\r
+       // private boolean shouldRemove;\r
+       // private int p0;\r
+       // private int p1;\r
+       //\r
+       // /**\r
+       // * Whether or not this is a drop using\r
+       // * <code>DropMode.INSERT</code>.\r
+       // */\r
+       // private boolean modeBetween = false;\r
+       //\r
+       // /**\r
+       // * Whether or not this is a drop.\r
+       // */\r
+       // private boolean isDrop = false;\r
+       //\r
+       // /**\r
+       // * The drop action.\r
+       // */\r
+       // private int dropAction = MOVE;\r
+       //\r
+       // /**\r
+       // * The drop bias.\r
+       // */\r
+       // private Position.Bias dropBias;\r
+       //\r
+       // /**\r
+       // * Try to find a flavor that can be used to import a Transferable.\r
+       // * The set of usable flavors are tried in the following order:\r
+       // * <ol>\r
+       // * <li>First, an attempt is made to find a flavor matching the content type\r
+       // * of the EditorKit for the component.\r
+       // * <li>Second, an attempt to find a text/plain flavor is made.\r
+       // * <li>Third, an attempt to find a flavor representing a String reference\r
+       // * in the same VM is made.\r
+       // * <li>Lastly, DataFlavor.stringFlavor is searched for.\r
+       // * </ol>\r
+       // */\r
+       // protected DataFlavor getImportFlavor(DataFlavor[] flavors, JTextComponent\r
+       // c) {\r
+       // DataFlavor plainFlavor = null;\r
+       // DataFlavor refFlavor = null;\r
+       // DataFlavor stringFlavor = null;\r
+       //\r
+       // if (c instanceof JEditorPane) {\r
+       // for (int i = 0; i < flavors.length; i++) {\r
+       // String mime = flavors[i].getMimeType();\r
+       // if (mime.startsWith(((JEditorPane)c).getEditorKit().getContentType())) {\r
+       // return flavors[i];\r
+       // } else if (plainFlavor == null && mime.startsWith("text/plain")) {\r
+       // plainFlavor = flavors[i];\r
+       // } else if (refFlavor == null &&\r
+       // mime.startsWith("application/x-java-jvm-local-objectref")\r
+       // && flavors[i].getRepresentationClass() == jsjava.lang.String.class) {\r
+       // refFlavor = flavors[i];\r
+       // } else if (stringFlavor == null &&\r
+       // flavors[i].equals(DataFlavor.stringFlavor)) {\r
+       // stringFlavor = flavors[i];\r
+       // }\r
+       // }\r
+       // if (plainFlavor != null) {\r
+       // return plainFlavor;\r
+       // } else if (refFlavor != null) {\r
+       // return refFlavor;\r
+       // } else if (stringFlavor != null) {\r
+       // return stringFlavor;\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       //\r
+       // for (int i = 0; i < flavors.length; i++) {\r
+       // String mime = flavors[i].getMimeType();\r
+       // if (mime.startsWith("text/plain")) {\r
+       // return flavors[i];\r
+       // } else if (refFlavor == null &&\r
+       // mime.startsWith("application/x-java-jvm-local-objectref")\r
+       // && flavors[i].getRepresentationClass() == jsjava.lang.String.class) {\r
+       // refFlavor = flavors[i];\r
+       // } else if (stringFlavor == null &&\r
+       // flavors[i].equals(DataFlavor.stringFlavor)) {\r
+       // stringFlavor = flavors[i];\r
+       // }\r
+       // }\r
+       // if (refFlavor != null) {\r
+       // return refFlavor;\r
+       // } else if (stringFlavor != null) {\r
+       // return stringFlavor;\r
+       // }\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Import the given stream data into the text component.\r
+       // */\r
+       // protected void handleReaderImport(Reader in, JTextComponent c, boolean\r
+       // useRead)\r
+       // throws BadLocationException, IOException {\r
+       // if (useRead) {\r
+       // int startPosition = c.getSelectionStart();\r
+       // int endPosition = c.getSelectionEnd();\r
+       // int length = endPosition - startPosition;\r
+       // EditorKit kit = c.getUI().getEditorKit(c);\r
+       // Document doc = c.getDocument();\r
+       // if (length > 0) {\r
+       // doc.remove(startPosition, length);\r
+       // }\r
+       // kit.read(in, doc, startPosition);\r
+       // } else {\r
+       // char[] buff = new char[1024];\r
+       // int nch;\r
+       // boolean lastWasCR = false;\r
+       // int last;\r
+       // StringBuffer sbuff = null;\r
+       //\r
+       // // Read in a block at a time, mapping \r\n to \n, as well as single\r
+       // // \r to \n.\r
+       // while ((nch = in.read(buff, 0, buff.length)) != -1) {\r
+       // if (sbuff == null) {\r
+       // sbuff = new StringBuffer(nch);\r
+       // }\r
+       // last = 0;\r
+       // for(int counter = 0; counter < nch; counter++) {\r
+       // switch(buff[counter]) {\r
+       // case '\r':\r
+       // if (lastWasCR) {\r
+       // if (counter == 0) {\r
+       // sbuff.append('\n');\r
+       // } else {\r
+       // buff[counter - 1] = '\n';\r
+       // }\r
+       // } else {\r
+       // lastWasCR = true;\r
+       // }\r
+       // break;\r
+       // case '\n':\r
+       // if (lastWasCR) {\r
+       // if (counter > (last + 1)) {\r
+       // sbuff.append(buff, last, counter - last - 1);\r
+       // }\r
+       // // else nothing to do, can skip \r, next write will\r
+       // // write \n\r
+       // lastWasCR = false;\r
+       // last = counter;\r
+       // }\r
+       // break;\r
+       // default:\r
+       // if (lastWasCR) {\r
+       // if (counter == 0) {\r
+       // sbuff.append('\n');\r
+       // } else {\r
+       // buff[counter - 1] = '\n';\r
+       // }\r
+       // lastWasCR = false;\r
+       // }\r
+       // break;\r
+       // }\r
+       // }\r
+       // if (last < nch) {\r
+       // if (lastWasCR) {\r
+       // if (last < (nch - 1)) {\r
+       // sbuff.append(buff, last, nch - last - 1);\r
+       // }\r
+       // } else {\r
+       // sbuff.append(buff, last, nch - last);\r
+       // }\r
+       // }\r
+       // }\r
+       // if (lastWasCR) {\r
+       // sbuff.append('\n');\r
+       // }\r
+       // c.replaceSelection(sbuff != null ? sbuff.toString() : "");\r
+       // }\r
+       // }\r
+       //\r
+       // // --- TransferHandler methods ------------------------------------\r
+       //\r
+       // /**\r
+       // * This is the type of transfer actions supported by the source. Some models\r
+       // are\r
+       // * not mutable, so a transfer operation of COPY only should\r
+       // * be advertised in that case.\r
+       // *\r
+       // * @param c The component holding the data to be transfered. This\r
+       // * argument is provided to enable sharing of TransferHandlers by\r
+       // * multiple components.\r
+       // * @return This is implemented to return NONE if the component is a\r
+       // JPasswordField\r
+       // * since exporting data via user gestures is not allowed. If the text\r
+       // component is\r
+       // * editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.\r
+       // */\r
+       // public int getSourceActions(JComponent c) {\r
+       // if (c instanceof JPasswordField &&\r
+       // c.getClientProperty("JPasswordField.cutCopyAllowed") !=\r
+       // Boolean.TRUE) {\r
+       // return NONE;\r
+       // }\r
+       //\r
+       // return ((JTextComponent)c).isEditable() ? COPY_OR_MOVE : COPY;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Create a Transferable to use as the source for a data transfer.\r
+       // *\r
+       // * @param comp The component holding the data to be transfered. This\r
+       // * argument is provided to enable sharing of TransferHandlers by\r
+       // * multiple components.\r
+       // * @return The representation of the data to be transfered.\r
+       // *\r
+       // */\r
+       // protected Transferable createTransferable(JComponent comp) {\r
+       // exportComp = (JTextComponent)comp;\r
+       // shouldRemove = true;\r
+       // p0 = exportComp.getSelectionStart();\r
+       // p1 = exportComp.getSelectionEnd();\r
+       // return (p0 != p1) ? (new TextTransferable(exportComp, p0, p1)) : null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * This method is called after data has been exported. This method should\r
+       // remove\r
+       // * the data that was transfered if the action was MOVE.\r
+       // *\r
+       // * @param source The component that was the source of the data.\r
+       // * @param data The data that was transferred or possibly null\r
+       // * if the action is <code>NONE</code>.\r
+       // * @param action The actual action that was performed.\r
+       // */\r
+       // protected void exportDone(JComponent source, Transferable data, int action)\r
+       // {\r
+       // // only remove the text if shouldRemove has not been set to\r
+       // // false by importData and only if the action is a move\r
+       // if (shouldRemove && action == MOVE) {\r
+       // TextTransferable t = (TextTransferable)data;\r
+       // t.removeText();\r
+       // }\r
+       //\r
+       // exportComp = null;\r
+       // }\r
+       //\r
+       // public boolean importData(TransferSupport support) {\r
+       // isDrop = support.isDrop();\r
+       //\r
+       // if (isDrop) {\r
+       // modeBetween =\r
+       // ((JTextComponent)support.getComponent()).getDropMode() == DropMode.INSERT;\r
+       //\r
+       // dropBias =\r
+       // ((JTextComponent.DropLocation)support.getDropLocation()).getBias();\r
+       //\r
+       // dropAction = support.getDropAction();\r
+       // }\r
+       //\r
+       // try {\r
+       // return super.importData(support);\r
+       // } finally {\r
+       // isDrop = false;\r
+       // modeBetween = false;\r
+       // dropBias = null;\r
+       // dropAction = MOVE;\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * This method causes a transfer to a component from a clipboard or a\r
+       // * DND drop operation. The Transferable represents the data to be\r
+       // * imported into the component.\r
+       // *\r
+       // * @param comp The component to receive the transfer. This\r
+       // * argument is provided to enable sharing of TransferHandlers by\r
+       // * multiple components.\r
+       // * @param t The data to import\r
+       // * @return true if the data was inserted into the component, false\r
+       // otherwise.\r
+       // */\r
+       // public boolean importData(JComponent comp, Transferable t) {\r
+       // JTextComponent c = (JTextComponent)comp;\r
+       //\r
+       // int pos = modeBetween\r
+       // ? ((JTextComponent.DropLocation)c.getDropLocation()).getIndex()\r
+       // : c.getCaretPosition();\r
+       //\r
+       // // if we are importing to the same component that we exported from\r
+       // // then don't actually do anything if the drop location is inside\r
+       // // the drag location and set shouldRemove to false so that exportDone\r
+       // // knows not to remove any data\r
+       // if (dropAction == MOVE && c == exportComp && pos >= p0 && pos <= p1) {\r
+       // shouldRemove = false;\r
+       // return true;\r
+       // }\r
+       //\r
+       // boolean imported = false;\r
+       // DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);\r
+       // if (importFlavor != null) {\r
+       // try {\r
+       // boolean useRead = false;\r
+       // if (comp instanceof JEditorPane) {\r
+       // JEditorPane ep = (JEditorPane)comp;\r
+       // if (!ep.getContentType().startsWith("text/plain") &&\r
+       // importFlavor.getMimeType().startsWith(ep.getContentType())) {\r
+       // useRead = true;\r
+       // }\r
+       // }\r
+       // InputContext ic = c.getInputContext();\r
+       // if (ic != null) {\r
+       // ic.endComposition();\r
+       // }\r
+       // Reader r = importFlavor.getReaderForText(t);\r
+       //\r
+       // if (modeBetween) {\r
+       // Caret caret = c.getCaret();\r
+       // if (caret instanceof DefaultCaret) {\r
+       // ((DefaultCaret)caret).setDot(pos, dropBias);\r
+       // } else {\r
+       // c.setCaretPosition(pos);\r
+       // }\r
+       // }\r
+       //\r
+       // handleReaderImport(r, c, useRead);\r
+       //\r
+       // if (isDrop) {\r
+       // c.requestFocus();\r
+       // Caret caret = c.getCaret();\r
+       // if (caret instanceof DefaultCaret) {\r
+       // int newPos = caret.getDot();\r
+       // Position.Bias newBias = ((DefaultCaret)caret).getDotBias();\r
+       //\r
+       // ((DefaultCaret)caret).setDot(pos, dropBias);\r
+       // ((DefaultCaret)caret).moveDot(newPos, newBias);\r
+       // } else {\r
+       // c.select(pos, c.getCaretPosition());\r
+       // }\r
+       // }\r
+       //\r
+       // imported = true;\r
+       // } catch (UnsupportedFlavorException ufe) {\r
+       // } catch (BadLocationException ble) {\r
+       // } catch (IOException ioe) {\r
+       // }\r
+       // }\r
+       // return imported;\r
+       // }\r
+       //\r
+       // /**\r
+       // * This method indicates if a component would accept an import of the given\r
+       // * set of data flavors prior to actually attempting to import it.\r
+       // *\r
+       // * @param comp The component to receive the transfer. This\r
+       // * argument is provided to enable sharing of TransferHandlers by\r
+       // * multiple components.\r
+       // * @param flavors The data formats available\r
+       // * @return true if the data can be inserted into the component, false\r
+       // otherwise.\r
+       // */\r
+       // public boolean canImport(JComponent comp, DataFlavor[] flavors) {\r
+       // JTextComponent c = (JTextComponent)comp;\r
+       // if (!(c.isEditable() && c.isEnabled())) {\r
+       // return false;\r
+       // }\r
+       // return (getImportFlavor(flavors, c) != null);\r
+       // }\r
+       //\r
+       // /**\r
+       // * A possible implementation of the Transferable interface\r
+       // * for text components. For a JEditorPane with a rich set\r
+       // * of EditorKit implementations, conversions could be made\r
+       // * giving a wider set of formats. This is implemented to\r
+       // * offer up only the active content type and text/plain\r
+       // * (if that is not the active format) since that can be\r
+       // * extracted from other formats.\r
+       // */\r
+       // static class TextTransferable extends BasicTransferable {\r
+       //\r
+       // TextTransferable(JTextComponent c, int start, int end) {\r
+       // super(null, null);\r
+       //\r
+       // this.c = c;\r
+       //\r
+       // Document doc = c.getDocument();\r
+       //\r
+       // try {\r
+       // p0 = doc.createPosition(start);\r
+       // p1 = doc.createPosition(end);\r
+       //\r
+       // plainData = c.getSelectedText();\r
+       //\r
+       // if (c instanceof JEditorPane) {\r
+       // JEditorPane ep = (JEditorPane)c;\r
+       //\r
+       // mimeType = ep.getContentType();\r
+       //\r
+       // if (mimeType.startsWith("text/plain")) {\r
+       // return;\r
+       // }\r
+       //\r
+       // StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());\r
+       // ep.getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() -\r
+       // p0.getOffset());\r
+       //\r
+       // if (mimeType.startsWith("text/html")) {\r
+       // htmlData = sw.toString();\r
+       // } else {\r
+       // richText = sw.toString();\r
+       // }\r
+       // }\r
+       // } catch (BadLocationException ble) {\r
+       // } catch (IOException ioe) {\r
+       // }\r
+       // }\r
+       //\r
+       // void removeText() {\r
+       // if ((p0 != null) && (p1 != null) && (p0.getOffset() != p1.getOffset())) {\r
+       // try {\r
+       // Document doc = c.getDocument();\r
+       // doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());\r
+       // } catch (BadLocationException e) {\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       // // ---- EditorKit other than plain or HTML text -----------------------\r
+       //\r
+       // /**\r
+       // * If the EditorKit is not for text/plain or text/html, that format\r
+       // * is supported through the "richer flavors" part of BasicTransferable.\r
+       // */\r
+       // protected DataFlavor[] getRicherFlavors() {\r
+       // if (richText == null) {\r
+       // return null;\r
+       // }\r
+       //\r
+       // try {\r
+       // DataFlavor[] flavors = new DataFlavor[3];\r
+       // flavors[0] = new DataFlavor(mimeType + ";class=java.lang.String");\r
+       // flavors[1] = new DataFlavor(mimeType + ";class=java.io.Reader");\r
+       // flavors[2] = new DataFlavor(mimeType +\r
+       // ";class=java.io.InputStream;charset=unicode");\r
+       // return flavors;\r
+       // } catch (ClassNotFoundException cle) {\r
+       // // fall through to unsupported (should not happen)\r
+       // }\r
+       //\r
+       // return null;\r
+       // }\r
+       //\r
+       // /**\r
+       // * The only richer format supported is the file list flavor\r
+       // */\r
+       // protected Object getRicherData(DataFlavor flavor) throws\r
+       // UnsupportedFlavorException {\r
+       // if (richText == null) {\r
+       // return null;\r
+       // }\r
+       //\r
+       // if (String.class.equals(flavor.getRepresentationClass())) {\r
+       // return richText;\r
+       // } else if (Reader.class.equals(flavor.getRepresentationClass())) {\r
+       // return new StringReader(richText);\r
+       // } else if (InputStream.class.equals(flavor.getRepresentationClass())) {\r
+       // return new StringBufferInputStream(richText);\r
+       // }\r
+       // throw new UnsupportedFlavorException(flavor);\r
+       // }\r
+       //\r
+       // Position p0;\r
+       // Position p1;\r
+       // String mimeType;\r
+       // String richText;\r
+       // JTextComponent c;\r
+       // }\r
+       //\r
+       // }\r
+\r
+       // /**\r
+       // * Creates a new UI.\r
+       // */\r
+       // public JSTextUI() {\r
+       // // painted = false;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Creates the object to use for a caret. By default an\r
+       // * instance of BasicCaret is created. This method\r
+       // * can be redefined to provide something else that implements\r
+       // * the InputPosition interface or a subclass of JCaret.\r
+       // *\r
+       // * @return the caret object\r
+       // */\r
+       // protected Caret createCaret() {\r
+       // return new BasicCaret();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Creates the object to use for adding highlights. By default\r
+       // * an instance of BasicHighlighter is created. This method\r
+       // * can be redefined to provide something else that implements\r
+       // * the Highlighter interface or a subclass of DefaultHighlighter.\r
+       // *\r
+       // * @return the highlighter\r
+       // */\r
+       // protected Highlighter createHighlighter() {\r
+       // return new BasicHighlighter();\r
+       // }\r
+       //\r
+       // /**\r
+       // * Fetches the name of the keymap that will be installed/used\r
+       // * by default for this UI. This is implemented to create a\r
+       // * name based upon the classname. The name is the the name\r
+       // * of the class with the package prefix removed.\r
+       // *\r
+       // * @return the name\r
+       // */\r
+       // protected String getKeymapName() {\r
+       // String nm = getClass().getName();\r
+       // int index = nm.lastIndexOf('.');\r
+       // if (index >= 0) {\r
+       // nm = nm.substring(index+1, nm.length());\r
+       // }\r
+       // return nm;\r
+       // }\r
+       //\r
+       // /**\r
+       // * Creates the keymap to use for the text component, and installs\r
+       // * any necessary bindings into it. By default, the keymap is\r
+       // * shared between all instances of this type of TextUI. The\r
+       // * keymap has the name defined by the getKeymapName method. If the\r
+       // * keymap is not found, then DEFAULT_KEYMAP from JTextComponent is used.\r
+       // * <p>\r
+       // * The set of bindings used to create the keymap is fetched\r
+       // * from the UIManager using a key formed by combining the\r
+       // * {@link #getPropertyPrefix} method\r
+       // * and the string <code>.keyBindings</code>. The type is expected\r
+       // * to be <code>JTextComponent.KeyBinding[]</code>.\r
+       // *\r
+       // * @return the keymap\r
+       // * @see #getKeymapName\r
+       // * @see jsjavax.swing.text.JTextComponent\r
+       // */\r
+       // protected Keymap createKeymap() {\r
+       // String nm = getKeymapName();\r
+       // Keymap map = JTextComponent.getKeymap(nm);\r
+       // if (map == null) {\r
+       // Keymap parent = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);\r
+       // map = JTextComponent.addKeymap(nm, parent);\r
+       // String prefix = getPropertyPrefix();\r
+       // Object o = DefaultLookup.get(editor, this,\r
+       // prefix + ".keyBindings");\r
+       // if ((o != null) && (o instanceof JTextComponent.KeyBinding[])) {\r
+       // JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) o;\r
+       // JTextComponent.loadKeymap(map, bindings, getComponent().getActions());\r
+       // }\r
+       // }\r
+       // return map;\r
+       // }\r
+       //\r
+       // /**\r
+       // * This method gets called when a bound property is changed\r
+       // * on the associated JTextComponent. This is a hook\r
+       // * which UI implementations may change to reflect how the\r
+       // * UI displays bound properties of JTextComponent subclasses.\r
+       // * This is implemented to do nothing (i.e. the response to\r
+       // * properties in JTextComponent itself are handled prior\r
+       // * to calling this method).\r
+       // *\r
+       // * This implementation updates the background of the text\r
+       // * component if the editable and/or enabled state changes.\r
+       // *\r
+       // * @param evt the property change event\r
+       // */\r
+       // protected void propertyChange(PropertyChangeEvent evt) {\r
+       // if (evt.getPropertyName().equals("editable") ||\r
+       // evt.getPropertyName().equals("enabled")) {\r
+       //\r
+       // updateBackground((JTextComponent)evt.getSource());\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Updates the background of the text component based on whether the\r
+       // * text component is editable and/or enabled.\r
+       // *\r
+       // * @param c the JTextComponent that needs its background color updated\r
+       // */\r
+       // private void updateBackground(JTextComponent c) {\r
+       // // This is a temporary workaround.\r
+       // // This code does not correctly deal with Synth (Synth doesn't use\r
+       // // properties like this), nor does it deal with the situation where\r
+       // // the developer grabs the color from a JLabel and sets it as\r
+       // // the background for a JTextArea in all look and feels. The problem\r
+       // // scenario results if the Color obtained for the Label and TextArea\r
+       // // is ==, which is the case for the windows look and feel.\r
+       // // Until an appropriate solution is found, the code is being\r
+       // // reverted to what it was before the original fix.\r
+       // if (this instanceof sun.swing.plaf.synth.SynthUI ||\r
+       // (c instanceof JTextArea)) {\r
+       // return;\r
+       // }\r
+       // Color background = c.getBackground();\r
+       // if (background instanceof UIResource) {\r
+       // String prefix = getPropertyPrefix();\r
+       //\r
+       // Color disabledBG =\r
+       // DefaultLookup.getColor(c, this, prefix + ".disabledBackground", null);\r
+       // Color inactiveBG =\r
+       // DefaultLookup.getColor(c, this, prefix + ".inactiveBackground", null);\r
+       // Color bg =\r
+       // DefaultLookup.getColor(c, this, prefix + ".background", null);\r
+       //\r
+       // /* In an ideal situation, the following check would not be necessary\r
+       // * and we would replace the color any time the previous color was a\r
+       // * UIResouce. However, it turns out that there is existing code that\r
+       // * uses the following inadvisable pattern to turn a text area into\r
+       // * what appears to be a multi-line label:\r
+       // *\r
+       // * JLabel label = new JLabel();\r
+       // * JTextArea area = new JTextArea();\r
+       // * area.setBackground(label.getBackground());\r
+       // * area.setEditable(false);\r
+       // *\r
+       // * JLabel's default background is a UIResource. As such, just\r
+       // * checking for UIResource would have us always changing the\r
+       // * background away from what the developer wanted.\r
+       // *\r
+       // * Therefore, for JTextArea/JEditorPane, we'll additionally check\r
+       // * that the color we're about to replace matches one that was\r
+       // * installed by us from the UIDefaults.\r
+       // */\r
+       // if ((c instanceof JTextArea || c instanceof JEditorPane)\r
+       // && background != disabledBG\r
+       // && background != inactiveBG\r
+       // && background != bg) {\r
+       //\r
+       // return;\r
+       // }\r
+       //\r
+       // Color newColor = null;\r
+       // if (!c.isEnabled()) {\r
+       // newColor = disabledBG;\r
+       // }\r
+       // if (newColor == null && !c.isEditable()) {\r
+       // newColor = inactiveBG;\r
+       // }\r
+       // if (newColor == null) {\r
+       // newColor = bg;\r
+       // }\r
+       // if (newColor != null && newColor != background) {\r
+       // c.setBackground(newColor);\r
+       // }\r
+       // }\r
+       // }\r
+       //\r
+       // /**\r
+       // * Gets the name used as a key to look up properties through the\r
+       // * UIManager. This is used as a prefix to all the standard\r
+       // * text properties.\r
+       // *\r
+       // * @return the name\r
+       // */\r
+       // protected abstract String getPropertyPrefix();\r
+\r
+}\r