package com.vci.client.workflow.editor;
|
|
import java.util.*;
|
import java.awt.*;
|
import javax.swing.*;
|
import javax.swing.table.*;
|
import javax.swing.event.*;
|
import java.awt.event.MouseEvent;
|
import java.util.EventObject;
|
|
/**
|
* <p>Title:DblclickCellEditor双击可编辑</p>
|
* <p>Description:实现单元格的双击编辑操作</p>
|
* <p>Copyright: Copyright (C) 2011 </p>
|
* <p>Company: VCI </p>
|
*
|
* @author liud
|
* @time 2013-5-22
|
* @version 1.0
|
*/
|
public class DblclickCellEditor extends DefaultCellEditor {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
protected HashMap<Integer, TableCellEditor> editors;
|
protected TableCellEditor editor, defaultEditor;
|
protected Object value;
|
protected ChangeEvent changeEvent = null;
|
protected int clickCountToStart = 2;
|
JTable table = null;
|
|
public DblclickCellEditor(JComboBox checkBox , JTable table) {
|
super(checkBox);
|
this.table = table;
|
editors = new HashMap<Integer, TableCellEditor>();
|
defaultEditor = new DefaultCellEditor(checkBox);//new JTextField()
|
}
|
|
public void setEditorAt(int row, TableCellEditor editor) {
|
editors.put(new Integer(row),editor);
|
}
|
|
public Component getTableCellEditorComponent(JTable table,
|
Object value, boolean isSelected, int row, int column) {
|
try{
|
return editor.getTableCellEditorComponent(table,
|
value, isSelected, row, column);
|
}catch(Exception e){
|
e.printStackTrace();
|
return null;
|
}
|
}
|
|
public Object getCellEditorValue() {
|
return editor.getCellEditorValue();
|
}
|
|
public boolean stopCellEditing() {
|
try{
|
return editor.stopCellEditing();
|
}catch(Exception e){
|
return false;
|
}
|
}
|
public void cancelCellEditing() {
|
editor.cancelCellEditing();
|
}
|
|
public void addCellEditorListener(CellEditorListener l) {
|
editor.addCellEditorListener(l);
|
}
|
|
public void removeCellEditorListener(CellEditorListener l) {
|
editor.removeCellEditorListener(l);
|
}
|
|
public boolean isCellEditable(EventObject anEvent) {
|
selectEditor((MouseEvent)anEvent);
|
if (anEvent instanceof MouseEvent) {
|
if (((MouseEvent)anEvent).getClickCount() < clickCountToStart){
|
return false;
|
}
|
}
|
return editor.isCellEditable(anEvent);
|
}
|
|
protected void selectEditor(MouseEvent e) {
|
int row;
|
if (e == null) {
|
row = table.getSelectionModel().getAnchorSelectionIndex();
|
} else {
|
row = table.rowAtPoint(e.getPoint());
|
}
|
editor = (TableCellEditor)editors.get(new Integer(row));
|
if (editor == null) {
|
editor = defaultEditor;
|
}
|
}
|
|
}
|