Revision 22951 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/StyleSelector.java

View differences:

StyleSelector.java
40 40
 */
41 41

  
42 42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.11  2007-08-21 09:32:53  jvidal
47
* javadoc
48
*
49
* Revision 1.10  2007/05/31 09:36:22  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.9  2007/05/10 09:47:50  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.8  2007/05/08 15:44:07  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.7  2007/04/27 12:10:17  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.6  2007/04/11 16:02:43  jaume
62
* file filter
63
*
64
* Revision 1.5  2007/04/05 16:08:34  jaume
65
* Styled labeling stuff
66
*
67
* Revision 1.4  2007/04/04 16:01:14  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.2  2007/03/09 11:25:00  jaume
71
* Advanced symbology (start committing)
72
*
73
* Revision 1.1.2.4  2007/02/21 07:35:14  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1.2.3  2007/02/08 15:43:04  jaume
77
* some bug fixes in the editor and removed unnecessary imports
78
*
79
* Revision 1.1.2.2  2007/01/30 18:10:10  jaume
80
* start commiting labeling stuff
81
*
82
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
83
* *** empty log message ***
84
*
85
*
86
*/
43
 *
44
 * $Id$
45
 * $Log$
46
 * Revision 1.11  2007-08-21 09:32:53  jvidal
47
 * javadoc
48
 *
49
 * Revision 1.10  2007/05/31 09:36:22  jaume
50
 * *** empty log message ***
51
 *
52
 * Revision 1.9  2007/05/10 09:47:50  jaume
53
 * *** empty log message ***
54
 *
55
 * Revision 1.8  2007/05/08 15:44:07  jaume
56
 * *** empty log message ***
57
 *
58
 * Revision 1.7  2007/04/27 12:10:17  jaume
59
 * *** empty log message ***
60
 *
61
 * Revision 1.6  2007/04/11 16:02:43  jaume
62
 * file filter
63
 *
64
 * Revision 1.5  2007/04/05 16:08:34  jaume
65
 * Styled labeling stuff
66
 *
67
 * Revision 1.4  2007/04/04 16:01:14  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.2  2007/03/09 11:25:00  jaume
71
 * Advanced symbology (start committing)
72
 *
73
 * Revision 1.1.2.4  2007/02/21 07:35:14  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.1.2.3  2007/02/08 15:43:04  jaume
77
 * some bug fixes in the editor and removed unnecessary imports
78
 *
79
 * Revision 1.1.2.2  2007/01/30 18:10:10  jaume
80
 * start commiting labeling stuff
81
 *
82
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
83
 * *** empty log message ***
84
 *
85
 *
86
 */
