List of usage examples for java.awt Window setSize
public void setSize(int width, int height)
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void setFrameRelativeSize(Window frame, int width, int height) { //Get the screen size Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); //Calculate the frame location frame.setSize(screenSize.width - width, screenSize.height - height); }
From source file:Main.java
/** * Sets the size of the window to a width and height factor of the screen size. * //from w w w . j a v a 2 s . co m * @param window The window to set the size. * @param widthFactor The width factor of the screen size. * @param heightFactor The height factor of the screen size. */ public static void setSize(Window window, double widthFactor, double heightFactor) { Dimension screenSize = getScreenSize(window); int width = (int) (screenSize.getWidth() * widthFactor); int height = (int) (screenSize.getHeight() * heightFactor); window.setSize(width, height); }
From source file:de.erdesignerng.util.ApplicationPreferences.java
public void setWindowSize(String aAlias, Window aWindow) { try {/* www. j a va2 s. co m*/ int width = Integer.parseInt(windowDefinitions.get(WINDOWWIDTHPREFIX + aAlias)); int height = Integer.parseInt(windowDefinitions.get(WINDOWHEIGHTPREFIX + aAlias)); aWindow.setSize(width, height); } catch (NumberFormatException e) { // If no old size is known, an Exception is thrown // This can be ignored } }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
@Override public void doPostOpenActions() { Window w = GuiUtil.getOwnerWindow(this); if (w != null) { GuiUtil.centreOnScreen(w);//from ww w .j av a 2 s . c o m if (tableModel == null) { w.setSize(600, 400); } if (splitPane != null) { splitPane.setDividerLocation(0.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 ww w. ja v a 2 s. co 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.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 ww w. j a va 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) {//from w ww. j ava 2 s .co m 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;/*from w w w . ja va2s . co m*/ 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 w w . jav a2s.c om*/ 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(); } }