root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / SingleSymbol.java @ 23377
History | View | Annotate | Download (8.06 KB)
1 |
/*
|
---|---|
2 |
* Created on 30-abr-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
48 |
|
49 |
import java.awt.Dimension; |
50 |
import java.awt.event.ActionEvent; |
51 |
import java.awt.event.ActionListener; |
52 |
|
53 |
import javax.swing.BorderFactory; |
54 |
import javax.swing.BoxLayout; |
55 |
import javax.swing.ImageIcon; |
56 |
import javax.swing.JComponent; |
57 |
import javax.swing.JPanel; |
58 |
import javax.swing.JTextField; |
59 |
import javax.swing.border.TitledBorder; |
60 |
|
61 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
62 |
import org.gvsig.gui.beans.swing.JButton; |
63 |
|
64 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.andami.messages.NotificationManager; |
67 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
71 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
72 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
73 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
74 |
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow; |
75 |
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer; |
76 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
77 |
|
78 |
/**
|
79 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
80 |
*/
|
81 |
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
82 |
private JPanel symbolPanel = null; |
83 |
private int shapeType; |
84 |
private GridBagLayoutPanel legendPanel = null; |
85 |
private SymbolPreviewer symbolPreviewComponent;
|
86 |
private JButton btnOpenSymbolSelector; |
87 |
private JTextField txtLabel; |
88 |
private JButton btnOpenSymbolLevelsEditor; |
89 |
private SingleSymbolLegend legend;
|
90 |
private ZSort zSort;
|
91 |
|
92 |
|
93 |
public SingleSymbol() {
|
94 |
super();
|
95 |
initialize(); |
96 |
} |
97 |
/**
|
98 |
* This method initializes this
|
99 |
*
|
100 |
*/
|
101 |
private void initialize() { |
102 |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
103 |
this.setSize(new java.awt.Dimension(490,379)); |
104 |
this.add(getSymbolPanel(), null); |
105 |
this.add(getLegendPanel(), null); |
106 |
|
107 |
} |
108 |
|
109 |
public void setData(FLayer lyr, ILegend legend) { |
110 |
try {
|
111 |
shapeType = ((FLyrVect) lyr).getShapeType(); |
112 |
} catch (ReadDriverException e) {
|
113 |
NotificationManager.addError("Could not find out the shape type" ,e);
|
114 |
} |
115 |
if (legend instanceof SingleSymbolLegend) { |
116 |
setSymbol(legend.getDefaultSymbol()); |
117 |
this.legend = (SingleSymbolLegend) legend;
|
118 |
|
119 |
} else {
|
120 |
this.legend = (SingleSymbolLegend) LegendFactory.
|
121 |
createSingleSymbolLegend(shapeType); |
122 |
} |
123 |
getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
124 |
this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
|
125 |
} |
126 |
|
127 |
/* (non-Javadoc)
|
128 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
129 |
*/
|
130 |
public ILegend getLegend() {
|
131 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
132 |
symbol.setDescription(txtLabel.getText()); |
133 |
SingleSymbolLegend leg = new SingleSymbolLegend(symbol);
|
134 |
leg.setZSort(zSort); |
135 |
return leg;
|
136 |
} |
137 |
|
138 |
public String getDescription() { |
139 |
return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
140 |
} |
141 |
|
142 |
public Class getParentClass() { |
143 |
return Features.class;
|
144 |
} |
145 |
|
146 |
public String getTitle() { |
147 |
return PluginServices.getText(this,"Simbolo_unico"); |
148 |
} |
149 |
|
150 |
public JPanel getPanel() { |
151 |
return this; |
152 |
} |
153 |
|
154 |
public ImageIcon getIcon() { |
155 |
return new ImageIcon(this.getClass().getClassLoader(). |
156 |
getResource("images/single-symbol.png"));
|
157 |
} |
158 |
|
159 |
public Class getLegendClass() { |
160 |
return SingleSymbolLegend.class;
|
161 |
} |
162 |
/**
|
163 |
* This method initializes symbolPanel
|
164 |
*
|
165 |
* @return javax.swing.JPanel
|
166 |
*/
|
167 |
private JPanel getSymbolPanel() { |
168 |
if (symbolPanel == null) { |
169 |
symbolPanel = new JPanel(); |
170 |
symbolPanel.setBorder( |
171 |
BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
172 |
symbolPanel.add(getSymbolPreviewPanel()); |
173 |
symbolPanel.add(getBtnOpenSymbolSelector()); |
174 |
symbolPanel.add(getBtnOpenSymbolLevelsEditor()); |
175 |
} |
176 |
return symbolPanel;
|
177 |
} |
178 |
|
179 |
private JButton getBtnOpenSymbolLevelsEditor() { |
180 |
if (btnOpenSymbolLevelsEditor == null) { |
181 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
182 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
183 |
} |
184 |
|
185 |
return btnOpenSymbolLevelsEditor;
|
186 |
} |
187 |
private JButton getBtnOpenSymbolSelector() { |
188 |
if (btnOpenSymbolSelector == null) { |
189 |
btnOpenSymbolSelector = new JButton(); |
190 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
191 |
btnOpenSymbolSelector.addActionListener(this);
|
192 |
} |
193 |
return btnOpenSymbolSelector;
|
194 |
} |
195 |
|
196 |
private SymbolPreviewer getSymbolPreviewPanel() {
|
197 |
if (symbolPreviewComponent == null) { |
198 |
symbolPreviewComponent = new SymbolPreviewer();
|
199 |
symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
200 |
symbolPreviewComponent.setPreferredSize(new Dimension(120, 40)); |
201 |
} |
202 |
return symbolPreviewComponent;
|
203 |
} |
204 |
/**
|
205 |
* This method initializes legendPanel
|
206 |
*
|
207 |
* @return javax.swing.JPanel
|
208 |
*/
|
209 |
private GridBagLayoutPanel getLegendPanel() {
|
210 |
if (legendPanel == null) { |
211 |
legendPanel = new GridBagLayoutPanel();
|
212 |
legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
213 |
PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
214 |
legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
215 |
txtLabel.addActionListener(this);
|
216 |
} |
217 |
return legendPanel;
|
218 |
} |
219 |
|
220 |
public void setShapeType(int shapeType) { |
221 |
this.shapeType = shapeType;
|
222 |
} |
223 |
|
224 |
public void setSymbol(ISymbol symbol) { |
225 |
getSymbolPreviewPanel().setSymbol(symbol); |
226 |
if (legend != null){ |
227 |
legend.setDefaultSymbol(symbol); |
228 |
} |
229 |
if(symbol.getDescription() != null) |
230 |
txtLabel.setText(symbol.getDescription()); |
231 |
else
|
232 |
txtLabel.setText(" ("+PluginServices.getText(this, "current")+")"); |
233 |
} |
234 |
|
235 |
public ISymbol getSymbol() {
|
236 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
237 |
symbol.setDescription(txtLabel.getText()); |
238 |
return symbol;
|
239 |
} |
240 |
|
241 |
public boolean isSuitableFor(FLayer layer) { |
242 |
return (layer instanceof FLyrVect) ; |
243 |
} |
244 |
|
245 |
public void actionPerformed(ActionEvent e) { |
246 |
JComponent c = (JComponent) e.getSource(); |
247 |
if (c.equals(getBtnOpenSymbolSelector())){
|
248 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
249 |
PluginServices.getMDIManager().addWindow(se); |
250 |
ISymbol sym = (ISymbol) se.getSelectedObject(); |
251 |
if (sym != null) { |
252 |
// no symbol, no changes
|
253 |
setSymbol((ISymbol) se.getSelectedObject()); |
254 |
} |
255 |
} else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
256 |
if (legend != null) { |
257 |
ZSort myZSort = legend.getZSort(); |
258 |
if (myZSort == null) { |
259 |
myZSort = new ZSort(legend);
|
260 |
} |
261 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
262 |
PluginServices.getMDIManager().addWindow(sl); |
263 |
zSort = sl.getZSort(); |
264 |
} |
265 |
} |
266 |
} |
267 |
|
268 |
} |