Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / panels / DimensionTree.java @ 3537

History | View | Annotate | Download (7.31 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: DimensionTree.java 3537 2006-01-05 23:15:59Z jaume $
45
* $Log$
46
* Revision 1.1.2.3  2006-01-05 23:15:53  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.1.2.2  2006/01/04 18:09:02  jaume
50
* Time dimension
51
*
52
* Revision 1.1.2.1  2006/01/03 18:08:40  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
/**
58
 * 
59
 */
60
package com.iver.cit.gvsig.gui.panels;
61
import java.awt.Color;
62
import java.awt.Component;
63
import java.awt.event.ActionEvent;
64
import java.awt.event.ActionListener;
65
import java.util.EventObject;
66

    
67
import javax.swing.JButton;
68
import javax.swing.JLabel;
69
import javax.swing.JPanel;
70
import javax.swing.JTree;
71
import javax.swing.event.CellEditorListener;
72
import javax.swing.event.TreeModelListener;
73
import javax.swing.tree.TreeCellEditor;
74
import javax.swing.tree.TreeCellRenderer;
75
import javax.swing.tree.TreeModel;
76
import javax.swing.tree.TreePath;
77

    
78
import com.iver.andami.PluginServices;
79
import com.iver.cit.gvsig.fmap.layers.IFMapWMSDimension;
80
import com.iver.cit.gvsig.fmap.layers.TimeDimension;
81
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
82
/**
83
 * @author jaume
84
 *
85
 */
86
public class DimensionTree extends JTree {
87
        private int rowHeight = 28;
88
    public DimensionTree(){
89
        super();
90
        initialize();
91
    }
92
    
93
    private void initialize(){
94
        setToggleClickCount(1);
95
        setRowHeight(rowHeight);
96
        setCellRenderer(new DimensionTreeCellRenderer());
97
        setCellEditor(new DimensionTreeCellEditor());
98
    }
99
    
100
    private class DimensionTreeCellRenderer implements TreeCellRenderer {
101
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
102
                    if (!leaf){
103
                            JTree t = new JTree();
104
                            Component branchComponent = t.getCellRenderer().getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); 
105
                            return branchComponent;
106
                    } else {
107
                            JPanel leafComponent = new JPanel();
108
                            leafComponent.setBackground(Color.WHITE);
109
                            JButton btn = new JButton();
110
                            btn.setBounds(0, 0, 40, rowHeight);
111
                            btn.setText(PluginServices.getText(this, "edit"));
112
                            leafComponent.add(btn);
113
                            JLabel lbl =new JLabel(((TimeDimension) value).getName());
114
                            leafComponent.add(lbl);
115
                            return leafComponent;
116
                    }
117
                    
118
            }
119
    }
120
    
121
    private class DimensionTreeCellEditor implements TreeCellEditor {
122
            IFMapWMSDimension dim;
123
            public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
124
                    if (!leaf){
125
                            JTree t = new JTree();
126
                            Component branchComponent = t.getCellEditor().getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row); 
127
                            return branchComponent;
128
                    } else {
129
                            JPanel leafComponent = new JPanel();
130
                            leafComponent.setBackground(Color.WHITE);
131
                            JButton btn = new JButton();
132
                            btn.setBounds(0, 0, 40, rowHeight);
133
                            btn.setText(PluginServices.getText(this, "edit"));
134
                            dim = (IFMapWMSDimension) value;
135
                            btn.addActionListener(new ActionListener(){
136
                                    public void actionPerformed(ActionEvent e) {
137
                                            System.out.println("aaaa"+dim.getExpression());
138
                                            
139
                                    }
140
                            });
141
                            leafComponent.add(btn);
142
                            JLabel lbl =new JLabel(((TimeDimension) value).getName());
143
                            leafComponent.add(lbl);
144
                            return leafComponent;
145
                    }
146
            }
147
            
148
                public void cancelCellEditing() {
149
                        // TODO Auto-generated method stub
150
                        
151
                }
152

    
153
                public boolean stopCellEditing() {
154
                        // TODO Auto-generated method stub
155
                        return false;
156
                }
157

    
158
                public Object getCellEditorValue() {
159
                        // TODO Auto-generated method stub
160
                        return null;
161
                }
162

    
163
                public boolean isCellEditable(EventObject anEvent) {
164
                        // TODO Auto-generated method stub
165
                        return false;
166
                }
167

    
168
                public boolean shouldSelectCell(EventObject anEvent) {
169
                        // TODO Auto-generated method stub
170
                        return false;
171
                }
172

    
173
                public void addCellEditorListener(CellEditorListener l) {
174
                        // TODO Auto-generated method stub
175
                        
176
                }
177

    
178
                public void removeCellEditorListener(CellEditorListener l) {
179
                        // TODO Auto-generated method stub
180
                        
181
                }
182
            
183
    }
184
}
185

    
186
class DimensionTreeModel implements TreeModel {
187
    
188

    
189
        WMSLayerNode root;
190

    
191
        public DimensionTreeModel(WMSLayerNode root){
192
        this.root = root;
193
        
194
    }
195
    public Object getRoot() {
196
        return root;
197
    }
198

    
199
    public int getChildCount(Object parent) {
200
        int count=0;
201
        
202
        if (parent == root)
203
            count = ((WMSLayerNode) parent).getChildren().size();
204
        else
205
            count = ((WMSLayerNode) parent).getDimensions().size();
206
        return count;
207
     }
208

    
209
    public boolean isLeaf(Object node) {
210
        return (node instanceof IFMapWMSDimension);
211
    }
212

    
213
    public void addTreeModelListener(TreeModelListener l) {
214
    }
215

    
216
    public void removeTreeModelListener(TreeModelListener l) {
217
    }
218

    
219
    public Object getChild(Object parent, int index) {
220
        if (parent instanceof IFMapWMSDimension)
221
            return null;
222
        if (parent == root)
223
            return ((WMSLayerNode) parent).getChildren().get(index);
224
        
225
        return ((WMSLayerNode) parent).getDimensions().get(index);
226
    }
227

    
228
    public int getIndexOfChild(Object parent, Object child) {
229
        if (parent instanceof IFMapWMSDimension){ 
230
            return -1;   
231
        }
232
         
233
        WMSLayerNode l = (WMSLayerNode)parent;
234
        if (l.getParent()==null){
235
            for (int i = 0; i < l.getChildren().size(); i++) {
236
                if (l.getChildren().get(i).equals(child)){
237
                   return i;
238
                }
239
            }
240
        } else {
241
            for (int i = 0; i < l.getDimensions().size(); i++) {
242
                if (l.getChildren().get(i).equals(child)){
243
                    return i;
244
                }
245
            }
246
        }
247
        return -1;
248
    }
249

    
250
    public void valueForPathChanged(TreePath path, Object newValue) {
251
        
252
    }  
253
    
254
    /**
255
     * Adds a new branch to this tree. It must be a layer node.
256
     * @param node
257
     */
258
    public void addLayerBranch(WMSLayerNode node){
259
        WMSLayerNode myNode = (WMSLayerNode) node.clone();
260
        myNode.setParent((WMSLayerNode) getRoot());
261
        ((WMSLayerNode)getRoot()).getChildren().add(myNode);
262
    }
263
}
264