Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/app/gui/styling/SymbolEditor.java

View differences:

SymbolEditor.java
29 29
import java.awt.event.ActionEvent;
30 30
import java.awt.event.ActionListener;
31 31
import java.lang.reflect.Constructor;
32
import java.util.ArrayList;
33 32
import java.util.Comparator;
34
import java.util.Hashtable;
35
import java.util.Iterator;
36 33
import java.util.List;
37
import java.util.Map;
38 34
import java.util.TreeSet;
39

  
40 35
import javax.swing.BorderFactory;
41 36
import javax.swing.JComboBox;
42 37
import javax.swing.JLabel;
43 38
import javax.swing.JPanel;
44 39
import javax.swing.JTabbedPane;
45
import javax.swing.SwingUtilities;
46 40
import org.apache.commons.lang3.mutable.MutableObject;
47

  
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

  
51 41
import org.gvsig.andami.PluginServices;
52 42
import org.gvsig.andami.messages.NotificationManager;
53 43
import org.gvsig.andami.ui.mdiManager.IWindow;
......
59 49
import org.gvsig.fmap.geom.GeometryLocator;
60 50
import org.gvsig.fmap.geom.GeometryManager;
61 51
import org.gvsig.fmap.geom.type.GeometryType;
62
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
63
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
64 52
import org.gvsig.fmap.mapcontext.MapContextLocator;
65 53
import org.gvsig.fmap.mapcontext.MapContextManager;
66 54
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
......
70 58
import org.gvsig.i18n.Messages;
71 59
import org.gvsig.symbology.swing.SymbologySwingLocator;
72 60
import org.gvsig.symbology.swing.SymbologySwingManager;
61
import org.slf4j.Logger;
62
import org.slf4j.LoggerFactory;
73 63

  
74 64
/**
75
 * Creates the panel that is used to control the properties of a symbol in
76
 * order to modify or check them and to create a new one.
65
 * Creates the panel that is used to control the properties of a symbol in order
66
 * to modify or check them and to create a new one.
77 67
 *
78 68
 * @author jaume dominguez faus - jaume.dominguez@iver.es
79 69
 *
80 70
 */
