svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / AcceptCancelPanel.java @ 42246
History | View | Annotate | Download (5.78 KB)
1 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40561 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40561 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40561 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40561 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: AcceptCancelPanel.java 39402 2012-12-10 08:06:54Z nbrodin $
|
||
27 | * $Log$
|
||
28 | * Revision 1.2 2007-09-12 16:28:23 bsanchez
|
||
29 | * *** empty log message ***
|
||
30 | *
|
||
31 | * Revision 1.1 2007/08/20 08:34:45 evercher
|
||
32 | * He fusionado LibUI con LibUIComponents
|
||
33 | *
|
||
34 | * Revision 1.5 2006/11/06 07:29:04 jaume
|
||
35 | * *** empty log message ***
|
||
36 | *
|
||
37 | * Revision 1.4 2006/09/14 08:31:58 cesar
|
||
38 | * Replace PluginServices.getText by the new Messages bridge class from libUI
|
||
39 | *
|
||
40 | * Revision 1.3.2.1 2006/09/13 13:13:19 cesar
|
||
41 | * Replace PluginServices.getText by the new Messages bridge class from libUI
|
||
42 | *
|
||
43 | * Revision 1.3 2006/07/20 11:12:25 jaume
|
||
44 | * *** empty log message ***
|
||
45 | *
|
||
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.JButton; |
||
60 | import javax.swing.JPanel; |
||
61 | |||
62 | /**
|
||
63 | * A JPanel representing a normative sized and aligned Ok and Cancel buttons according
|
||
64 | * on the gvSIG's style sheet. The buttons size is automatically handled as far as the
|
||
65 | * panel is BorderLayout-ed.
|
||
66 | *
|
||
67 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
68 | *
|
||
69 | */
|
||
70 | public class AcceptCancelPanel extends JPanel { |
||
71 | private static final long serialVersionUID = -1834568346328338410L; |
||
72 | |||
73 | private JButton btnOk = null; |
||
74 | private JButton btnCancel = null; |
||
75 | |||
76 | /**
|
||
77 | * Creates a new instance of the panel with the buttons aligned to the right
|
||
78 | * and with the respective action handlers.
|
||
79 | * @param okAction, the handler for the ok button clicking.
|
||
80 | * @param cancelAction, the handler for the cancel button clicking.
|
||
81 | *
|
||
82 | */
|
||
83 | public AcceptCancelPanel(ActionListener okAction, ActionListener cancelAction) { |
||
84 | super();
|
||
85 | initialize(okAction, cancelAction); |
||
86 | } |
||
87 | /**
|
||
88 | * Creates a new instance of the panel with the buttons aligned to the right
|
||
89 | * with no listeners set.
|
||
90 | *
|
||
91 | */
|
||
92 | public AcceptCancelPanel() {
|
||
93 | super();
|
||
94 | initialize(null, null); |
||
95 | } |
||
96 | /**
|
||
97 | * This method initializes this
|
||
98 | *
|
||
99 | */
|
||
100 | private void initialize(ActionListener okAction, ActionListener cancelAction) { |
||
101 | this.setLayout(new BorderLayout()); |
||
102 | JPanel aux = new JPanel(); |
||
103 | aux.add(getBtnOk(okAction), java.awt.BorderLayout.EAST); |
||
104 | aux.add(getCancelButton(cancelAction), java.awt.BorderLayout.EAST); |
||
105 | this.add(aux, java.awt.BorderLayout.EAST);
|
||
106 | } |
||
107 | |||
108 | /**
|
||
109 | * This method initializes btnOk
|
||
110 | *
|
||
111 | * @return javax.swing.JButton
|
||
112 | */
|
||
113 | private JButton getBtnOk(ActionListener okAction) { |
||
114 | if (btnOk == null) { |
||
115 | btnOk = new JButton(); |
||
116 | 42246 | mcompany | btnOk.setText(Messages.getText("aceptar"));
|
117 | 40435 | jjdelcerro | btnOk.setActionCommand("OK");
|
118 | if (okAction != null) |
||
119 | btnOk.addActionListener(okAction); |
||
120 | } |
||
121 | return btnOk;
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * This method initializes btnCancel
|
||
126 | *
|
||
127 | * @return javax.swing.JButton
|
||
128 | */
|
||
129 | private JButton getCancelButton(ActionListener cancelAction) { |
||
130 | if (btnCancel == null) { |
||
131 | btnCancel = new JButton(); |
||
132 | 42246 | mcompany | btnCancel.setText(Messages.getText("cancel"));
|
133 | 40435 | jjdelcerro | btnCancel.setActionCommand("CANCEL");
|
134 | if (cancelAction != null) |
||
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 | * Sets the ActionListener to the <b>OK</b> button removing any other previous one.
|
||
150 | * @param l
|
||
151 | */
|
||
152 | public void setOkButtonActionListener(ActionListener l) { |
||
153 | ActionListener[] listeners = btnOk.getActionListeners(); |
||
154 | for (int i = 0; i < listeners.length; i++) { |
||
155 | btnOk.removeActionListener(listeners[i]); |
||
156 | } |
||
157 | btnOk.addActionListener(l); |
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * Sets the ActionListener to the <b>cancel</b> button removing any other previous one.
|
||
162 | * @param l
|
||
163 | */
|
||
164 | public void setCancelButtonActionListener(ActionListener l) { |
||
165 | ActionListener[] listeners = btnCancel.getActionListeners(); |
||
166 | for (int i = 0; i < listeners.length; i++) { |
||
167 | btnCancel.removeActionListener(listeners[i]); |
||
168 | } |
||
169 | btnCancel.addActionListener(l); |
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * Adds an ActionListener to the <b>OK</b> button.
|
||
174 | * @param l
|
||
175 | */
|
||
176 | public void addOkButtonActionListener(ActionListener l) { |
||
177 | btnOk.addActionListener(l); |
||
178 | } |
||
179 | |||
180 | /**
|
||
181 | * Returns the ok button contained by this panel since resizing issues should be
|
||
182 | * automatically handled by the layout manager. The use of this method is discouraged,
|
||
183 | * it is keeped only for compatibility issues. Try using specific button properties
|
||
184 | * access methods contained by this class instead.
|
||
185 | * @return the Ok button
|
||
186 | * @deprecated
|
||
187 | */
|
||
188 | public JButton getOkButton() { |
||
189 | return btnOk;
|
||
190 | } |
||
191 | |||
192 | public boolean isOkButtonEnabled() { |
||
193 | return btnOk.isEnabled();
|
||
194 | } |
||
195 | |||
196 | public boolean isCancelButtonEnabled() { |
||
197 | return btnCancel.isEnabled();
|
||
198 | } |
||
199 | |||
200 | public void setOkButtonEnabled(boolean b) { |
||
201 | btnOk.setEnabled(b); |
||
202 | } |
||
203 | |||
204 | public void setCancelButtonEnabled(boolean b) { |
||
205 | btnCancel.setEnabled(b); |
||
206 | } |
||
207 | } |