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