81 71
public class SymbolEditor extends JPanel implements IWindow {
82
	private static final long serialVersionUID = 9209260593958625497L;
83
	
84
	private static final GeometryManager GEOMETRY_MANAGER = 
85
	    GeometryLocator.getGeometryManager();
86
	
87
	private static final Logger LOG =
88
	    LoggerFactory.getLogger(SymbolEditor.class);
89
	
90
	private WindowInfo wi;
91
	private JPanel pnlWest = null;
92
	private JPanel pnlCenter = null;
93
	private JPanel pnlPreview = null;
94
	private JPanel pnlLayers = null;
95
	private AcceptCancelPanel okCancelPanel;
96
	private ISymbol symbol;
97
	private SymbolPreviewer symbolPreview = null;
98
	private JPanel pnlTypeAndUnits = null;
99
	private JComboBox cmbType;
100
	private JComboBoxUnits cmbUnits;
101
	private JTabbedPane tabbedPane = null;
102
	private GeometryType shapeType;
103
	private ActionListener cmbTypeActionListener;
104 72

  
105
	private AbstractTypeSymbolEditor[] tabs;
106
	private SymbolLayerManager layerManager;
107
	private boolean replacing = false;
108
	private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
109
	
110
	private ISymbol oldSymbol;
111
	
112
	private MapContextManager mapContextManager = MapContextLocator
113
			.getMapContextManager();
114
        private transient FeatureStore featureStore;
115
        private transient MutableObject<Feature> sampleFeature;
116
	
117
	public SymbolEditor(ISymbol symbol, GeometryType geometryType) {
118
	    super();
119
	    initialize(symbol, geometryType);
120
	}	
121
	
122
	public SymbolEditor(ISymbol symbol, int shapeType) {
123
	    super();
124
	    try {
73
    private static final long serialVersionUID = 9209260593958625497L;
74

  
75
    private static final GeometryManager GEOMETRY_MANAGER
76
            = GeometryLocator.getGeometryManager();
77

  
78
    private static final Logger LOG
79
            = LoggerFactory.getLogger(SymbolEditor.class);
80

  
81
    private WindowInfo wi;
82
    private JPanel pnlWest = null;
83
    private JPanel pnlCenter = null;
84
    private JPanel pnlPreview = null;
85
    private JPanel pnlLayers = null;
86
    private AcceptCancelPanel okCancelPanel;
87
    private ISymbol symbol;
88
    private SymbolPreviewer symbolPreview = null;
89
    private JPanel pnlTypeAndUnits = null;
90
    private JComboBox cmbType;
91
    private JComboBoxUnits cmbUnits;
92
    private JTabbedPane tabbedPane = null;
93
    private GeometryType shapeType;
94
    private ActionListener cmbTypeActionListener;
95

  
96
    private AbstractTypeSymbolEditor[] tabs;
97
    private SymbolLayerManager layerManager;
98
    private boolean replacing = false;
99
    private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
100

  
101
    private ISymbol oldSymbol;
102

  
103
    private MapContextManager mapContextManager = MapContextLocator
104
            .getMapContextManager();
105
    private transient FeatureStore featureStore;
106
    private transient MutableObject<Feature> sampleFeature;
107

  
108
    public SymbolEditor(ISymbol symbol, GeometryType geometryType) {
109
        super();
110
        initialize(symbol, geometryType);
111
    }
112

  
113
    public SymbolEditor(ISymbol symbol, int shapeType) {
114
        super();
115
        try {
125 116
            GeometryType geometryType = GEOMETRY_MANAGER.getGeometryType(shapeType, SUBTYPES.GEOM2D);
126 117
            initialize(symbol, geometryType);
127
        } catch (GeometryTypeNotSupportedException e1) {
118
        } catch (Exception e1) {
128 119
            LOG.error("Impossible to get the geometry type", e1);
129
        } catch (GeometryTypeNotValidException e1) {
130
            LOG.error("Impossible to get the geometry type", e1);
131
        }	   
132
	}   
133
	    
134
	
135
	/**
136
	 * Constructor method
137
	 *
138
	 * @param symbol ISymbol
139
	 * @param shapeType int
140
	 */
141
	private void initialize(ISymbol symbol, GeometryType shapeType) {
142
//////////	/-------------------------------------
143
//      removing the Geometry.TYPES.TEXT: this code can not be executed
144
//		if (shapeType == Geometry.TYPES.TEXT) {
145
////			this.symbol = symbol == null ? new SimpleTextSymbol(): symbol;
146
//			this.symbol = symbol == null ? SymbologyLocator.getSymbologyManager().createSimpleTextSymbol(): symbol;
147
//		} else {
148
//////////	/-------------------------------------
120
        }
121
    }
149 122

  
150
			if (!(symbol instanceof IMultiLayerSymbol)) {
151
				// this is a simple symbol (or null one); it will be
152
				// converted to a multilayer one to accept layer addition
153
				IMultiLayerSymbol nSym =
154
						mapContextManager.getSymbolManager()
155
						.createMultiLayerSymbol(shapeType.getType());
123
    /**
124
     * Constructor method
125
     *
126
     * @param symbol ISymbol
127
     * @param shapeType int
128
     */
129
    private void initialize(ISymbol symbol, GeometryType shapeType) {
130
        if (!(symbol instanceof IMultiLayerSymbol)) {
131
            // this is a simple symbol (or null one); it will be
132
            // converted to a multilayer one to accept layer addition
133
            IMultiLayerSymbol nSym
134
                    = mapContextManager.getSymbolManager()
135
                            .createMultiLayerSymbol(shapeType.getType());
136
            nSym.addLayer(symbol);
156 137

  
157
//				if (!(symbol instanceof FSymbol)) {
158
					nSym.addLayer(symbol);
159
//				}
138
            if (symbol instanceof CartographicSupport) {
139
                CartographicSupport cs = (CartographicSupport) symbol;
140
                CartographicSupport nCs = (CartographicSupport) nSym;
141
                nCs.setReferenceSystem(cs.getReferenceSystem());
142
                nCs.setUnit(cs.getUnit());
143
            }
160 144

  
161
				if (symbol instanceof CartographicSupport) {
162
					CartographicSupport cs = (CartographicSupport) symbol;
163
					CartographicSupport nCs = (CartographicSupport) nSym;
164
					nCs.setReferenceSystem(cs.getReferenceSystem());
165
					nCs.setUnit(cs.getUnit());
166
				}
145
            this.symbol = nSym;
146
        } else {
147
            this.symbol = symbol;
148
        }
167 149

  
168
				this.symbol = nSym;
169
			} else {
170
				this.symbol = symbol;
171
			}
150
        // apply units and reference system to comboboxes
151
        if (this.symbol instanceof CartographicSupport) {
152
            CartographicSupport cs = (CartographicSupport) this.symbol;
153
            getCmbUnits().setSelectedUnitIndex(cs.getUnit());
154
            getCmbUnitsReferenceSystem().
155
                    setSelectedIndex(cs.getReferenceSystem());
172 156

  
173
			// apply units and reference system to comboboxes
174
			if (this.symbol instanceof CartographicSupport) {
175
				CartographicSupport cs = (CartographicSupport) this.symbol;
176
				getCmbUnits().setSelectedUnitIndex(cs.getUnit());
177
				getCmbUnitsReferenceSystem().
178
					setSelectedIndex(cs.getReferenceSystem());
157
        }
179 158

  
180
			}
159
        try {
160
            this.oldSymbol = (ISymbol) this.symbol.clone();
161
        } catch (CloneNotSupportedException e) {
162
            NotificationManager.addWarning("Symbol layer", e);
163
        }
164
        this.shapeType = shapeType;
165
        initialize();
166
    }
181 167

  
182
//		}
183
		try {
184
			this.oldSymbol = (ISymbol) this.symbol.clone();
185
		} catch (CloneNotSupportedException e) {
186
			NotificationManager.addWarning("Symbol layer", e);
187
		}
188
		this.shapeType = shapeType;
189
		initialize();
190
	}
168
    /**
169
     * This method initializes this
170
     *
171
     */
172
    private void initialize() {
173
        SymbologySwingManager symbologySwingManager = SymbologySwingLocator.getSwingManager();
174
        cmbTypeActionListener = new ActionListener() {
175
            int prevIndex = -2;
191 176

  
192
	/**
193
	 * This method initializes this
194
	 *
195
	 */
196
	private void initialize() {
197
                SymbologySwingManager symbologySwingManager = SymbologySwingLocator.getSwingManager();
198
		cmbTypeActionListener = new ActionListener() {
199
			int prevIndex = -2;
177
            @Override
178
            public void actionPerformed(ActionEvent e) {
179
                int index = getCmbType().getSelectedIndex();
180
                if (prevIndex != index) {
181
                    // needs to refresh
182
                    prevIndex = index;
200 183

  
201
			public void actionPerformed(ActionEvent e) {
202
				int index = getCmbType().getSelectedIndex();
203
				if (prevIndex != index) {
204
					// needs to refresh
205
					prevIndex = index;
184
                    AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType()
185
                            .getSelectedItem();
206 186

  
207
					AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType()
208
							.getSelectedItem();
187
                    if (layerManager != null) {
188
                        ISymbol l = layerManager.getSelectedLayer();
209 189

  
210
//////////			/-------------------------------------
211
					if (layerManager!=null) {
212
//////////			/-------------------------------------
213
							ISymbol l = layerManager.getSelectedLayer();
190
                        // if the symbol is not null and is it managed by the "options" class
191
                        // refresh the controls
192
                        if (l != null && options.canManageSymbol(l)) {
193
                            if (l instanceof CartographicSupport) {
194
                                CartographicSupport cs = (CartographicSupport) l;
195
                                getCmbUnits().setSelectedUnitIndex(cs.getUnit());
196
                                getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem());
197
                            }
198
                            options.refreshControls(l);
199
                        }
214 200

  
215
						// if the symbol is not null and is it managed by the "options" class
216
						// refresh the controls
217
						if (l != null
218
//								&& l.getClass().equals(options.getSymbolClass())) {
219
								&& options.canManageSymbol(l)) {
220
							if (l instanceof CartographicSupport) {
221
								CartographicSupport cs = (CartographicSupport) l;
222
								getCmbUnits().setSelectedUnitIndex(cs.getUnit());
223
								getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem());
224
							}
225
							options.refreshControls(l);
226
						}
201
                        replaceOptions(options);
202
                        options.refreshControls(l);
203
                    } else {
204
                        replaceOptions(options);
205
                    }
206
                }
207
            }
208
        };
227 209

  
228
						replaceOptions(options);
229
//////////			/-------------------------------------
230
					} else {
231
						replaceOptions(options);
232
					}
233
//////////			/-------------------------------------
210
        Comparator tabComparator = (Comparator) (Object o1, Object o2) -> {
211
            AbstractTypeSymbolEditor pnl1 = (AbstractTypeSymbolEditor) o1;
212
            AbstractTypeSymbolEditor pnl2 = (AbstractTypeSymbolEditor) o2;
213
            int result = pnl1.getName().compareTo(pnl2.getName());
214
            return result;
215
        };
234 216

  
235
				}
236
			}
237
		};
217
        TreeSet set = new TreeSet(tabComparator);
218
        List editors = symbologySwingManager.getSymbolEditorClassesByGeometryType(shapeType);
219
        Class[] constrLocator = new Class[]{SymbolEditor.class};
220
        Object[] constrInitargs = new Object[]{this};
221
        for (int i = 0; i < editors.size(); i++) {
222
            Class editorClass = (Class) editors.get(i);
223
            try {
224
                Constructor c = editorClass.getConstructor(constrLocator);
225
                AbstractTypeSymbolEditor instance = (AbstractTypeSymbolEditor) c.newInstance(constrInitargs);
226
                instance.setFeatureStore(featureStore);
227
                set.add(instance);
228
            } catch (Exception e) {
229
                NotificationManager.addError(Messages.getText("failed_installing_symbol_editor") + " "
230
                        + editorClass.getName(), e);
231
            }
232
        }
233
        tabs = (AbstractTypeSymbolEditor[]) set
234
                .toArray(new AbstractTypeSymbolEditor[0]);
238 235

  
239
		Comparator tabComparator = new Comparator() {
240
			public int compare(Object o1, Object o2) {
241
				AbstractTypeSymbolEditor pnl1 = (AbstractTypeSymbolEditor) o1;
242
				AbstractTypeSymbolEditor pnl2 = (AbstractTypeSymbolEditor) o2;
243
				int result = pnl1.getName().compareTo(pnl2.getName());
244
				return result;
245
			}
246
		};
236
        this.setLayout(new BorderLayout());
237
        this.add(getPnlWest(), BorderLayout.WEST);
238
        this.add(getPnlCenter(), BorderLayout.CENTER);
239
        this.add(getOkCancelPanel(), BorderLayout.SOUTH);
247 240

  
241
        cmbTypeActionListener.actionPerformed(null);
242
        refresh();
243
    }
