public InputViewer(Shell parent, Properties properties, String resources) { sShell = new org.eclipse.swt.widgets.Shell(parent); sShell.setLocation(parent.getLocation().x + 200, parent.getLocation().y + 150); sShell.setSize(new org.eclipse.swt.graphics.Point(471, 146)); sShell.setLayout(null); listeners = new Vector<DialogInputListener>(); ApplicationFactory factory = new ApplicationFactory(sShell, resources, getClass().getName()); factory.createLabel("lbl").setBounds(15, 15, 100, 20); txtName = factory.createText(); txtName.setBounds(120, 15, 280, 20); txtName.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode != 13) return; enter(); } }); factory .createButton( "but", new SelectionAdapter() { @SuppressWarnings("unused") public void widgetSelected(SelectionEvent e) { enter(); } }) .setBounds(180, 50, 90, 20); sShell.setSize(420, 120); sShell.open(); }
@Override protected void configureShell(Shell shell) { super.configureShell(shell); Shell s2 = shell.getParent().getShell(); if (s2 != null) shell.setLocation(s2.getLocation()); shell.setBounds(shell.getLocation().x, shell.getLocation().y, 550, 500); if (domain == null) shell.setText(CredentialMessages.AddACredentialDomain); else { shell.setText(CredentialMessages.EditACredentialDomain); } }
private void maximize() { mNonMaximizedLocation = mShell.getLocation(); mNonMaximizedSize = mShell.getSize(); Monitor monitor = mShell.getMonitor(); mShell.setBounds(monitor.getBounds()); }
/** Adjusts form size according to contents dimensions */ public void resize() { Shell sh = parentComposite.getShell(); Point p0 = sh.getLocation(); Point p1 = sh.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); Rectangle r = sh.getDisplay().getClientArea(); p1.x = Math.min(p1.x, (r.width - p0.x)); p1.y = Math.min(p1.y, (r.height - p0.y)); sh.setSize(p1); }
/** * (non-Javadoc) * * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) */ protected Point getInitialLocation(Point initialSize) { Shell parent = getParentShell(); Point parentSize, parentLocation; if (parent != null) { parentSize = parent.getSize(); parentLocation = parent.getLocation(); } else { Rectangle bounds = getShell().getDisplay().getBounds(); parentSize = new Point(bounds.width, bounds.height); parentLocation = new Point(0, 0); } // We have to take parent location into account because SWT considers all // shell locations to be in display coordinates, even if the shell is parented. return new Point( parentSize.x - initialSize.x + parentLocation.x - POPUP_OFFSET, parentSize.y - initialSize.y + parentLocation.y - POPUP_OFFSET); }
public Point getLocation() { return shell.getLocation(); }
private void doResize(int side, MouseEvent e) { if (sideCurrentlyResizing == SIDE_NONE) { Cursor cursor = null; switch (side) { case SIDE_TOP_LEFT: case SIDE_BOTTOM_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENWSE); break; case SIDE_LEFT: case SIDE_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZEWE); break; case SIDE_BOTTOM_LEFT: case SIDE_TOP_RIGHT: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENESW); break; case SIDE_TOP: case SIDE_BOTTOM: cursor = CursorCache.getCursor(SWT.CURSOR_SIZENS); break; } mShell.setCursor(cursor); } // this clause deals with shell resizing as our shell has no borders but we still need to mimic // it // it's all just location and size pushing to simulate a mouse resize if (sideCurrentlyResizing != SIDE_NONE) { // do shell resize Point point = Display.getDefault().map(mShell, null, e.x, e.y); int deltaX = e.x - mMouseDownLoc.x; int deltaY = e.y - mMouseDownLoc.y; switch (sideCurrentlyResizing) { case SIDE_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, mShell.getLocation().y); mShell.setSize(mShell.getSize().x - deltaX, mShell.getSize().y); break; case SIDE_BOTTOM: mShell.setSize(mShell.getSize().x, mShellSizeBeforeResize.y + deltaY); break; case SIDE_RIGHT: mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShell.getSize().y); break; case SIDE_TOP: mShell.setSize(mShellSizeBeforeResize.x, mShell.getSize().y - deltaY); mShell.setLocation(mShell.getLocation().x, point.y - mMouseDownLoc.y); break; case SIDE_TOP_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, point.y - mMouseDownLoc.y); mShell.setSize(mShell.getSize().x - deltaX, mShell.getSize().y - deltaY); break; case SIDE_BOTTOM_LEFT: mShell.setLocation(point.x - mMouseDownLoc.x, mShell.getLocation().y); mShell.setSize(mShell.getSize().x - deltaX, mShellSizeBeforeResize.y + deltaY); break; case SIDE_BOTTOM_RIGHT: mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShellSizeBeforeResize.y + deltaY); break; case SIDE_TOP_RIGHT: mShell.setLocation(mShell.getLocation().x, point.y - mMouseDownLoc.y); mShell.setSize(mShellSizeBeforeResize.x + deltaX, mShell.getSize().y - deltaY); break; } /* // TODO: Make this pretty and flicker-less if (mShell.getSize().x < 40) mShell.setSize(40, mShell.getSize().y); if (mShell.getSize().y < 40); mShell.setSize(mShell.getSize().y, 40);*/ } }
private void animation20_Runnable() { // final long start = System.nanoTime(); if (_shell == null || _shell.isDisposed() || _shell.isVisible() == false) { return; } try { /* * endAlpha will be the final fadeIn/fadeOut value when the animation stops */ int finalFadeAlpha = -1; int currentAlpha = _shell.getAlpha(); boolean isLoopBreak = false; _animationMoveCounter++; while (true) { int newAlpha = -1; if (_isShellFadingIn) { final int shellStartX = _shellStartLocation.x; final int shellStartY = _shellStartLocation.y; final int shellEndX = _shellEndLocation.x; final int shellEndY = _shellEndLocation.y; final Point shellCurrentLocation = _shell.getLocation(); final boolean isInTarget = shellCurrentLocation.x == shellEndX && shellCurrentLocation.y == shellEndY; final int diffAlpha = ALPHA_OPAQUE / _fadeInSteps; newAlpha = currentAlpha + diffAlpha; if (newAlpha > ALPHA_OPAQUE) { newAlpha = ALPHA_OPAQUE; } finalFadeAlpha = ALPHA_OPAQUE; if (isInTarget && currentAlpha == ALPHA_OPAQUE) { // target is reached and fully visible, stop animation _isShellFadingIn = false; return; } else { if (isInTarget == false) { // move to target final int diffX = shellStartX - shellEndX; final int diffY = shellStartY - shellEndY; final double moveX = (double) diffX / MOVE_STEPS * _animationMoveCounter; final double moveY = (double) diffY / MOVE_STEPS * _animationMoveCounter; final int shellCurrentX = (int) (shellStartX - moveX); final int shellCurrentY = (int) (shellStartY - moveY); _shell.setLocation(shellCurrentX, shellCurrentY); } } } else if (_isShellFadingOut) { if (_fadeOutDelayCounter++ < FADE_OUT_DELAY_STEPS) { // delay fade out _display.timerExec(FADE_TIME_INTERVAL, _animationTimer); return; } final int alphaDiff = ALPHA_OPAQUE / _fadeOutSteps; newAlpha = currentAlpha - alphaDiff; finalFadeAlpha = 0; if (newAlpha <= 0) { // shell is not visible any more, hide it now _shell.setAlpha(0); // hide shell setShellVisible(false); _isShellFadingOut = false; return; } } if (newAlpha == -1) { return; } else { if (newAlpha != currentAlpha) { _shell.setAlpha(newAlpha); } if (_shell.getAlpha() != newAlpha) { // platform do not support shell alpha, this occured on Ubuntu 12.04 if (isLoopBreak) { break; } // loop only once isLoopBreak = true; currentAlpha = finalFadeAlpha; continue; } else { _display.timerExec(FADE_TIME_INTERVAL, _animationTimer); break; } } } } catch (final Exception err) { StatusUtil.log(err); } finally { // final float timeDiff = (float) (System.nanoTime() - start) / 1000000; // System.out.println(UI.timeStampNano() + " animation20_Runnable:\t" + timeDiff + " ms\t" + // " ms"); // // TODO remove SYSTEM.OUT.PRINTLN } }
private void animation10_StartKomplex() { // final long start = System.nanoTime(); if (_isShellFadingIn) { // set fading in location final Point shellSize = _shell.getSize(); Point shellEndLocation = getToolTipLocation(shellSize); shellEndLocation = fixupDisplayBounds(shellSize, shellEndLocation); final boolean isShellVisible = _shell.isVisible(); if (shellEndLocation.x == _shellEndLocation.x && shellEndLocation.y == _shellEndLocation.y && isShellVisible) { // shell is already fading in with the correct location return; } // set new end location _shellEndLocation = shellEndLocation; if (isShellVisible) { // shell is already visible, move from the current position to the target position _shellStartLocation = _shell.getLocation(); } else { // shell is not visible, set position directly without moving animation, do only fading // animation _shellStartLocation = _shellEndLocation; _shell.setLocation(_shellStartLocation.x, _shellStartLocation.y); _shell.setAlpha(0); setShellVisible(true); } } else if (_isShellFadingOut) { // fading out has no movement _fadeOutDelayCounter = 0; } // start animation now _animationMoveCounter = 0; animation20_Runnable(); // System.out.println(UI.timeStampNano() // + " animation10_StartKomplex\t" // + ((float) (System.nanoTime() - start) / 1000000) // + " ms"); // // TODO remove SYSTEM.OUT.PRINTLN }
protected void configureShell(Shell shell) { super.configureShell(shell); shell.setBounds(shell.getLocation().x, shell.getLocation().y, 400, 300); }