Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolLevelsWindow.java @ 43510

History | View | Annotate | Download (20.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.gui.styling;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.Component;
29
import java.awt.FlowLayout;
30
import java.awt.Font;
31
import java.awt.Graphics;
32
import java.awt.Graphics2D;
33
import java.awt.Point;
34
import java.awt.Rectangle;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
37
import java.awt.event.MouseEvent;
38
import java.awt.event.MouseListener;
39
import java.awt.geom.GeneralPath;
40
import java.util.Hashtable;
41
import java.util.Iterator;
42

    
43
import javax.swing.BorderFactory;
44
import javax.swing.BoxLayout;
45
import javax.swing.Icon;
46
import javax.swing.JButton;
47
import javax.swing.JCheckBox;
48
import javax.swing.JComponent;
49
import javax.swing.JPanel;
50
import javax.swing.JScrollPane;
51
import javax.swing.JTable;
52
import javax.swing.border.EtchedBorder;
53
import javax.swing.event.ChangeEvent;
54
import javax.swing.table.DefaultTableModel;
55
import javax.swing.table.TableCellEditor;
56
import javax.swing.table.TableColumn;
57
import javax.swing.table.TableModel;
58

    
59
import org.gvsig.andami.PluginServices;
60
import org.gvsig.andami.ui.mdiManager.IWindow;
61
import org.gvsig.andami.ui.mdiManager.WindowInfo;
62
import org.gvsig.app.project.documents.gui.TableSymbolCellRenderer;
63
import org.gvsig.fmap.mapcontext.MapContextLocator;
64
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
65
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
66
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
67
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
68
import org.gvsig.gui.beans.AcceptCancelPanel;
69
import org.gvsig.gui.beans.swing.JBlank;
70
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor;
71
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor;
72
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer;
73
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer;
74
import org.gvsig.i18n.Messages;
75

    
76
import org.apache.commons.lang3.StringUtils;
77

    
78

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

    
117
        private ActionListener action = new ActionListener() {
118
                public void actionPerformed(ActionEvent e) {
119
                        String actionCommand = e.getActionCommand();
120
                        if ("OK".equals(actionCommand)) {
121
                                tblLevels.editingStopped(new ChangeEvent(tblLevels));
122
                                applyValues();
123
                        }
124

    
125
                        PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this);
126

    
127
                }
128
        };
129

    
130
    public SymbolLevelsWindow(ZSort zSort) {
131
        super();
132
        initialize();
133
        setModel(zSort);
134
        quitaEsteMetodo();
135
        tblLevels.setRowHeight(23);
136
    }
137
    
138
    private void quitaEsteMetodo() {
139
        getBtnSwitchView().setEnabled(false);
140
        getBtnDown().setEnabled(false);
141
        getBtnUp().setEnabled(false);
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
        /**
232
         * Sets the model
233
         * @param plan ZSort
234
         */
235

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

    
267
                if (mode == DEFAULT_VIEW) {
268
                        // default view (JOIN and MERGE)
269
                        dataVector = new Object[syms.length][syms.length];
270
                        for (int i = 0; i < syms.length; i++) {
271
                                dataVector[i] = new Object[defaultHeaders.length];
272
                                dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
273
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
274
                                if (syms[i] instanceof IMultiLayerSymbol) {
275
                                        boolean joined = true;
276
                                        int[] levels = zSort.getLevels(syms[i]);
277
                                        if(levels != null){
278
                                                for (int j = 0; j < levels.length; j++) {
279
                                                        if (joined) {
280
                                                                joined = levels[j] != levels[j+1];
281
                                                        }
282
                                                }
283
                                        }
284

    
285

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

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

    
329
                                                             zSort.getTopLevelIndexAllowed() + /* according to the set of
330
                                                              * symbols this will get the
331
                                                              * max level reachable
332
                                                              */
333
                                                             1 /* plus 1 to get a count instead of an index */];
334
                        for (int i = 0; i < syms.length; i++) {
335
                                dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
336
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
337
                                if (syms[i] instanceof IMultiLayerSymbol) {
338
                                        int[] levels = zSort.getLevels(syms[i]);
339

    
340
                                        for (int j = 0; j < levels.length; j++) {
341
                                                dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = levels[j];
342
                                        }
343
                                } else {
344
                                        dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getLevels(syms[i])[0]);
345
                                }
346
                        }
347

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

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

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

    
360
                        { // Object static initialize block
361

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

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

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

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

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

    
445
                });
446

    
447
        }
