ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
      }
   }
 
}