1 16 package org.apache.log4j.lf5.viewer.categoryexplorer; 17 18 import javax.swing.*; 19 import javax.swing.event.CellEditorListener ; 20 import javax.swing.event.ChangeEvent ; 21 import javax.swing.event.EventListenerList ; 22 import javax.swing.table.TableCellEditor ; 23 import javax.swing.tree.TreeCellEditor ; 24 import java.awt.*; 25 import java.awt.event.MouseEvent ; 26 import java.util.EventObject ; 27 28 35 36 38 public class CategoryAbstractCellEditor implements TableCellEditor , TreeCellEditor { 39 43 protected EventListenerList _listenerList = new EventListenerList (); 47 protected Object _value; 48 protected ChangeEvent _changeEvent = null; 49 protected int _clickCountToStart = 1; 50 51 55 59 63 public Object getCellEditorValue() { 64 return _value; 65 } 66 67 public void setCellEditorValue(Object value) { 68 _value = value; 69 } 70 71 public void setClickCountToStart(int count) { 72 _clickCountToStart = count; 73 } 74 75 public int getClickCountToStart() { 76 return _clickCountToStart; 77 } 78 79 public boolean isCellEditable(EventObject anEvent) { 80 if (anEvent instanceof MouseEvent ) { 81 if (((MouseEvent ) anEvent).getClickCount() < _clickCountToStart) { 82 return false; 83 } 84 } 85 return true; 86 } 87 88 public boolean shouldSelectCell(EventObject anEvent) { 89 if (this.isCellEditable(anEvent)) { 90 if (anEvent == null || 91 ((MouseEvent ) anEvent).getClickCount() >= _clickCountToStart) { 92 return true; 93 } 94 } 95 return false; 96 } 97 98 public boolean stopCellEditing() { 99 fireEditingStopped(); 100 return true; 101 } 102 103 public void cancelCellEditing() { 104 fireEditingCanceled(); 105 } 106 107 public void addCellEditorListener(CellEditorListener l) { 108 _listenerList.add(CellEditorListener .class, l); 109 } 110 111 public void removeCellEditorListener(CellEditorListener l) { 112 _listenerList.remove(CellEditorListener .class, l); 113 } 114 115 public Component getTreeCellEditorComponent( 116 JTree tree, Object value, 117 boolean isSelected, 118 boolean expanded, 119 boolean leaf, int row) { 120 return null; 121 } 122 123 public Component getTableCellEditorComponent( 124 JTable table, Object value, 125 boolean isSelected, 126 int row, int column) { 127 return null; 128 } 129 130 protected void fireEditingStopped() { 134 Object [] listeners = _listenerList.getListenerList(); 135 136 for (int i = listeners.length - 2; i >= 0; i -= 2) { 137 if (listeners[i] == CellEditorListener .class) { 138 if (_changeEvent == null) { 139 _changeEvent = new ChangeEvent (this); 140 } 141 142 ((CellEditorListener ) listeners[i + 1]).editingStopped(_changeEvent); 143 } 144 } 145 } 146 147 protected void fireEditingCanceled() { 148 Object [] listeners = _listenerList.getListenerList(); 149 150 for (int i = listeners.length - 2; i >= 0; i -= 2) { 151 if (listeners[i] == CellEditorListener .class) { 152 if (_changeEvent == null) { 153 _changeEvent = new ChangeEvent (this); 154 } 155 156 ((CellEditorListener ) listeners[i + 1]).editingCanceled(_changeEvent); 157 } 158 } 159 } 160 161 165 169 } 170 | Popular Tags |