SwtMisc { public static Event copyEvent(Event event) { Event copy = new Event(); copy.display = event.display; copy.widget = event.widget; copy.type = event.type; copy.detail = event.detail; copy.item = event.item; copy.index = event.index; copy.gc = event.gc; copy.x = event.x; copy.y = event.y; copy.width = event.width; copy.height = event.height; copy.count = event.count; copy.time = event.time; copy.button = event.button; copy.character = event.character; copy.keyCode = event.keyCode; copy.keyLocation = event.keyLocation; copy.stateMask = event.stateMask; copy.start = event.start; copy.end = event.end; copy.text = event.text; copy.segments = event.segments; copy.segmentsChars = event.segmentsChars; copy.doit = event.doit; copy.data = event.data; copy.touches = event.touches; copy.xDirection = event.xDirection; copy.yDirection = event.yDirection; copy.magnification = event.magnification; copy.rotation = event.rotation; return copy; }  static boolean flagIsSet(int flag, int style); static boolean flagIsSet(int flag, Widget widget); static int setFlag(int flag, boolean isSet, int style); static Listener asListener(Runnable runnable); static Display assertUI(); static void assertNotUI(); static Color getSystemColor(int code); static Cursor getSystemCursor(int cursor); static Image getSystemIcon(int icon); @Deprecated static void requestLayout(Control control); static void asyncLayout(Composite cmp); static void asyncLayoutOnResize(Composite cmp); static void clean(Composite cmp); static void assertClean(Composite cmp); static Event copyEvent(Event event); static void withGcRun(Consumer<GC> consumer); static T withGcCompute(Function<GC, T> function); static void loopUntil(Predicate<Display> until); static void loopUntilDisposed(Widget widget); static T loopUntilGet(CompletionStage<T> future); static void blockForSuccess(String title, String msg, @Nullable Shell parent); static void blockForSuccess(String title, String msg); static void blockForError(String title, String msg, @Nullable Shell parent); static void blockForError(String title, String msg); static boolean blockForQuestion(String title, String message, @Nullable Shell parent); static boolean blockForQuestion(String title, String message); static boolean blockForOkCancel(String title, String message, @Nullable Shell parent); static boolean blockForOkCancel(String title, String message); static int blockForMessageBox(String title, String message, @Nullable Shell parent, int style); static int blockForMessageBox(String title, String message, int style); static int systemFontHeight(); static int systemFontWidth(); static int systemFontSnug(); static int defaultButtonWidth(); static int defaultDialogWidth(); static Point scaleByFontHeight(int cols, int rows); static int scaleByFontHeight(int rows); static Point scaleByFont(int cols, int rows); static Point scaleByFont(String str); static Rectangle globalBounds(Control control); static Rectangle globalBounds(ControlWrapper control); static Rectangle toDisplay(Control control, Rectangle rect); static Optional<Monitor> monitorFor(Point p); static void setEnabledDeep(Composite root, boolean enabled); static void forEachDeep(Composite root, Consumer<Control> ctlSetter); static void setForegroundDeep(Composite root, Color foreground); static void setBackgroundDeep(Composite root, Color background); static Shell rootShell(Control ctl); static TreeDef.Parented<Composite> treeDefComposite(); static TreeDef.Parented<Control> treeDefControl(); static TreeDef.Parented<Shell> treeDefShell();  }
@Test public void testCopyEvent() { Event original = new Event(); FieldsAndGetters.fields(original).map(Map.Entry::getKey).forEach(Errors.rethrow().wrap(field -> { if (field.getType().equals(boolean.class)) { field.set(original, Math.random() < 0.5 ? false : true); } else if (field.getType().equals(int.class)) { field.set(original, (int) (1000 * Math.random())); } })); Function<Event, List<Object>> getData = e -> FieldsAndGetters.fields(e).map(Map.Entry::getValue).collect(Collectors.toList()); Event copy = SwtMisc.copyEvent(original); Assert.assertEquals(getData.apply(original), getData.apply(copy)); }