View Javadoc

1   /*
2    * $Id: SelectionEvent.java,v 1.18 2011/06/16 09:29:40 jbmeslin Exp $
3    * 
4    */
5   package org.rcfaces.core.event;
6   
7   import javax.faces.component.UIComponent;
8   import javax.faces.event.ActionEvent;
9   import javax.faces.event.FacesListener;
10  
11  /**
12   * @author Olivier Oeuillot (latest modification by $Author: jbmeslin $)
13   * @version $Revision: 1.18 $ $Date: 2011/06/16 09:29:40 $
14   */
15  public class SelectionEvent extends ActionEvent implements ITypedEvent {
16      private static final String REVISION = "$Revision: 1.18 $";
17  
18      private static final long serialVersionUID = 3488075281502266801L;
19  
20      public static final int SELECTED_EVENT_TYPE = 0x100;
21  
22      public static final int DEFAULT_SELECTED_EVENT_TYPE = 0x102;
23  
24      public static final int UNKNOWN_POSITION = -1;
25  
26      public static final int UNKNOWN_KEY = -1;
27  
28      public static final int UNKNOWN_BUTTONS = 0x8000;
29  
30      public static final int UNKNOWN_MODIFIERS = 0x8000;
31  
32      public static final int BUTTON_1 = 0x01;
33  
34      public static final int BUTTON_2 = 0x02;
35  
36      public static final int BUTTON_3 = 0x04;
37  
38      public static final int MODIFIER_ALT = 0x01;
39  
40      public static final int MODIFIER_CTRL = 0x02;
41  
42      public static final int MODIFIER_SHIFT = 0x04;
43  
44      private final int type;
45  
46      private final int keyCode;
47  
48      private final int mouseX;
49  
50      private final int mouseY;
51  
52      private final int buttonsMask;
53  
54      private final int modifiersMask;
55  
56      private String value;
57  
58      private Object valueObject;
59  
60      private Object item;
61  
62      public SelectionEvent(UIComponent component, String value,
63              Object valueObject, Object item, int detail) {
64          this(component, computeTypeFromDetail(detail), UNKNOWN_POSITION,
65                  UNKNOWN_POSITION, UNKNOWN_BUTTONS, UNKNOWN_MODIFIERS,
66                  UNKNOWN_KEY);
67  
68          this.value = value;
69          this.valueObject = valueObject;
70          this.item = item;
71      }
72  
73      private static int computeTypeFromDetail(int detail) {
74          // XXX A terminer !
75          return 0;
76      }
77  
78      public SelectionEvent(UIComponent component, int type, int mouseX,
79              int mouseY, int buttonsMask, int modifiersMask) {
80          this(component, type, mouseX, mouseY, buttonsMask, modifiersMask,
81                  UNKNOWN_KEY);
82      }
83  
84      public SelectionEvent(UIComponent component, int type, int mouseX,
85              int mouseY, int buttonsMask, int modifiersMask, int keyCode) {
86          super(component);
87  
88          this.type = type;
89  
90          this.mouseX = mouseX;
91          this.mouseY = mouseY;
92  
93          this.buttonsMask = buttonsMask;
94          this.modifiersMask = modifiersMask;
95          this.keyCode = keyCode;
96      }
97  
98      public int getType() {
99          return type;
100     }
101 
102     public Object getItem() {
103         return item;
104     }
105 
106     public String getValue() {
107         return value;
108     }
109 
110     public Object getValueObject() {
111         return valueObject;
112     }
113 
114     public int getButtonsMask() {
115         return buttonsMask;
116     }
117 
118     public int getKeyCode() {
119         return keyCode;
120     }
121 
122     public int getModifiersMask() {
123         return modifiersMask;
124     }
125 
126     public int getMouseX() {
127         return mouseX;
128     }
129 
130     public int getMouseY() {
131         return mouseY;
132     }
133 
134     public boolean isAppropriateListener(FacesListener listener) {
135 
136         if (listener instanceof ISelectionListener) {
137             return true;
138         }
139 
140         return super.isAppropriateListener(listener);
141     }
142 
143     public void processListener(FacesListener listener) {
144         if (listener instanceof ISelectionListener) {
145             ((ISelectionListener) listener).componentSelected(this);
146             return;
147         }
148 
149         super.processListener(listener);
150     }
151 
152 }