248 244

  
249
		TreeSet set = new TreeSet(tabComparator);
250
		List editors = symbologySwingManager.getSymbolEditorClassesByGeometryType(shapeType);
251
		Class[] constrLocator = new Class[] {SymbolEditor.class};
252
		Object[] constrInitargs = new Object[] { this };
253
		for (int i = 0; i < editors.size(); i++) {
254
			Class editorClass = (Class) editors.get(i);
255
			try {
256
				Constructor c = editorClass.getConstructor(constrLocator);
257
				AbstractTypeSymbolEditor instance = (AbstractTypeSymbolEditor) c.newInstance(constrInitargs); 
258
                                instance.setFeatureStore(featureStore);
259
				set.add(instance);
260
			} catch (Exception e) {
261
				NotificationManager.addError(Messages.getText("failed_installing_symbol_editor")+" "
262
						+editorClass.getName(), e);
263
			}
264
		};
265
 		tabs = (AbstractTypeSymbolEditor[]) set
266
				.toArray(new AbstractTypeSymbolEditor[0]);
245
    /**
246
     * Returns an array of tabs. The value of this array will depend on the
247
     * symbol selected. For example, if the symbol is composed by lines this
248
     * method will return tha tabs that allow the user to modify a simple line
249
     * symbol(in this case simple line and arrow decorator tabs)
250
     *
251
     * @param sym
252
     * @return tabs[] AbstractTypeSymbolEditor[]
253
     */
