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 / JComboBoxSimpleMarkeStyles.java @ 40560

History | View | Annotate | Download (4.68 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.Color;
27
import java.awt.Component;
28
import java.awt.Dimension;
29

    
30
import javax.swing.JComboBox;
31
import javax.swing.JList;
32
import javax.swing.ListCellRenderer;
33
import javax.swing.UIManager;
34

    
35
import org.gvsig.symbology.SymbologyLocator;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol;
38

    
39

    
40
/**
41
 * JComboBox used by the user to select the different styles of simple marker symbols.
42
 * The available options are: circle style,square style,cross style, diamond style,x style
43
 * and triangle style.
44
 *
45
 * @author jaume dominguez faus - jaume.dominguez@iver.es
46
 */
47
public class JComboBoxSimpleMarkeStyles extends JComboBox{
48
        /**
49
         * 
50
         */
51
        private static final long serialVersionUID = 3018193423738880772L;
52
        private Color symColor = Color.BLACK;
53
        private Color outlineColor = Color.BLACK;
54
        private boolean outlined = false;
55
        static MyItem[] pointTypes = new MyItem[] {
56
                new MyItem(IMarkerSymbol.CIRCLE_STYLE),
57
                new MyItem(IMarkerSymbol.SQUARE_STYLE),
58
                new MyItem(IMarkerSymbol.CROSS_STYLE),
59
                new MyItem(IMarkerSymbol.DIAMOND_STYLE),
60
                new MyItem(IMarkerSymbol.X_STYLE),
61
                new MyItem(IMarkerSymbol.TRIANGLE_STYLE),
62
                new MyItem(IMarkerSymbol.STAR_STYLE),
63
        };
64

    
65
        /**
66
         * Constructor method
67
         *
68
         */
69

    
70
        public JComboBoxSimpleMarkeStyles() {
71
                super();
72
                removeAllItems();
73
                for (int i = 0; i < pointTypes.length; i++) {
74
                        addItem(pointTypes[i]);
75
                }
76

    
77
                setEditable(false);
78
                setRenderer(new ListCellRenderer() {
79

    
80
                        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
81
                                SymbolPreviewer preview = new SymbolPreviewer() ;
82
                                ISimpleMarkerSymbol mySymbol = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol();
83
                                mySymbol.setColor(symColor);
84
                                mySymbol.setOutlined(outlined);
85
                                mySymbol.setOutlineColor(outlineColor);
86
                                if (value instanceof MyItem) {
87
                                        mySymbol.setStyle(((MyItem) value).style);
88
                                } else {
89
                                        mySymbol.setStyle(((Integer) value).intValue());
90
                                }
91

    
92
                                mySymbol.setUnit(-1); // pixel
93
                                mySymbol.setSize(10);
94
                                preview.setForeground(UIManager.getColor(isSelected
95
                                                ? "ComboBox.selectionForeground"
96
                                                                : "ComboBox.foreground"));
97
                                preview.setBackground(UIManager.getColor(isSelected
98
                                                ? "ComboBox.selectionBackground"
99
                                                                : "ComboBox.background"));
100
                                preview.setSymbol(mySymbol);
101
                                preview.setSize(preview.getWidth(), 20);
102
                                preview.setPreferredSize(new Dimension(preview.getWidth(), 20));
103
                                return preview;
104
                        }
105
                });
106
        }
107

    
108
        /**
109
         * Establishes the color of the simple marker symbol.
110
         * @param c,Color
111
         */
112
        public void setSymbolColor(Color c) {
113
                this.symColor = c;
114
        }
115

    
116
        /**
117
         * Sets the color for the outline of the simple marker symbol
118
         * @param c,Color
119
         */
120
        public void setOutlineColor(Color c) {
121
                outlined = c!=null;
122
                outlineColor = c;
123
        }
124

    
125
        public Object getSelectedItem() {
126
                return new Integer(((MyItem) super.getSelectedItem()).style);
127
        }
128

    
129
        public void setSelectedItem(Object item) {
130
                if (item instanceof Integer) {
131
                        int myItem = ((Integer) item).intValue();
132
                        for (int i = 0; i < pointTypes.length; i++) {
133
                                if (myItem == pointTypes[i].style)
134
                                        setSelectedIndex(i);
135
                        }
136
                }
137
                super.setSelectedItem(item);
138
        }
139
}
140
/**
141
 * Used to store the different options that the JComboBoxsimplemarkerStyles shows to
142
 * the user.
143
 *
144
 */
145
class MyItem {
146
        int style;
147

    
148
        /**
149
         * Constructor method
150
         * @param style
151
         */
152
        MyItem(int style) {
153
                this.style = style;
154
        }
155

    
156
        public boolean equals(Object obj) {
157
                if (obj instanceof Integer) {
158
                        Integer integer = (Integer) obj;
159
                        return integer.intValue()==style;
160
                }
161

    
162
                if (obj instanceof MyItem) {
163
                        return ((MyItem) obj).style == style;
164

    
165
                }
166
                return super.equals(obj);
167
        }
168
}