87 87
package com.iver.cit.gvsig.gui.styling;
88 88

  
89 89
import java.awt.BorderLayout;
......
91 91
import java.awt.Component;
92 92
import java.awt.Dimension;
93 93
import java.awt.FlowLayout;
94
import java.awt.Rectangle;
95 94
import java.awt.event.ActionEvent;
96 95
import java.awt.event.ActionListener;
97 96
import java.io.File;
......
118 117
import com.iver.andami.PluginServices;
119 118
import com.iver.andami.messages.NotificationManager;
120 119
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
121
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
122 120
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle;
123 121
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
124 122
import com.iver.cit.gvsig.gui.JComboBoxUnits;
......
138 136
public class StyleSelector extends SymbolSelector {
139 137
	private static final long serialVersionUID = -7476555713446755512L;
140 138
	private ImageSizePanel isp;
139
	private IStyle styleType;
141 140

  
142 141
	public StyleSelector(IStyle style, int shapeType) {
143
		this(style, shapeType, new SelectorFilter() {
142
		this(style, shapeType, new StyleSelectorFilter() {
143

  
144 144
			public boolean accepts(Object obj) {
145 145
				return obj instanceof IStyle;
146 146
			}
147

  
148
			public IStyle getAllowedObject() {
149
				return null;
150
			}
147 151
		});
148 152
	}
149 153
	/**
......
153 157
	 * @param shapeType
154 158
	 * @param filter
155 159
	 */
156
	public StyleSelector(IStyle style, int shapeType, SelectorFilter filter) {
160
	public StyleSelector(IStyle style, int shapeType, StyleSelectorFilter filter) {
157 161
		super(null, shapeType, filter, false);
158 162

  
159
    	Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
163
		styleType = ((AbstractStyleSelectorFilter)filter).getAllowedObject();
164
		Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
160 165
		rootDir = new File(prefs.get("SymbolStylesFolder", System.getProperty("user.home")+"/gvSIG/Styles"));
161 166
		if (!rootDir.exists())
162 167
			rootDir.mkdir();
......
173 178

  
174 179
	@Override
175 180
	protected void initialize(Object currentElement) throws ClassNotFoundException {
176
    	library = new StyleLibrary(rootDir);
181
		library = new StyleLibrary(rootDir);
177 182

  
178
    	this.setLayout(new BorderLayout());
179
    	this.setSize(400, 221);
183
		this.setLayout(new BorderLayout());
184
		this.setSize(400, 221);
180 185

  
181
    	this.add(getJNorthPanel(), BorderLayout.NORTH);
182
    	this.add(getJSplitPane(), BorderLayout.CENTER);
183
    	this.add(getJEastPanel(), BorderLayout.EAST);
184
    	ActionListener okAction = new ActionListener() {
185
    		public void actionPerformed(ActionEvent e) {
186
    			accepted = true;
187
    			PluginServices.getMDIManager().closeWindow(StyleSelector.this);
188
    		}
189
    	}, cancelAction = new ActionListener() {
190
    		public void actionPerformed(ActionEvent e) {
191
    			setSymbol(null);
192
    			PluginServices.getMDIManager().closeWindow(StyleSelector.this);
193
    		}
194
    	};
186
		this.add(getJNorthPanel(), BorderLayout.NORTH);
187
		this.add(getJSplitPane(), BorderLayout.CENTER);
188
		this.add(getJEastPanel(), BorderLayout.EAST);
189
		ActionListener okAction = new ActionListener() {
190
			public void actionPerformed(ActionEvent e) {
191
				accepted = true;
192
				PluginServices.getMDIManager().closeWindow(StyleSelector.this);
193
			}
194
		}, cancelAction = new ActionListener() {
195
			public void actionPerformed(ActionEvent e) {
196
				setSymbol(null);
197
				PluginServices.getMDIManager().closeWindow(StyleSelector.this);
198
			}
199
		};
195 200

  
196
    	okCancelPanel = new AcceptCancelPanel();
197
    	okCancelPanel.setOkButtonActionListener(okAction);
198
    	okCancelPanel.setCancelButtonActionListener(cancelAction);
201
		okCancelPanel = new AcceptCancelPanel();
202
		okCancelPanel.setOkButtonActionListener(okAction);
203
		okCancelPanel.setCancelButtonActionListener(cancelAction);
199 204

  
200
    	this.add(okCancelPanel, BorderLayout.SOUTH);
201
    	libraryBrowser.setSelectionRow(0);
205
		this.add(okCancelPanel, BorderLayout.SOUTH);
206
		libraryBrowser.setSelectionRow(0);
202 207

  
203
    	SillyDragNDropAction dndAction = new SillyDragNDropAction();
204
    	libraryBrowser.addMouseListener(dndAction);
205
    	libraryBrowser.addMouseMotionListener(dndAction);
206
    	getJListSymbols().addMouseListener(dndAction);
207
    	getJListSymbols().addMouseMotionListener(dndAction);
208
    	setSymbol(currentElement);
209
    }
208
		SillyDragNDropAction dndAction = new SillyDragNDropAction();
209
		libraryBrowser.addMouseListener(dndAction);
210
		libraryBrowser.addMouseMotionListener(dndAction);
211
		getJListSymbols().addMouseListener(dndAction);
212
		getJListSymbols().addMouseMotionListener(dndAction);
213
		setSymbol(currentElement);
214
	}
210 215

  
211 216
	@Override
212 217
	public void setSymbol(Object style) {
......
231 236
	protected SymbolSelectorListModel newListModel() {
232 237
		StyleSelectorListModel listModel = new StyleSelectorListModel(
233 238
				dir,
234
//				selectedElement,
235 239
				sFilter,
236 240
				StyleSelectorListModel.STYLE_FILE_EXTENSION);
237 241
		return listModel;
......
248 252
			jPanelOptions.addComponent("",
249 253
					cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
250 254
		}
251
    	return jPanelOptions;
252
    }
255
		return jPanelOptions;
256
	}
253 257

  
254 258
	/**
255 259
	 *
256
     * This method initializes ImageSizePanel
257
     *
258
     * @return isp ImageSizePanel
259
     */
260
	 private ImageSizePanel getImageSizePanel() {
261
		 if (isp == null) {
260
	 * This method initializes ImageSizePanel
261
	 *
262
	 * @return isp ImageSizePanel
263
	 */
264
	private ImageSizePanel getImageSizePanel() {
265
		if (isp == null) {
262 266
			isp = new ImageSizePanel();
263 267
			isp.addActionListener(new ActionListener() {
264 268
				public void actionPerformed(ActionEvent e) {
......
276 280

  
277 281
	protected void updateOptionsPanel() {
278 282
		IStyle s = ((StylePreviewer) jPanelPreview).getStyle();
279
	    if (s instanceof ILabelStyle) {
283
		if (s instanceof ILabelStyle) {
280 284
			ILabelStyle lab = (ILabelStyle) s;
281 285
			Dimension sz = lab.getSize();
282 286
			getImageSizePanel().setImageSize(sz);
283 287
		}
284
	 }
288
	}
285 289

  
286 290

  
287
    /**
288
     * This method initializes jList
289
     *
290
     * @return javax.swing.JList
291
     */
292
    protected JList getJListSymbols() {
293
    	if (jListSymbols == null) {
294
    		jListSymbols = new JDnDList();
295
    		jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
296
            jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
297
            jListSymbols.setVisibleRowCount(-1);
298
            jListSymbols.addListSelectionListener(new ListSelectionListener() {
299
            	public void valueChanged(ListSelectionEvent e) {
300
            		setStyle(jListSymbols.getSelectedValue());
301
            		updateOptionsPanel();
302
            	}
303
            });
304
            ListCellRenderer renderer = new ListCellRenderer() {
305
        		private Color mySelectedBGColor = new Color(255,145,100,255);
306
    			public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
307
    				IStyle sty = (IStyle) value;
308
    				JPanel pnl = new JPanel();
309
    				BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
310
    				pnl.setLayout(layout);
311
    				Color bgColor = (isSelected) ? mySelectedBGColor
312
    							 : getJListSymbols().getBackground();
291
	/**
292
	 * This method initializes jList
293
	 *
294
	 * @return javax.swing.JList
295
	 */
296
	protected JList getJListSymbols() {
297
		if (jListSymbols == null) {
298
			jListSymbols = new JDnDList();
299
			jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
300
			jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
301
			jListSymbols.setVisibleRowCount(-1);
302
			jListSymbols.addListSelectionListener(new ListSelectionListener() {
303
				public void valueChanged(ListSelectionEvent e) {
304
					setStyle(jListSymbols.getSelectedValue());
305
					updateOptionsPanel();
306
				}
307
			});
308
			ListCellRenderer renderer = new ListCellRenderer() {
309
				private Color mySelectedBGColor = new Color(255,145,100,255);
310
				public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
311
					IStyle sty = (IStyle) value;
312
					JPanel pnl = new JPanel();
313
					BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
314
					pnl.setLayout(layout);
315
					Color bgColor = (isSelected) ? mySelectedBGColor
316
							: getJListSymbols().getBackground();
313 317

  
314
    				pnl.setBackground(bgColor);
315
    				StylePreviewer sp = new StylePreviewer();
316
    				sp.setShowOutline(false);
317
    				sp.setAlignmentX(Component.CENTER_ALIGNMENT);
318
    				sp.setPreferredSize(new Dimension(50, 50));
319
    				sp.setStyle(sty);
320
    				sp.setBackground(bgColor);
321
    				pnl.add(sp);
322
    				JLabel lbl = new JLabel(sty.getDescription());
323
    				lbl.setBackground(bgColor);
324
    				lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
325
    				pnl.add(lbl);
318
					pnl.setBackground(bgColor);
319
					StylePreviewer sp = new StylePreviewer();
320
					sp.setShowOutline(false);
321
					sp.setAlignmentX(Component.CENTER_ALIGNMENT);
322
					sp.setPreferredSize(new Dimension(50, 50));
323
					sp.setStyle(sty);
324
					sp.setBackground(bgColor);
325
					pnl.add(sp);
326
					JLabel lbl = new JLabel(sty.getDescription());
327
					lbl.setBackground(bgColor);
328
					lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
329
					pnl.add(lbl);
326 330

  
327
    				return pnl;
328
    			}
331
					return pnl;
332
				}
329 333

  
330
        	};
331
        	jListSymbols.setCellRenderer(renderer);
332
    	}
333
    	return jListSymbols;
334
    }
335
    /**
336
     * Modify the previsualization showed in the panel with the style of the
337
     * new object selected.
338
     *
339
     * @param selectedValue
340
     */
341
   protected void setStyle(Object selectedValue) {
334
			};
335
			jListSymbols.setCellRenderer(renderer);
336
		}
337
		return jListSymbols;
338
	}
339
	/**
340
	 * Modify the previsualization showed in the panel with the style of the
341
	 * new object selected.
342
	 *
343
	 * @param selectedValue
344
	 */
345
	protected void setStyle(Object selectedValue) {
342 346
		//selectedElement = selectedValue;
343 347
		((StylePreviewer) jPanelPreview).setStyle((IStyle) selectedValue);
344 348
		doLayout();
......
346 350
	}
347 351

  
348 352
	protected void newPressed() {
349
		StyleEditor se = new StyleEditor(null);
353

  
354
		StyleEditor se = new StyleEditor(styleType);
350 355
		PluginServices.getMDIManager().addWindow(se);
351 356
		setStyle(se.getStyle());
357

  
352 358
	}
353 359

  
354 360
	protected void propertiesPressed() {
355 361
		StyleEditor se = new StyleEditor((IStyle) getSelectedObject());
356
		PluginServices.getMDIManager().addWindow(se);
357
		setStyle(se.getStyle());
362
		if(se != null){
363
			PluginServices.getMDIManager().addWindow(se);
364
			setStyle(se.getStyle());
365
		}
358 366
	}
359 367

  
360 368
	protected void savePressed() {
......
420 428
		}
421 429
	}
422 430

  
423
    /**
424
     * This method initializes jPanelPreview
425
     *
426
     * @return javax.swing.JComponent
427
     */
428
    protected JComponent getJPanelPreview() {
429
    	if (jPanelPreview == null) {
430
    		jPanelPreview = new StylePreviewer();
431
    		jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
432
    		jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
433
    		((StylePreviewer) jPanelPreview).setShowOutline(true);
434
    	}
435
    	return jPanelPreview;
436
    }
431
	/**
432
	 * This method initializes jPanelPreview
433
	 *
434
	 * @return javax.swing.JComponent
435
	 */
436
	protected JComponent getJPanelPreview() {
437
		if (jPanelPreview == null) {
438
			jPanelPreview = new StylePreviewer();
439
			jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
440
			jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
441
			((StylePreviewer) jPanelPreview).setShowOutline(true);
442
		}
443
		return jPanelPreview;
444
	}
437 445

  
438
    @Override
439
    public void actionPerformed(ActionEvent e) {
440
    	if (!act) return;
446
	@Override
447
	public void actionPerformed(ActionEvent e) {
448
		if (!act) return;
441 449
		Object selectedElement = ((StylePreviewer) jPanelPreview).getStyle();//getSelectedObject();
442 450
		performActionOn(selectedElement, e);
443 451
		StyleSelector.this.repaint();
444
    }
452
	}
445 453

  
446
    public int getUnit() {
447
    	return cmbUnits.getSelectedUnitIndex();
448
    }
454
	public int getUnit() {
455
		return cmbUnits.getSelectedUnitIndex();
456
	}
449 457

  
450
    public int getReferenceSystem() {
451
    	return cmbReferenceSystem.getSelectedIndex();
452
    }
458
	public int getReferenceSystem() {
459
		return cmbReferenceSystem.getSelectedIndex();
460
	}
453 461

  
454 462
	public void setUnit(int unit) {
455 463
		cmbUnits.setSelectedUnitIndex(unit);

Also available in: Unified diff