svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / SingleSymbol.java @ 39117
History | View | Annotate | Download (8.56 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 | 29598 | jpiera | package org.gvsig.app.project.documents.view.legend.gui; |
48 | 10679 | jaume | |
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 | 38608 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
62 | 29598 | jpiera | import org.gvsig.andami.PluginServices; |
63 | import org.gvsig.andami.messages.NotificationManager; |
||
64 | import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
||
65 | import org.gvsig.app.gui.styling.SymbolPreviewer; |
||
66 | import org.gvsig.app.gui.styling.SymbolSelector; |
||
67 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
68 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextLocator; |
69 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
70 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
71 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
72 | 31631 | jpiera | import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
73 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
74 | 10679 | jaume | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
75 | import org.gvsig.gui.beans.swing.JButton; |
||
76 | 30011 | cordinyana | import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
77 | import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend; |
||
78 | 10679 | jaume | |
79 | |||
80 | /**
|
||
81 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
82 | */
|
||
83 | 11704 | jaume | public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
84 | 10679 | jaume | private JPanel symbolPanel = null; |
85 | private int shapeType; |
||
86 | private GridBagLayoutPanel legendPanel = null; |
||
87 | private SymbolPreviewer symbolPreviewComponent;
|
||
88 | private JButton btnOpenSymbolSelector; |
||
89 | private JTextField txtLabel; |
||
90 | 11704 | jaume | private JButton btnOpenSymbolLevelsEditor; |
91 | private SingleSymbolLegend legend;
|
||
92 | 11850 | jaume | private ZSort zSort;
|
93 | 10679 | jaume | |
94 | 21299 | vcaballero | |
95 | 10679 | jaume | public SingleSymbol() {
|
96 | super();
|
||
97 | initialize(); |
||
98 | } |
||
99 | /**
|
||
100 | * This method initializes this
|
||
101 | *
|
||
102 | */
|
||
103 | private void initialize() { |
||
104 | this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
||
105 | this.setSize(new java.awt.Dimension(490,379)); |
||
106 | this.add(getSymbolPanel(), null); |
||
107 | this.add(getLegendPanel(), null); |
||
108 | |||
109 | } |
||
110 | |||
111 | 11558 | jaume | public void setData(FLayer lyr, ILegend legend) { |
112 | 10679 | jaume | try {
|
113 | shapeType = ((FLyrVect) lyr).getShapeType(); |
||
114 | 21299 | vcaballero | } catch (ReadException e) {
|
115 | 10679 | jaume | NotificationManager.addError("Could not find out the shape type" ,e);
|
116 | } |
||
117 | if (legend instanceof SingleSymbolLegend) { |
||
118 | setSymbol(legend.getDefaultSymbol()); |
||
119 | 13928 | jaume | this.legend = (SingleSymbolLegend) legend;
|
120 | 12427 | jaume | |
121 | 10679 | jaume | } else {
|
122 | 30011 | cordinyana | this.legend = (SingleSymbolLegend) MapContextLocator
|
123 | .getMapContextManager().createLegend( |
||
124 | SingleSymbolLegend.LEGEND_NAME); |
||
125 | this.legend.setShapeType(shapeType);
|
||
126 | // LegendFactory.
|
||
127 | // createSingleSymbolLegend(shapeType);
|
||
128 | 10679 | jaume | } |
129 | 16332 | jdominguez | getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
130 | 26414 | fdiaz | getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
|
131 | 22752 | 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 | 22752 | vcaballero | ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
139 | symbol.setDescription(txtLabel.getText()); |
||
140 | 30011 | cordinyana | AbstractVectorialLegend leg = new SingleSymbolLegend(symbol);
|
141 | 39117 | jldominguez | leg.setShapeType(shapeType); |
142 | 11850 | jaume | leg.setZSort(zSort); |
143 | 13955 | jaume | return leg;
|
144 | 10679 | jaume | } |
145 | |||
146 | public String getDescription() { |
||
147 | 11850 | jaume | return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
148 | 10679 | jaume | } |
149 | |||
150 | public Class getParentClass() { |
||
151 | return Features.class;
|
||
152 | } |
||
153 | |||
154 | public String getTitle() { |
||
155 | return PluginServices.getText(this,"Simbolo_unico"); |
||
156 | } |
||
157 | |||
158 | public JPanel getPanel() { |
||
159 | return this; |
||
160 | } |
||
161 | |||
162 | 18623 | jdominguez | public ImageIcon getIcon() { |
163 | 38608 | jjdelcerro | return IconThemeHelper.getImageIcon("legend-overview-single-symbol"); |
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 | 26414 | fdiaz | 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 | 22752 | 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 | 26422 | fdiaz | setOnlySymbol(symbol); |
234 | if(symbol.getDescription() != null) { |
||
235 | txtLabel.setText(symbol.getDescription()); |
||
236 | } |
||
237 | } |
||
238 | |||
239 | private void setOnlySymbol(ISymbol symbol){ |
||
240 | 10679 | jaume | getSymbolPreviewPanel().setSymbol(symbol); |
241 | 22752 | vcaballero | if (legend != null){ |
242 | 12427 | jaume | legend.setDefaultSymbol(symbol); |
243 | 22752 | vcaballero | } |
244 | 10679 | jaume | } |
245 | |||
246 | 26422 | fdiaz | |
247 | 10679 | jaume | public ISymbol getSymbol() {
|
248 | 22752 | vcaballero | ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
249 | symbol.setDescription(txtLabel.getText()); |
||
250 | return symbol;
|
||
251 | 10679 | jaume | } |
252 | 11704 | jaume | public boolean isSuitableFor(FLayer layer) { |
253 | return (layer instanceof FLyrVect) ; |
||
254 | } |
||
255 | |||
256 | public void actionPerformed(ActionEvent e) { |
||
257 | JComponent c = (JComponent) e.getSource(); |
||
258 | if (c.equals(getBtnOpenSymbolSelector())){
|
||
259 | 13729 | jaume | ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
260 | 11704 | jaume | PluginServices.getMDIManager().addWindow(se); |
261 | ISymbol sym = (ISymbol) se.getSelectedObject(); |
||
262 | if (sym != null) { |
||
263 | // no symbol, no changes
|
||
264 | 26422 | fdiaz | setOnlySymbol(sym); |
265 | 11704 | jaume | } |
266 | } else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
||
267 | 11850 | jaume | if (legend != null) { |
268 | ZSort myZSort = legend.getZSort(); |
||
269 | if (myZSort == null) { |
||
270 | myZSort = new ZSort(legend);
|
||
271 | } |
||
272 | SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
||
273 | 11704 | jaume | PluginServices.getMDIManager().addWindow(sl); |
274 | 11850 | jaume | zSort = sl.getZSort(); |
275 | 11704 | jaume | } |
276 | 23712 | vcaballero | }else if (c.equals(txtLabel)){ |
277 | getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText()); |
||
278 | 11704 | jaume | } |
279 | } |
||
280 | |||
281 | 13955 | jaume | } |