254
    private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
255
        if (sym == null) {
256
            return tabs[0];
257
        }
258
        for (AbstractTypeSymbolEditor tab : tabs) {
259
            if (tab.canManageSymbol(sym)) {
260
                return tab;
261
            }
262
        }
263
        return tabs[0];
264
    }
267 265

  
268
		this.setLayout(new BorderLayout());
269
		this.add(getPnlWest(), BorderLayout.WEST);
270
		this.add(getPnlCenter(), BorderLayout.CENTER);
271
		this.add(getOkCancelPanel(), BorderLayout.SOUTH);
266
    /**
267
     * Initializes the OkCancel panel where the accept and cancel buttons will
268
     * be placed
269
     *
270
     * @return okCancelPanel AcceptCancelPanel
271
     */
272
    private AcceptCancelPanel getOkCancelPanel() {
273
        if (okCancelPanel == null) {
274
            ActionListener action = (ActionEvent e) -> {
275
                if ("CANCEL".equals(e.getActionCommand())) {
276
                    symbol = oldSymbol;
277
                }
278
                PluginServices.getMDIManager().closeWindow(
279
                        SymbolEditor.this);
280
            };
281
            okCancelPanel = new AcceptCancelPanel(action, action);
282
        }
283
        return okCancelPanel;
284
    }
272 285

  
273
		cmbTypeActionListener.actionPerformed(null);
274
		refresh();
275
	}
276
	/**
277
	 * Returns an array of tabs. The value of this array will depend on the
278
	 * symbol selected. For example, if the symbol is composed by lines this
279
	 * method will return tha tabs that allow the user to modify a simple line
280
	 * symbol(in this case simple line and arrow decorator tabs)
281
	 * @param sym
282
	 * @return tabs[] AbstractTypeSymbolEditor[]
283
	 */
284
	private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
285
		if (sym == null) {
286
			return tabs[0];
287
		}
288
		for (int i = 0; i < tabs.length; i++) {
289
//			if (tabs[i].getSymbolClass().equals(sym.getClass())) {
290
			if (tabs[i].canManageSymbol(sym)) {
291
				return tabs[i];
292
			}
293
		}
294
		return tabs[0];
295
	}
296
	/**
297
	 * Initializes the OkCancel panel where the accept and cancel buttons
298
	 * will be placed
299
	 * @return okCancelPanel AcceptCancelPanel
300
	 */
301
	private AcceptCancelPanel getOkCancelPanel() {
302
		if (okCancelPanel == null) {
303
			ActionListener action = new ActionListener() {
304
				public void actionPerformed(ActionEvent e) {
305
					if ("CANCEL".equals(e.getActionCommand())) {
306
						symbol = oldSymbol;
307
					}
308
					PluginServices.getMDIManager().closeWindow(
309
							SymbolEditor.this);
310
				}
311
			};
312
			okCancelPanel = new AcceptCancelPanel(action, action);
313
		}
314
		return okCancelPanel;
315
	}
286
    @Override
287
    public WindowInfo getWindowInfo() {
288
        if (wi == null) {
289
            wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
290
            wi.setWidth(750);
291
            wi.setHeight(500);
292
            wi.setTitle(Messages.getText("symbol_property_editor"));
293
        }
294
        return wi;
295
    }
316 296

  
317
	public WindowInfo getWindowInfo() {
318
		if (wi == null) {
319
			wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
320
			wi.setWidth(750);
321
			wi.setHeight(500);
322
			wi.setTitle(Messages.getText("symbol_property_editor"));
323
		}
324
		return wi;
325
	}
297
    public ISymbol getSymbol() {
298
        if (symbol instanceof CartographicSupport) {
299
            CartographicSupport cs = (CartographicSupport) symbol;
300
            cs.setUnit(getUnit());
301
            cs.setReferenceSystem(getReferenceSystem());
302
        }
303
        return symbol;
304
    }
