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 14821 jmvivo
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 11704 jaume
 *
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 14821 jmvivo
 *   Av. Blasco Ib��ez, 50
24 11704 jaume
 *   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 14160 jdominguez
import java.awt.Color;
45
import java.awt.Component;
46 11704 jaume
import java.awt.FlowLayout;
47 14160 jdominguez
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 11704 jaume
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
54 14160 jdominguez
import java.awt.event.MouseEvent;
55
import java.awt.event.MouseListener;
56
import java.awt.geom.GeneralPath;
57 11820 jaume
import java.util.Hashtable;
58
import java.util.Iterator;
59 11704 jaume
60
import javax.swing.BorderFactory;
61
import javax.swing.BoxLayout;
62 14160 jdominguez
import javax.swing.Icon;
63 11704 jaume
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 14236 jdominguez
import javax.swing.event.ChangeEvent;
71 11704 jaume
import javax.swing.table.DefaultTableModel;
72
import javax.swing.table.TableColumn;
73 11734 jaume
import javax.swing.table.TableModel;
74 11704 jaume
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 11734 jaume
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor;
79 11704 jaume
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer;
80 11820 jaume
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer;
81 11704 jaume
82
import com.iver.andami.PluginServices;
83
import com.iver.andami.ui.mdiManager.IWindow;
84
import com.iver.andami.ui.mdiManager.WindowInfo;
85 18623 jdominguez
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
86 11704 jaume
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
87
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
88 18623 jdominguez
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
89 11734 jaume
import com.iver.cit.gvsig.fmap.rendering.ZSort;
90 11704 jaume
import com.iver.cit.gvsig.project.documents.gui.TableSymbolCellRenderer;
91
92
/**
93 13189 jvidal
 * 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 11704 jaume
 * @author jaume dominguez faus - jaume.dominguez@iver.es
100
 */
101
public class SymbolLevelsWindow extends JPanel implements IWindow, ActionListener {
102 13928 jaume
        private static final long serialVersionUID = 3241898997869313055L;
103 11734 jaume
        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 11704 jaume
        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 14160 jdominguez
        private static int viewMode = ADVANCED_VIEW;
117 11704 jaume
        private JCheckBox chkSpecifyDrawOrder = null;
118
        private JPanel pnlCenter = null;
119
        private JScrollPane srclLevels = null;
120
        private JTable tblLevels = null;
121 14821 jmvivo
        private JButton btnUp = null;
122 11704 jaume
        private JButton btnDown;
123
        private JPanel pnlSouth = null;
124
        private String[] advancedHeaders;
125
        private JButton btnSwitchView;
126 11734 jaume
        private ZSort zSort;
127 14160 jdominguez
        private SymbolSummary summary = new SymbolSummary();
128 11704 jaume
129 11734 jaume
        private ActionListener action = new ActionListener() {
130
                public void actionPerformed(ActionEvent e) {
131
                        String actionCommand = e.getActionCommand();
132
                        if ("OK".equals(actionCommand)) {
133 14236 jdominguez
                                tblLevels.editingStopped(new ChangeEvent(tblLevels));
134 11734 jaume
                                applyValues();
135
                        }
136 11820 jaume
137 11734 jaume
                        PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this);
138 11820 jaume
139 11734 jaume
                }
140
        };
141 11704 jaume
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 13189 jvidal
        /**
150
         * Completes the main table of the panel with the symbols contained in the
151
         * legend of the map.
152
         *
153
         */
154 11734 jaume
        private void applyValues() {
155
156
                // update symbol order
157
                TableModel model = tblLevels.getModel();
158
159
160
161 14160 jdominguez
                Hashtable<ISymbol, int[] > aTable = new Hashtable<ISymbol, int[]>();
162 11820 jaume
                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 11734 jaume
171 11820 jaume
                        int[] symbolLevels = new int[length];
172
                        if (viewMode == DEFAULT_VIEW) {
173 13928 jaume
                                // default view (JOIN and MERGE)
174 11820 jaume
                                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 13928 jaume
                                                        int[] prevSymbolLevels = aTable.get(symbols[i-1]);
182 11820 jaume
                                                        for (j = 0; j < symbolLevels.length; j++) {
183
                                                                symbolLevels[j] = prevSymbolLevels[j];
184 11734 jaume
                                                        }
185 11820 jaume
                                                } 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 11734 jaume
                                                        }
