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