root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / utils / xmlTreeTable / XMLTreeTableCellEditor.java @ 2047
History | View | Annotate | Download (3.62 KB)
1 |
package es.gva.cit.catalogClient.utils.xmlTreeTable; |
---|---|
2 |
|
3 |
//File: JComponentCellEditor.java
|
4 |
//Author: Zafir Anjum
|
5 |
import java.awt.Component; |
6 |
import java.awt.event.*; |
7 |
import javax.swing.table.*; |
8 |
import javax.swing.event.*; |
9 |
import java.util.EventObject; |
10 |
import javax.swing.tree.*; |
11 |
import java.io.Serializable; |
12 |
import javax.swing.*; |
13 |
|
14 |
|
15 |
public class XMLTreeTableCellEditor implements TableCellEditor, TreeCellEditor, |
16 |
Serializable {
|
17 |
|
18 |
protected EventListenerList listenerList = new EventListenerList(); |
19 |
transient protected ChangeEvent changeEvent = null; |
20 |
|
21 |
protected JComponent editorComponent = null; |
22 |
protected JComponent container = null; // Can be tree or table |
23 |
|
24 |
|
25 |
public Component getComponent() { |
26 |
return editorComponent;
|
27 |
} |
28 |
|
29 |
|
30 |
public Object getCellEditorValue() { |
31 |
return editorComponent;
|
32 |
} |
33 |
|
34 |
public boolean isCellEditable(EventObject anEvent) { |
35 |
return true; |
36 |
} |
37 |
|
38 |
public boolean shouldSelectCell(EventObject anEvent) { |
39 |
if( editorComponent != null && anEvent instanceof MouseEvent |
40 |
&& ((MouseEvent)anEvent).getID() == MouseEvent.MOUSE_PRESSED ) |
41 |
{ |
42 |
Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 3, 3 ); |
43 |
MouseEvent e = (MouseEvent)anEvent; |
44 |
MouseEvent e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_RELEASED, |
45 |
e.getWhen() + 100000, e.getModifiers(), 3, 3, e.getClickCount(), |
46 |
e.isPopupTrigger() ); |
47 |
dispatchComponent.dispatchEvent(e2); |
48 |
e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_CLICKED, |
49 |
e.getWhen() + 100001, e.getModifiers(), 3, 3, 1, |
50 |
e.isPopupTrigger() ); |
51 |
dispatchComponent.dispatchEvent(e2); |
52 |
} |
53 |
return false; |
54 |
} |
55 |
|
56 |
public boolean stopCellEditing() { |
57 |
fireEditingStopped(); |
58 |
return true; |
59 |
} |
60 |
|
61 |
public void cancelCellEditing() { |
62 |
fireEditingCanceled(); |
63 |
} |
64 |
|
65 |
public void addCellEditorListener(CellEditorListener l) { |
66 |
listenerList.add(CellEditorListener.class, l);
|
67 |
} |
68 |
|
69 |
public void removeCellEditorListener(CellEditorListener l) { |
70 |
listenerList.remove(CellEditorListener.class, l);
|
71 |
} |
72 |
|
73 |
protected void fireEditingStopped() { |
74 |
Object[] listeners = listenerList.getListenerList(); |
75 |
// Process the listeners last to first, notifying
|
76 |
// those that are interested in this event
|
77 |
for (int i = listeners.length-2; i>=0; i-=2) { |
78 |
if (listeners[i]==CellEditorListener.class) { |
79 |
// Lazily create the event:
|
80 |
if (changeEvent == null) |
81 |
changeEvent = new ChangeEvent(this); |
82 |
((CellEditorListener)listeners[i+1]).editingStopped(changeEvent); |
83 |
} |
84 |
} |
85 |
} |
86 |
|
87 |
protected void fireEditingCanceled() { |
88 |
// Guaranteed to return a non-null array
|
89 |
Object[] listeners = listenerList.getListenerList(); |
90 |
// Process the listeners last to first, notifying
|
91 |
// those that are interested in this event
|
92 |
for (int i = listeners.length-2; i>=0; i-=2) { |
93 |
if (listeners[i]==CellEditorListener.class) { |
94 |
// Lazily create the event:
|
95 |
if (changeEvent == null) |
96 |
changeEvent = new ChangeEvent(this); |
97 |
((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent); |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
// implements javax.swing.tree.TreeCellEditor
|
103 |
public Component getTreeCellEditorComponent(JTree tree, Object value, |
104 |
boolean isSelected, boolean expanded, boolean leaf, int row) { |
105 |
String stringValue = tree.convertValueToText(value, isSelected,
|
106 |
expanded, leaf, row, false);
|
107 |
|
108 |
editorComponent = (JComponent)value;
|
109 |
container = tree; |
110 |
return editorComponent;
|
111 |
} |
112 |
|
113 |
// implements javax.swing.table.TableCellEditor
|
114 |
public Component getTableCellEditorComponent(JTable table, Object value, |
115 |
boolean isSelected, int row, int column) { |
116 |
|
117 |
editorComponent = (JComponent)value;
|
118 |
container = table; |
119 |
return editorComponent;
|
120 |
} |
121 |
|
122 |
} // End of class JComponentCellEditor
|