194
                                                }
195 11820 jaume
                                                needToJoin = false;
196
                                        }
197
                                        if (join && needToJoin) {
198
                                                for (int j = 0; j < symbolLevels.length; j++) {
199
                                                        symbolLevels[j] = zSort.getLevelCount()+j+1;
200 11734 jaume
                                                }
201
                                        }
202 11820 jaume
                                        if (!join && !merge) {
203
                                                for (int j = 0; j < symbolLevels.length; j++) {
204
                                                        symbolLevels[j] = zSort.getLevelCount();
205 11734 jaume
                                                }
206
                                        }
207
                                } else {
208 11820 jaume
                                        symbolLevels[0] = zSort.getLevelCount();
209 11734 jaume
                                }
210 11820 jaume
                        } else {
211 13928 jaume
                                // ADVANCED VIEW (user may set map levels manually)
212 11820 jaume
                                for (int j = 0; j < symbolLevels.length; j++) {
213
                                        symbolLevels[j] = ((Integer) model.getValueAt(i, j+FIRST_LEVEL_COLUMN_INDEX)).intValue();
214
                                }
215 11734 jaume
                        }
216 11820 jaume
217
                        aTable.put(symbols[i], symbolLevels);
218 11734 jaume
                }
219 12427 jaume
220 13928 jaume
                Iterator<ISymbol> it = aTable.keySet().iterator();
221 11820 jaume
                while (it.hasNext()) {
222 13928 jaume
                        ISymbol sym = it.next();
223
                        zSort.setLevels(sym, aTable.get(sym));
224 11820 jaume
                }
225 12427 jaume
226 11820 jaume
                zSort.setUsingZSort(getChkSpecifyDrawOrder().isSelected());
227 11734 jaume
        }
228
229 11820 jaume
        public SymbolLevelsWindow(ZSort zSort) {
230 11704 jaume
                super();
231
                initialize();
232 11820 jaume
                setModel(zSort);
233 16235 jdominguez
                quitaEsteMetodo();
234 11734 jaume
                tblLevels.setRowHeight(23);
235
        }
236 16235 jdominguez
        private void quitaEsteMetodo() {
237
                getBtnSwitchView().setEnabled(false);
238
                getBtnDown().setEnabled(false);
239
                getBtnUp().setEnabled(false);
240
        }
241 13189 jvidal
        /**
242
         * Sets the model
243
         * @param plan ZSort
244
         */
245 14821 jmvivo
246 11734 jaume
        public void setModel(ZSort plan) {
247 11850 jaume
                advancedHeaders = new String[FIRST_LEVEL_COLUMN_INDEX
248 13928 jaume
                                             +plan.getTopLevelIndexAllowed() ];
249 11734 jaume
                advancedHeaders[SYMBOL_COLUMN_INDEX] = defaultHeaders[SYMBOL_COLUMN_INDEX];
250
                advancedHeaders[DESCRIPTION_COLUMN_INDEX] = defaultHeaders[DESCRIPTION_COLUMN_INDEX];
251 11704 jaume
                for (int i = 2; i < advancedHeaders.length; i++) {
252
                        advancedHeaders[i] = String.valueOf(i-1);
253
                }
254 11734 jaume
                this.zSort = plan;
255 11704 jaume
                initTableContents(getTblLevels(), plan, viewMode);
256 11734 jaume
                getChkSpecifyDrawOrder().setSelected(plan.isUsingZSort());
257 11704 jaume
        }
