Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolLevelsWindow.java @ 29870

History | View | Annotate | Download (21.3 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 com.iver.cit.gvsig.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.EventObject;
58
import java.util.Hashtable;
59
import java.util.Iterator;
60

    
61
import javax.swing.BorderFactory;
62
import javax.swing.BoxLayout;
63
import javax.swing.Icon;
64
import javax.swing.JButton;
65
import javax.swing.JCheckBox;
66
import javax.swing.JComponent;
67
import javax.swing.JPanel;
68
import javax.swing.JScrollPane;
69
import javax.swing.JTable;
70
import javax.swing.border.EtchedBorder;
71
import javax.swing.event.CellEditorListener;
72
import javax.swing.event.ChangeEvent;
73
import javax.swing.table.DefaultTableModel;
74
import javax.swing.table.TableCellEditor;
75
import javax.swing.table.TableColumn;
76
import javax.swing.table.TableModel;
77

    
78
import org.gvsig.gui.beans.AcceptCancelPanel;
79
import org.gvsig.gui.beans.swing.JBlank;
80
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor;
81
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor;
82
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer;
83
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer;
84

    
85
import com.iver.andami.PluginServices;
86
import com.iver.andami.ui.mdiManager.IWindow;
87
import com.iver.andami.ui.mdiManager.WindowInfo;
88
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
89
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
90
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
91
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
92
import com.iver.cit.gvsig.fmap.rendering.ZSort;
93
import com.iver.cit.gvsig.project.documents.gui.TableSymbolCellRenderer;
94

    
95
/**
96
 * Creates a panel to specify an order for the symbols of a map. This order
97
 * is important when the map is going to be painted because, apart from that
98
 * the waste of time can be less, the final representation of the map will
99
 * depend on this order.
100
 *
101
 *
102
 * @author jaume dominguez faus - jaume.dominguez@iver.es
103
 */
104
public class SymbolLevelsWindow extends JPanel implements IWindow, ActionListener {
105
        private static final long serialVersionUID = 3241898997869313055L;
106
        private static final int DESCRIPTION_COLUMN_INDEX = 1;
107
        private static final int SYMBOL_COLUMN_INDEX = 0;
108
        private static final int MERGE_COLUMN_INDEX = 3;
109
        private static final int JOIN_COLUMN_INDEX = 2;
110
        private static final int FIRST_LEVEL_COLUMN_INDEX = 2;
111
        private static final String[] defaultHeaders = new String[] {
112
                PluginServices.getText(SymbolLevelsWindow.class, "symbol"),
113
                PluginServices.getText(SymbolLevelsWindow.class, "description"),
114
                PluginServices.getText(SymbolLevelsWindow.class, "join"),
115
                PluginServices.getText(SymbolLevelsWindow.class, "merge"),
116
        };
117
        private static final int DEFAULT_VIEW = 0;
118
        private static final int ADVANCED_VIEW = 1;
119
        private static int viewMode = ADVANCED_VIEW;
120
        private JCheckBox chkSpecifyDrawOrder = null;
121
        private JPanel pnlCenter = null;
122
        private JScrollPane srclLevels = null;
123
        private JTable tblLevels = null;
124
        private JButton btnUp = null;
125
        private JButton btnDown;
126
        private JPanel pnlSouth = null;
127
        private String[] advancedHeaders;
128
        private JButton btnSwitchView;
129
        private ZSort zSort;
130
        private SymbolSummary summary = new SymbolSummary();
131

    
132
        private ActionListener action = new ActionListener() {
133
                public void actionPerformed(ActionEvent e) {
134
                        String actionCommand = e.getActionCommand();
135
                        if ("OK".equals(actionCommand)) {
136
                                tblLevels.editingStopped(new ChangeEvent(tblLevels));
137
                                applyValues();
138
                        }
139

    
140
                        PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this);
141

    
142
                }
143
        };
144

    
145
        public WindowInfo getWindowInfo() {
146
                WindowInfo wi = new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MODALDIALOG);
147
                wi.setTitle(PluginServices.getText(this, "symbol_levels"));
148
                wi.setWidth(getWidth()+10);
149
                wi.setHeight(getHeight());
150
                return wi;
151
        }
152
        /**
153
         * Completes the main table of the panel with the symbols contained in the
154
         * legend of the map.
155
         *
156
         */
157
        private void applyValues() {
158

    
159
                // update symbol order
160
                TableModel model = tblLevels.getModel();
161

    
162

    
163

    
164
                Hashtable<ISymbol, int[] > aTable = new Hashtable<ISymbol, int[]>();
165
                ISymbol[] symbols = new ISymbol[model.getRowCount()];
166
                for (int i = 0; i < symbols.length; i++) {
167
                        symbols[i] = (ISymbol) model.getValueAt(i, SYMBOL_COLUMN_INDEX);
168
                        int length = 1;
169
                        if (symbols[i] instanceof IMultiLayerSymbol) {
170
                                IMultiLayerSymbol mlSym = (IMultiLayerSymbol) symbols[i];
171
                                length = mlSym.getLayerCount();
172
                        }
173

    
174
                        int[] symbolLevels = new int[length];
175
                        if (viewMode == DEFAULT_VIEW) {
176
                                // default view (JOIN and MERGE)
177
                                if (symbols[i] instanceof IMultiLayerSymbol) {
178
                                        boolean join = ((Boolean) model.getValueAt(i, JOIN_COLUMN_INDEX)).booleanValue();
179
                                        boolean merge= ((Boolean) model.getValueAt(i, MERGE_COLUMN_INDEX)).booleanValue();
180
                                        boolean needToJoin = true;
181
                                        if (merge && i>0) {
182
                                                int j=0;
183
                                                try {
184
                                                        int[] prevSymbolLevels = aTable.get(symbols[i-1]);
185
                                                        for (j = 0; j < symbolLevels.length; j++) {
186
                                                                symbolLevels[j] = prevSymbolLevels[j];
187
                                                        }
188
                                                } catch (IndexOutOfBoundsException ex) {
189
                                                        /* perfect, no problem
190
                                                         * the previous symbol has different amount of layers
191
                                                         * that is ok because we just have to replicate
192
                                                         * the values of each cell
193
                                                         */
194
                                                        for (; j < symbolLevels.length; j++) {
195
                                                                symbolLevels[j] = symbolLevels[j-1]+1;
196
                                                        }
197
                                                }
198
                                                needToJoin = false;
199
                                        }
200
                                        if (join && needToJoin) {
201
                                                for (int j = 0; j < symbolLevels.length; j++) {
202
                                                        symbolLevels[j] = zSort.getLevelCount()+j+1;
203
                                                }
204
                                        }
205
                                        if (!join && !merge) {
206
                                                for (int j = 0; j < symbolLevels.length; j++) {
207
                                                        symbolLevels[j] = zSort.getLevelCount();
208
                                                }
209
                                        }
210
                                } else {
211
                                        symbolLevels[0] = zSort.getLevelCount();
212
                                }
213
                        } else {
214
                                // ADVANCED VIEW (user may set map levels manually)
215
                                for (int j = 0; j < symbolLevels.length; j++) {
216
                                        symbolLevels[j] = ((Integer) model.getValueAt(i, j+FIRST_LEVEL_COLUMN_INDEX)).intValue();
217
                                }
218
                        }
219

    
220
                        aTable.put(symbols[i], symbolLevels);
221
                }
222

    
223
                Iterator<ISymbol> it = aTable.keySet().iterator();
224
                while (it.hasNext()) {
225
                        ISymbol sym = it.next();
226
                        zSort.setLevels(sym, aTable.get(sym));
227
                }
228

    
229
                zSort.setUsingZSort(getChkSpecifyDrawOrder().isSelected());
230
        }
231

    
232
        public SymbolLevelsWindow(ZSort zSort) {
233
                super();
234
                initialize();
235
                setModel(zSort);
236
                quitaEsteMetodo();
237
                tblLevels.setRowHeight(23);
238
        }
239
        private void quitaEsteMetodo() {
240
                getBtnSwitchView().setEnabled(false);
241
                getBtnDown().setEnabled(false);
242
                getBtnUp().setEnabled(false);
243
        }
244
        /**
245
         * Sets the model
246
         * @param plan ZSort
247
         */
