⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcelleditor.java

📁 gcc的组建
💻 JAVA
字号:
/* DefaultCellEditor.java --   Copyright (C) 2002, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Component;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.MouseEvent;import java.io.Serializable;import java.util.EventObject;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.event.CellEditorListener;import javax.swing.table.TableCellEditor;import javax.swing.tree.TreeCellEditor;/** * The default implementation of {@link TableCellEditor} and * {@link TreeCellEditor}. It provides editor components for * some standard object types. *  * @author Andrew Selkirk * * @status mostly unimplemented */public class DefaultCellEditor  extends AbstractCellEditor  implements TableCellEditor, TreeCellEditor{  private static final long serialVersionUID = 3564035141373880027L;  /**   * Delegates a couple of method calls (such as {@link #isCellEditable}   * to the component it contains and listens for events that indicate   * that editing has stopped.   */  protected class EditorDelegate    implements ActionListener, ItemListener, Serializable  {    private static final long serialVersionUID = -1420007406015481933L;    /**     * value     */    protected Object value;    /**     * Constructor EditorDelegate     */    protected EditorDelegate()    {      // Nothing to do here.    }    /**     * setValue     *     * @param value TODO     */    public void setValue(Object value)    {      // TODO: should be setting the value in the editorComp      this.value = value;    }   /**     * getCellEditorValue     *      * @returns Object     */    public Object getCellEditorValue()    {      // TODO: should be getting the updated value from the editorComp      return value;    } // getCellEditorValue()    /**     * isCellEditable     *      * @param event TODO     *     * @returns boolean     */    public boolean isCellEditable(EventObject event)    {      if (event == null || !(event instanceof MouseEvent) ||          (((MouseEvent) event).getClickCount() >= getClickCountToStart()))        return true;      return false;    } // isCellEditable()    /**     * shouldSelectCell     *      * @param event TODO     *     * @returns boolean     */    public boolean shouldSelectCell(EventObject event)    {      // return true to indicate that the editing cell may be selected      return true;    } // shouldSelectCell()    /**     * stopCellEditing     *      * @returns boolean     */    public boolean stopCellEditing()    {      fireEditingStopped();      return true;    } // stopCellEditing()    /**     * cancelCellEditing     */    public void cancelCellEditing()    {      fireEditingCanceled();    } // cancelCellEditing()    /**     * startCellEditing     *      * @param event TODO     *     * @returns boolean     */    public boolean startCellEditing(EventObject event)    {      // return true to indicate that editing has begun      return true;    } // startCellEditing()    /**     * actionPerformed     *      * @param event TODO     */    public void actionPerformed(ActionEvent event)    {      stopCellEditing();    } // actionPerformed()    /**     * itemStateChanged     *      * @param event TODO     */    public void itemStateChanged(ItemEvent event)    {      stopCellEditing();    } // itemStateChanged()    void fireEditingStopped()    {      CellEditorListener[] listeners = getCellEditorListeners();      for (int index = 0; index < listeners.length; index++)        listeners[index].editingStopped(changeEvent);          }        void fireEditingCanceled()    {      CellEditorListener[] listeners = getCellEditorListeners();      for (int index = 0; index < listeners.length; index++)        listeners[index].editingCanceled(changeEvent);    }  } // EditorDelegate	/**   * editorComponent   */  protected JComponent editorComponent;  /**   * delegate   */  protected EditorDelegate delegate;  /**   * clickCountToStart   */  protected int clickCountToStart;  /**   * Constructor DefaultCellEditor   *    * @param textfield TODO   */  public DefaultCellEditor(JTextField textfield)  {    editorComponent = textfield;    clickCountToStart = 3;  } // DefaultCellEditor()  /**   * Constructor DefaultCellEditor   *    * @param checkbox TODO   */  public DefaultCellEditor(JCheckBox checkbox)  {    editorComponent = checkbox;    clickCountToStart = 1;  } // DefaultCellEditor()  /**   * Constructor DefaultCellEditor   *    * @param combobox TODO   */  public DefaultCellEditor(JComboBox combobox)  {    editorComponent = combobox;    clickCountToStart = 1;  } // DefaultCellEditor()  /**   * getComponent   *    * @returns Component   */  public Component getComponent()  {    return editorComponent;   } // getComponent()  /**   * getClickCountToStart   *    * @returns int   */  public int getClickCountToStart()  {    return clickCountToStart;  } // getClickCountToStart()  /**   * setClickCountToStart   *    * @param count TODO   */  public void setClickCountToStart(int count)  {    clickCountToStart = count;  } // setClickCountToStart()  /**   * getCellEditorValue   *    * @returns Object   */  public Object getCellEditorValue()  {    return delegate.getCellEditorValue();  } // getCellEditorValue()  /**   * isCellEditable   *    * @param event TODO   *   * @returns boolean   */  public boolean isCellEditable(EventObject event)  {    return delegate.isCellEditable(event);  } // isCellEditable()  /**   * shouldSelectCell   *    * @param event TODO   *   * @returns boolean   */  public boolean shouldSelectCell(EventObject event)  {    return delegate.shouldSelectCell(event);  } // shouldSelectCell()  /**   * stopCellEditing   *    * @returns boolean   */  public boolean stopCellEditing()  {    return delegate.stopCellEditing();  } // stopCellEditing()  /**   * cancelCellEditing   */  public void cancelCellEditing()  {    delegate.cancelCellEditing();  } // cancelCellEditing()  /**   * Sets an initial value for the editor.    * This will cause the editor to stopEditing and lose any partially    * edited value if the editor is editing when this method is called.   * Returns the component that should be added to the client's Component    * hierarchy. Once installed in the client's hierarchy this component will    * then be able to draw and receive user input.    *    * @param tree - the JTree that is asking the editor to edit; this    * parameter can be null   * @param value - the value of the cell to be edited   * @param isSelected - true is the cell is to be renderer with selection   * highlighting   * @param expanded - true if the node is expanded   * @param leaf - true if the node is a leaf node   * @param row - the row index of the node being edited   *   * @returns Component the component for editing   */  public Component getTreeCellEditorComponent(JTree tree, Object value,                                              boolean isSelected,                                              boolean expanded, boolean leaf,                                              int row)  {    if (editorComponent instanceof JTextField)      {        ((JTextField)editorComponent).setText(value.toString());        delegate = new EditorDelegate();        ((JTextField)editorComponent).addActionListener(delegate);      }    else if (editorComponent instanceof JCheckBox)      {        ((JCheckBox)editorComponent).setText(value.toString());        delegate = new EditorDelegate();        ((JCheckBox)editorComponent).addActionListener(delegate);      }    else if (editorComponent instanceof JComboBox)      {        ((JComboBox)editorComponent).setSelectedItem(value.toString());        delegate = new EditorDelegate();        ((JComboBox)editorComponent).addActionListener(delegate);      }    return editorComponent;  } // getTreeCellEditorComponent()  /**   * getTableCellEditorComponent   *    * @param table TODO   * @param value TODO   * @param isSelected TODO   * @param row TODO   * @param column TODO   *   * @returns Component   */  public Component getTableCellEditorComponent(JTable table, Object value,                                               boolean isSelected, int row,                                               int column)  {    // NOTE: as specified by Sun, we don't call new() everytime, we return     // editorComponent on each call to getTableCellEditorComponent or    // getTreeCellEditorComponent.  However, currently JTextFields have a    // problem with getting rid of old text, so without calling new() there    // are some strange results.  If you edit more than one cell in the table    // text from previously edited cells may unexpectedly show up in the     // cell you are currently editing.  This will be fixed automatically    // when JTextField is fixed.    if (editorComponent instanceof JTextField)      {        ((JTextField)editorComponent).setText(value.toString());        delegate = new EditorDelegate();        ((JTextField)editorComponent).addActionListener(delegate);      }    else      {        // TODO      }    return editorComponent;  } // getTableCellEditorComponent()}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -