svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolLevelsWindow.java @ 34291
History | View | Annotate | Download (20.5 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.app.gui.styling; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Component; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Font; |
48 |
import java.awt.Graphics; |
49 |
import java.awt.Graphics2D; |
50 |
import java.awt.Point; |
51 |
import java.awt.Rectangle; |
52 |
import java.awt.event.ActionEvent; |
53 |
import java.awt.event.ActionListener; |
54 |
import java.awt.event.MouseEvent; |
55 |
import java.awt.event.MouseListener; |
56 |
import java.awt.geom.GeneralPath; |
57 |
import java.util.Hashtable; |
58 |
import java.util.Iterator; |
59 |
|
60 |
import javax.swing.BorderFactory; |
61 |
import javax.swing.BoxLayout; |
62 |
import javax.swing.Icon; |
63 |
import javax.swing.JButton; |
64 |
import javax.swing.JCheckBox; |
65 |
import javax.swing.JComponent; |
66 |
import javax.swing.JPanel; |
67 |
import javax.swing.JScrollPane; |
68 |
import javax.swing.JTable; |
69 |
import javax.swing.border.EtchedBorder; |
70 |
import javax.swing.event.ChangeEvent; |
71 |
import javax.swing.table.DefaultTableModel; |
72 |
import javax.swing.table.TableCellEditor; |
73 |
import javax.swing.table.TableColumn; |
74 |
import javax.swing.table.TableModel; |
75 |
|
76 |
import org.gvsig.andami.PluginServices; |
77 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
78 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
79 |
import org.gvsig.app.project.documents.gui.TableSymbolCellRenderer; |
80 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
81 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
82 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
83 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
84 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
85 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
86 |
import org.gvsig.gui.beans.swing.JBlank; |
87 |
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor; |
88 |
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor; |
89 |
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer; |
90 |
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer; |
91 |
import org.gvsig.i18n.Messages; |
92 |
|
93 |
|
94 |
/**
|
95 |
* Creates a panel to specify an order for the symbols of a map. This order
|
96 |
* is important when the map is going to be painted because, apart from that
|
97 |
* the waste of time can be less, the final representation of the map will
|
98 |
* depend on this order.
|
99 |
*
|
100 |
*
|
101 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
102 |
*/
|
103 |
public class SymbolLevelsWindow extends JPanel implements IWindow, ActionListener { |
104 |
private static final long serialVersionUID = 3241898997869313055L; |
105 |
private static final int DESCRIPTION_COLUMN_INDEX = 1; |
106 |
private static final int SYMBOL_COLUMN_INDEX = 0; |
107 |
private static final int MERGE_COLUMN_INDEX = 3; |
108 |
private static final int JOIN_COLUMN_INDEX = 2; |
109 |
private static final int FIRST_LEVEL_COLUMN_INDEX = 2; |
110 |
private static final String[] defaultHeaders = new String[] { |
111 |
Messages.getText("symbol"),
|
112 |
Messages.getText("description"),
|
113 |
Messages.getText("join"),
|
114 |
Messages.getText("merge"),
|
115 |
}; |
116 |
private static final int DEFAULT_VIEW = 0; |
117 |
private static final int ADVANCED_VIEW = 1; |
118 |
private static int viewMode = ADVANCED_VIEW; |
119 |
private JCheckBox chkSpecifyDrawOrder = null; |
120 |
private JPanel pnlCenter = null; |
121 |
private JScrollPane srclLevels = null; |
122 |
private JTable tblLevels = null; |
123 |
private JButton btnUp = null; |
124 |
private JButton btnDown; |
125 |
private JPanel pnlSouth = null; |
126 |
private String[] advancedHeaders; |
127 |
private JButton btnSwitchView; |
128 |
private ZSort zSort;
|
129 |
private SymbolSummary summary = new SymbolSummary(); |
130 |
|
131 |
private ActionListener action = new ActionListener() { |
132 |
public void actionPerformed(ActionEvent e) { |
133 |
String actionCommand = e.getActionCommand();
|
134 |
if ("OK".equals(actionCommand)) { |
135 |
tblLevels.editingStopped(new ChangeEvent(tblLevels)); |
136 |
applyValues(); |
137 |
} |
138 |
|
139 |
PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this); |
140 |
|
141 |
} |
142 |
}; |
143 |
|
144 |
public WindowInfo getWindowInfo() {
|
145 |
WindowInfo wi = new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MODALDIALOG);
|
146 |
wi.setTitle(Messages.getText("symbol_levels"));
|
147 |
wi.setWidth(getWidth()+10);
|
148 |
wi.setHeight(getHeight()); |
149 |
return wi;
|
150 |
} |
151 |
/**
|
152 |
* Completes the main table of the panel with the symbols contained in the
|
153 |
* legend of the map.
|
154 |
*
|
155 |
*/
|
156 |
private void applyValues() { |
157 |
|
158 |
// update symbol order
|
159 |
TableModel model = tblLevels.getModel();
|
160 |
|
161 |
|
162 |
|
163 |
Hashtable<ISymbol, int[] > aTable = new Hashtable<ISymbol, int[]>(); |
164 |
ISymbol[] symbols = new ISymbol[model.getRowCount()]; |
165 |
for (int i = 0; i < symbols.length; i++) { |
166 |
symbols[i] = (ISymbol) model.getValueAt(i, SYMBOL_COLUMN_INDEX); |
167 |
int length = 1; |
168 |
if (symbols[i] instanceof IMultiLayerSymbol) { |
169 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) symbols[i]; |
170 |
length = mlSym.getLayerCount(); |
171 |
} |
172 |
|
173 |
int[] symbolLevels = new int[length]; |
174 |
if (viewMode == DEFAULT_VIEW) {
|
175 |
// default view (JOIN and MERGE)
|
176 |
if (symbols[i] instanceof IMultiLayerSymbol) { |
177 |
boolean join = ((Boolean) model.getValueAt(i, JOIN_COLUMN_INDEX)).booleanValue(); |
178 |
boolean merge= ((Boolean) model.getValueAt(i, MERGE_COLUMN_INDEX)).booleanValue(); |
179 |
boolean needToJoin = true; |
180 |
if (merge && i>0) { |
181 |
int j=0; |
182 |
try {
|
183 |
int[] prevSymbolLevels = aTable.get(symbols[i-1]); |
184 |
for (j = 0; j < symbolLevels.length; j++) { |
185 |
symbolLevels[j] = prevSymbolLevels[j]; |
186 |
} |
187 |
} catch (IndexOutOfBoundsException ex) { |
188 |
/* perfect, no problem
|
189 |
* the previous symbol has different amount of layers
|
190 |
* that is ok because we just have to replicate
|
191 |
* the values of each cell
|
192 |
*/
|
193 |
for (; j < symbolLevels.length; j++) {
|
194 |
symbolLevels[j] = symbolLevels[j-1]+1; |
195 |
} |
196 |
} |
197 |
needToJoin = false;
|
198 |
} |
199 |
if (join && needToJoin) {
|
200 |
for (int j = 0; j < symbolLevels.length; j++) { |
201 |
symbolLevels[j] = zSort.getLevelCount()+j+1;
|
202 |
} |
203 |
} |
204 |
if (!join && !merge) {
|
205 |
for (int j = 0; j < symbolLevels.length; j++) { |
206 |
symbolLevels[j] = zSort.getLevelCount(); |
207 |
} |
208 |
} |
209 |
} else {
|
210 |
symbolLevels[0] = zSort.getLevelCount();
|
211 |
} |
212 |
} else {
|
213 |
// ADVANCED VIEW (user may set map levels manually)
|
214 |
for (int j = 0; j < symbolLevels.length; j++) { |
215 |
symbolLevels[j] = ((Integer) model.getValueAt(i, j+FIRST_LEVEL_COLUMN_INDEX)).intValue();
|
216 |
} |
217 |
} |
218 |
|
219 |
aTable.put(symbols[i], symbolLevels); |
220 |
} |
221 |
|
222 |
Iterator<ISymbol> it = aTable.keySet().iterator();
|
223 |
while (it.hasNext()) {
|
224 |
ISymbol sym = it.next(); |
225 |
zSort.setLevels(sym, aTable.get(sym)); |
226 |
} |
227 |
|
228 |
zSort.setUsingZSort(getChkSpecifyDrawOrder().isSelected()); |
229 |
} |
230 |
|
231 |
public SymbolLevelsWindow(ZSort zSort) {
|
232 |
super();
|
233 |
initialize(); |
234 |
setModel(zSort); |
235 |
quitaEsteMetodo(); |
236 |
tblLevels.setRowHeight(23);
|
237 |
} |
238 |
private void quitaEsteMetodo() { |
239 |
getBtnSwitchView().setEnabled(false);
|
240 |
getBtnDown().setEnabled(false);
|
241 |
getBtnUp().setEnabled(false);
|
242 |
} |
243 |
/**
|
244 |
* Sets the model
|
245 |
* @param plan ZSort
|
246 |
*/
|
247 |
|
248 |
public void setModel(ZSort plan) { |
249 |
advancedHeaders = new String[FIRST_LEVEL_COLUMN_INDEX |
250 |
+plan.getTopLevelIndexAllowed() ]; |
251 |
advancedHeaders[SYMBOL_COLUMN_INDEX] = defaultHeaders[SYMBOL_COLUMN_INDEX]; |
252 |
advancedHeaders[DESCRIPTION_COLUMN_INDEX] = defaultHeaders[DESCRIPTION_COLUMN_INDEX]; |
253 |
for (int i = 2; i < advancedHeaders.length; i++) { |
254 |
advancedHeaders[i] = String.valueOf(i-1); |
255 |
} |
256 |
this.zSort = plan;
|
257 |
getChkSpecifyDrawOrder().setSelected(plan.isUsingZSort()); |
258 |
initTableContents(getTblLevels(), plan, viewMode); |
259 |
} |
260 |
/**
|
261 |
* Initializes the table that it is showed in the panel where the user can
|
262 |
* see the different symbols of the legend and has options to specify the
|
263 |
* level for each one, merge and so on.
|
264 |
*
|
265 |
* @param table
|
266 |
* @param zSort
|
267 |
* @param mode
|
268 |
*/
|
269 |
private void initTableContents(JTable table, ZSort zSort, int mode) { |
270 |
DefaultTableModel model = new DefaultTableModel(); |
271 |
Object[][] dataVector = null; |
272 |
ISymbol[] syms = zSort.getSymbols();
|
273 |
String[] labels = zSort.getDescriptions(); |
274 |
|
275 |
if (mode == DEFAULT_VIEW) {
|
276 |
// default view (JOIN and MERGE)
|
277 |
dataVector = new Object[syms.length][syms.length]; |
278 |
for (int i = 0; i < syms.length; i++) { |
279 |
dataVector[i] = new Object[defaultHeaders.length]; |
280 |
dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i]; |
281 |
dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i]; |
282 |
if (syms[i] instanceof IMultiLayerSymbol) { |
283 |
boolean joined = true; |
284 |
int[] levels = zSort.getLevels(syms[i]); |
285 |
if(levels != null){ |
286 |
for (int j = 0; j < levels.length; j++) { |
287 |
if (joined) {
|
288 |
joined = levels[j] != levels[j+1];
|
289 |
} |
290 |
} |
291 |
} |
292 |
|
293 |
|
294 |
boolean merged = true; |
295 |
if (i<syms.length-1) { |
296 |
for (int j = 0; joined && j < levels.length; j++) { |
297 |
// must be joined to be merged
|
298 |
ISymbol nextSymbol = syms[i+1];
|
299 |
int[] nextLevels = zSort.getLevels(nextSymbol); |
300 |
if(nextLevels != null){ |
301 |
if (nextSymbol instanceof IMultiLayerSymbol) { |
302 |
if (j<nextLevels.length) {
|
303 |
merged = levels[j] == nextLevels[j]; |
304 |
} |
305 |
} else {
|
306 |
merged = levels[0] == nextLevels[0]; |
307 |
} |
308 |
} |
309 |
} |
310 |
if (!merged) {
|
311 |
break;
|
312 |
} |
313 |
} |
314 |
if (!joined) {
|
315 |
merged = false;
|
316 |
} |
317 |
dataVector[i][JOIN_COLUMN_INDEX] = new Boolean(joined); |
318 |
dataVector[i][MERGE_COLUMN_INDEX] = new Boolean(merged); |
319 |
} |
320 |
} |
321 |
|
322 |
model.setDataVector(dataVector, defaultHeaders); |
323 |
table.setModel(model); |
324 |
TableColumn col = table.getColumnModel().getColumn(JOIN_COLUMN_INDEX);
|
325 |
col.setCellRenderer(new BooleanTableCellRenderer(true)); |
326 |
col.setCellEditor(new BooleanTableCellEditor(table));
|
327 |
col = table.getColumnModel().getColumn(MERGE_COLUMN_INDEX); |
328 |
col.setCellRenderer(new BooleanTableCellRenderer(true)); |
329 |
col.setCellEditor(new BooleanTableCellEditor(table));
|
330 |
} else {
|
331 |
// advanced view (user may input the map level manually)
|
332 |
dataVector = new Object[syms.length][ |
333 |
FIRST_LEVEL_COLUMN_INDEX + /* this is the first column that
|
334 |
* contains a level for the symbol
|
335 |
*/
|
336 |
|
337 |
zSort.getTopLevelIndexAllowed() + /* according to the set of
|
338 |
* symbols this will get the
|
339 |
* max level reachable
|
340 |
*/
|
341 |
1 /* plus 1 to get a count instead of an index */]; |
342 |
for (int i = 0; i < syms.length; i++) { |
343 |
dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i]; |
344 |
dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i]; |
345 |
if (syms[i] instanceof IMultiLayerSymbol) { |
346 |
int[] levels = zSort.getLevels(syms[i]); |
347 |
|
348 |
for (int j = 0; j < levels.length; j++) { |
349 |
dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = levels[j]; |
350 |
} |
351 |
} else {
|
352 |
dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getLevels(syms[i])[0]); |
353 |
} |
354 |
} |
355 |
|
356 |
model.setDataVector(dataVector, advancedHeaders); |
357 |
table.setModel(model); |
358 |
for (int j = FIRST_LEVEL_COLUMN_INDEX; j < model.getColumnCount(); j++) { |
359 |
|
360 |
table.getColumnModel().getColumn(j).setCellRenderer(new NumberTableCellRenderer(true, false)); |
361 |
table.getColumnModel().getColumn(j).setCellEditor(new IntegerTableCellEditor());
|
362 |
} |
363 |
} |
364 |
|
365 |
TableSymbolCellRenderer symbolCellRenderer = new TableSymbolCellRenderer(true) { |
366 |
private static final long serialVersionUID = 5603529641148869112L; |
367 |
|
368 |
{ // Object static initialize block
|
369 |
|
370 |
preview = new SymbolPreviewer() {
|
371 |
private static final long serialVersionUID = 7262380340075167043L; |
372 |
private Icon downIcon = new Icon(){ |
373 |
public int getIconHeight() { return 7; } |
374 |
public int getIconWidth() { return 7; } |
375 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
376 |
Graphics2D g2 = (Graphics2D) g; |
377 |
g2.setColor(Color.GRAY);
|
378 |
g2.translate(x + c.getWidth()-getIconWidth()*2, y + c.getHeight()-getIconHeight()*2); |
379 |
GeneralPath gp = new GeneralPath(); |
380 |
gp.moveTo(0, 0); |
381 |
gp.lineTo(getIconWidth()/2, getIconHeight()-1); |
382 |
gp.lineTo(getIconWidth()-1, 0); |
383 |
g2.fill(gp); |
384 |
g2.translate(-(x + c.getWidth()-getIconWidth()*2), -(y + c.getHeight()-getIconHeight()*2)); |
385 |
} |
386 |
}; |
387 |
@Override
|
388 |
public void paint(Graphics g) { |
389 |
super.paint(g);
|
390 |
if (getSymbol() instanceof IMultiLayerSymbol) { |
391 |
downIcon.paintIcon(this, g, 0, 0); |
392 |
} |
393 |
} |
394 |
}; |
395 |
|
396 |
} // Object static initialize block
|
397 |
}; |
398 |
TableColumn col = table.getColumnModel().getColumn(SYMBOL_COLUMN_INDEX);
|
399 |
col.setCellRenderer(symbolCellRenderer); |
400 |
} |
401 |
|
402 |
private void initialize() { |
403 |
this.setLayout(new BorderLayout(15, 15)); |
404 |
this.setSize(564, 344); |
405 |
|
406 |
this.add(getChkSpecifyDrawOrder(), BorderLayout.NORTH); |
407 |
this.add(new JBlank(20, 20)); |
408 |
this.add(getPnlCenter(), BorderLayout.CENTER); |
409 |
this.add(getPnlSouth(), BorderLayout.SOUTH); |
410 |
tblLevels.addMouseListener(new MouseListener() { |
411 |
public void mouseReleased(MouseEvent e) { } |
412 |
public void mouseClicked(MouseEvent e) { } |
413 |
public void mouseEntered(MouseEvent e) { } |
414 |
public void mouseExited(MouseEvent e) { |
415 |
summary.sym = null;
|
416 |
repaint(); |
417 |
} |
418 |
|
419 |
public void mousePressed(MouseEvent e) { |
420 |
Point where = e.getPoint();
|
421 |
int whereX = where.x;
|
422 |
int whereY = where.y;
|
423 |
Rectangle bounds = tblLevels.getBounds();
|
424 |
/*
|
425 |
* calculate the right border x-position of the symbol
|
426 |
* column
|
427 |
*/
|
428 |
int rightEdge = 0; |
429 |
for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) { |
430 |
rightEdge += tblLevels.getColumnModel().getColumn(i).getWidth(); |
431 |
} |
432 |
if (whereX >= bounds.x &&
|
433 |
whereX <= rightEdge + bounds.x && |
434 |
whereY >= bounds.y && |
435 |
whereY <= bounds.height + bounds.y) { |
436 |
int rowHeight = tblLevels.getRowHeight();
|
437 |
int rowClicked = (whereY - bounds.y) / rowHeight;
|
438 |
ISymbol sym = (ISymbol) tblLevels. |
439 |
getModel(). |
440 |
getValueAt( |
441 |
rowClicked, |
442 |
SYMBOL_COLUMN_INDEX); |
443 |
if (sym instanceof IMultiLayerSymbol) { |
444 |
summary.sym = (IMultiLayerSymbol) sym; |
445 |
summary.rowIndex = rowClicked; |
446 |
} else {
|
447 |
summary.sym = null;
|
448 |
} |
449 |
repaint(); |
450 |
} |
451 |
} |
452 |
|
453 |
}); |
454 |
|
455 |
} |
456 |
|
457 |
private JCheckBox getChkSpecifyDrawOrder() { |
458 |
if (chkSpecifyDrawOrder == null) { |
459 |
chkSpecifyDrawOrder = new JCheckBox("<html><b>"+ |
460 |
Messages.getText("draw_symbols_in_specified_order")
|
461 |
+"</b></html>");
|
462 |
chkSpecifyDrawOrder.addActionListener(this);
|
463 |
} |
464 |
return chkSpecifyDrawOrder;
|
465 |
} |
466 |
|
467 |
|
468 |
private JPanel getPnlCenter() { |
469 |
if (pnlCenter == null) { |
470 |
pnlCenter = new JPanel(); |
471 |
pnlCenter.setLayout(new BorderLayout(0, 15)); |
472 |
pnlCenter.add(getSrclLevels(), BorderLayout.CENTER);
|
473 |
pnlCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); |
474 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 15)); |
475 |
JPanel pnlButtons = new JPanel(); |
476 |
pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS)); |
477 |
pnlButtons.add(new JBlank(1, 70)); |
478 |
pnlButtons.add(getBtnUp()); |
479 |
pnlButtons.add(new JBlank(1, 10)); |
480 |
pnlButtons.add(getBtnDown()); |
481 |
pnlButtons.setVisible(false);
|
482 |
aux.add(pnlButtons); |
483 |
pnlCenter.add(aux, BorderLayout.EAST);
|
484 |
|
485 |
} |
486 |
pnlCenter.setEnabled(getChkSpecifyDrawOrder().isSelected()); |
487 |
return pnlCenter;
|
488 |
} |
489 |
|
490 |
private JScrollPane getSrclLevels() { |
491 |
if (srclLevels == null) { |
492 |
srclLevels = new JScrollPane(); |
493 |
srclLevels.setViewportView(getTblLevels()); |
494 |
} |
495 |
srclLevels.setEnabled(getChkSpecifyDrawOrder().isSelected()); |
496 |
return srclLevels;
|
497 |
} |
498 |
|
499 |
|
500 |
private JTable getTblLevels() { |
501 |
if (tblLevels == null) { |
502 |
tblLevels = new JTable() { |
503 |
private static final long serialVersionUID = -1545710722048183232L; |
504 |
|
505 |
@Override
|
506 |
protected void paintComponent(Graphics g) { |
507 |
super.paintComponent(g);
|
508 |
summary.paint((Graphics2D) g);
|
509 |
} |
510 |
}; |
511 |
summary.rowHeight = tblLevels.getRowHeight(); |
512 |
} |
513 |
tblLevels.setEnabled(getChkSpecifyDrawOrder().isSelected()); |
514 |
return tblLevels;
|
515 |
} |
516 |
|
517 |
|
518 |
private JButton getBtnUp() { |
519 |
if (btnUp == null) { |
520 |
btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono")); |
521 |
btnUp.setActionCommand("MOVE_UP");
|
522 |
} |
523 |
return btnUp;
|
524 |
} |
525 |
|
526 |
private JButton getBtnDown() { |
527 |
if (btnDown == null) { |
528 |
btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono")); |
529 |
btnDown.setActionCommand("MOVE_DOWN");
|
530 |
} |
531 |
return btnDown;
|
532 |
} |
533 |
|
534 |
|
535 |
private JPanel getPnlSouth() { |
536 |
if (pnlSouth == null) { |
537 |
pnlSouth = new JPanel(new BorderLayout()); |
538 |
JPanel aux = new JPanel(); |
539 |
aux.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
540 |
aux.add(getBtnSwitchView()); |
541 |
pnlSouth.add(aux, BorderLayout.NORTH);
|
542 |
|
543 |
aux = new JPanel(); |
544 |
aux.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
545 |
pnlSouth.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH); |
546 |
|
547 |
} |
548 |
return pnlSouth;
|
549 |
} |
550 |
|
551 |
private JButton getBtnSwitchView() { |
552 |
if (btnSwitchView == null) { |
553 |
btnSwitchView = new JButton( |
554 |
(viewMode != DEFAULT_VIEW) ? |
555 |
Messages.getText("default_view"):
|
556 |
Messages.getText("advanced_view")
|
557 |
); |
558 |
btnSwitchView.addActionListener(this);
|
559 |
btnSwitchView.setVisible(false);
|
560 |
} |
561 |
|
562 |
return btnSwitchView;
|
563 |
} |
564 |
|
565 |
public void actionPerformed(ActionEvent e) { |
566 |
JComponent c = (JComponent) e.getSource(); |
567 |
if (c.equals(getChkSpecifyDrawOrder())) {
|
568 |
getPnlCenter().setEnabled(getChkSpecifyDrawOrder().isSelected()); |
569 |
getSrclLevels().setEnabled(getChkSpecifyDrawOrder().isSelected()); |
570 |
TableCellEditor tce = getTblLevels().getCellEditor();
|
571 |
if (tce != null){ |
572 |
tce.stopCellEditing(); |
573 |
} |
574 |
getTblLevels().setEnabled(getChkSpecifyDrawOrder().isSelected()); |
575 |
} else if (c.equals(getBtnSwitchView())) { |
576 |
viewMode = (viewMode == ADVANCED_VIEW) ? DEFAULT_VIEW : ADVANCED_VIEW; |
577 |
initTableContents(getTblLevels(), zSort, viewMode); |
578 |
btnSwitchView.setText((viewMode != DEFAULT_VIEW) ? |
579 |
Messages.getText("default_view"):
|
580 |
Messages.getText("advanced_view"));
|
581 |
} |
582 |
} |
583 |
/**
|
584 |
* Gets the ZSort value
|
585 |
*
|
586 |
* @return zSort ZSort
|
587 |
*/
|
588 |
public ZSort getZSort() {
|
589 |
return zSort;
|
590 |
} |
591 |
|
592 |
private class SymbolSummary { |
593 |
int witdh;
|
594 |
int rowHeight = 10; |
595 |
|
596 |
int rowIndex;
|
597 |
|
598 |
IMultiLayerSymbol sym; |
599 |
|
600 |
void paint(Graphics2D g){ |
601 |
|
602 |
if (sym != null) { |
603 |
int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6)); |
604 |
int whereX = 0; |
605 |
for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) { |
606 |
whereX += tblLevels.getColumnModel().getColumn(i).getWidth(); |
607 |
} |
608 |
whereX -= 40;
|
609 |
int width = 150; |
610 |
int height = Math.max(rowHeight*sym.getLayerCount(), rowHeight); |
611 |
Rectangle bounds = new Rectangle(whereX, whereY, width, height); |
612 |
g.setColor(new Color(255, 255, 220)); |
613 |
g.fill(bounds); |
614 |
|
615 |
g.setColor(new Color(255, 230, 20)); |
616 |
g.draw(bounds); |
617 |
|
618 |
g.setFont(new Font("Arial", Font.BOLD, 10)); |
619 |
|
620 |
for (int i = 0; i < sym.getLayerCount(); i++) { |
621 |
g.setColor(Color.black);
|
622 |
g.drawString(i+1+":", whereX+5, height + whereY - ( (i*rowHeight) + 5 )); |
623 |
Rectangle rect = new Rectangle(whereX + 20, |
624 |
height + whereY - ((i+1)*rowHeight) + 3, |
625 |
width - 20,
|
626 |
rowHeight - 6);
|
627 |
try {
|
628 |
sym.getLayer(i).drawInsideRectangle(g, null, rect,null); |
629 |
} catch (SymbolDrawingException e) {
|
630 |
if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
|
631 |
try {
|
632 |
MapContextLocator.getSymbolManager() |
633 |
.getWarningSymbol( |
634 |
SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
635 |
"",
|
636 |
SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) |
637 |
.drawInsideRectangle(g, null, rect,
|
638 |
null);
|
639 |
} catch (SymbolDrawingException e1) {
|
640 |
// IMPOSSIBLE TO REACH THIS
|
641 |
} |
642 |
} else {
|
643 |
// should be unreachable code
|
644 |
throw new Error(Messages.getText("symbol_shapetype_mismatch")); |
645 |
} |
646 |
} |
647 |
} |
648 |
|
649 |
} |
650 |
}; |
651 |
} |
652 |
|
653 |
public Object getWindowProfile() { |
654 |
return WindowInfo.DIALOG_PROFILE;
|
655 |
} |
656 |
|
657 |
} |