258 13189 jvidal
        /**
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 11820 jaume
        private void initTableContents(JTable table, ZSort zSort, int mode) {
268 11704 jaume
                DefaultTableModel model = new DefaultTableModel();
269
                Object[][] dataVector = null;
270 11820 jaume
                ISymbol[] syms = zSort.getSymbols();
271
                String[] labels = zSort.getDescriptions();
272 14821 jmvivo
273 11704 jaume
                if (mode == DEFAULT_VIEW) {
274 13928 jaume
                        // default view (JOIN and MERGE)
275 11704 jaume
                        dataVector = new Object[syms.length][syms.length];
276
                        for (int i = 0; i < syms.length; i++) {
277
                                dataVector[i] = new Object[defaultHeaders.length];
278 11734 jaume
                                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 11741 jaume
                                        for (int j = 0; j < mlSymbol.getLayerCount(); j++) {
285 11734 jaume
                                                if (joined)
286 11820 jaume
                                                        joined = zSort.getSymbolLevel(mlSymbol.getLayer(j)) != zSort.getSymbolLevel(mlSymbol.getLayer(j+1));
287 11704 jaume
                                        }
288 11741 jaume
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 11820 jaume
                                                                        merged = zSort.getSymbolLevel(mlSymbol.getLayer(j)) == zSort.getSymbolLevel(nextMLSymbol.getLayer(j));
299 11741 jaume
                                                                }
300
                                                        } else {
301 11820 jaume
                                                                merged = zSort.getSymbolLevel(mlSymbol.getLayer(0)) == zSort.getSymbolLevel(nextSymbol);
302 11741 jaume
                                                        }
303
                                                }
304
                                                if (!merged)
305
                                                        break;
306
                                        }
307
                                        if (!joined) merged = false;
308 11734 jaume
                                        dataVector[i][JOIN_COLUMN_INDEX] = new Boolean(joined);
309 11741 jaume
                                        dataVector[i][MERGE_COLUMN_INDEX] = new Boolean(merged);
310 11704 jaume
                                }
311
                        }
312
313
                        model.setDataVector(dataVector, defaultHeaders);
314
                        table.setModel(model);
315 11734 jaume
                        TableColumn col = table.getColumnModel().getColumn(JOIN_COLUMN_INDEX);
316 11704 jaume
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
317 11741 jaume
                        col.setCellEditor(new BooleanTableCellEditor(table));
318 11734 jaume
                        col = table.getColumnModel().getColumn(MERGE_COLUMN_INDEX);
319 11704 jaume
                        col.setCellRenderer(new BooleanTableCellRenderer(true));
320 11741 jaume
                        col.setCellEditor(new BooleanTableCellEditor(table));
321 11704 jaume
                } else {
322 13928 jaume
                        // advanced view (user may input the map level manually)
323
                        dataVector = new Object[syms.length][
324 14821 jmvivo
                                             FIRST_LEVEL_COLUMN_INDEX + /* this is the first column that
325 13928 jaume
                                                                                                      * contains a level for the symbol
326 14821 jmvivo
                                                                                                      */
327
328 13928 jaume
                                             zSort.getTopLevelIndexAllowed() + /* according to the set of
329
                                                                                                                      * symbols this will get the
330
                                                                                                                      * max level reachable
331 14821 jmvivo
                                                                                                                      */
332 13928 jaume
                                             1 /* plus 1 to get a count instead of an index */];
333 11704 jaume
                        for (int i = 0; i < syms.length; i++) {
334 11734 jaume
                                dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
335
                                dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
336 11704 jaume
                                if (syms[i] instanceof IMultiLayerSymbol) {
337
                                        IMultiLayerSymbol mySym = (IMultiLayerSymbol) syms[i];
338 11741 jaume
                                        for (int j = 0; j < mySym.getLayerCount(); j++) {
339 14160 jdominguez
                                                dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getSymbolLevel(mySym.getLayer(j)));
340 11704 jaume
                                        }
341
                                } else {
342 11820 jaume
                                        dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getSymbolLevel(syms[i]));
343 11704 jaume
                                }
344
                        }
345 11820 jaume
346 11704 jaume
                        model.setDataVector(dataVector, advancedHeaders);
347
                        table.setModel(model);
348 11734 jaume
                        for (int j = FIRST_LEVEL_COLUMN_INDEX; j < model.getColumnCount(); j++) {
349 14821 jmvivo
350 11820 jaume
                                table.getColumnModel().getColumn(j).setCellRenderer(new NumberTableCellRenderer(true, false));
351 11734 jaume
                                table.getColumnModel().getColumn(j).setCellEditor(new IntegerTableCellEditor());
352
                        }
353 11704 jaume
                }
354 14160 jdominguez
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 11734 jaume
                TableColumn col = table.getColumnModel().getColumn(SYMBOL_COLUMN_INDEX);
