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