Statistics
| Revision:

root / trunk / libraries / libUI / src / org / gvsig / gui / beans / AcceptCancelPanel.java @ 8514

History | View | Annotate | Download (5.75 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

    
42
/* CVS MESSAGES:
43
*
44
* $Id: AcceptCancelPanel.java 8514 2006-11-06 07:29:04Z jaume $
45
* $Log$
46
* Revision 1.5  2006-11-06 07:29:04  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.4  2006/09/14 08:31:58  cesar
50
* Replace PluginServices.getText by the new Messages bridge class from libUI
51
*
52
* Revision 1.3.2.1  2006/09/13 13:13:19  cesar
53
* Replace PluginServices.getText by the new Messages bridge class from libUI
54
*
55
* Revision 1.3  2006/07/20 11:12:25  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.2  2006/07/20 10:42:37  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1  2006/07/03 07:12:28  jaume
62
* *** empty log message ***
63
*
64
*
65
*/
66
package org.gvsig.gui.beans;
67

    
68
import java.awt.BorderLayout;
69
import java.awt.event.ActionListener;
70

    
71
import javax.swing.JPanel;
72

    
73
import org.gvsig.gui.beans.swing.JButton;
74

    
75
/**
76
 * A JPanel representing a normative sized and aligned Ok and Cancel buttons according
77
 * on the gvSIG's style sheet. The buttons size is automatically handled as far as the
78
 * panel is BorderLayout-ed.
79
 *
80
 * @author jaume dominguez faus - jaume.dominguez@iver.es
81
 *
82
 */
83
public class AcceptCancelPanel extends JPanel {
84

    
85
        private JButton btnOk = null;
86
        private JButton btnCancel = null;
87

    
88
        /**
89
         * Creates a new instance of the panel with the buttons aligned to the right
90
         * and with the respective action handlers.
91
         * @param okAction, the handler for the ok button clicking.
92
         * @param cancelAction, the handler for the cancel button clicking.
93
         *
94
         */
95
        public AcceptCancelPanel(ActionListener okAction, ActionListener cancelAction) {
96
                super();
97
                initialize(okAction, cancelAction);
98
        }
99
        /**
100
         * Creates a new instance of the panel with the buttons aligned to the right
101
         * with no listeners set.
102
         *
103
         */
104
        public AcceptCancelPanel() {
105
                super();
106
                initialize(null, null);
107
        }
108
        /**
109
         * This method initializes this
110
         *
111
         */
112
        private void initialize(ActionListener okAction, ActionListener cancelAction) {
113
        this.setLayout(new BorderLayout());
114
        JPanel aux = new JPanel();
115
        aux.add(getBtnOk(okAction), java.awt.BorderLayout.EAST);
116
        aux.add(getCancelButton(cancelAction), java.awt.BorderLayout.EAST);
117
        this.add(aux, java.awt.BorderLayout.EAST);
118
        }
119

    
120
        /**
121
         * This method initializes btnOk
122
         *
123
         * @return javax.swing.JButton
124
         */
125
        private JButton getBtnOk(ActionListener okAction) {
126
                if (btnOk == null) {
127
                        btnOk = new JButton();
128
                        btnOk.setText(Messages.getText("ok" ));
129
                        btnOk.setActionCommand("OK");
130
                        if (okAction != null)
131
                                btnOk.addActionListener(okAction);
132
                }
133
                return btnOk;
134
        }
135

    
136
        /**
137
         * This method initializes btnCancel
138
         *
139
         * @return javax.swing.JButton
140
         */
141
        private JButton getCancelButton(ActionListener cancelAction) {
142
                if (btnCancel == null) {
143
                        btnCancel = new JButton();
144
                        btnCancel.setText(Messages.getText("cancel" ));
145
                        btnCancel.setActionCommand("CANCEL");
146
                        if (cancelAction != null)
147
                                btnCancel.addActionListener(cancelAction);
148
                }
149
                return btnCancel;
150
        }
151

    
152
        /**
153
         * Adds an ActionListener to the <b>cancel</b> button.
154
         * @param l
155
         */
156
        public void addCancelButtonActionListener(ActionListener l) {
157
                btnCancel.addActionListener(l);
158
        }
159

    
160
        /**
161
         * Sets the ActionListener to the <b>OK</b> button removing any other previous one.
162
         * @param l
163
         */
164
        public void setOkButtonActionListener(ActionListener l) {
165
                ActionListener[] listeners = btnOk.getActionListeners();
166
                for (int i = 0; i < listeners.length; i++) {
167
                        btnOk.removeActionListener(listeners[i]);
168
                }
169
                btnOk.addActionListener(l);
170
        }
171

    
172
        /**
173
         * Sets the ActionListener to the <b>cancel</b> button removing any other previous one.
174
         * @param l
175
         */
176
        public void setCancelButtonActionListener(ActionListener l) {
177
                ActionListener[] listeners = btnCancel.getActionListeners();
178
                for (int i = 0; i < listeners.length; i++) {
179
                        btnCancel.removeActionListener(listeners[i]);
180
                }
181
                btnCancel.addActionListener(l);
182
        }
183

    
184
        /**
185
         * Adds an ActionListener to the <b>OK</b> button.
186
         * @param l
187
         */
188
        public void addOkButtonActionListener(ActionListener l) {
189
                btnOk.addActionListener(l);
190
        }
191

    
192
        /**
193
         * Returns the ok button contained by this panel since resizing issues should be
194
         * automatically handled by the layout manager. The use of this method is discouraged,
195
         * it is keeped only for compatibility issues. Try using specific button properties
196
         * access methods contained by this class instead.
197
         * @return the Ok button
198
         * @deprecated
199
         */
200
        public JButton getOkButton() {
201
                return btnOk;
202
        }
203

    
204
        public boolean isOkButtonEnabled() {
205
                return btnOk.isEnabled();
206
        }
207

    
208
        public boolean isCancelButtonEnabled() {
209
                return btnCancel.isEnabled();
210
        }
211

    
212
        public void setOkButtonEnabled(boolean b) {
213
                btnOk.setEnabled(b);
214
        }
215

    
216
        public void setCancelButtonEnabled(boolean b) {
217
                btnCancel.setEnabled(b);
218
        }
219
}