Revision 8458 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/SymbolEditor.java

View differences:

SymbolEditor.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.4  2006-10-30 19:30:35  jaume
46
* Revision 1.5  2006-10-31 16:16:34  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.4  2006/10/30 19:30:35  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.3  2006/10/29 23:53:49  jaume
50 53
* *** empty log message ***
51 54
*
......
108 111
    private ArrayList layers;
109 112
    private ActionListener cmbTypeActionListener;
110 113

  
111
    private AbstractTypeSymbolEditorPanel[] polygonOptions;
114
    private AbstractTypeSymbolEditorPanel[] tabs;
115
	private AbstractTypeSymbolEditorPanel[] pointOptions;
112 116

  
113 117

  
114 118
    public SymbolEditor(ISymbol symbol, int shapeType) {
......
135 139

  
136 140
    				if (tabbedPane != null)
137 141
    					getPnlCenter().remove(tabbedPane);
138
    				JPanel[] tabs = ((AbstractTypeSymbolEditorPanel) getCmbType().getSelectedItem()).getTabs();
142
    				AbstractTypeSymbolEditorPanel options =
143
    					(AbstractTypeSymbolEditorPanel) getCmbType().getSelectedItem();
144
    				options.refreshControls(getSelectedLayerIndex());
145
    				JPanel[] tabs = options.getTabs();
139 146
    				tabbedPane = new JTabbedPane();
140 147
    				tabbedPane.setPreferredSize(new Dimension(300, 300));
141 148
    				for (int i = 0; i < tabs.length; i++) {
......
147 154
    		}
148 155
    	};
149 156

  
157
    	Comparator tabComparator = new Comparator() {
158
			public int compare(Object o1, Object o2) {
159
				if (! (o1 instanceof AbstractTypeSymbolEditorPanel
160
					|| o1 instanceof AbstractTypeSymbolEditorPanel))
161
					throw new IllegalArgumentException(PluginServices.getText(this, "trying_to_add_a_non_TypeSymbolEditor_panel"));
162
				AbstractTypeSymbolEditorPanel pnl1 = (AbstractTypeSymbolEditorPanel) o1,
163
				pnl2 = (AbstractTypeSymbolEditorPanel) o2;
164
				int result = pnl1.getName().compareTo(pnl2.getName());
165
				if (result == 0)
166
					throw new IllegalArgumentException(PluginServices.getText(this, "two_panels_with_the_same_name"));
167
				return result;
168
			}
169
		};
170
		TreeSet set = new TreeSet(tabComparator);
171

  
172
    	if (shapeType == FShape.POLYGON)
150 173
    	{
151 174
    		// Polygon options
152
        	TreeSet set = new TreeSet(new Comparator() {
153
    			public int compare(Object o1, Object o2) {
154
    				if (! (o1 instanceof AbstractTypeSymbolEditorPanel
155
    					|| o1 instanceof AbstractTypeSymbolEditorPanel))
156
    					throw new IllegalArgumentException(PluginServices.getText(this, "trying_to_add_a_non_TypeSymbolEditor_panel"));
157
    				AbstractTypeSymbolEditorPanel pnl1 = (AbstractTypeSymbolEditorPanel) o1,
158
    				pnl2 = (AbstractTypeSymbolEditorPanel) o2;
159
    				int result = pnl1.getName().compareTo(pnl2.getName());
160
    				if (result == 0)
161
    					throw new IllegalArgumentException(PluginServices.getText(this, "two_panels_with_the_same_name"));
162
    				return result;
163
    			}
164
        	});
165 175

  
166 176
        	// add here your options for polygon symbols
167 177
        	set.add(new SimpleFill(SymbolEditor.this));
168 178
        	set.add(new MarkerFill(SymbolEditor.this));
169
        	polygonOptions = (AbstractTypeSymbolEditorPanel[]) set.toArray(new AbstractTypeSymbolEditorPanel[0]);
170
        };
179
        }
180
        else if (shapeType == FShape.POINT)
181
        {
182
        	// Point options
171 183

  
184
        	// add here your options for point symbol
185
        	set.add(new CharacterMarker(SymbolEditor.this));
186
        }
187
    	tabs = (AbstractTypeSymbolEditorPanel[]) set.toArray(new AbstractTypeSymbolEditorPanel[0]);
188

  
172 189
        this.setLayout(new BorderLayout());
173 190
        this.add(getPnlWest(), BorderLayout.WEST);
174 191
        this.add(getPnlCenter(), BorderLayout.CENTER);
......
327 344

  
328 345
    private JComboBox getCmbType() {
329 346
        if (cmbType == null) {
330
        	AbstractTypeSymbolEditorPanel[] tabs = null;
331
            switch (shapeType) {
332
            case FShape.POINT:
333
                break;
334
            case FShape.LINE:
335
                break;
336
            case FShape.POLYGON:
337
            	tabs = polygonOptions;
338
                break;
339
            default:
340
            }
341 347
            cmbType = new JComboBox(tabs);
342 348
            cmbType.addActionListener(cmbTypeActionListener);
343 349
        }
......
357 363
		refresh();
358 364
	}
359 365

  
360
	protected void addLayerToSymbol(XMLEntity layerXML) {
366
	protected void setLayerToSymbol(int layerIndex, XMLEntity layerXML) {
361 367
    	XMLEntity symXML = symbol.getXMLEntity();
362
    	symXML.addChild(layerXML);
368
    	ArrayList layers = new ArrayList();
369
    	for (int i = 0; i < symXML.getChildrenCount(); i++) {
370
			layers.add(symXML.getChild(i));
371
		}
372
    	layers.add(layerIndex, layerXML);
373
    	symXML.removeAllChildren();
374
    	for (int i = 0; i < layers.size(); i++) {
375
    		symXML.addChild((XMLEntity) layers.get(i));
376
		}
377
    	symbol.setXMLEntity(symXML);
363 378
    	refresh();
364 379
    }
365 380

  
......
372 387
    	getSymbolPreview().setSymbol(symbol);
373 388
	}
374 389

  
390

  
391
	public int getSelectedLayerIndex() {
392
		// TODO de moment zero, per? en un futur s'espera que hi haja m?s d'una capa
393
		return 0;
394
	}
395

  
375 396
}  //  @jve:decl-index=0:visual-constraint="10,10"

Also available in: Unified diff