248

    
249
        public void setModel(ZSort plan) {
250
                advancedHeaders = new String[FIRST_LEVEL_COLUMN_INDEX
251
                                             +plan.getTopLevelIndexAllowed() ];
252
                advancedHeaders[SYMBOL_COLUMN_INDEX] = defaultHeaders[SYMBOL_COLUMN_INDEX];
253
                advancedHeaders[DESCRIPTION_COLUMN_INDEX] = defaultHeaders[DESCRIPTION_COLUMN_INDEX];
254
                for (int i = 2; i < advancedHeaders.length; i++) {
255
                        advancedHeaders[i] = String.valueOf(i-1);
256
                }
257
                this.zSort = plan;
258
                getChkSpecifyDrawOrder().setSelected(plan.isUsingZSort());
259
                initTableContents(getTblLevels(), plan, viewMode);
260
        }
261
        /**
262
         * Initializes the table that it is showed in the panel where the user can
263
         * see the different symbols of the legend and has options to specify the
264
         * level for each one, merge and so on.
265
         *
266
         * @param table
267
         * @param zSort
268
         * @param mode
269
         */
270
        private void initTableContents(JTable table, ZSort zSort, int mode) {
271
                DefaultTableModel model = new DefaultTableModel();
272
                Object[][] dataVector = null;
273
                ISymbol[] syms = zSort.getSymbols();
274
//                String[] labels = zSort.getDescriptions();
275

    
276
                if (mode == DEFAULT_VIEW) {
277
                        // default view (JOIN and MERGE)
278
                        dataVector = new Object[syms.length][syms.length];
279
                        for (int i = 0; i < syms.length; i++) {
280
                                dataVector[i] = new Object[defaultHeaders.length];
281
                                ISymbol symbol = syms[i];
282
                                dataVector[i][SYMBOL_COLUMN_INDEX] = symbol;
283
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = symbol.getDescription();
284
                                if (symbol instanceof IMultiLayerSymbol) {
285
                                        boolean joined = true;
286
                                        int[] levels = zSort.getLevels(symbol);
287
                                        if(levels != null){
288
                                                for (int j = 0; j < levels.length; j++) {
289
                                                        if (joined)
290
                                                                joined = levels[j] != levels[j+1];
291
                                                }
292
                                        }
293

    
294

    
295

    
296
                                        boolean merged = true;
297
                                        if (i<syms.length-1) {
298
                                                for (int j = 0; joined && j < levels.length; j++) {
299
                                                        // must be joined to be merged
300
                                                        ISymbol nextSymbol = syms[i+1];
301
                                                        int[] nextLevels = zSort.getLevels(nextSymbol);
302
                                                        if(nextLevels != null){
303
                                                                if (nextSymbol instanceof IMultiLayerSymbol) {
304
                                                                        if (j<nextLevels.length) {
305
                                                                                merged = levels[j] == nextLevels[j];
306
                                                                        }
307
                                                                } else {
308
                                                                        merged = levels[0] == nextLevels[0];
309
                                                                }
310
                                                        }
311
                                                }
312
                                                if (!merged)
313
                                                        break;
314
                                        }
315
                                        if (!joined) merged = false;
316
                                        dataVector[i][JOIN_COLUMN_INDEX] = new Boolean(joined);
317
                                        dataVector[i][MERGE_COLUMN_INDEX] = new Boolean(merged);
318
                                }
319
                        }
320

    
321
                        model.setDataVector(dataVector, defaultHeaders);
322
                        table.setModel(model);
323
                        TableColumn col = table.getColumnModel().getColumn(JOIN_COLUMN_INDEX);
324
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
325
                        col.setCellEditor(new BooleanTableCellEditor(table));
326
                        col = table.getColumnModel().getColumn(MERGE_COLUMN_INDEX);
327
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
328
                        col.setCellEditor(new BooleanTableCellEditor(table));
329

    
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
                                ISymbol symbol = syms[i];
344
                                dataVector[i][SYMBOL_COLUMN_INDEX] = symbol;
345
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = symbol.getDescription();
346
                                if (symbol instanceof IMultiLayerSymbol) {
347
                                        int[] levels = zSort.getLevels(symbol);
348

    
349
                                        for (int j = 0; j < levels.length; j++) {
350
                                                dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = levels[j];
351
                                        }
352
                                } else {
353
                                        dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getLevels(symbol)[0]);
354
                                }
355
                        }
356

    
357
                        model.setDataVector(dataVector, advancedHeaders);
