Revision 3554 branches/gvSIG_WMSv2/extensions/extWMS/src/com/iver/cit/gvsig/gui/panels/DimensionTree.java

View differences:

DimensionTree.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1.2.3  2006-01-05 23:15:53  jaume
46
* Revision 1.1.2.4  2006-01-09 18:10:38  jaume
47
* casi con el time dimension
48
*
49
* Revision 1.1.2.3  2006/01/05 23:15:53  jaume
47 50
* *** empty log message ***
48 51
*
49 52
* Revision 1.1.2.2  2006/01/04 18:09:02  jaume
......
63 66
import java.awt.event.ActionEvent;
64 67
import java.awt.event.ActionListener;
65 68
import java.util.EventObject;
69
import java.util.Hashtable;
66 70

  
67 71
import javax.swing.JButton;
68 72
import javax.swing.JLabel;
......
79 83
import com.iver.cit.gvsig.fmap.layers.IFMapWMSDimension;
80 84
import com.iver.cit.gvsig.fmap.layers.TimeDimension;
81 85
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
86
import com.iver.cit.gvsig.gui.beans.BeanListener;
87
import com.iver.cit.gvsig.gui.beans.panels.EditionPanel;
82 88
/**
83 89
 * @author jaume
84 90
 *
85 91
 */
86 92
public class DimensionTree extends JTree {
87 93
	private int rowHeight = 28;
94
    private EditionPanel ep = null;
95
    private IFMapWMSDimension current = null;
96
    
88 97
    public DimensionTree(){
89 98
        super();
90 99
        initialize();
......
94 103
        setToggleClickCount(1);
95 104
        setRowHeight(rowHeight);
96 105
        setCellRenderer(new DimensionTreeCellRenderer());
97
        setCellEditor(new DimensionTreeCellEditor());
106
        ep = new EditionPanel();
107
        ep.addListener(new BeanListener(){
108

  
109
            public void beanValueChanged(Object value) {
110
                Object[] obj = (Object[]) value;
111
                Integer min = (Integer) obj[0];
112
                Integer max = (Integer) obj[1];
113
                String expression = (String) obj[2];
114
                
115
                DimensionTreeModel model = (DimensionTreeModel) getModel();
116
                model.setMin(current, min);
117
                model.setMax(current, max);
118
                model.setExpr(current, expression);
119
            }
120
            
121
        });
122
        
123
        addMouseListener(new java.awt.event.MouseAdapter() { 
124
            public void mouseClicked(java.awt.event.MouseEvent e) {
125
                TreePath tp = getSelectionPath();
126
                if (tp == null)
127
                    return;
128
                Object[] objects = tp.getPath();
129
                if (!(objects[objects.length-1] instanceof IFMapWMSDimension))
130
                    return;
131
                current = (IFMapWMSDimension) objects[objects.length-1];
132
                
133
                // Build the edition panel.
134
                DimensionTreeModel model = (DimensionTreeModel) getModel();
135
                ep.setProperties(current, model.getMin(current), model.getMax(current));
136
                PluginServices.getMDIManager().addView(ep);
137
            }
138
        });
98 139
    }
99 140
    
100 141
    private class DimensionTreeCellRenderer implements TreeCellRenderer {
......
118 159
    	}
119 160
    }
120 161
    
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 162
}
185 163

  
186 164
class DimensionTreeModel implements TreeModel {
187
    
165
    Hashtable lowLimits   = new Hashtable();
166
    Hashtable highLimits  = new Hashtable();
167
    Hashtable expressions = new Hashtable();
188 168

  
189 169
	WMSLayerNode root;
190 170

  
191 171
	public DimensionTreeModel(WMSLayerNode root){
192 172
        this.root = root;
173
/**
174
     * @param currentDimensionNode
175
     * @param min
176
     */
177
          
193 178
        
194 179
    }
180
    /**
181
     * @param currentDimensionNode
182
     * @param min
183
     */
184
    public void setMin(IFMapWMSDimension currentDimensionNode, Integer val) {
185
        lowLimits.put(currentDimensionNode, val);
186
    }
187
    /**
188
     * @param currentDimensionNode
189
     * @param min
190
     */
191
    public void setMax(IFMapWMSDimension currentDimensionNode, Integer val) {
192
        highLimits.put(currentDimensionNode, val);
193
    }
194
    /**
195
     * @param currentDimensionNode
196
     * @param min
197
     */
198
    public void setExpr(IFMapWMSDimension currentDimensionNode, String val) {
199
        expressions.put(currentDimensionNode, val);
200
    }
201
    
195 202
    public Object getRoot() {
196 203
        return root;
197 204
    }
......
260 267
        myNode.setParent((WMSLayerNode) getRoot());
261 268
        ((WMSLayerNode)getRoot()).getChildren().add(myNode);
262 269
    }
270
    
271
    public Integer getMin(IFMapWMSDimension dim){
272
        Integer min = (Integer) lowLimits.get(dim);
273
        if (min == null)
274
            min = new Integer(1);
275
        return min;
276
    }
277
    
278
    public Integer getMax(IFMapWMSDimension dim){
279
        Integer max = (Integer) highLimits.get(dim);
280
        if (max == null)
281
            max = new Integer(dim.valueCount());
282
       
283
        return max;
284
    }
263 285
}
264 286

  

Also available in: Unified diff