1 package com.ca.directory.jxplorer.viewer.tableviewer; 2 3 import java.awt.*; 4 import java.util.*; 5 import javax.swing.*; 6 import javax.swing.event.*; 7 import javax.swing.table.*; 8 import javax.swing.tree.*; 9 import java.awt.event.MouseEvent ; 10 import java.util.EventObject ; 11 12 13 abstract public class AbstractCellEditor implements TableCellEditor 14 { 15 protected EventListenerList listenerList = new EventListenerList(); 16 protected Object value; 17 protected ChangeEvent changeEvent = null; 18 protected int clickCountToStart = 1; 19 20 public void addCellEditorListener(CellEditorListener l) 25 { 26 listenerList.add(CellEditorListener.class, l); 27 } 28 29 public void removeCellEditorListener(CellEditorListener l) 31 { 32 listenerList.remove(CellEditorListener.class, l); 33 } 34 35 42 protected void fireEditingStopped() 43 { 44 Object [] listeners = listenerList.getListenerList(); 46 for (int i = listeners.length-2; i>=0; i-=2) 49 { 50 if (listeners[i]==CellEditorListener.class) 51 { 52 if (changeEvent == null) 54 changeEvent = new ChangeEvent(this); 55 ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent); 56 } 57 } 58 } 59 60 67 protected void fireEditingCanceled() 68 { 69 Object [] listeners = listenerList.getListenerList(); 71 for (int i = listeners.length-2; i>=0; i-=2) 74 { 75 if (listeners[i]==CellEditorListener.class) 76 { 77 if (changeEvent == null) 79 changeEvent = new ChangeEvent(this); 80 ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent); 81 } 82 } 83 } 84 85 86 public Object getCellEditorValue() 87 { 88 return value; 89 } 90 91 public void setCellEditorValue(Object value) 92 { 93 this.value = value; 94 } 95 96 97 103 public void setClickCountToStart(int count) 104 { 105 clickCountToStart = count; 106 } 107 108 112 public int getClickCountToStart() 113 { 114 return clickCountToStart; 115 } 116 117 public boolean isCellEditable(EventObject anEvent) 119 { 120 if (anEvent instanceof MouseEvent ) 121 { 122 return ((MouseEvent )anEvent).getClickCount() >= clickCountToStart; 123 } 124 return true; 125 } 126 127 128 public boolean stopCellEditing() 130 { 131 fireEditingStopped(); 132 return true; 133 } 134 135 public void cancelCellEditing() 137 { 138 fireEditingCanceled(); 139 } 140 141 public boolean shouldSelectCell(EventObject anEvent) 143 { 144 return true; 145 } 146 147 } | Popular Tags |