358
                        table.setModel(model);
359
                        for (int j = FIRST_LEVEL_COLUMN_INDEX; j < model.getColumnCount(); j++) {
360

    
361
                                table.getColumnModel().getColumn(j).setCellRenderer(new NumberTableCellRenderer(true, false));
362
                                table.getColumnModel().getColumn(j).setCellEditor(new IntegerTableCellEditor());
363
                        }
364
                }
365

    
366
                TableSymbolCellRenderer symbolCellRenderer = new TableSymbolCellRenderer(true) {
367
                        private static final long serialVersionUID = 5603529641148869112L;
368

    
369
                        { // Object static initialize block
370

    
371
                        preview = new SymbolPreviewer() {
372
                                private static final long serialVersionUID = 7262380340075167043L;
373
                                private Icon downIcon = new Icon(){
374
                                        public int getIconHeight() { return 7; }
375
                                        public int getIconWidth() { return 7; }
376
                                        public void paintIcon(Component c, Graphics g, int x, int y) {
377
                                                Graphics2D g2 = (Graphics2D) g;
378
                                                g2.setColor(Color.GRAY);
379
                                                        g2.translate(x + c.getWidth()-getIconWidth()*2, y + c.getHeight()-getIconHeight()*2);
380
                                                GeneralPath gp = new GeneralPath();
381
                                                gp.moveTo(0, 0);
382
                                                gp.lineTo(getIconWidth()/2, getIconHeight()-1);
383
                                                gp.lineTo(getIconWidth()-1, 0);
384
                                                g2.fill(gp);
385
                                                g2.translate(-(x + c.getWidth()-getIconWidth()*2), -(y + c.getHeight()-getIconHeight()*2));
386
                                        }
387
                                };
388
                                        @Override
389
                                public void paint(Graphics g) {
390
                                        super.paint(g);
391
                                        if (getSymbol() instanceof IMultiLayerSymbol) {
392
                                                downIcon.paintIcon(this, g, 0, 0);
393
                                        }
394
                                }
395
                        };
396

    
397
                        } // Object static initialize block
398
                };
399
                TableCellEditor symbolCellEditor = new TableCellEditor(){
400

    
401
                        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
402
                                return null;
403
                        }
404

    
405
                        public void addCellEditorListener(CellEditorListener l) {
406
                        }
407

    
408
                        public void cancelCellEditing() {
409
                        }
410

    
411
                        public Object getCellEditorValue() {
412
                                return null;
413
                        }
414

    
415
                        public boolean isCellEditable(EventObject anEvent) {
416
                                return false;
417
                        }
418

    
419
                        public void removeCellEditorListener(CellEditorListener l) {
420
                        }
421

    
422
                        public boolean shouldSelectCell(EventObject anEvent) {
423
                                return false;
424
                        }
425

    
426
                        public boolean stopCellEditing() {
427
                                return false;
428
                        }
429

    
430
                };
431
                TableColumn col = table.getColumnModel().getColumn(SYMBOL_COLUMN_INDEX);
432
                col.setCellRenderer(symbolCellRenderer);
433
                col.setCellEditor(symbolCellEditor);
434
        }
