Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / utils / xmlTreeTable / XMLTreeTableCellEditor.java @ 3613

History | View | Annotate | Download (6.58 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package es.gva.cit.catalogClient.utils.xmlTreeTable;
43
import java.awt.Component;
44
import java.awt.event.MouseEvent;
45
import java.io.Serializable;
46
import java.util.EventObject;
47
import javax.swing.JComponent;
48
import javax.swing.JTable;
49
import javax.swing.JTree;
50
import javax.swing.SwingUtilities;
51
import javax.swing.event.CellEditorListener;
52
import javax.swing.event.ChangeEvent;
53
import javax.swing.event.EventListenerList;
54
import javax.swing.table.TableCellEditor;
55
import javax.swing.tree.TreeCellEditor;
56
//File: JComponentCellEditor.java
57
//Author: Zafir Anjum
58

    
59
/**
60
 * DOCUMENT ME!
61
 * 
62
 * 
63
 * @author $author$
64
 */
65
public class XMLTreeTableCellEditor implements Serializable, TableCellEditor, TreeCellEditor {
66
/**
67
 * 
68
 * 
69
 */
70
    protected EventListenerList listenerList = new EventListenerList();
71
/**
72
 * 
73
 * 
74
 */
75
    protected transient ChangeEvent changeEvent = null;
76
/**
77
 * 
78
 * 
79
 */
80
    protected JComponent editorComponent = null;
81
/**
82
 * 
83
 * 
84
 */
85
    protected JComponent container = null;
86
// Can be tree or table
87

    
88
/**
89
 * DOCUMENT ME!
90
 * 
91
 * 
92
 * @return DOCUMENT ME!
93
 */
94
    public Component getComponent() {        
95
        return editorComponent;
96
    } 
97

    
98
/**
99
 * DOCUMENT ME!
100
 * 
101
 * 
102
 * @return DOCUMENT ME!
103
 */
104
    public Object getCellEditorValue() {        
105
        return editorComponent;
106
    } 
107

    
108
/**
109
 * DOCUMENT ME!
110
 * 
111
 * 
112
 * @return DOCUMENT ME!
113
 * @param anEvent DOCUMENT ME!
114
 */
115
    public boolean isCellEditable(EventObject anEvent) {        
116
        return true;
117
    } 
118

    
119
/**
120
 * DOCUMENT ME!
121
 * 
122
 * 
123
 * @return DOCUMENT ME!
124
 * @param anEvent DOCUMENT ME!
125
 */
126
    public boolean shouldSelectCell(EventObject anEvent) {        
127
        if ((editorComponent != null) && anEvent instanceof MouseEvent &&
128
                (((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED)) {
129
            Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent,
130
                    3, 3);
131
            MouseEvent e = (MouseEvent) anEvent;
132
            MouseEvent e2 = new MouseEvent(dispatchComponent,
133
                    MouseEvent.MOUSE_RELEASED, e.getWhen() + 100000,
134
                    e.getModifiers(), 3, 3, e.getClickCount(),
135
                    e.isPopupTrigger());
136
            dispatchComponent.dispatchEvent(e2);
137
            e2 = new MouseEvent(dispatchComponent, MouseEvent.MOUSE_CLICKED,
138
                    e.getWhen() + 100001, e.getModifiers(), 3, 3, 1,
139
                    e.isPopupTrigger());
140
            dispatchComponent.dispatchEvent(e2);
141
        }
142
        return false;
143
    } 
144

    
145
/**
146
 * DOCUMENT ME!
147
 * 
148
 * 
149
 * @return DOCUMENT ME!
150
 */
151
    public boolean stopCellEditing() {        
152
        fireEditingStopped();
153
        return true;
154
    } 
155

    
156
/**
157
 * DOCUMENT ME!
158
 * 
159
 */
160
    public void cancelCellEditing() {        
161
        fireEditingCanceled();
162
    } 
163

    
164
/**
165
 * DOCUMENT ME!
166
 * 
167
 * 
168
 * @param l DOCUMENT ME!
169
 */
170
    public void addCellEditorListener(CellEditorListener l) {        
171
        listenerList.add(CellEditorListener.class, l);
172
    } 
173

    
174
/**
175
 * DOCUMENT ME!
176
 * 
177
 * 
178
 * @param l DOCUMENT ME!
179
 */
180
    public void removeCellEditorListener(CellEditorListener l) {        
181
        listenerList.remove(CellEditorListener.class, l);
182
    } 
183

    
184
/**
185
 * DOCUMENT ME!
186
 * 
187
 */
188
    protected void fireEditingStopped() {        
189
        Object[] listeners = listenerList.getListenerList();
190
        // Process the listeners last to first, notifying
191
        // those that are interested in this event
192
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
193
            if (listeners[i] == CellEditorListener.class) {
194
                // Lazily create the event:
195
                if (changeEvent == null) {
196
                    changeEvent = new ChangeEvent(this);
197
                }
198
                ((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
199
            }
200
        }
201
    } 
202

    
203
/**
204
 * DOCUMENT ME!
205
 * 
206
 */
207
    protected void fireEditingCanceled() {        
208
        // Guaranteed to return a non-null array
209
        Object[] listeners = listenerList.getListenerList();
210
        // Process the listeners last to first, notifying
211
        // those that are interested in this event
212
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
213
            if (listeners[i] == CellEditorListener.class) {
214
                // Lazily create the event:
215
                if (changeEvent == null) {
216
                    changeEvent = new ChangeEvent(this);
217
                }
218
                ((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
219
            }
220
        }
221
    } 
222
// implements javax.swing.tree.TreeCellEditor
223

    
224
/**
225
 * 
226
 * 
227
 * 
228
 * @return 
229
 * @param tree 
230
 * @param value 
231
 * @param isSelected 
232
 * @param expanded 
233
 * @param leaf 
234
 * @param row 
235
 */
236
    public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {        
237
        tree.convertValueToText(value, isSelected,
238
                expanded, leaf, row, false);
239
        editorComponent = (JComponent) value;
240
        container = tree;
241
        return editorComponent;
242
    } 
243
// implements javax.swing.table.TableCellEditor
244

    
245
/**
246
 * 
247
 * 
248
 * 
249
 * @return 
250
 * @param table 
251
 * @param value 
252
 * @param isSelected 
253
 * @param row 
254
 * @param column 
255
 */
256
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {        
257
        editorComponent = (JComponent) value;
258
        container = table;
259
        return editorComponent;
260
    } 
261
 }
262
// End of class JComponentCellEditor