root / branches / v10 / libraries / libUI / src / org / gvsig / gui / beans / AcceptCancelPanel.java @ 10564
History | View | Annotate | Download (5.98 KB)
1 | 6140 | jaume | /* 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 | 9037 | ppiqueras | * Revision 1.3.2.4 2006-11-28 09:47:16 ppiqueras
|
47 | * Actualizaci?n desde HEAD a v10 de libUI fruto de cambio de dependencia de libUI con el proyecto _fwAndami. (cambiado PluginServices.getText(..., ...) por Messages.getText(...)
|
||
48 | 8765 | jjdelcerro | *
|
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 | 7244 | cesar | * Replace PluginServices.getText by the new Messages bridge class from libUI
|
54 | *
|
||
55 | 8765 | jjdelcerro | * 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 | 7244 | cesar | * Revision 1.3 2006/07/20 11:12:25 jaume
|
59 | 6140 | jaume | * *** empty log message ***
|
60 | *
|
||
61 | 6460 | jaume | * Revision 1.2 2006/07/20 10:42:37 jaume
|
62 | * *** empty log message ***
|
||
63 | *
|
||
64 | 6455 | jaume | * Revision 1.1 2006/07/03 07:12:28 jaume
|
65 | * *** empty log message ***
|
||
66 | 6140 | jaume | *
|
67 | 6455 | jaume | *
|
68 | 6140 | jaume | */
|
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 | 6455 | jaume | * 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 | 6140 | jaume | * 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 | 6460 | jaume | aux.add(getBtnOk(okAction), java.awt.BorderLayout.EAST); |
119 | aux.add(getCancelButton(cancelAction), java.awt.BorderLayout.EAST); |
||
120 | 6140 | jaume | 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 | 7244 | cesar | btnOk.setText(Messages.getText("ok" ));
|
132 | 8765 | jjdelcerro | btnOk.setActionCommand("OK");
|
133 | 6460 | jaume | if (okAction != null) |
134 | btnOk.addActionListener(okAction); |
||
135 | 6140 | jaume | } |
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 | 7244 | cesar | btnCancel.setText(Messages.getText("cancel" ));
|
148 | 8765 | jjdelcerro | btnCancel.setActionCommand("CANCEL");
|
149 | 6460 | jaume | if (cancelAction != null) |
150 | btnCancel.addActionListener(cancelAction); |
||
151 | 6140 | jaume | } |
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 | 6460 | jaume | * 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 | 6140 | jaume | * 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 | } |