Statistics
| Revision:

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

History | View | Annotate | Download (20.1 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.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.TableColumn;
73
import javax.swing.table.TableModel;
74

    
75
import org.gvsig.gui.beans.AcceptCancelPanel;
76
import org.gvsig.gui.beans.swing.JBlank;
77
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor;
78
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor;
79
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer;
80
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer;
81

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

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

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

    
137
                        PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this);
138

    
139
                }
140
        };
141

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

    
156
                // update symbol order
157
                TableModel model = tblLevels.getModel();
158

    
159

    
160

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

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

    
217
                        aTable.put(symbols[i], symbolLevels);
218
                }
219

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

    
226
                zSort.setUsingZSort(getChkSpecifyDrawOrder().isSelected());
227
        }
228

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

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

    
273
                if (mode == DEFAULT_VIEW) {
274
                        // default view (JOIN and MERGE)
275
                        dataVector = new Object[syms.length][syms.length];
276
                        for (int i = 0; i < syms.length; i++) {
277
                                dataVector[i] = new Object[defaultHeaders.length];
278
                                dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
279
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
280
                                if (syms[i] instanceof IMultiLayerSymbol) {
281
                                        boolean joined = true;
282
                                        IMultiLayerSymbol mlSymbol = (IMultiLayerSymbol) syms[i];
283
                                        // is joined if each layer belongs to distinct level
284
                                        for (int j = 0; j < mlSymbol.getLayerCount(); j++) {
285
                                                if (joined)
286
                                                        joined = zSort.getSymbolLevel(mlSymbol.getLayer(j)) != zSort.getSymbolLevel(mlSymbol.getLayer(j+1));
287
                                        }
288

    
289

    
290
                                        boolean merged = true;
291
                                        if (i<syms.length-1) {
292
                                                for (int j = 0; joined && j < mlSymbol.getLayerCount(); j++) {
293
                                                        // must be joined to be merged
294
                                                        ISymbol nextSymbol = syms[i+1];
295
                                                        if (nextSymbol instanceof IMultiLayerSymbol) {
296
                                                                IMultiLayerSymbol nextMLSymbol = (IMultiLayerSymbol) nextSymbol;
297
                                                                if (j<nextMLSymbol.getLayerCount()) {
298
                                                                        merged = zSort.getSymbolLevel(mlSymbol.getLayer(j)) == zSort.getSymbolLevel(nextMLSymbol.getLayer(j));
299
                                                                }
300
                                                        } else {
301
                                                                merged = zSort.getSymbolLevel(mlSymbol.getLayer(0)) == zSort.getSymbolLevel(nextSymbol);
302
                                                        }
303
                                                }
304
                                                if (!merged)
305
                                                        break;
306
                                        }
307
                                        if (!joined) merged = false;
308
                                        dataVector[i][JOIN_COLUMN_INDEX] = new Boolean(joined);
309
                                        dataVector[i][MERGE_COLUMN_INDEX] = new Boolean(merged);
310
                                }
311
                        }
312

    
313
                        model.setDataVector(dataVector, defaultHeaders);
314
                        table.setModel(model);
315
                        TableColumn col = table.getColumnModel().getColumn(JOIN_COLUMN_INDEX);
316
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
317
                        col.setCellEditor(new BooleanTableCellEditor(table));
318
                        col = table.getColumnModel().getColumn(MERGE_COLUMN_INDEX);
319
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
320
                        col.setCellEditor(new BooleanTableCellEditor(table));
321
                } else {
322
                        // advanced view (user may input the map level manually)
323
                        dataVector = new Object[syms.length][
324
                                             FIRST_LEVEL_COLUMN_INDEX + /* this is the first column that
325
                                                                                                      * contains a level for the symbol
326
                                                                                                      */
327

    
328
                                             zSort.getTopLevelIndexAllowed() + /* according to the set of
329
                                                                                                                      * symbols this will get the
330
                                                                                                                      * max level reachable
331
                                                                                                                      */
332
                                             1 /* plus 1 to get a count instead of an index */];
333
                        for (int i = 0; i < syms.length; i++) {
334
                                dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
335
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
336
                                if (syms[i] instanceof IMultiLayerSymbol) {
337
                                        IMultiLayerSymbol mySym = (IMultiLayerSymbol) syms[i];
338
                                        for (int j = 0; j < mySym.getLayerCount(); j++) {
339
                                                dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getSymbolLevel(mySym.getLayer(j)));
340
                                        }
341
                                } else {
342
                                        dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getSymbolLevel(syms[i]));
343
                                }
