defaultcelleditor.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 554 行 · 第 1/2 页
JAVA
554 行
return value = f.getText(); } } /** * Provides getter and setter methods to work with the combo box. * * @author Audrius Meskauskas (audriusa@Bioinformatics.org) */ private class JComboBoxDelegate 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. */ public void setValue(Object aValue) { value = aValue; JComboBox c = (JComboBox) editorComponent; if (value != null) c.setSelectedItem(value); } /** * Get the value for the editor component. * * @return value the value of the component (as String) */ public Object getCellEditorValue() { JComboBox c = (JComboBox) editorComponent; return value = c.getSelectedItem(); } } /** * Provides getter and setter methods to work with the check box. * * @author Audrius Meskauskas (audriusa@Bioinformatics.org) */ private class JCheckBoxDelegate extends EditorDelegate { /** * Use the serial version UID for interoperability. */ private static final long serialVersionUID = 1; /** * Set the value for the editor component. * * @param value the value to set (must be Boolean). */ public void setValue(Object value) { JCheckBox c = (JCheckBox) editorComponent; if (value == null) c.setSelected(false); else c.setSelected( ((Boolean) value).booleanValue()); } /** * Get the value for the editor component. * * @return value the value of the component (must be CharSequence) */ public Object getCellEditorValue() { JCheckBox c = (JCheckBox) editorComponent; value = c.isSelected() ? Boolean.TRUE : Boolean.FALSE; return value; } } /** * The Swing JComponent, performing the editing session. */ protected JComponent editorComponent; /** * The editor delegate, responsible for listening the {@link #editorComponent} * events and getting/setting its value. */ protected EditorDelegate delegate; /** * The number of the mouse clicks, required to start the editing session. */ protected int clickCountToStart; /** * Create the DefaultCellEditor that uses the text field as its editor * component (appropriate for the text content) * * @param textfield the text field as will be used as the editor component */ public DefaultCellEditor(JTextField textfield) { editorComponent = textfield; clickCountToStart = 2; delegate = new JTextFieldDelegate(); textfield.addActionListener(delegate); } // DefaultCellEditor() /** * Constructor DefaultCellEditor that uses the checkbox (appropriate * for boolean values) * * @param checkbox the checkbox that will be used with this editor. */ public DefaultCellEditor(JCheckBox checkbox) { editorComponent = checkbox; clickCountToStart = 1; delegate = new JCheckBoxDelegate(); checkbox.addActionListener(delegate); } // DefaultCellEditor() /** * Constructor DefaultCellEditor that uses the combo box. * * @param combobox the combo box that will be used with this editor. */ public DefaultCellEditor(JComboBox combobox) { editorComponent = combobox; clickCountToStart = 1; delegate = new JComboBoxDelegate(); combobox.addActionListener(delegate); } // DefaultCellEditor() /** * Get the component that performs the editing sessions. It is the same * component that was passed in constructor. * * @return the component, performing the editing sessions. */ public Component getComponent() { return editorComponent; } // getComponent() /** * Get the number of mouse clicks, required to start the editing session. * * @return int the number of mouse clicks, required to start the session */ public int getClickCountToStart() { return clickCountToStart; } // getClickCountToStart() /** * Set the number of mouse clicks, required to start the editing session. * * @param count the number of clicks, required to start the session */ public void setClickCountToStart(int count) { clickCountToStart = count; } // setClickCountToStart() /** * Get the value, currently being displayed by the editor component. The * call is forwarded to the {@link #delegate}. * * @return Object the value (class depends on the editor component) */ public Object getCellEditorValue() { return delegate.getCellEditorValue(); } // getCellEditorValue() /** * Forwards call to the {@link #delegate}. * * @param event forwarded to the delegate. * * @return boolean returned by delegate */ public boolean isCellEditable(EventObject event) { return delegate.isCellEditable(event); } // isCellEditable() /** * Forwards call to the {@link #delegate}. * * @param event forwarded to the delegate. * * @return boolean returned by delegate */ public boolean shouldSelectCell(EventObject event) { return delegate.shouldSelectCell(event); } // shouldSelectCell() /** * Forwards call to the {@link #delegate}. * * @return boolean returned by delegate */ public boolean stopCellEditing() { return delegate.stopCellEditing(); } // stopCellEditing() /** * Forwards call to the {@link #delegate}. */ 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 * * @return Component the component for editing */ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { delegate.setValue(value); return editorComponent; } // getTreeCellEditorComponent() /** * Get the cell editor component that will perform the editing session. If * returned once, the same component is also returned on the repetetive calls * again (reused). * * @param table the table where the editing is performed * @param value the current value of the table. It is set as the initial * component value. * @param isSelected if true, the cell is currently selected * @param row the row of the cell being edited * @param column the column of the cell being edited * * @return Component the component that will perform the editing session */ 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. delegate.setValue(value); return editorComponent; } // getTableCellEditorComponent()}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?