Statistics
| Revision:

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

History | View | Annotate | Download (3.27 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 java.util.Vector;
44

    
45
import javax.swing.ComboBoxModel;
46

    
47
import com.iver.andami.PluginServices;
48
import com.iver.cit.gvsig.project.documents.layout.Attributes;
49
import com.iver.utiles.swing.JComboBox;
50

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

    
63
        /**
64
         * Creates a new instance of JUnitComboBox leaving "pixel" units automatically
65
         * pre-selected.
66
         */
67
        public JUnitsComboBox() {
68
                super();
69
                String[] units = new String[Attributes.NAMES.length+1];
70
                for (int i = 0; i < Attributes.NAMES.length; i++) {
71
                        units[i] = PluginServices.getText(this, Attributes.NAMES[i]);
72
                }
73
                units[units.length-1] = PluginServices.getText(this, "pixels");
74

    
75
                for (int i = 0; i < units.length; i++) {
76
                        super.addItem(units[i]);
77
                }
78
                setSelectedIndex(units.length-1);
79

    
80
        }
81

    
82
        /**
83
         * Returns the conversion factor from the <b>unit selected in the combo box</b>
84
         * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
85
         * @return
86
         */
87
        public double getUnitConversionFactor() {
88
                        double unitFactor;
89
                        try {
90
                                unitFactor = Attributes.CHANGE[getSelectedIndex()]/100;
91
                        } catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji
92
                                unitFactor = 0; // which represents size in pixel
93
                        }
94
                        return unitFactor;
95

    
96
        }
97

    
98
        /**
99
         * the use of this method is not allowed in this combo box.
100
         * @deprecated
101
         */
102
        public void addItem(Object anObject) {
103
                throw new Error("Operation not allowed");
104
        }
105

    
106
        /**
107
         * the use of this method is not allowed for this combo box.
108
         * @deprecated
109
         */
110
        public void removeAllItems() {
111
                throw new Error("Operation not allowed");
112
        }
113

    
114
}