Java Code Examples for java.awt.Window#getMinimumSize()

The following examples show how to use java.awt.Window#getMinimumSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowGeometryPersisterImpl.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param scheduledExecutorService it's used to dealy interraction with
 *                                 configPairs to avoid spamming it with values
 *                                 while user still dragging element
 */
public WindowGeometryPersisterImpl(Window window, String windowId, ConfigPairs configPairs,
		ScheduledExecutorService scheduledExecutorService) {
	Preconditions.checkArgument(scheduledExecutorService != null);
	Preconditions.checkArgument(window != null);
	Preconditions.checkArgument(StringUtils.hasText(windowId));
	Preconditions.checkArgument(configPairs != null);

	this.window = window;
	// NOTE: We do + window.getMinimumSize() because from
	// version to version application windows sizes might change
	this.keyId = windowId + "_" + window.getMinimumSize();
	this.configPairs = configPairs;
	this.scheduledExecutorService = scheduledExecutorService;
	window.addComponentListener(this);
}
 
Example 2
Source File: WindowUtils.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
public static void packAndCenterWindowOn(Window window, Component centeredOn) {
    window.pack();
    Dimension prefSize = window.getPreferredSize();
    Dimension minSize  = window.getMinimumSize();
    int       width    = Math.max(prefSize.width, minSize.width);
    int       height   = Math.max(prefSize.height, minSize.height);
    int       x;
    int       y;
    if (centeredOn != null) {
        Point     where = centeredOn.getLocationOnScreen();
        Dimension size  = centeredOn.getSize();
        x = where.x + (size.width - width) / 2;
        y = where.y + (size.height - height) / 2;
    } else {
        Rectangle bounds = getMaximumWindowBounds(window);
        x = bounds.x + (bounds.width - width) / 2;
        y = bounds.y + (bounds.height - height) / 2;
    }
    window.setLocation(x, y);
    forceOnScreen(window);
}
 
Example 3
Source File: WindowSizeEnforcer.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** @param window The window to enforce min/max size on. */
public static void enforce(Window window) {
    Dimension origSize  = window.getSize();
    Dimension otherSize = window.getMinimumSize();
    int       width     = origSize.width;
    int       height    = origSize.height;

    if (width < otherSize.width) {
        width = otherSize.width;
    }
    if (height < otherSize.height) {
        height = otherSize.height;
    }
    otherSize = window.getMaximumSize();
    if (width > otherSize.width) {
        width = otherSize.width;
    }
    if (height > otherSize.height) {
        height = otherSize.height;
    }
    if (width != origSize.width || height != origSize.height) {
        window.setSize(width, height);
    }
}
 
Example 4
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
 */
public void mouseDragged(MouseEvent ev) {
    Window w  = (Window) ev.getSource();
    Point  pt = ev.getPoint();

    if (isMovingWindow) {
        Point eventLocationOnScreen = ev.getLocationOnScreen();

        w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
    } else if (dragCursor != 0) {
        Rectangle r           = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min         = w.getMinimumSize();

        switch (dragCursor) {

        case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;

        case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;

        case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;

        case Cursor.NE_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY));
            break;

        case Cursor.SE_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.NW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY));
            break;

        case Cursor.SW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        default:
            break;
        }

        if (!r.equals(startBounds)) {
            w.setBounds(r);
            // Defer repaint/validate on mouseReleased unless dynamic
            // layout is active.
            if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
                w.validate();
                getRootPane().repaint();
            }
        }
    }
}
 
Example 5
Source File: DecorationUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    isPressed = true;
    startDragLoc = getScreenLoc(e);

    Window w = SwingUtilities.getWindowAncestor((Component)e.getSource());
    startWinBounds = w.getBounds();
    resizedBounds.setBounds(startWinBounds);
    minSize = w.getMinimumSize();
}
 
