Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / AcceptCancelPanel.java @ 13136

History | View | Annotate | Download (5.84 KB)

1 13136 evercher
/* 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$
45
* $Log$
46
* Revision 1.1  2007-08-20 08:34:45  evercher
47
* He fusionado LibUI con LibUIComponents
48
*
49
* Revision 1.5  2006/11/06 07:29:04  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.4  2006/09/14 08:31:58  cesar
53
* Replace PluginServices.getText by the new Messages bridge class from libUI
54
*
55
* Revision 1.3.2.1  2006/09/13 13:13:19  cesar
56
* Replace PluginServices.getText by the new Messages bridge class from libUI
57
*
58
* Revision 1.3  2006/07/20 11:12:25  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.2  2006/07/20 10:42:37  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.1  2006/07/03 07:12:28  jaume
65
* *** empty log message ***
66
*
67
*
68
*/
69
package org.gvsig.gui.beans;
70
71
import java.awt.BorderLayout;
72
import java.awt.event.ActionListener;
73
74
import javax.swing.JPanel;
75
76
import org.gvsig.gui.beans.swing.JButton;
77
78
/**
79
 * A JPanel representing a normative sized and aligned Ok and Cancel buttons according
80
 * on the gvSIG's style sheet. The buttons size is automatically handled as far as the
81
 * panel is BorderLayout-ed.
82
 *
83
 * @author jaume dominguez faus - jaume.dominguez@iver.es
84
 *
85
 */
86
public class AcceptCancelPanel extends JPanel {
87
88
        private JButton btnOk = null;
89
        private JButton btnCancel = null;
90
91
        /**
92
         * Creates a new instance of the panel with the buttons aligned to the right
93
         * and with the respective action handlers.
94
         * @param okAction, the handler for the ok button clicking.
95
         * @param cancelAction, the handler for the cancel button clicking.
96
         *
97
         */
98
        public AcceptCancelPanel(ActionListener okAction, ActionListener cancelAction) {
99
                super();
100
                initialize(okAction, cancelAction);
101
        }
102
        /**
103
         * Creates a new instance of the panel with the buttons aligned to the right
104
         * with no listeners set.
105
         *
106
         */
107
        public AcceptCancelPanel() {
108
                super();
109
                initialize(null, null);
110
        }
111
        /**
112
         * This method initializes this
113
         *
114
         */
115
        private void initialize(ActionListener okAction, ActionListener cancelAction) {
116
        this.setLayout(new BorderLayout());
117
        JPanel aux = new JPanel();
118
        aux.add(getBtnOk(okAction), java.awt.BorderLayout.EAST);
119
        aux.add(getCancelButton(cancelAction), java.awt.BorderLayout.EAST);
120
        this.add(aux, java.awt.BorderLayout.EAST);
121
        }
122
123
        /**
124
         * This method initializes btnOk
125
         *
126
         * @return javax.swing.JButton
127
         */
128
        private JButton getBtnOk(ActionListener okAction) {
129
                if (btnOk == null) {
130
                        btnOk = new JButton();
131
                        btnOk.setText(Messages.getText("ok" ));
132
                        btnOk.setActionCommand("OK");
133
                        if (okAction != null)
134
                                btnOk.addActionListener(okAction);
135
                }
136
                return btnOk;
137
        }
138
139
        /**
140
         * This method initializes btnCancel
141
         *
142
         * @return javax.swing.JButton
143
         */
144
        private JButton getCancelButton(ActionListener cancelAction) {
145
                if (btnCancel == null) {
146
                        btnCancel = new JButton();
147
                        btnCancel.setText(Messages.getText("cancel" ));
148
                        btnCancel.setActionCommand("CANCEL");
149
                        if (cancelAction != null)
150
                                btnCancel.addActionListener(cancelAction);
151
                }
152
                return btnCancel;
153
        }
154
155
        /**
156
         * Adds an ActionListener to the <b>cancel</b> button.
157
         * @param l
158
         */
159
        public void addCancelButtonActionListener(ActionListener l) {
160
                btnCancel.addActionListener(l);
161
        }
162
163
        /**
164
         * Sets the ActionListener to the <b>OK</b> button removing any other previous one.
165
         * @param l
166
         */
167
        public void setOkButtonActionListener(ActionListener l) {
168
                ActionListener[] listeners = btnOk.getActionListeners();
169
                for (int i = 0; i < listeners.length; i++) {
170
                        btnOk.removeActionListener(listeners[i]);
171
                }
172
                btnOk.addActionListener(l);
173
        }
174
175
        /**
176
         * Sets the ActionListener to the <b>cancel</b> button removing any other previous one.
177
         * @param l
178
         */
179
        public void setCancelButtonActionListener(ActionListener l) {
180
                ActionListener[] listeners = btnCancel.getActionListeners();
181
                for (int i = 0; i < listeners.length; i++) {
182
                        btnCancel.removeActionListener(listeners[i]);
183
                }
184
                btnCancel.addActionListener(l);
185
        }
186
187
        /**
188
         * Adds an ActionListener to the <b>OK</b> button.
189
         * @param l
190
         */
191
        public void addOkButtonActionListener(ActionListener l) {
192
                btnOk.addActionListener(l);
193
        }
194
195
        /**
196
         * Returns the ok button contained by this panel since resizing issues should be
197
         * automatically handled by the layout manager. The use of this method is discouraged,
198
         * it is keeped only for compatibility issues. Try using specific button properties
199
         * access methods contained by this class instead.
200
         * @return the Ok button
201
         * @deprecated
202
         */
203
        public JButton getOkButton() {
204
                return btnOk;
205
        }
206
207
        public boolean isOkButtonEnabled() {
208
                return btnOk.isEnabled();
209
        }
210
211
        public boolean isCancelButtonEnabled() {
212
                return btnCancel.isEnabled();
213
        }
214
215
        public void setOkButtonEnabled(boolean b) {
216
                btnOk.setEnabled(b);
217
        }
218
219
        public void setCancelButtonEnabled(boolean b) {
220
                btnCancel.setEnabled(b);
221
        }
222
}