Example usage for java.awt Window validate

List of usage examples for java.awt Window validate

Introduction

In this page you can find the example usage for java.awt Window validate.

Prototype

public void validate() 

Source Link

Document

Validates this container and all of its subcomponents.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();

    Button btn = new Button("OK");
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gs = ge.getDefaultScreenDevice();
            gs.setFullScreenWindow(null);
        }//from www  . jav  a2  s  .  c o  m
    });
    Frame frame = new Frame(gs.getDefaultConfiguration());
    Window win = new Window(frame);
    win.add(btn, BorderLayout.CENTER);
    try {
        gs.setFullScreenWindow(win);
        win.validate();
    } finally {
        gs.setFullScreenWindow(null);
    }
}

From source file:Main.java

/**
 * Set the specified window to the style of Windows<sup>TM</sup> system.
 * //w  ww. j a  v  a  2  s  . c  o  m
 * @param window
 *            the specified window
 * @deprecated Please use {@link SwingUtils#setSystemLookAndFeel(Component)}
 *             instead.
 */
public static void setWindowsLookLike(Window window) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");//$NON-NLS-1$
        SwingUtilities.updateComponentTreeUI(window);
        window.validate();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Center window on screen./*  w ww .j  ava2  s. c  o m*/
 *
 * @param window    window to be centered.
 * @param packFrame if <code>true</code> call window's <code>pack()</code>
 *                  method before centering.
 */
public static void centerOnScreen(final Window window, final boolean packFrame) {
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame) {
        window.pack();
    } else {
        window.validate();
    }

    window.setLocationRelativeTo(null);
}

From source file:SwingUtils.java

public static void centerOnScreen(Window window, boolean packFrame) {
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame) {
        window.pack();/*from  w ww  . ja  v a 2 s.  c  o  m*/
    } else {
        window.validate();
    }

    //Center the frame window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

/**
 * Center window on screen./*from   w  ww .  ja va2 s.  c  o m*/
 *
 * @param window    window to be centered.
 * @param packFrame if <code>true</code> call window's <code>pack()</code>
 *                  method before centering.
 */