326 305

  
327
	public ISymbol getSymbol() {
328
		if (symbol instanceof CartographicSupport) {
329
			CartographicSupport cs = (CartographicSupport) symbol;
330
			cs.setUnit(getUnit());
331
			cs.setReferenceSystem(getReferenceSystem());
332
		}
333
//
334
//		if (symbol instanceof MultiLayerLineSymbol) {
335
//			MultiLayerLineSymbol mLineSym = (MultiLayerLineSymbol) symbol;
336
//			double lineWidth = 0;
337
//			for (int i = 0; i < mLineSym.getLayerCount(); i++) {
338
//				lineWidth = Math.max(lineWidth, ((ILineSymbol) mLineSym.getLayer(i)).getLineWidth());
339
//			}
340
//
341
//			if (mLineSym.getLineWidth() != lineWidth)
342
//				mLineSym.setLineWidth(lineWidth);
343
//		}
344
		return symbol;
345
	}
346
	/**
347
	 * Initializes the west panel
348
	 * @return
349
	 */
350
	private JPanel getPnlWest() {
351
		if (pnlWest == null) {
352
			pnlWest = new JPanel();
353
			pnlWest.setLayout(new BorderLayout());
354
			pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH);
355
//////////	/-------------------------------------
356
			if (symbol instanceof IMultiLayerSymbol) {
357
//////////		/-------------------------------------
306
    /**
307
     * Initializes the west panel
308
     *
309
     * @return
310
     */
311
    private JPanel getPnlWest() {
312
        if (pnlWest == null) {
313
            pnlWest = new JPanel();
314
            pnlWest.setLayout(new BorderLayout());
315
            pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH);
316
            if (symbol instanceof IMultiLayerSymbol) {
317
                pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH);
318
            } // otherwise, no layer manager needed
319
        }
320
        return pnlWest;
321
    }
358 322

  
323
    /**
324
     * Initializes the center panel that shows the properties of a symbol.
325
     *
326
     * @return pnlCenter JPanel
327
     */
328
    private JPanel getPnlCenter() {
329
        if (pnlCenter == null) {
330
            pnlCenter = new JPanel(new BorderLayout());
331
            pnlCenter.setBorder(BorderFactory.createTitledBorder(null,
332
                    Messages.getText("properties")));
333
            pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH);
334
        }
335
        return pnlCenter;
336
    }
359 337

  
360
				pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH);
338
    /**
339
     * Initializes the preview panel that allows the user to see a
340
     * previsualization of the final symbol
341
     *
342
     * @return pnlPreview JPanel
343
     */
344
    private JPanel getPnlPreview() {
345
        if (pnlPreview == null) {
346
            pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
347
            pnlPreview.setBorder(BorderFactory.createTitledBorder(null,
348
                    Messages.getText("preview")));
349
            pnlPreview.add(getSymbolPreviewer());
350
        }
351
        return pnlPreview;
352
    }
361 353

  
362
//////////		/-------------------------------------
363
			} // otherwise, no layer manager needed
364
//////////	/-------------------------------------
365
		}
366
		return pnlWest;
367
	}
368
	/**
369
	 * Initializes the center panel that shows the properties of a symbol.
370
	 *
371
	 * @return pnlCenter JPanel
372
	 */
373
	private JPanel getPnlCenter() {
374
		if (pnlCenter == null) {
375
			pnlCenter = new JPanel(new BorderLayout());
376
			pnlCenter.setBorder(BorderFactory.createTitledBorder(null,
377
					Messages.getText("properties")));
378
			pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH);
379
		}
380
		return pnlCenter;
381
	}
382
	/**
383
	 * Initializes the preview panel that allows the user to see a previsualization
384
	 * of the final symbol
385
	 *
386
	 * @return pnlPreview JPanel
387
	 */
388
	private JPanel getPnlPreview() {
389
		if (pnlPreview == null) {
390
			pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
391
			pnlPreview.setBorder(BorderFactory.createTitledBorder(null,
392
					Messages.getText("preview")));
393
			pnlPreview.add(getSymbolPreviewer());
394
		}
395
		return pnlPreview;
396
	}
397
	/**
398
	 * Initializes the Layers panel that shows the different layers created that
399
	 * compose a symbol.
400
	 * @return pnlLayers JPanel
401
	 */
402
	private JPanel getPnlLayers() {
403
		if (pnlLayers == null) {
404
			pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
405
			pnlLayers.setBorder(BorderFactory.createTitledBorder(null,
406
					Messages.getText("layers")));
407
			pnlLayers.add(getLayerManager());
408
		}
409
		return pnlLayers;
410
	}
411
	/**
412
	 * Obtains the layer manager used in the panel that shows the different layers
413
	 * that compose the symbol.
414
	 *
415
	 * @return layerManager SymbolLayerManager
416
	 */
417
	private SymbolLayerManager getLayerManager() {
418
		if (layerManager == null) {
419
			layerManager = new SymbolLayerManager(this);
420
		}
421
		return layerManager;
422
	}
423
	/**
424
	 * Obtains the symbol previewer used in the panel that shows the previsualization
425
	 * of the final symbol.
426
	 *
427
	 * @return symbolPreview getSymbolPreviewer
428
	 */
429
	private SymbolPreviewer getSymbolPreviewer() {
430
		if (symbolPreview == null) {
431
                    symbolPreview = new SymbolPreviewer(getSampleFeature());
432
                    symbolPreview.setPreferredSize(new Dimension(150, 100));
433
		}
434
		return symbolPreview;
435
	}
436
        