448
        
449
        private JPanel getNorthPanel() {
450
        if (pnlNorth == null) {
451
            pnlNorth = new JPanel();
452
            pnlNorth.setLayout(new BorderLayout());
453
            pnlNorth.add(new JBlank(15, 15), BorderLayout.NORTH);
454
            pnlNorth.add(getChkSpecifyDrawOrder(), BorderLayout.CENTER);
455
            pnlNorth.add(new JBlank(15, 0), BorderLayout.WEST);
456
        }
457
        return pnlNorth;
458
    }
459

    
460
        private JCheckBox getChkSpecifyDrawOrder() {
461
                if (chkSpecifyDrawOrder == null) {
462
                        chkSpecifyDrawOrder = new JCheckBox("<html><b>"+
463
                                        Messages.getText("draw_symbols_in_specified_order")
464
                                        +"</b></html>");
465
                        chkSpecifyDrawOrder.addActionListener(this);
466
                }
467
                return chkSpecifyDrawOrder;
468
        }
469

    
470

    
471
        private JPanel getPnlCenter() {
472
                if (pnlCenter == null) {
473
                        pnlCenter = new JPanel();
474
                        pnlCenter.setLayout(new BorderLayout(0, 15));
475
                        pnlCenter.add(getSrclLevels(), BorderLayout.CENTER);
476
                        pnlCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
477
//                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 15));
478
//                        JPanel pnlButtons = new JPanel();
479
//                        pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS));
480
//                        pnlButtons.add(new JBlank(1, 70));
481
//                        pnlButtons.add(getBtnUp());
482
//                        pnlButtons.add(new JBlank(1, 10));
483
//                        pnlButtons.add(getBtnDown());
484
//                        pnlButtons.setVisible(false);
485
//                        aux.add(pnlButtons);
486
//                        pnlCenter.add(aux, BorderLayout.EAST);
487

    
488
                }
489
                pnlCenter.setEnabled(getChkSpecifyDrawOrder().isSelected());
490
                return pnlCenter;
491
        }
492

    
493
        private JScrollPane getSrclLevels() {
494
                if (srclLevels == null) {
495
                        srclLevels = new JScrollPane();
496
                        srclLevels.setViewportView(getTblLevels());
497
                }
498
                srclLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
499
                return srclLevels;
500
        }
501

    
502

    
503
        private JTable getTblLevels() {
504
                if (tblLevels == null) {
505
                        tblLevels = new JTable() {
506
                                private static final long serialVersionUID = -1545710722048183232L;
507

    
508
                                @Override
509
                                protected void paintComponent(Graphics g) {
510
                                        super.paintComponent(g);
511
                                        summary.paint((Graphics2D) g);
512
                }
513
                        };
514
                        summary.rowHeight = tblLevels.getRowHeight();
515
                }
516
                tblLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
517
                return tblLevels;
518
        }
519

    
520

    
521
        private JButton getBtnUp() {
522
                if (btnUp == null) {
523
                        btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono"));
524
                        btnUp.setActionCommand("MOVE_UP");
525
                }
526
                return btnUp;
527
        }
528

    
529
        private JButton getBtnDown() {
530
                if (btnDown == null) {
531
                        btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono"));
532
                        btnDown.setActionCommand("MOVE_DOWN");
533
                }
534
                return btnDown;
535
        }
536

    
537

    
538
        private JPanel getPnlSouth() {
539
                if (pnlSouth == null) {
540
                        pnlSouth = new JPanel(new BorderLayout());
541
                        JPanel aux = new JPanel();
542
//                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
543
//                        aux.add(getBtnSwitchView());
544
//                        pnlSouth.add(aux, BorderLayout.NORTH);
545

    
546
                        aux = new JPanel();
547
                        aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
548
                        pnlSouth.add(new AcceptCancelPanel(action, action));
549

    
550
                }
551
                return pnlSouth;
552
        }
