Revision 4520
trunk/libraries/libUI/doc/contents.html | ||
---|---|---|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|
2 |
<HTML> |
|
3 |
<HEAD> |
|
4 |
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-15"> |
|
5 |
<TITLE></TITLE> |
|
6 |
<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)"> |
|
7 |
<META NAME="CREATED" CONTENT="20060322;9174300"> |
|
8 |
<META NAME="CHANGED" CONTENT="20060322;10202100"> |
|
9 |
<STYLE> |
|
10 |
<!-- |
|
11 |
@page { size: 21cm 29.7cm; margin: 2cm } |
|
12 |
P { margin-bottom: 0.21cm } |
|
13 |
A:link { color: #000080; text-decoration: underline } |
|
14 |
A:visited { color: #800000; text-decoration: underline } |
|
15 |
--> |
|
16 |
</STYLE> |
|
17 |
</HEAD> |
|
18 |
<BODY LANG="en-US" LINK="#000080" VLINK="#800000" DIR="LTR"> |
|
19 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=3 STYLE="font-size: 13pt"><B>PRESENT |
|
20 |
BEANS.</B></FONT></FONT></P> |
|
21 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
22 |
</P> |
|
23 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>DefaultBean.java |
|
24 |
(extends JPanel (standard in Swing)):</B><SPAN STYLE="font-weight: medium"> |
|
25 |
Just a JPanel with addListener(BeanListener l), |
|
26 |
removeListener(BeanListener l), and callValueChange(Object value) |
|
27 |
methods for adding listeners, removing listeners, and firing |
|
28 |
BeanValueChange events.</SPAN></FONT></FONT></P> |
|
29 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
30 |
</P> |
|
31 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>Pager.java |
|
32 |
(extends DefaultBean.java)</B>: this is an |
|
33 |
AcrobatReader-page-browser-like bean that allows you to easy browse a |
|
34 |
list of values. Each time you drag the slider, click a button or type |
|
35 |
a number an Integer value is produced and a BeanValueChanged event is |
|
36 |
fired returning an Object value. Catch this event and cast the value |
|
37 |
produced to a Integer (or even an int) and use it to move your list |
|
38 |
pointer to this position. An example of use can be found in |
|
39 |
<B>SamplePanel.java</B></FONT></FONT></P> |
|
40 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
41 |
</P> |
|
42 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
43 |
</P> |
|
44 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=3 STYLE="font-size: 13pt"><B>PRESENT |
|
45 |
CONTROLS.</B></FONT></FONT></P> |
|
46 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
47 |
</P> |
|
48 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
49 |
org.gvsig.gui.beans.controls</B></FONT></FONT></P> |
|
50 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
51 |
</P> |
|
52 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>MultilineTooltip.java |
|
53 |
(extends JToolTip (standard in Swing)): </B><SPAN STYLE="font-weight: medium">Allows |
|
54 |
using more than one line length tooltips. It also automatically |
|
55 |
calculates the size of the screen rectangle used and the preferred |
|
56 |
sized up on the contained text. It does NOT format the text to fit |
|
57 |
within a given size. The user must provide the text as she/he wishes |
|
58 |
to show it. It means that new line characters must be placed in the |
|
59 |
string as well as it was a System.out.println statement.</SPAN></FONT></FONT></P> |
|
60 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
61 |
</P> |
|
62 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
63 |
org.gvsig.gui.beans.controls.dnd</B></FONT></FONT></P> |
|
64 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
65 |
</P> |
|
66 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>JDnDList |
|
67 |
(extends JList (standard in Swing)): </B><SPAN STYLE="font-weight: medium">A |
|
68 |
JList that allows drag'n'drop elements. It accepts changing position |
|
69 |
of one or more elements within the list, adding other from other |
|
70 |
JDnDList's, removing sets of selected items, and other features. In |
|
71 |
order to use this features you have to use a JDnDListModel as the |
|
72 |
list's model.</SPAN></FONT></FONT></P> |
|
73 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
74 |
</P> |
|
75 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>JDnDListModel |
|
76 |
(extends AbstractListModel (standard in Swing)): </B><SPAN STYLE="font-weight: medium">List |
|
77 |
model to use in junction the JDnDList. Contains some useful tools.</SPAN></FONT></FONT></P> |
|
78 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
79 |
</P> |
|
80 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
81 |
org.gvsig.gui.geans.listeners</B></FONT></FONT></P> |
|
82 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
83 |
</P> |
|
84 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>BeanListener.java: |
|
85 |
</B><SPAN STYLE="font-weight: medium">Defines an object which listens |
|
86 |
for changes in the value produced by a bean. It is used, for example, |
|
87 |
in</SPAN><B> DefaultBean.java.</B></FONT></FONT></P> |
|
88 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
89 |
</P> |
|
90 |
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR> |
|
91 |
</P> |
|
92 |
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Courier, monospace"><FONT SIZE=2>by |
|
93 |
Jaume Domínguez Faus (:S)</FONT></FONT></P> |
|
94 |
</BODY> |
|
95 |
</HTML> |
|
0 | 96 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/Pager.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-03-22 11:18:29 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.4 2006/02/28 15:25:14 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2.2.6 2006/02/23 10:36:30 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.2.2.5 2006/02/16 10:36:41 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.1 2006/02/16 09:09:05 caballero |
|
59 |
* PAger de Jaume |
|
60 |
* |
|
61 |
* Revision 1.2.2.4 2006/02/10 13:23:18 jaume |
|
62 |
* page value can now be set externally |
|
63 |
* |
|
64 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume |
|
65 |
* correcciones de bugs |
|
66 |
* |
|
67 |
* Revision 1.3 2006/01/26 16:07:14 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.2.2.1 2006/01/26 12:59:32 jaume |
|
71 |
* 0.5 |
|
72 |
* |
|
73 |
* Revision 1.2 2006/01/24 14:36:33 jaume |
|
74 |
* This is the new version |
|
75 |
* |
|
76 |
* Revision 1.1.2.5 2006/01/19 16:09:30 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.1.2.4 2006/01/17 17:05:39 jaume |
|
80 |
* fixed crazy buttons behavior :-P |
|
81 |
* |
|
82 |
* Revision 1.1.2.3 2006/01/17 17:01:55 jaume |
|
83 |
* fixed crazy buttons behavior :-P |
|
84 |
* |
|
85 |
* Revision 1.1.2.2 2006/01/11 12:20:30 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* Revision 1.1.2.1 2006/01/10 13:11:38 jaume |
|
89 |
* *** empty log message *** |
|
90 |
* |
|
91 |
* Revision 1.1.2.1 2006/01/10 11:33:31 jaume |
|
92 |
* Time dimension working against Jet Propulsion Laboratory's WMS server |
|
93 |
* |
|
94 |
* Revision 1.1.2.3 2006/01/09 18:10:38 jaume |
|
95 |
* casi con el time dimension |
|
96 |
* |
|
97 |
* Revision 1.1.2.2 2006/01/02 18:08:01 jaume |
|
98 |
* Tree de estilos |
|
99 |
* |
|
100 |
* Revision 1.1.2.1 2005/12/30 08:56:19 jaume |
|
101 |
* *** empty log message *** |
|
102 |
* |
|
103 |
* |
|
104 |
*/ |
|
105 |
/** |
|
106 |
* |
|
107 |
*/ |
|
108 |
package org.gvsig.gui.beans; |
|
109 |
|
|
110 |
import java.awt.Dimension; |
|
111 |
import java.awt.event.ActionEvent; |
|
112 |
import java.awt.event.ActionListener; |
|
113 |
|
|
114 |
import javax.swing.ImageIcon; |
|
115 |
import javax.swing.JButton; |
|
116 |
import javax.swing.JPanel; |
|
117 |
import javax.swing.JSlider; |
|
118 |
import javax.swing.JTextField; |
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
/** |
|
123 |
* Bean that is useful to browse a very large list of data. It |
|
124 |
* includes a set of navigation buttons to step ahead or behind |
|
125 |
* by one or going to the first and last element of the list as |
|
126 |
* well as an slider and a text field for directly focus on a |
|
127 |
* list item. |
|
128 |
* |
|
129 |
* @author jaume dominguez faus |
|
130 |
* |
|
131 |
*/ |
|
132 |
public class Pager extends DefaultBean { |
|
133 |
private JPanel buttonsPanel = null; |
|
134 |
private JButton btnFastBackward = null; |
|
135 |
private JButton btnBackward = null; |
|
136 |
private JTextField txtItemCountDisplay = null; |
|
137 |
private JButton btnForward = null; |
|
138 |
private JButton btnFastForward = null; |
|
139 |
private JPanel sliderPanel = null; |
|
140 |
private JSlider slider = null; |
|
141 |
private int itemCount; |
|
142 |
private int lowLimit; |
|
143 |
private int currentValue = -1; |
|
144 |
private int orientation; |
|
145 |
private boolean refreshing = false; |
|
146 |
public static int HORIZONTAL=0; |
|
147 |
public static int VERTICAL=1; |
|
148 |
/** |
|
149 |
* This is the default constructor. Creates a new instance of ItemBrowser with |
|
150 |
* zero items. |
|
151 |
*/ |
|
152 |
public Pager(int orientation){ |
|
153 |
super(); |
|
154 |
this.orientation=orientation; |
|
155 |
initialize(0, 0); |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Creates a new instance of ItemBrowser defining its edges |
|
160 |
* @param lowIndex, the lowest edge. |
|
161 |
* @param itemCount, the highest edge. |
|
162 |
*/ |
|
163 |
public Pager(int lowIndex, int itemCount,int orientation) { |
|
164 |
super(); |
|
165 |
this.orientation=orientation; |
|
166 |
initialize(lowIndex, itemCount); |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* This method initializes this |
|
171 |
* |
|
172 |
* @return void |
|
173 |
*/ |
|
174 |
private void initialize(int lowIndex, int itemCount) { |
|
175 |
setItemCount(itemCount); |
|
176 |
this.lowLimit = lowIndex; |
|
177 |
this.setLayout(null); |
|
178 |
if (orientation==VERTICAL){ |
|
179 |
this.setSize(45,305); |
|
180 |
this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray,1)); |
|
181 |
this.setPreferredSize(new Dimension(40,300)); |
|
182 |
}else{ |
|
183 |
this.setSize(240, 50); |
|
184 |
this.setPreferredSize(new Dimension(190,50)); |
|
185 |
} |
|
186 |
|
|
187 |
this.add(getSliderPanel(), null); |
|
188 |
this.add(getButtonsPanel(), null); |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* This method initializes buttonsPanel |
|
193 |
* |
|
194 |
* @return javax.swing.JPanel |
|
195 |
*/ |
|
196 |
private JPanel getButtonsPanel() { |
|
197 |
if (buttonsPanel == null) { |
|
198 |
buttonsPanel = new JPanel(); |
|
199 |
buttonsPanel.setLayout(null); |
|
200 |
buttonsPanel.setName("buttonsPanel"); |
|
201 |
buttonsPanel.setPreferredSize(new java.awt.Dimension(173,50)); |
|
202 |
if (orientation==VERTICAL){ |
|
203 |
buttonsPanel.setBounds(3, 182, 35,115); |
|
204 |
}else{ |
|
205 |
buttonsPanel.setBounds(5, 25, 240, 25); |
|
206 |
} |
|
207 |
|
|
208 |
buttonsPanel.add(getBtnFastBackward(), null); |
|
209 |
buttonsPanel.add(getBtnBackward(), null); |
|
210 |
buttonsPanel.add(getTxtItemCountDisplay(), null); |
|
211 |
buttonsPanel.add(getBtnForward(), null); |
|
212 |
buttonsPanel.add(getBtnFastForward(), null); |
|
213 |
} |
|
214 |
return buttonsPanel; |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* This method initializes btnFastBackWard |
|
219 |
* |
|
220 |
* @return javax.swing.JButton |
|
221 |
*/ |
|
222 |
private JButton getBtnFastBackward() { |
|
223 |
if (btnFastBackward == null) { |
|
224 |
btnFastBackward = new JButton(); |
|
225 |
if (orientation==VERTICAL){ |
|
226 |
btnFastBackward.setBounds(7, 1, 20, 24); |
|
227 |
}else{ |
|
228 |
btnFastBackward.setBounds(2, 1, 20, 24); |
|
229 |
} |
|
230 |
|
|
231 |
btnFastBackward.setEnabled(itemCount!=0); |
|
232 |
btnFastBackward.addActionListener(new ActionListener() { |
|
233 |
public void actionPerformed(ActionEvent e) { |
|
234 |
if (currentValue != lowLimit){ |
|
235 |
setValue(lowLimit, true); |
|
236 |
} |
|
237 |
}}); |
|
238 |
btnFastBackward.setIcon(new ImageIcon(getClass().getResource("images/fastbackward.png"))); |
|
239 |
} |
|
240 |
return btnFastBackward; |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* This method initializes btnBackward |
|
245 |
* |
|
246 |
* @return javax.swing.JButton |
|
247 |
*/ |
|
248 |
private JButton getBtnBackward() { |
|
249 |
if (btnBackward == null) { |
|
250 |
btnBackward = new JButton(); |
|
251 |
if (orientation==VERTICAL){ |
|
252 |
btnBackward.setBounds(7, 21, 20, 24); |
|
253 |
}else{ |
|
254 |
btnBackward.setBounds(21, 1, 20, 24); |
|
255 |
} |
|
256 |
|
|
257 |
btnBackward.setEnabled(itemCount!=0); |
|
258 |
btnBackward.addActionListener(new ActionListener() { |
|
259 |
public void actionPerformed(ActionEvent e) { |
|
260 |
if (currentValue > lowLimit ){ |
|
261 |
setValue(currentValue-1, true); |
|
262 |
} |
|
263 |
}}); |
|
264 |
btnBackward.setIcon(new ImageIcon(getClass().getResource("images/backward.png"))); |
|
265 |
} |
|
266 |
return btnBackward; |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* This method initializes txtItemCountDisplay |
|
271 |
* |
|
272 |
* @return javax.swing.JTextField |
|
273 |
*/ |
|
274 |
private JTextField getTxtItemCountDisplay() { |
|
275 |
if (txtItemCountDisplay == null) { |
|
276 |
txtItemCountDisplay = new JTextField(); |
|
277 |
txtItemCountDisplay.setEnabled(itemCount!=0); |
|
278 |
txtItemCountDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER); |
|
279 |
if (orientation==VERTICAL){ |
|
280 |
txtItemCountDisplay.setBounds(2,43, 33, 23); |
|
281 |
} else { |
|
282 |
txtItemCountDisplay.setBounds(43, 2, 144, 23); |
|
283 |
} |
|
284 |
|
|
285 |
txtItemCountDisplay.setText(lowLimit+" / "+itemCount); |
|
286 |
txtItemCountDisplay.addMouseListener(new java.awt.event.MouseAdapter() { |
|
287 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
|
288 |
txtItemCountDisplay.setText(currentValue+""); |
|
289 |
txtItemCountDisplay.setSelectionStart(0); |
|
290 |
txtItemCountDisplay.setSelectionEnd(txtItemCountDisplay.getText().length()); |
|
291 |
} |
|
292 |
}); |
|
293 |
txtItemCountDisplay.addActionListener(new java.awt.event.ActionListener() { |
|
294 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
295 |
try { |
|
296 |
int v = Integer.parseInt(txtItemCountDisplay.getText()); |
|
297 |
v = (v>itemCount) ? itemCount : v; |
|
298 |
setValue(v, true); |
|
299 |
} catch (Exception ex){ |
|
300 |
refreshText(currentValue); |
|
301 |
} |
|
302 |
txtItemCountDisplay.transferFocusDownCycle(); |
|
303 |
} |
|
304 |
}); |
|
305 |
txtItemCountDisplay.setEnabled(false); |
|
306 |
} |
|
307 |
return txtItemCountDisplay; |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* This, sets the bean value and triggers an event that can be captured |
|
312 |
* by a listener. |
|
313 |
* @param number |
|
314 |
* @param fireEvent, if true then this method will fire the event. If false, |
|
315 |
* then the value will be changed silently. |
|
316 |
* |
|
317 |
*/ |
|
318 |
public void setValue(int number, boolean fireEvent) { |
|
319 |
if (number < lowLimit) |
|
320 |
number = lowLimit; |
|
321 |
if (number > itemCount-1) |
|
322 |
number = itemCount; |
|
323 |
if (number != currentValue) { |
|
324 |
currentValue = number; |
|
325 |
refreshControls(); |
|
326 |
if (fireEvent) |
|
327 |
callValueChanged(new Integer(currentValue)); |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
331 |
/** |
|
332 |
* Refreshes all the mutable controls in this component. |
|
333 |
*/ |
|
334 |
private void refreshControls() { |
|
335 |
int normalizedValue = (int) ((currentValue / (float) itemCount)*100); |
|
336 |
refreshSlider(normalizedValue); |
|
337 |
refreshText(currentValue); |
|
338 |
} |
|
339 |
|
|
340 |
/** |
|
341 |
* Sets the slider to the correct (scaled) position. |
|
342 |
* @param normalizedValue |
|
343 |
*/ |
|
344 |
private void refreshSlider(int normalizedValue) { |
|
345 |
refreshing = true; |
|
346 |
getSlider().setValue(normalizedValue); |
|
347 |
refreshing = false; |
|
348 |
} |
|
349 |
|
|
350 |
/** |
|
351 |
* @param string |
|
352 |
*/ |
|
353 |
private void refreshText(int value) { |
|
354 |
String newText = (value+1) +" / "+itemCount; |
|
355 |
|
|
356 |
if (!getTxtItemCountDisplay().getText().equals(newText)) |
|
357 |
getTxtItemCountDisplay().setText(newText); |
|
358 |
} |
|
359 |
|
|
360 |
/** |
|
361 |
* This method initializes btnForward |
|
362 |
* |
|
363 |
* @return javax.swing.JButton |
|
364 |
*/ |
|
365 |
private JButton getBtnForward() { |
|
366 |
if (btnForward == null) { |
|
367 |
btnForward = new JButton(); |
|
368 |
if (orientation==VERTICAL){ |
|
369 |
btnForward.setBounds(7, 67, 20, 24); |
|
370 |
}else{ |
|
371 |
btnForward.setBounds(189, 1, 20, 24); |
|
372 |
} |
|
373 |
|
|
374 |
btnForward.setEnabled(itemCount!=0); |
|
375 |
btnForward.addActionListener(new ActionListener() { |
|
376 |
public void actionPerformed(ActionEvent e) { |
|
377 |
if (currentValue < itemCount-1){ |
|
378 |
setValue(currentValue+1, true); |
|
379 |
} |
|
380 |
}}); |
|
381 |
btnForward.setIcon(new ImageIcon(getClass().getResource("images/forward.png"))); |
|
382 |
} |
|
383 |
return btnForward; |
|
384 |
} |
|
385 |
|
|
386 |
/** |
|
387 |
* This method initializes btnFastForward |
|
388 |
* |
|
389 |
* @return javax.swing.JButton |
|
390 |
*/ |
|
391 |
private JButton getBtnFastForward() { |
|
392 |
if (btnFastForward == null) { |
|
393 |
btnFastForward = new JButton(); |
|
394 |
if (orientation==VERTICAL){ |
|
395 |
btnFastForward.setBounds(7, 91, 20, 24); |
|
396 |
}else{ |
|
397 |
btnFastForward.setBounds(208, 1, 20, 24); |
|
398 |
} |
|
399 |
|
|
400 |
btnFastForward.setEnabled(itemCount!=0); |
|
401 |
btnFastForward.addActionListener(new ActionListener() { |
|
402 |
public void actionPerformed(ActionEvent e) { |
|
403 |
if (currentValue < itemCount-1){ |
|
404 |
setValue(itemCount-1, true); |
|
405 |
} |
|
406 |
}}); |
|
407 |
btnFastForward.setIcon(new ImageIcon(getClass().getResource("images/fastforward.png"))); |
|
408 |
} |
|
409 |
return btnFastForward; |
|
410 |
} |
|
411 |
|
|
412 |
/** |
|
413 |
* This method initializes sliderPanel |
|
414 |
* |
|
415 |
* @return javax.swing.JPanel |
|
416 |
*/ |
|
417 |
private JPanel getSliderPanel() { |
|
418 |
if (sliderPanel == null) { |
|
419 |
sliderPanel = new JPanel(); |
|
420 |
sliderPanel.setLayout(null); |
|
421 |
sliderPanel.setName("sliderPanel"); |
|
422 |
if (orientation==VERTICAL){ |
|
423 |
sliderPanel.setBounds(3, 0, 35, 181); |
|
424 |
}else{ |
|
425 |
sliderPanel.setBounds(5, 0, 300, 26); |
|
426 |
} |
|
427 |
sliderPanel.setEnabled(false); |
|
428 |
sliderPanel.add(getSlider(), null); |
|
429 |
} |
|
430 |
return sliderPanel; |
|
431 |
} |
|
432 |
|
|
433 |
/** |
|
434 |
* This method initializes slider |
|
435 |
* |
|
436 |
* @return javax.swing.JSlider |
|
437 |
*/ |
|
438 |
private JSlider getSlider() { |
|
439 |
if (slider == null) { |
|
440 |
slider = new JSlider(); |
|
441 |
slider.setValue(0); |
|
442 |
if (orientation==VERTICAL){ |
|
443 |
slider.setOrientation(JSlider.VERTICAL); |
|
444 |
slider.setSize(24, 230); |
|
445 |
}else{ |
|
446 |
slider.setOrientation(JSlider.HORIZONTAL); |
|
447 |
slider.setSize(230, 24); |
|
448 |
} |
|
449 |
|
|
450 |
slider.setLocation(0, 1); |
|
451 |
slider.setEnabled(itemCount!=0); |
|
452 |
slider.addMouseListener(new java.awt.event.MouseAdapter() { |
|
453 |
public void mouseReleased(java.awt.event.MouseEvent e) { |
|
454 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
|
455 |
if (value >= itemCount) |
|
456 |
value = itemCount - 1; |
|
457 |
refreshText(value); |
|
458 |
setValue(value, false); |
|
459 |
} |
|
460 |
}); |
|
461 |
slider.addChangeListener(new javax.swing.event.ChangeListener() { |
|
462 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
|
463 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
|
464 |
if (value >= itemCount) |
|
465 |
value = itemCount - 1; |
|
466 |
refreshText(value); |
|
467 |
if (!refreshing) |
|
468 |
callValueChanged(new Integer(value)); |
|
469 |
} |
|
470 |
}); |
|
471 |
} |
|
472 |
return slider; |
|
473 |
} |
|
474 |
|
|
475 |
/** |
|
476 |
* Sets the amount of items that this component will handle. |
|
477 |
* @param count |
|
478 |
*/ |
|
479 |
public void setItemCount(int count){ |
|
480 |
itemCount = count; |
|
481 |
getSlider().setEnabled(count != 0); |
|
482 |
getBtnFastBackward().setEnabled(count != 0); |
|
483 |
getBtnBackward().setEnabled(count != 0); |
|
484 |
getTxtItemCountDisplay().setEnabled(count != 0); |
|
485 |
getBtnForward().setEnabled(count != 0); |
|
486 |
getBtnFastForward().setEnabled(count != 0); |
|
487 |
} |
|
488 |
|
|
489 |
/** |
|
490 |
* Sets the starting point if none is defined the pager will start from 0. |
|
491 |
* @param initial position |
|
492 |
*/ |
|
493 |
public void setStartingPosition(int initialPosition) { |
|
494 |
lowLimit = initialPosition; |
|
495 |
} |
|
496 |
|
|
497 |
public void setCurrentPosition(int pos) { |
|
498 |
setValue(pos, true); |
|
499 |
} |
|
500 |
} // @jve:decl-index=0:visual-constraint="10,15" |
|
0 | 501 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/SamplePanel.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-03-22 11:18:29 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.6 2006/02/28 15:25:14 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.4.2.4 2006/02/16 10:36:41 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.4.2.3 2006/01/31 16:25:24 jaume |
|
56 |
* correcciones de bugs |
|
57 |
* |
|
58 |
* Revision 1.5 2006/01/26 16:07:14 jaume |
|
59 |
* *** empty log message *** |
|
60 |
* |
|
61 |
* Revision 1.4.2.1 2006/01/26 12:59:32 jaume |
|
62 |
* 0.5 |
|
63 |
* |
|
64 |
* Revision 1.4 2006/01/26 12:50:20 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.3 2006/01/25 15:14:02 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.2 2006/01/24 14:36:33 jaume |
|
71 |
* This is the new version |
|
72 |
* |
|
73 |
* Revision 1.1.2.5 2006/01/10 13:11:38 jaume |
|
74 |
* *** empty log message *** |
|
75 |
* |
|
76 |
* Revision 1.1.2.4 2006/01/10 11:33:31 jaume |
|
77 |
* Time dimension working against Jet Propulsion Laboratory's WMS server |
|
78 |
* |
|
79 |
* Revision 1.1.2.3 2006/01/09 18:10:38 jaume |
|
80 |
* casi con el time dimension |
|
81 |
* |
|
82 |
* Revision 1.1.2.2 2006/01/02 18:08:01 jaume |
|
83 |
* Tree de estilos |
|
84 |
* |
|
85 |
* Revision 1.1.2.1 2005/12/30 08:56:19 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* |
|
89 |
*/ |
|
90 |
/** |
|
91 |
* |
|
92 |
*/ |
|
93 |
package org.gvsig.gui.beans; |
|
94 |
|
|
95 |
import javax.swing.JFrame; |
|
96 |
import javax.swing.JPanel; |
|
97 |
|
|
98 |
import org.gvsig.gui.beans.listeners.BeanListener; |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
/** |
|
104 |
* Sample class for see how to use BeanListeners. |
|
105 |
* <p> |
|
106 |
* Have fun! ;-) |
|
107 |
* </p> |
|
108 |
* @author jaume |
|
109 |
* |
|
110 |
*/ |
|
111 |
public class SamplePanel extends JPanel { |
|
112 |
|
|
113 |
private Pager ep; |
|
114 |
/** |
|
115 |
* This is the default constructor |
|
116 |
*/ |
|
117 |
public SamplePanel() { |
|
118 |
super(); |
|
119 |
initialize(); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* This method initializes this |
|
124 |
* |
|
125 |
* @return void |
|
126 |
*/ |
|
127 |
private void initialize() { |
|
128 |
this.setSize(300, 200); |
|
129 |
this.setLayout(null); |
|
130 |
|
|
131 |
this.add(getEditionPanel(), null); |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
private Pager getEditionPanel(){ |
|
136 |
if (ep == null){ |
|
137 |
ep = new Pager(0, 20, Pager.HORIZONTAL); |
|
138 |
ep.addListener(new BeanListener(){ |
|
139 |
|
|
140 |
public void beanValueChanged(Object value) { |
|
141 |
System.out.println("("+((Integer) value).intValue()+")"); |
|
142 |
} |
|
143 |
|
|
144 |
}); |
|
145 |
} |
|
146 |
return ep; |
|
147 |
} |
|
148 |
|
|
149 |
public static void main(String[] args){ |
|
150 |
//dim = new TimeDimension("units", "unitSymbol", "2004-12-24/2005-12-18/P1D"); |
|
151 |
|
|
152 |
JFrame frame = new JFrame(); |
|
153 |
frame.getContentPane().add(new SamplePanel()); |
|
154 |
frame.setBounds(0, 0, 279, 63); |
|
155 |
frame.pack(); |
|
156 |
frame.show(); |
|
157 |
} |
|
158 |
} |
|
0 | 159 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/controls/dnd/JDnDListModel.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-03-22 11:18:29 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.4 2006/02/28 15:25:14 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume |
|
53 |
* correcciones de bugs |
|
54 |
* |
|
55 |
* Revision 1.3 2006/01/26 16:07:14 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.2.2.1 2006/01/26 12:59:33 jaume |
|
59 |
* 0.5 |
|
60 |
* |
|
61 |
* Revision 1.2 2006/01/24 14:36:33 jaume |
|
62 |
* This is the new version |
|
63 |
* |
|
64 |
* Revision 1.1.2.2 2006/01/17 12:55:40 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.1.2.1 2006/01/10 13:11:38 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.1.2.1 2005/12/29 08:26:54 jaume |
|
71 |
* some gui issues where fixed |
|
72 |
* |
|
73 |
* Revision 1.1.2.2 2005/12/22 16:46:00 jaume |
|
74 |
* puede borrar m?ltiples intervalos de entradas dentro de la lista |
|
75 |
* |
|
76 |
* Revision 1.1.2.1 2005/12/19 18:12:35 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* |
|
80 |
*/ |
|
81 |
/** |
|
82 |
* |
|
83 |
*/ |
|
84 |
package org.gvsig.gui.beans.controls.dnd; |
|
85 |
|
|
86 |
import java.util.ArrayList; |
|
87 |
import java.util.Collection; |
|
88 |
import java.util.Iterator; |
|
89 |
|
|
90 |
import javax.swing.AbstractListModel; |
|
91 |
|
|
92 |
|
|
93 |
/** |
|
94 |
* List model to use in junction the JDnDList. Contains some useful tools. |
|
95 |
* |
|
96 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
97 |
* |
|
98 |
*/ |
|
99 |
public class JDnDListModel extends AbstractListModel { |
|
100 |
private ArrayList items = new ArrayList(); |
|
101 |
/** |
|
102 |
* Inserts a collection of items before the specified index |
|
103 |
*/ |
|
104 |
public void insertItems( int index, Collection objects ) { |
|
105 |
// Handle the case where the items are being added to the end of the list |
|
106 |
if( index == -1 ) { |
|
107 |
// Add the items |
|
108 |
for( Iterator i = objects.iterator(); i.hasNext(); ) { |
|
109 |
String item = ( String )i.next(); |
|
110 |
addElement(items.size(), item ); |
|
111 |
} |
|
112 |
} else { |
|
113 |
// Insert the items |
|
114 |
for( Iterator i = objects.iterator(); i.hasNext(); ) { |
|
115 |
Object item = i.next(); |
|
116 |
insertElement( index++, item ); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
// Tell the list to update itself |
|
121 |
this.fireContentsChanged( this, 0, this.items.size() - 1 ); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Inserts a new element into the list at the position mentioned in the index param. |
|
126 |
* @param index |
|
127 |
* @param item |
|
128 |
*/ |
|
129 |
public boolean insertElement(int index, Object element) { |
|
130 |
if (element == null) { |
|
131 |
return false; |
|
132 |
} |
|
133 |
for (int i = 0; i < items.size(); i++) { |
|
134 |
|
|
135 |
if (items.get(i).equals(items)) { |
|
136 |
return false; |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
this.items.add(index, element); |
|
141 |
return true; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Adds a new element at the position indicated by pos of the list. |
|
146 |
* @param j |
|
147 |
* @param pos |
|
148 |
*/ |
|
149 |
public boolean addElement(int j, Object element) { |
|
150 |
if (element == null) { |
|
151 |
return false; |
|
152 |
} |
|
153 |
|
|
154 |
for (int i = 0; i < items.size(); i++) { |
|
155 |
if (items.get(i).equals(items)) { |
|
156 |
return false; |
|
157 |
} |
|
158 |
} |
|
159 |
this.items.add(j, element); |
|
160 |
fireContentsChanged(this, items.size() - 1, items.size() - 1); |
|
161 |
return true; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Adds a new element at the position indicated by pos of the list. |
|
166 |
* @param j |
|
167 |
* @param pos |
|
168 |
*/ |
|
169 |
public boolean addElement(Object element) { |
|
170 |
return addElement(items.size(), element); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Removes every elements contained in the collection from this list. |
|
175 |
*/ |
|
176 |
public void delElements(Collection c) { |
|
177 |
items.removeAll(c); |
|
178 |
this.fireContentsChanged(this, 0, items.size()); |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Removes the items of the list mentioned by the index array passed as argument. |
|
183 |
* @param indices |
|
184 |
*/ |
|
185 |
public void delIndices(int[] indices){ |
|
186 |
int removed = 0; |
|
187 |
for (int i = 0; i < indices.length; i++) { |
|
188 |
items.remove(indices[i]-removed); |
|
189 |
removed++; |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
public void itemsMoved( int newIndex, int[] indicies ) { |
|
194 |
|
|
195 |
// Copy the objects to a temporary ArrayList |
|
196 |
ArrayList objects = new ArrayList(); |
|
197 |
for( int i=0; i<indicies.length; i++ ) { |
|
198 |
objects.add( this.items.get( indicies[ i ] ) ); |
|
199 |
} |
|
200 |
|
|
201 |
// Delete the objects from the list |
|
202 |
for( int i=indicies.length-1; i>=0; i-- ) { |
|
203 |
this.items.remove( indicies[ i ] ); |
|
204 |
} |
|
205 |
|
|
206 |
// Insert the items at the new location |
|
207 |
insertItems( newIndex, objects ); |
|
208 |
} |
|
209 |
|
|
210 |
/* (non-Javadoc) |
|
211 |
* @see javax.swing.ListModel#getSize() |
|
212 |
*/ |
|
213 |
public int getSize() { |
|
214 |
return items.size(); |
|
215 |
} |
|
216 |
|
|
217 |
/* (non-Javadoc) |
|
218 |
* @see javax.swing.ListModel#getElementAt(int) |
|
219 |
*/ |
|
220 |
public Object getElementAt(int index) { |
|
221 |
return items.get(index); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* Removes any item currently contained by this list. |
|
226 |
* |
|
227 |
*/ |
|
228 |
public void clear() { |
|
229 |
items.clear(); |
|
230 |
fireContentsChanged(this, 0, 0); |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Returns an ArrayList containing the elements of this list. |
|
235 |
*/ |
|
236 |
public ArrayList getElements() { |
|
237 |
return items; |
|
238 |
} |
|
239 |
|
|
240 |
|
|
241 |
} |
|
0 | 242 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/controls/dnd/JDnDList.java | ||
---|---|---|
1 |
package org.gvsig.gui.beans.controls.dnd; |
|
2 |
|
|
3 |
import java.awt.datatransfer.DataFlavor; |
|
4 |
import java.awt.datatransfer.StringSelection; |
|
5 |
import java.awt.datatransfer.Transferable; |
|
6 |
import java.awt.datatransfer.UnsupportedFlavorException; |
|
7 |
import java.awt.dnd.DnDConstants; |
|
8 |
import java.awt.dnd.DragGestureEvent; |
|
9 |
import java.awt.dnd.DragGestureListener; |
|
10 |
import java.awt.dnd.DragSource; |
|
11 |
import java.awt.dnd.DragSourceDragEvent; |
|
12 |
import java.awt.dnd.DragSourceDropEvent; |
|
13 |
import java.awt.dnd.DragSourceEvent; |
|
14 |
import java.awt.dnd.DragSourceListener; |
|
15 |
import java.awt.dnd.DropTarget; |
|
16 |
import java.awt.dnd.DropTargetDragEvent; |
|
17 |
import java.awt.dnd.DropTargetDropEvent; |
|
18 |
import java.awt.dnd.DropTargetEvent; |
|
19 |
import java.awt.dnd.DropTargetListener; |
|
20 |
import java.io.IOException; |
|
21 |
import java.util.ArrayList; |
|
22 |
import java.util.StringTokenizer; |
|
23 |
|
|
24 |
import javax.swing.JList; |
|
25 |
|
|
26 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
27 |
* |
|
28 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
29 |
* |
|
30 |
* This program is free software; you can redistribute it and/or |
|
31 |
* modify it under the terms of the GNU General Public License |
|
32 |
* as published by the Free Software Foundation; either version 2 |
|
33 |
* of the License, or (at your option) any later version. |
|
34 |
* |
|
35 |
* This program is distributed in the hope that it will be useful, |
|
36 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
37 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
38 |
* GNU General Public License for more details. |
|
39 |
* |
|
40 |
* You should have received a copy of the GNU General Public License |
|
41 |
* along with this program; if not, write to the Free Software |
|
42 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
43 |
* |
|
44 |
* For more information, contact: |
|
45 |
* |
|
46 |
* Generalitat Valenciana |
|
47 |
* Conselleria d'Infraestructures i Transport |
|
48 |
* Av. Blasco Ib??ez, 50 |
|
49 |
* 46010 VALENCIA |
|
50 |
* SPAIN |
|
51 |
* |
|
52 |
* +34 963862235 |
|
53 |
* gvsig@gva.es |
|
54 |
* www.gvsig.gva.es |
|
55 |
* |
|
56 |
* or |
|
57 |
* |
|
58 |
* IVER T.I. S.A |
|
59 |
* Salamanca 50 |
|
60 |
* 46005 Valencia |
|
61 |
* Spain |
|
62 |
* |
|
63 |
* +34 963163400 |
|
64 |
* dac@iver.es |
|
65 |
*/ |
|
66 |
|
|
67 |
/* CVS MESSAGES: |
|
68 |
* |
|
69 |
* $Id$ |
|
70 |
* $Log$ |
|
71 |
* Revision 1.1 2006-03-22 11:18:29 jaume |
|
72 |
* *** empty log message *** |
|
73 |
* |
|
74 |
* Revision 1.4 2006/02/28 15:25:14 jaume |
|
75 |
* *** empty log message *** |
|
76 |
* |
|
77 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume |
|
78 |
* correcciones de bugs |
|
79 |
* |
|
80 |
* Revision 1.3 2006/01/26 16:07:14 jaume |
|
81 |
* *** empty log message *** |
|
82 |
* |
|
83 |
* Revision 1.2.2.1 2006/01/26 12:59:33 jaume |
|
84 |
* 0.5 |
|
85 |
* |
|
86 |
* Revision 1.2 2006/01/24 14:36:33 jaume |
|
87 |
* This is the new version |
|
88 |
* |
|
89 |
* Revision 1.1.2.1 2006/01/10 13:11:38 jaume |
|
90 |
* *** empty log message *** |
|
91 |
* |
|
92 |
* Revision 1.1.2.1 2005/12/29 08:26:54 jaume |
|
93 |
* some gui issues where fixed |
|
94 |
* |
|
95 |
* Revision 1.1.2.1 2005/12/19 18:12:35 jaume |
|
96 |
* *** empty log message *** |
|
97 |
* |
|
98 |
* |
|
99 |
*/ |
|
100 |
/** |
|
101 |
* <p> |
|
102 |
* A JList that allows drag'n'drop elements. It accepts changing position of |
|
103 |
* one or more elements within the list, adding other from other JDnDList's, |
|
104 |
* removing sets of selected items, and other features. |
|
105 |
* </p> |
|
106 |
* <p> |
|
107 |
* In order to use this features you have to use a JDnDListModel as the list's |
|
108 |
* model. |
|
109 |
* </p> |
|
110 |
* jaume dominguez faus - jaume.dominguez@iver.es |
|
111 |
*/ |
|
112 |
public class JDnDList extends JList implements DragSourceListener, DragGestureListener, DropTargetListener{ |
|
113 |
private DragSource dragSource; |
|
114 |
private DropTarget dropTarget; |
|
115 |
private boolean dragging; |
|
116 |
private int overIndex; |
|
117 |
private int[] selectedIndices; |
|
118 |
|
|
119 |
|
|
120 |
public JDnDList() { |
|
121 |
dropTarget = new DropTarget (this, this); |
|
122 |
dragSource = new DragSource(); |
|
123 |
dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this); |
|
124 |
} |
|
125 |
|
|
126 |
public JDnDList( JDnDListModel model ) { |
|
127 |
super( model ); |
|
128 |
// Configure ourselves to be a drag source |
|
129 |
dragSource = new DragSource(); |
|
130 |
dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this); |
|
131 |
|
|
132 |
// Configure ourselves to be a drop target |
|
133 |
dropTarget = new DropTarget( this, this ); |
|
134 |
} |
|
135 |
|
|
136 |
public void dragGestureRecognized(DragGestureEvent dge) { |
|
137 |
this.selectedIndices = this.getSelectedIndices(); |
|
138 |
Object[] selectedObjects = this.getSelectedValues(); |
|
139 |
if( selectedObjects.length > 0 ) { |
|
140 |
StringBuffer sb = new StringBuffer(); |
|
141 |
for( int i=0; i<selectedObjects.length; i++ ) { |
|
142 |
sb.append( selectedObjects[ i ].toString() + "\n" ); |
|
143 |
} |
|
144 |
|
|
145 |
// Build a StringSelection object that the Drag Source |
|
146 |
// can use to transport a string to the Drop Target |
|
147 |
StringSelection text = new StringSelection( sb.toString() ); |
|
148 |
|
|
149 |
// Start dragging the object |
|
150 |
this.dragging = true; |
|
151 |
dragSource.startDrag( dge, DragSource.DefaultMoveDrop, text, this ); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
public void dragDropEnd(DragSourceDropEvent dsde) { |
|
156 |
this.dragging = false; |
|
157 |
} |
|
158 |
|
|
159 |
public void dragExit(DropTargetEvent dte) { |
|
160 |
this.overIndex = -1; |
|
161 |
} |
|
162 |
public void dragEnter(DropTargetDragEvent dtde) { |
|
163 |
this.overIndex = this.locationToIndex( dtde.getLocation() ); |
|
164 |
this.setSelectedIndex( this.overIndex ); |
|
165 |
} |
|
166 |
public void dragOver(DropTargetDragEvent dtde) { |
|
167 |
// See who we are over... |
|
168 |
int overIndex = this.locationToIndex( dtde.getLocation() ); |
|
169 |
if( overIndex != -1 && overIndex != this.overIndex ) { |
|
170 |
// If the value has changed from what we were previously over |
|
171 |
// then change the selected object to the one we are over; this |
|
172 |
// is a visual representation that this is where the drop will occur |
|
173 |
this.overIndex = overIndex; |
|
174 |
this.setSelectedIndex( this.overIndex ); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
public void drop(DropTargetDropEvent dtde) { |
|
179 |
try { |
|
180 |
Transferable transferable = dtde.getTransferable(); |
|
181 |
if( transferable.isDataFlavorSupported( DataFlavor.stringFlavor ) ) { |
|
182 |
dtde.acceptDrop( DnDConstants.ACTION_MOVE ); |
|
183 |
|
|
184 |
// Find out where the item was dropped |
|
185 |
int newIndex = this.locationToIndex( dtde.getLocation() ); |
|
186 |
|
|
187 |
// Get the items out of the transferable object and build an |
|
188 |
// array out of them... |
|
189 |
String s = ( String )transferable.getTransferData( DataFlavor.stringFlavor ); |
|
190 |
StringTokenizer st = new StringTokenizer( s ); |
|
191 |
ArrayList items = new ArrayList(); |
|
192 |
while( st.hasMoreTokens() ) { |
|
193 |
items.add( st.nextToken() ); |
|
194 |
} |
|
195 |
JDnDListModel model = ( JDnDListModel )this.getModel(); |
|
196 |
|
|
197 |
// If we are dragging from our this to our list them move the items, |
|
198 |
// otherwise just add them... |
|
199 |
if( this.dragging ) { |
|
200 |
//model.itemsMoved( newIndex, items ); |
|
201 |
model.itemsMoved( newIndex, this.selectedIndices ); |
|
202 |
} else { |
|
203 |
model.insertItems( newIndex, items ); |
|
204 |
} |
|
205 |
|
|
206 |
// Update the selected indicies |
|
207 |
int[] newIndicies = new int[ items.size() ]; |
|
208 |
for( int i=0; i<items.size(); i++ ) { |
|
209 |
newIndicies[ i ] = newIndex + i; |
|
210 |
} |
|
211 |
this.setSelectedIndices( newIndicies ); |
|
212 |
|
|
213 |
// Reset the over index |
|
214 |
this.overIndex = -1; |
|
215 |
|
|
216 |
dtde.getDropTargetContext().dropComplete( true ); |
|
217 |
} else { |
|
218 |
dtde.rejectDrop(); |
|
219 |
} |
|
220 |
} catch( IOException exception ) { |
|
221 |
exception.printStackTrace(); |
|
222 |
System.err.println( "Exception" + exception.getMessage()); |
|
223 |
dtde.rejectDrop(); |
|
224 |
} catch( UnsupportedFlavorException ufException ) { |
|
225 |
ufException.printStackTrace(); |
|
226 |
System.err.println( "Exception" + ufException.getMessage()); |
|
227 |
dtde.rejectDrop(); |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
231 |
/* (non-Javadoc) |
|
232 |
* @see java.awt.dnd.DragSourceListener#dragEnter(java.awt.dnd.DragSourceDragEvent) |
|
233 |
*/ |
|
234 |
public void dragEnter(DragSourceDragEvent dsde) { |
|
235 |
|
|
236 |
} |
|
237 |
|
|
238 |
/* (non-Javadoc) |
|
239 |
* @see java.awt.dnd.DragSourceListener#dragOver(java.awt.dnd.DragSourceDragEvent) |
|
240 |
*/ |
|
241 |
public void dragOver(DragSourceDragEvent dsde) { |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
/* (non-Javadoc) |
|
246 |
* @see java.awt.dnd.DragSourceListener#dropActionChanged(java.awt.dnd.DragSourceDragEvent) |
|
247 |
*/ |
|
248 |
public void dropActionChanged(DragSourceDragEvent dsde) { |
|
249 |
|
|
250 |
} |
|
251 |
|
|
252 |
/* (non-Javadoc) |
|
253 |
* @see java.awt.dnd.DragSourceListener#dragExit(java.awt.dnd.DragSourceEvent) |
|
254 |
*/ |
|
255 |
public void dragExit(DragSourceEvent dse) { |
|
256 |
|
|
257 |
} |
|
258 |
|
|
259 |
/* (non-Javadoc) |
|
260 |
* @see java.awt.dnd.DropTargetListener#dropActionChanged(java.awt.dnd.DropTargetDragEvent) |
|
261 |
*/ |
|
262 |
public void dropActionChanged(DropTargetDragEvent dtde) { |
|
263 |
|
|
264 |
} |
|
265 |
} |
|
0 | 266 |
trunk/libraries/libUI/src/org/gvsig/gui/beans/controls/MultiLineToolTip.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-03-22 11:18:29 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.4 2006/02/28 15:25:14 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume |
|
53 |
* correcciones de bugs |
|
54 |
* |
|
55 |
* Revision 1.3 2006/01/26 16:07:14 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.2.2.1 2006/01/26 12:59:32 jaume |
|
59 |
* 0.5 |
|
60 |
* |
|
61 |
* Revision 1.2 2006/01/24 14:36:33 jaume |
|
62 |
* This is the new version |
|
63 |
* |
|
64 |
* Revision 1.1.2.1 2006/01/17 12:56:03 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* |
|
68 |
*/ |
|
69 |
/** |
|
70 |
* |
|
71 |
*/ |
|
72 |
package org.gvsig.gui.beans.controls; |
|
73 |
|
|
74 |
import java.awt.Dimension; |
|
75 |
import java.awt.FontMetrics; |
|
76 |
import java.awt.Graphics; |
|
77 |
import java.awt.Toolkit; |
|
78 |
import java.io.BufferedReader; |
|
79 |
import java.io.IOException; |
|
80 |
import java.io.StringReader; |
|
81 |
import java.util.Enumeration; |
|
82 |
import java.util.Vector; |
|
83 |
|
|
84 |
import javax.swing.JComponent; |
|
85 |
import javax.swing.JToolTip; |
|
86 |
import javax.swing.SwingUtilities; |
|
87 |
import javax.swing.plaf.metal.MetalToolTipUI; |
|
88 |
|
|
89 |
|
|
90 |
/** |
|
91 |
* <p> |
|
92 |
* Allows using more than one line length tooltips. It also automatically |
|
93 |
* calculates the size of the screen rectangle used and the preferred sized |
|
94 |
* up on the contained text. It does NOT format the text to fit within a |
|
95 |
* given size. The user must provide the text as she/he wishes to show it. |
|
96 |
* </p> |
|
97 |
* <p> |
|
98 |
* It means that new line characters must be placed in the string as well as |
|
99 |
* it was a System.out.println statement. |
|
100 |
* </p> |
|
101 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
102 |
* |
|
103 |
*/ |
|
104 |
public class MultiLineToolTip extends JToolTip { |
|
105 |
public MultiLineToolTip() { |
|
106 |
setUI(new MultiLineToolTipUI()); |
|
107 |
} |
|
108 |
|
|
109 |
private class MultiLineToolTipUI extends MetalToolTipUI { |
|
110 |
private String[] strs; |
|
111 |
|
|
112 |
private int maxWidth = 0; |
|
113 |
|
|
114 |
public void paint(Graphics g, JComponent c) { |
|
115 |
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics( |
|
116 |
g.getFont()); |
|
117 |
Dimension size = c.getSize(); |
|
118 |
g.setColor(c.getBackground()); |
|
119 |
g.fillRect(0, 0, size.width, size.height); |
|
120 |
g.setColor(c.getForeground()); |
|
121 |
if (strs != null) { |
|
122 |
for (int i = 0; i < strs.length; i++) { |
|
123 |
g.drawString(strs[i], 3, (metrics.getHeight()) * (i + 1)); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
public Dimension getPreferredSize(JComponent c) { |
|
129 |
FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics( |
|
130 |
c.getFont()); |
|
131 |
String tipText = ((JToolTip) c).getTipText(); |
|
132 |
if (tipText == null) { |
|
133 |
tipText = ""; |
|
134 |
} |
|
135 |
BufferedReader br = new BufferedReader(new StringReader(tipText)); |
|
136 |
String line; |
|
137 |
int _maxWidth = 0; |
|
138 |
Vector v = new Vector(); |
|
139 |
try { |
|
140 |
while ((line = br.readLine()) != null) { |
|
141 |
int width = SwingUtilities.computeStringWidth(metrics, line); |
|
142 |
_maxWidth = (_maxWidth < width) ? width : _maxWidth; |
|
143 |
v.addElement(line); |
|
144 |
} |
|
145 |
} catch (IOException ex) { |
|
146 |
ex.printStackTrace(); |
|
147 |
} |
|
148 |
int lines = v.size(); |
|
149 |
if (lines < 1) { |
|
150 |
strs = null; |
|
151 |
lines = 1; |
|
152 |
} else { |
|
153 |
strs = new String[lines]; |
|
154 |
int i = 0; |
|
155 |
for (Enumeration e = v.elements(); e.hasMoreElements(); i++) { |
|
156 |
strs[i] = (String) e.nextElement(); |
|
157 |
} |
|
158 |
} |
|
159 |
int height = metrics.getHeight() * lines; |
|
160 |
this.maxWidth = _maxWidth; |
|
161 |
return new Dimension(_maxWidth + 6, height + 4); |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
|
|
0 | 168 |
Also available in: Unified diff