437
	/**
438
	 * Initializes the type and units panel where two Jcomboboxes will be placed
439
	 * in order to change the type and the units used in the map.
440
	 *
441
	 * @return pnlTypeAndUnits JPanel
442
	 */
443
	private JPanel getPnlTypeAndUnits() {
444
		if (pnlTypeAndUnits == null) {
445
			pnlTypeAndUnits = new JPanel();
446
			pnlTypeAndUnits.setLayout(new BorderLayout());
447
			JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
448
			aux.add(new JLabel(Messages.getText("type")));
449
			aux.add(getCmbType());
450
			pnlTypeAndUnits.add(aux, BorderLayout.WEST);
354
    /**
355
     * Initializes the Layers panel that shows the different layers created that
356
     * compose a symbol.
357
     *
358
     * @return pnlLayers JPanel
359
     */
360
    private JPanel getPnlLayers() {
361
        if (pnlLayers == null) {
362
            pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
363
            pnlLayers.setBorder(BorderFactory.createTitledBorder(null,
364
                    Messages.getText("layers")));
365
            pnlLayers.add(getLayerManager());
366
        }
367
        return pnlLayers;
368
    }
451 369

  
452
			aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
453
			aux.add(new JLabel(Messages.getText("units")));
454
			aux.add(getCmbUnits());
455
			aux.add(getCmbUnitsReferenceSystem());
456
			pnlTypeAndUnits.add(aux, BorderLayout.EAST);
370
    /**
371
     * Obtains the layer manager used in the panel that shows the different
372
     * layers that compose the symbol.
373
     *
374
     * @return layerManager SymbolLayerManager
375
     */
376
    private SymbolLayerManager getLayerManager() {
377
        if (layerManager == null) {
378
            layerManager = new SymbolLayerManager(this);
379
        }
380
        return layerManager;
381
    }
457 382

  
458
		}
459
		return pnlTypeAndUnits;
460
	}
461
	/**
462
	 * Obtains the JCombobox to select the reference unit to be used in the
463
	 * final representation of the map in this case there are two options (in
464
	 * the paper and in the map).
465
	 * @return
466
	 */
467
	private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
468
		if (cmbUnitsReferenceSystem == null) {
469
			cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
383
    /**
384
     * Obtains the symbol previewer used in the panel that shows the
385
     * previsualization of the final symbol.
386
     *
387
     * @return symbolPreview getSymbolPreviewer
388
     */
389
    private SymbolPreviewer getSymbolPreviewer() {
390
        if (symbolPreview == null) {
391
            symbolPreview = new SymbolPreviewer(getSampleFeature());
392
            symbolPreview.setPreferredSize(new Dimension(150, 100));
393
        }
394
        return symbolPreview;
395
    }
470 396

  
471
		}
397
    /**
398
     * Initializes the type and units panel where two Jcomboboxes will be placed
399
     * in order to change the type and the units used in the map.
400
     *
401
     * @return pnlTypeAndUnits JPanel
402
     */
403
    private JPanel getPnlTypeAndUnits() {
404
        if (pnlTypeAndUnits == null) {
405
            pnlTypeAndUnits = new JPanel();
406
            pnlTypeAndUnits.setLayout(new BorderLayout());
407
            JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
408
            aux.add(new JLabel(Messages.getText("type")));
409
            aux.add(getCmbType());
410
            pnlTypeAndUnits.add(aux, BorderLayout.WEST);
472 411

  
473
		return cmbUnitsReferenceSystem;
474
	}
475
	/**
476
	 * Returns the Jcombobox used to select the reference unit (centimeters,
477
	 * milimeters and so on) to be used in the final representation of the map.
478
	 *
479
	 * @return cmbUnits JUnitsComboBox
480
	 */
481
	private JComboBoxUnits getCmbUnits() {
482
		if (cmbUnits == null) {
483
			cmbUnits = new JComboBoxUnits();
484
		}
485
		return cmbUnits;
486
	}
487
	/**
488
	 * Returns the option selected in the reference unit Jcombobox
489
	 *
490
	 */
491
	public int getUnit() {
492
		return getCmbUnits().getSelectedUnitIndex();
493
	}
412
            aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
413
            aux.add(new JLabel(Messages.getText("units")));
414
            aux.add(getCmbUnits());
415
            aux.add(getCmbUnitsReferenceSystem());
416
            pnlTypeAndUnits.add(aux, BorderLayout.EAST);
494 417

  
495
	public int getReferenceSystem() {
496
		return getCmbUnitsReferenceSystem().getSelectedIndex();
497
	}
498
	/**
499
	 * Returns the Jcombobox used in the panel to select the type of symbol.
500
	 *
501
	 * @return cmbType JComboBox
502
	 */
503
	private JComboBox getCmbType() {
504
		if (cmbType == null) {
505
			cmbType = new JComboBox(tabs);
506
			cmbType.addActionListener(cmbTypeActionListener);
507
		}
508
		return cmbType;
509
	}
510
	/**
511
	 * Sets a layer to a symbol in order to create a final symbol composed
512
	 * by different layers.
513
	 *
514
	 * @param layer
515
	 */
516
	protected void setLayerToSymbol(ISymbol layer) {
517
		int i = getLayerManager().getSelectedLayerIndex();
518
		IMultiLayerSymbol s = (IMultiLayerSymbol) symbol;
519
		if (i >= 0 && i < s.getLayerCount()) {
520
			s.setLayer(s.getLayerCount() - 1 - i, layer);
418
        }
419
        return pnlTypeAndUnits;
420
    }
521 421

  
522
		}
