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 @ 40596
History | View | Annotate | Download (8.17 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.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
|
31 |
import javax.swing.BorderFactory; |
32 |
import javax.swing.BoxLayout; |
33 |
import javax.swing.ImageIcon; |
34 |
import javax.swing.JComponent; |
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.JTextField; |
37 |
import javax.swing.border.TitledBorder; |
38 |
|
39 |
import org.gvsig.andami.IconThemeHelper; |
40 |
import org.gvsig.andami.PluginServices; |
41 |
import org.gvsig.andami.messages.NotificationManager; |
42 |
import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
43 |
import org.gvsig.app.gui.styling.SymbolPreviewer; |
44 |
import org.gvsig.app.gui.styling.SymbolSelector; |
45 |
import org.gvsig.fmap.dal.exception.ReadException; |
46 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
47 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
48 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
51 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
52 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
53 |
import org.gvsig.gui.beans.swing.JButton; |
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend; |
56 |
|
57 |
|
58 |
/**
|
59 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
60 |
*/
|
61 |
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener { |
62 |
private JPanel symbolPanel = null; |
63 |
private int shapeType; |
64 |
private GridBagLayoutPanel legendPanel = null; |
65 |
private SymbolPreviewer symbolPreviewComponent;
|
66 |
private JButton btnOpenSymbolSelector; |
67 |
private JTextField txtLabel; |
68 |
private JButton btnOpenSymbolLevelsEditor; |
69 |
private SingleSymbolLegend legend;
|
70 |
private ZSort zSort;
|
71 |
|
72 |
|
73 |
public SingleSymbol() {
|
74 |
super();
|
75 |
initialize(); |
76 |
} |
77 |
/**
|
78 |
* This method initializes this
|
79 |
*
|
80 |
*/
|
81 |
private void initialize() { |
82 |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
83 |
this.setSize(new java.awt.Dimension(490,379)); |
84 |
this.add(getSymbolPanel(), null); |
85 |
this.add(getLegendPanel(), null); |
86 |
|
87 |
} |
88 |
|
89 |
public void setData(FLayer lyr, ILegend legend) { |
90 |
try {
|
91 |
shapeType = ((FLyrVect) lyr).getShapeType(); |
92 |
} catch (ReadException e) {
|
93 |
NotificationManager.addError("Could not find out the shape type" ,e);
|
94 |
} |
95 |
if (legend instanceof SingleSymbolLegend) { |
96 |
setSymbol(legend.getDefaultSymbol()); |
97 |
this.legend = (SingleSymbolLegend) legend;
|
98 |
|
99 |
} else {
|
100 |
this.legend = (SingleSymbolLegend) MapContextLocator
|
101 |
.getMapContextManager().createLegend( |
102 |
SingleSymbolLegend.LEGEND_NAME); |
103 |
this.legend.setShapeType(shapeType);
|
104 |
// LegendFactory.
|
105 |
// createSingleSymbolLegend(shapeType);
|
106 |
} |
107 |
getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
|
108 |
getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
|
109 |
this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
|
110 |
} |
111 |
|
112 |
/* (non-Javadoc)
|
113 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
114 |
*/
|
115 |
public ILegend getLegend() {
|
116 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
117 |
symbol.setDescription(txtLabel.getText()); |
118 |
AbstractVectorialLegend leg = new SingleSymbolLegend();
|
119 |
leg.setShapeType(shapeType); |
120 |
leg.setDefaultSymbol(symbol); |
121 |
leg.setZSort(zSort); |
122 |
return leg;
|
123 |
} |
124 |
|
125 |
public String getDescription() { |
126 |
return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo"); |
127 |
} |
128 |
|
129 |
public Class getParentClass() { |
130 |
return Features.class;
|
131 |
} |
132 |
|
133 |
public String getTitle() { |
134 |
return PluginServices.getText(this,"Simbolo_unico"); |
135 |
} |
136 |
|
137 |
public JPanel getPanel() { |
138 |
return this; |
139 |
} |
140 |
|
141 |
public ImageIcon getIcon() { |
142 |
return IconThemeHelper.getImageIcon("legend-overview-single-symbol"); |
143 |
} |
144 |
|
145 |
public Class getLegendClass() { |
146 |
return SingleSymbolLegend.class;
|
147 |
} |
148 |
/**
|
149 |
* This method initializes symbolPanel
|
150 |
*
|
151 |
* @return javax.swing.JPanel
|
152 |
*/
|
153 |
private JPanel getSymbolPanel() { |
154 |
if (symbolPanel == null) { |
155 |
symbolPanel = new JPanel(); |
156 |
symbolPanel.setBorder( |
157 |
BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
158 |
symbolPanel.add(getSymbolPreviewPanel()); |
159 |
symbolPanel.add(getBtnOpenSymbolSelector()); |
160 |
symbolPanel.add(getBtnOpenSymbolLevelsEditor()); |
161 |
} |
162 |
return symbolPanel;
|
163 |
} |
164 |
|
165 |
private JButton getBtnOpenSymbolLevelsEditor() { |
166 |
if (btnOpenSymbolLevelsEditor == null) { |
167 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
168 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
169 |
btnOpenSymbolLevelsEditor.setEnabled(legend != null);
|
170 |
} |
171 |
|
172 |
return btnOpenSymbolLevelsEditor;
|
173 |
} |
174 |
private JButton getBtnOpenSymbolSelector() { |
175 |
if (btnOpenSymbolSelector == null) { |
176 |
btnOpenSymbolSelector = new JButton(); |
177 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
178 |
btnOpenSymbolSelector.addActionListener(this);
|
179 |
} |
180 |
return btnOpenSymbolSelector;
|
181 |
} |
182 |
|
183 |
private SymbolPreviewer getSymbolPreviewPanel() {
|
184 |
if (symbolPreviewComponent == null) { |
185 |
symbolPreviewComponent = new SymbolPreviewer();
|
186 |
symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1)); |
187 |
symbolPreviewComponent.setPreferredSize(new Dimension(120, 40)); |
188 |
} |
189 |
return symbolPreviewComponent;
|
190 |
} |
191 |
/**
|
192 |
* This method initializes legendPanel
|
193 |
*
|
194 |
* @return javax.swing.JPanel
|
195 |
*/
|
196 |
private GridBagLayoutPanel getLegendPanel() {
|
197 |
if (legendPanel == null) { |
198 |
legendPanel = new GridBagLayoutPanel();
|
199 |
legendPanel.setBorder(BorderFactory.createTitledBorder(null, |
200 |
PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
201 |
legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25)); |
202 |
txtLabel.addActionListener(this);
|
203 |
} |
204 |
return legendPanel;
|
205 |
} |
206 |
|
207 |
public void setShapeType(int shapeType) { |
208 |
this.shapeType = shapeType;
|
209 |
} |
210 |
|
211 |
public void setSymbol(ISymbol symbol) { |
212 |
setOnlySymbol(symbol); |
213 |
if(symbol.getDescription() != null) { |
214 |
txtLabel.setText(symbol.getDescription()); |
215 |
} |
216 |
} |
217 |
|
218 |
private void setOnlySymbol(ISymbol symbol){ |
219 |
getSymbolPreviewPanel().setSymbol(symbol); |
220 |
if (legend != null){ |
221 |
legend.setDefaultSymbol(symbol); |
222 |
} |
223 |
} |
224 |
|
225 |
|
226 |
public ISymbol getSymbol() {
|
227 |
ISymbol symbol = getSymbolPreviewPanel().getSymbol(); |
228 |
symbol.setDescription(txtLabel.getText()); |
229 |
return symbol;
|
230 |
} |
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 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType); |
239 |
PluginServices.getMDIManager().addWindow(se); |
240 |
ISymbol sym = (ISymbol) se.getSelectedObject(); |
241 |
if (sym != null) { |
242 |
// no symbol, no changes
|
243 |
setOnlySymbol(sym); |
244 |
} |
245 |
} else if (c.equals(getBtnOpenSymbolLevelsEditor())){ |
246 |
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 |
PluginServices.getMDIManager().addWindow(sl); |
253 |
zSort = sl.getZSort(); |
254 |
} |
255 |
}else if (c.equals(txtLabel)){ |
256 |
getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText()); |
257 |
} |
258 |
} |
259 |
|
260 |
} |