svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / SingleSymbol.java @ 24283
History | View | Annotate | Download (8.34 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.layers.XMLException; |
71 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
72 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
73 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
74 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
75 |
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow; |
76 |
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer; |
77 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
78 |
|
79 |
/**
|
80 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
81 |
*/
|
82 |
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
83 |
private JPanel symbolPanel = null; |
84 |
private int shapeType; |
85 |
private GridBagLayoutPanel legendPanel = null; |
86 |
private SymbolPreviewer symbolPreviewComponent;
|
87 |
private JButton btnOpenSymbolSelector; |
88 |
private JTextField txtLabel; |
89 |
private JButton btnOpenSymbolLevelsEditor; |
90 |
private SingleSymbolLegend legend;
|
91 |
private ZSort zSort;
|
92 |
|
93 |
|
94 |
public SingleSymbol() {
|
95 |
super();
|
96 |
initialize(); |
97 |
} |
98 |
/**
|
99 |
* This method initializes this
|
100 |
*
|
101 |
*/
|
102 |
private void initialize() { |
103 |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
104 |
this.setSize(new java.awt.Dimension(490,379)); |
105 |
this.add(getSymbolPanel(), null); |
106 |
this.add(getLegendPanel(), null); |
107 |
|
108 |
} |
109 |
|
110 |
public void setData(FLayer lyr, ILegend legend) { |
111 |
try {
|
112 |
shapeType = ((FLyrVect) lyr).getShapeType(); |
113 |
} catch (ReadDriverException e) {
|
114 |
NotificationManager.addError("Could not find out the shape type" ,e);
|
115 |
} |
116 |
if (legend instanceof SingleSymbolLegend) { |
117 |
setSymbol(legend.getDefaultSymbol()); |
118 |
try {
|
119 |
this.legend = (SingleSymbolLegend) legend.cloneLegend();
|
120 |
} catch (XMLException e) {
|
121 |
// TODO Auto-generated catch block
|
122 |
e.printStackTrace(); |
123 |
} |
124 |
|
125 |
} else {
|
126 |
this.legend = (SingleSymbolLegend) LegendFactory.
|
127 |
createSingleSymbolLegend(shapeType); |
128 |
} |
129 |
getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
130 |
this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
|
131 |
} |
132 |
|
133 |
/* (non-Javadoc)
|
134 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
135 |
*/
|
136 |
public ILegend getLegend() {
|
137 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
138 |
symbol.setDescription(txtLabel.getText()); |
139 |
SingleSymbolLegend leg = new SingleSymbolLegend(symbol);
|
140 |
leg.setZSort(zSort); |
141 |
return leg;
|
142 |
} |
143 |
|
144 |
public String getDescription() { |
145 |
return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
146 |
} |
147 |
|
148 |
public Class getParentClass() { |
149 |
return Features.class;
|
150 |
} |
151 |
|
152 |
public String getTitle() { |
153 |
return PluginServices.getText(this,"Simbolo_unico"); |
154 |
} |
155 |
|
156 |
public JPanel getPanel() { |
157 |
return this; |
158 |
} |
159 |
|
160 |
public ImageIcon getIcon() { |
161 |
return new ImageIcon(this.getClass().getClassLoader(). |
162 |
getResource("images/single-symbol.png"));
|
163 |
} |
164 |
|
165 |
public Class getLegendClass() { |
166 |
return SingleSymbolLegend.class;
|
167 |
} |
168 |
/**
|
169 |
* This method initializes symbolPanel
|
170 |
*
|
171 |
* @return javax.swing.JPanel
|
172 |
*/
|
173 |
private JPanel getSymbolPanel() { |
174 |
if (symbolPanel == null) { |
175 |
symbolPanel = new JPanel(); |
176 |
symbolPanel.setBorder( |
177 |
BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
178 |
symbolPanel.add(getSymbolPreviewPanel()); |
179 |
symbolPanel.add(getBtnOpenSymbolSelector()); |
180 |
symbolPanel.add(getBtnOpenSymbolLevelsEditor()); |
181 |
} |
182 |
return symbolPanel;
|
183 |
} |
184 |
|
185 |
private JButton getBtnOpenSymbolLevelsEditor() { |
186 |
if (btnOpenSymbolLevelsEditor == null) { |
187 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
188 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
189 |
} |
190 |
|
191 |
return btnOpenSymbolLevelsEditor;
|
192 |
} |
193 |
private JButton getBtnOpenSymbolSelector() { |
194 |
if (btnOpenSymbolSelector == null) { |
195 |
btnOpenSymbolSelector = new JButton(); |
196 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
197 |
btnOpenSymbolSelector.addActionListener(this);
|
198 |
} |
199 |
return btnOpenSymbolSelector;
|
200 |
} |
201 |
|
202 |
private SymbolPreviewer getSymbolPreviewPanel() {
|
203 |
if (symbolPreviewComponent == null) { |
204 |
symbolPreviewComponent = new SymbolPreviewer();
|
205 |
symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
206 |
symbolPreviewComponent.setPreferredSize(new Dimension(120, 40)); |
207 |
} |
208 |
return symbolPreviewComponent;
|
209 |
} |
210 |
/**
|
211 |
* This method initializes legendPanel
|
212 |
*
|
213 |
* @return javax.swing.JPanel
|
214 |
*/
|
215 |
private GridBagLayoutPanel getLegendPanel() {
|
216 |
if (legendPanel == null) { |
217 |
legendPanel = new GridBagLayoutPanel();
|
218 |
legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
219 |
PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
220 |
legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
221 |
txtLabel.addActionListener(this);
|
222 |
} |
223 |
return legendPanel;
|
224 |
} |
225 |
|
226 |
public void setShapeType(int shapeType) { |
227 |
this.shapeType = shapeType;
|
228 |
} |
229 |
|
230 |
public void setSymbol(ISymbol symbol) { |
231 |
getSymbolPreviewPanel().setSymbol(symbol); |
232 |
if (legend != null){ |
233 |
legend.setDefaultSymbol(symbol); |
234 |
} |
235 |
if(symbol.getDescription() != null) |
236 |
txtLabel.setText(symbol.getDescription()); |
237 |
// else
|
238 |
// txtLabel.setText(" ("+PluginServices.getText(this, "current")+")");
|
239 |
} |
240 |
|
241 |
public ISymbol getSymbol() {
|
242 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
243 |
symbol.setDescription(txtLabel.getText()); |
244 |
return symbol;
|
245 |
} |
246 |
|
247 |
public boolean isSuitableFor(FLayer layer) { |
248 |
return (layer instanceof FLyrVect) ; |
249 |
} |
250 |
|
251 |
public void actionPerformed(ActionEvent e) { |
252 |
JComponent c = (JComponent) e.getSource(); |
253 |
if (c.equals(getBtnOpenSymbolSelector())){
|
254 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
255 |
PluginServices.getMDIManager().addWindow(se); |
256 |
ISymbol sym = (ISymbol) se.getSelectedObject(); |
257 |
if (sym != null) { |
258 |
// no symbol, no changes
|
259 |
setSymbol((ISymbol) se.getSelectedObject()); |
260 |
} |
261 |
} else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
262 |
if (legend != null) { |
263 |
ZSort myZSort = legend.getZSort(); |
264 |
if (myZSort == null) { |
265 |
myZSort = new ZSort(legend);
|
266 |
} |
267 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
268 |
PluginServices.getMDIManager().addWindow(sl); |
269 |
zSort = sl.getZSort(); |
270 |
} |
271 |
}else if (c.equals(txtLabel)){ |
272 |
getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText()); |
273 |
} |
274 |
} |
275 |
|
276 |
} |