Java Code Examples for javax.swing.JFrame#getExtendedState()

The following examples show how to use javax.swing.JFrame#getExtendedState() . These examples are extracted from open source projects. 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 Project: seaglass   File: SeaGlassTitlePane.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Maximize/Restore the window.
 *
 * @param maximize iconify {@code true} if we are to maximize the window,
 *                 {@code false} if we are to restore the window.
 */
private void setParentMaximum(boolean maximize) {
    if (rootParent instanceof JFrame) {
        JFrame frame = (JFrame) rootParent;
        int    state = frame.getExtendedState();

        if (maximize) {
            GraphicsConfiguration gc = frame.getGraphicsConfiguration();
            Insets                i  = Toolkit.getDefaultToolkit().getScreenInsets(gc);
            Rectangle             r  = gc.getBounds();

            r.x      = 0;
            r.y      = 0;
            r.width  -= i.left + i.right;
            r.height -= i.top + i.bottom;
            frame.setMaximizedBounds(r);
        }

        frame.setExtendedState(maximize ? state | Frame.MAXIMIZED_BOTH : state & ~Frame.MAXIMIZED_BOTH);
    }
}
 
Example 2
Source Project: ghidra   File: AbstractDockingTool.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void toFront() {
	JFrame frame = winMgr.getRootFrame();
	if (frame.getExtendedState() == Frame.ICONIFIED) {
		frame.setExtendedState(Frame.NORMAL);
	}
	frame.toFront();
}
 
Example 3
Source Project: FancyBing   File: GuiUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Check window for normal state.
    Checks if window is not maximized (in either or both directions) and
    not iconified. */
public static boolean isNormalSizeMode(JFrame window)
{
    int state = window.getExtendedState();
    int mask = Frame.MAXIMIZED_BOTH | Frame.MAXIMIZED_VERT
        | Frame.MAXIMIZED_HORIZ | Frame.ICONIFIED;
    return ((state & mask) == 0);
}
 
Example 4
/**
 * Minimize the provided frame.
 *
 * @param frame the frame to minimize to icon
 * @see #unMinimize(JFrame)
 */
public static void minimize (JFrame frame)
{
    int state = frame.getExtendedState();
    state &= ICONIFIED;
    frame.setExtendedState(state);
}
 
Example 5
/**
 * Restore a frame, possibly minimized, to the front (either normal or maximized)
 *
 * @param frame the frame to show
 * @see #minimize(JFrame)
 */
public static void unMinimize (JFrame frame)
{
    int state = frame.getExtendedState();

    if ((state & ICONIFIED) != 0) {
        state &= ~ICONIFIED;
    }

    frame.setExtendedState(state);

    frame.setVisible(true);
    frame.toFront();
}
 
Example 6
@Override
public void componentMoved(ComponentEvent e) {
  if (!(e.getComponent() instanceof JFrame))
    return;
  JFrame frame = (JFrame) e.getComponent();
  int state = frame.getExtendedState();
  isMaximized = ((state & Frame.MAXIMIZED_HORIZ) != 0) && ((state & Frame.MAXIMIZED_VERT) != 0);
  if (!isMaximized) {
    position = frame.getLocation();
  }
}
 
Example 7
@Override
public void componentResized(ComponentEvent e) {
  if (!(e.getComponent() instanceof JFrame))
    return;
  JFrame frame = (JFrame) e.getComponent();
  int state = frame.getExtendedState();
  isMaximized = ((state & Frame.MAXIMIZED_HORIZ) != 0) && ((state & Frame.MAXIMIZED_VERT) != 0);
  if (!isMaximized) {
    dimension = frame.getSize();
  }
}
 
Example 8
Source Project: seaglass   File: SeaGlassTitlePane.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Iconify/Restore the window.
 *
 * @param iconify {@code true} if we are to iconify the window,
 *                {@code false} if we are to restore the window.
 */
private void setParentIcon(boolean iconify) {
    if (rootParent instanceof JFrame) {
        JFrame frame = (JFrame) rootParent;
        int    state = frame.getExtendedState();

        ((JFrame) rootParent).setExtendedState(iconify ? state | Frame.ICONIFIED : state & ~Frame.ICONIFIED);
    }
}
 
