svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / SingleSymbol.java @ 29583
History | View | Annotate | Download (8.95 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 != null && legend instanceof SingleSymbolLegend) { |
117 |
setSymbol(legend.getDefaultSymbol()); |
118 |
try {
|
119 |
this.legend = (SingleSymbolLegend) legend.cloneLegend();
|
120 |
// this.zSort = this.legend.getZSort();
|
121 |
} catch (XMLException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} |
125 |
|
126 |
} else {
|
127 |
this.legend = (SingleSymbolLegend) LegendFactory.
|
128 |
createSingleSymbolLegend(shapeType); |
129 |
} |
130 |
getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
131 |
getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
|
132 |
this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
|
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
137 |
*/
|
138 |
public ILegend getLegend() {
|
139 |
if (this.legend == null) { |
140 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
141 |
symbol.setDescription(txtLabel.getText()); |
142 |
this.legend = new SingleSymbolLegend(symbol); |
143 |
} |
144 |
return this.legend; |
145 |
// ISymbol symbol = getSymbolPreviewPanel().getSymbol();
|
146 |
// symbol.setDescription(txtLabel.getText());
|
147 |
// SingleSymbolLegend leg = new SingleSymbolLegend(symbol);
|
148 |
// leg.setZSort(zSort);
|
149 |
// return leg;
|
150 |
} |
151 |
|
152 |
public String getDescription() { |
153 |
return PluginServices.getText(this,"Muestra_todos_los_elementos_de_una_capa_usando_el_mismo_simbolo"); |
154 |
} |
155 |
|
156 |
public Class getParentClass() { |
157 |
return Features.class;
|
158 |
} |
159 |
|
160 |
public String getTitle() { |
161 |
return PluginServices.getText(this,"Simbolo_unico"); |
162 |
} |
163 |
|
164 |
public JPanel getPanel() { |
165 |
return this; |
166 |
} |
167 |
|
168 |
public ImageIcon getIcon() { |
169 |
return new ImageIcon(this.getClass().getClassLoader(). |
170 |
getResource("images/single-symbol.png"));
|
171 |
} |
172 |
|
173 |
public Class getLegendClass() { |
174 |
return SingleSymbolLegend.class;
|
175 |
} |
176 |
/**
|
177 |
* This method initializes symbolPanel
|
178 |
*
|
179 |
* @return javax.swing.JPanel
|
180 |
*/
|
181 |
private JPanel getSymbolPanel() { |
182 |
if (symbolPanel == null) { |
183 |
symbolPanel = new JPanel(); |
184 |
symbolPanel.setBorder( |
185 |
BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
186 |
symbolPanel.add(getSymbolPreviewPanel()); |
187 |
symbolPanel.add(getBtnOpenSymbolSelector()); |
188 |
symbolPanel.add(getBtnOpenSymbolLevelsEditor()); |
189 |
} |
190 |
return symbolPanel;
|
191 |
} |
192 |
|
193 |
private JButton getBtnOpenSymbolLevelsEditor() { |
194 |
if (btnOpenSymbolLevelsEditor == null) { |
195 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
196 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
197 |
btnOpenSymbolLevelsEditor.setEnabled(legend != null);
|
198 |
} |
199 |
|
200 |
return btnOpenSymbolLevelsEditor;
|
201 |
} |
202 |
private JButton getBtnOpenSymbolSelector() { |
203 |
if (btnOpenSymbolSelector == null) { |
204 |
btnOpenSymbolSelector = new JButton(); |
205 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
206 |
btnOpenSymbolSelector.addActionListener(this);
|
207 |
} |
208 |
return btnOpenSymbolSelector;
|
209 |
} |
210 |
|
211 |
private SymbolPreviewer getSymbolPreviewPanel() {
|
212 |
if (symbolPreviewComponent == null) { |
213 |
symbolPreviewComponent = new SymbolPreviewer();
|
214 |
symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
215 |
symbolPreviewComponent.setPreferredSize(new Dimension(120, 40)); |
216 |
} |
217 |
return symbolPreviewComponent;
|
218 |
} |
219 |
/**
|
220 |
* This method initializes legendPanel
|
221 |
*
|
222 |
* @return javax.swing.JPanel
|
223 |
*/
|
224 |
private GridBagLayoutPanel getLegendPanel() {
|
225 |
if (legendPanel == null) { |
226 |
legendPanel = new GridBagLayoutPanel();
|
227 |
legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
228 |
PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
229 |
legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
230 |
txtLabel.addActionListener(this);
|
231 |
} |
232 |
return legendPanel;
|
233 |
} |
234 |
|
235 |
public void setShapeType(int shapeType) { |
236 |
this.shapeType = shapeType;
|
237 |
} |
238 |
|
239 |
public void setSymbol(ISymbol symbol) { |
240 |
setOnlySymbol(symbol); |
241 |
if(symbol.getDescription() != null) |
242 |
txtLabel.setText(symbol.getDescription()); |
243 |
// else
|
244 |
// txtLabel.setText(" ("+PluginServices.getText(this, "current")+")");
|
245 |
} |
246 |
|
247 |
private void setOnlySymbol(ISymbol symbol){ |
248 |
getSymbolPreviewPanel().setSymbol(symbol); |
249 |
if (legend != null){ |
250 |
legend.setDefaultSymbol(symbol); |
251 |
} |
252 |
} |
253 |
|
254 |
public ISymbol getSymbol() {
|
255 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
256 |
symbol.setDescription(txtLabel.getText()); |
257 |
return symbol;
|
258 |
} |
259 |
|
260 |
public boolean isSuitableFor(FLayer layer) { |
261 |
return (layer instanceof FLyrVect) ; |
262 |
} |
263 |
|
264 |
public void actionPerformed(ActionEvent e) { |
265 |
JComponent c = (JComponent) e.getSource(); |
266 |
if (c.equals(getBtnOpenSymbolSelector())){
|
267 |
ISymbol auxSymbol = getSymbol(); |
268 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(auxSymbol, shapeType); |
269 |
PluginServices.getMDIManager().addWindow(se); |
270 |
ISymbol sym = (ISymbol) se.getSelectedObject(); |
271 |
if (sym != null && sym != auxSymbol) { |
272 |
// no symbol, no changes
|
273 |
setOnlySymbol(sym); |
274 |
// zSort = null;
|
275 |
} |
276 |
} else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
277 |
ZSort myZSort = null;
|
278 |
if (legend != null) { |
279 |
// if(zSort == null){
|
280 |
myZSort = legend.getZSort(); |
281 |
if (myZSort == null) { |
282 |
myZSort = new ZSort(legend);
|
283 |
} |
284 |
// }
|
285 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
286 |
PluginServices.getMDIManager().addWindow(sl); |
287 |
// zSort = sl.getZSort();
|
288 |
this.legend.setZSort(sl.getZSort());
|
289 |
} |
290 |
}else if (c.equals(txtLabel)){ |
291 |
getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText()); |
292 |
} |
293 |
} |
294 |
|
295 |
} |