defaultcelleditor.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 554 行 · 第 1/2 页

JAVA
554
字号
/* DefaultCellEditor.java --   Copyright (C) 2002, 2004, 2006, 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 * @author Audrius Meskauskas */public class DefaultCellEditor  extends AbstractCellEditor  implements TableCellEditor, TreeCellEditor{  private static final long serialVersionUID = 3564035141373880027L;  /**   * This changeable module access the editor component in the component   * specific way. For instance, to set the value for JTextField, we need to    * call setText(String), and for JCheckBox we need to call    * setSelected(boolean). Each default editor has the component specific   * derivative of this class. These derivatives are private inner classes of   * the DefaultCellEditor.   *    * The editor delegate is also set for the editor component as the action   * listener. It listens for the events that indicate that editing has stopped.   */  protected class EditorDelegate    implements ActionListener, ItemListener, Serializable  {    /**     * Use the serial version UID for interoperability.     */    private static final long serialVersionUID = -1420007406015481933L;    /**     * The object value (updated when getting and setting the value).     */    protected Object value;    /**     * Constructor EditorDelegate     */    protected EditorDelegate()    {      // Nothing to do here.    }        /**     * Set the value for the editor component. This method is normally     * overridden to set the value in the way, specific for the text     * component, check box or combo box.     *     * @param aValue the value to set (String, Boolean or Number).     */    public void setValue(Object aValue)    {      value = aValue;    }    /**     * Get the value for the editor component. This method is normally     * overridden to obtain the value in the way, specific for the text     * component, check box or combo box.     *     * @return value the value of the component (String, Boolean or Number).     */    public Object getCellEditorValue()    {      return value;    }     /**     * The default method returns true for the {@link MouseEvent} and false      * for any other events.     *      * @param event the event to check     *     * @return true if the passed event is the mouse event and false otherwise.     */    public boolean isCellEditable(EventObject event)    {      if (event == null || !(event instanceof MouseEvent) ||          (((MouseEvent) event).getClickCount() >= getClickCountToStart()))        return true;      return false;    } // isCellEditable()    /**     * Returns true to indicate that the editing cell can be selected.     *      * The default method returns true without action but may be overridden     * in derived classes for more specific behavior.     *      * @param event unused in default method     *     * @return true always     */    public boolean shouldSelectCell(EventObject event)    {      // return true to indicate that the editing cell may be selected      return true;    }    /**     * Finish the cell editing session. This method notifies the registered     * cell editor listeners (including the table) that the editing has been     * stopped.      *      * @return boolean     */    public boolean stopCellEditing()    {      fireEditingStopped();      return true;    } // stopCellEditing()    /**     * Cancel the cell editing session. This method notifies the registered     * cell editor listeners (including the table) that the editing has been     * canceled.     */    public void cancelCellEditing()    {      fireEditingCanceled();    } // cancelCellEditing()    /**     * Start editing session and returns true to indicate the editing has begun.     * The default method returns true without action but may be overridden     * in derived classes for more specific behavior.     *      * @param event  the event.     *      * @return true, always     */    public boolean startCellEditing(EventObject event)    {      // return true to indicate that editing has begun      return true;    } // startCellEditing()    /**     * This event is fired by the editor component (for instance, by pressing     * ENTER in the {@link JTextField}. The default method delegates call to     * the {@link #stopCellEditing}, finishing the editing session.      *      * @param event unused in default method     */    public void actionPerformed(ActionEvent event)    {      stopCellEditing();    } // actionPerformed()    /**     * This event is fired by the editor component.The default method delegates     * call to the {@link #stopCellEditing}, finishing the editing session.      *      * @param event unused in default method     */    public void itemStateChanged(ItemEvent event)    {      stopCellEditing();    } // itemStateChanged()    /**     * Notify the registered listeners (including the table) that the editing     * has been completed.     */    void fireEditingStopped()    {      CellEditorListener[] listeners = getCellEditorListeners();      for (int index = 0; index < listeners.length; index++)        listeners[index].editingStopped(changeEvent);          }        /**     * Notify the registered listeners (including the table) that the editing     * has been canceled.     */    void fireEditingCanceled()    {      CellEditorListener[] listeners = getCellEditorListeners();      for (int index = 0; index < listeners.length; index++)        listeners[index].editingCanceled(changeEvent);    }  } // EditorDelegate    /**   * Provides getter and setter methods to work with the text component.   *    * @author Audrius Meskauskas (audriusa@Bioinformatics.org)   */  private class JTextFieldDelegate extends EditorDelegate  {    /**     * Use the serial version UID for interoperability.     */    private static final long serialVersionUID = 1;        /**     * Set the value for the editor component.     *     * @param aValue the value to set (toString() will be called).     */    public void setValue(Object aValue)    {      value = aValue;      JTextField f = (JTextField) editorComponent;      if (value == null)        f.setText("");      else        f.setText(value.toString());    }    /**     * Get the value for the editor component.      *     * @return value the value of the component (String)     */    public Object getCellEditorValue()    {      JTextField f = (JTextField) editorComponent;

⌨️ 快捷键说明

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