svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / JComboBoxUnits.java @ 34002
History | View | Annotate | Download (3.81 KB)
1 | 18623 | jdominguez | /* 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 | 29598 | jpiera | package org.gvsig.app.gui; |
42 | 18623 | jdominguez | |
43 | 29598 | jpiera | import org.gvsig.andami.PluginServices; |
44 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
45 | 29598 | jpiera | import org.gvsig.utils.swing.JComboBox; |
46 | 20994 | jmvivo | |
47 | 18623 | jdominguez | |
48 | /**
|
||
49 | * <p>Class representing a JComboBox with the measure units handled by the application.
|
||
50 | * It takes values from Attributes.NAMES and Attributes.CHANGE static fields. So, to
|
||
51 | * add more measure units, you must edit Attributes class and change will be automatically
|
||
52 | * reflected in the combo box.</p>
|
||
53 | *
|
||
54 | * <p>The internatiolanization of the field is automatically handled by the system</p>
|
||
55 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
56 | */
|
||
57 | public class JComboBoxUnits extends JComboBox { |
||
58 | private static final long serialVersionUID = 8015263853737441433L; |
||
59 | |||
60 | /**
|
||
61 | * Creates a new instance of JUnitComboBox including "pixel" units and
|
||
62 | * setting them as automatically pre-selected.
|
||
63 | */
|
||
64 | public JComboBoxUnits() {
|
||
65 | this(true); |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | *
|
||
70 | * Creates a new instance of JUnitComboBox. If includePixel is true
|
||
71 | * then pixel units are included in the list and they are automatically
|
||
72 | * pre-selected. Otherwise, meters are preselected.
|
||
73 | *
|
||
74 | */
|
||
75 | public JComboBoxUnits(boolean includePixel) { |
||
76 | super();
|
||
77 | 20334 | vcaballero | String[] names=MapContext.getDistanceNames(); |
78 | 20345 | vcaballero | |
79 | 20334 | vcaballero | for (int i = 0; i < names.length; i++) { |
80 | 20345 | vcaballero | super.addItem(PluginServices.getText(this,names[i])); |
81 | 18623 | jdominguez | } |
82 | if (includePixel) {
|
||
83 | super.addItem(PluginServices.getText(this, "pixels")); |
||
84 | setSelectedItem(PluginServices.getText(this, "pixels")); |
||
85 | } else {
|
||
86 | setSelectedIndex(1);
|
||
87 | } |
||
88 | setMaximumRowCount(10);
|
||
89 | } |
||
90 | |||
91 | |||
92 | /**
|
||
93 | * Returns the conversion factor from the <b>unit selected in the combo box</b>
|
||
94 | * to <b>meters</b> or <b>0</b> if pixels have been selected as the size unit.
|
||
95 | * @return
|
||
96 | */
|
||
97 | public double getUnitConversionFactor() { |
||
98 | double unitFactor;
|
||
99 | try {
|
||
100 | 20334 | vcaballero | unitFactor = MapContext.getDistanceTrans2Meter()[getSelectedIndex()]; |
101 | 18623 | jdominguez | } catch (ArrayIndexOutOfBoundsException aioobEx) { //jijiji |
102 | unitFactor = 0; // which represents size in pixel |
||
103 | } |
||
104 | return unitFactor;
|
||
105 | |||
106 | } |
||
107 | |||
108 | /**
|
||
109 | * the use of this method is not allowed in this combo box.
|
||
110 | * @deprecated
|
||
111 | */
|
||
112 | public void addItem(Object anObject) { |
||
113 | throw new Error("Operation not allowed"); |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * the use of this method is not allowed for this combo box.
|
||
118 | * @deprecated
|
||
119 | */
|
||
120 | public void removeAllItems() { |
||
121 | throw new Error("Operation not allowed"); |
||
122 | } |
||
123 | |||
124 | public int getSelectedUnitIndex() { |
||
125 | int i = getSelectedIndex();
|
||
126 | 20334 | vcaballero | if (i>MapContext.getDistanceNames().length-1) |
127 | 18623 | jdominguez | return -1; |
128 | else return i; |
||
129 | } |
||
130 | |||
131 | public void setSelectedUnitIndex(int unitIndex) { |
||
132 | if (unitIndex == -1) { |
||
133 | setSelectedIndex(getItemCount()-1);
|
||
134 | } else {
|
||
135 | setSelectedIndex(unitIndex); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | |||
140 | |||
141 | } |