root / org.gvsig.legend.aggregate / trunk / org.gvsig.legend.aggregate / org.gvsig.legend.aggregate.swing / org.gvsig.legend.aggregate.swing.impl / src / main / java / org / gvsig / legend / aggregate / swing / impl / DefaultAggregateLegendEditor.java @ 1846
History | View | Annotate | Download (11.9 KB)
1 |
|
---|---|
2 |
package org.gvsig.legend.aggregate.swing.impl; |
3 |
|
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.awt.event.ItemEvent; |
8 |
import java.awt.event.ItemListener; |
9 |
import java.util.Collection; |
10 |
import javax.swing.AbstractButton; |
11 |
import javax.swing.DefaultComboBoxModel; |
12 |
import javax.swing.ImageIcon; |
13 |
import javax.swing.JLabel; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.SwingUtilities; |
16 |
import javax.swing.event.ChangeEvent; |
17 |
import javax.swing.event.ChangeListener; |
18 |
import org.gvsig.app.gui.styling.StyleSelector; |
19 |
import org.gvsig.app.project.documents.view.legend.gui.Features; |
20 |
import org.gvsig.fmap.dal.exception.DataException; |
21 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
22 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
23 |
import org.gvsig.fmap.dal.feature.FeatureType; |
24 |
import org.gvsig.fmap.geom.Geometry; |
25 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
26 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
27 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
28 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
29 |
import org.gvsig.legend.aggregate.lib.api.AggregateLegend; |
30 |
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator; |
31 |
import org.gvsig.legend.aggregate.lib.api.Operation; |
32 |
import org.gvsig.legend.aggregate.swing.api.AggregateLegendEditor; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.i18n.I18nManager; |
35 |
import org.gvsig.tools.swing.api.ColorChooserController; |
36 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
37 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
38 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
39 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
40 |
|
41 |
|
42 |
public class DefaultAggregateLegendEditor extends DefaultAggregateLegendEditorView implements AggregateLegendEditor { |
43 |
|
44 |
private static final long serialVersionUID = 4307714097793669675L; |
45 |
|
46 |
private final Class<? extends AggregateLegend> legendClass; |
47 |
private AggregateLegend legend;
|
48 |
private FLayer layer;
|
49 |
private ILabelStyle style;
|
50 |
private final ColorChooserController outlineColor; |
51 |
private final ColorChooserController fillColor; |
52 |
private final ColorChooserController textColor; |
53 |
|
54 |
public DefaultAggregateLegendEditor() {
|
55 |
this.legendClass = AggregateLegendLocator.getAggregateLegendManager().getLegendClass();
|
56 |
this.btnStyle.addActionListener(new ActionListener() { |
57 |
@Override
|
58 |
public void actionPerformed(ActionEvent e) { |
59 |
doSelectLabelStyle(); |
60 |
} |
61 |
}); |
62 |
this.outlineColor = ToolsSwingLocator.getToolsSwingManager().createColorChooserController(
|
63 |
txtOutlineColor, btnOutlineColor, sldOutlineColorAlpha |
64 |
); |
65 |
this.fillColor = ToolsSwingLocator.getToolsSwingManager().createColorChooserController(
|
66 |
txtFillColor, btnFillColor, sldFillColorAlpha |
67 |
); |
68 |
this.textColor = ToolsSwingLocator.getToolsSwingManager().createColorChooserController(
|
69 |
txtTextColor, btnTextColor, sldTextColorAlpha |
70 |
); |
71 |
Collection<Operation> operations = AggregateLegendLocator.getAggregateLegendManager().getOperations(); |
72 |
DefaultComboBoxModel<Operation> operationsModel = new DefaultComboBoxModel<>(); |
73 |
for( Operation operation : operations ) { |
74 |
operationsModel.addElement(operation); |
75 |
} |
76 |
this.cboOperation.setModel(operationsModel);
|
77 |
this.rdbBasic.addChangeListener(new ChangeListener() { |
78 |
@Override
|
79 |
public void stateChanged(ChangeEvent e) { |
80 |
doChangeMode(); |
81 |
} |
82 |
}); |
83 |
this.rdbStyled.addChangeListener(new ChangeListener() { |
84 |
@Override
|
85 |
public void stateChanged(ChangeEvent e) { |
86 |
doChangeMode(); |
87 |
} |
88 |
}); |
89 |
this.btnTextFont.addActionListener(new ActionListener() { |
90 |
@Override
|
91 |
public void actionPerformed(ActionEvent e) { |
92 |
showFontChooser(); |
93 |
} |
94 |
}); |
95 |
this.cboOperation.addItemListener(new ItemListener() { |
96 |
@Override
|
97 |
public void itemStateChanged(ItemEvent e) { |
98 |
// Para evitar cuelgues en depuracion
|
99 |
SwingUtilities.invokeLater(new Runnable() { |
100 |
@Override
|
101 |
public void run() { |
102 |
doOperationChanged(); |
103 |
} |
104 |
}); |
105 |
} |
106 |
}); |
107 |
this.translateAll();
|
108 |
} |
109 |
|
110 |
private void translate(AbstractButton component) { |
111 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
112 |
component.setText(i18n.getTranslation(component.getText())); |
113 |
} |
114 |
|
115 |
private void translate(JLabel component) { |
116 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
117 |
component.setText(i18n.getTranslation(component.getText())); |
118 |
} |
119 |
|
120 |
private void translateAll() { |
121 |
this.translate(this.rdbBasic); |
122 |
this.translate(this.lblSymbolSize); |
123 |
this.translate(this.lblFillColor); |
124 |
this.translate(this.lblFillColorAlpha); |
125 |
this.translate(this.lblOutlineColor); |
126 |
this.translate(this.lblOutlineColorAlpha); |
127 |
this.translate(this.lblTextColor); |
128 |
this.translate(this.lblTextColorAlpha); |
129 |
this.translate(this.lblTextFont); |
130 |
this.translate(this.lblShowBounds); |
131 |
this.translate(this.rdbStyled); |
132 |
this.translate(this.lblStyle); |
133 |
this.translate(this.lblOperation); |
134 |
this.translate(this.lblOperationAttribute); |
135 |
this.translate(this.lblOperationValue); |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void setData(FLayer layer, ILegend legend) { |
140 |
this.layer = layer;
|
141 |
if( this.getLegendClass().isInstance(legend) ) { |
142 |
this.legend = (AggregateLegend) legend;
|
143 |
} else {
|
144 |
this.legend = AggregateLegendLocator.getAggregateLegendManager().createAggregateLegend();
|
145 |
} |
146 |
this.spnSymbolSize.setValue(this.legend.getSymbolSize()); |
147 |
this.outlineColor.set(this.legend.getOutlineColor()); |
148 |
this.fillColor.set(this.legend.getFillColor()); |
149 |
this.textColor.set(this.legend.getTextColor()); |
150 |
this.chkShowBounds.setSelected(this.legend.isShowBounds()); |
151 |
this.txtTextFont.setText(this.legend.getFont().getFontName()); |
152 |
if( this.legend.getLabelStyle()!=null ) { |
153 |
this.txtStyle.setText(this.legend.getLabelStyle().getDescription()); |
154 |
} |
155 |
Operation operation = this.legend.getOperation(); |
156 |
this.txtOutlineColor.setText(operation.getAditionalValue()==null? "":operation.getAditionalValue()); |
157 |
if( this.layer instanceof FLyrVect ) { |
158 |
FeatureStore store = ((FLyrVect)this.layer).getFeatureStore();
|
159 |
try {
|
160 |
FeatureType type = store.getDefaultFeatureType(); |
161 |
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(); |
162 |
for( FeatureAttributeDescriptor attr : type ) {
|
163 |
model.addElement(attr.getName()); |
164 |
} |
165 |
this.cboOperationAttribute.setModel(model);
|
166 |
} catch (DataException ex) {
|
167 |
this.cboOperationAttribute.removeAllItems();
|
168 |
} |
169 |
this.cboOperationAttribute.setSelectedIndex(0); |
170 |
this.cboOperationAttribute.setSelectedItem(operation.getAttributeName());
|
171 |
} |
172 |
for( int i=0; i<this.cboOperation.getItemCount(); i++ ) { |
173 |
Operation x = (Operation) this.cboOperation.getItemAt(i); |
174 |
if( x.getName().equalsIgnoreCase(this.legend.getOperation().getName()) ) { |
175 |
this.cboOperation.setSelectedIndex(i);
|
176 |
doOperationChanged(); |
177 |
break;
|
178 |
} |
179 |
} |
180 |
this.rdbBasic.setSelected(!this.legend.isUseStyle()); |
181 |
this.rdbStyled.setSelected(this.legend.isUseStyle()); |
182 |
} |
183 |
|
184 |
@Override
|
185 |
public ILegend getLegend() {
|
186 |
|
187 |
legend.setUseStyle(this.rdbStyled.isSelected());
|
188 |
legend.setSymbolSize((int) this.spnSymbolSize.getValue()); |
189 |
legend.setOutlineColor(this.outlineColor.get());
|
190 |
legend.setFillColor(this.fillColor.get());
|
191 |
legend.setTextColor(this.textColor.get());
|
192 |
legend.setShowBounds(this.chkShowBounds.isSelected());
|
193 |
legend.setLabelStyle(this.style);
|
194 |
Operation operation = (Operation) this.cboOperation.getSelectedItem(); |
195 |
if( operation!=null ) { |
196 |
operation = operation.clone(); |
197 |
if( operation.isAditionalValueRequiered() ) {
|
198 |
operation.setAditionalValue(this.txtOperationValue.getText());
|
199 |
} |
200 |
if( operation.isAttributeRequiered() ) {
|
201 |
operation.setAttributeName((String) this.cboOperationAttribute.getSelectedItem()); |
202 |
} |
203 |
this.legend.setOperation(operation);
|
204 |
} |
205 |
return legend;
|
206 |
} |
207 |
|
208 |
private void doChangeMode() { |
209 |
if( this.rdbBasic.isSelected() ) { |
210 |
this.spnSymbolSize.setEnabled(true); |
211 |
this.fillColor.setEnabled(true); |
212 |
this.outlineColor.setEnabled(true); |
213 |
this.textColor.setEnabled(true); |
214 |
this.txtTextFont.setEnabled(true); |
215 |
this.chkShowBounds.setEnabled(true); |
216 |
|
217 |
this.btnStyle.setEnabled(false); |
218 |
} else {
|
219 |
this.spnSymbolSize.setEnabled(false); |
220 |
this.fillColor.setEnabled(false); |
221 |
this.outlineColor.setEnabled(false); |
222 |
this.textColor.setEnabled(false); |
223 |
this.txtTextFont.setEnabled(false); |
224 |
this.chkShowBounds.setEnabled(false); |
225 |
|
226 |
this.btnStyle.setEnabled(true); |
227 |
} |
228 |
} |
229 |
|
230 |
private void doOperationChanged() { |
231 |
Operation operation = (Operation) this.cboOperation.getSelectedItem(); |
232 |
if( operation==null ) { |
233 |
this.cboOperationAttribute.setEnabled(false); |
234 |
this.txtOperationValue.setEnabled(false); |
235 |
this.lblOperationDescription.setText(""); |
236 |
return;
|
237 |
} |
238 |
this.txtOperationValue.setEnabled(operation.isAditionalValueRequiered());
|
239 |
this.cboOperationAttribute.setEnabled(operation.isAttributeRequiered());
|
240 |
if( operation.isAttributeRequiered() && this.cboOperationAttribute.getSelectedIndex()<0 ) { |
241 |
this.cboOperationAttribute.setSelectedIndex(0); |
242 |
} |
243 |
//this.lblOperationDescription.setText(operation.getDescription());
|
244 |
this.cboOperation.setToolTipText(operation.getDescription());
|
245 |
} |
246 |
|
247 |
private void showFontChooser() { |
248 |
|
249 |
} |
250 |
|
251 |
@Override
|
252 |
public String getDescription() { |
253 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
254 |
return i18n.getTranslation( "_Aggregate_legend_description"); |
255 |
} |
256 |
|
257 |
@Override
|
258 |
public ImageIcon getIcon() { |
259 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
260 |
return theme.get("legend-overview-vectorial-aggregated"); |
261 |
} |
262 |
|
263 |
@Override
|
264 |
public Class getParentClass() { |
265 |
return Features.class;
|
266 |
} |
267 |
|
268 |
@Override
|
269 |
public String getTitle() { |
270 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
271 |
return i18n.getTranslation( "_Aggregate_legend"); |
272 |
} |
273 |
|
274 |
@Override
|
275 |
public JPanel getPanel() { |
276 |
return this; |
277 |
} |
278 |
|
279 |
@Override
|
280 |
public Class getLegendClass() { |
281 |
return this.legendClass; |
282 |
} |
283 |
|
284 |
@Override
|
285 |
public boolean isSuitableFor(FLayer layer) { |
286 |
return true; |
287 |
} |
288 |
|
289 |
private void doSelectLabelStyle() { |
290 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
291 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
292 |
final StyleSelector styleSelector = new StyleSelector(this.style, Geometry.TYPES.POINT); |
293 |
styleSelector.setPreferredSize(new Dimension(600, 350)); |
294 |
winmanager.showWindow( |
295 |
styleSelector, |
296 |
i18n.getTranslation("_Select_style"),
|
297 |
WindowManager.MODE.DIALOG |
298 |
); |
299 |
ILabelStyle x = (ILabelStyle) styleSelector.getSelectedObject(); |
300 |
if( x != null ) { |
301 |
this.style = x;
|
302 |
} |
303 |
} |
304 |
} |