389 11704 jaume
                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 14160 jdominguez
                tblLevels.addMouseListener(new MouseListener() {
401 14821 jmvivo
                        public void mouseReleased(MouseEvent e) { }
402 14160 jdominguez
                        public void mouseClicked(MouseEvent e)  { }
403
                        public void mouseEntered(MouseEvent e)  { }
404 14821 jmvivo
                        public void mouseExited(MouseEvent e)  {
405 14160 jdominguez
                                summary.sym = null;
406
                                repaint();
407 14821 jmvivo
        }
408 14160 jdominguez
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 14821 jmvivo
                                 */
418 14160 jdominguez
                                int rightEdge = 0;
419
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
420 14821 jmvivo
                                        rightEdge += tblLevels.getColumnModel().getColumn(i).getWidth();
421 14160 jdominguez
                                }
422 14821 jmvivo
                                if (whereX >= bounds.x &&
423 14160 jdominguez
                                        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 14821 jmvivo
                                }
441 14160 jdominguez
                        }
442 14821 jmvivo
443 14160 jdominguez
                });
444
445 11704 jaume
        }
446
447
        private JCheckBox getChkSpecifyDrawOrder() {
448
                if (chkSpecifyDrawOrder == null) {
449 16235 jdominguez
                        chkSpecifyDrawOrder = new JCheckBox("<html><b>"+
450
                                        PluginServices.getText(this, "draw_symbols_in_specified_order")
451
                                        +"</b></html>");
452 11704 jaume
                        chkSpecifyDrawOrder.addActionListener(this);
453
                }
454
                return chkSpecifyDrawOrder;
455
        }
456
457 14821 jmvivo
458 11704 jaume
        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 14821 jmvivo
487 11704 jaume
        private JTable getTblLevels() {
488
                if (tblLevels == null) {
489 14160 jdominguez
                        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 14821 jmvivo
                }
497 14160 jdominguez
                        };
498
                        summary.rowHeight = tblLevels.getRowHeight();
499 11704 jaume
                }
500
                return tblLevels;
501
        }
502
503 14821 jmvivo
504 11704 jaume
        private JButton getBtnUp() {
505
                if (btnUp == null) {
506 14821 jmvivo
                        btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono"));
507 11704 jaume
                        btnUp.setActionCommand("MOVE_UP");
508
                }
509
                return btnUp;
510
        }
511 14821 jmvivo
512 11704 jaume
        private JButton getBtnDown() {
513
                if (btnDown == null) {
514 14821 jmvivo
                        btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono"));
515 11704 jaume
                        btnDown.setActionCommand("MOVE_DOWN");
516
                }
517
                return btnDown;
518
        }
519
520 14821 jmvivo
521 11704 jaume
        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 11734 jaume
                        pnlSouth.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
532 11704 jaume
533
                }
534
                return pnlSouth;
535
        }
536 14821 jmvivo
537 11704 jaume
        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 11734 jaume
                        initTableContents(getTblLevels(), zSort, viewMode);
557 11704 jaume
                        btnSwitchView.setText((viewMode != DEFAULT_VIEW) ?
558
                                        PluginServices.getText(this, "default_view"):
559
                                        PluginServices.getText(this, "advanced_view"));
560
                }
561
        }
562 13189 jvidal
        /**
563
         * Gets the ZSort value
564
         *
565
         * @return zSort ZSort
566
         */
567 11820 jaume
        public ZSort getZSort() {
568
                return zSort;
569
        }
570
571 14160 jdominguez
        private class SymbolSummary {
572
                int witdh;
573
                int rowHeight = 10;
574 14821 jmvivo
575 14160 jdominguez
                int rowIndex;
576 14821 jmvivo
577 14160 jdominguez
                IMultiLayerSymbol sym;
578 14821 jmvivo
579 14160 jdominguez
                void paint(Graphics2D g){
580 14821 jmvivo
581 14160 jdominguez
                        if (sym != null) {
582
                                int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6));
583 14821 jmvivo
                                int whereX = 0;
584 14160 jdominguez
                                for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
585 14821 jmvivo
                                        whereX += tblLevels.getColumnModel().getColumn(i).getWidth();
586 11820 jaume
                                }
587 14160 jdominguez
                                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 11820 jaume
594 14160 jdominguez
                                g.setColor(new Color(255, 230, 20));
595
                                g.draw(bounds);
596 14821 jmvivo
597 14160 jdominguez
                                g.setFont(new Font("Arial", Font.BOLD, 10));
598 18623 jdominguez
599 14160 jdominguez
                                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 18623 jdominguez
                                        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 11820 jaume
                                }
624 14821 jmvivo
625 11820 jaume
                        }
626 14160 jdominguez
                };
627
        }
628 14821 jmvivo
}