Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.algorithm / org.gvsig.raster.tools.algorithm.swing / org.gvsig.raster.tools.algorithm.swing.impl / src / main / java / org / gvsig / raster / tools / algorithm / swing / impl / bean / combotext / ComboTextImpl.java @ 1310

History | View | Annotate | Download (3.83 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22
package org.gvsig.raster.tools.algorithm.swing.impl.bean.combotext;
23

    
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29

    
30
import javax.swing.BorderFactory;
31
import javax.swing.JComboBox;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.JTextField;
35

    
36
import org.gvsig.raster.swing.listener.PanelChangeEvent;
37
import org.gvsig.raster.swing.listener.PanelChangeListener;
38

    
39
/**
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class ComboTextImpl extends JPanel implements ActionListener {
43
        private static final long   serialVersionUID    = 1L;
44
        private JComboBox           combo               = null;
45
        private JTextField          jtext               = null;
46
        private JLabel              label               = null;
47
        private String              boxLabel            = null;
48
        private boolean             borderEnabled       = false;
49
        private boolean             labelsEnabled       = false;
50
        private PanelChangeListener listener            = null;
51
        
52
        public ComboTextImpl(String[] labels, boolean border, boolean labelEnabled) {
53
                if(labels != null) {
54
                        label = new JLabel(labels[0]);
55
                        boxLabel = labels[1];
56
                }
57
                this.borderEnabled = border;
58
                this.labelsEnabled = labelEnabled;
59
                init();
60
        }
61
        
62
        private void init() {
63
                this.setLayout(new GridBagLayout());
64
                if(borderEnabled)
65
                        setBorder(BorderFactory.createTitledBorder(boxLabel));
66
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
67
                
68
                int x = 0;
69
                
70
                if(labelsEnabled) {
71
                        gridBagConstraints1.fill = java.awt.GridBagConstraints.NONE;
72
                        gridBagConstraints1.gridx = x;
73
                        this.add(label, gridBagConstraints1);
74
                        x++;
75
                }
76
                
77
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
78
                gridBagConstraints1.weightx = 1;
79

    
80
                gridBagConstraints1.gridx = x;
81
                this.add(getCombo(), gridBagConstraints1);
82
                x++;
83
                
84
                gridBagConstraints1.fill = java.awt.GridBagConstraints.NONE;
85
                gridBagConstraints1.weightx = 0;
86
                gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
87

    
88
                gridBagConstraints1.gridx = x;
89
                this.add(getTextField(), gridBagConstraints1);        
90
        }
91
        
92
        public JComboBox getCombo() {
93
                if(combo == null) {
94
                        combo = new JComboBox();
95
                        combo.addActionListener(this);
96
                }
97
                return combo;
98
        }
99

    
100
        public JTextField getTextField() {
101
                if(jtext == null) {
102
                        jtext = new JTextField();
103
                        jtext.addActionListener(this);
104
                        jtext.setEditable(true);
105
                        jtext.setPreferredSize(new Dimension(60, 24));
106
                        jtext.setSize(new Dimension(60, 24));
107
                        jtext.setMinimumSize(new Dimension(60, 24));
108
                        jtext.setMaximumSize(new Dimension(60, 24));
109
                }
110
                return jtext;
111
        }
112
        
113
        public void addPanelChangeEvent(PanelChangeListener listener) {
114
                this.listener = listener;
115
        }
116

    
117
        public void setEnabled(boolean enable) {
118
                getTextField().setEnabled(enable);
119
                getCombo().setEnabled(enable);
120
        }
121

    
122
        public void actionPerformed(ActionEvent e) {
123
                if(listener != null)
124
                        listener.panelHasChanged(new PanelChangeEvent(e));
125
        }
126
}