344
                        }
345

    
346
                        model.setDataVector(dataVector, advancedHeaders);
347
                        table.setModel(model);
348
                        for (int j = FIRST_LEVEL_COLUMN_INDEX; j < model.getColumnCount(); j++) {
349

    
350
                                table.getColumnModel().getColumn(j).setCellRenderer(new NumberTableCellRenderer(true, false));
351
                                table.getColumnModel().getColumn(j).setCellEditor(new IntegerTableCellEditor());
352
                        }
353
                }
354

    
355
                TableSymbolCellRenderer symbolCellRenderer = new TableSymbolCellRenderer(true) {
356
                        private static final long serialVersionUID = 5603529641148869112L;
357

    
358
                        { // Object static initialize block
359

    
360
                        preview = new SymbolPreviewer() {
361
                                private static final long serialVersionUID = 7262380340075167043L;
362
                                private Icon downIcon = new Icon(){
363
                                        public int getIconHeight() { return 7; }
364
                                        public int getIconWidth() { return 7; }
365
                                        public void paintIcon(Component c, Graphics g, int x, int y) {
366
                                                Graphics2D g2 = (Graphics2D) g;
367
                                                g2.setColor(Color.GRAY);
368
                                                        g2.translate(x + c.getWidth()-getIconWidth()*2, y + c.getHeight()-getIconHeight()*2);
369
                                                GeneralPath gp = new GeneralPath();
370
                                                gp.moveTo(0, 0);
371
                                                gp.lineTo(getIconWidth()/2, getIconHeight()-1);
372
                                                gp.lineTo(getIconWidth()-1, 0);
373
                                                g2.fill(gp);
374
                                                g2.translate(-(x + c.getWidth()-getIconWidth()*2), -(y + c.getHeight()-getIconHeight()*2));
375
                                        }
376
                                };
377
                                        @Override
378
                                public void paint(Graphics g) {
379
                                        super.paint(g);
380
                                        if (getSymbol() instanceof IMultiLayerSymbol) {
381
                                                downIcon.paintIcon(this, g, 0, 0);
382
                                        }
383
                                }
384
                        };
385

    
386
                        } // Object static initialize block
387
                };
388
                TableColumn col = table.getColumnModel().getColumn(SYMBOL_COLUMN_INDEX);
389
                col.setCellRenderer(symbolCellRenderer);
390
        }
