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