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