Statistics
| Revision:

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

History | View | Annotate | Download (4.71 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.Color;
44
import java.awt.Component;
45
import java.awt.Dimension;
46

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

    
51
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
52
import com.iver.utiles.swing.JComboBox;
53

    
54
/**
55
 * JComboBox used by the user to select the different styles of simple marker symbols.
56
 * The available options are: circle style,square style,cross style, diamond style,x style
57
 * and triangle style.
58
 *
59
 * @author jaume dominguez faus - jaume.dominguez@iver.es
60
 */
61
public class JComboBoxSimpleMarkeStyles extends JComboBox{
62
        private Color symColor = Color.BLACK;
63
        private Color outlineColor = Color.BLACK;
64
        private boolean outlined = false;
65
        static MyItem[] pointTypes = new MyItem[] {
66
                new MyItem(SimpleMarkerSymbol.CIRCLE_STYLE),
67
                new MyItem(SimpleMarkerSymbol.SQUARE_STYLE),
68
                new MyItem(SimpleMarkerSymbol.CROSS_STYLE),
69
                new MyItem(SimpleMarkerSymbol.DIAMOND_STYLE),
70
                new MyItem(SimpleMarkerSymbol.X_STYLE),
71
                new MyItem(SimpleMarkerSymbol.TRIANGLE_STYLE),
72
                new MyItem(SimpleMarkerSymbol.STAR_STYLE),
73
        };
74

    
75
        /**
76
         * Constructor method
77
         *
78
         */
79

    
80
        public JComboBoxSimpleMarkeStyles() {
81
                super();
82
                removeAllItems();
83
                for (int i = 0; i < pointTypes.length; i++) {
84
                        addItem(pointTypes[i]);
85
                }
86

    
87
                setEditable(false);
88
                setRenderer(new ListCellRenderer() {
89

    
90
                        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
91
                                SymbolPreviewer preview = new SymbolPreviewer() ;
92
                                SimpleMarkerSymbol mySymbol = new SimpleMarkerSymbol();
93
                                mySymbol.setColor(symColor);
94
                                mySymbol.setOutlined(outlined);
95
                                mySymbol.setOutlineColor(outlineColor);
96
                                if (value instanceof MyItem) {
97
                                        mySymbol.setStyle(((MyItem) value).style);
98
                                } else {
99
                                        mySymbol.setStyle(((Integer) value).intValue());
100
                                }
101

    
102
                                mySymbol.setUnit(-1); // pixel
103
                                mySymbol.setSize(10);
104
                                preview.setForeground(UIManager.getColor(isSelected
105
                                                ? "ComboBox.selectionForeground"
106
                                                                : "ComboBox.foreground"));
107
                                preview.setBackground(UIManager.getColor(isSelected
108
                                                ? "ComboBox.selectionBackground"
109
                                                                : "ComboBox.background"));
110
                                preview.setSymbol(mySymbol);
111
                                preview.setSize(preview.getWidth(), 20);
112
                                preview.setPreferredSize(new Dimension(preview.getWidth(), 20));
113
                                return preview;
114
                        }
115
                });
116
        }
117

    
118
        /**
119
         * Establishes the color of the simple marker symbol.
120
         * @param c,Color
121
         */
122
        public void setSymbolColor(Color c) {
123
                this.symColor = c;
124
        }
125

    
126
        /**
127
         * Sets the color for the outline of the simple marker symbol
128
         * @param c,Color
129
         */
130
        public void setOutlineColor(Color c) {
131
                outlined = c!=null;
132
                outlineColor = c;
133
        }
134

    
135
        public Object getSelectedItem() {
136
                return new Integer(((MyItem) super.getSelectedItem()).style);
137
        }
138

    
139
        public void setSelectedItem(Object item) {
140
                if (item instanceof Integer) {
141
                        int myItem = ((Integer) item).intValue();
142
                        for (int i = 0; i < pointTypes.length; i++) {
143
                                if (myItem == pointTypes[i].style)
144
                                        setSelectedIndex(i);
145
                        }
146
                }
147
                super.setSelectedItem(item);
148
        }
149
}
150
/**
151
 * Used to store the different options that the JComboBoxsimplemarkerStyles shows to
152
 * the user.
153
 *
154
 */
155
class MyItem {
156
        int style;
157

    
158
        /**
159
         * Constructor method
160
         * @param style
161
         */
162
        MyItem(int style) {
163
                this.style = style;
164
        }
165

    
166
        public boolean equals(Object obj) {
167
                if (obj instanceof Integer) {
168
                        Integer integer = (Integer) obj;
169
                        return integer.intValue()==style;
170
                }
171

    
172
                if (obj instanceof MyItem) {
173
                        return ((MyItem) obj).style == style;
174

    
175
                }
176
                return super.equals(obj);
177
        }
178
}