391

    
392
        private void initialize() {
393
                this.setLayout(new BorderLayout(15, 15));
394
                this.setSize(564, 344);
395

    
396
                this.add(getChkSpecifyDrawOrder(), BorderLayout.NORTH);
397
                this.add(new JBlank(20, 20));
398
                this.add(getPnlCenter(), BorderLayout.CENTER);
399
                this.add(getPnlSouth(), BorderLayout.SOUTH);
400
                tblLevels.addMouseListener(new MouseListener() {
401
                        public void mouseReleased(MouseEvent e) { }
402
                        public void mouseClicked(MouseEvent e)  { }
403
                        public void mouseEntered(MouseEvent e)  { }
404
                        public void mouseExited(MouseEvent e)  {
405
                                summary.sym = null;
406
                                repaint();
407
        }
408

    
409
                        public void mousePressed(MouseEvent e) {
410
                                Point where = e.getPoint();
411
                                int whereX = where.x;
412
                                int whereY = where.y;
413
                                Rectangle bounds = tblLevels.getBounds();
414
                                /*
415
                                 * calculate the right border x-position of the symbol
416
                                 * column
417
                                 */
418
                                int rightEdge = 0;
419
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
420
                                        rightEdge += tblLevels.getColumnModel().getColumn(i).getWidth();
421
                                }
422
                                if (whereX >= bounds.x &&
423
                                        whereX <= rightEdge + bounds.x &&
424
                                        whereY >= bounds.y &&
425
                                        whereY <= bounds.height + bounds.y) {
426
                                        int rowHeight = tblLevels.getRowHeight();
427
                                        int rowClicked = (whereY - bounds.y) / rowHeight;
428
                                        ISymbol sym = (ISymbol) tblLevels.
429
                                                                                        getModel().
430
                                                                                        getValueAt(
431
                                                                                                rowClicked,
432
                                                                                                SYMBOL_COLUMN_INDEX);
433
                                        if (sym instanceof IMultiLayerSymbol) {
434
                                                summary.sym = (IMultiLayerSymbol) sym;
435
                                                summary.rowIndex = rowClicked;
436
                                        } else {
437
                                                summary.sym = null;
438
                                        }
439
                                        repaint();
440
                                }
441
                        }
442

    
443
                });
444

    
445
        }
446

    
447
        private JCheckBox getChkSpecifyDrawOrder() {
448
                if (chkSpecifyDrawOrder == null) {
449
                        chkSpecifyDrawOrder = new JCheckBox("<html><b>"+
450
                                        PluginServices.getText(this, "draw_symbols_in_specified_order")
451
                                        +"</b></html>");
452
                        chkSpecifyDrawOrder.addActionListener(this);
453
                }
454
                return chkSpecifyDrawOrder;
455
        }
456

    
457

    
458
        private JPanel getPnlCenter() {
459
                if (pnlCenter == null) {
460
                        pnlCenter = new JPanel();
461
                        pnlCenter.setLayout(new BorderLayout(0, 15));
462
                        pnlCenter.add(getSrclLevels(), BorderLayout.CENTER);
463
                        pnlCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
464
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 15));
465
                        JPanel pnlButtons = new JPanel();
466
                        pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS));
467
                        pnlButtons.add(new JBlank(1, 70));
468
                        pnlButtons.add(getBtnUp());
469
                        pnlButtons.add(new JBlank(1, 10));
470
                        pnlButtons.add(getBtnDown());
471
                        aux.add(pnlButtons);
472
                        pnlCenter.add(aux, BorderLayout.EAST);
473

    
474
                }
475
                return pnlCenter;
476
        }
477

    
478
        private JScrollPane getSrclLevels() {
479
                if (srclLevels == null) {
480
                        srclLevels = new JScrollPane();
481
                        srclLevels.setViewportView(getTblLevels());
482
                }
483
                return srclLevels;
484
        }
485

    
486

    
487
        private JTable getTblLevels() {
488
                if (tblLevels == null) {
489
                        tblLevels = new JTable() {
490
                                private static final long serialVersionUID = -1545710722048183232L;
491

    
492
                                @Override
493
                                protected void paintComponent(Graphics g) {
494
                                        super.paintComponent(g);
495
                                        summary.paint((Graphics2D) g);
496
                }
497
                        };
498
                        summary.rowHeight = tblLevels.getRowHeight();
499
                }
500
                return tblLevels;
501
        }
502

    
503

    
504
        private JButton getBtnUp() {
505
                if (btnUp == null) {
506
                        btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono"));
507
                        btnUp.setActionCommand("MOVE_UP");
508
                }
509
                return btnUp;
510
        }
511

    
512
        private JButton getBtnDown() {
513
                if (btnDown == null) {
514
                        btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono"));
515
                        btnDown.setActionCommand("MOVE_DOWN");
516
                }
517
                return btnDown;
518
        }
