Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / swing / JComboBoxFontSizes.java @ 40561

History | View | Annotate | Download (3.44 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.gui.beans.swing;
25

    
26
import java.awt.Dimension;
27
import java.util.ArrayList;
28

    
29
import javax.swing.DefaultComboBoxModel;
30
import javax.swing.JComboBox;
31

    
32
/**
33
 * @author jaume dominguez faus - jaume.dominguez@iver.es
34
 */
35
public class JComboBoxFontSizes extends JComboBox {
36
  private static final long serialVersionUID = 3256519971028107511L;
37
                private static ArrayList sizes;
38
    private static float DEFAULT_FONT_SIZE = 10;
39
    public JComboBoxFontSizes() {
40
        super();
41
        if (sizes == null) {
42
            sizes = new ArrayList();
43
            sizes.add(new Integer(5));
44
            sizes.add(new Integer(6));
45
            sizes.add(new Integer(7));
46
            sizes.add(new Integer(8));
47
            sizes.add(new Integer(9));
48
            sizes.add(new Integer(10));
49
            sizes.add(new Integer(11));
50
            sizes.add(new Integer(12));
51
            sizes.add(new Integer(13));
52
            sizes.add(new Integer(14));
53
            sizes.add(new Integer(16));
54
            sizes.add(new Integer(18));
55
            sizes.add(new Integer(20));
56
            sizes.add(new Integer(22));
57
            sizes.add(new Integer(24));
58
            sizes.add(new Integer(28));
59
            sizes.add(new Integer(36));
60
            sizes.add(new Integer(48));
61
            sizes.add(new Integer(72));
62
        }
63

    
64
        setModel(new DefaultComboBoxModel((Integer[]) sizes.toArray(new Integer[sizes.size()])));
65
        setSelectedIndex(7);
66
        setEditable(true);
67
        setPreferredSize(new Dimension(50, 20));
68
    }
69

    
70
    public float getSelectedValue() {
71
        Object v = getSelectedItem();
72
        if (v instanceof Integer) {
73
            return ((Integer) v).floatValue();
74
        }
75
        if (v instanceof String) {
76
            try{
77
                return Float.parseFloat((String) v);
78
            } catch (Exception e) {
79
                return DEFAULT_FONT_SIZE;
80
            }
81
        }
82
        if (v instanceof Double || v instanceof Float) {
83
            return ((Double) v).floatValue();
84
        }
85
        return DEFAULT_FONT_SIZE;
86
    }
87

    
88
    public void setSelectedItem(Object anObject) {
89
             if (anObject instanceof Double || anObject instanceof Float) {
90
              if (((Double) anObject).doubleValue() == 10) {
91
                      super.setSelectedItem(new Integer(10));
92
                      return;
93
              }
94
              super.setSelectedItem(anObject);
95
         } else if (anObject instanceof String) {
96
                 setSelectedItem( new Double((String)anObject));
97
         } else {
98
                 super.setSelectedItem(anObject);
99
         }
100
    }
101
}