3261N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Basis of a text components look-and-feel. This provides the 0N/A * basic editor view and controller services that may be useful 0N/A * when creating a look-and-feel for an extension of 0N/A * <code>JTextComponent</code>. 0N/A * Most state is held in the associated <code>JTextComponent</code> 0N/A * as bound properties, and the UI installs default values for the 0N/A * various properties. This default will install something for 0N/A * all of the properties. Typically, a LAF implementation will 0N/A * do more however. At a minimum, a LAF would generally install 0N/A * This class also provides some concurrency support if the 0N/A * <code>Document</code> associated with the JTextComponent is a subclass of 0N/A * <code>AbstractDocument</code>. Access to the View (or View hierarchy) is 0N/A * serialized between any thread mutating the model and the Swing 0N/A * event thread (which is expected to render, do model/view coordinate 0N/A * translation, etc). <em>Any access to the root view should first 0N/A * acquire a read-lock on the AbstractDocument and release that lock 0N/A * in a finally block.</em> 0N/A * An important method to define is the {@link #getPropertyPrefix} method 0N/A * which is used as the basis of the keys used to fetch defaults 0N/A * from the UIManager. The string should reflect the type of 0N/A * TextUI (eg. TextField, TextArea, etc) without the particular 0N/A * LAF part of the name (eg Metal, Motif, etc). 0N/A * To build a view of the model, one of the following strategies 0N/A * One strategy is to simply redefine the 0N/A * ViewFactory interface in the UI. By default, this UI itself acts 0N/A * as the factory for View implementations. This is useful 0N/A * for simple factories. To do this reimplement the 0N/A * {@link #create} method. 0N/A * A common strategy for creating more complex types of documents 0N/A * is to have the EditorKit implementation return a factory. Since 0N/A * the EditorKit ties all of the pieces necessary to maintain a type 0N/A * of document, the factory is typically an important part of that 0N/A * and should be produced by the EditorKit implementation. 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * @author Timothy Prinzing 0N/A * @author Shannon Hickey (drag and drop) 0N/A * Creates the object to use for a caret. By default an 0N/A * instance of BasicCaret is created. This method 0N/A * can be redefined to provide something else that implements 0N/A * the InputPosition interface or a subclass of JCaret. 0N/A * @return the caret object 0N/A * Creates the object to use for adding highlights. By default 0N/A * an instance of BasicHighlighter is created. This method 0N/A * can be redefined to provide something else that implements 0N/A * the Highlighter interface or a subclass of DefaultHighlighter. 0N/A * @return the highlighter 0N/A * by default for this UI. This is implemented to create a 0N/A * name based upon the classname. The name is the the name 0N/A * of the class with the package prefix removed. 0N/A * Creates the keymap to use for the text component, and installs 0N/A * any necessary bindings into it. By default, the keymap is 0N/A * shared between all instances of this type of TextUI. The 0N/A * keymap has the name defined by the getKeymapName method. If the 0N/A * keymap is not found, then DEFAULT_KEYMAP from JTextComponent is used. 0N/A * The set of bindings used to create the keymap is fetched 0N/A * from the UIManager using a key formed by combining the 0N/A * {@link #getPropertyPrefix} method 0N/A * and the string <code>.keyBindings</code>. The type is expected 0N/A * to be <code>JTextComponent.KeyBinding[]</code>. 0N/A * @return the keymap 0N/A * @see #getKeymapName 0N/A * @see javax.swing.text.JTextComponent 0N/A * This method gets called when a bound property is changed 0N/A * on the associated JTextComponent. This is a hook 0N/A * which UI implementations may change to reflect how the 0N/A * UI displays bound properties of JTextComponent subclasses. 0N/A * This is implemented to do nothing (i.e. the response to 0N/A * properties in JTextComponent itself are handled prior 0N/A * to calling this method). 0N/A * This implementation updates the background of the text 0N/A * component if the editable and/or enabled state changes. 0N/A * @param evt the property change event 0N/A * Updates the background of the text component based on whether the 0N/A * text component is editable and/or enabled. 0N/A * @param c the JTextComponent that needs its background color updated 0N/A // This is a temporary workaround. 0N/A // This code does not correctly deal with Synth (Synth doesn't use 0N/A // properties like this), nor does it deal with the situation where 0N/A // the developer grabs the color from a JLabel and sets it as 0N/A // the background for a JTextArea in all look and feels. The problem 0N/A // scenario results if the Color obtained for the Label and TextArea 0N/A // is ==, which is the case for the windows look and feel. 0N/A // Until an appropriate solution is found, the code is being 0N/A // reverted to what it was before the original fix. 0N/A /* In an ideal situation, the following check would not be necessary 0N/A * and we would replace the color any time the previous color was a 0N/A * UIResouce. However, it turns out that there is existing code that 0N/A * uses the following inadvisable pattern to turn a text area into 0N/A * what appears to be a multi-line label: 0N/A * JLabel label = new JLabel(); 0N/A * JTextArea area = new JTextArea(); 0N/A * area.setBackground(label.getBackground()); 0N/A * area.setEditable(false); 0N/A * JLabel's default background is a UIResource. As such, just 0N/A * checking for UIResource would have us always changing the 0N/A * background away from what the developer wanted. 0N/A * that the color we're about to replace matches one that was 0N/A * installed by us from the UIDefaults. 0N/A * Gets the name used as a key to look up properties through the 0N/A * UIManager. This is used as a prefix to all the standard 1999N/A * Initializes component properties, such as font, foreground, 0N/A * background, caret color, selection color, selected text color, 0N/A * disabled text color, and border color. The font, foreground, and 0N/A * background properties are only set if their current value is either null 0N/A * or a UIResource, other properties are set if the current 0N/A * @see #uninstallDefaults 1999N/A * Sets the component properties that have not been explicitly overridden 1999N/A * to {@code null}. A property is considered overridden if its current 1999N/A * value is not a {@code UIResource}. 0N/A * @see #installDefaults 0N/A * Installs listeners for the UI. 0N/A * Uninstalls listeners for the UI. 0N/A // backward compatibility support... keymaps for the UI 0N/A // are now installed in the more friendly input map. 0N/A * Get the InputMap to use for the UI. 0N/A * Invoked when the focus accelerator changes, this will update the 0N/A * key bindings as necessary. 0N/A * Invoked when editable property is changed. 0N/A * removing 'TAB' and 'SHIFT-TAB' from traversalKeysSet in case 0N/A * editor is editable 0N/A * adding 'TAB' and 'SHIFT-TAB' to traversalKeysSet in case 0N/A * editor is non editable 0N/A * Fix for 4514331 Non-editable JTextArea and similar 0N/A * should allow Tab to keyboard - accessibility 0N/A "focusTraversalKeysForward",
0N/A "focusTraversalKeysBackward",
0N/A * As needed updates cursor for the target editor. 0N/A * Returns the <code>TransferHandler</code> that will be installed if 0N/A * their isn't one installed on the <code>JTextComponent</code>. 0N/A * Fetch an action map to use. 0N/A * fix for bug 4515750 0N/A * JTextField & non-editable JTextArea bind return key - default btn not accessible 0N/A * Wrap the return action so that it is only enabled when the 0N/A * component is editable. This allows the default button to be 0N/A * processed when the text component has focus and isn't editable. 0N/A * Create a default action map. This is basically the 0N/A * set of actions found exported by the component. 0N/A //System.out.println("building map for UI: " + getPropertyPrefix()); 0N/A for (
int i =
0; i < n; i++) {
0N/A //System.out.println(" " + a.getValue(Action.NAME)); 0N/A * Paints a background for the view. This will only be 0N/A * called if isOpaque() on the associated component is 0N/A * true. The default is to paint the background color 0N/A * @param g the graphics context 0N/A * Fetches the text component associated with this 0N/A * UI implementation. This will be null until 0N/A * the ui has been installed. 0N/A * @return the editor component 0N/A * Flags model changes. 0N/A * This is called whenever the model has changed. 0N/A * It is implemented to rebuild the view hierarchy 0N/A * to represent the default root element of the 0N/A // create a view hierarchy 0N/A * Sets the current root of the view hierarchy and calls invalidate(). 0N/A * If there were any child components, they will be removed (i.e. 0N/A * there are assumed to have come from components embedded in views). 0N/A * @param v the root view 0N/A * Paints the interface safely with a guarantee that 0N/A * the model won't change from the view of this thread. 0N/A * This does the following things, rendering from 0N/A * If the component is marked as opaque, the background 0N/A * is painted in the current background color of the 0N/A * The highlights (if any) are painted. 0N/A * The view hierarchy is painted. 0N/A * The caret is painted. 0N/A * @param g the graphics context 0N/A // paint the background 0N/A // paint the highlights 0N/A // paint the view hierarchy 0N/A // --- ComponentUI methods -------------------------------------------- 0N/A * Installs the UI for a component. This does the following 2294N/A * Sets the associated component to opaque if the opaque property 2294N/A * has not already been set by the client program. This will cause the 0N/A * component's background color to be painted. 1999N/A * Installs the default caret and highlighter into the 2215N/A * associated component. These properties are only set if their 2215N/A * current value is either {@code null} or an instance of 1999N/A * Attaches to the editor and model. If there is no 0N/A * model, a default one is created. 1999N/A * Creates the view factory and the view hierarchy used 0N/A * to represent the model. 0N/A * @param c the editor component 0N/A * @see ComponentUI#installUI 2385N/A // common case is background painted... this can 2385N/A // easily be changed by subclasses or from outside 0N/A // attach to the model and editor 0N/A // no model, create a default one. This will 0N/A // fire a notification to the updateHandler 0N/A // which takes care of the rest. 0N/A // by default, use default LayoutManger implementation that 0N/A // will position the components associated with a View object. 0N/A throw new Error(
"TextUI needs JTextComponent");
0N/A * Deinstalls the UI for a component. This removes the listeners, 0N/A * uninstalls the highlighter, removes views, and nulls out the keymap. 0N/A * @param c the editor component 0N/A * @see ComponentUI#uninstallUI 0N/A // detach from the model 0N/A * Superclass paints background in an uncontrollable way 0N/A * (i.e. one might want an image tiled into the background). 0N/A * To prevent this from happening twice, this method is 0N/A * reimplemented to simply paint. 1999N/A * <em>NOTE:</em> NOTE: Superclass is also not thread-safe in its 1999N/A * rendering of the background, although that is not an issue with the 0N/A * Paints the interface. This is routed to the 0N/A * paintSafely method under the guarantee that 0N/A * the model won't change from the view of this thread 0N/A * while it's rendering (if the associated model is 0N/A * derived from AbstractDocument). This enables the 0N/A * model to potentially be updated asynchronously. 0N/A * @param g the graphics context 0N/A * @param c the editor component 0N/A * Gets the preferred size for the editor component. If the component 0N/A * has been given a size prior to receiving this request, it will 0N/A * set the size of the view hierarchy to reflect the size of the component 0N/A * before requesting the preferred size of the view hierarchy. This 0N/A * allows formatted views to format to the current component size before 0N/A * answering the request. Other views don't care about currently formatted 0N/A * size and give the same answer either way. 0N/A * @param c the editor component 0N/A // Probably haven't been layed out yet, force some sort of 0N/A * Gets the minimum size for the editor component. 0N/A * @param c the editor component 0N/A * Gets the maximum size for the editor component. 0N/A * @param c the editor component 0N/A // ---- TextUI methods ------------------------------------------- 0N/A * Gets the allocation to give the root View. Due 0N/A * to an unfortunate set of historical events this 0N/A * method is inappropriately named. The Rectangle 0N/A * returned has nothing to do with visibility. 0N/A * The component must have a non-zero positive size for 0N/A * this translation to be computed. 0N/A * @return the bounding box for the root view 0N/A * Converts the given location in the model to a place in 0N/A * the view coordinate system. 0N/A * The component must have a non-zero positive size for 0N/A * this translation to be computed. 0N/A * @param tc the text component for which this UI is installed 0N/A * @param pos the local location in the model to translate >= 0 0N/A * @return the coordinates as a rectangle, null if the model is not painted 0N/A * @exception BadLocationException if the given position does not 0N/A * represent a valid location in the associated document 0N/A * @see TextUI#modelToView 0N/A * Converts the given location in the model to a place in 0N/A * the view coordinate system. 0N/A * The component must have a non-zero positive size for 0N/A * this translation to be computed. 0N/A * @param tc the text component for which this UI is installed 0N/A * @param pos the local location in the model to translate >= 0 0N/A * @return the coordinates as a rectangle, null if the model is not painted 0N/A * @exception BadLocationException if the given position does not 0N/A * represent a valid location in the associated document 0N/A * @see TextUI#modelToView 0N/A * Converts the given place in the view coordinate system 0N/A * to the nearest representative location in the model. 0N/A * The component must have a non-zero positive size for 0N/A * this translation to be computed. 0N/A * @param tc the text component for which this UI is installed 0N/A * @param pt the location in the view to translate. This 0N/A * should be in the same coordinate system as the mouse events. 0N/A * @return the offset from the start of the document >= 0, 0N/A * @see TextUI#viewToModel 0N/A * Converts the given place in the view coordinate system 0N/A * to the nearest representative location in the model. 0N/A * The component must have a non-zero positive size for 0N/A * this translation to be computed. 0N/A * @param tc the text component for which this UI is installed 0N/A * @param pt the location in the view to translate. This 0N/A * should be in the same coordinate system as the mouse events. 0N/A * @return the offset from the start of the document >= 0, 0N/A * -1 if the component doesn't yet have a positive size. 0N/A * @see TextUI#viewToModel 0N/A * Causes the portion of the view responsible for the 0N/A * given part of the model to be repainted. Does nothing if 0N/A * the view is not currently painted. 0N/A * @param tc the text component for which this UI is installed 0N/A * @param p0 the beginning of the range >= 0 0N/A * @param p1 the end of the range >= p0 0N/A * @see TextUI#damageRange 0N/A * Causes the portion of the view responsible for the 0N/A * given part of the model to be repainted. 0N/A * @param p0 the beginning of the range >= 0 0N/A * @param p1 the end of the range >= p0 0N/A * Fetches the EditorKit for the UI. 0N/A * @param tc the text component for which this UI is installed 0N/A * @return the editor capabilities 0N/A * @see TextUI#getEditorKit 0N/A * Fetches a View with the allocation of the associated 0N/A * text component (i.e. the root of the hierarchy) that 0N/A * can be traversed to determine how the model is being 0N/A * represented spatially. 0N/A * <font color=red><b>NOTE:</b>The View hierarchy can 0N/A * be traversed from the root view, and other things 0N/A * can be done as well. Things done in this way cannot 0N/A * be protected like simple method calls through the TextUI. 0N/A * Therefore, proper operation in the presence of concurrency 0N/A * must be arranged by any logic that calls this method! 0N/A * @param tc the text component for which this UI is installed 0N/A * @see TextUI#getRootView 0N/A * Returns the string to be used as the tooltip at the passed in location. 0N/A * This forwards the method onto the root View. 0N/A * @see javax.swing.text.JTextComponent#getToolTipText 0N/A * @see javax.swing.text.View#getToolTipText 0N/A // --- ViewFactory methods ------------------------------ 0N/A * Creates a view for an element. 0N/A * If a subclass wishes to directly implement the factory 0N/A * producing the view(s), it should reimplement this 0N/A * method. By default it simply returns null indicating 0N/A * it is unable to represent the element. 0N/A * @param elem the element 0N/A * Creates a view for an element. 0N/A * If a subclass wishes to directly implement the factory 0N/A * producing the view(s), it should reimplement this 0N/A * method. By default it simply returns null indicating 0N/A * it is unable to represent the part of the element. 0N/A * @param elem the element 0N/A * @param p0 the starting offset >= 0 0N/A * @param p1 the ending offset >= p0 0N/A // ----- member variables --------------------------------------- 0N/A * Root view that acts as a gateway between the component 0N/A * and the View hierarchy. 0N/A // get rid of back reference so that the old 0N/A // hierarchy can be garbage collected. 0N/A * Fetches the attributes to use when rendering. At the root 0N/A * level there are no attributes. If an attribute is resolved 0N/A * up the view hierarchy this is the end of the line. 0N/A * Determines the preferred span for this view along an axis. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @return the span the view would like to be rendered into. 0N/A * Typically the view is told to render into the span 0N/A * that is returned, although there is no guarantee. 0N/A * The parent may choose to resize or break the view. 0N/A * Determines the minimum span for this view along an axis. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @return the span the view would like to be rendered into. 0N/A * Typically the view is told to render into the span 0N/A * that is returned, although there is no guarantee. 0N/A * The parent may choose to resize or break the view. 0N/A * Determines the maximum span for this view along an axis. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @return the span the view would like to be rendered into. 0N/A * Typically the view is told to render into the span 0N/A * that is returned, although there is no guarantee. 0N/A * The parent may choose to resize or break the view. 0N/A * Specifies that a preference has changed. 0N/A * Child views can call this on the parent to indicate that 0N/A * the preference has changed. The root view routes this to 0N/A * invalidate on the hosting component. 0N/A * This can be called on a different thread from the 0N/A * event dispatching thread and is basically unsafe to 0N/A * propagate into the component. To make this safe, 0N/A * the operation is transferred over to the event dispatching 0N/A * thread for completion. It is a design goal that all view 0N/A * methods be safe to call without concern for concurrency, 0N/A * and this behavior helps make that true. 0N/A * @param child the child view 0N/A * @param width true if the width preference has changed 0N/A * @param height true if the height preference has changed 0N/A * Determines the desired alignment for this view along an axis. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @return the desired alignment, where 0.0 indicates the origin 0N/A * and 1.0 the full span away from the origin 0N/A * @param g the graphics context 0N/A * @param allocation the region to render into 0N/A * Sets the view parent. 0N/A * @param parent the parent view 0N/A throw new Error(
"Can't set parent on root view");
0N/A * Returns the number of views in this view. Since 0N/A * this view simply wraps the root of the view hierarchy 0N/A * it has exactly one child. 0N/A * @return the number of views 0N/A * Gets the n-th view in this container. 0N/A * @param n the number of the view to get 0N/A * Returns the child view index representing the given position in 0N/A * the model. This is implemented to return the index of the only 0N/A * @param pos the position >= 0 0N/A * @return index of the view representing the given position, or 0N/A * -1 if no view represents that position 0N/A * Fetches the allocation for the given child view. 0N/A * This enables finding out where various views 0N/A * are located, without assuming the views store 0N/A * their location. This returns the given allocation 0N/A * since this view simply acts as a gateway between 0N/A * the view hierarchy and the associated component. 0N/A * @param index the index of the child 0N/A * @param a the allocation to this view. 0N/A * @return the allocation to the child 0N/A * Provides a mapping from the document model coordinate space 0N/A * to the coordinate space of the view mapped to it. 0N/A * @param pos the position to convert 0N/A * @param a the allocated region to render into 0N/A * @return the bounding box of the given position 0N/A * Provides a mapping from the document model coordinate space 0N/A * to the coordinate space of the view mapped to it. 0N/A * @param p0 the position to convert >= 0 0N/A * @param b0 the bias toward the previous character or the 0N/A * next character represented by p0, in case the 0N/A * position is a boundary of two views. 0N/A * @param p1 the position to convert >= 0 0N/A * @param b1 the bias toward the previous character or the 0N/A * next character represented by p1, in case the 0N/A * position is a boundary of two views. 0N/A * @param a the allocated region to render into 0N/A * @return the bounding box of the given position is returned 0N/A * @exception BadLocationException if the given position does 0N/A * not represent a valid location in the associated document 0N/A * @exception IllegalArgumentException for an invalid bias argument 0N/A * @see View#viewToModel 0N/A * Provides a mapping from the view coordinate space to the logical 0N/A * coordinate space of the model. 0N/A * @param x x coordinate of the view location to convert 0N/A * @param y y coordinate of the view location to convert 0N/A * @param a the allocated region to render into 0N/A * @return the location within the model that best represents the 0N/A * given point in the view 0N/A * Provides a way to determine the next visually represented model 0N/A * location that one might place a caret. Some views may not be visible, 0N/A * they might not be in the same order found in the model, or they just 0N/A * might not allow access to some of the locations in the model. 0N/A * @param pos the position to convert >= 0 0N/A * @param a the allocated region to render into 0N/A * @param direction the direction from the current position that can 0N/A * be thought of as the arrow keys typically found on a keyboard. 0N/A * This may be SwingConstants.WEST, SwingConstants.EAST, 0N/A * SwingConstants.NORTH, or SwingConstants.SOUTH. 0N/A * @return the location within the model that best represents the next 0N/A * location visual position. 0N/A * @exception BadLocationException 0N/A * @exception IllegalArgumentException for an invalid direction 0N/A * Gives notification that something was inserted into the document 0N/A * in a location that this view is responsible for. 0N/A * @param e the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * Gives notification that something was removed from the document 0N/A * in a location that this view is responsible for. 0N/A * @param e the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * Gives notification from the document that attributes were changed 0N/A * in a location that this view is responsible for. 0N/A * @param e the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * Returns the document model underlying the view. 0N/A * Returns the starting offset into the model for this view. 0N/A * @return the starting offset 0N/A * Returns the ending offset into the model for this view. 0N/A * @return the ending offset 0N/A * Gets the element that this view is mapped to. 0N/A * Breaks this view on the given axis at the given length. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @param len specifies where a break is desired in the span 0N/A * @param the current allocation of the view 0N/A * @return the fragment of the view that represents the given span 0N/A * if the view can be broken, otherwise null 0N/A throw new Error(
"Can't break root view");
0N/A * Determines the resizability of the view along the 0N/A * given axis. A value of 0 or less is not resizable. 0N/A * @param axis may be either X_AXIS or Y_AXIS 0N/A * @return the weight 0N/A * Sets the view size. 0N/A * @param width the width 0N/A * @param height the height 0N/A * Fetches the container hosting the view. This is useful for 0N/A * things like scheduling a repaint, finding out the host 0N/A * components font, etc. The default implementation 0N/A * of this is to forward the query to the parent view. 0N/A * @return the container 0N/A * Fetches the factory to be used for building the 0N/A * various view fragments that make up the view that 0N/A * represents the model. This is what determines 0N/A * how the model will be represented. This is implemented 0N/A * to fetch the factory provided by the associated 0N/A * EditorKit unless that is null, in which case this 0N/A * simply returns the BasicTextUI itself which allows 0N/A * subclasses to implement a simple factory directly without 0N/A * creating extra objects. 0N/A * @return the factory 0N/A * Handles updates from various places. If the model is changed, 0N/A * this class unregisters as a listener to the old model and 0N/A * registers with the new model. If the document model changes, 0N/A * the change is forwarded to the root view. If the focus 0N/A * accelerator changes, a new keystroke is registered to request 0N/A // --- PropertyChangeListener methods ----------------------- 0N/A * This method gets called when a bound property is changed. 0N/A * We are looking for document changes on the editor. 0N/A // Changes in ComponentOrientation require the views to be 0N/A // --- DocumentListener methods ----------------------- 0N/A * The insert notification. Gets sent to the root of the view structure 0N/A * that represents the portion of the model being represented by the 0N/A * editor. The factory is added as an argument to the update so that 0N/A * the views can update themselves in a dynamic (not hardcoded) way. 0N/A * @param e The change notification from the currently associated 0N/A * @see DocumentListener#insertUpdate 0N/A // i18n flag changed, rebuild the view 0N/A // normal insert update 0N/A * The remove notification. Gets sent to the root of the view structure 0N/A * that represents the portion of the model being represented by the 0N/A * editor. The factory is added as an argument to the update so that 0N/A * the views can update themselves in a dynamic (not hardcoded) way. 0N/A * @param e The change notification from the currently associated 0N/A * @see DocumentListener#removeUpdate 0N/A * The change notification. Gets sent to the root of the view structure 0N/A * that represents the portion of the model being represented by the 0N/A * editor. The factory is added as an argument to the update so that 0N/A * the views can update themselves in a dynamic (not hardcoded) way. 0N/A * @param e The change notification from the currently associated 614N/A * @see DocumentListener#changedUpdate(DocumentEvent) 0N/A // --- LayoutManager2 methods -------------------------------- 0N/A * Adds the specified component with the specified name to 0N/A * @param name the component name 0N/A * @param comp the component to be added 0N/A * Removes the specified component from the layout. 0N/A * @param comp the component to be removed 0N/A // remove the constraint record 0N/A * Calculates the preferred size dimensions for the specified 0N/A * panel given the components in the specified parent container. 0N/A * @param parent the component to be laid out 0N/A * @see #minimumLayoutSize 0N/A // should not be called (JComponent uses UI instead) 0N/A * Calculates the minimum size dimensions for the specified 0N/A * panel given the components in the specified parent container. 0N/A * @param parent the component to be laid out 0N/A * @see #preferredLayoutSize 0N/A // should not be called (JComponent uses UI instead) 0N/A * Lays out the container in the specified panel. This is 0N/A * implemented to position all components that were added 0N/A * with a View object as a constraint. The current allocation 0N/A * of the associated View is used as the location of the 0N/A * A read-lock is acquired on the document to prevent the 0N/A * view tree from being modified while the layout process 0N/A * @param parent the component which needs to be laid out 0N/A * Find the Shape representing the given view. 0N/A * Adds the specified component to the layout, using the specified 0N/A * constraint object. We only store those components that were added 0N/A * with a constraint that is of type View. 0N/A * @param comp the component to be added 0N/A * @param constraint where/how the component is added to the layout. 0N/A * Returns the maximum size of this component. 0N/A * @see java.awt.Component#getMinimumSize() 0N/A * @see java.awt.Component#getPreferredSize() 0N/A * @see LayoutManager 0N/A // should not be called (JComponent uses UI instead) 0N/A * Returns the alignment along the x axis. This specifies how 0N/A * the component would like to be aligned relative to other 0N/A * components. The value should be a number between 0 and 1 0N/A * where 0 represents alignment along the origin, 1 is aligned 0N/A * the furthest away from the origin, 0.5 is centered, etc. 0N/A * Returns the alignment along the y axis. This specifies how 0N/A * the component would like to be aligned relative to other 0N/A * components. The value should be a number between 0 and 1 0N/A * where 0 represents alignment along the origin, 1 is aligned 0N/A * the furthest away from the origin, 0.5 is centered, etc. 0N/A * Invalidates the layout, indicating that if the layout manager 0N/A * has cached information it should be discarded. 0N/A * The "layout constraints" for the LayoutManager2 implementation. 0N/A * These are View objects for those components that are represented 0N/A * by a View in the View tree. 0N/A * Wrapper for text actions to return isEnabled false in case editor is non editable 0N/A * The operation to perform when this action is triggered. 0N/A * @param e the action event 0N/A * Registered in the ActionMap. 0N/A * Listens for mouse events for the purposes of detecting drag gestures. 0N/A * BasicTextUI will maintain one of these per AppContext. 0N/A * Determines if the following are true: 0N/A * <li>the component is enabled 0N/A * <li>the press event is located over a selection 0N/A * Whether or not this is a drop using 0N/A * <code>DropMode.INSERT</code>. 0N/A * Whether or not this is a drop. 0N/A * Try to find a flavor that can be used to import a Transferable. 0N/A * The set of usable flavors are tried in the following order: 0N/A * <li>First, an attempt is made to find a flavor matching the content type 0N/A * of the EditorKit for the component. 0N/A * <li>Second, an attempt to find a text/plain flavor is made. 0N/A * <li>Third, an attempt to find a flavor representing a String reference 0N/A * in the same VM is made. 0N/A * <li>Lastly, DataFlavor.stringFlavor is searched for. 0N/A * Import the given stream data into the text component. 0N/A // Read in a block at a time, mapping \r\n to \n, as well as single 0N/A // else nothing to do, can skip \r, next write will 0N/A // --- TransferHandler methods ------------------------------------ 0N/A * This is the type of transfer actions supported by the source. Some models are 0N/A * not mutable, so a transfer operation of COPY only should 0N/A * be advertised in that case. 0N/A * @param c The component holding the data to be transfered. This 0N/A * argument is provided to enable sharing of TransferHandlers by 0N/A * multiple components. 0N/A * @return This is implemented to return NONE if the component is a JPasswordField 0N/A * since exporting data via user gestures is not allowed. If the text component is 0N/A * editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed. 0N/A * Create a Transferable to use as the source for a data transfer. 0N/A * @param comp The component holding the data to be transfered. This 0N/A * argument is provided to enable sharing of TransferHandlers by 0N/A * multiple components. 0N/A * @return The representation of the data to be transfered. 0N/A * This method is called after data has been exported. This method should remove 0N/A * the data that was transfered if the action was MOVE. 0N/A * @param source The component that was the source of the data. 0N/A * @param data The data that was transferred or possibly null 0N/A * if the action is <code>NONE</code>. 0N/A * @param action The actual action that was performed. 0N/A // only remove the text if shouldRemove has not been set to 0N/A // false by importData and only if the action is a move 0N/A * This method causes a transfer to a component from a clipboard or a 0N/A * DND drop operation. The Transferable represents the data to be 0N/A * imported into the component. 0N/A * @param comp The component to receive the transfer. This 0N/A * argument is provided to enable sharing of TransferHandlers by 0N/A * multiple components. 0N/A * @param t The data to import 0N/A * @return true if the data was inserted into the component, false otherwise. 0N/A // if we are importing to the same component that we exported from 0N/A // then don't actually do anything if the drop location is inside 0N/A // the drag location and set shouldRemove to false so that exportDone 0N/A // knows not to remove any data 0N/A * This method indicates if a component would accept an import of the given 0N/A * set of data flavors prior to actually attempting to import it. 0N/A * @param comp The component to receive the transfer. This 0N/A * argument is provided to enable sharing of TransferHandlers by 0N/A * multiple components. 0N/A * @param flavors The data formats available 0N/A * @return true if the data can be inserted into the component, false otherwise. 0N/A * A possible implementation of the Transferable interface 0N/A * for text components. For a JEditorPane with a rich set 0N/A * of EditorKit implementations, conversions could be made 0N/A * giving a wider set of formats. This is implemented to 0N/A * (if that is not the active format) since that can be 0N/A * extracted from other formats. 0N/A // ---- EditorKit other than plain or HTML text ----------------------- 0N/A * is supported through the "richer flavors" part of BasicTransferable. 0N/A // fall through to unsupported (should not happen) 0N/A * The only richer format supported is the file list flavor