root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / SingleSymbol.java @ 21743
History | View | Annotate | Download (7.68 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 | 21299 | vcaballero | import org.gvsig.data.ReadException; |
62 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.layers.FLayer; |
63 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
64 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
65 | import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory; |
||
66 | import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend; |
||
67 | import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
||
68 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
69 | 10679 | jaume | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
70 | import org.gvsig.gui.beans.swing.JButton; |
||
71 | |||
72 | import com.iver.andami.PluginServices; |
||
73 | import com.iver.andami.messages.NotificationManager; |
||
74 | 11704 | jaume | import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow; |
75 | 10679 | jaume | 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 | 11704 | jaume | public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
82 | 10679 | jaume | 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 | 11704 | jaume | private JButton btnOpenSymbolLevelsEditor; |
89 | private SingleSymbolLegend legend;
|
||
90 | 11850 | jaume | private ZSort zSort;
|
91 | 10679 | jaume | |
92 | 21299 | vcaballero | |
93 | 10679 | jaume | 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 | 11558 | jaume | public void setData(FLayer lyr, ILegend legend) { |
110 | 10679 | jaume | try {
|
111 | shapeType = ((FLyrVect) lyr).getShapeType(); |
||
112 | 21299 | vcaballero | } catch (ReadException e) {
|
113 | 10679 | jaume | NotificationManager.addError("Could not find out the shape type" ,e);
|
114 | } |
||
115 | if (legend instanceof SingleSymbolLegend) { |
||
116 | setSymbol(legend.getDefaultSymbol()); |
||
117 | 13928 | jaume | this.legend = (SingleSymbolLegend) legend;
|
118 | 12427 | jaume | |
119 | 10679 | jaume | } else {
|
120 | 13928 | jaume | this.legend = (SingleSymbolLegend) LegendFactory.
|
121 | createSingleSymbolLegend(shapeType); |
||
122 | 10679 | jaume | } |
123 | 16332 | jdominguez | getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
124 | 10679 | jaume | } |
125 | |||
126 | /* (non-Javadoc)
|
||
127 | * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
||
128 | */
|
||
129 | 11558 | jaume | public ILegend getLegend() {
|
130 | 11850 | jaume | SingleSymbolLegend leg = new SingleSymbolLegend(getSymbolPreviewPanel().getSymbol());
|
131 | leg.setZSort(zSort); |
||
132 | 13955 | jaume | return leg;
|
133 | 10679 | jaume | } |
134 | |||
135 | public String getDescription() { |
||
136 | 11850 | jaume | return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
137 | 10679 | jaume | } |
138 | |||
139 | public Class getParentClass() { |
||
140 | return Features.class;
|
||
141 | } |
||
142 | |||
143 | public String getTitle() { |
||
144 | return PluginServices.getText(this,"Simbolo_unico"); |
||
145 | } |
||
146 | |||
147 | public JPanel getPanel() { |
||
148 | return this; |
||
149 | } |
||
150 | |||
151 | 18623 | jdominguez | public ImageIcon getIcon() { |
152 | return new ImageIcon(this.getClass().getClassLoader(). |
||
153 | getResource("images/single-symbol.png"));
|
||
154 | 10679 | jaume | } |
155 | |||
156 | public Class getLegendClass() { |
||
157 | return SingleSymbolLegend.class;
|
||
158 | } |
||
159 | /**
|
||
160 | * This method initializes symbolPanel
|
||
161 | *
|
||
162 | * @return javax.swing.JPanel
|
||
163 | */
|
||
164 | private JPanel getSymbolPanel() { |
||
165 | if (symbolPanel == null) { |
||
166 | symbolPanel = new JPanel(); |
||
167 | symbolPanel.setBorder( |
||
168 | BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
||
169 | symbolPanel.add(getSymbolPreviewPanel()); |
||
170 | symbolPanel.add(getBtnOpenSymbolSelector()); |
||
171 | 11704 | jaume | symbolPanel.add(getBtnOpenSymbolLevelsEditor()); |
172 | 10679 | jaume | } |
173 | return symbolPanel;
|
||
174 | } |
||
175 | |||
176 | 11704 | jaume | private JButton getBtnOpenSymbolLevelsEditor() { |
177 | if (btnOpenSymbolLevelsEditor == null) { |
||
178 | btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
||
179 | btnOpenSymbolLevelsEditor.addActionListener(this);
|
||
180 | } |
||
181 | |||
182 | return btnOpenSymbolLevelsEditor;
|
||
183 | } |
||
184 | 10679 | jaume | private JButton getBtnOpenSymbolSelector() { |
185 | if (btnOpenSymbolSelector == null) { |
||
186 | btnOpenSymbolSelector = new JButton(); |
||
187 | btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
||
188 | 11704 | jaume | btnOpenSymbolSelector.addActionListener(this);
|
189 | 10679 | jaume | } |
190 | return btnOpenSymbolSelector;
|
||
191 | } |
||
192 | |||
193 | private SymbolPreviewer getSymbolPreviewPanel() {
|
||
194 | if (symbolPreviewComponent == null) { |
||
195 | symbolPreviewComponent = new SymbolPreviewer();
|
||
196 | symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
||
197 | symbolPreviewComponent.setPreferredSize(new Dimension(120, 40)); |
||
198 | } |
||
199 | return symbolPreviewComponent;
|
||
200 | } |
||
201 | /**
|
||
202 | * This method initializes legendPanel
|
||
203 | *
|
||
204 | * @return javax.swing.JPanel
|
||
205 | */
|
||
206 | private GridBagLayoutPanel getLegendPanel() {
|
||
207 | if (legendPanel == null) { |
||
208 | legendPanel = new GridBagLayoutPanel();
|
||
209 | legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
||
210 | PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
||
211 | legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
||
212 | } |
||
213 | return legendPanel;
|
||
214 | } |
||
215 | |||
216 | public void setShapeType(int shapeType) { |
||
217 | this.shapeType = shapeType;
|
||
218 | } |
||
219 | |||
220 | public void setSymbol(ISymbol symbol) { |
||
221 | getSymbolPreviewPanel().setSymbol(symbol); |
||
222 | 12427 | jaume | if (legend != null) |
223 | legend.setDefaultSymbol(symbol); |
||
224 | |||
225 | 10679 | jaume | } |
226 | |||
227 | public ISymbol getSymbol() {
|
||
228 | return getSymbolPreviewPanel().getSymbol();
|
||
229 | } |
||
230 | 11704 | jaume | |
231 | public boolean isSuitableFor(FLayer layer) { |
||
232 | return (layer instanceof FLyrVect) ; |
||
233 | } |
||
234 | |||
235 | public void actionPerformed(ActionEvent e) { |
||
236 | JComponent c = (JComponent) e.getSource(); |
||
237 | if (c.equals(getBtnOpenSymbolSelector())){
|
||
238 | 13729 | jaume | ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
239 | 11704 | jaume | PluginServices.getMDIManager().addWindow(se); |
240 | ISymbol sym = (ISymbol) se.getSelectedObject(); |
||
241 | if (sym != null) { |
||
242 | // no symbol, no changes
|
||
243 | setSymbol((ISymbol) se.getSelectedObject()); |
||
244 | } |
||
245 | } else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
||
246 | 11850 | jaume | if (legend != null) { |
247 | ZSort myZSort = legend.getZSort(); |
||
248 | if (myZSort == null) { |
||
249 | myZSort = new ZSort(legend);
|
||
250 | } |
||
251 | SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
||
252 | 11704 | jaume | PluginServices.getMDIManager().addWindow(sl); |
253 | 11850 | jaume | zSort = sl.getZSort(); |
254 | 11704 | jaume | } |
255 | } |
||
256 | } |
||
257 | |||
258 | 13955 | jaume | } |