gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / Utils.java @ 2846
History | View | Annotate | Download (2.04 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.tools.swing.impl; |
7 |
|
8 |
import java.awt.event.FocusEvent; |
9 |
import java.awt.event.FocusListener; |
10 |
import org.apache.commons.lang3.ArrayUtils; |
11 |
import org.slf4j.Logger; |
12 |
import org.slf4j.LoggerFactory; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author jjdelcerro
|
17 |
*/
|
18 |
public class Utils { |
19 |
private static final Logger LOGGER = LoggerFactory.getLogger(Utils.class); |
20 |
|
21 |
private Utils() {
|
22 |
// No se debe instanciar
|
23 |
} |
24 |
|
25 |
public static void fireFocusEvent(java.awt.Component c, int eventId) { |
26 |
FocusListener[] focusListeners = c.getListeners(FocusListener.class); |
27 |
if( !ArrayUtils.isEmpty(focusListeners) ) {
|
28 |
for (FocusListener focusListener : focusListeners) { |
29 |
if( focusListener == null ) { |
30 |
continue;
|
31 |
} |
32 |
try {
|
33 |
FocusEvent e = new FocusEvent(c, eventId); |
34 |
switch(eventId) {
|
35 |
case FocusEvent.FOCUS_GAINED: |
36 |
focusListener.focusGained(e); |
37 |
break;
|
38 |
case FocusEvent.FOCUS_LOST: |
39 |
focusListener.focusLost(e); |
40 |
break;
|
41 |
} |
42 |
} catch(Throwable t) { |
43 |
LOGGER.warn("Can't fire eveny focusGained on DropDownLabel ("+focusListener.getClass().getName()+").",t); |
44 |
} |
45 |
} |
46 |
} |
47 |
} |
48 |
|
49 |
public static void propagateFocusEvent(java.awt.Component source, java.awt.Component target) { |
50 |
source.addFocusListener(new FocusListener() { |
51 |
@Override
|
52 |
public void focusGained(FocusEvent e) { |
53 |
fireFocusEvent(target, FocusEvent.FOCUS_GAINED);
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
public void focusLost(FocusEvent e) { |
58 |
fireFocusEvent(target, FocusEvent.FOCUS_LOST);
|
59 |
} |
60 |
}); |
61 |
} |
62 |
} |