Revision 11439
trunk/libraries/libUI/src/org/gvsig/gui/beans/swing/JFontSizeComboBox.java | ||
---|---|---|
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 org.gvsig.gui.beans.swing; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
import java.util.ArrayList; |
|
45 |
|
|
46 |
import javax.swing.DefaultComboBoxModel; |
|
47 |
import javax.swing.JComboBox; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
51 |
*/ |
|
52 |
public class JFontSizeComboBox extends JComboBox { |
|
53 |
private static ArrayList sizes; |
|
54 |
private static float DEFAULT_FONT_SIZE = 10; |
|
55 |
public JFontSizeComboBox() { |
|
56 |
super(); |
|
57 |
if (sizes == null) { |
|
58 |
sizes = new ArrayList(); |
|
59 |
sizes.add(new Integer(5)); |
|
60 |
sizes.add(new Integer(6)); |
|
61 |
sizes.add(new Integer(7)); |
|
62 |
sizes.add(new Integer(8)); |
|
63 |
sizes.add(new Integer(9)); |
|
64 |
sizes.add(new Integer(10)); |
|
65 |
sizes.add(new Integer(11)); |
|
66 |
sizes.add(new Integer(12)); |
|
67 |
sizes.add(new Integer(13)); |
|
68 |
sizes.add(new Integer(14)); |
|
69 |
sizes.add(new Integer(16)); |
|
70 |
sizes.add(new Integer(18)); |
|
71 |
sizes.add(new Integer(20)); |
|
72 |
sizes.add(new Integer(22)); |
|
73 |
sizes.add(new Integer(24)); |
|
74 |
sizes.add(new Integer(28)); |
|
75 |
sizes.add(new Integer(36)); |
|
76 |
sizes.add(new Integer(48)); |
|
77 |
sizes.add(new Integer(72)); |
|
78 |
} |
|
79 |
|
|
80 |
setModel(new DefaultComboBoxModel((Integer[]) sizes.toArray(new Integer[sizes.size()]))); |
|
81 |
setSelectedIndex(7); |
|
82 |
setEditable(true); |
|
83 |
setPreferredSize(new Dimension(30, 20)); |
|
84 |
} |
|
85 |
|
|
86 |
public float getSelectedValue() { |
|
87 |
Object v = getSelectedItem(); |
|
88 |
if (v instanceof Integer) { |
|
89 |
return ((Integer) v).floatValue(); |
|
90 |
} |
|
91 |
if (v instanceof String) { |
|
92 |
try{ |
|
93 |
return Float.parseFloat((String) v); |
|
94 |
} catch (Exception e) { |
|
95 |
return DEFAULT_FONT_SIZE; |
|
96 |
} |
|
97 |
} |
|
98 |
if (v instanceof Double || v instanceof Float) { |
|
99 |
return ((Double) v).floatValue(); |
|
100 |
} |
|
101 |
return DEFAULT_FONT_SIZE; |
|
102 |
} |
|
103 |
|
|
104 |
public void setSelectedItem(Object anObject) { |
|
105 |
if (anObject instanceof Double || anObject instanceof Float) { |
|
106 |
if (((Double) anObject).doubleValue() == 10) { |
|
107 |
super.setSelectedItem(new Integer(10)); |
|
108 |
return; |
|
109 |
} |
|
110 |
super.setSelectedItem(anObject); |
|
111 |
} else if (anObject instanceof String) { |
|
112 |
setSelectedItem( new Double((String)anObject)); |
|
113 |
} else { |
|
114 |
super.setSelectedItem(anObject); |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
0 | 118 |
Also available in: Unified diff