日期:2014-05-20 浏览次数:20655 次
/*
* @(#)DefaultCellEditor.java 1.53 08/02/04
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.eamois.ui.util;
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.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.TableCellEditor;
import javax.swing.tree.TreeCellEditor;
public class PRSCellEditor extends AbstractCellEditor implements
TableCellEditor, TreeCellEditor {
protected JTextArea editorComponent;
protected EditorDelegate delegate;
protected int clickCountToStart = 1;
public PRSCellEditor(final JTextArea textArea) {
textArea.setLineWrap(true);
editorComponent = textArea;
this.clickCountToStart = 2;
delegate = new EditorDelegate() {
public void setValue(Object value) {
textArea.setText((value != null) ? value.toString() : "");
}
public Object getCellEditorValue() {
return textArea.getText();
}
};
}
public Component getComponent() {
return editorComponent;
}
public void setClickCountToStart(int count) {
clickCountToStart = count;
}
public int getClickCountToStart() {
return clickCountToStart;
}
public Object getCellEditorValue() {
return delegate.getCellEditorValue();
}
public boolean isCellEditable(EventObject anEvent) {
return delegate.isCellEditable(anEvent);
}
public boolean shouldSelectCell(EventObject anEvent) {
return delegate.shouldSelectCell(anEvent);
}
public boolean stopCellEditing() {
return delegate.stopCellEditing();
}
public void cancelCellEditing() {
delegate.cancelCellEditing();
}
public Component getTreeCellEditorComponent(JTree tree, Object value,
boolean isSelected, boolean expanded, boolean leaf, int row) {
String stringValue = tree.convertValueToText(value, isSelected,
expanded, leaf, row, false);
delegate.setValue(stringValue);
return editorComponent;
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
delegate.setValue(value);
// if (editorComponent instanceof JCheckBox) {
//
// TableCellRenderer renderer = table.getCellRenderer(row, column);
// Component c = renderer.getTableCellRendererComponent(table, value,