/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @param target The component to be laid out. * @return A size deemed suitable for laying out the container. * @see #minimumLayoutSize */ public Dimension preferredLayoutSize(Container target) { int count; Component component; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock()) { // get the the total height and maximum width component ret = new Dimension(0, 0); count = target.getComponentCount(); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); ret.width = Math.max(ret.width, dimension.width); ret.height += dimension.height; } } insets = target.getInsets(); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } return (ret); }
/** * Returns the maximum amount of space the layout can use. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize(Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if (root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } if (root.getMenuBar() != null) { mbd = root.getMenuBar().getMaximumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof HokageRootPaneUI)) { JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane(); if (titlePane != null) { tpd = titlePane.getMaximumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); }
/** * Calculates the preferred size dimensions for the specified panel given the components in the * specified parent container. * * @see #minimumLayoutSize * @param target The component to be laid out. * @return A size deemed suitable for laying out the container. */ public Dimension preferredLayoutSize(Container target) { int count; Container parent; Component component; Point point; Dimension dimension; Insets insets; Dimension ret; synchronized (target.getTreeLock()) { count = target.getComponentCount(); if (0 == count) { // be the same size unless we have a parent ret = target.getSize(); parent = target.getParent(); if (null != parent) { insets = parent.getInsets(); ret = parent.getSize(); ret.setSize( ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom); } } else { ret = new Dimension(0, 0); for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { point = component.getLocation(); dimension = component.getPreferredSize(); ret.width = Math.max(ret.width, point.x + dimension.width); ret.height = Math.max(ret.height, point.y + dimension.height); } } insets = target.getInsets(); ret.width += insets.left + insets.right; ret.height += insets.top + insets.bottom; } } return (ret); }
/** * Returns the amount of space the layout would like to have. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's preferred size */ public Dimension preferredLayoutSize(Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; int tpHeight = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if (root.getContentPane() != null) { cpd = root.getContentPane().getPreferredSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if (root.getMenuBar() != null) { mbd = root.getMenuBar().getPreferredSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof HokageRootPaneUI)) { JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane(); if (titlePane != null) { tpd = titlePane.getPreferredSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } return new Dimension( Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); }
private Dimension getLayoutSize(Container parent, int hGap, boolean layout) { Insets insets = parent.getInsets(); int lineMaxX = 0; int lineY = 0; int currentY = 0; int currentX = 0; int maxY = 0; int maxX = 0; int topMargin = 0; int leftMargin = 0; Dimension d; Component[] components = parent.getComponents(); for (int i = 0; i < components.length; i++) { if (components[i] instanceof CPLabel) { topMargin = 20; leftMargin = 0; currentY = lineY; currentX = lineMaxX + hGap; lineMaxX = currentX; } else if (components[i] instanceof CPCheckBox) { topMargin = 0; leftMargin = 0; } if (components[i] instanceof CRLF) { lineY = maxY; lineMaxX = 0; } else { // It's not a CRLF, lay it out. d = components[i].getPreferredSize(); if (layout) { components[i].setBounds( insets.left + leftMargin + currentX, insets.top + topMargin + currentY, d.width, d.height); } currentY += topMargin + d.height; lineMaxX = Math.max(lineMaxX, leftMargin + currentX + d.width); maxX = Math.max(maxX, lineMaxX); maxY = Math.max(maxY, topMargin + currentY + d.height); } } return new Dimension(insets.left + maxX + insets.right, insets.top + maxY + insets.bottom); }
/** * Lays out the container. * * @param target The container which needs to be laid out. */ public void layoutContainer(Container target) { Insets insets; int x; int y; int count; int width; Component component; Dimension dimension; synchronized (target.getTreeLock()) { insets = target.getInsets(); x = insets.left; y = insets.top; count = target.getComponentCount(); width = 0; for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getPreferredSize(); width = Math.max(width, dimension.width); component.setSize(dimension.width, dimension.height); component.setLocation(x, y); y += dimension.height; } } // now set them all to the same width for (int i = 0; i < count; i++) { component = target.getComponent(i); if (component.isVisible()) { dimension = component.getSize(); dimension.width = width; component.setSize(dimension.width, dimension.height); } } } }
RootWindow(Container container, Screen screen, Format[] format, Client c) { super(screen.rootId); rootwindow = container; client = c; screen.setRoot((Window) this); this.width = (short) (screen.width); this.height = (short) (screen.height); this.screen = screen; depth = screen.rootDepth; id = screen.rootId; type = DRAWABLE_WINDOW; x = y = 0; origin.x = 0; origin.y = 0; clss = (byte) InputOutput; for (int i = 0; i < format.length; i++) { if (format[i].depth == screen.rootDepth) { this.bitsPerPixel = format[i].bpp; } } setVisual(screen.rootVisual); setBackgroundIsPixel(); background.pixel = screen.white; setBorderIsPixel(); border.pixel = screen.black; borderWidth = 0; Resource.add(this); makeOptional(); attr &= ~(1 << 3); // cursorIsNone optional.cursor = Cursor.rootCursor; setColormap(screen.defaultColormap); // if(rootwindow instanceof JFrame){ // rootwindow.setSize(this.width+10, this.height+30); // ?? // } // else{ rootwindow.setSize(this.width, this.height); // } try { ddxwindow = (DDXWindow) (Window.dDXWindow.newInstance()); } catch (Exception e) { System.err.println(e); /*ddxwindow=new DDXWindowImp();*/ } ddxwindow.init(this); ddxwindow.setLocation(0, 0); if (rootwindow instanceof Frame) { // ((Frame)rootwindow).setLayout(null); ((Frame) rootwindow).setResizable(false); ((Frame) rootwindow).setMenuBar(null); ((Frame) rootwindow).add((java.awt.Component) ddxwindow); } else if (rootwindow instanceof Applet) { ((Applet) rootwindow).add((java.awt.Component) ddxwindow); } /* else if(rootwindow instanceof JFrame){ ((JFrame)rootwindow).getContentPane().setLayout(null); ((JFrame)rootwindow).setResizable(false); ((JFrame)rootwindow).setJMenuBar(null); ((JFrame)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } else if(rootwindow instanceof JWindow){ ((JWindow)rootwindow).getContentPane().setLayout(null); ((JWindow)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } else if (rootwindow instanceof JApplet){ ((JApplet)rootwindow).setJMenuBar(null); ((JApplet)rootwindow).getContentPane().add((java.awt.Component)ddxwindow); } */ else { rootwindow.add((java.awt.Component) ddxwindow); } if (screen.windowmode != WeirdX.InBrowser) { rootwindow.addNotify(); } else { rootwindow.setVisible(true); } ddxwindow.setVisible(true); { rootwindow.validate(); Insets insets = rootwindow.getInsets(); rootwindow.setSize( this.width + insets.left + insets.right, this.height + insets.top + insets.bottom); ddxwindow.setLocation(insets.left, insets.top); rootwindow.validate(); } ddxwindow.requestFocus(); Window.focus.win = id; Window.LOCK = rootwindow.getTreeLock(); Client.LOCK = rootwindow.getTreeLock(); Resource.LOCK = rootwindow.getTreeLock(); spriteTrace[0] = this; sprite.win = this; }