Statistics
| Revision:

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

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