svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / SingleSymbol.java @ 42880
History | View | Annotate | Download (8.71 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.app.project.documents.view.legend.gui; |
26 |
|
27 |
import java.awt.BorderLayout; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
|
32 |
import javax.swing.BorderFactory; |
33 |
import javax.swing.BoxLayout; |
34 |
import javax.swing.ImageIcon; |
35 |
import javax.swing.JComponent; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JTextField; |
38 |
import javax.swing.border.TitledBorder; |
39 |
|
40 |
import org.gvsig.andami.IconThemeHelper; |
41 |
import org.gvsig.andami.PluginServices; |
42 |
import org.gvsig.andami.messages.NotificationManager; |
43 |
import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
44 |
import org.gvsig.app.gui.styling.SymbolPreviewer; |
45 |
import org.gvsig.app.gui.styling.SymbolSelector; |
46 |
import org.gvsig.fmap.dal.exception.ReadException; |
47 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
48 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
49 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
53 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
54 |
import org.gvsig.gui.beans.swing.JButton; |
55 |
import org.gvsig.i18n.Messages; |
56 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
57 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend; |
58 |
|
59 |
|
60 |
/**
|
61 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
62 |
*/
|
63 |
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
64 |
private JPanel symbolPanel = null; |
65 |
private int shapeType; |
66 |
private GridBagLayoutPanel legendPanel = null; |
67 |
private SymbolPreviewer symbolPreviewComponent;
|
68 |
private JButton btnOpenSymbolSelector; |
69 |
private JTextField txtLabel; |
70 |
private JButton btnOpenSymbolLevelsEditor; |
71 |
private SingleSymbolLegend legend;
|
72 |
private ZSort zSort;
|
73 |
|
74 |
|
75 |
public SingleSymbol() {
|
76 |
super();
|
77 |
initialize(); |
78 |
} |
79 |
/**
|
80 |
* This method initializes this
|
81 |
*
|
82 |
*/
|
83 |
private void initialize() { |
84 |
this.setLayout(new BorderLayout()); |
85 |
this.setSize(new java.awt.Dimension(320, 160)); |
86 |
this.add(getSymbolPanel(), BorderLayout.CENTER); |
87 |
this.add(getLegendPanel(), BorderLayout.SOUTH); |
88 |
|
89 |
} |
90 |
|
91 |
public void setData(FLayer lyr, ILegend legend) { |
92 |
try {
|
93 |
shapeType = ((FLyrVect) lyr).getShapeType(); |
94 |
} catch (ReadException e) {
|
95 |
NotificationManager.addError("Could not find out the shape type" ,e);
|
96 |
} |
97 |
if (legend instanceof SingleSymbolLegend) { |
98 |
setSymbol(legend.getDefaultSymbol()); |
99 |
this.legend = (SingleSymbolLegend) legend;
|
100 |
|
101 |
} else {
|
102 |
this.legend = (SingleSymbolLegend) MapContextLocator
|
103 |
.getMapContextManager().createLegend( |
104 |
SingleSymbolLegend.LEGEND_NAME); |
105 |
this.legend.setShapeType(shapeType);
|
106 |
// LegendFactory.
|
107 |
// createSingleSymbolLegend(shapeType);
|
108 |
} |
109 |
getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
110 |
getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
|
111 |
this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
|
112 |
} |
113 |
|
114 |
/* (non-Javadoc)
|
115 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
116 |
*/
|
117 |
public ILegend getLegend() {
|
118 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
119 |
symbol.setDescription(txtLabel.getText()); |
120 |
AbstractVectorialLegend leg = new SingleSymbolLegend();
|
121 |
leg.setShapeType(shapeType); |
122 |
leg.setDefaultSymbol(symbol); |
123 |
leg.setZSort(zSort); |
124 |
return leg;
|
125 |
} |
126 |
|
127 |
public String getDescription() { |
128 |
return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
129 |
} |
130 |
|
131 |
public Class getParentClass() { |
132 |
return Features.class;
|
133 |
} |
134 |
|
135 |
public String getTitle() { |
136 |
return PluginServices.getText(this,"Simbolo_unico"); |
137 |
} |
138 |
|
139 |
public JPanel getPanel() { |
140 |
return this; |
141 |
} |
142 |
|
143 |
public ImageIcon getIcon() { |
144 |
return IconThemeHelper.getImageIcon("legend-overview-single-symbol"); |
145 |
} |
146 |
|
147 |
public Class getLegendClass() { |
148 |
return SingleSymbolLegend.class;
|
149 |
} |
150 |
/**
|
151 |
* This method initializes symbolPanel
|
152 |
*
|
153 |
* @return javax.swing.JPanel
|
154 |
*/
|
155 |
private JPanel getSymbolPanel() { |
156 |
if (symbolPanel == null) { |
157 |
symbolPanel = new JPanel(new BorderLayout()); |
158 |
symbolPanel.setBorder( |
159 |
BorderFactory.createTitledBorder(null, |
160 |
Messages.getText("symbol"), TitledBorder.DEFAULT_JUSTIFICATION, |
161 |
TitledBorder.DEFAULT_POSITION, null, null)); |
162 |
|
163 |
symbolPanel.add( |
164 |
putInPanel(getSymbolPreviewPanel()), |
165 |
BorderLayout.CENTER);
|
166 |
|
167 |
JPanel bp = new JPanel(new BorderLayout()); |
168 |
bp.add(putInPanel(getBtnOpenSymbolSelector()), BorderLayout.CENTER);
|
169 |
bp.add(putInPanel(getBtnOpenSymbolLevelsEditor()), BorderLayout.SOUTH);
|
170 |
|
171 |
symbolPanel.add(putInPanel(bp), BorderLayout.EAST);
|
172 |
} |
173 |
return symbolPanel;
|
174 |
} |
175 |
|
176 |
private JPanel putInPanel(JComponent comp) { |
177 |
JPanel resp = new JPanel(); |
178 |
resp.add(comp); |
179 |
return resp;
|
180 |
} |
181 |
|
182 |
private JButton getBtnOpenSymbolLevelsEditor() { |
183 |
if (btnOpenSymbolLevelsEditor == null) { |
184 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
185 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
186 |
btnOpenSymbolLevelsEditor.setEnabled(legend != null);
|
187 |
} |
188 |
|
189 |
return btnOpenSymbolLevelsEditor;
|
190 |
} |
191 |
private JButton getBtnOpenSymbolSelector() { |
192 |
if (btnOpenSymbolSelector == null) { |
193 |
btnOpenSymbolSelector = new JButton(); |
194 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
195 |
btnOpenSymbolSelector.addActionListener(this);
|
196 |
} |
197 |
return btnOpenSymbolSelector;
|
198 |
} |
199 |
|
200 |
private SymbolPreviewer getSymbolPreviewPanel() {
|
201 |
if (symbolPreviewComponent == null) { |
202 |
symbolPreviewComponent = new SymbolPreviewer();
|
203 |
symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
204 |
symbolPreviewComponent.setPreferredSize(new Dimension(150, 75)); |
205 |
} |
206 |
return symbolPreviewComponent;
|
207 |
} |
208 |
/**
|
209 |
* This method initializes legendPanel
|
210 |
*
|
211 |
* @return javax.swing.JPanel
|
212 |
*/
|
213 |
private GridBagLayoutPanel getLegendPanel() {
|
214 |
if (legendPanel == null) { |
215 |
legendPanel = new GridBagLayoutPanel();
|
216 |
legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
217 |
PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
218 |
legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
219 |
txtLabel.addActionListener(this);
|
220 |
} |
221 |
return legendPanel;
|
222 |
} |
223 |
|
224 |
public void setShapeType(int shapeType) { |
225 |
this.shapeType = shapeType;
|
226 |
} |
227 |
|
228 |
public void setSymbol(ISymbol symbol) { |
229 |
getSymbolPreviewPanel().setSymbol(symbol); |
230 |
if(symbol.getDescription() != null) { |
231 |
txtLabel.setText(symbol.getDescription()); |
232 |
} |
233 |
if (legend != null){ |
234 |
legend.setDefaultSymbol(symbol); |
235 |
} |
236 |
} |
237 |
|
238 |
private void setOnlySymbol(ISymbol symbol){ |
239 |
getSymbolPreviewPanel().setSymbol(symbol); |
240 |
if (legend != null){ |
241 |
legend.setDefaultSymbol(symbol); |
242 |
} |
243 |
} |
244 |
|
245 |
|
246 |
public ISymbol getSymbol() {
|
247 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
248 |
symbol.setDescription(txtLabel.getText()); |
249 |
return symbol;
|
250 |
} |
251 |
public boolean isSuitableFor(FLayer layer) { |
252 |
return (layer instanceof FLyrVect) ; |
253 |
} |
254 |
|
255 |
public void actionPerformed(ActionEvent e) { |
256 |
JComponent c = (JComponent) e.getSource(); |
257 |
if (c.equals(getBtnOpenSymbolSelector())){
|
258 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
259 |
PluginServices.getMDIManager().addWindow(se); |
260 |
ISymbol sym = (ISymbol) se.getSelectedObject(); |
261 |
if (sym != null) { |
262 |
// no symbol, no changes
|
263 |
setOnlySymbol(sym); |
264 |
} |
265 |
} else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
266 |
if (legend != null) { |
267 |
ZSort myZSort = legend.getZSort(); |
268 |
if (myZSort == null) { |
269 |
myZSort = new ZSort(legend);
|
270 |
} |
271 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
272 |
PluginServices.getMDIManager().addWindow(sl); |
273 |
zSort = sl.getZSort(); |
274 |
} |
275 |
}else if (c.equals(txtLabel)){ |
276 |
getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText()); |
277 |
} |
278 |
} |
279 |
|
280 |
} |