Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / JUnitsComboBox.java @ 12906

History | View | Annotate | Download (3.85 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;
42

    
43
import com.iver.andami.PluginServices;
44
import com.iver.cit.gvsig.fmap.MapContext;
45
import com.iver.utiles.swing.JComboBox;
46

    
47
/**
48
 * <p>Class representing a JComboBox with the measure units handled by the application.
49
 * It takes values from Attributes.NAMES and Attributes.CHANGE static fields. So, to
50
 * add more measure units, you must edit Attributes class and change will be automatically
51
 * reflected in the combo box.</p>
52
 *
53
 * <p>The internatiolanization of the field is automatically handled by the system</p>
54
 * @author jaume dominguez faus - jaume.dominguez@iver.es
55
 */
56
public class JUnitsComboBox extends JComboBox {
57
        private static final long serialVersionUID = 8015263853737441433L;
58

    
59
        /**
60
         * Creates a new instance of JUnitComboBox including "pixel" units and
61
         * setting them as automatically pre-selected.
62
         */
63
        public JUnitsComboBox() {
64
                this(true);
65
        }
66

    
67
        /**
68
         *
69
         * Creates a new instance of JUnitComboBox. If includePixel is true
70
         * then pixel units are included in the list and they are automatically
71
         * pre-selected. Otherwise, meters are preselected.
72
         *
73
         */
74
        public JUnitsComboBox(boolean includePixel) {
75
                super();
76
                String[] units = new String[MapContext.NAMES.length];
77
                for (int i = 0; i < MapContext.NAMES.length; i++) {
78
                        units[i] = MapContext.NAMES[i];
79
                }
80

    
81
                for (int i = 0; i < units.length; i++) {
82
                        super.addItem(units[i]);
83
                }
84
                if (includePixel) {
85
                        super.addItem(PluginServices.getText(this, "pixels"));
86
                        setSelectedItem(PluginServices.getText(this, "pixels"));
87
                } else {
88
                        setSelectedIndex(1);
89
                }
90
                setMaximumRowCount(10);
91
        }
92

    
93

    
94
        /**
95
         * Returns the conversion factor from the <b>unit selected in the combo box</b>
96
         * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
97
         * @return
98
         */
99
        public double getUnitConversionFactor() {
100
                        double unitFactor;
101
                        try {
102
                                unitFactor = MapContext.CHANGEM[getSelectedIndex()];
103
                        } catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji
104
                                unitFactor = 0; // which represents size in pixel
105
                        }
106
                        return unitFactor;
107

    
108
        }
109

    
110
        /**
111
         * the use of this method is not allowed in this combo box.
112
         * @deprecated
113
         */
114
        public void addItem(Object anObject) {
115
                throw new Error("Operation not allowed");
116
        }
117

    
118
        /**
119
         * the use of this method is not allowed for this combo box.
120
         * @deprecated
121
         */
122
        public void removeAllItems() {
123
                throw new Error("Operation not allowed");
124
        }
125

    
126
        public int getSelectedUnitIndex() {
127
                int i = getSelectedIndex();
128
                if (i>MapContext.CHANGE.length-1)
129
                        return -1;
130
                else return i;
131
        }
132

    
133
        public void setSelectedUnitIndex(int unitIndex) {
134
                if (unitIndex == -1) {
135
                        setSelectedIndex(getItemCount()-1);
136
                } else {
137
                        setSelectedIndex(unitIndex);
138
                }
139
        }
140

    
141

    
142

    
143
}