Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart4.png 97% of files have more coverage
23   91   14   4.6
14   48   0.61   5
5     2.8  
1    
 
  DragAwareEventQueue       Line # 34 23 0% 14 25 40.5% 0.4047619
 
No Tests
 
1    /*
2    * Created on Apr 3, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.input;
17   
18    import static java.awt.AWTEvent.MOUSE_EVENT_MASK;
19    import static java.awt.AWTEvent.MOUSE_MOTION_EVENT_MASK;
20    import static java.awt.event.MouseEvent.*;
21    import static javax.swing.SwingUtilities.convertMouseEvent;
22    import static javax.swing.SwingUtilities.getDeepestComponentAt;
23   
24    import java.awt.*;
25    import java.awt.event.AWTEventListener;
26    import java.awt.event.MouseEvent;
27    import java.util.EmptyStackException;
28   
29    /**
30    * Catches native drop target events, which are normally hidden from AWTEventListeners.
31    *
32    * @author Alex Ruiz
33    */
 
34    class DragAwareEventQueue extends EventQueue {
35   
36    private final Toolkit toolkit;
37    private final long mask;
38    private final AWTEventListener eventListener;
39    private final NativeDnDIdentifier nativeDnd;
40   
 
41  4 toggle DragAwareEventQueue(Toolkit toolkit, long mask, AWTEventListener eventListener) {
42  4 this(toolkit, mask, eventListener, new NativeDnDIdentifier());
43    }
44   
 
45  4 toggle DragAwareEventQueue(Toolkit toolkit, long mask, AWTEventListener eventListener, NativeDnDIdentifier nativeDnd) {
46  4 this.toolkit = toolkit;
47  4 this.mask = mask;
48  4 this.eventListener = eventListener;
49  4 this.nativeDnd = nativeDnd;
50    }
51   
52    /**
53    * Stops dispatching events using this <code>EventQueue</code>, only if this <code>EventQueue</code> is the same
54    * as the <code>{@link Toolkit}</code>'s system event queue. Any pending events are transferred to the previous
55    * <code>EventQueue</code> for processing.
56    * @throws EmptyStackException if no previous push was made on this <code>EventQueue</code>.
57    */
 
58  2 toggle @Override public void pop() throws EmptyStackException {
59  2 EventQueue systemEventQueue = toolkit.getSystemEventQueue();
60  1 if (systemEventQueue == this) super.pop();
61    }
62   
63    /**
64    * Dispatch native drag/drop events the same way non-native drags are reported. Enter/Exit are reported with the
65    * appropriate source, while drag and release events use the drag source as the source.
66    * @param e an instance of <code>java.awt.AWTEvent</code>.
67    */
 
68  1 toggle @Override protected void dispatchEvent(AWTEvent e) {
69    // TODO: implement enter/exit events
70    // TODO: change source to drag source, not mouse under
71  1 if (nativeDnd.isNativeDragAndDrop(e)) {
72  0 MouseEvent mouseEvent = (MouseEvent) e;
73  0 Component target = getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
74  0 if (target != mouseEvent.getSource())
75  0 mouseEvent = convertMouseEvent(mouseEvent.getComponent(), mouseEvent, target);
76  0 relayDnDEvent(mouseEvent);
77    }
78  1 super.dispatchEvent(e);
79    }
80   
 
81  0 toggle private void relayDnDEvent(MouseEvent event) {
82  0 int eventId = event.getID();
83  0 if (eventId == MOUSE_MOVED || eventId == MOUSE_DRAGGED) {
84  0 if ((mask & MOUSE_MOTION_EVENT_MASK) != 0) eventListener.eventDispatched(event);
85  0 return;
86    }
87  0 if (eventId >= MOUSE_FIRST && eventId <= MOUSE_LAST) {
88  0 if ((mask & MOUSE_EVENT_MASK) != 0) eventListener.eventDispatched(event);
89    }
90    }
91    }