Revision 44921 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/VectorialUniqueValue.java
VectorialUniqueValue.java | ||
---|---|---|
31 | 31 |
import java.awt.event.ActionEvent; |
32 | 32 |
import java.awt.event.ActionListener; |
33 | 33 |
import java.util.ArrayList; |
34 |
import java.util.Iterator; |
|
35 | 34 |
import java.util.Random; |
36 | 35 |
|
37 | 36 |
import javax.swing.DefaultComboBoxModel; |
... | ... | |
44 | 43 |
|
45 | 44 |
import org.gvsig.andami.IconThemeHelper; |
46 | 45 |
import org.gvsig.andami.PluginServices; |
47 |
import org.gvsig.andami.messages.NotificationManager; |
|
48 | 46 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
49 | 47 |
import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
50 | 48 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
69 | 67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
70 | 68 |
import org.gvsig.tools.ToolsLocator; |
71 | 69 |
import org.gvsig.tools.dispose.DisposableIterator; |
70 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
71 |
import org.gvsig.tools.i18n.I18nManager; |
|
72 | 72 |
import org.slf4j.Logger; |
73 | 73 |
import org.slf4j.LoggerFactory; |
74 | 74 |
|
... | ... | |
80 | 80 |
*/ |
81 | 81 |
public class VectorialUniqueValue extends JPanel implements ILegendPanel, ActionListener { |
82 | 82 |
|
83 |
private static final Logger logger = LoggerFactory
|
|
84 |
.getLogger(VectorialUniqueValue.class);
|
|
83 |
private static final Logger LOGGER = LoggerFactory
|
|
84 |
.getLogger(VectorialUniqueValue.class); |
|
85 | 85 |
|
86 |
protected VectorialUniqueValueLegend theLegend;
|
|
87 |
private ClassifiableVectorial layer;
|
|
88 |
private SymbolTable symbolTable;
|
|
89 |
protected JComboBox cmbFields;
|
|
90 |
private JButton btnRemoveAll;
|
|
91 |
private JButton btnRemove;
|
|
92 |
private JCheckBox chbUseDefault = null;
|
|
93 |
private JSymbolPreviewButton defaultSymbolPrev;
|
|
94 |
private VectorialUniqueValueLegend auxLegend;
|
|
95 |
private JPanel pnlCenter;
|
|
96 |
private JButton btnOpenSymbolLevelsEditor;
|
|
86 |
protected VectorialUniqueValueLegend theLegend; |
|
87 |
private ClassifiableVectorial layer; |
|
88 |
private SymbolTable symbolTable; |
|
89 |
protected JComboBox cmbFields; |
|
90 |
private JButton btnRemoveAll; |
|
91 |
private JButton btnRemove; |
|
92 |
private JCheckBox chbUseDefault = null; |
|
93 |
private JSymbolPreviewButton defaultSymbolPrev; |
|
94 |
private VectorialUniqueValueLegend auxLegend; |
|
95 |
private JPanel pnlCenter; |
|
96 |
private JButton btnOpenSymbolLevelsEditor; |
|
97 | 97 |
|
98 |
private JComboBoxColorScheme cmbColorScheme;
|
|
99 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
|
|
98 |
private JComboBoxColorScheme cmbColorScheme; |
|
99 |
private final GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
|
|
100 | 100 |
|
101 |
private MapContextManager mapContextManager = MapContextLocator |
|
102 |
.getMapContextManager(); |
|
101 |
private final MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
|
103 | 102 |
|
104 |
/**
|
|
105 |
*
|
|
106 |
*/
|
|
107 |
public VectorialUniqueValue() {
|
|
108 |
super();
|
|
109 |
initComponents();
|
|
110 |
}
|
|
103 |
/** |
|
104 |
* |
|
105 |
*/ |
|
106 |
public VectorialUniqueValue() { |
|
107 |
super(); |
|
108 |
initComponents(); |
|
109 |
} |
|
111 | 110 |
|
112 |
/** |
|
113 |
* DOCUMENT ME! |
|
114 |
*/ |
|
115 |
protected void initComponents() { |
|
116 |
JPanel pnlButtons = new JPanel(); |
|
111 |
protected void initComponents() { |
|
112 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
113 |
JPanel pnlButtons = new JPanel(); |
|
117 | 114 |
|
118 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
|
119 |
"Anadir_todos")); |
|
120 |
btnAddAll.setActionCommand("ADD_ALL_VALUES"); |
|
121 |
btnAddAll.addActionListener(this); |
|
122 |
pnlButtons.add(btnAddAll); |
|
115 |
JButton btnAddAll = new JButton(i18n.getTranslation("Anadir_todos")); |
|
116 |
btnAddAll.setActionCommand("ADD_ALL_VALUES"); |
|
117 |
btnAddAll.addActionListener(this); |
|
118 |
pnlButtons.add(btnAddAll); |
|
123 | 119 |
|
124 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir"));
|
|
125 |
btnAdd.setActionCommand("ADD_VALUE");
|
|
126 |
btnAdd.addActionListener(this);
|
|
127 |
pnlButtons.add(btnAdd);
|
|
120 |
JButton btnAdd = new JButton(i18n.getTranslation("Anadir"));
|
|
121 |
btnAdd.setActionCommand("ADD_VALUE"); |
|
122 |
btnAdd.addActionListener(this); |
|
123 |
pnlButtons.add(btnAdd); |
|
128 | 124 |
|
129 |
btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos"));
|
|
130 |
btnRemoveAll.setActionCommand("REMOVE_ALL");
|
|
131 |
btnRemoveAll.addActionListener(this);
|
|
132 |
pnlButtons.add(btnRemoveAll);
|
|
125 |
btnRemoveAll = new JButton(i18n.getTranslation("Quitar_todos"));
|
|
126 |
btnRemoveAll.setActionCommand("REMOVE_ALL"); |
|
127 |
btnRemoveAll.addActionListener(this); |
|
128 |
pnlButtons.add(btnRemoveAll); |
|
133 | 129 |
|
134 |
btnRemove = new JButton(PluginServices.getText(this, "Quitar"));
|
|
135 |
btnRemove.setActionCommand("REMOVE");
|
|
136 |
btnRemove.addActionListener(this);
|
|
137 |
pnlButtons.add(btnRemove);
|
|
130 |
btnRemove = new JButton(i18n.getTranslation("Quitar"));
|
|
131 |
btnRemove.setActionCommand("REMOVE"); |
|
132 |
btnRemove.addActionListener(this); |
|
133 |
pnlButtons.add(btnRemove); |
|
138 | 134 |
|
139 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
|
|
140 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
|
141 |
btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
|
|
142 |
pnlButtons.add(btnOpenSymbolLevelsEditor);
|
|
143 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0);
|
|
135 |
btnOpenSymbolLevelsEditor = new JButton(i18n.getTranslation("symbol_levels"));
|
|
136 |
btnOpenSymbolLevelsEditor.addActionListener(this); |
|
137 |
btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR"); |
|
138 |
pnlButtons.add(btnOpenSymbolLevelsEditor); |
|
139 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
|
144 | 140 |
|
145 |
pnlCenter = new JPanel();
|
|
146 |
pnlCenter.setLayout(new BorderLayout());
|
|
141 |
pnlCenter = new JPanel(); |
|
142 |
pnlCenter.setLayout(new BorderLayout()); |
|
147 | 143 |
|
148 |
cmbFields = new JComboBox();
|
|
149 |
cmbFields.setActionCommand("FIELD_SELECTED");
|
|
150 |
cmbFields.addActionListener(this);
|
|
151 |
cmbFields.setVisible(true);
|
|
144 |
cmbFields = new JComboBox(); |
|
145 |
cmbFields.setActionCommand("FIELD_SELECTED"); |
|
146 |
cmbFields.addActionListener(this); |
|
147 |
cmbFields.setVisible(true); |
|
152 | 148 |
|
153 |
JPanel pnlNorth = new JPanel();
|
|
154 |
pnlNorth.setLayout(new GridLayout(0, 2));
|
|
149 |
JPanel pnlNorth = new JPanel(); |
|
150 |
pnlNorth.setLayout(new GridLayout(0, 2)); |
|
155 | 151 |
|
156 |
GridBagLayoutPanel auxPanel = new GridBagLayoutPanel(); |
|
157 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText( |
|
158 |
this, "Campo_de_clasificacion") + ": "); |
|
159 |
auxPanel.add(lblFieldClassification); |
|
160 |
auxPanel.add(cmbFields); |
|
161 |
pnlNorth.add(auxPanel); |
|
152 |
GridBagLayoutPanel auxPanel = new GridBagLayoutPanel(); |
|
153 |
JLabel lblFieldClassification = new JLabel(i18n.getTranslation("Campo_de_clasificacion") + ": "); |
|
154 |
auxPanel.add(lblFieldClassification); |
|
155 |
auxPanel.add(cmbFields); |
|
156 |
pnlNorth.add(auxPanel); |
|
162 | 157 |
|
163 |
auxPanel = new GridBagLayoutPanel();
|
|
164 |
auxPanel.add(new JLabel(PluginServices.getText(this, "color_scheme") + ": "));
|
|
165 |
cmbColorScheme = new JComboBoxColorScheme(false);
|
|
166 |
cmbColorScheme.addActionListener(this);
|
|
167 |
auxPanel.add(cmbColorScheme);
|
|
168 |
pnlNorth.add(auxPanel);
|
|
158 |
auxPanel = new GridBagLayoutPanel(); |
|
159 |
auxPanel.add(new JLabel(i18n.getTranslation("color_scheme") + ": "));
|
|
160 |
cmbColorScheme = new JComboBoxColorScheme(false); |
|
161 |
cmbColorScheme.addActionListener(this); |
|
162 |
auxPanel.add(cmbColorScheme); |
|
163 |
pnlNorth.add(auxPanel); |
|
169 | 164 |
|
170 |
defaultSymbolPanel.add(getChbUseDefault(), null);
|
|
171 |
pnlNorth.add(defaultSymbolPanel);
|
|
172 |
pnlNorth.add(new JBlank(0, 30));
|
|
165 |
defaultSymbolPanel.add(getChbUseDefault(), null); |
|
166 |
pnlNorth.add(defaultSymbolPanel); |
|
167 |
pnlNorth.add(new JBlank(0, 30)); |
|
173 | 168 |
|
174 |
this.setLayout(new BorderLayout());
|
|
175 |
this.add(pnlNorth, BorderLayout.NORTH);
|
|
176 |
this.add(pnlCenter, BorderLayout.CENTER);
|
|
177 |
this.add(pnlButtons, BorderLayout.SOUTH);
|
|
169 |
this.setLayout(new BorderLayout()); |
|
170 |
this.add(pnlNorth, BorderLayout.NORTH); |
|
171 |
this.add(pnlCenter, BorderLayout.CENTER); |
|
172 |
this.add(pnlButtons, BorderLayout.SOUTH); |
|
178 | 173 |
|
179 |
}
|
|
174 |
} |
|
180 | 175 |
|
181 |
/** |
|
182 |
* DOCUMENT ME! |
|
183 |
*/ |
|
184 |
private void fillTableValues() { |
|
185 |
FeatureStore elRs; |
|
176 |
private void fillTableValues() { |
|
177 |
FeatureStore elRs; |
|
186 | 178 |
|
187 |
try { |
|
188 |
elRs = ((FLyrVect) layer).getFeatureStore(); |
|
189 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
190 |
if (fieldName == null) { |
|
191 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "no_hay_campo_seleccionado")); |
|
192 |
return; |
|
193 |
} |
|
179 |
try { |
|
180 |
elRs = ((FLyrVect) layer).getFeatureStore(); |
|
181 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
182 |
if (fieldName == null) { |
|
183 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
184 |
JOptionPane.showMessageDialog( |
|
185 |
(Component) PluginServices.getMainFrame(), |
|
186 |
i18n.getTranslation("no_hay_campo_seleccionado") |
|
187 |
); |
|
188 |
return; |
|
189 |
} |
|
194 | 190 |
|
195 |
symbolTable.removeAllItems();
|
|
191 |
symbolTable.removeAllItems(); |
|
196 | 192 |
|
197 |
int numSymbols = 0;
|
|
198 |
ISymbol theSymbol = null;
|
|
193 |
int numSymbols = 0; |
|
194 |
ISymbol theSymbol;
|
|
199 | 195 |
|
200 |
//auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend(); |
|
201 |
// auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType()); |
|
202 |
auxLegend = (VectorialUniqueValueLegend) MapContextLocator |
|
203 |
.getMapContextManager().createLegend( |
|
204 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
|
205 |
auxLegend.setShapeType(layer.getShapeType()); |
|
206 |
auxLegend.setClassifyingFieldNames(new String[]{fieldName}); |
|
207 |
FeatureAttributeDescriptor attr = elRs.getDefaultFeatureTypeQuietly().getAttributeDescriptor(fieldName); |
|
208 |
int fieldType = attr.getDataType().getType(); |
|
209 |
auxLegend.setClassifyingFieldTypes(new int[]{fieldType}); |
|
210 |
Object clave = null; |
|
196 |
auxLegend = (VectorialUniqueValueLegend) MapContextLocator |
|
197 |
.getMapContextManager().createLegend( |
|
198 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
|
199 |
auxLegend.setShapeType(layer.getShapeType()); |
|
200 |
auxLegend.setClassifyingFieldNames(new String[]{fieldName}); |
|
201 |
FeatureAttributeDescriptor attr = elRs.getDefaultFeatureTypeQuietly().getAttributeDescriptor(fieldName); |
|
202 |
int fieldType = attr.getDataType().getType(); |
|
203 |
auxLegend.setClassifyingFieldTypes(new int[]{fieldType}); |
|
204 |
Object clave; |
|
211 | 205 |
|
212 |
//Object resul;
|
|
213 |
if (chbUseDefault.isSelected()) {
|
|
214 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
|
215 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
|
|
216 |
}
|
|
206 |
//Object resul; |
|
207 |
if (chbUseDefault.isSelected()) { |
|
208 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
209 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol()); |
|
210 |
} |
|
217 | 211 |
|
218 |
Color[] colorScheme = cmbColorScheme.getSelectedColors();
|
|
212 |
Color[] colorScheme = cmbColorScheme.getSelectedColors(); |
|
219 | 213 |
|
220 |
Color[] colors = new Color[colorScheme.length]; |
|
221 |
for (int i = 0; i < colorScheme.length; i++) { |
|
222 |
colors[i] = colorScheme[i]; |
|
223 |
} |
|
224 |
auxLegend.setColorScheme(colors); |
|
214 |
Color[] colors = new Color[colorScheme.length]; |
|
215 |
System.arraycopy(colorScheme, 0, colors, 0, colorScheme.length); |
|
216 |
auxLegend.setColorScheme(colors); |
|
225 | 217 |
|
226 |
Random rand = new Random(System.currentTimeMillis());
|
|
218 |
Random rand = new Random(System.currentTimeMillis()); |
|
227 | 219 |
|
228 |
FeatureSet set = null;
|
|
229 |
DisposableIterator iterator = null;
|
|
220 |
FeatureSet set = null; |
|
221 |
DisposableIterator iterator = null; |
|
230 | 222 |
|
231 |
try {
|
|
232 |
set = elRs.getFeatureSet();
|
|
223 |
try { |
|
224 |
set = elRs.getFeatureSet(); |
|
233 | 225 |
|
234 |
int count = 0;
|
|
226 |
int count = 0; |
|
235 | 227 |
|
236 |
iterator = set.fastIterator();
|
|
237 |
while (iterator.hasNext()) {
|
|
238 |
Feature feature = (Feature) iterator.next();
|
|
239 |
clave = feature.get(fieldName);
|
|
240 |
// }
|
|
241 |
// for (int j = 0; j < elRs.getRowCount(); j++) {
|
|
242 |
// clave = elRs.getFieldValue(j, idField);
|
|
228 |
iterator = set.fastIterator(); |
|
229 |
while (iterator.hasNext()) { |
|
230 |
Feature feature = (Feature) iterator.next(); |
|
231 |
clave = feature.get(fieldName); |
|
232 |
if (clave == null) {
|
|
233 |
continue;
|
|
234 |
}
|
|
243 | 235 |
|
244 |
// if (clave instanceof NullValue) { |
|
245 |
// continue; |
|
246 |
// } |
|
247 |
if (clave == null) { |
|
248 |
continue; |
|
249 |
} |
|
236 |
// //Comprobar que no esta repetido y no hace falta |
|
237 |
// introducir en el hashtable el campo junto con el simbolo. |
|
238 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
250 | 239 |
|
251 |
// //Comprobar que no esta repetido y no hace falta |
|
252 |
// introducir en el hashtable el campo junto con el simbolo. |
|
253 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
240 |
if (count == 100) { |
|
241 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
242 |
int resp = JOptionPane.showConfirmDialog(this, |
|
243 |
i18n.getTranslation("mas_de_100_simbolos"), |
|
244 |
i18n.getTranslation("quiere_continuar"), |
|
245 |
JOptionPane.YES_NO_OPTION, |
|
246 |
JOptionPane.WARNING_MESSAGE); |
|
254 | 247 |
|
255 |
if (count == 100) { |
|
256 |
int resp = JOptionPane.showConfirmDialog(this, |
|
257 |
PluginServices.getText(this, |
|
258 |
"mas_de_100_simbolos"), |
|
259 |
PluginServices.getText(this, |
|
260 |
"quiere_continuar"), |
|
261 |
JOptionPane.YES_NO_OPTION, |
|
262 |
JOptionPane.WARNING_MESSAGE); |
|
248 |
if ((resp == JOptionPane.NO_OPTION) |
|
249 |
|| (resp == JOptionPane.DEFAULT_OPTION)) { |
|
250 |
break; |
|
251 |
} |
|
252 |
} |
|
263 | 253 |
|
264 |
if ((resp == JOptionPane.NO_OPTION) |
|
265 |
|| (resp == JOptionPane.DEFAULT_OPTION)) { |
|
266 |
break; |
|
267 |
} |
|
268 |
} |
|
254 |
// si no esta creado el simbolo se crea |
|
255 |
// jaume (moved to ISymbol); theSymbol = new |
|
256 |
// FSymbol(layer.getShapeType()); |
|
257 |
theSymbol = mapContextManager.getSymbolManager().createSymbol( |
|
258 |
layer.getShapeType(), |
|
259 |
colorScheme[rand.nextInt(colorScheme.length)] |
|
260 |
); |
|
261 |
theSymbol.setDescription(clave.toString()); |
|
262 |
auxLegend.addSymbol(clave, theSymbol); |
|
263 |
count++; |
|
264 |
} |
|
269 | 265 |
|
270 |
// si no esta creado el simbolo se crea |
|
271 |
// jaume (moved to ISymbol); theSymbol = new |
|
272 |
// FSymbol(layer.getShapeType()); |
|
273 |
theSymbol |
|
274 |
= mapContextManager.getSymbolManager() |
|
275 |
.createSymbol( |
|
276 |
layer |
|
277 |
.getShapeType(), colorScheme[rand |
|
278 |
.nextInt(colorScheme.length)]); |
|
279 |
theSymbol.setDescription(clave.toString()); |
|
280 |
auxLegend.addSymbol(clave, theSymbol); |
|
281 |
count++; |
|
282 |
} |
|
266 |
} // for |
|
267 |
} finally { |
|
268 |
DisposeUtils.disposeQuietly(iterator); |
|
269 |
DisposeUtils.disposeQuietly(set); |
|
270 |
} |
|
283 | 271 |
|
284 |
} // for |
|
285 |
} finally { |
|
286 |
if (iterator != null) { |
|
287 |
iterator.dispose(); |
|
288 |
} |
|
289 |
if (set != null) { |
|
290 |
set.dispose(); |
|
291 |
} |
|
292 |
} |
|
272 |
Object[] values = auxLegend.getValues(); |
|
273 |
String[] descriptions = new String[values.length]; |
|
274 |
ISymbol[] symbols = new ISymbol[values.length]; |
|
293 | 275 |
|
294 |
Object[] values = auxLegend.getValues(); |
|
295 |
String[] descriptions = new String[values.length]; |
|
296 |
ISymbol[] symbols = new ISymbol[values.length]; |
|
276 |
for (int i = 0; i < values.length; i++) { |
|
277 |
Object value = values[i]; |
|
278 |
symbols[i] = auxLegend.getSymbolByValue(value); |
|
279 |
descriptions[i] = symbols[i].getDescription(); |
|
280 |
} |
|
297 | 281 |
|
298 |
for (int i = 0; i < values.length; i++) {
|
|
299 |
Object value = values[i];
|
|
300 |
symbols[i] = auxLegend.getSymbolByValue(value);
|
|
301 |
descriptions[i] = symbols[i].getDescription();
|
|
302 |
}
|
|
282 |
symbolTable.fillTableFromSymbolList(symbols,
|
|
283 |
values, descriptions);
|
|
284 |
} catch (DataException e) {
|
|
285 |
LOGGER.warn("recovering_recordset", e);
|
|
286 |
} |
|
303 | 287 |
|
304 |
symbolTable.fillTableFromSymbolList(symbols, |
|
305 |
values, descriptions); |
|
306 |
// elRs.stop(); |
|
307 |
// set.dispose(); |
|
308 |
} catch (DataException e) { |
|
309 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
|
310 |
} |
|
288 |
btnRemoveAll.setEnabled(true); |
|
289 |
btnRemove.setEnabled(true); |
|
290 |
} |
|
311 | 291 |
|
312 |
btnRemoveAll.setEnabled(true); |
|
313 |
btnRemove.setEnabled(true); |
|
292 |
private boolean compareClassifyingFieldNames(String[] a, String[] b) { |
|
293 |
if (a == b) { |
|
294 |
return true; |
|
295 |
} |
|
296 |
if (a == null || b == null) { |
|
297 |
return false; |
|
298 |
} |
|
299 |
if (a.length != b.length) { |
|
300 |
return false; |
|
301 |
} |
|
302 |
for (int i = 0; i < a.length; i++) { |
|
303 |
if (!a[i].equals(b[i])) { |
|
304 |
return false; |
|
305 |
} |
|
306 |
} |
|
307 |
return true; |
|
308 |
} |
|
314 | 309 |
|
315 |
//m_bCacheDirty = false; |
|
310 |
private boolean compareClassifyingFieldTypes(int[] a, int[] b) { |
|
311 |
if (a == b) { |
|
312 |
return true; |
|
316 | 313 |
} |
314 |
if (a == null || b == null) { |
|
315 |
return false; |
|
316 |
} |
|
317 |
if (a.length != b.length) { |
|
318 |
return false; |
|
319 |
} |
|
320 |
for (int i = 0; i < a.length; i++) { |
|
321 |
if (a[i] != b[i]) { |
|
322 |
return false; |
|
323 |
} |
|
324 |
} |
|
325 |
return true; |
|
326 |
} |
|
317 | 327 |
|
318 |
private boolean compareClassifyingFieldNames(String[] a, String[] b) { |
|
319 |
if (a == b) { |
|
320 |
return true; |
|
321 |
} |
|
322 |
if (a == null || b == null) { |
|
323 |
return false; |
|
324 |
} |
|
325 |
if (a.length != b.length) { |
|
326 |
return false; |
|
327 |
} |
|
328 |
for (int i = 0; i < a.length; i++) { |
|
329 |
if (!a[i].equals(b[i])) { |
|
330 |
return false; |
|
331 |
} |
|
332 |
} |
|
333 |
return true; |
|
328 |
/** |
|
329 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo el |
|
330 |
* symbolList, si no tambi�n el arrayKeys y el defaultRenderer |
|
331 |
*/ |
|
332 |
private void fillSymbolListFromTable() { |
|
333 |
Object clave; |
|
334 |
ISymbol theSymbol; |
|
335 |
ArrayList visitedKeys = new ArrayList(); |
|
336 |
boolean changedLegend = false; |
|
337 |
|
|
338 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
339 |
String[] classifyingFieldNames = new String[]{fieldName}; |
|
340 |
if (auxLegend != null) { |
|
341 |
if (!compareClassifyingFieldNames(classifyingFieldNames, auxLegend.getClassifyingFieldNames())) { |
|
342 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
|
343 |
changedLegend = true; |
|
344 |
} |
|
345 |
} else { |
|
346 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
|
347 |
changedLegend = true; |
|
334 | 348 |
} |
335 | 349 |
|
336 |
private boolean compareClassifyingFieldTypes(int[] a, int[] b) { |
|
337 |
if (a == b) { |
|
338 |
return true; |
|
350 |
FLyrVect m = (FLyrVect) layer; |
|
351 |
|
|
352 |
try { |
|
353 |
int fieldType = m.getFeatureStore().getDefaultFeatureType() |
|
354 |
.getAttributeDescriptor(cmbFields.getSelectedIndex()) |
|
355 |
.getType(); |
|
356 |
int[] classifyingFieldTypes = new int[]{fieldType}; |
|
357 |
if (auxLegend != null) { |
|
358 |
if (!compareClassifyingFieldTypes(classifyingFieldTypes, auxLegend.getClassifyingFieldTypes())) { |
|
359 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
|
360 |
changedLegend = true; |
|
339 | 361 |
} |
340 |
if (a == null || b == null) { |
|
341 |
return false; |
|
342 |
} |
|
343 |
if (a.length != b.length) { |
|
344 |
return false; |
|
345 |
} |
|
346 |
for (int i = 0; i < a.length; i++) { |
|
347 |
if (a[i] != b[i]) { |
|
348 |
return false; |
|
349 |
} |
|
350 |
} |
|
351 |
return true; |
|
362 |
} else { |
|
363 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
|
364 |
changedLegend = true; |
|
365 |
} |
|
366 |
} catch (DataException e) { |
|
367 |
LOGGER.warn("could_not_setup_legend", e); |
|
368 |
} catch (Exception e) { |
|
369 |
LOGGER.warn("could_not_setup_legend", e); |
|
352 | 370 |
} |
353 | 371 |
|
354 |
/** |
|
355 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo el |
|
356 |
* symbolList, si no tambi�n el arrayKeys y el defaultRenderer |
|
357 |
*/ |
|
358 |
private void fillSymbolListFromTable() { |
|
359 |
Object clave = null; |
|
360 |
ISymbol theSymbol; |
|
361 |
ArrayList visitedKeys = new ArrayList(); |
|
362 |
boolean changedLegend = false; |
|
372 |
if (changedLegend) { |
|
373 |
auxLegend.clear(); |
|
374 |
} |
|
363 | 375 |
|
364 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
365 |
String[] classifyingFieldNames = new String[]{fieldName}; |
|
376 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
|
377 |
clave = symbolTable.getFieldValue(row, 1); |
|
378 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0); |
|
379 |
String description = (String) symbolTable.getFieldValue(row, 2); |
|
380 |
theSymbol.setDescription(description); |
|
381 |
ISymbol legendSymbol = null; |
|
382 |
if (auxLegend != null) { |
|
383 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
|
384 |
} |
|
385 |
if (legendSymbol == null || (auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())) { |
|
366 | 386 |
if (auxLegend != null) { |
367 |
if (!compareClassifyingFieldNames(classifyingFieldNames, auxLegend.getClassifyingFieldNames())) { |
|
368 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
|
369 |
changedLegend = true; |
|
370 |
} |
|
371 |
} else { |
|
372 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
|
373 |
changedLegend = true; |
|
387 |
auxLegend.addSymbol(clave, theSymbol); |
|
374 | 388 |
} |
389 |
} else { |
|
375 | 390 |
|
376 |
FLyrVect m = (FLyrVect) layer; |
|
391 |
// avoid same instance |
|
392 |
if (legendSymbol != theSymbol) { |
|
377 | 393 |
|
378 |
try { |
|
379 |
int fieldType = m.getFeatureStore().getDefaultFeatureType() |
|
380 |
.getAttributeDescriptor(cmbFields.getSelectedIndex()) |
|
381 |
.getType(); |
|
382 |
// int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex()); |
|
383 |
int[] classifyingFieldTypes = new int[]{fieldType}; |
|
384 |
if (auxLegend != null) { |
|
385 |
if (!compareClassifyingFieldTypes(classifyingFieldTypes, auxLegend.getClassifyingFieldTypes())) { |
|
386 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
|
387 |
changedLegend = true; |
|
388 |
} |
|
389 |
} else { |
|
390 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
|
391 |
changedLegend = true; |
|
392 |
} |
|
393 |
} catch (DataException e) { |
|
394 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e); |
|
395 |
} catch (Exception e) { |
|
396 |
NotificationManager.showMessageWarning(PluginServices.getText(this, "could_not_setup_legend"), e); |
|
397 |
} |
|
398 |
|
|
399 |
if (changedLegend) { |
|
400 |
auxLegend.clear(); |
|
401 |
} |
|
402 |
|
|
403 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
|
404 |
clave = symbolTable.getFieldValue(row, 1); |
|
405 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0); |
|
406 |
String description = (String) symbolTable.getFieldValue(row, 2); |
|
407 |
theSymbol.setDescription(description); |
|
408 |
ISymbol legendSymbol = null; |
|
409 |
if (auxLegend != null) { |
|
410 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
|
411 |
} |
|
412 |
if (legendSymbol == null || (auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())) { |
|
413 |
if (auxLegend != null) { |
|
414 |
auxLegend.addSymbol(clave, theSymbol); |
|
415 |
} |
|
416 |
} else { |
|
417 |
|
|
418 |
// avoid same instance |
|
419 |
if (legendSymbol != theSymbol) { |
|
420 |
|
|
421 |
/* |
|
394 |
/* |
|
422 | 395 |
* Perhaps use this "if" when implementations of ISymbol |
423 | 396 |
* properly implement the equals method. |
424 |
*/ |
|
425 |
// if (!legendSymbol.equals(theSymbol)) { |
|
426 |
auxLegend.replace(legendSymbol, theSymbol); |
|
427 |
// } |
|
428 |
} |
|
429 |
} |
|
430 |
visitedKeys.add(clave); |
|
397 |
*/ |
|
398 |
// if (!legendSymbol.equals(theSymbol)) { |
|
399 |
auxLegend.replace(legendSymbol, theSymbol); |
|
400 |
// } |
|
431 | 401 |
} |
402 |
} |
|
403 |
visitedKeys.add(clave); |
|
404 |
} |
|
405 |
if (auxLegend != null) { |
|
406 |
Object[] keys = auxLegend.getValues(); |
|
407 |
for (Object key : keys) { |
|
408 |
if (!visitedKeys.contains(key)) { |
|
409 |
auxLegend.delSymbol(key); |
|
410 |
} |
|
411 |
} |
|
412 |
} |
|
413 |
clave = null; |
|
414 |
if (chbUseDefault.isSelected()) { |
|
415 |
theSymbol = defaultSymbolPrev.getSymbol(); |
|
416 |
if (theSymbol != null) { |
|
417 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
418 |
String description = i18n.getTranslation("default"); |
|
419 |
theSymbol.setDescription(description); |
|
420 |
ISymbol legendSymbol = null; |
|
432 | 421 |
if (auxLegend != null) { |
433 |
Object[] keys = auxLegend.getValues(); |
|
434 |
for (int i = 0; i < keys.length; i++) { |
|
435 |
Object key = keys[i]; |
|
436 |
if (!visitedKeys.contains(key)) { |
|
437 |
auxLegend.delSymbol(key); |
|
438 |
} |
|
439 |
} |
|
422 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
|
440 | 423 |
} |
441 |
clave = null; |
|
442 |
if (chbUseDefault.isSelected()) { |
|
443 |
theSymbol = defaultSymbolPrev.getSymbol(); |
|
444 |
if (theSymbol != null) { |
|
445 |
String description = PluginServices.getText(this, "default"); |
|
446 |
theSymbol.setDescription(description); |
|
447 |
ISymbol legendSymbol = null; |
|
448 |
if (auxLegend != null) { |
|
449 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
|
450 |
} |
|
451 |
if (legendSymbol == null) { |
|
452 |
auxLegend.addSymbol(clave, theSymbol); |
|
453 |
} else { |
|
454 |
// if(!legendSymbol.equals(theSymbol)){ |
|
455 |
if (legendSymbol != theSymbol) { |
|
456 |
auxLegend.replace(legendSymbol, theSymbol); |
|
457 |
} |
|
458 |
} |
|
459 |
} |
|
424 |
if (legendSymbol == null) { |
|
425 |
auxLegend.addSymbol(clave, theSymbol); |
|
460 | 426 |
} else { |
461 |
if (auxLegend != null) { |
|
462 |
ISymbol legendSymbol = auxLegend.getSymbolByValue(clave); |
|
463 |
if (legendSymbol != null) { |
|
464 |
auxLegend.replace(legendSymbol, null); |
|
465 |
} |
|
466 |
} |
|
427 |
if (legendSymbol != theSymbol) { |
|
428 |
auxLegend.replace(legendSymbol, theSymbol); |
|
429 |
} |
|
467 | 430 |
} |
431 |
} |
|
432 |
} else { |
|
433 |
if (auxLegend != null) { |
|
434 |
ISymbol legendSymbol = auxLegend.getSymbolByValue(clave); |
|
435 |
if (legendSymbol != null) { |
|
436 |
auxLegend.replace(legendSymbol, null); |
|
437 |
} |
|
438 |
} |
|
468 | 439 |
} |
440 |
} |
|
469 | 441 |
|
470 |
/** |
|
471 |
* DOCUMENT ME! |
|
472 |
*/ |
|
473 |
private void fillFieldNames() { |
|
474 |
FeatureStore rs; |
|
442 |
private void fillFieldNames() { |
|
443 |
FeatureStore rs; |
|
475 | 444 |
|
476 |
try { |
|
477 |
rs = ((FLyrVect) layer).getFeatureStore(); |
|
478 |
// logger.debug("rs.start()"); |
|
479 |
// rs.start(); |
|
445 |
try { |
|
446 |
rs = ((FLyrVect) layer).getFeatureStore(); |
|
447 |
ArrayList names = new ArrayList(); |
|
448 |
for (FeatureAttributeDescriptor descriptor : rs.getDefaultFeatureType()) { |
|
449 |
Class fieldClass = descriptor.getDataType().getDefaultClass(); |
|
450 |
if (Comparable.class.isAssignableFrom(fieldClass)) { |
|
451 |
names.add(descriptor.getName()); |
|
452 |
} |
|
453 |
} |
|
454 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0])); |
|
455 |
cmbFields.setModel(cM); |
|
480 | 456 |
|
481 |
ArrayList names = new ArrayList(); |
|
482 |
Iterator iterator = rs.getDefaultFeatureType().iterator(); |
|
483 |
while (iterator.hasNext()) { |
|
484 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next(); |
|
485 |
Class fieldClass = ToolsLocator.getDataTypesManager().getDefaultClass(descriptor.getDataType().getType()); |
|
486 |
if (Comparable.class.isAssignableFrom(fieldClass)) { |
|
487 |
names.add(descriptor.getName()); |
|
488 |
} |
|
489 |
} |
|
490 |
// String[] nomFields = new String[rs.getFieldCount()]; |
|
491 |
// |
|
492 |
// for (int i = 0; i < rs.getFieldCount(); i++) { |
|
493 |
// nomFields[i] = rs.getFieldName(i).trim(); |
|
494 |
// } |
|
495 |
// |
|
496 |
// rs.stop(); |
|
457 |
} catch (DataException e) { |
|
458 |
LOGGER.warn("recovering_recordset", e); |
|
459 |
} |
|
460 |
} |
|
497 | 461 |
|
498 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0])); |
|
499 |
cmbFields.setModel(cM); |
|
500 |
|
|
501 |
// fieldsListValor.setSelectedIndex(0); |
|
502 |
} catch (DataException e) { |
|
503 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
|
504 |
} |
|
462 |
@Override |
|
463 |
public void setData(FLayer layer, ILegend legend) { |
|
464 |
this.layer = (ClassifiableVectorial) layer; |
|
465 |
int shapeType = 0; |
|
466 |
try { |
|
467 |
shapeType = this.layer.getShapeType(); |
|
468 |
} catch (ReadException e) { |
|
469 |
LOGGER.warn("generating_intervals", e); |
|
505 | 470 |
} |
506 | 471 |
|
507 |
@Override |
|
508 |
public void setData(FLayer layer, ILegend legend) { |
|
509 |
this.layer = (ClassifiableVectorial) layer; |
|
510 |
int shapeType = 0; |
|
511 |
try { |
|
512 |
shapeType = this.layer.getShapeType(); |
|
513 |
} catch (ReadException e) { |
|
514 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
|
515 |
} |
|
472 |
getDefaultSymbolPrev(shapeType); |
|
516 | 473 |
|
517 |
getDefaultSymbolPrev(shapeType); |
|
474 |
if (symbolTable != null) { |
|
475 |
pnlCenter.remove(symbolTable); |
|
476 |
} |
|
477 |
symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType); |
|
478 |
pnlCenter.add(symbolTable, BorderLayout.CENTER); |
|
518 | 479 |
|
519 |
if (symbolTable != null) { |
|
520 |
pnlCenter.remove(symbolTable); |
|
521 |
} |
|
522 |
symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType); |
|
523 |
pnlCenter.add(symbolTable, BorderLayout.CENTER); |
|
480 |
fillFieldNames(); |
|
524 | 481 |
|
525 |
fillFieldNames();
|
|
482 |
symbolTable.removeAllItems();
|
|
526 | 483 |
|
527 |
symbolTable.removeAllItems(); |
|
484 |
if (VectorialUniqueValueLegend.class.equals(legend.getClass())) { |
|
485 |
auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
|
486 |
getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol()); |
|
487 |
cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]); |
|
488 |
setColorScheme(); |
|
528 | 489 |
|
529 |
if (VectorialUniqueValueLegend.class.equals(legend.getClass())) { |
|
530 |
auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
|
531 |
getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol()); |
|
532 |
cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]); |
|
533 |
setColorScheme(); |
|
490 |
Object[] values = auxLegend.getValues(); |
|
491 |
String[] descriptions = new String[values.length]; |
|
492 |
ISymbol[] symbols = new ISymbol[values.length]; |
|
534 | 493 |
|
535 |
Object[] values = auxLegend.getValues(); |
|
536 |
String[] descriptions = new String[values.length]; |
|
537 |
ISymbol[] symbols = new ISymbol[values.length]; |
|
494 |
for (int i = 0; i < values.length; i++) { |
|
495 |
Object value = values[i]; |
|
496 |
symbols[i] = auxLegend.getSymbolByValue(value); |
|
497 |
descriptions[i] = symbols[i].getDescription(); |
|
498 |
} |
|
538 | 499 |
|
539 |
for (int i = 0; i < values.length; i++) { |
|
540 |
Object value = values[i]; |
|
541 |
symbols[i] = auxLegend.getSymbolByValue(value); |
|
542 |
descriptions[i] = symbols[i].getDescription(); |
|
543 |
} |
|
544 |
|
|
545 |
symbolTable.fillTableFromSymbolList(symbols, |
|
546 |
values, descriptions); |
|
547 |
chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol()); |
|
548 |
} else { |
|
549 |
auxLegend = new VectorialUniqueValueLegend(shapeType); |
|
550 |
} |
|
551 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
|
552 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
|
500 |
symbolTable.fillTableFromSymbolList(symbols, values, descriptions); |
|
501 |
chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol()); |
|
502 |
} else { |
|
503 |
auxLegend = new VectorialUniqueValueLegend(shapeType); |
|
553 | 504 |
} |
505 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
|
506 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
|
507 |
} |
|
554 | 508 |
|
555 |
private void setColorScheme() {
|
|
509 |
private void setColorScheme() { |
|
556 | 510 |
|
557 |
if (auxLegend.getColorScheme() != null) { |
|
558 |
Color[] colorScheme = auxLegend.getColorScheme(); |
|
559 |
// ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length]; |
|
560 |
// for (int i = 0; i < auxLegend.getColorScheme().length; i++) { |
|
561 |
// colors[i] = new ColorItem(); |
|
562 |
// colors[i].setColor(auxLegend.getColorScheme()[i]); |
|
563 |
// } |
|
564 |
cmbColorScheme.setSelectedColors(colorScheme); |
|
565 |
} |
|
511 |
if (auxLegend.getColorScheme() != null) { |
|
512 |
Color[] colorScheme = auxLegend.getColorScheme(); |
|
513 |
cmbColorScheme.setSelectedColors(colorScheme); |
|
566 | 514 |
} |
515 |
} |
|
567 | 516 |
|
568 |
private void getDefaultSymbolPrev(int shapeType) { |
|
569 |
if (defaultSymbolPrev == null) { |
|
570 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType); |
|
571 |
defaultSymbolPrev.setPreferredSize(new Dimension(110, 20)); |
|
572 |
defaultSymbolPrev.addActionListener(this); |
|
573 |
defaultSymbolPanel.add(defaultSymbolPrev, null); |
|
574 |
} |
|
517 |
private void getDefaultSymbolPrev(int shapeType) { |
|
518 |
if (defaultSymbolPrev == null) { |
|
519 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType); |
|
520 |
defaultSymbolPrev.setPreferredSize(new Dimension(110, 20)); |
|
521 |
defaultSymbolPrev.addActionListener(this); |
|
522 |
defaultSymbolPanel.add(defaultSymbolPrev, null); |
|
575 | 523 |
} |
524 |
} |
|
576 | 525 |
|
577 |
/* (non-Javadoc) |
|
578 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend() |
|
579 |
*/ |
|
580 |
@Override |
|
581 |
public ILegend getLegend() { |
|
582 |
fillSymbolListFromTable(); |
|
526 |
@Override |
|
527 |
public ILegend getLegend() { |
|
528 |
fillSymbolListFromTable(); |
|
583 | 529 |
|
584 |
if (auxLegend != null) { |
|
585 |
// your settings that are not the set of symbols must be located here |
|
586 |
// auxLegend.setClassifyingFieldNames( |
|
587 |
// new String[] {(String) cmbFields.getSelectedItem()}); |
|
588 |
|
|
589 |
ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol(); |
|
590 |
ISymbol symbol = defaultSymbolPrev.getSymbol(); |
|
591 |
if (symbol != null) { |
|
592 |
if (symbol != defaultSymbolLegend) { |
|
593 |
auxLegend.setDefaultSymbol(symbol); |
|
594 |
} |
|
595 |
} |
|
596 |
|
|
597 |
auxLegend.useDefaultSymbol(chbUseDefault.isSelected()); |
|
598 |
|
|
599 |
theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend(); |
|
600 |
theLegend.setZSort(auxLegend.getZSort()); |
|
530 |
if (auxLegend != null) { |
|
531 |
ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol(); |
|
532 |
ISymbol symbol = defaultSymbolPrev.getSymbol(); |
|
533 |
if (symbol != null) { |
|
534 |
if (symbol != defaultSymbolLegend) { |
|
535 |
auxLegend.setDefaultSymbol(symbol); |
|
601 | 536 |
} |
537 |
} |
|
538 |
auxLegend.useDefaultSymbol(chbUseDefault.isSelected()); |
|
602 | 539 |
|
603 |
return theLegend; |
|
540 |
theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend(); |
|
541 |
theLegend.setZSort(auxLegend.getZSort()); |
|
604 | 542 |
} |
543 |
return theLegend; |
|
544 |
} |
|
605 | 545 |
|
606 |
private JCheckBox getChbUseDefault() { |
|
607 |
if (chbUseDefault == null) { |
|
608 |
chbUseDefault = new JCheckBox(); |
|
609 |
chbUseDefault.setSelected(false); |
|
610 |
chbUseDefault.addActionListener(new java.awt.event.ActionListener() { |
|
611 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
612 |
if (chbUseDefault.isSelected()) { |
|
613 |
auxLegend.useDefaultSymbol(true); |
|
614 |
} else { |
|
615 |
auxLegend.useDefaultSymbol(false); |
|
616 |
} |
|
617 |
} |
|
618 |
}); |
|
619 |
chbUseDefault.setText(PluginServices.getText(this, "resto_valores") + ": "); |
|
546 |
private JCheckBox getChbUseDefault() { |
|
547 |
if (chbUseDefault == null) { |
|
548 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
549 |
chbUseDefault = new JCheckBox(); |
|
550 |
chbUseDefault.setSelected(false); |
|
551 |
chbUseDefault.addActionListener((java.awt.event.ActionEvent e) -> { |
|
552 |
if (chbUseDefault.isSelected()) { |
|
553 |
auxLegend.useDefaultSymbol(true); |
|
554 |
} else { |
|
555 |
auxLegend.useDefaultSymbol(false); |
|
620 | 556 |
} |
621 |
|
|
622 |
return chbUseDefault;
|
|
557 |
}); |
|
558 |
chbUseDefault.setText(i18n.getTranslation("resto_valores") + ": ");
|
|
623 | 559 |
} |
624 | 560 |
|
625 |
/** |
|
626 |
* A�ade el resto de valores. |
|
627 |
*/ |
|
628 |
private void addDefault() { |
|
629 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
630 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol()); |
|
631 |
symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
|
632 |
null, auxLegend.getDefaultSymbol().getDescription()); |
|
633 |
symbolTable.repaint(); |
|
634 |
} |
|
561 |
return chbUseDefault; |
|
562 |
} |
|
635 | 563 |
|
636 |
/** |
|
637 |
* Elimina el resto de valores que no estan representados por ning�n otro |
|
638 |
* s�mbolo.. |
|
639 |
*/ |
|
640 |
private void delDefault() { |
|
641 |
auxLegend.delSymbol(null); |
|
642 |
symbolTable.removeRow(null); |
|
643 |
symbolTable.repaint(); |
|
644 |
} |
|
645 |
|
|
646 |
@Override |
|
647 |
public void actionPerformed(ActionEvent e) { |
|
564 |
private void addDefault() { |
|
565 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
566 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol()); |
|
567 |
symbolTable.addTableRecord( |
|
568 |
auxLegend.getDefaultSymbol(), |
|
569 |
null, |
|
570 |
auxLegend.getDefaultSymbol().getDescription() |
|
571 |
); |
|
572 |
symbolTable.repaint(); |
|
573 |
} |
|
648 | 574 |
|
649 |
//modificar el combobox de valor |
|
650 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
|
651 |
JComboBox cb = (JComboBox) e.getSource(); |
|
652 |
String fieldName = (String) cb.getSelectedItem(); |
|
653 |
symbolTable.removeAllItems(); |
|
654 |
btnOpenSymbolLevelsEditor.setEnabled(false); |
|
575 |
private void delDefault() { |
|
576 |
auxLegend.delSymbol(null); |
|
577 |
symbolTable.removeRow(null); |
|
578 |
symbolTable.repaint(); |
|
579 |
} |
|
655 | 580 |
|
656 |
// if (theLegend.getClassifyingFieldNames()!=null && fieldName != theLegend.getClassifyingFieldNames()[0]) { |
|
657 |
// //m_bCacheDirty = true; |
|
658 |
// theLegend.setClassifyingFieldNames(new String[] {fieldName}); |
|
659 |
// } |
|
660 |
// |
|
661 |
// //////////////////////////////////////////PEPE |
|
662 |
// FLyrVect m = (FLyrVect) layer; |
|
663 |
// try { |
|
664 |
// int fieldType = m.getSource().getRecordset().getFieldType((int)cb.getSelectedIndex()); |
|
665 |
// if (theLegend.getClassifyingFieldTypes()!=null && fieldType != theLegend.getClassifyingFieldTypes()[0]) { |
|
666 |
// //m_bCacheDirty = true; |
|
667 |
// theLegend.setClassifyingFieldTypes(new int[] {fieldType}); |
|
668 |
// } |
|
669 |
// } catch (ReadDriverException e1) { |
|
670 |
// NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e1); |
|
671 |
// } |
|
672 |
// /////////////////////////////////////////PEPE |
|
673 |
} |
|
581 |
@Override |
|
582 |
public void actionPerformed(ActionEvent e) { |
|
674 | 583 |
|
675 |
// add all elements by value |
|
676 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
|
677 |
fillTableValues(); |
|
678 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
|
679 |
} |
|
584 |
//modificar el combobox de valor |
|
585 |
if ("FIELD_SELECTED".equals(e.getActionCommand())) { |
|
586 |
JComboBox cb = (JComboBox) e.getSource(); |
|
587 |
String fieldName = (String) cb.getSelectedItem(); |
|
588 |
symbolTable.removeAllItems(); |
|
589 |
btnOpenSymbolLevelsEditor.setEnabled(false); |
|
590 |
} |
|
680 | 591 |
|
681 |
// add only one value |
|
682 |
if (e.getActionCommand() == "ADD_VALUE") { |
|
683 |
try { |
|
684 |
ISymbol symbol |
|
685 |
= mapContextManager.getSymbolManager().createSymbol( |
|
686 |
layer.getShapeType()); |
|
687 |
Double clave = new Double(0.0); |
|
688 |
symbolTable.addTableRecord(symbol, |
|
689 |
clave, "0 - 0"); |
|
690 |
btnOpenSymbolLevelsEditor.setEnabled(true); |
|
691 |
} catch (ReadException ex) { |
|
692 |
NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex); |
|
693 |
} |
|
694 |
} |
|
592 |
// add all elements by value |
|
593 |
if ("ADD_ALL_VALUES".equals(e.getActionCommand())) { |
|
594 |
fillTableValues(); |
|
595 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
|
596 |
} |
|
695 | 597 |
|
696 |
//Vacia la tabla |
|
697 |
if (e.getActionCommand() == "REMOVE_ALL") { |
|
698 |
symbolTable.removeAllItems(); |
|
699 |
auxLegend.setZSort(null); |
|
700 |
btnOpenSymbolLevelsEditor.setEnabled(false); |
|
598 |
// add only one value |
|
599 |
if ("ADD_VALUE".equals(e.getActionCommand())) { |
|
600 |
try { |
|
601 |
ISymbol symbol = mapContextManager.getSymbolManager().createSymbol( |
|
602 |
layer.getShapeType() |
|
603 |
); |
|
604 |
Double clave = 0.0; |
|
605 |
symbolTable.addTableRecord( |
|
606 |
symbol, clave, "0 - 0" |
|
607 |
); |
|
608 |
btnOpenSymbolLevelsEditor.setEnabled(true); |
|
609 |
} catch (ReadException ex) { |
|
610 |
LOGGER.warn("getting_shape_type", ex); |
|
611 |
} |
|
612 |
} |
|
701 | 613 |
|
702 |
} |
|
614 |
//Vacia la tabla |
|
615 |
if ("REMOVE_ALL".equals(e.getActionCommand())) { |
|
616 |
symbolTable.removeAllItems(); |
|
617 |
auxLegend.setZSort(null); |
|
618 |
btnOpenSymbolLevelsEditor.setEnabled(false); |
|
703 | 619 |
|
704 |
//Quitar solo el elemento seleccionado |
|
705 |
if (e.getActionCommand() == "REMOVE") { |
|
706 |
symbolTable.removeSelectedRows(); |
|
707 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount() > 0); |
|
708 |
} |
|
709 |
|
|
710 |
if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") { |
|
711 |
ZSort myZSort = null; |
|
712 |
if (auxLegend != null) { |
|
713 |
myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort(); |
|
714 |
if (myZSort == null) { |
|
715 |
myZSort = new ZSort(auxLegend); |
|
716 |
} |
|
717 |
} |
|
718 |
if (myZSort == null && theLegend != null) { |
|
719 |
myZSort = new ZSort(theLegend); |
|
720 |
} |
|
721 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort); |
|
722 |
PluginServices.getMDIManager().addWindow(sl); |
|
723 |
auxLegend.setZSort(sl.getZSort()); |
|
724 |
} |
|
725 | 620 |
} |
726 | 621 |
|
727 |
@Override |
|
728 |
public String getDescription() { |
|
729 |
return PluginServices.getText(this, "Dado_un_campo_de_atributos") + "," + PluginServices.getText(this, "muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + "."; |
|
622 |
//Quitar solo el elemento seleccionado |
|
623 |
if ("REMOVE".equals(e.getActionCommand())) { |
|
624 |
symbolTable.removeSelectedRows(); |
|
625 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount() > 0); |
|
730 | 626 |
} |
731 | 627 |
|
732 |
@Override |
|
733 |
public ImageIcon getIcon() { |
|
734 |
return IconThemeHelper.getImageIcon( |
|
735 |
"legend-overview-vectorial-unique-value"); |
|
628 |
if ("OPEN_SYMBOL_LEVEL_EDITOR".equals(e.getActionCommand())) { |
|
629 |
ZSort myZSort = null; |
|
630 |
if (auxLegend != null) { |
|
631 |
myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort(); |
|
632 |
if (myZSort == null) { |
|
633 |
myZSort = new ZSort(auxLegend); |
|
634 |
} |
|
635 |
} |
|
636 |
if (myZSort == null && theLegend != null) { |
|
637 |
myZSort = new ZSort(theLegend); |
|
638 |
} |
|
639 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort); |
|
640 |
PluginServices.getMDIManager().addWindow(sl); |
|
641 |
auxLegend.setZSort(sl.getZSort()); |
|
736 | 642 |
} |
643 |
} |
|
737 | 644 |
|
738 |
@Override |
|
739 |
public Class getParentClass() { |
|
740 |
return Categories.class; |
|
741 |
} |
|
645 |
@Override |
|
646 |
public String getDescription() { |
|
647 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
648 |
return i18n.getTranslation("Dado_un_campo_de_atributos") + "," |
|
649 |
+ i18n.getTranslation("muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + "."; |
|
650 |
} |
|
742 | 651 |
|
743 |
@Override |
|
744 |
public String getTitle() { |
|
745 |
return PluginServices.getText(this, "Valores_unicos"); |
|
746 |
} |
|
652 |
@Override |
|
653 |
public ImageIcon getIcon() { |
|
654 |
return IconThemeHelper.getImageIcon( |
|
655 |
"legend-overview-vectorial-unique-value"); |
|
656 |
} |
|
747 | 657 |
|
748 |
@Override
|
|
749 |
public JPanel getPanel() {
|
|
750 |
return this;
|
|
751 |
}
|
|
658 |
@Override |
|
659 |
public Class getParentClass() {
|
|
660 |
return Categories.class;
|
|
661 |
} |
|
752 | 662 |
|
753 |
@Override |
|
754 |
public Class getLegendClass() { |
|
755 |
return VectorialUniqueValueLegend.class; |
|
756 |
} |
|
663 |
@Override |
|
664 |
public String getTitle() { |
|
665 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
666 |
return i18n.getTranslation("Valores_unicos"); |
|
667 |
} |
|
757 | 668 |
|
758 |
@Override |
|
759 |
public boolean isSuitableFor(FLayer layer) { |
|
760 |
return (layer instanceof FLyrVect); |
|
761 |
} |
|
669 |
@Override |
|
670 |
public JPanel getPanel() { |
|
671 |
return this; |
|
672 |
} |
|
673 |
|
|
674 |
@Override |
|
675 |
public Class getLegendClass() { |
|
676 |
return VectorialUniqueValueLegend.class; |
|
677 |
} |
|
678 |
|
|
679 |
@Override |
|
680 |
public boolean isSuitableFor(FLayer layer) { |
|
681 |
return (layer instanceof FLyrVect); |
|
682 |
} |
|
762 | 683 |
} |
Also available in: Unified diff