< prev index next >

src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java

Print this page

        

*** 32,58 **** import java.awt.*; import java.awt.event.*; import java.util.EventObject; /** ! * A <code>TreeCellEditor</code>. You need to supply an ! * instance of <code>DefaultTreeCellRenderer</code> * so that the icons can be obtained. You can optionally supply ! * a <code>TreeCellEditor</code> that will be layed out according ! * to the icon in the <code>DefaultTreeCellRenderer</code>. ! * If you do not supply a <code>TreeCellEditor</code>, ! * a <code>TextField</code> will be used. Editing is started * on a triple mouse click, or after a click, pause, click and * a delay of 1200 milliseconds. *<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&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.JTree * * @author Scott Violet --- 32,58 ---- import java.awt.*; import java.awt.event.*; import java.util.EventObject; /** ! * A {@code TreeCellEditor}. You need to supply an ! * instance of {@code DefaultTreeCellRenderer} * so that the icons can be obtained. You can optionally supply ! * a {@code TreeCellEditor} that will be layed out according ! * to the icon in the {@code DefaultTreeCellRenderer}. ! * If you do not supply a {@code TreeCellEditor}, ! * a {@code TextField} will be used. Editing is started * on a triple mouse click, or after a click, pause, click and * a delay of 1200 milliseconds. *<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&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.JTree * * @author Scott Violet
*** 63,144 **** protected TreeCellEditor realEditor; /** Renderer, used to get border and offsets from. */ protected DefaultTreeCellRenderer renderer; ! /** Editing container, will contain the <code>editorComponent</code>. */ protected Container editingContainer; /** * Component used in editing, obtained from the ! * <code>editingContainer</code>. */ protected transient Component editingComponent; /** * As of Java 2 platform v1.4 this field should no longer be used. If * you wish to provide similar behavior you should directly override ! * <code>isCellEditable</code>. */ protected boolean canEdit; /** * Used in editing. Indicates x position to place ! * <code>editingComponent</code>. */ protected transient int offset; ! /** <code>JTree</code> instance listening too. */ protected transient JTree tree; /** Last path that was selected. */ protected transient TreePath lastPath; /** Used before starting the editing session. */ protected transient Timer timer; /** * Row that was last passed into ! * <code>getTreeCellEditorComponent</code>. */ protected transient int lastRow; /** True if the border selection color should be drawn. */ protected Color borderSelectionColor; /** Icon to use when editing. */ protected transient Icon editingIcon; /** ! * Font to paint with, <code>null</code> indicates * font of renderer is to be used. */ protected Font font; /** ! * Constructs a <code>DefaultTreeCellEditor</code> * object for a JTree using the specified renderer and * a default editor. (Use this constructor for normal editing.) * ! * @param tree a <code>JTree</code> object ! * @param renderer a <code>DefaultTreeCellRenderer</code> object */ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) { this(tree, renderer, null); } /** ! * Constructs a <code>DefaultTreeCellEditor</code> ! * object for a <code>JTree</code> using the * specified renderer and the specified editor. (Use this constructor * for specialized editing.) * ! * @param tree a <code>JTree</code> object ! * @param renderer a <code>DefaultTreeCellRenderer</code> object ! * @param editor a <code>TreeCellEditor</code> object */ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { this.renderer = renderer; realEditor = editor; --- 63,144 ---- protected TreeCellEditor realEditor; /** Renderer, used to get border and offsets from. */ protected DefaultTreeCellRenderer renderer; ! /** Editing container, will contain the {@code editorComponent}. */ protected Container editingContainer; /** * Component used in editing, obtained from the ! * {@code editingContainer}. */ protected transient Component editingComponent; /** * As of Java 2 platform v1.4 this field should no longer be used. If * you wish to provide similar behavior you should directly override ! * {@code isCellEditable}. */ protected boolean canEdit; /** * Used in editing. Indicates x position to place ! * {@code editingComponent}. */ protected transient int offset; ! /** {@code JTree} instance listening too. */ protected transient JTree tree; /** Last path that was selected. */ protected transient TreePath lastPath; /** Used before starting the editing session. */ protected transient Timer timer; /** * Row that was last passed into ! * {@code getTreeCellEditorComponent}. */ protected transient int lastRow; /** True if the border selection color should be drawn. */ protected Color borderSelectionColor; /** Icon to use when editing. */ protected transient Icon editingIcon; /** ! * Font to paint with, {@code null} indicates * font of renderer is to be used. */ protected Font font; /** ! * Constructs a {@code DefaultTreeCellEditor} * object for a JTree using the specified renderer and * a default editor. (Use this constructor for normal editing.) * ! * @param tree a {@code JTree} object ! * @param renderer a {@code DefaultTreeCellRenderer} object */ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) { this(tree, renderer, null); } /** ! * Constructs a {@code DefaultTreeCellEditor} ! * object for a {@code JTree} using the * specified renderer and the specified editor. (Use this constructor * for specialized editing.) * ! * @param tree a {@code JTree} object ! * @param renderer a {@code DefaultTreeCellRenderer} object ! * @param editor a {@code TreeCellEditor} object */ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { this.renderer = renderer; realEditor = editor;
*** 165,192 **** public Color getBorderSelectionColor() { return borderSelectionColor; } /** ! * Sets the font to edit with. <code>null</code> indicates * the renderers font should be used. This will NOT * override any font you have set in the editor ! * the receiver was instantiated with. If <code>null</code> * for an editor was passed in a default editor will be * created that will pick up this font. * ! * @param font the editing <code>Font</code> * @see #getFont */ public void setFont(Font font) { this.font = font; } /** * Gets the font used for editing. * ! * @return the editing <code>Font</code> * @see #setFont */ public Font getFont() { return font; } --- 165,192 ---- public Color getBorderSelectionColor() { return borderSelectionColor; } /** ! * Sets the font to edit with. {@code null} indicates * the renderers font should be used. This will NOT * override any font you have set in the editor ! * the receiver was instantiated with. If {@code null} * for an editor was passed in a default editor will be * created that will pick up this font. * ! * @param font the editing {@code Font} * @see #getFont */ public void setFont(Font font) { this.font = font; } /** * Gets the font used for editing. * ! * @return the editing {@code Font} * @see #setFont */ public Font getFont() { return font; }
*** 194,204 **** // // TreeCellEditor // /** ! * Configures the editor. Passed onto the <code>realEditor</code>. */ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { --- 194,204 ---- // // TreeCellEditor // /** ! * Configures the editor. Passed onto the {@code realEditor}. */ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
*** 240,251 **** public Object getCellEditorValue() { return realEditor.getCellEditorValue(); } /** ! * If the <code>realEditor</code> returns true to this ! * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; --- 240,251 ---- public Object getCellEditorValue() { return realEditor.getCellEditorValue(); } /** ! * If the {@code realEditor} returns true to this ! * message, {@code prepareForEditing} * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false;
*** 285,303 **** prepareForEditing(); return retValue; } /** ! * Messages the <code>realEditor</code> for the return value. */ public boolean shouldSelectCell(EventObject event) { return realEditor.shouldSelectCell(event); } /** ! * If the <code>realEditor</code> will allow editing to stop, ! * the <code>realEditor</code> is removed and true is returned, * otherwise false is returned. */ public boolean stopCellEditing() { if(realEditor.stopCellEditing()) { cleanupAfterEditing(); --- 285,303 ---- prepareForEditing(); return retValue; } /** ! * Messages the {@code realEditor} for the return value. */ public boolean shouldSelectCell(EventObject event) { return realEditor.shouldSelectCell(event); } /** ! * If the {@code realEditor} will allow editing to stop, ! * the {@code realEditor} is removed and true is returned, * otherwise false is returned. */ public boolean stopCellEditing() { if(realEditor.stopCellEditing()) { cleanupAfterEditing();
*** 305,343 **** } return false; } /** ! * Messages <code>cancelCellEditing</code> to the ! * <code>realEditor</code> and removes it from this instance. */ public void cancelCellEditing() { realEditor.cancelCellEditing(); cleanupAfterEditing(); } /** ! * Adds the <code>CellEditorListener</code>. * @param l the listener to be added */ public void addCellEditorListener(CellEditorListener l) { realEditor.addCellEditorListener(l); } /** ! * Removes the previously added <code>CellEditorListener</code>. * @param l the listener to be removed */ public void removeCellEditorListener(CellEditorListener l) { realEditor.removeCellEditorListener(l); } /** ! * Returns an array of all the <code>CellEditorListener</code>s added * to this DefaultTreeCellEditor with addCellEditorListener(). * ! * @return all of the <code>CellEditorListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public CellEditorListener[] getCellEditorListeners() { return ((DefaultCellEditor)realEditor).getCellEditorListeners(); --- 305,343 ---- } return false; } /** ! * Messages {@code cancelCellEditing} to the ! * {@code realEditor} and removes it from this instance. */ public void cancelCellEditing() { realEditor.cancelCellEditing(); cleanupAfterEditing(); } /** ! * Adds the {@code CellEditorListener}. * @param l the listener to be added */ public void addCellEditorListener(CellEditorListener l) { realEditor.addCellEditorListener(l); } /** ! * Removes the previously added {@code CellEditorListener}. * @param l the listener to be removed */ public void removeCellEditorListener(CellEditorListener l) { realEditor.removeCellEditorListener(l); } /** ! * Returns an array of all the {@code CellEditorListener}s added * to this DefaultTreeCellEditor with addCellEditorListener(). * ! * @return all of the {@code CellEditorListener}s added or an empty * array if no listeners have been added * @since 1.4 */ public CellEditorListener[] getCellEditorListeners() { return ((DefaultCellEditor)realEditor).getCellEditorListeners();
*** 346,356 **** // // TreeSelectionListener // /** ! * Resets <code>lastPath</code>. */ public void valueChanged(TreeSelectionEvent e) { if(tree != null) { if(tree.getSelectionCount() == 1) lastPath = tree.getSelectionPath(); --- 346,356 ---- // // TreeSelectionListener // /** ! * Resets {@code lastPath}. */ public void valueChanged(TreeSelectionEvent e) { if(tree != null) { if(tree.getSelectionCount() == 1) lastPath = tree.getSelectionPath();
*** 397,407 **** } } } /** ! * Returns true if <code>event</code> is a <code>MouseEvent</code> * and the click count is 1. * * @param event the event being studied * @return whether {@code event} should starts the editing timer */ --- 397,407 ---- } } } /** ! * Returns true if {@code event} is a {@code MouseEvent} * and the click count is 1. * * @param event the event being studied * @return whether {@code event} should starts the editing timer */
*** 426,438 **** } timer.start(); } /** ! * Returns true if <code>event</code> is <code>null</code>, ! * or it is a <code>MouseEvent</code> with a click count &gt; 2 ! * and <code>inHitRegion</code> returns true. * * @param event the event being studied * @return whether editing can be started for the given {@code event} */ protected boolean canEditImmediately(EventObject event) { --- 426,438 ---- } timer.start(); } /** ! * Returns true if {@code event} is {@code null}, ! * or it is a {@code MouseEvent} with a click count &gt; 2 ! * and {@code inHitRegion} returns true. * * @param event the event being studied * @return whether editing can be started for the given {@code event} */ protected boolean canEditImmediately(EventObject event) {
*** 447,457 **** } /** * Returns true if the passed in location is a valid mouse location * to start editing from. This is implemented to return false if ! * <code>x</code> is &lt;= the width of the icon and icon gap displayed * by the renderer. In other words this returns true if the user * clicks over the text part displayed by the renderer, and false * otherwise. * @param x the x-coordinate of the point * @param y the y-coordinate of the point --- 447,457 ---- } /** * Returns true if the passed in location is a valid mouse location * to start editing from. This is implemented to return false if ! * {@code x} is &lt;= the width of the icon and icon gap displayed * by the renderer. In other words this returns true if the user * clicks over the text part displayed by the renderer, and false * otherwise. * @param x the x-coordinate of the point * @param y the y-coordinate of the point
*** 477,487 **** return true; } /** * Determine the offset. ! * @param tree a <code>JTree</code> object * @param value a value * @param isSelected selection status * @param expanded expansion status * @param leaf leaf status * @param row current row --- 477,487 ---- return true; } /** * Determine the offset. ! * @param tree a {@code JTree} object * @param value a value * @param isSelected selection status * @param expanded expansion status * @param leaf leaf status * @param row current row
*** 508,541 **** } } /** * Invoked just before editing is to start. Will add the ! * <code>editingComponent</code> to the ! * <code>editingContainer</code>. */ protected void prepareForEditing() { if (editingComponent != null) { editingContainer.add(editingComponent); } } /** * Creates the container to manage placement of ! * <code>editingComponent</code>. * * @return new Container object */ protected Container createContainer() { return new EditorContainer(); } /** ! * This is invoked if a <code>TreeCellEditor</code> * is not supplied in the constructor. ! * It returns a <code>TextField</code> editor. ! * @return a new <code>TextField</code> editor */ protected TreeCellEditor createTreeCellEditor() { Border aBorder = UIManager.getBorder("Tree.editorBorder"); @SuppressWarnings("serial") // Safe: outer class is non-serializable DefaultCellEditor editor = new DefaultCellEditor --- 508,541 ---- } } /** * Invoked just before editing is to start. Will add the ! * {@code editingComponent} to the ! * {@code editingContainer}. */ protected void prepareForEditing() { if (editingComponent != null) { editingContainer.add(editingComponent); } } /** * Creates the container to manage placement of ! * {@code editingComponent}. * * @return new Container object */ protected Container createContainer() { return new EditorContainer(); } /** ! * This is invoked if a {@code TreeCellEditor} * is not supplied in the constructor. ! * It returns a {@code TextField} editor. ! * @return a new {@code TextField} editor */ protected TreeCellEditor createTreeCellEditor() { Border aBorder = UIManager.getBorder("Tree.editorBorder"); @SuppressWarnings("serial") // Safe: outer class is non-serializable DefaultCellEditor editor = new DefaultCellEditor
*** 551,586 **** return editor; } /** * Cleans up any state after editing has completed. Removes the ! * <code>editingComponent</code> the <code>editingContainer</code>. */ private void cleanupAfterEditing() { if (editingComponent != null) { editingContainer.remove(editingComponent); } editingComponent = null; } /** ! * <code>TextField</code> used when no editor is supplied. * This textfield locks into the border it is constructed with. * It also prefers its parents font over its font. And if the ! * renderer is not <code>null</code> and no font * has been specified the preferred height is that of the renderer. */ @SuppressWarnings("serial") // Safe: outer class is non-serializable public class DefaultTextField extends JTextField { /** Border to use. */ protected Border border; /** * Constructs a ! * <code>DefaultTreeCellEditor.DefaultTextField</code> object. * ! * @param border a <code>Border</code> object * @since 1.4 */ public DefaultTextField(Border border) { setBorder(border); } --- 551,586 ---- return editor; } /** * Cleans up any state after editing has completed. Removes the ! * {@code editingComponent} the {@code editingContainer}. */ private void cleanupAfterEditing() { if (editingComponent != null) { editingContainer.remove(editingComponent); } editingComponent = null; } /** ! * {@code TextField} used when no editor is supplied. * This textfield locks into the border it is constructed with. * It also prefers its parents font over its font. And if the ! * renderer is not {@code null} and no font * has been specified the preferred height is that of the renderer. */ @SuppressWarnings("serial") // Safe: outer class is non-serializable public class DefaultTextField extends JTextField { /** Border to use. */ protected Border border; /** * Constructs a ! * {@code DefaultTreeCellEditor.DefaultTextField} object. * ! * @param border a {@code Border} object * @since 1.4 */ public DefaultTextField(Border border) { setBorder(border); }
*** 602,612 **** super.setBorder(border); this.border = border; } /** ! * Overrides <code>JComponent.getBorder</code> to * returns the current border. */ public Border getBorder() { return border; } --- 602,612 ---- super.setBorder(border); this.border = border; } /** ! * Overrides {@code JComponent.getBorder} to * returns the current border. */ public Border getBorder() { return border; }
*** 625,638 **** } return font; } /** ! * Overrides <code>JTextField.getPreferredSize</code> to * return the preferred size based on current font, if set, * or else use renderer's font. ! * @return a <code>Dimension</code> object containing * the preferred size */ public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); --- 625,638 ---- } return font; } /** ! * Overrides {@code JTextField.getPreferredSize} to * return the preferred size based on current font, if set, * or else use renderer's font. ! * @return a {@code Dimension} object containing * the preferred size */ public Dimension getPreferredSize() { Dimension size = super.getPreferredSize();
*** 647,662 **** } } /** ! * Container responsible for placing the <code>editingComponent</code>. */ @SuppressWarnings("serial") // Safe: outer class is non-serializable public class EditorContainer extends Container { /** ! * Constructs an <code>EditorContainer</code> object. */ public EditorContainer() { setLayout(null); } --- 647,662 ---- } } /** ! * Container responsible for placing the {@code editingComponent}. */ @SuppressWarnings("serial") // Safe: outer class is non-serializable public class EditorContainer extends Container { /** ! * Constructs an {@code EditorContainer} object. */ public EditorContainer() { setLayout(null); }
*** 668,678 **** public void EditorContainer() { setLayout(null); } /** ! * Overrides <code>Container.paint</code> to paint the node's * icon and use the selection color for the background. */ public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); --- 668,678 ---- public void EditorContainer() { setLayout(null); } /** ! * Overrides {@code Container.paint} to paint the node's * icon and use the selection color for the background. */ public void paint(Graphics g) { int width = getWidth(); int height = getHeight();
*** 698,710 **** } super.paint(g); } /** ! * Lays out this <code>Container</code>. If editing, * the editor will be placed at ! * <code>offset</code> in the x direction and 0 for y. */ public void doLayout() { if(editingComponent != null) { int width = getWidth(); int height = getHeight(); --- 698,710 ---- } super.paint(g); } /** ! * Lays out this {@code Container}. If editing, * the editor will be placed at ! * {@code offset} in the x direction and 0 for y. */ public void doLayout() { if(editingComponent != null) { int width = getWidth(); int height = getHeight();
*** 734,750 **** totalY; return getHeight() / 2 - (totalY + (totalHeight / 2)); } /** ! * Returns the preferred size for the <code>Container</code>. * This will be at least preferred size of the editor plus ! * <code>offset</code>. ! * @return a <code>Dimension</code> containing the preferred ! * size for the <code>Container</code>; if ! * <code>editingComponent</code> is <code>null</code> the ! * <code>Dimension</code> returned is 0, 0 */ public Dimension getPreferredSize() { if(editingComponent != null) { Dimension pSize = editingComponent.getPreferredSize(); --- 734,750 ---- totalY; return getHeight() / 2 - (totalY + (totalHeight / 2)); } /** ! * Returns the preferred size for the {@code Container}. * This will be at least preferred size of the editor plus ! * {@code offset}. ! * @return a {@code Dimension} containing the preferred ! * size for the {@code Container}; if ! * {@code editingComponent} is {@code null} the ! * {@code Dimension} returned is 0, 0 */ public Dimension getPreferredSize() { if(editingComponent != null) { Dimension pSize = editingComponent.getPreferredSize();
< prev index next >