Revision 2637
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.301/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/test/java/org/gvsig/tools/AppTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
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 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools; |
|
25 |
|
|
26 |
import junit.framework.Test; |
|
27 |
import junit.framework.TestCase; |
|
28 |
import junit.framework.TestSuite; |
|
29 |
|
|
30 |
/** |
|
31 |
* Unit test for simple App. |
|
32 |
*/ |
|
33 |
public class AppTest extends TestCase { |
|
34 |
|
|
35 |
/** |
|
36 |
* @return the suite of tests being tested |
|
37 |
*/ |
|
38 |
public static Test suite() { |
|
39 |
return new TestSuite(AppTest.class); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* Create the test case |
|
44 |
* |
|
45 |
* @param testName |
|
46 |
* name of the test case |
|
47 |
*/ |
|
48 |
public AppTest(String testName) { |
|
49 |
super(testName); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Rigourous Test :-) |
|
54 |
*/ |
|
55 |
public void testApp() { |
|
56 |
assertTrue(true); |
|
57 |
} |
|
58 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.301/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.tools.swing.impl.ToolsSwingDefaultImplLibrary |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.301/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultJListWithCheckbox.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.swing.impl; |
|
3 |
|
|
4 |
import java.awt.Color; |
|
5 |
import java.awt.Dimension; |
|
6 |
import java.awt.Point; |
|
7 |
import java.awt.Rectangle; |
|
8 |
import java.awt.event.MouseAdapter; |
|
9 |
import java.awt.event.MouseEvent; |
|
10 |
import java.beans.Transient; |
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.Iterator; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Set; |
|
15 |
import java.util.Vector; |
|
16 |
import javax.accessibility.AccessibleContext; |
|
17 |
import javax.swing.DefaultListSelectionModel; |
|
18 |
import javax.swing.JList; |
|
19 |
import javax.swing.ListCellRenderer; |
|
20 |
import javax.swing.ListModel; |
|
21 |
import javax.swing.ListSelectionModel; |
|
22 |
import javax.swing.event.ListSelectionEvent; |
|
23 |
import javax.swing.event.ListSelectionListener; |
|
24 |
import javax.swing.plaf.ListUI; |
|
25 |
import javax.swing.text.Position; |
|
26 |
import org.gvsig.tools.swing.api.DefaultCheckListCellRenderer; |
|
27 |
import org.gvsig.tools.swing.api.JListWithCheckbox; |
|
28 |
import org.slf4j.Logger; |
|
29 |
import org.slf4j.LoggerFactory; |
|
30 |
|
|
31 |
public class DefaultJListWithCheckbox extends JListWithCheckbox { |
|
32 |
|
|
33 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJListWithCheckbox.class); |
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
private final JList wrappedList; |
|
38 |
private ListSelectionModel checkedsModel = new DefaultListSelectionModel(); |
|
39 |
private Set<ListSelectionListener> checkedsListeners; |
|
40 |
private final ListSelectionListener checksModelListener; |
|
41 |
private final DefaultCheckListCellRenderer checkListCellRenderer; |
|
42 |
|
|
43 |
public DefaultJListWithCheckbox(final JList wrappedList) { |
|
44 |
this.wrappedList = wrappedList; |
|
45 |
this.checkedsModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
|
46 |
this.checkedsListeners = new HashSet<>(); |
|
47 |
|
|
48 |
this.checkListCellRenderer = new DefaultCheckListCellRenderer( |
|
49 |
this.wrappedList.getCellRenderer(), |
|
50 |
this.checkedsModel |
|
51 |
); |
|
52 |
this.wrappedList.setCellRenderer(this.checkListCellRenderer); |
|
53 |
this.wrappedList.addMouseListener(new MouseAdapter() { |
|
54 |
@Override |
|
55 |
public void mouseClicked(MouseEvent me) { |
|
56 |
int index = wrappedList.locationToIndex(me.getPoint()); |
|
57 |
if (index < 0) { |
|
58 |
return; |
|
59 |
} |
|
60 |
ListCellRenderer renderer = wrappedList.getCellRenderer(); |
|
61 |
int checkBoxWidth = 16; |
|
62 |
if(renderer instanceof DefaultCheckListCellRenderer){ |
|
63 |
checkBoxWidth = ((DefaultCheckListCellRenderer)renderer).getCheckBoxWidth(); |
|
64 |
} |
|
65 |
if (me.getX() > wrappedList.getCellBounds(index, index).getX() + checkBoxWidth) { |
|
66 |
return; |
|
67 |
} |
|
68 |
toggleCheck(index); |
|
69 |
} |
|
70 |
}); |
|
71 |
this.checksModelListener = new ListSelectionListener() { |
|
72 |
@Override |
|
73 |
public void valueChanged(ListSelectionEvent lse) { |
|
74 |
wrappedList.repaint(); |
|
75 |
//fireCheckedsListeners(lse); |
|
76 |
} |
|
77 |
}; |
|
78 |
this.setCheckedModel(checkedsModel); |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public final void setCheckedModel(ListSelectionModel checkedsModel) { |
|
83 |
this.checkedsModel.removeListSelectionListener(this.checksModelListener); |
|
84 |
this.checkedsModel = checkedsModel; |
|
85 |
this.checkedsModel.addListSelectionListener(this.checksModelListener); |
|
86 |
this.checkListCellRenderer.setCheckedModel(checkedsModel); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public void toggleCheck(int index) { |
|
91 |
if (index < 0) { |
|
92 |
return; |
|
93 |
} |
|
94 |
if (this.checkedsModel.isSelectedIndex(index)) { |
|
95 |
this.checkedsModel.removeSelectionInterval(index, index); |
|
96 |
} else { |
|
97 |
this.checkedsModel.addSelectionInterval(index, index); |
|
98 |
} |
|
99 |
// FIXME: isAdjusting is set to false always |
|
100 |
fireCheckedsListeners(new ListSelectionEvent(this, index, index, false)); |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public ListUI getUI() { |
|
105 |
return this.wrappedList.getUI(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public void setUI(ListUI ui) { |
|
110 |
this.wrappedList.setUI(ui); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void updateUI() { |
|
115 |
if( this.wrappedList!= null ) { |
|
116 |
this.wrappedList.updateUI(); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public String getUIClassID() { |
|
122 |
return this.wrappedList.getUIClassID(); |
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public Object getPrototypeCellValue() { |
|
127 |
return this.wrappedList.getPrototypeCellValue(); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public void setPrototypeCellValue(Object prototypeCellValue) { |
|
132 |
this.wrappedList.setPrototypeCellValue(prototypeCellValue); |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public int getFixedCellWidth() { |
|
137 |
return this.wrappedList.getFixedCellWidth(); |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public void setFixedCellWidth(int width) { |
|
142 |
this.wrappedList.setFixedCellWidth(width); |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public int getFixedCellHeight() { |
|
147 |
return this.wrappedList.getFixedCellHeight(); |
|
148 |
} |
|
149 |
|
|
150 |
@Override |
|
151 |
public void setFixedCellHeight(int height) { |
|
152 |
this.wrappedList.setFixedCellHeight(height); |
|
153 |
} |
|
154 |
|
|
155 |
@Transient |
|
156 |
@Override |
|
157 |
public ListCellRenderer getCellRenderer() { |
|
158 |
return this.wrappedList.getCellRenderer(); |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public void setCellRenderer(ListCellRenderer cellRenderer) { |
|
163 |
this.wrappedList.setCellRenderer(cellRenderer); |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public Color getSelectionForeground() { |
|
168 |
return this.wrappedList.getSelectionForeground(); |
|
169 |
} |
|
170 |
|
|
171 |
@Override |
|
172 |
public void setSelectionForeground(Color selectionForeground) { |
|
173 |
this.wrappedList.setSelectionForeground(selectionForeground); |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public Color getSelectionBackground() { |
|
178 |
return this.wrappedList.getSelectionBackground(); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public void setSelectionBackground(Color selectionBackground) { |
|
183 |
this.wrappedList.setSelectionBackground(selectionBackground); |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public int getVisibleRowCount() { |
|
188 |
return this.wrappedList.getVisibleRowCount(); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public void setVisibleRowCount(int visibleRowCount) { |
|
193 |
this.wrappedList.setVisibleRowCount(visibleRowCount); |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public int getLayoutOrientation() { |
|
198 |
return this.wrappedList.getLayoutOrientation(); |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public void setLayoutOrientation(int layoutOrientation) { |
|
203 |
this.wrappedList.setLayoutOrientation(layoutOrientation); |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public int getFirstVisibleIndex() { |
|
208 |
return this.wrappedList.getFirstVisibleIndex(); |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public int getLastVisibleIndex() { |
|
213 |
return this.wrappedList.getLastVisibleIndex(); |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public void ensureIndexIsVisible(int index) { |
|
218 |
this.wrappedList.ensureIndexIsVisible(index); |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public void setDragEnabled(boolean b) { |
|
223 |
this.wrappedList.setDragEnabled(b); |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public boolean getDragEnabled() { |
|
228 |
return this.wrappedList.getDragEnabled(); |
|
229 |
} |
|
230 |
// |
|
231 |
// public final void setDropMode(DropMode dropMode) { |
|
232 |
// this.wrappedList.setDropMode(dropMode); |
|
233 |
// } |
|
234 |
// |
|
235 |
// public final DropMode getDropMode() { |
|
236 |
// |
|
237 |
// } |
|
238 |
// |
|
239 |
// public final DropLocation getDropLocation() { |
|
240 |
// |
|
241 |
// } |
|
242 |
|
|
243 |
@Override |
|
244 |
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) { |
|
245 |
return this.wrappedList.getNextMatch(prefix, startIndex, bias); |
|
246 |
} |
|
247 |
|
|
248 |
@Override |
|
249 |
public String getToolTipText(MouseEvent event) { |
|
250 |
return this.wrappedList.getToolTipText(event); |
|
251 |
} |
|
252 |
|
|
253 |
@Override |
|
254 |
public int locationToIndex(Point location) { |
|
255 |
return this.wrappedList.locationToIndex(location); |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public Point indexToLocation(int index) { |
|
260 |
return this.wrappedList.indexToLocation(index); |
|
261 |
} |
|
262 |
|
|
263 |
@Override |
|
264 |
public Rectangle getCellBounds(int index0, int index1) { |
|
265 |
return this.wrappedList.getCellBounds(index0, index1); |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
269 |
public ListModel getModel() { |
|
270 |
return this.wrappedList.getModel(); |
|
271 |
} |
|
272 |
|
|
273 |
@Override |
|
274 |
public void setModel(ListModel model) { |
|
275 |
this.wrappedList.setModel(model); |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public void setListData(Object[] listData) { |
|
280 |
this.wrappedList.setListData(listData); |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
public void setListData(Vector listData) { |
|
285 |
this.wrappedList.setListData(listData); |
|
286 |
} |
|
287 |
|
|
288 |
@Override |
|
289 |
public ListSelectionModel getSelectionModel() { |
|
290 |
return this.wrappedList.getSelectionModel(); |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public ListSelectionModel getCheckedModel() { |
|
295 |
return this.checkedsModel; |
|
296 |
} |
|
297 |
|
|
298 |
@Override |
|
299 |
public void addListSelectionListener(ListSelectionListener listener) { |
|
300 |
this.wrappedList.addListSelectionListener(listener); |
|
301 |
} |
|
302 |
|
|
303 |
@Override |
|
304 |
public void addChecksListener(ListSelectionListener listener) { |
|
305 |
this.checkedsListeners.add(listener); |
|
306 |
} |
|
307 |
|
|
308 |
@Override |
|
309 |
public void removeListSelectionListener(ListSelectionListener listener) { |
|
310 |
this.wrappedList.removeListSelectionListener(listener); |
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public void removeChecksListener(ListSelectionListener listener) { |
|
315 |
this.checkedsListeners.remove(listener); |
|
316 |
} |
|
317 |
|
|
318 |
@Override |
|
319 |
public ListSelectionListener[] getListSelectionListeners() { |
|
320 |
return this.wrappedList.getListSelectionListeners(); |
|
321 |
} |
|
322 |
|
|
323 |
@Override |
|
324 |
public ListSelectionListener[] getChecksListeners() { |
|
325 |
return this.checkedsListeners.toArray(new ListSelectionListener[1]); |
|
326 |
} |
|
327 |
|
|
328 |
protected void fireCheckedsListeners(ListSelectionEvent event) { |
|
329 |
Iterator<ListSelectionListener> it = this.checkedsListeners.iterator(); |
|
330 |
while(it.hasNext()) { |
|
331 |
ListSelectionListener listener = it.next(); |
|
332 |
try { |
|
333 |
listener.valueChanged(event); |
|
334 |
} catch(Throwable th) { |
|
335 |
LOGGER.warn("Problems calling check listener ("+listener+").",th); |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
@Override |
|
341 |
public void setSelectionModel(ListSelectionModel selectionModel) { |
|
342 |
this.wrappedList.setSelectionModel(selectionModel); |
|
343 |
} |
|
344 |
|
|
345 |
@Override |
|
346 |
public void setSelectionMode(int selectionMode) { |
|
347 |
this.wrappedList.setSelectionMode(selectionMode); |
|
348 |
} |
|
349 |
|
|
350 |
@Override |
|
351 |
public int getSelectionMode() { |
|
352 |
return this.wrappedList.getSelectionMode(); |
|
353 |
} |
|
354 |
|
|
355 |
@Override |
|
356 |
public int getAnchorSelectionIndex() { |
|
357 |
return this.wrappedList.getAnchorSelectionIndex(); |
|
358 |
} |
|
359 |
|
|
360 |
@Override |
|
361 |
public int getLeadSelectionIndex() { |
|
362 |
return this.wrappedList.getLeadSelectionIndex(); |
|
363 |
} |
|
364 |
|
|
365 |
@Override |
|
366 |
public int getMinSelectionIndex() { |
|
367 |
return this.wrappedList.getMinSelectionIndex(); |
|
368 |
} |
|
369 |
|
|
370 |
@Override |
|
371 |
public int getMaxSelectionIndex() { |
|
372 |
return this.wrappedList.getMaxSelectionIndex(); |
|
373 |
} |
|
374 |
|
|
375 |
@Override |
|
376 |
public boolean isSelectedIndex(int index) { |
|
377 |
return this.wrappedList.isSelectedIndex(index); |
|
378 |
} |
|
379 |
|
|
380 |
@Override |
|
381 |
public boolean isSelectionEmpty() { |
|
382 |
return this.wrappedList.isSelectionEmpty(); |
|
383 |
} |
|
384 |
|
|
385 |
@Override |
|
386 |
public void clearSelection() { |
|
387 |
this.wrappedList.clearSelection(); |
|
388 |
} |
|
389 |
|
|
390 |
@Override |
|
391 |
public void setSelectionInterval(int anchor, int lead) { |
|
392 |
this.wrappedList.setSelectionInterval(anchor, lead); |
|
393 |
} |
|
394 |
|
|
395 |
@Override |
|
396 |
public void addSelectionInterval(int anchor, int lead) { |
|
397 |
this.wrappedList.addSelectionInterval(anchor, lead); |
|
398 |
} |
|
399 |
|
|
400 |
@Override |
|
401 |
public void removeSelectionInterval(int index0, int index1) { |
|
402 |
this.wrappedList.removeSelectionInterval(index0, index1); |
|
403 |
} |
|
404 |
|
|
405 |
@Override |
|
406 |
public void setValueIsAdjusting(boolean b) { |
|
407 |
this.wrappedList.setValueIsAdjusting(b); |
|
408 |
} |
|
409 |
|
|
410 |
@Override |
|
411 |
public boolean getValueIsAdjusting() { |
|
412 |
return this.wrappedList.getValueIsAdjusting(); |
|
413 |
} |
|
414 |
|
|
415 |
@Transient |
|
416 |
@Override |
|
417 |
public int[] getSelectedIndices() { |
|
418 |
return this.wrappedList.getSelectedIndices(); |
|
419 |
} |
|
420 |
|
|
421 |
@Override |
|
422 |
public void setSelectedIndex(int index) { |
|
423 |
this.wrappedList.setSelectedIndex(index); |
|
424 |
} |
|
425 |
|
|
426 |
@Override |
|
427 |
public void setSelectedIndices(int[] indices) { |
|
428 |
this.wrappedList.setSelectedIndices(indices); |
|
429 |
} |
|
430 |
|
|
431 |
@Deprecated |
|
432 |
@Override |
|
433 |
public Object[] getSelectedValues() { |
|
434 |
return this.wrappedList.getSelectedValues(); |
|
435 |
} |
|
436 |
|
|
437 |
@Override |
|
438 |
public List getSelectedValuesList() { |
|
439 |
return this.wrappedList.getSelectedValuesList(); |
|
440 |
} |
|
441 |
|
|
442 |
@Override |
|
443 |
public int getSelectedIndex() { |
|
444 |
return this.wrappedList.getSelectedIndex(); |
|
445 |
} |
|
446 |
|
|
447 |
@Override |
|
448 |
public Object getSelectedValue() { |
|
449 |
return this.wrappedList.getSelectedValue(); |
|
450 |
} |
|
451 |
|
|
452 |
@Override |
|
453 |
public void setSelectedValue(Object anObject, boolean shouldScroll) { |
|
454 |
this.wrappedList.setSelectedValue(anObject, shouldScroll); |
|
455 |
} |
|
456 |
|
|
457 |
@Override |
|
458 |
public Dimension getPreferredScrollableViewportSize() { |
|
459 |
return this.wrappedList.getPreferredScrollableViewportSize(); |
|
460 |
} |
|
461 |
|
|
462 |
@Override |
|
463 |
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { |
|
464 |
return this.wrappedList.getScrollableUnitIncrement(visibleRect, orientation, direction); |
|
465 |
} |
|
466 |
|
|
467 |
@Override |
|
468 |
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { |
|
469 |
return this.wrappedList.getScrollableBlockIncrement(visibleRect, orientation, direction); |
|
470 |
} |
|
471 |
|
|
472 |
@Override |
|
473 |
public boolean getScrollableTracksViewportWidth() { |
|
474 |
return this.wrappedList.getScrollableTracksViewportWidth(); |
|
475 |
} |
|
476 |
|
|
477 |
@Override |
|
478 |
public boolean getScrollableTracksViewportHeight() { |
|
479 |
return this.wrappedList.getScrollableTracksViewportHeight(); |
|
480 |
} |
|
481 |
|
|
482 |
@Override |
|
483 |
public AccessibleContext getAccessibleContext() { |
|
484 |
return this.wrappedList.getAccessibleContext(); |
|
485 |
} |
|
486 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.301/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/MessageBarControllerImpl.java | ||
---|---|---|
1 |
package org.gvsig.tools.swing.impl; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
import javax.swing.ImageIcon; |
|
6 |
import javax.swing.JLabel; |
|
7 |
import javax.swing.JOptionPane; |
|
8 |
import javax.swing.SwingUtilities; |
|
9 |
import javax.swing.Timer; |
|
10 |
import javax.swing.text.JTextComponent; |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
12 |
import org.gvsig.tools.swing.api.MessageBarController; |
|
13 |
import org.slf4j.Logger; |
|
14 |
import org.slf4j.LoggerFactory; |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* @author omartinez |
|
19 |
*/ |
|
20 |
public class MessageBarControllerImpl implements MessageBarController { |
|
21 |
|
|
22 |
private JLabel label; |
|
23 |
private int time; |
|
24 |
private final Timer timer; |
|
25 |
private static final Logger LOGGER = LoggerFactory.getLogger(MessageBarControllerImpl.class); |
|
26 |
|
|
27 |
public MessageBarControllerImpl(JLabel label, int time) { |
|
28 |
this.label = label; |
|
29 |
this.time = time; |
|
30 |
this.timer = this.buildTimer(); |
|
31 |
} |
|
32 |
|
|
33 |
private Timer buildTimer() { |
|
34 |
Timer newTimer; |
|
35 |
newTimer = new Timer(this.time, new ActionListener() { |
|
36 |
public void actionPerformed(ActionEvent e) { |
|
37 |
try { |
|
38 |
clear(); |
|
39 |
} catch (Throwable ex) { |
|
40 |
LOGGER.info("Can't clear message", ex); |
|
41 |
} |
|
42 |
} |
|
43 |
}); |
|
44 |
return newTimer; |
|
45 |
} |
|
46 |
|
|
47 |
private String toHTML(String s) { |
|
48 |
s = StringUtils.replace(s, "\n", "\n<br>"); |
|
49 |
s = StringUtils.replace(s, "<html>", ""); |
|
50 |
s = StringUtils.replace(s, "</html>", ""); |
|
51 |
s = "<html>" + s + "</html>"; |
|
52 |
return s; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public void setTime(int time) { |
|
57 |
this.time = time; |
|
58 |
this.timer.setDelay(this.time); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void setText(String msg, int messageType) { |
|
63 |
|
|
64 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
65 |
SwingUtilities.invokeLater(new Runnable() { |
|
66 |
public void run() { |
|
67 |
setText(msg, messageType); |
|
68 |
} |
|
69 |
}); |
|
70 |
return; |
|
71 |
} |
|
72 |
timer.stop(); |
|
73 |
if (StringUtils.isBlank(msg)) { |
|
74 |
this.clear(); |
|
75 |
return; |
|
76 |
} |
|
77 |
label.setText(toHTML(msg)); |
|
78 |
label.paintImmediately(label.getVisibleRect()); |
|
79 |
label.paintImmediately(label.getVisibleRect()); |
|
80 |
timer.start(); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public void setText(String text) { |
|
85 |
this.setText(text, -1); |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public void clear() { |
|
91 |
this.label.setText(""); |
|
92 |
} |
|
93 |
|
|
94 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.301/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultCompoundIcon.java | ||
---|---|---|
1 |
package org.gvsig.tools.swing.impl; |
|
2 |
|
|
3 |
import org.gvsig.tools.swing.api.CompoundIcon; |
|
4 |
import java.awt.Component; |
|
5 |
import java.awt.Graphics; |
|
6 |
import javax.swing.Icon; |
|
7 |
import javax.swing.SwingConstants; |
|
8 |
|
|
9 |
|
|
10 |
/* |
|
11 |
* Based on portions of code from CompoundIcon of Rob Camick |
|
12 |
* Posted on March 29, 2009 in Java Tips Weblog. |
|
13 |
* https://tips4java.wordpress.com/2009/03/29/compound-icon/ |
|
14 |
*/ |
|
15 |
/** |
|
16 |
* The CompoundIcon will paint two, or more, Icons as a single Icon. The Icons |
|
17 |
* are painted in the order in which they are added. |
|
18 |
* |
|
19 |
* The Icons are layed out on the specified axis: |
|
20 |
* <ul> |
|
21 |
* <li>X-Axis (horizontally) |
|
22 |
* <li>Y-Axis (vertically) |
|
23 |
* <li>Z-Axis (stacked) |
|
24 |
* </ul> |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class DefaultCompoundIcon implements CompoundIcon { |
|
28 |
|
|
29 |
private Icon[] icons; |
|
30 |
|
|
31 |
private int orientation; |
|
32 |
|
|
33 |
private int gap; |
|
34 |
|
|
35 |
private int alignmentX = SwingConstants.CENTER; |
|
36 |
private int alignmentY = SwingConstants.CENTER; |
|
37 |
|
|
38 |
/** |
|
39 |
* Convenience contructor for creating a CompoundIcon where the icons are |
|
40 |
* layed out HORIZONTAL, the gap is 0 and the X/Y alignments will |
|
41 |
* default to CENTER. |
|
42 |
* |
|
43 |
* @param icons the Icons to be painted as part of the CompoundIcon |
|
44 |
*/ |
|
45 |
public DefaultCompoundIcon(Icon... icons) { |
|
46 |
this(SwingConstants.HORIZONTAL, icons); |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* Convenience contructor for creating a CompoundIcon where the gap is 0 and |
|
51 |
* the X/Y alignments will default to CENTER. |
|
52 |
* |
|
53 |
* @param orientation the orientation used to lay out the icons for painting. |
|
54 |
* Must be one of SwingConstants.HORIZONTAL, SwingConstants.VERTICAL or STACKED. |
|
55 |
* @param icons the Icons to be painted as part of the CompoundIcon |
|
56 |
*/ |
|
57 |
public DefaultCompoundIcon(int orientation, Icon... icons) { |
|
58 |
this(orientation, 0, icons); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Convenience contructor for creating a CompoundIcon where the X/Y |
|
63 |
* alignments will default to CENTER. |
|
64 |
* |
|
65 |
* @param orientation the orientation used to lay out the icons for painting. |
|
66 |
* Must be one of SwingConstants.HORIZONTAL, SwingConstants.VERTICAL or STACKED. |
|
67 |
* @param gap the gap between the icons |
|
68 |
* @param icons the Icons to be painted as part of the CompoundIcon |
|
69 |
*/ |
|
70 |
public DefaultCompoundIcon(int orientation, int gap, Icon... icons) { |
|
71 |
this(orientation, gap, SwingConstants.CENTER, SwingConstants.CENTER, icons); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Create a CompoundIcon specifying all the properties. |
|
76 |
* |
|
77 |
* @param orientation the orientation used to lay out the icons for painting. |
|
78 |
* Must be one of SwingConstants.HORIZONTAL, SwingConstants.VERTICAL or STACKED. |
|
79 |
* @param gap the gap between the icons |
|
80 |
* @param alignmentX the X alignment of the icons. Common values are LEFT, |
|
81 |
* CENTER, RIGHT. |
|
82 |
* @param alignmentY the Y alignment of the icons. Common values are TOP, |
|
83 |
* CENTER, BOTTOM. |
|
84 |
* @param icons the Icons to be painted as part of the CompoundIcon |
|
85 |
*/ |
|
86 |
public DefaultCompoundIcon(int orientation, int gap, int alignmentX, int alignmentY, Icon... icons) { |
|
87 |
switch (orientation) { |
|
88 |
case SwingConstants.HORIZONTAL: |
|
89 |
case SwingConstants.VERTICAL: |
|
90 |
case STACKED: |
|
91 |
break; |
|
92 |
default: |
|
93 |
throw new IllegalArgumentException("Incorrent value '" + orientation + "' of orientation."); |
|
94 |
} |
|
95 |
switch (alignmentX) { |
|
96 |
case SwingConstants.CENTER: |
|
97 |
case SwingConstants.LEFT: |
|
98 |
case SwingConstants.RIGHT: |
|
99 |
break; |
|
100 |
default: |
|
101 |
throw new IllegalArgumentException("Incorrent value '" + alignmentX + "' of AlignmentX."); |
|
102 |
} |
|
103 |
switch (alignmentY) { |
|
104 |
case SwingConstants.CENTER: |
|
105 |
case SwingConstants.TOP: |
|
106 |
case SwingConstants.BOTTOM: |
|
107 |
break; |
|
108 |
default: |
|
109 |
throw new IllegalArgumentException("Incorrent value '" + alignmentY + "' of AlignmentY."); |
|
110 |
} |
|
111 |
this.orientation = orientation; |
|
112 |
this.gap = gap; |
|
113 |
this.alignmentX = alignmentX; |
|
114 |
this.alignmentY = alignmentY; |
|
115 |
|
|
116 |
for (int i = 0; i < icons.length; i++) { |
|
117 |
if (icons[i] == null) { |
|
118 |
String message = "Icon (" + i + ") cannot be null"; |
|
119 |
throw new IllegalArgumentException(message); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
this.icons = icons; |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* Get the orientation along which each icon is painted. |
|
128 |
* |
|
129 |
* @return the orientation |
|
130 |
*/ |
|
131 |
@Override |
|
132 |
public int getOrientation() { |
|
133 |
return orientation; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Get the gap between each icon |
|
138 |
* |
|
139 |
* @return the gap in pixels |
|
140 |
*/ |
|
141 |
@Override |
|
142 |
public int getGap() { |
|
143 |
return gap; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Get the alignment of the icon on the x-axis |
|
148 |
* |
|
149 |
* @return the alignment |
|
150 |
*/ |
|
151 |
@Override |
|
152 |
public float getAlignmentX() { |
|
153 |
return alignmentX; |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Get the alignment of the icon on the y-axis |
|
158 |
* |
|
159 |
* @return the alignment |
|
160 |
*/ |
|
161 |
@Override |
|
162 |
public float getAlignmentY() { |
|
163 |
return alignmentY; |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Get the number of Icons contained in this CompoundIcon. |
|
168 |
* |
|
169 |
* @return the total number of Icons |
|
170 |
*/ |
|
171 |
@Override |
|
172 |
public int getIconCount() { |
|
173 |
return icons.length; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Get the Icon at the specified index. |
|
178 |
* |
|
179 |
* @param index the index of the Icon to be returned |
|
180 |
* @return the Icon at the specifed index |
|
181 |
* @exception IndexOutOfBoundsException if the index is out of range |
|
182 |
*/ |
|
183 |
@Override |
|
184 |
public Icon getIcon(int index) { |
|
185 |
return icons[index]; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Gets the width of this icon. |
|
190 |
* |
|
191 |
* @return the width of the icon in pixels. |
|
192 |
*/ |
|
193 |
@Override |
|
194 |
public int getIconWidth() { |
|
195 |
int width = 0; |
|
196 |
|
|
197 |
// Add the width of all Icons while also including the gap |
|
198 |
if (orientation == SwingConstants.HORIZONTAL) { |
|
199 |
width += (icons.length - 1) * gap; |
|
200 |
|
|
201 |
for (Icon icon : icons) { |
|
202 |
width += icon.getIconWidth(); |
|
203 |
} |
|
204 |
} else { // Just find the maximum width |
|
205 |
for (Icon icon : icons) { |
|
206 |
width = Math.max(width, icon.getIconWidth()); |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
210 |
return width; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Gets the height of this icon. |
|
215 |
* |
|
216 |
* @return the height of the icon in pixels. |
|
217 |
*/ |
|
218 |
@Override |
|
219 |
public int getIconHeight() { |
|
220 |
int height = 0; |
|
221 |
|
|
222 |
// Add the height of all Icons while also including the gap |
|
223 |
if (orientation == SwingConstants.VERTICAL) { |
|
224 |
height += (icons.length - 1) * gap; |
|
225 |
|
|
226 |
for (Icon icon : icons) { |
|
227 |
height += icon.getIconHeight(); |
|
228 |
} |
|
229 |
} else { // Just find the maximum height |
|
230 |
for (Icon icon : icons) { |
|
231 |
height = Math.max(height, icon.getIconHeight()); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
return height; |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* Paint the icons of this compound icon at the specified location |
|
240 |
* |
|
241 |
* @param c The component on which the icon is painted |
|
242 |
* @param g the graphics context |
|
243 |
* @param x the X coordinate of the icon's top-left corner |
|
244 |
* @param y the Y coordinate of the icon's top-left corner |
|
245 |
*/ |
|
246 |
@Override |
|
247 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
248 |
switch (orientation) { |
|
249 |
default: |
|
250 |
case SwingConstants.HORIZONTAL: |
|
251 |
{ |
|
252 |
int height = getIconHeight(); |
|
253 |
for (Icon icon : icons) { |
|
254 |
int iconY = getOffset(height, icon.getIconHeight(), alignmentY); |
|
255 |
icon.paintIcon(c, g, x, y + iconY); |
|
256 |
x += icon.getIconWidth() + gap; |
|
257 |
} break; |
|
258 |
} |
|
259 |
case SwingConstants.VERTICAL: |
|
260 |
{ |
|
261 |
int width = getIconWidth(); |
|
262 |
for (Icon icon : icons) { |
|
263 |
int iconX = getOffset(width, icon.getIconWidth(), alignmentX); |
|
264 |
icon.paintIcon(c, g, x + iconX, y); |
|
265 |
y += icon.getIconHeight() + gap; |
|
266 |
} break; |
|
267 |
} |
|
268 |
case STACKED: |
|
269 |
{ |
|
270 |
int width = getIconWidth(); |
|
271 |
int height = getIconHeight(); |
|
272 |
for (Icon icon : icons) { |
|
273 |
int iconX = getOffset(width, icon.getIconWidth(), alignmentX); |
|
274 |
int iconY = getOffset(height, icon.getIconHeight(), alignmentY); |
|
275 |
icon.paintIcon(c, g, x + iconX, y + iconY); |
|
276 |
} break; |
|
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
/* |
|
282 |
* When the icon value is smaller than the maximum value of all icons the |
|
283 |
* icon needs to be aligned appropriately. Calculate the offset to be used |
|
284 |
* when painting the icon to achieve the proper alignment. |
|
285 |
*/ |
|
286 |
private int getOffset(int maxValue, int iconValue, int alignment) { |
|
287 |
float offset; |
|
288 |
switch (alignment) { |
|
289 |
case SwingConstants.TOP: |
Also available in: Unified diff