root / trunk / frameworks / _fwAndami / src / com / iver / andami / preferences / AbstractPreferencePage.java @ 6337
History | View | Annotate | Download (6.86 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.andami.preferences; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.GridBagConstraints; |
45 |
import java.awt.GridBagLayout; |
46 |
import java.awt.Insets; |
47 |
import java.util.Map; |
48 |
|
49 |
import javax.swing.JComponent; |
50 |
import javax.swing.JLabel; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.border.EmptyBorder; |
53 |
|
54 |
import com.iver.utiles.extensionPoints.IExtensionBuilder; |
55 |
/**
|
56 |
* The abstract class that any preference page should extend.
|
57 |
*
|
58 |
* @author jaume dominguez faus - jaume.dominguez
|
59 |
*
|
60 |
*/
|
61 |
public abstract class AbstractPreferencePage extends JPanel implements IPreference, IExtensionBuilder{ |
62 |
|
63 |
private GridBagLayout gridBag; |
64 |
|
65 |
/**
|
66 |
* The number of components already added to the layout manager.
|
67 |
*/
|
68 |
protected int y; |
69 |
|
70 |
private String title; |
71 |
|
72 |
protected String parentID = null; // Por defecto, nodo raiz |
73 |
|
74 |
/**
|
75 |
* Creates a new preference page.
|
76 |
*/
|
77 |
public AbstractPreferencePage()
|
78 |
{ |
79 |
setLayout(gridBag = new GridBagLayout()); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Adds a labeled component to the option pane. Components are
|
84 |
* added in a vertical fashion, one per row. The label is
|
85 |
* displayed to the left of the component.
|
86 |
* @param label The label
|
87 |
* @param comp The component
|
88 |
*/
|
89 |
public void addComponent(String label, Component comp) |
90 |
{ |
91 |
JLabel l = newLabel(label, comp);
|
92 |
l.setBorder(new EmptyBorder(0,0,0,12)); |
93 |
addComponent(l,comp,GridBagConstraints.BOTH);
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Adds a labeled component to the option pane. Components are
|
98 |
* added in a vertical fashion, one per row. The label is
|
99 |
* displayed to the left of the component.
|
100 |
* @param label The label
|
101 |
* @param comp The component
|
102 |
* @param fill Fill parameter to GridBagConstraints for the right
|
103 |
* component
|
104 |
*/
|
105 |
public void addComponent(String label, Component comp, int fill) |
106 |
{ |
107 |
JLabel l = newLabel(label, comp);
|
108 |
l.setBorder(new EmptyBorder(0,0,0,12)); |
109 |
addComponent(l,comp,fill); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Adds a labeled component to the option pane. Components are
|
114 |
* added in a vertical fashion, one per row. The label is
|
115 |
* displayed to the left of the component.
|
116 |
* @param comp1 The label
|
117 |
* @param comp2 The component
|
118 |
*
|
119 |
* @since jEdit 4.1pre3
|
120 |
*/
|
121 |
public void addComponent(Component comp1, Component comp2) |
122 |
{ |
123 |
addComponent(comp1,comp2,GridBagConstraints.BOTH);
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Adds a labeled component to the option pane. Components are
|
128 |
* added in a vertical fashion, one per row. The label is
|
129 |
* displayed to the left of the component.
|
130 |
* @param comp1 The label
|
131 |
* @param comp2 The component
|
132 |
* @param fill Fill parameter to GridBagConstraints for the right
|
133 |
* component
|
134 |
*
|
135 |
* @since jEdit 4.1pre3
|
136 |
*/
|
137 |
public void addComponent(Component comp1, Component comp2, int fill) |
138 |
{ |
139 |
copyToolTips(comp1, comp2); |
140 |
GridBagConstraints cons = new GridBagConstraints(); |
141 |
cons.gridy = y++; |
142 |
cons.gridheight = 1;
|
143 |
cons.gridwidth = 1;
|
144 |
cons.weightx = 0.0f;
|
145 |
cons.insets = new Insets(1,0,1,0); |
146 |
cons.fill = GridBagConstraints.BOTH;
|
147 |
|
148 |
gridBag.setConstraints(comp1,cons); |
149 |
add(comp1); |
150 |
|
151 |
cons.fill = fill; |
152 |
cons.gridx = 1;
|
153 |
cons.weightx = 1.0f;
|
154 |
gridBag.setConstraints(comp2,cons); |
155 |
add(comp2); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Adds a component to the option pane. Components are
|
160 |
* added in a vertical fashion, one per row.
|
161 |
* @param comp The component
|
162 |
*/
|
163 |
public void addComponent(Component comp) |
164 |
{ |
165 |
GridBagConstraints cons = new GridBagConstraints(); |
166 |
cons.gridy = y++; |
167 |
cons.gridheight = 1;
|
168 |
cons.gridwidth = GridBagConstraints.REMAINDER;
|
169 |
cons.fill = GridBagConstraints.NONE;
|
170 |
cons.anchor = GridBagConstraints.WEST;
|
171 |
cons.weightx = 1.0f;
|
172 |
cons.insets = new Insets(1,0,1,0); |
173 |
|
174 |
gridBag.setConstraints(comp,cons); |
175 |
add(comp); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Adds a component to the option pane. Components are
|
180 |
* added in a vertical fashion, one per row.
|
181 |
* @param comp The component
|
182 |
* @param fill Fill parameter to GridBagConstraints
|
183 |
*/
|
184 |
public void addComponent(Component comp, int fill) |
185 |
{ |
186 |
GridBagConstraints cons = new GridBagConstraints(); |
187 |
cons.gridy = y++; |
188 |
cons.gridheight = 1;
|
189 |
cons.gridwidth = GridBagConstraints.REMAINDER;
|
190 |
cons.fill = fill; |
191 |
cons.anchor = GridBagConstraints.WEST;
|
192 |
cons.weightx = 1.0f;
|
193 |
cons.insets = new Insets(1,0,1,0); |
194 |
|
195 |
gridBag.setConstraints(comp,cons); |
196 |
add(comp); |
197 |
} |
198 |
|
199 |
private void copyToolTips (Component c1, Component c2) { |
200 |
int tooltips = 0; |
201 |
int jc=0; |
202 |
String text = null; |
203 |
JComponent jc1 = null, jc2 = null; |
204 |
try {
|
205 |
jc1 = (JComponent) c1;
|
206 |
text = jc1.getToolTipText(); |
207 |
++jc; |
208 |
if (text != null && text.length() > 0) tooltips++; |
209 |
} |
210 |
catch (Exception e) {} |
211 |
try {
|
212 |
jc2 = (JComponent) c2;
|
213 |
String text2 = jc2.getToolTipText();
|
214 |
++jc; |
215 |
if (text2 != null && text2.length() > 0) { |
216 |
text = text2; |
217 |
tooltips++; |
218 |
} |
219 |
} |
220 |
catch (Exception e) {} |
221 |
if (tooltips == 1 && jc == 2) { |
222 |
jc1.setToolTipText(text); |
223 |
jc2.setToolTipText(text); |
224 |
} |
225 |
} |
226 |
|
227 |
/**
|
228 |
* @return a label which has the same tooltiptext as the Component
|
229 |
* that it is a label for. This is used to create labels from inside
|
230 |
* AbstractPreferencePage.
|
231 |
*/
|
232 |
public JLabel newLabel(String label, Component comp) |
233 |
{ |
234 |
JLabel retval = new JLabel(label); |
235 |
try /* to get the tooltip of the component */ |
236 |
{ |
237 |
JComponent jc = (JComponent) comp; |
238 |
String tttext = jc.getToolTipText();
|
239 |
retval.setToolTipText(tttext); |
240 |
} |
241 |
catch (Exception e) |
242 |
{ |
243 |
/* There probably wasn't a tooltip,
|
244 |
* or it wasn't a JComponent.
|
245 |
We don't care. */
|
246 |
} |
247 |
return retval;
|
248 |
} |
249 |
|
250 |
public final void setParentID(String parentID) { |
251 |
this.parentID = parentID;
|
252 |
} |
253 |
public final String getParentID() { |
254 |
return parentID;
|
255 |
} |
256 |
|
257 |
public final void setTitle(String title) { |
258 |
this.title = title;
|
259 |
} |
260 |
|
261 |
public String toString() |
262 |
{ |
263 |
return title;
|
264 |
} |
265 |
|
266 |
public Object create() { |
267 |
return this; |
268 |
} |
269 |
|
270 |
public Object create(Object[] args) { |
271 |
return this; |
272 |
} |
273 |
|
274 |
public Object create(Map args) { |
275 |
return this; |
276 |
} |
277 |
|
278 |
|
279 |
} |