Example 6
Source File: LizziePane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
public void mouseDragged(MouseEvent e) {
  Window w = (Window) e.getSource();
  Point pt = e.getPoint();

  if (isMovingWindow) {
    Point eventLocationOnScreen = e.getLocationOnScreen();
    w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
  } else if (dragCursor != 0) {
    Rectangle r = w.getBounds();
    Rectangle startBounds = new Rectangle(r);
    Dimension min = w.getMinimumSize();

    switch (dragCursor) {
      case Cursor.E_RESIZE_CURSOR:
        adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
        break;
      case Cursor.S_RESIZE_CURSOR:
        adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.N_RESIZE_CURSOR:
        adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
        break;
      case Cursor.W_RESIZE_CURSOR:
        adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
        break;
      case Cursor.NE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            pt.y - dragOffsetY,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            0,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.NW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            pt.y - dragOffsetY,
            -(pt.x - dragOffsetX),
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            0,
            -(pt.x - dragOffsetX),
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      default:
        break;
    }
    if (!r.equals(startBounds)) {
      w.setBounds(r);
      // Defer repaint/validate on mouseReleased unless dynamic
      // layout is active.
      if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
        w.validate();
        getRootPane().repaint();
      }
    }
  }
}
 
Example 7
Source File: WindowUtils.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Forces the specified window onscreen.
 *
 * @param window The window to force onscreen.
 */
public static void forceOnScreen(Window window) {
    Rectangle maxBounds = getMaximumWindowBounds(window);
    Rectangle bounds    = window.getBounds();
    Point     location  = new Point(bounds.x, bounds.y);
    Dimension size      = window.getMinimumSize();

    if (bounds.width < size.width) {
        bounds.width = size.width;
    }
    if (bounds.height < size.height) {
        bounds.height = size.height;
    }

    if (bounds.x < maxBounds.x) {
        bounds.x = maxBounds.x;
    } else if (bounds.x >= maxBounds.x + maxBounds.width) {
        bounds.x = maxBounds.x + maxBounds.width - 1;
    }

    if (bounds.x + bounds.width >= maxBounds.x + maxBounds.width) {
        bounds.x = maxBounds.x + maxBounds.width - bounds.width;
        if (bounds.x < maxBounds.x) {
            bounds.x = maxBounds.x;
            bounds.width = maxBounds.width;
        }
    }

    if (bounds.y < maxBounds.y) {
        bounds.y = maxBounds.y;
    } else if (bounds.y >= maxBounds.y + maxBounds.height) {
        bounds.y = maxBounds.y + maxBounds.height - 1;
    }

    if (bounds.y + bounds.height >= maxBounds.y + maxBounds.height) {
        bounds.y = maxBounds.y + maxBounds.height - bounds.height;
        if (bounds.y < maxBounds.y) {
            bounds.y = maxBounds.y;
            bounds.height = maxBounds.height;
        }
    }

    if (location.x != bounds.x || location.y != bounds.y) {
        window.setBounds(bounds);
    } else {
        window.setSize(bounds.width, bounds.height);
    }
    window.validate();
}
 
Example 8
Source File: WindowMouseHandler.java    From littleluck with Apache License 2.0 2 votes vote down vote up
public void updateBound(Point pt, Window w)
{
    Rectangle r = w.getBounds();
    Rectangle startBounds = new Rectangle(r);
    Dimension min = w.getMinimumSize();

    switch (dragCursor)
    {
        case Cursor.E_RESIZE_CURSOR:

            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);

            break;

        case Cursor.S_RESIZE_CURSOR:

            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        case Cursor.N_RESIZE_CURSOR:

            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));

            break;

        case Cursor.W_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);

            break;

        case Cursor.NE_RESIZE_CURSOR:

            adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX)
                    - r.width, -(pt.y - dragOffsetY));
            break;
        case Cursor.SE_RESIZE_CURSOR:

            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width,
                    pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        case Cursor.NW_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY,
                    -(pt.x - dragOffsetX), -(pt.y - dragOffsetY));

            break;

        case Cursor.SW_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX),
                    pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        default:

            break;
    }

    if(!r.equals(startBounds))
    {
        w.setBounds(r);

        if (Toolkit.getDefaultToolkit().isDynamicLayoutActive())
        {
            w.validate();
            w.repaint();
        }
    }
}