Example 9
public static void savePrefs(JFrame frame, ColourChooser chooser, LayerManager layers)
{
	Preferences prefs = Preferences.userNodeForPackage(UserPreferences.class);
	
	if((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH)
	{
		prefs.putBoolean(WINDOW_MAXIMIZED, true);
	}
	else
	{
		windowWidth = frame.getWidth();
		windowHeight = frame.getHeight();
		prefs.putInt(WINDOW_WIDTH, windowWidth);
		prefs.putInt(WINDOW_HEIGHT, windowHeight);
		prefs.putBoolean(WINDOW_MAXIMIZED, false);
	}
	colourPickerX = chooser.getX();
	colourPickerY = chooser.getY();
	colourPickerMode = chooser.getMode();
	prefs.putInt(COLOUR_PICKER_X, colourPickerX);
	prefs.putInt(COLOUR_PICKER_Y, colourPickerY);
	prefs.putInt(COLOUR_PICKER_MODE, colourPickerMode);
	prefs.putBoolean(COLOUR_PICKER_VISIBLE, chooser.isVisible());
	
	layersX = layers.dialog.getX();
	layersY = layers.dialog.getY();
	layersWidth = layers.dialog.getWidth();
	layersHeight = layers.dialog.getHeight();
	prefs.putInt(LAYERS_X, layersX);
	prefs.putInt(LAYERS_Y, layersY);
	prefs.putInt(LAYERS_WIDTH, layersWidth);
	prefs.putInt(LAYERS_HEIGHT, layersHeight);
	prefs.putBoolean(LAYERS_VISIBLE, layers.isVisible());
	
	prefs.putBoolean(COLOUR_PICKER_VISIBLE, chooser.isVisible());
	
	prefs.putBoolean(BACKGROUND_DARK, Menu.DARK_BACKGROUND);
}
 
Example 10
Source Project: littleluck   File: WindowMouseHandler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 处理JFrame的双击标题面板缩放事件
 */
public void mouseClicked(MouseEvent e)
{
    Window window = (Window) e.getSource();

    if(window instanceof JFrame)
    {
        JFrame frame = (JFrame) window;

        JRootPane root = frame.getRootPane();

        // 不包含窗体装饰直接返回
        if (root.getWindowDecorationStyle() == JRootPane.NONE)
        {
            return;
        }

        // 不在标题栏覆盖区域直接返回
        if(!titleArea.contains(e.getPoint()))
        {
            return;
        }

        if ((e.getClickCount() % 2) == 0 && ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0))
        {
            int state = frame.getExtendedState();

            if (frame.isResizable())
            {
                if ((state & JFrame.MAXIMIZED_BOTH) != 0)
                {
                    frame.setExtendedState(state & ~JFrame.MAXIMIZED_BOTH);
                }
                else
                {
                    frame.setExtendedState(state | JFrame.MAXIMIZED_BOTH);
                }
            }
        }
    }
}
 
Example 11
Source Project: littleluck   File: WindowMouseHandler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 *  v1.0.1:修复自定义拖拽区域BUG, 增加边界判断
 */
public void mousePressed(MouseEvent e)
{
    Window window = (Window) e.getSource();

    JRootPane root = LuckWindowUtil.getRootPane(window);

    // 不包含窗体装饰直接返回
    if (root == null || root.getWindowDecorationStyle() == JRootPane.NONE)
    {
        return;
    }
    
    if (window != null)
    {
        window.toFront();
    }

    // 如果是单击标题栏, 则标记接下来的拖动事件为移动窗口, 判断当前鼠标是否超出边界
    if (dragArea.contains(e.getPoint())
            && dragCursor == Cursor.DEFAULT_CURSOR)
    {
        if(window instanceof JFrame)
        {
            JFrame frame = (JFrame)window;

            // 如果当前窗体是全屏状态则直接返回
            if(frame.getExtendedState() == JFrame.MAXIMIZED_BOTH)
            {
                return;
            }
        }

        // 设置为可以移动并记录当前坐标
        isMovingWindow = true;

        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;
    }
    else if(LuckWindowUtil.isResizable(window))
    {
        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;

        dragWidth = window.getWidth();

        dragHeight = window.getHeight();

        JRootPane rootPane = LuckWindowUtil.getRootPane(window);

        if(rootPane != null && LuckWindowUtil.isResizable(window))
        {
            dragCursor = getCursor(dragWidth, dragHeight, e.getPoint(), rootPane.getInsets());
        }
    }
}
 
Example 12
Source Project: Luyten   File: WindowPosition.java    License: Apache License 2.0 4 votes vote down vote up
public void readPositionFromWindow(JFrame window) {
	isFullScreen = (window.getExtendedState() == JFrame.MAXIMIZED_BOTH);
	if (!isFullScreen) {
		this.readPositionFromComponent(window);
	}
}