435

    
436
        private void initialize() {
437
                this.setLayout(new BorderLayout(15, 15));
438
                this.setSize(564, 344);
439

    
440
                this.add(getChkSpecifyDrawOrder(), BorderLayout.NORTH);
441
                this.add(new JBlank(20, 20));
442
                this.add(getPnlCenter(), BorderLayout.CENTER);
443
                this.add(getPnlSouth(), BorderLayout.SOUTH);
444
                tblLevels.addMouseListener(new MouseListener() {
445
                        public void mouseReleased(MouseEvent e) { }
446
                        public void mouseClicked(MouseEvent e)  { }
447
                        public void mouseEntered(MouseEvent e)  { }
448
                        public void mouseExited(MouseEvent e)  {
449
                                summary.sym = null;
450
                                repaint();
451
        }
452

    
453
                        public void mousePressed(MouseEvent e) {
454
                                Point where = e.getPoint();
455
                                int whereX = where.x;
456
                                int whereY = where.y;
457
                                Rectangle bounds = tblLevels.getBounds();
458
                                /*
459
                                 * calculate the right border x-position of the symbol
460
                                 * column
461
                                 */
462
                                int rightEdge = 0;
463
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
464
                                        rightEdge += tblLevels.getColumnModel().getColumn(i).getWidth();
465
                                }
466
                                if (whereX >= bounds.x &&
467
                                        whereX <= rightEdge + bounds.x &&
468
                                        whereY >= bounds.y &&
469
                                        whereY <= bounds.height + bounds.y) {
470
                                        int rowHeight = tblLevels.getRowHeight();
471
                                        int rowClicked = (whereY - bounds.y) / rowHeight;
472
                                        ISymbol sym = (ISymbol) tblLevels.
473
                                                                                        getModel().
474
                                                                                        getValueAt(
475
                                                                                                rowClicked,
476
                                                                                                SYMBOL_COLUMN_INDEX);
477
                                        if (sym instanceof IMultiLayerSymbol) {
478
                                                summary.sym = (IMultiLayerSymbol) sym;
479
                                                summary.rowIndex = rowClicked;
480
                                        } else {
481
                                                summary.sym = null;
482
                                        }
483
                                        repaint();
484
                                }
485
                        }
486

    
487
                });
488

    
489
        }
490

    
491
        private JCheckBox getChkSpecifyDrawOrder() {
492
                if (chkSpecifyDrawOrder == null) {
493
                        chkSpecifyDrawOrder = new JCheckBox("<html><b>"+
494
                                        PluginServices.getText(this, "draw_symbols_in_specified_order")
495
                                        +"</b></html>");
496
                        chkSpecifyDrawOrder.addActionListener(this);
497
                }
498
                return chkSpecifyDrawOrder;
499
        }
500

    
501

    
502
        private JPanel getPnlCenter() {
503
                if (pnlCenter == null) {
504
                        pnlCenter = new JPanel();
505
                        pnlCenter.setLayout(new BorderLayout(0, 15));
506
                        pnlCenter.add(getSrclLevels(), BorderLayout.CENTER);
507
                        pnlCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
508
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 15));
509
                        JPanel pnlButtons = new JPanel();
510
                        pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS));
511
                        pnlButtons.add(new JBlank(1, 70));
512
                        pnlButtons.add(getBtnUp());
513
                        pnlButtons.add(new JBlank(1, 10));
514
                        pnlButtons.add(getBtnDown());
515
                        pnlButtons.setVisible(false);
516
                        aux.add(pnlButtons);
517
                        pnlCenter.add(aux, BorderLayout.EAST);
518
                }
519
                pnlCenter.setEnabled(getChkSpecifyDrawOrder().isSelected());
520
                return pnlCenter;
521
        }
522

    
523
        private JScrollPane getSrclLevels() {
524
                if (srclLevels == null) {
525
                        srclLevels = new JScrollPane();
526
                        srclLevels.setViewportView(getTblLevels());
527
                }
528
                srclLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
529
                return srclLevels;
530
        }
531

    
532

    
533
        private JTable getTblLevels() {
534
                if (tblLevels == null) {
535
                        tblLevels = new JTable() {
536
                                private static final long serialVersionUID = -1545710722048183232L;
537

    
538
                                @Override
539
                                protected void paintComponent(Graphics g) {
540
                                        super.paintComponent(g);
541
                                        summary.paint((Graphics2D) g);
542
                                }
543
                        };
544
                        summary.rowHeight = tblLevels.getRowHeight();
545
                }
546
                tblLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
547
                return tblLevels;
548
        }
549

    
550

    
551
        private JButton getBtnUp() {
552
                if (btnUp == null) {
553
                        btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono"));
554
                        btnUp.setActionCommand("MOVE_UP");
555
                }
556
                return btnUp;
557
        }
558

    
559
        private JButton getBtnDown() {
560
                if (btnDown == null) {
561
                        btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono"));
562
                        btnDown.setActionCommand("MOVE_DOWN");
563
                }
564
                return btnDown;
565
        }
566

    
567

    
568
        private JPanel getPnlSouth() {
569
                if (pnlSouth == null) {
570
                        pnlSouth = new JPanel(new BorderLayout());
571
                        JPanel aux = new JPanel();
572
                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
573
                        aux.add(getBtnSwitchView());
574
                        pnlSouth.add(aux, BorderLayout.NORTH);
575

    
576
                        aux = new JPanel();
577
                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
578
                        pnlSouth.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
579

    
580
                }
581
                return pnlSouth;
582
        }