public static void centerOnScreen(Window window, boolean packFrame) {
    //Validate frames that have preset sizes
    //Pack frames that have useful preferred size info, e.g. from their layout
    if (packFrame) {
        window.pack();
    } else {
        window.validate();
    }

    //Center the frame window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = window.getSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:com.jcraft.weirdx.DDXWindowImpSwing.java

public void setSize(int w, int h) {
    boolean resized = false;
    if (w != this.width || h != this.height)
        resized = true;/*from www .  j ava 2 s  .  c  om*/

    if (!resized && !bwc) {
        return;
    }

    int offx = 0, offy = 0;

    int bitgrabity = window.attr & (15 << 8);
    if (bitgrabity != 0) {
        if (bitgrabity == (7 << 8) || // SouthWest
                bitgrabity == (8 << 8) || // South
                bitgrabity == (9 << 8)) { // SouthEast
            offy = this.height - h;
        }
        if (bitgrabity == (3 << 8) || // NorthEast
                bitgrabity == (6 << 8) || // East
                bitgrabity == (9 << 8)) { // SouthEast
            offx = this.width - w;
        }
    }

    //int originalWidth = this.width, originalHeight = this.height;
    this.width = w;
    this.height = h;
    super.setSize(w + 2 * bw, h + 2 * bw);

    bwc = false;

    if (window.screen.windowmode != WeirdX.InBrowser && window.hasFrame()) {
        java.awt.Window frame = window.getFrame();
        frame.validate();
        Insets insets = frame.getInsets();
        frame.setSize(w + 2 * bw + insets.left + insets.right, h + 2 * bw + insets.top + insets.bottom);
        frame.validate();
    }

    if (window.clss == InputOnly) {
        return;
    }

    if (offi != null && resized) {
        if (w < exposed.x || h < exposed.y) {
            exposed.setBounds(0, 0, 0, 0);
        } else if (w < (exposed.x + exposed.width) || h < (exposed.y + exposed.height)) {
            exposed.setBounds(exposed.x, exposed.y,
                    (exposed.width < (w - exposed.x) ? exposed.width : (w - exposed.x)),
                    (exposed.height < (h - exposed.y) ? exposed.height : (h - exposed.y)));
        }

        try {
            Image tmp = offi;
            Graphics tmpg = offg;

            offi = createImage(w, h);
            offg = offi.getGraphics();
            window.makeBackgroundTile(0, 0, w, h);
            if (bitgrabity != 0) {
                offg.drawImage(tmp, 0, 0, this);
            }

            if (offx != 0 || offy != 0) {
                int copyx = 0, copyy = 0, copyw = w, copyh = h, dx = 0, dy = 0;
                if (offy > 0) {
                    copyy = offy;
                    copyh = h - offy;
                    dy = offy * -1;
                } else if (offy < 0) {
                    dy = offy * -1;
                }
                if (offx > 0) {
                    copyx = offx;
                    copyw = w - offx;
                    dx = offx * -1;
                } else if (offx < 0) {
                    dx = offx * -1;
                }
                offg.copyArea(copyx, copyy, copyw, copyh, dx, dy);
            }

            if (tmp != offi) {
                tmp.flush();
                tmpg.dispose();
            }

            if (bitgrabity == 0) {
                exposed.setBounds(0, 0, 0, 0);
                window.makeBackgroundTile(0, 0, width, height);
            }
            window.currentGC = null;
        } catch (Exception e) {
            LOG.error(e);
            offi = null;
            offg = null;
        } catch (java.lang.OutOfMemoryError e) {
            LOG.error(e);
            offi = null;
            offg = null;
        }
        //System.out.println("DDXW: "+getBackground());
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void setSize(int w, int h) {
    boolean resized = false;
    if (w != this.width || h != this.height)
        resized = true;//from   w w  w. j a  v  a 2s  .c o m

    if (!resized && !bwc) {
        return;
    }

    int offx = 0, offy = 0;

    int bitgrabity = window.attr & (15 << 8);
    if (bitgrabity != 0) {
        if (bitgrabity == (7 << 8) || // SouthWest
                bitgrabity == (8 << 8) || // South
                bitgrabity == (9 << 8)) { // SouthEast
            offy = this.height - h;
        }
        if (bitgrabity == (3 << 8) || // NorthEast
                bitgrabity == (6 << 8) || // East
                bitgrabity == (9 << 8)) { // SouthEast
            offx = this.width - w;
        }
    }

    //int originalWidth=this.width, originalHeight = this.height;
    this.width = w;
    this.height = h;
    super.setSize(w + 2 * bw, h + 2 * bw);

    bwc = false;

    if (window.screen.windowmode != WeirdX.InBrowser && window.hasFrame()) {
        java.awt.Window frame = window.getFrame();
        frame.validate();
        Insets insets = frame.getInsets();
        frame.setSize(w + 2 * bw + insets.left + insets.right, h + 2 * bw + insets.top + insets.bottom);
        frame.validate();
    }

    if (window.clss == InputOnly) {
        return;
    }

    if (offi != null && resized) {
        if (w < exposed.x || h < exposed.y) {
            exposed.setBounds(0, 0, 0, 0);
        } else if (w < (exposed.x + exposed.width) || h < (exposed.y + exposed.height)) {
            exposed.setBounds(exposed.x, exposed.y,
                    (exposed.width < (w - exposed.x) ? exposed.width : (w - exposed.x)),
                    (exposed.height < (h - exposed.y) ? exposed.height : (h - exposed.y)));
        }

        try {
            Image tmp = offi;
            Graphics tmpg = offg;

            offi = createImage(w, h);
            offg = offi.getGraphics();
            window.makeBackgroundTile(0, 0, w, h);
            if (bitgrabity != 0) {
                offg.drawImage(tmp, 0, 0, this);
            }

            if (offx != 0 || offy != 0) {
                int copyx = 0, copyy = 0, copyw = w, copyh = h, dx = 0, dy = 0;
                if (offy > 0) {
                    copyy = offy;
                    copyh = h - offy;
                    dy = offy * -1;
                } else if (offy < 0) {
                    dy = offy * -1;
                }
                if (offx > 0) {
                    copyx = offx;
                    copyw = w - offx;
                    dx = offx * -1;
                } else if (offx < 0) {
                    dx = offx * -1;
                }
                offg.copyArea(copyx, copyy, copyw, copyh, dx, dy);
            }

            if (tmp != offi) {
                tmp.flush();
                tmpg.dispose();
            }

            if (bitgrabity == 0) {
                exposed.setBounds(0, 0, 0, 0);
                window.makeBackgroundTile(0, 0, width, height);
            }
            window.currentGC = null;
        } catch (Exception e) {
            LOG.equals(e);
            offi = null;
            offg = null;
        } catch (java.lang.OutOfMemoryError e) {
            LOG.error(e);
            offi = null;
            offg = null;
        }
        //System.out.println("DDXW: "+getBackground());
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void setVisible(boolean b) {
    if (b) {/*  ww w.j  a v a2  s  .c  om*/
        if (offi == null && window.clss != InputOnly) {
            allocImage();
        }
        if (window != window.screen.root && !isVisible()) {
            exposed.setBounds(0, 0, 0, 0);
        }
        super.setVisible(true);
        if (window.screen.windowmode != WeirdX.InBrowser && window.hasFrame()) {
            java.awt.Window frame = window.getFrame();

            if (frame instanceof java.awt.Frame) {
                frame.add("Center", this);
                frame.pack();
                synchronized (XWindow.LOCK) {
                    Property p = window.getProperty();
                    while (p != null) {
                        if (p.propertyName == 39)
                            break;
                        p = p.next;
                    }
                    if (p != null && p.type == 31) {
                        String title = "";
                        if (p.size > 0) {
                            title = new String(p.data);
                        }
                        ((java.awt.Frame) (frame)).setTitle(title);
                    }
                }
            } else {
                frame.add(this);
            }

            frame.validate();
            Insets insets = frame.getInsets();
            frame.setSize(window.width + window.borderWidth * 2 + insets.left + insets.right,
                    window.height + window.borderWidth * 2 + insets.top + insets.bottom);
            super.setLocation(insets.left, insets.top);
            frame.validate();
        }
    } else {
        if (isVisible()) {
            super.setVisible(false);
            if (window != window.screen.root && window.screen.root.width * window.screen.root.height
                    / 4 <= window.width * window.height) {
                freeImage();
                exposed.setBounds(0, 0, 0, 0);
            }
        }
    }
}

From source file:com.jcraft.weirdx.XWindow.java

static final void reqConfigureWindow(Client c) throws IOException {
    int foo;// w  ww  . j a  v  a 2 s .  c om
    int n;
    InputOutput io = c.client;
    foo = io.readInt();
    XWindow win = c.lookupWindow(foo);
    if (win == null) {
        c.errorValue = foo;
        c.errorReason = 3; // BadWindow
    }

    int mask = io.readShort();
    io.readPad(2);
    c.length -= 3;
    if (c.errorReason != 0) {
        return;
    }
    if (((win.clss == InputOnly) && (mask & IllegalInputOnlyConfigureMask) != 0)
            || ((mask & CWSibling) != 0 && (mask & CWStackMode) == 0)) {
        c.errorReason = 8; // BadMatch
        return;
    }

    int index;
    int x, y;
    int w = win.width;
    int h = win.height;
    int bw = win.borderWidth;
    XWindow sib = null;

    synchronized (LOCK) {
        win = c.lookupWindow(win.id);
        if (win == null) {
            c.errorValue = win.id;
            c.errorReason = 3; // BadWindow
            return;
        }
        if (win.screen.root != win && win.parent == null)
            return;
        if (win.parent != null) {
            x = win.x - win.parent.x - bw;
            y = win.y - win.parent.y - bw;
        } else {
            x = win.x;
            y = win.y;
        }

        mask &= 0x7f;

        int beforex = x, beforey = y;

        int smode = 0;
        int tmp = mask;
        while (tmp != 0 && c.length != 0) {
            index = lowbit(tmp);
            tmp &= ~index;
            switch (index) {
            case CWX:
                foo = io.readInt();
                foo = (short) (foo & 0xffff);
                if (foo == x) {
                    mask -= CWX;
                } else {
                    x = (short) (foo);
                }
                break;
            case CWY:
                foo = io.readInt();
                foo = (short) (foo & 0xffff);
                if (foo == y) {
                    mask -= CWY;
                } else {
                    y = (short) (foo);
                }
                break;
            case CWWidth:
                foo = io.readInt();
                foo = (foo & 0xffff);
                if (w == foo) {
                    mask -= CWWidth;
                } else {
                    w = foo;
                }
                break;
            case CWHeight:
                foo = io.readInt();
                foo = (foo & 0xffff);
                if (h == foo) {
                    mask -= CWHeight;
                } else {
                    h = foo;
                }
                break;
            case CWBorderWidth:
                foo = io.readInt();
                foo = (foo & 0xffff);
                bw = foo;
                break;
            case CWSibling:
                foo = io.readInt();
                sib = c.lookupWindow(foo);
                if (sib == null) {
                    c.errorValue = foo;
                    c.errorReason = 3; // BadWindow
                } else if ((sib.parent != win.parent) || (sib == win)) {
                    c.errorReason = 8; // BadMatch
                }
                break;
            case CWStackMode:
                foo = io.readInt();
                foo &= 0xff;
                smode = foo;
                if ((smode != TopIf) && (smode != BottomIf) && (smode != Opposite) && (smode != Above)
                        && (smode != Below)) {
                    c.errorValue = foo;
                    c.errorReason = 2; // BadValue
                }
                break;
            default:
                c.errorValue = mask;
                c.errorReason = 2; // BadValue
                return;
            }
            c.length--;
            if (c.errorReason != 0) {
                return;
            }
        }
        if (c.length != 0) {
            c.errorValue = mask;
            c.errorReason = 2; // BadValue
            return;
        }

        if (mask == 0) {
            return;
        }

        if (win.parent == null)
            return;

        if ((mask & CWStackMode) != 0) {
            sib = win.getPlaceInTheStack(sib, win.parent.x + x, win.parent.y + y, w + bw * 2, h + bw * 2,
                    smode);
        } else {
            sib = win.nextSib;
        }

        if (((win.attr & overrideRedirect) == 0) && (win.parent.redirectSend())) {
            c.cevent.mkConfigureRequest(((mask & CWStackMode) != 0) ? smode : Above, win.parent.id, win.id,
                    ((mask & CWSibling) != 0) ? sib.id : 0, x, y, w, h, bw, mask);
            if (win.parent.sendEvent(c.cevent, 1, Event.SubstructureRedirectMask, c) == 1) {
                return;
            }

        }

        int action = Restack;
        if ((mask & (CWX | CWY)) != 0 && (mask & (CWHeight | CWWidth)) == 0) {
            action = Move;
        } else if ((mask & ChangeMask) != 0) {
            if (w == 0 || h == 0) {
                c.errorValue = 0;
                c.errorReason = 2; // BadBalue;
                return;
            }
            action = Resize;
        }

        if (action == Resize) {
            boolean sizec = ((w != win.width) || (h != win.height));
            if (sizec && (((win.eventMask | win.getOtherEventMask()) & Event.ResizeRedirectMask) != 0)) {
                c.cevent.mkResizeRequest(win.id, w, h);
                if (win.sendEvent(c.cevent, 1, Event.ResizeRedirectMask, c) == 1) {
                    w = win.width;
                    h = win.height;
                    sizec = false;
                }
            }
            if (!sizec) {
                if ((mask & (CWX | CWY)) != 0)
                    action = Move;
                else if ((mask & (CWStackMode | CWBorderWidth)) != 0) {
                    action = Restack;
                } else {
                    return;
                }
            }
        }

        if ((action == Resize) || (((mask & CWX) != 0) && x != beforex) || (((mask & CWY) != 0) && y != beforey)
                || (((mask & CWBorderWidth) != 0) && bw != win.borderWidth)
                || (((mask & CWStackMode) != 0) && win.nextSib != sib)) {
            if (win.substrSend()) {
                c.cevent.mkConfigureNotify(win.id, (sib != null ? sib.id : 0), x, y, w, h, bw,
                        (win.attr & overrideRedirect) != 0 ? 0 : 1);
                win.sendEvent(c.cevent, 1, null);
            }

            if ((mask & CWBorderWidth) != 0) {
                if (action == Restack) {
                    action = Move;
                    win.borderWidth = bw;
                    win.ddxwindow.setBorder(bw);
                } else if ((action == Move) && ((beforex + win.borderWidth) == x + bw)
                        && ((beforey + win.borderWidth) == y + bw)) {
                    action = Reborder;
                } else {
                    win.borderWidth = bw;
                    win.ddxwindow.setBorder(bw);
                }
            }

            if ((mask & CWStackMode) != 0) {
                win.reflectStackChange(sib);
            }

            if (((mask & CWX) != 0) || ((mask & CWY) != 0) || ((mask & CWWidth) != 0)
                    || ((mask & CWHeight) != 0) || ((mask & CWBorderWidth) != 0)) {
                win.origin.x = x + bw;
                win.origin.y = y + bw;

                int dx, dy, dw, dh;
                dx = dy = dw = dh = 0;
                dw = w - win.width;
                dh = h - win.height;
                win.height = h;
                win.width = w;

                int newx = win.parent.x + x + bw;
                int newy = win.parent.y + y + bw;

                int oldx, oldy;
                oldx = win.x;
                oldy = win.y;

                x = win.x = newx;
                y = win.y = newy;

                XWindow wToValidate = win.moveInStack(sib);
                if (((mask & CWWidth) != 0) || ((mask & CWHeight) != 0) || ((mask & CWBorderWidth) != 0)) {
                    if (win.screen.windowmode != WeirdX.InBrowser && win.hasFrame()) {
                        java.awt.Window frame = win.getFrame();
                        frame.validate();
                        Insets insets = frame.getInsets();
                        frame.setSize(win.width + win.borderWidth * 2 + insets.left + insets.right,
                                win.height + win.borderWidth * 2 + insets.bottom + insets.top);
                        frame.validate();
                    }

                    win.ddxwindow.setSize(win.width, win.height);
                }

                win.resizeChildrenWinSize(x - oldx, y - oldy, dw, dh);
                win.ddxwindow.setLocation(win.origin.x - win.borderWidth + win.parent.borderWidth,
                        win.origin.y - win.borderWidth + win.parent.borderWidth);

            }
            return;
        } else {
            return;
        }
    }
}

From source file:com.jcraft.weirdx.XWindow.java

void reparent(XWindow newparent, int xx, int yy, Client c) throws IOException {
    boolean wasMapped;

    synchronized (LOCK) {
        if (parent == null)
            return;

        int bw = borderWidth;
        wasMapped = ((attr & mapped) != 0);
        XWindow prev;/*from   w  ww .ja va2s .c o m*/

        makeOptional();

        if (wasMapped) {
            unmapWindow(false);
        }

        c.cevent.mkReparentNotify(id, id, newparent.id, xx, yy, ((attr & overrideRedirect) != 0 ? 1 : 0));

        sendEvent(c.cevent, 1, newparent);

        prev = parent;
        if (prev.firstChild == this)
            prev.firstChild = nextSib;
        if (prev.lastChild == this)
            prev.lastChild = prevSib;

        if (nextSib != null)
            nextSib.prevSib = prevSib;
        if (prevSib != null)
            prevSib.nextSib = nextSib;

        parent = newparent;

        nextSib = newparent.firstChild;
        prevSib = null;
        if (newparent.firstChild != null)
            newparent.firstChild.prevSib = this;
        else
            newparent.lastChild = this;
        newparent.firstChild = this;

        origin.x = (short) (xx);
        origin.y = (short) (yy);
        x = (short) (xx + newparent.x);
        y = (short) (yy + newparent.y);

        if (screen.windowmode != WeirdX.InBrowser && hasFrame()) {
            java.awt.Window frame = getFrame();
            frame.remove((java.awt.Component) ddxwindow);
            //   frame.dispose();                                        
            delFrame();
        }
        if (screen.windowmode != WeirdX.InBrowser && newparent == screen.root) {
            java.awt.Window frame = getFrame();
            /*if(frame instanceof JFrame){                               
              ((JFrame)frame).setJMenuBar(null);                       
              ((JFrame)frame).getContentPane().setLayout(null);        
                ((JFrame)frame).setResizable(false);                                 
            }                                                          
            else*/ if (frame instanceof Frame) {
                ((Frame) frame).setMenuBar(null);
                ((Frame) frame).setResizable(true);
            }

            ddxwindow.setLocation(0, 0);

            frame.add((java.awt.Component) ddxwindow);

            frame.validate();
            Insets insets = frame.getInsets();
            frame.setSize(this.width + this.borderWidth * 2 + insets.left + insets.right,
                    this.height + this.borderWidth * 2 + insets.bottom + insets.top);
            frame.validate();

            if (frame instanceof Frame) {
                addWindowListener((java.awt.Frame) frame);
                addComponentListener((java.awt.Frame) frame);
            }
        } else {
            newparent.ddxwindow.add((java.awt.Component) ddxwindow, 0); // ???
            ddxwindow.setLocation(origin.x - borderWidth + parent.borderWidth,
                    origin.y - borderWidth + parent.borderWidth);
        }

        resizeChildrenWinSize(0, 0, 0, 0);

        if (wasMapped) {
            mapWindow(c);
        }

        recalculateDeliverableEvents();
    }
}