public void hook(IWidget widget) { final Display display = widget.getDisplay(); if (this.display != null && this.display != display) { throw new IllegalArgumentException("Widget needs to be on same display"); } else { if (display == null) { throw new IllegalArgumentException("Widget needs to be in the widgettree."); } this.display = display; this.widget = widget; display.addGlobalEventListener(listener); } }
/** * Make this window draggable or not * * @param b whether the window should be movable with the mouse or not */ public void setMovable(boolean b) { if (!b) { if (moveDnDListener != null) { Display d = getDisplay(); if (d == null) throw new IllegalStateException("Uh, sorry, the window has to be in the widget tree"); d.removeDndListener(moveDnDListener); } } else { if (moveDnDListener == null) { Display d = getDisplay(); if (d == null) throw new IllegalStateException("Uh, sorry, the window has to be in the widget tree"); moveDnDListener = new WindowMoveDnDListenerImpl(); d.addDndListener(moveDnDListener); } } }
public void unHook(IWidget widget) { if (display != null) { if (widget == this.widget) { display.removeGlobalEventListener(listener); display = null; this.widget = null; } else { throw new IllegalArgumentException("needs to be the hooked widget."); } } else { throw new IllegalStateException("first you need to hook onto a widget."); } }
/** * Make this window resizable with the mouse or not. * * @param b flag whether the window shall be resizable or not */ public void setResizable(boolean b) { if (!b) { if (resizeDnDListener != null) { Display d = getDisplay(); if (d == null) throw new IllegalStateException( "Uh, sorry, the window has to be in the widget tree if you want to disable resizing :)"); d.removeDndListener(resizeDnDListener); resizeDnDListener = null; } } else { if (resizeDnDListener == null) { Display d = getDisplay(); if (d == null) throw new IllegalStateException( "Uh, sorry, the window has to be in the widget tree if you want to enable resizing :)"); d.removeDndListener( resizeDnDListener); // first remove old instance (in case of two subsequent // setResizable(true) calls) resizeDnDListener = new WindowResizeDnDListenerImpl(); d.addDndListener(resizeDnDListener); } } }