583

    
584
        private JButton getBtnSwitchView() {
585
                if (btnSwitchView == null) {
586
                        btnSwitchView = new JButton(
587
                                        (viewMode != DEFAULT_VIEW) ?
588
                                        PluginServices.getText(this, "default_view"):
589
                                        PluginServices.getText(this, "advanced_view")
590
                                        );
591
                        btnSwitchView.addActionListener(this);
592
                        btnSwitchView.setVisible(false);
593
                }
594

    
595
                return btnSwitchView;
596
        }
597

    
598
        public void actionPerformed(ActionEvent e) {
599
                JComponent c = (JComponent) e.getSource();
600
                if (c.equals(getChkSpecifyDrawOrder())) {
601
                        getPnlCenter().setEnabled(getChkSpecifyDrawOrder().isSelected());
602
                        getSrclLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
603
                        TableCellEditor tce = getTblLevels().getCellEditor();
604
                        if (tce != null){
605
                                tce.stopCellEditing();
606
                        }
607
                        getTblLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
608
                } else if (c.equals(getBtnSwitchView())) {
609
                        viewMode = (viewMode == ADVANCED_VIEW) ? DEFAULT_VIEW : ADVANCED_VIEW;
610
                        initTableContents(getTblLevels(), zSort, viewMode);
611
                        btnSwitchView.setText((viewMode != DEFAULT_VIEW) ?
612
                                        PluginServices.getText(this, "default_view"):
613
                                        PluginServices.getText(this, "advanced_view"));
614
                }
615
        }
616
        /**
617
         * Gets the ZSort value
618
         *
619
         * @return zSort ZSort
620
         */
621
        public ZSort getZSort() {
622
                return zSort;
623
        }
624

    
625
        private class SymbolSummary {
626
                int witdh;
627
                int rowHeight = 10;
628

    
629
                int rowIndex;
630

    
631
                IMultiLayerSymbol sym;
632

    
633
                void paint(Graphics2D g){
634

    
635
                        if (sym != null) {
636
                                int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6));
637
                                int whereX = 0;
638
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
639
                                        whereX += tblLevels.getColumnModel().getColumn(i).getWidth();
640
                                }
641
                                whereX -= 40;
642
                                int width = 150;
643
                                int height = Math.max(rowHeight*sym.getLayerCount(), rowHeight);
644
                                Rectangle bounds = new Rectangle(whereX, whereY, width, height);
645
                                g.setColor(new Color(255, 255, 220));
646
                                g.fill(bounds);
647

    
648
                                g.setColor(new Color(255, 230, 20));
649
                                g.draw(bounds);
650

    
651
                                g.setFont(new Font("Arial", Font.BOLD, 10));
652

    
653
                                for (int i = 0; i < sym.getLayerCount(); i++) {
654
                                        g.setColor(Color.black);
655
                                        g.drawString(i+1+":", whereX+5, height + whereY - ( (i*rowHeight) + 5 ));
656
                                        Rectangle rect = new Rectangle(whereX + 20,
657
                                                        height + whereY - ((i+1)*rowHeight) + 3,
658
                                                        width - 20,
659
                                                        rowHeight - 6);
660
                                        try {
661
                                                sym.getLayer(i).drawInsideRectangle(g, null, rect, null);
662
                                        } catch (SymbolDrawingException e) {
663
                                                if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
664
                                                        try {
665
                                                                SymbologyFactory.getWarningSymbol(
666
                                                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
667
                                                                                "",
668
                                                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS).drawInsideRectangle(g, null, rect, null);
669
                                                        } catch (SymbolDrawingException e1) {
670
                                                                // IMPOSSIBLE TO REACH THIS
671
                                                        }
672
                                                } else {
673
                                                        // should be unreachable code
674
                                                        throw new Error(PluginServices.getText(this, "symbol_shapetype_mismatch"));
675
                                                }
676
                                        }
677
                                }
678

    
679
                        }
680
                };
681
        }
682

    
683
        public Object getWindowProfile() {
684
                return WindowInfo.DIALOG_PROFILE;
685
        }
686
}