519

    
520

    
521
        private JPanel getPnlSouth() {
522
                if (pnlSouth == null) {
523
                        pnlSouth = new JPanel(new BorderLayout());
524
                        JPanel aux = new JPanel();
525
                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
526
                        aux.add(getBtnSwitchView());
527
                        pnlSouth.add(aux, BorderLayout.NORTH);
528

    
529
                        aux = new JPanel();
530
                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
531
                        pnlSouth.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
532

    
533
                }
534
                return pnlSouth;
535
        }
536

    
537
        private JButton getBtnSwitchView() {
538
                if (btnSwitchView == null) {
539
                        btnSwitchView = new JButton(
540
                                        (viewMode != DEFAULT_VIEW) ?
541
                                        PluginServices.getText(this, "default_view"):
542
                                        PluginServices.getText(this, "advanced_view")
543
                                        );
544
                        btnSwitchView.addActionListener(this);
545
                }
546

    
547
                return btnSwitchView;
548
        }
549

    
550
        public void actionPerformed(ActionEvent e) {
551
                JComponent c = (JComponent) e.getSource();
552
                if (c.equals(getChkSpecifyDrawOrder())) {
553
                        getPnlCenter().setEnabled(getChkSpecifyDrawOrder().isSelected());
554
                } else if (c.equals(getBtnSwitchView())) {
555
                        viewMode = (viewMode == ADVANCED_VIEW) ? DEFAULT_VIEW : ADVANCED_VIEW;
556
                        initTableContents(getTblLevels(), zSort, viewMode);
557
                        btnSwitchView.setText((viewMode != DEFAULT_VIEW) ?
558
                                        PluginServices.getText(this, "default_view"):
559
                                        PluginServices.getText(this, "advanced_view"));
560
                }
561
        }
562
        /**
563
         * Gets the ZSort value
564
         *
565
         * @return zSort ZSort
566
         */
567
        public ZSort getZSort() {
568
                return zSort;
569
        }
570

    
571
        private class SymbolSummary {
572
                int witdh;
573
                int rowHeight = 10;
574

    
575
                int rowIndex;
576

    
577
                IMultiLayerSymbol sym;
578

    
579
                void paint(Graphics2D g){
580

    
581
                        if (sym != null) {
582
                                int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6));
583
                                int whereX = 0;
584
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
585
                                        whereX += tblLevels.getColumnModel().getColumn(i).getWidth();
586
                                }
587
                                whereX -= 40;
588
                                int width = 150;
589
                                int height = Math.max(rowHeight*sym.getLayerCount(), rowHeight);
590
                                Rectangle bounds = new Rectangle(whereX, whereY, width, height);
591
                                g.setColor(new Color(255, 255, 220));
592
                                g.fill(bounds);
593

    
594
                                g.setColor(new Color(255, 230, 20));
595
                                g.draw(bounds);
596

    
597
                                g.setFont(new Font("Arial", Font.BOLD, 10));
598
                                
599
                                for (int i = 0; i < sym.getLayerCount(); i++) {
600
                                        g.setColor(Color.black);
601
                                        g.drawString(i+1+":", whereX+5, height + whereY - ( (i*rowHeight) + 5 ));
602
                                        Rectangle rect = new Rectangle(whereX + 20,
603
                                                        height + whereY - ((i+1)*rowHeight) + 3,
604
                                                        width - 20,
605
                                                        rowHeight - 6);
606
                                        try {
607
                                                sym.getLayer(i).drawInsideRectangle(g, null, rect);
608
                                        } catch (SymbolDrawingException e) {
609
                                                if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
610
                                                        try {
611
                                                                SymbologyFactory.getWarningSymbol(
612
                                                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
613
                                                                                "",
614
                                                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS).drawInsideRectangle(g, null, rect);
615
                                                        } catch (SymbolDrawingException e1) {
616
                                                                // IMPOSSIBLE TO REACH THIS
617
                                                        }
618
                                                } else {
619
                                                        // should be unreachable code
620
                                                        throw new Error(PluginServices.getText(this, "symbol_shapetype_mismatch"));
621
                                                }
622
                                        }
623
                                }
624

    
625
                        }
626
                };
627
        }
628
}