Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Utility to simplify event listener notifcation of SWT widgets. Basically created for JUnit testing.

View SWTEventHelper.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Touch;
import org.eclipse.swt.widgets.Widget;
 
public class SWTEventHelper {
 
private final Event event;
 
private SWTEventHelper( int eventType ) {
event = new Event();
event.type = eventType;
}
 
public static SWTEventHelper trigger( int eventType ) {
return new SWTEventHelper( eventType );
}
 
public SWTEventHelper atX( int x ) {
event.x = x;
return this;
}
 
public SWTEventHelper atY( int y ) {
event.y = y;
return this;
}
 
public SWTEventHelper at( int x, int y ) {
return atX( x ).atY( y );
}
 
public SWTEventHelper withCount( int count ) {
event.count = count;
return this;
}
 
public SWTEventHelper withStateMask( int stateMask ) {
event.stateMask = stateMask;
return this;
}
 
public SWTEventHelper withButton( int button ) {
event.button = button;
return this;
}
 
public SWTEventHelper withCharacter( char character ) {
event.character = character;
return this;
}
 
public SWTEventHelper withData( Object data ) {
event.data = data;
return this;
}
 
public SWTEventHelper withDetail( int detail ) {
event.detail = detail;
return this;
}
 
public SWTEventHelper withEnd( int end ) {
event.end = end;
return this;
}
 
public SWTEventHelper withStart( int start ) {
event.start = start;
return this;
}
 
public SWTEventHelper withRange( int start, int end ) {
return withStart( start ).withEnd( end );
}
 
public SWTEventHelper withGC( GC gc ) {
event.gc = gc;
return this;
}
 
public SWTEventHelper withWidth( int width ) {
event.width = width;
return this;
}
 
public SWTEventHelper withHeight( int height ) {
event.height = height;
return this;
}
 
public SWTEventHelper withSize( int width, int height ) {
return withWidth( width ).withHeight( height );
}
 
public SWTEventHelper withIndex( int index ) {
event.index = index;
return this;
}
 
public SWTEventHelper withItem( Widget item ) {
event.item = item;
return this;
}
 
public SWTEventHelper withKeyCode( int keyCode ) {
event.keyCode = keyCode;
return this;
}
 
public SWTEventHelper withKeyLocation( int keyLocation ) {
event.keyLocation = keyLocation;
return this;
}
 
public SWTEventHelper withMagnification( double magnification ) {
event.magnification = magnification;
return this;
}
 
public SWTEventHelper withRotation( double rotation ) {
event.rotation = rotation;
return this;
}
 
public SWTEventHelper withText( String text ) {
event.text = text;
return this;
}
 
public SWTEventHelper withTime( int time ) {
event.time = time;
return this;
}
 
public SWTEventHelper withTouches( Touch[] touches ) {
event.touches = touches;
return this;
}
 
public SWTEventHelper withXDirection( int xDirection ) {
event.xDirection = xDirection;
return this;
}
 
public SWTEventHelper withYDirection( int yDirection ) {
event.yDirection = yDirection;
return this;
}
 
public void on( Widget widget ) {
event.widget = widget;
event.display = widget.getDisplay();
widget.notifyListeners( event.type, event );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.