root / org.gvsig.legend.heatmap / trunk / org.gvsig.legend.heatmap / org.gvsig.legend.heatmap.swing / org.gvsig.legend.heatmap.swing.impl / src / main / java / org / gvsig / legend / heatmap / swing / impl / DefaultHeatmapLegendEditor.java @ 1853
History | View | Annotate | Download (9.98 KB)
1 | 1717 | jjdelcerro | |
---|---|---|---|
2 | package org.gvsig.legend.heatmap.swing.impl; |
||
3 | |||
4 | 1766 | jjdelcerro | import java.awt.Color; |
5 | 1851 | jjdelcerro | import javax.swing.AbstractButton; |
6 | 1717 | jjdelcerro | import javax.swing.ImageIcon; |
7 | 1766 | jjdelcerro | import javax.swing.JFormattedTextField; |
8 | 1851 | jjdelcerro | import javax.swing.JLabel; |
9 | 1717 | jjdelcerro | import javax.swing.JPanel; |
10 | 1766 | jjdelcerro | import javax.swing.event.ChangeEvent; |
11 | import javax.swing.event.ChangeListener; |
||
12 | import org.apache.commons.lang3.StringUtils; |
||
13 | import org.gvsig.app.gui.styling.ColorSchemeSelector; |
||
14 | import org.gvsig.app.project.documents.view.legend.gui.Features; |
||
15 | import org.gvsig.fmap.dal.exception.DataException; |
||
16 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
17 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
18 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
19 | 1717 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.FLayer; |
20 | 1766 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
21 | 1717 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
22 | import org.gvsig.legend.heatmap.lib.api.HeatmapLegend; |
||
23 | import org.gvsig.legend.heatmap.lib.api.HeatmapLegendLocator; |
||
24 | import org.gvsig.legend.heatmap.swing.api.HeatmapLegendEditor; |
||
25 | import org.gvsig.tools.ToolsLocator; |
||
26 | import org.gvsig.tools.i18n.I18nManager; |
||
27 | 1766 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
28 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
29 | import org.gvsig.tools.swing.api.ColorChooserController; |
||
30 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
31 | 1717 | jjdelcerro | |
32 | |||
33 | public class DefaultHeatmapLegendEditor extends DefaultHeatmapLegendEditorView implements HeatmapLegendEditor { |
||
34 | |||
35 | private static final long serialVersionUID = 4307714097793669675L; |
||
36 | |||
37 | private HeatmapLegend legend;
|
||
38 | private FLayer layer;
|
||
39 | private final Class<? extends HeatmapLegend> legendClass; |
||
40 | 1766 | jjdelcerro | private ColorChooserController hotColorChooser;
|
41 | private ColorChooserController coldColorChooser;
|
||
42 | private ColorSchemeSelector colorSchemaSelector;
|
||
43 | 1847 | fdiaz | |
44 | 1717 | jjdelcerro | public DefaultHeatmapLegendEditor() {
|
45 | this.legendClass = HeatmapLegendLocator.getHeatmapLegendManager().getLegendClass();
|
||
46 | 1851 | jjdelcerro | initComponents(); |
47 | 1717 | jjdelcerro | } |
48 | 1847 | fdiaz | |
49 | 1851 | jjdelcerro | private void initComponents(){ |
50 | 1766 | jjdelcerro | ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
51 | this.hotColorChooser = toolsSwingManager.createColorChooserController(txtHotColorLabel, btnHotColor, sldHotColorAlpha);
|
||
52 | this.coldColorChooser = toolsSwingManager.createColorChooserController(txtColdColorLabel, btnColdColor, sldColdColorAlpha);
|
||
53 | this.colorSchemaSelector = new ColorSchemeSelector(cboColorTable, false); |
||
54 | this.rdbUseColorRamp.addChangeListener(new ChangeListener() { |
||
55 | @Override
|
||
56 | public void stateChanged(ChangeEvent e) { |
||
57 | useColorModeChanged(); |
||
58 | } |
||
59 | }); |
||
60 | this.chkUseField.addChangeListener(new ChangeListener() { |
||
61 | @Override
|
||
62 | public void stateChanged(ChangeEvent e) { |
||
63 | useFieldChanged(); |
||
64 | } |
||
65 | }); |
||
66 | this.chkColorTableUseAlpha.addChangeListener(new ChangeListener() { |
||
67 | @Override
|
||
68 | public void stateChanged(ChangeEvent e) { |
||
69 | useAlphaInColorTableChanged(); |
||
70 | } |
||
71 | }); |
||
72 | 1851 | jjdelcerro | translateAll(); |
73 | } |
||
74 | 1853 | fdiaz | |
75 | private void translateAll() { |
||
76 | 1851 | jjdelcerro | this.translate(this.lblDistance); |
77 | this.translate(this.lblPixels); |
||
78 | this.translate(this.rdbUseColorRamp); |
||
79 | this.translate(this.lblNumberOfColors); |
||
80 | this.translate(this.lblHotColor); |
||
81 | this.translate(this.lblHotColorAlpha); |
||
82 | this.translate(this.lblColdColor); |
||
83 | 1853 | fdiaz | this.translate(this.lblColdColorAlpha); |
84 | 1851 | jjdelcerro | this.translate(this.rdbUseColorTable); |
85 | this.translate(this.lblColorTable); |
||
86 | this.translate(this.chkColorTableUseAlpha); |
||
87 | this.translate(this.lblHotColorTransparency); |
||
88 | this.translate(this.lblColdColorTransparency); |
||
89 | this.translate(this.chkUseField); |
||
90 | } |
||
91 | 1853 | fdiaz | |
92 | 1851 | jjdelcerro | private void translate(AbstractButton component) { |
93 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
94 | component.setText(i18n.getTranslation(component.getText())); |
||
95 | } |
||
96 | 1853 | fdiaz | |
97 | 1851 | jjdelcerro | private void translate(JLabel component) { |
98 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
99 | component.setText(i18n.getTranslation(component.getText())); |
||
100 | } |
||
101 | 1853 | fdiaz | |
102 | 1851 | jjdelcerro | @Override
|
103 | public void setData(FLayer layer, ILegend legend) { |
||
104 | if( layer == this.layer && legend == this.legend ) { |
||
105 | return;
|
||
106 | } |
||
107 | this.layer = layer;
|
||
108 | if( this.getLegendClass().isInstance(legend) ) { |
||
109 | this.legend = (HeatmapLegend) legend;
|
||
110 | } else {
|
||
111 | this.legend = HeatmapLegendLocator.getHeatmapLegendManager().create();
|
||
112 | } |
||
113 | 1766 | jjdelcerro | this.spnDistance.setValue(this.legend.getDistance()); |
114 | if( this.legend.useRamp() ) { |
||
115 | this.rdbUseColorRamp.setSelected(true); |
||
116 | } else {
|
||
117 | this.rdbUseColorTable.setSelected(true); |
||
118 | } |
||
119 | if( this.legend.useAlphaInColorTable() ) { |
||
120 | this.chkColorTableUseAlpha.setSelected(true); |
||
121 | 1853 | fdiaz | this.coldColorChooser.set(this.legend.getRampColdColor()); |
122 | this.hotColorChooser.set(this.legend.getRampHotColor()); |
||
123 | this.spnNumberOfColors.setValue(this.legend.getRampNumColors()); |
||
124 | |||
125 | 1766 | jjdelcerro | } else {
|
126 | this.chkColorTableUseAlpha.setSelected(false); |
||
127 | } |
||
128 | this.sldColorTableColdAlpha.setValue(this.legend.getColorTableColdColorAlpha()); |
||
129 | this.sldColorTableHotAlpha.setValue(this.legend.getColorTableHotColorAlpha()); |
||
130 | |||
131 | 1853 | fdiaz | |
132 | 1766 | jjdelcerro | this.chkUseField.setEnabled(false); |
133 | this.chkUseField.setSelected(false); |
||
134 | this.cboFields.setEnabled(false); |
||
135 | this.cboFields.removeAllItems();
|
||
136 | if( layer instanceof FLyrVect ) { |
||
137 | FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
||
138 | if( store != null ) { |
||
139 | try {
|
||
140 | FeatureType ftype = store.getDefaultFeatureType(); |
||
141 | for( FeatureAttributeDescriptor attr : ftype ) {
|
||
142 | this.cboFields.addItem(attr.getName());
|
||
143 | } |
||
144 | if( this.cboFields.getItemCount()>0 ) { |
||
145 | this.chkUseField.setEnabled(true); |
||
146 | if( !StringUtils.isEmpty(this.legend.getFieldName()) ) { |
||
147 | this.chkUseField.setSelected(true); |
||
148 | this.cboFields.setSelectedItem(this.legend.getFieldName()); |
||
149 | this.cboFields.setEnabled(true); |
||
150 | } |
||
151 | } |
||
152 | } catch (Exception ex) { |
||
153 | 1847 | fdiaz | |
154 | 1766 | jjdelcerro | } |
155 | } |
||
156 | } |
||
157 | 1717 | jjdelcerro | } |
158 | 1847 | fdiaz | |
159 | 1766 | jjdelcerro | private void useColorModeChanged() { |
160 | if( this.rdbUseColorRamp.isSelected() ) { |
||
161 | this.hotColorChooser.setEnabled(true); |
||
162 | this.coldColorChooser.setEnabled(true); |
||
163 | this.spnNumberOfColors.setEnabled(true); |
||
164 | this.cboColorTable.setEnabled(false); |
||
165 | this.chkColorTableUseAlpha.setEnabled(false); |
||
166 | this.sldColorTableColdAlpha.setEnabled(false); |
||
167 | this.sldColorTableHotAlpha.setEnabled(false); |
||
168 | 1853 | fdiaz | this.spnNumberOfColors.setValue(this.legend.getRampNumColors()); |
169 | this.coldColorChooser.set(this.legend.getRampColdColor()); |
||
170 | this.hotColorChooser.set(this.legend.getRampHotColor()); |
||
171 | 1766 | jjdelcerro | } else {
|
172 | this.hotColorChooser.setEnabled(false); |
||
173 | this.coldColorChooser.setEnabled(false); |
||
174 | this.spnNumberOfColors.setEnabled(false); |
||
175 | this.cboColorTable.setEnabled(true); |
||
176 | this.chkColorTableUseAlpha.setEnabled(true); |
||
177 | this.sldColorTableColdAlpha.setEnabled(true); |
||
178 | this.sldColorTableHotAlpha.setEnabled(true); |
||
179 | 1847 | fdiaz | this.colorSchemaSelector.setSelectedColors(this.legend.getSourceColorTable()); |
180 | 1766 | jjdelcerro | } |
181 | } |
||
182 | 1847 | fdiaz | |
183 | 1766 | jjdelcerro | private void useFieldChanged() { |
184 | this.cboFields.setEnabled(this.chkUseField.isSelected()); |
||
185 | } |
||
186 | 1847 | fdiaz | |
187 | 1766 | jjdelcerro | private void useAlphaInColorTableChanged() { |
188 | boolean x = this.chkColorTableUseAlpha.isSelected(); |
||
189 | this.sldColorTableColdAlpha.setEnabled(x);
|
||
190 | this.sldColorTableHotAlpha.setEnabled(x);
|
||
191 | } |
||
192 | 1847 | fdiaz | |
193 | 1717 | jjdelcerro | @Override
|
194 | public ILegend getLegend() {
|
||
195 | 1766 | jjdelcerro | legend.setDistance((int) spnDistance.getValue());
|
196 | if( this.rdbUseColorRamp.isSelected() ) { |
||
197 | legend.setColorTable( |
||
198 | 1847 | fdiaz | (int) spnNumberOfColors.getValue(),
|
199 | coldColorChooser.get(), |
||
200 | 1766 | jjdelcerro | hotColorChooser.get() |
201 | ); |
||
202 | } else {
|
||
203 | legend.setColorTable( this.colorSchemaSelector.getSelectedColors());
|
||
204 | 1717 | jjdelcerro | } |
205 | 1766 | jjdelcerro | if( this.chkUseField.isSelected() ) { |
206 | String fieldName = (String) this.cboFields.getSelectedItem(); |
||
207 | if( fieldName != null ) { |
||
208 | this.legend.setFieldName(fieldName);
|
||
209 | } |
||
210 | 1717 | jjdelcerro | } |
211 | 1766 | jjdelcerro | this.legend.setColorTableColdColorAlpha(this.sldColorTableColdAlpha.getValue()); |
212 | this.legend.setColorTableHotColorAlpha(this.sldColorTableHotAlpha.getValue()); |
||
213 | this.legend.setUseAlphaInColorTable(this.chkColorTableUseAlpha.isSelected()); |
||
214 | 1847 | fdiaz | |
215 | 1717 | jjdelcerro | return legend;
|
216 | } |
||
217 | |||
218 | @Override
|
||
219 | public String getDescription() { |
||
220 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
221 | 1766 | jjdelcerro | return i18n.getTranslation( "_Heatmap_legend_description"); |
222 | 1717 | jjdelcerro | } |
223 | |||
224 | @Override
|
||
225 | public ImageIcon getIcon() { |
||
226 | 1766 | jjdelcerro | IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
227 | return theme.get("legend-overview-vectorial-heatmap"); |
||
228 | 1717 | jjdelcerro | } |
229 | |||
230 | @Override
|
||
231 | 1766 | jjdelcerro | public Class getParentClass() { |
232 | return Features.class;
|
||
233 | } |
||
234 | 1717 | jjdelcerro | |
235 | @Override
|
||
236 | public String getTitle() { |
||
237 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
238 | return i18n.getTranslation( "_Heatmap_legend"); |
||
239 | } |
||
240 | |||
241 | @Override
|
||
242 | public JPanel getPanel() { |
||
243 | return this; |
||
244 | } |
||
245 | |||
246 | @Override
|
||
247 | public Class getLegendClass() { |
||
248 | return this.legendClass; |
||
249 | } |
||
250 | |||
251 | @Override
|
||
252 | public boolean isSuitableFor(FLayer layer) { |
||
253 | return true; |
||
254 | } |
||
255 | 1766 | jjdelcerro | |
256 | private int getIntValue(JFormattedTextField text, int defaultValue) { |
||
257 | String s = text.getText();
|
||
258 | if( StringUtils.isEmpty(s) ) {
|
||
259 | return defaultValue;
|
||
260 | } |
||
261 | int value = defaultValue;
|
||
262 | try {
|
||
263 | value = Integer.parseInt(s);
|
||
264 | } catch(Throwable th) { |
||
265 | 1847 | fdiaz | |
266 | 1766 | jjdelcerro | } |
267 | return value;
|
||
268 | } |
||
269 | 1847 | fdiaz | |
270 | 1717 | jjdelcerro | } |