553

    
554
        private JButton getBtnSwitchView() {
555
                if (btnSwitchView == null) {
556
                        btnSwitchView = new JButton(
557
                                        (viewMode != DEFAULT_VIEW) ?
558
                                        Messages.getText("default_view"):
559
                                        Messages.getText("advanced_view")
560
                                        );
561
                        btnSwitchView.addActionListener(this);
562
                        btnSwitchView.setVisible(false);
563
                }
564

    
565
                return btnSwitchView;
566
        }
567

    
568
        public void actionPerformed(ActionEvent e) {
569
                JComponent c = (JComponent) e.getSource();
570
                if (c.equals(getChkSpecifyDrawOrder())) {
571
                        getPnlCenter().setEnabled(getChkSpecifyDrawOrder().isSelected());
572
                        getSrclLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
573
                        TableCellEditor tce = getTblLevels().getCellEditor();
574
                        if (tce != null){
575
                                tce.stopCellEditing();
576
                        }
577
                        getTblLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
578
                } else if (c.equals(getBtnSwitchView())) {
579
                        viewMode = (viewMode == ADVANCED_VIEW) ? DEFAULT_VIEW : ADVANCED_VIEW;
580
                        initTableContents(getTblLevels(), zSort, viewMode);
581
                        btnSwitchView.setText((viewMode != DEFAULT_VIEW) ?
582
                                        Messages.getText("default_view"):
583
                                        Messages.getText("advanced_view"));
584
                }
585
        }
586
        /**
587
         * Gets the ZSort value
588
         *
589
         * @return zSort ZSort
590
         */
591
        public ZSort getZSort() {
592
                return zSort;
593
        }
594

    
595
        private class SymbolSummary {
596
                int witdh;
597
                int rowHeight = 10;
598

    
599
                int rowIndex;
600

    
601
                IMultiLayerSymbol sym;
602

    
603
                void paint(Graphics2D g){
604

    
605
                        if (sym != null) {
606
                                int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6));
607
                                int whereX = 0;
608
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
609
                                        whereX += tblLevels.getColumnModel().getColumn(i).getWidth();
610
                                }
611
                                whereX -= 40;
612
                                int width = 150;
613
                                int height = Math.max(rowHeight*sym.getLayerCount(), rowHeight);
614
                                Rectangle bounds = new Rectangle(whereX, whereY, width, height);
615
                                g.setColor(new Color(255, 255, 220));
616
                                g.fill(bounds);
617

    
618
                                g.setColor(new Color(255, 230, 20));
619
                                g.draw(bounds);
620

    
621
                                g.setFont(new Font("Arial", Font.BOLD, 10));
622

    
623
                                for (int i = 0; i < sym.getLayerCount(); i++) {
624
                                        g.setColor(Color.black);
625
                                        g.drawString(i+1+":", whereX+5, height + whereY - ( (i*rowHeight) + 5 ));
626
                                        Rectangle rect = new Rectangle(whereX + 20,
627
                                                        height + whereY - ((i+1)*rowHeight) + 3,
628
                                                        width - 20,
629
                                                        rowHeight - 6);
630
                                        try {
631
                                                sym.getLayer(i).drawInsideRectangle(g, null, rect,null);
632
                                        } catch (SymbolDrawingException e) {
633
                                                if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
634
                                                        try {
635
                                                                MapContextLocator.getSymbolManager()
636
                                                                                .getWarningSymbol(
637
                                                                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
638
                                                                                                "",
639
                                                                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
640
                                                                                .drawInsideRectangle(g, null, rect,
641
                                                                                                null);
642
                                                        } catch (SymbolDrawingException e1) {
643
                                                                // IMPOSSIBLE TO REACH THIS
644
                                                        }
645
                                                } else {
646
                                                        // should be unreachable code
647
                                                        throw new Error(Messages.getText("symbol_shapetype_mismatch"));
648
                                                }
649
                                        }
650
                                }
651

    
652
                        }
653
                };
654
        }
655

    
656
        public Object getWindowProfile() {
657
                return WindowInfo.DIALOG_PROFILE;
658
        }
659

    
660
}