Statistics
| Revision:

gvsig-catalog / trunk / appCatalog / src / org / gvsig / catalog / utils / resourcestable / ButtonEditor.java @ 6

History | View | Annotate | Download (3.74 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 org.gvsig.catalog.utils.resourcestable;
43
import java.awt.Component;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.util.Collection;
47

    
48
import javax.swing.DefaultCellEditor;
49
import javax.swing.JButton;
50
import javax.swing.JCheckBox;
51
import javax.swing.JTable;
52

    
53
import org.gvsig.catalog.schemas.Resource;
54
import org.gvsig.catalog.ui.chooseresource.ChooseResourceDialogPanel;
55

    
56

    
57
/**
58
 * 
59
 * 
60
 * 
61
 * @author Jorge Piera Llodra (piera_jor@gva.es)
62
 */
63
public class ButtonEditor extends DefaultCellEditor {
64
/**
65
 * 
66
 * 
67
 */
68
    protected JButton button;
69

    
70
/**
71
 * 
72
 * 
73
 */
74
    private String label;
75

    
76
/**
77
 * 
78
 * 
79
 */
80
    private boolean isPushed;
81
/**
82
 * 
83
 * 
84
 */
85
    private ChooseResourceDialogPanel dialog;
86

    
87
/**
88
 * 
89
 * 
90
 */
91
    private java.util.Collection resources = new java.util.ArrayList();
92

    
93
/**
94
 * 
95
 * 
96
 * 
97
 * @param checkBox 
98
 * @param resources 
99
 * @param dialog 
100
 */
101
    public  ButtonEditor(JCheckBox checkBox, Collection resources, ChooseResourceDialogPanel dialog) {        
102
      super(checkBox);
103
      this.resources = resources;
104
      this.dialog = dialog;
105
      button = new JButton();
106
      button.setOpaque(true);
107
      button.addActionListener(new ActionListener() {
108
        public void actionPerformed(ActionEvent e) {
109
          fireEditingStopped();
110
        }
111
      });
112
    } 
113

    
114
/**
115
 * 
116
 * 
117
 * 
118
 * @return 
119
 * @param table 
120
 * @param value 
121
 * @param isSelected 
122
 * @param row 
123
 * @param column 
124
 */
125
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {        
126
      if (isSelected) {
127
        button.setForeground(table.getSelectionForeground());
128
        button.setBackground(table.getSelectionBackground());
129
      } else{
130
        button.setForeground(table.getForeground());
131
        button.setBackground(table.getBackground());
132
      }
133
      label = (value == null) ? "" : value.toString();
134
      button.setText( label );
135
      button.setName(String.valueOf(row));
136
      isPushed = true;
137
      return button;
138
    } 
139

    
140
/**
141
 * 
142
 * 
143
 * 
144
 * @return 
145
 */
146
    public Object getCellEditorValue() {        
147
      if (isPushed)  {
148
        Resource resource = (Resource)resources.toArray()[Integer.valueOf(button.getName()).intValue()];
149
        this.dialog.resourceButtonActionPerformed(resource);
150
        
151
      }
152
      isPushed = false;
153
      return new String(label) ;
154
    } 
155

    
156
/**
157
 * 
158
 * 
159
 * 
160
 * @return 
161
 */
162
    public boolean stopCellEditing() {        
163
      isPushed = false;
164
      return super.stopCellEditing();
165
    } 
166

    
167
/**
168
 * 
169
 * 
170
 */
171
    protected void fireEditingStopped() {        
172
      super.fireEditingStopped();
173
    } 
174
 }