Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / JComboBoxLineStyles.java @ 25807

History | View | Annotate | Download (4.46 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

    
42
package org.gvsig.symbology.gui.styling;
43

    
44
import java.awt.BasicStroke;
45
import java.awt.Component;
46
import java.awt.Dimension;
47

    
48
import javax.swing.JList;
49
import javax.swing.ListCellRenderer;
50
import javax.swing.UIManager;
51

    
52
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
53
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle;
54
import com.iver.cit.gvsig.gui.styling.StylePreviewer;
55
import com.iver.utiles.swing.JComboBox;
56
/**
57
 * ComboBox that shows the different styles of line that can be selected by
58
 * the user in order to modify a symbol composed by lines .
59
 *
60
 * @author jaume dominguez faus - jaume.dominguez@iver.es
61
 *
62
 */
63
public class JComboBoxLineStyles extends JComboBox {
64
        private static final long serialVersionUID = -4468684151503515142L;
65
        private static final int PREDEFINED_STYLE_COUNT = 6;
66
        private static final int LINE_WIDTH = 10;
67
        private static final int DOT_WIDTH = 2;
68
        private int endCap;
69
        private int lineJoin;
70
        private float miterlimit;
71
        private int width;
72

    
73
        public static  float[][] dash = new float[PREDEFINED_STYLE_COUNT][];
74
        {
75

    
76
                dash[0] = new float[] {        1 }; // no dash, line
77

    
78
                dash[1] = new float[] {        LINE_WIDTH        }; // lines
79

    
80
                dash[2] = new float[] {        DOT_WIDTH        }; // dots
81

    
82
                dash[3] = new float[] {        LINE_WIDTH,
83
                                                                DOT_WIDTH        }; // line + dot
84

    
85
                dash[4] = new float[] {        LINE_WIDTH,
86
                                                                DOT_WIDTH,
87
                                                                DOT_WIDTH        }; // line + dot + dot
88
                dash[5] = new float[] {        LINE_WIDTH,
89
                                                                LINE_WIDTH,
90
                                                                DOT_WIDTH,
91
                                                                DOT_WIDTH        }; // line + line + dot + dot
92
        }
93

    
94
        {
95
                BasicStroke dummy = new BasicStroke();
96
                endCap = dummy.getEndCap();
97
                lineJoin = dummy.getLineJoin();
98
                miterlimit = dummy.getMiterLimit();
99
        }
100

    
101
        ILineStyle[] styles = new ILineStyle[PREDEFINED_STYLE_COUNT];
102

    
103
        private ListCellRenderer renderer = new ListCellRenderer() {
104
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
105
                        SimpleLineStyle style = null;
106
                        if (value instanceof float[]) {
107
                        float[] d = (float[]) value;
108
                        style = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, d, 0);
109
                        } else if (value instanceof SimpleLineStyle) {
110
                                style = (SimpleLineStyle) value;
111
                        }
112
                        StylePreviewer sp = new StylePreviewer();
113
                        Dimension sz = new Dimension(80, 20);
114
                        sp.setSize(50, 25);
115
                        sp.setPreferredSize(sz);
116
                        sp.setStyle(style);
117
                        sp.setForeground(UIManager.getColor(isSelected
118
                                        ? "ComboBox.selectionForeground"
119
                                                        : "ComboBox.foreground"));
120
                        sp.setBackground(UIManager.getColor(isSelected
121
                                        ? "ComboBox.selectionBackground"
122
                                                        : "ComboBox.background"));
123
                        return sp;
124
                };
125
        };
126
        private void refreshStyles() {
127
                for (int i = 0; i < styles.length; i++) {
128
                        styles[i] = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, dash[i], width*5);
129
                }
130

    
131
                removeAllItems();
132
                for (int i = 0; i < styles.length; i++) {
133
                        addItem(styles[i]);
134
                }
135
        }
136
        /**
137
         * Constructor method
138
         *
139
         */
140
        public JComboBoxLineStyles() {
141
                super();
142
                initialize();
143

    
144
        }
145

    
146
        /**
147
         * Initializes this
148
         *
149
         */
150
        private void initialize() {
151
                removeAllItems();
152
                for (int i = 0; i < dash.length; i++) {
153
                        addItem(dash[i]);
154
                }
155
                setEditable(false);
156
                setRenderer(renderer);
157
                refreshStyles();
158
        }
159
        /**
160
         * Sets the width of the line
161
         * @param width
162
         */
163
        public void setLineWidth(int width) {
164
                this.width = width;
165
                refreshStyles();
166
        }
167

    
168
}