523
		refresh();
524
	}
422
    /**
423
     * Obtains the JCombobox to select the reference unit to be used in the
424
     * final representation of the map in this case there are two options (in
425
     * the paper and in the map).
426
     *
427
     * @return
428
     */
429
    private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
430
        if (cmbUnitsReferenceSystem == null) {
431
            cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
525 432

  
526
	public void refresh() {
527
		getSymbolPreviewer().setSymbol(symbol);
528
		doLayout();
529
		repaint();
530
	}
433
        }
531 434

  
532
	/**
533
	 * <p>
534
	 * Returns the type of the symbol that this panels is created for.<br>
535
	 * </p>
536
	 * <p>
537
	 * Possible values returned by this method are
538
	 * <ol>
539
	 * <li> <b> Geometry.TYPES.POINT </b>, for maker symbols </li>
540
	 * <li> <b> Geometry.TYPES.SURFACE </b>, for fill symbols </li>
541
	 * <li> <b> Geometry.TYPES.CURVE </b>, for line symbols (not yet implemented) </li>
542
	 * <li> <b> Geometry.TYPES.TEXT </b>, for text symbols (not yet implemented) </li>
543
	 * <li> maybe some other in the future </li>
544
	 * </ol>
545
	 * </p>
546
	 *
547
	 * @return
548
	 */
549
	public int getShapeType() {
550
		return shapeType.getType();
551
	}
552
	/**
553
	 * Obtains a new layer
554
	 *
555
	 * @return sym ISymbol
556
	 */
557
	public ISymbol getNewLayer() {
558
		ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem())
559
				.getLayer();
435
        return cmbUnitsReferenceSystem;
436
    }
560 437

  
561
		return sym;
562
	}
438
    /**
439
     * Returns the Jcombobox used to select the reference unit (centimeters,
440
     * milimeters and so on) to be used in the final representation of the map.
441
     *
442
     * @return cmbUnits JUnitsComboBox
443
     */
444
    private JComboBoxUnits getCmbUnits() {
445
        if (cmbUnits == null) {
446
            cmbUnits = new JComboBoxUnits();
447
        }
448
        return cmbUnits;
449
    }
563 450

  
564
	private void replaceOptions(AbstractTypeSymbolEditor options) {
565
		if (!replacing) {
566
			replacing = true;
567
			if (tabbedPane != null) {
568
				getPnlCenter().remove(tabbedPane);
569
			}
570
			JPanel[] tabs = options.getTabs();
571
			tabbedPane = new JTabbedPane();
572
			tabbedPane.setPreferredSize(new Dimension(300, 300));
573
			for (int i = 0; i < tabs.length; i++) {
574
				tabbedPane.addTab(tabs[i].getName(), tabs[i]);
575
			}
576
			getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
577
			getPnlCenter().doLayout();
578
			replacing = false;
579
		}
580
	}
451
    /**
452
     * Returns the option selected in the reference unit Jcombobox
453
     *
454
     */
455
    public int getUnit() {
456
        return getCmbUnits().getSelectedUnitIndex();
457
    }
581 458

  
459
    public int getReferenceSystem() {
460
        return getCmbUnitsReferenceSystem().getSelectedIndex();
461
    }
582 462

  
583
	public void setOptionsPageFor(ISymbol symbol) {
584
		AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol);
463
    /**
464
     * Returns the Jcombobox used in the panel to select the type of symbol.
465
     *
466
     * @return cmbType JComboBox
467
     */
468
    private JComboBox getCmbType() {
469
        if (cmbType == null) {
470
            cmbType = new JComboBox(tabs);
471
            cmbType.addActionListener(cmbTypeActionListener);
472
        }
473
        return cmbType;
474
    }
585 475

  
586
		options.refreshControls(symbol);
587
		getCmbType().setSelectedItem(options);
588
	}
589
	/**
590
	 * Obtains the units to be used for the reference system.
591
	 *
592
	 */
593
	public int getUnitsReferenceSystem() {
594
		return cmbUnitsReferenceSystem.getSelectedIndex();
595
	}
476
    /**
477
     * Sets a layer to a symbol in order to create a final symbol composed by
478
     * different layers.
479
     *
480
     * @param layer
481
     */
482
    protected void setLayerToSymbol(ISymbol layer) {
483
        int i = getLayerManager().getSelectedLayerIndex();
484
        IMultiLayerSymbol s = (IMultiLayerSymbol) symbol;
485
        if (i >= 0 && i < s.getLayerCount()) {
486
            s.setLayer(s.getLayerCount() - 1 - i, layer);
596 487

  
597
        /**
598
         * @deprecated use SymblogySwingManager
599
         */
600
	public static void addSymbolEditorPanel(Class<? extends TypeSymbolEditor> symbolEditor, int shapeType) {
601
            SymbologySwingManager manager = SymbologySwingLocator.getSwingManager();
602
            manager.registerSymbolEditor(symbolEditor, shapeType);
603
	}
604
	
605
        /**
606
         * @deprecated use SymblogySwingManager
607
         */
608
	private static List getSymbolsByType(GeometryType geometryType){
609
            SymbologySwingManager manager = SymbologySwingLocator.getSwingManager();
610
            return manager.getSymbolEditorClassesByGeometryType(geometryType);
611
	}
488
        }
489
        refresh();
490
    }
612 491

  
613
	public Object getWindowProfile() {
614
		return WindowInfo.DIALOG_PROFILE;
615
	}
492
    public void refresh() {
493
        getSymbolPreviewer().setSymbol(symbol);
494
        doLayout();
495
        repaint();
496
    }
616 497

  
617
        public void setFeatureStore(FeatureStore store) {
618
            this.featureStore = store;
619
            if( this.featureStore!=null ) {
620
                this.sampleFeature.setValue(this.featureStore.getSampleFeature());
621
                for (AbstractTypeSymbolEditor editor : tabs) {
622
                    editor.setFeatureStore(this.featureStore);
623
                }
498
    /**
499
     * <p>
500
     * Returns the type of the symbol that this panels is created for.<br>
501
     * </p>
502
     * <p>
503
     * Possible values returned by this method are
504
     * <ol>
505
     * <li> <b> Geometry.TYPES.POINT </b>, for maker symbols </li>
506
     * <li> <b> Geometry.TYPES.SURFACE </b>, for fill symbols </li>
507
     * <li> <b> Geometry.TYPES.CURVE </b>, for line symbols (not yet
508
     * implemented) </li>
509
     * <li> <b> Geometry.TYPES.TEXT </b>, for text symbols (not yet implemented)
510
     * </li>
511
     * <li> maybe some other in the future </li>
512
     * </ol>
513
     * </p>
514
     *
515
     * @return
516
     */
517
    public int getShapeType() {
518
        return shapeType.getType();
519
    }
520

  
521
    /**
522
     * Obtains a new layer
523
     *
524
     * @return sym ISymbol
525
     */
526
    public ISymbol getNewLayer() {
527
        ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem())
528
                .getLayer();
529

  
530
        return sym;
531
    }
532

  
533
    private void replaceOptions(AbstractTypeSymbolEditor options) {
534
        if (!replacing) {
535
            replacing = true;
536
            if (tabbedPane != null) {
537
                getPnlCenter().remove(tabbedPane);
624 538
            }
539
            JPanel[] theTabs = options.getTabs();
540
            tabbedPane = new JTabbedPane();
541
            tabbedPane.setPreferredSize(new Dimension(300, 300));
542
            for (JPanel theTab : theTabs) {
543
                tabbedPane.addTab(theTab.getName(), theTab);
544
            }
545
            getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
546
            getPnlCenter().doLayout();
547
            replacing = false;
625 548
        }
626
        
627
        public MutableObject<Feature> getSampleFeature() {
628
            if( this.sampleFeature == null ) {
629
                this.sampleFeature = new MutableObject();
630
                if( this.featureStore!=null ) {
631
                    this.sampleFeature.setValue(this.featureStore.getSampleFeature());
632
                }
549
    }
550

  
551
    public void setOptionsPageFor(ISymbol symbol) {
552
        AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol);
553

  
554
        options.refreshControls(symbol);
555
        getCmbType().setSelectedItem(options);
556
    }
557

  
558
    /**
559
     * Obtains the units to be used for the reference system.
560
     *
561
     */
562
    public int getUnitsReferenceSystem() {
563
        return cmbUnitsReferenceSystem.getSelectedIndex();
564
    }
565

  
566
    /**
567
     * @deprecated use SymblogySwingManager
568
     */
569
    public static void addSymbolEditorPanel(Class<? extends TypeSymbolEditor> symbolEditor, int shapeType) {
570
        SymbologySwingManager manager = SymbologySwingLocator.getSwingManager();
571
        manager.registerSymbolEditor(symbolEditor, shapeType);
572
    }
573

  
574
    /**
575
     * @deprecated use SymblogySwingManager
576
     */
577
    private static List getSymbolsByType(GeometryType geometryType) {
578
        SymbologySwingManager manager = SymbologySwingLocator.getSwingManager();
579
        return manager.getSymbolEditorClassesByGeometryType(geometryType);
580
    }
581

  
582
    @Override
583
    public Object getWindowProfile() {
584
        return WindowInfo.DIALOG_PROFILE;
585
    }
586

  
587
    public void setFeatureStore(FeatureStore store) {
588
        this.featureStore = store;
589
        if (this.featureStore != null) {
590
            this.sampleFeature.setValue(this.featureStore.getSampleFeature());
591
            for (AbstractTypeSymbolEditor editor : tabs) {
592
                editor.setFeatureStore(this.featureStore);
633 593
            }
634
            return this.sampleFeature;
635 594
        }
595
    }
596

  
597
    public MutableObject<Feature> getSampleFeature() {
598
        if (this.sampleFeature == null) {
599
            this.sampleFeature = new MutableObject();
600
            if (this.featureStore != null) {
601
                this.sampleFeature.setValue(this.featureStore.getSampleFeature());
602
            }
603
        }
604
        return this.sampleFeature;
605
    }
636 606
}

Also available in: Unified diff