public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int maxWidth = parent.getSize().width - (insets.left + insets.right); int maxHeight = parent.getSize().height - (insets.top + insets.bottom); int nComps = parent.getComponentCount(); if (this.sizeUnknown) { setSizes(parent); } Component c; if (nComps < 2) { c = parent.getComponent(0); if (c.isVisible()) { Dimension d = c.getPreferredSize(); c.setBounds(0, 0, d.width, d.height); return; } return; } double radialCurrent = Math.toRadians(SpiderWebPlot.DEFAULT_START_ANGLE); double radialIncrement = 6.283185307179586d / ((double) nComps); int midX = maxWidth / 2; int midY = maxHeight / 2; int a = midX - this.maxCompWidth; int b = midY - this.maxCompHeight; for (int i = 0; i < nComps; i++) { c = parent.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); double d2 = (double) midX; double d3 = (double) a; int x = (int) (((r0 - (r0 * Math.cos(radialCurrent))) - (d.getWidth() / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS)) + ((double) insets.left)); d2 = (double) midY; d3 = (double) b; c.setBounds( x, (int) (((r0 - (r0 * Math.sin(radialCurrent))) - (d.getHeight() / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS)) + ((double) insets.top)), d.width, d.height); } radialCurrent += radialIncrement; } }
public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Insets insets = parent.getInsets(); int itop = insets.top; int ileft = insets.left; int ibottom = insets.bottom; int iright = insets.right; int rightWidth = right.getPreferredSize().width; int bottomHeight = bottom.getPreferredSize().height; int centerWidth = size.width - rightWidth - ileft - iright; int centerHeight = size.height - bottomHeight - itop - ibottom; center.setBounds(ileft, itop, centerWidth, centerHeight); right.setBounds(ileft + centerWidth, itop, rightWidth, centerHeight); // Lay out all status components, in order Enumeration status = leftOfScrollBar.elements(); while (status.hasMoreElements()) { Component comp = (Component) status.nextElement(); Dimension dim = comp.getPreferredSize(); comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight); ileft += dim.width; } bottom.setBounds( ileft, itop + centerHeight, size.width - rightWidth - ileft - iright, bottomHeight); }
/** * Lays out the container in the specified container. * * @param parent the component which needs to be laid out */ public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int ncomponents = parent.getComponentCount(); if (ncomponents == 0) { return; } // Total parent dimensions Dimension size = parent.getSize(); int totalW = size.width - (insets.left + insets.right); int totalH = size.height - (insets.top + insets.bottom); // Cell dimensions, including padding int totalCellW = totalW / gridSize.width; int totalCellH = totalH / gridSize.height; // Cell dimensions, without padding int cellW = (totalW - ((gridSize.width + 1) * hgap)) / gridSize.width; int cellH = (totalH - ((gridSize.height + 1) * vgap)) / gridSize.height; for (int i = 0; i < ncomponents; i++) { Component c = parent.getComponent(i); Rectangle rect = (Rectangle) compTable.get(c); if (rect != null) { int x = insets.left + (totalCellW * rect.x) + hgap; int y = insets.top + (totalCellH * rect.y) + vgap; int w = (cellW * rect.width) - hgap; int h = (cellH * rect.height) - vgap; c.setBounds(x, y, w, h); } } } }
@Override public void layoutContainer(final Container parent) { final int componentCount = parent.getComponentCount(); if (componentCount == 0) return; final EditorEx history = myHistoryViewer; final EditorEx editor = componentCount == 2 ? myConsoleEditor : null; if (editor == null) { parent.getComponent(0).setBounds(parent.getBounds()); return; } final Dimension panelSize = parent.getSize(); if (panelSize.getHeight() <= 0) return; final Dimension historySize = history.getContentSize(); final Dimension editorSize = editor.getContentSize(); final Dimension newEditorSize = new Dimension(); // deal with width final int width = Math.max(editorSize.width, historySize.width); newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight(); history.getSoftWrapModel().forceAdditionalColumnsUsage(); editor .getSettings() .setAdditionalColumnsCount( 2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor)); history .getSettings() .setAdditionalColumnsCount( 2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history)); // deal with height if (historySize.width == 0) historySize.height = 0; final int minHistorySize = historySize.height > 0 ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0) : 0; final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight(); final int editorPreferred = editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height); final int historyPreferred = Math.max(minHistorySize, historySize.height); if (panelSize.height < minEditorSize) { newEditorSize.height = panelSize.height; } else if (panelSize.height < editorPreferred) { newEditorSize.height = panelSize.height - minHistorySize; } else if (panelSize.height < editorPreferred + historyPreferred) { newEditorSize.height = editorPreferred; } else { newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred; } final Dimension newHistorySize = new Dimension(width, panelSize.height - newEditorSize.height); // apply editor .getComponent() .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height); myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd()); history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height); }
/** * Shows this glass box on the glass pane. * * @param glassPane the glass pane * @param originX the location on the X-axis to position the glass box * @param originY the location on the Y-axis to position the glass box */ public void showOnGlassPane(Container glassPane, int originX, int originY) { Dimension gd = glassPane.getSize(); Dimension bd = getPreferredSize(); int x = Math.min(originX, gd.width - bd.width); int y = Math.min(originY, gd.height - bd.height); if (x < 0) { x = 0; } if (y < 0) { y = 0; } int width = x + bd.width < gd.width ? bd.width : gd.width; int height = y + bd.height < gd.height ? bd.height : gd.height; glassPane.setLayout(null); setBounds(x, y, width, height); glassPane.add(this); glassPane.setVisible(true); Container topLevel = getTopLevel(); topLevel.validate(); topLevel.repaint(); }
/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent( final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null || (parent.isVisible() == false)) { positionFrameOnScreen(dialog, horizontalPercent, verticalPercent); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int parentPointX = baseX + (int) (horizontalPercent * p.width); final int parentPointY = baseY + (int) (verticalPercent * p.height); final int dialogPointX = parentPointX - (int) (horizontalPercent * d.width); final int dialogPointY = parentPointY - (int) (verticalPercent * d.height); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height); final Rectangle intersectedDialogBounds = r.intersection(s); if (intersectedDialogBounds.width < d.width) { r.x = s.width - d.width; r.width = d.width; } if (intersectedDialogBounds.height < d.height) { r.y = s.height - d.height; r.height = d.height; } final Rectangle finalIntersection = r.intersection(s); dialog.setBounds(finalIntersection); }
public static Dimension getFrameSize(Component c) { Container parent = getRootContainer(c); if (parent != null) { return parent.getSize(); } return Toolkit.getDefaultToolkit().getScreenSize(); }
public GUITable() throws Exception { main_frame = new JFrame("Card Games"); main_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); main_frame.setPreferredSize(new Dimension(357, 323)); main_frame.setResizable(false); main_menu = new TableMenu(); main_frame.setJMenuBar(main_menu); Container cp = main_frame.getContentPane(); cp.setLayout(new CardLayout()); JLabel base = new JLabel("Use the game menu to start a game"); base.setHorizontalAlignment(SwingConstants.CENTER); base.setVerticalAlignment(SwingConstants.CENTER); cp.add(base, "Base"); base.setSize(cp.getSize()); main_frame.pack(); main_frame.setVisible(true); game_gui = null; games = new Hashtable<String, TableUI>(); this.host = GUIPlayer.getCurrentPlayer(); if (this.host == null) { main_menu.showNewUserDialog(main_frame); this.host = GUIPlayer.getCurrentPlayer(); if (this.host != null) main_menu.enableGameMenus(); } else main_menu.enableGameMenus(); }
public void layoutContainer(Container target) { Insets insets = target.getInsets(); int ncomponents = target.getComponentCount(); int top = 0; int left = insets.left; Dimension tps = target.getPreferredSize(); Dimension targetSize = target.getSize(); Component comp; Dimension ps; if (horizontalOrientation == Orientation.CENTER) left = left + (targetSize.width / 2) - (tps.width / 2); if (horizontalOrientation == Orientation.RIGHT) left = left + targetSize.width - tps.width; for (int i = 0; i < ncomponents; i++) { comp = target.getComponent(i); if (comp.isVisible()) { ps = comp.getPreferredSize(); if (verticalOrientation == Orientation.CENTER) top = (targetSize.height / 2) - (ps.height / 2); else if (verticalOrientation == Orientation.TOP) top = insets.top; else if (verticalOrientation == Orientation.BOTTOM) top = targetSize.height - ps.height - insets.bottom; comp.setBounds(left, top, ps.width, ps.height); left += ps.width + gap; } } }
/** * Returns the location where to dock the given {@code JToolBar}, at the given constraint * position. The constraint position must be one of the constants {@code BorderLayout.NORTH * NORTH}, {@code BorderLayout.EAST EAST}, {@code BorderLayout.SOUTH SOUTH}, or {@code * BorderLayout.WEST WEST}. * * <p><b>Note:</b> This method is accessed in the current executing thread. Such thread may or may * not be the event dispatch thread (EDT.) Client code must call this method from the EDT. * * @param toolBar the target {@code JToolBar}. * @param dock the container where to dock the {@code JToolBar} to. * @param constraint the constraint position. * @return the location where to dock the given {@code JToolBar}. * @throws IllegalArgumentException if the constraint has an invalid value. */ @RunsInCurrentThread public @Nonnull Point dockLocation( @Nonnull JToolBar toolBar, @Nonnull Container dock, @Nonnull String constraint) { checkValid(constraint); Insets insets = dock.getInsets(); // BasicToolBarUI prioritizes location N/E/W/S by proximity to the respective border. Close to // top border is N, even // if close to the left or right border. int offset = isHorizontal(toolBar) ? toolBar.getHeight() : toolBar.getWidth(); Dimension dockSize = dock.getSize(); if (NORTH.equals(constraint)) { return new Point(dockSize.width / 2, insets.top); } if (EAST.equals(constraint)) { return new Point( dockSize.width - insets.right - 1, verticalDockingYCoordinate(dockSize.height, insets, offset)); } if (WEST.equals(constraint)) { return new Point(insets.left, verticalDockingYCoordinate(dockSize.height, insets, offset)); } int x = dockSize.width / 2; // Make sure we don't get mistaken for EAST or WEST if (x < insets.left + offset) { x = insets.left + offset; } else if (x > dockSize.width - insets.right - offset - 1) { x = dockSize.width - insets.right - offset - 1; } return new Point(x, dockSize.height - insets.bottom - 1); }
public void layoutContainer(Container parent) { Dimension ourSize = preferredLayoutSize(parent), // Does the following do something useful? // And shouldn't we cater to real instead of maximum sizes? // This way, if a VerticallyLaidout component had a particular size forced upon it, // wouldn't we neglect to scale down to using minimum sizes so long as its maximum // size was bigger than our preferred? all: [Davis] maxSize = parent.getMaximumSize(), size = parent.getSize(); Insets isets = parent.getInsets(); Dimension compSize; int n = parent.getComponentCount(); int y; boolean usingPreferredSize = true; if (ourSize.width > maxSize.width || ourSize.height > maxSize.height) { ourSize = minimumLayoutSize(parent); usingPreferredSize = false; } switch (verticalAlignment) { case TOP: y = isets.top; break; case BOTTOM: y = (size.height - ourSize.height); break; default: // assume MIDDLE y = (size.height - ourSize.height) / 2 + isets.top; break; } for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); compSize = usingPreferredSize ? c.getPreferredSize() : c.getMinimumSize(); switch (horizontalAlignment) { case LEFT: c.setBounds(isets.left, y, compSize.width, compSize.height); break; case RIGHT: c.setBounds( ourSize.width - isets.right - compSize.width + isets.left, y, compSize.width, compSize.height); break; default: // assume CENTER c.setBounds( (ourSize.width - isets.left - isets.right - compSize.width + isets.left) / 2, y, compSize.width, compSize.height); } y += compSize.height + vgap; } }
/** * Compute the bounds of all of the Split/Divider/Leaf Nodes in the layout model, and then set the * bounds of each child component with a matching Leaf Node. */ public void layoutContainer(Container parent) { checkLayout(getModel()); Insets insets = parent.getInsets(); Dimension size = parent.getSize(); int width = size.width - (insets.left + insets.right); int height = size.height - (insets.top + insets.bottom); Rectangle bounds = new Rectangle(insets.left, insets.top, width, height); layout1(getModel(), bounds); layout2(getModel(), bounds); }
public void measureLayout(Container target, Dimension dimension, int type) { int count = target.getComponentCount(); if (count > 0) { Insets insets = target.getInsets(); Dimension size = target.getSize(); int x = 0; int y = 0; int maxWidth = 0; int maxHeight = 0; double radius = Math.min( size.width - insets.left - insets.right, size.height - insets.top - insets.bottom) / 2; Dimension[] sizes = new Dimension[count]; for (int i = 0; i < count; i++) { Component c = target.getComponent(i); if (includeComponent(c)) { Dimension d = getComponentSize(c, type); int w = d.width; int h = d.height; sizes[i] = d; maxWidth = Math.max(maxWidth, w); maxHeight = Math.max(maxHeight, h); } } if (dimension != null) { dimension.width = (int) (2 * radius - maxWidth); dimension.height = (int) (2 * radius - maxHeight); } else { int mx = (size.width - insets.left - insets.right - 2 * hMargin) / 2; int my = (size.height - insets.top - insets.bottom - 2 * vMargin) / 2; x = 0; y = 0; radius -= Math.max(maxWidth, maxHeight) / 2; for (int i = 0; i < count; i++) { Component c = target.getComponent(i); if (includeComponent(c)) { Dimension d = sizes[i]; int w = d.width; int h = d.height; double angle = 2 * Math.PI * i / count; x = mx + (int) (Math.sin(angle) * radius); y = my - (int) (Math.cos(angle) * radius); c.setBounds(insets.left + hMargin + x - w / 2, insets.top + vMargin + y - h / 2, w, h); } } } } }
/** * Lays out the specified container. * * @param target the component being laid out * @see Container */ @Override public void layoutContainer(Container target) { Insets insets = target.getInsets(); int top = insets.top, left = insets.left + hmargin; int width = target.getSize().width - left - insets.right - hmargin; Component children[] = target.getComponents(); // available vertical space int vroom = target.getSize().height - top - insets.bottom - vmargin * 2; top += vgap; for (int i = 0; i < children.length; i++) { if (!children[i].isVisible()) { continue; } int h = children[i].getPreferredSize().height + vmargin * 2; children[i].setBounds(left, top, width, h); top += h + vgap; vroom -= (h + vgap); } }
/** * 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); }
/** Lays out the container in the specified panel. */ public void layoutContainer(Container target) { synchronized (target.getTreeLock()) { Insets insets = target.getInsets(); Dimension dim = target.getSize(); int fullHeight = dim.height; int bottom = dim.height - insets.bottom - 1; int top = 0 + insets.top; int left = insets.left; int maxPosition = dim.width - (insets.left + insets.right) - hgap; int right = dim.width - insets.right; maxPosition = right; int height = bottom - top; int size = actions.size(); int w, h; if ((grip != null) && grip.isVisible()) { Dimension d = grip.getPreferredSize(); grip.setBounds(left, top + vgap, d.width, bottom - top - 2 * vgap); left += d.width; left += hgap; } for (int i = 0; i < size; i++) { left += hgap; Component comp = (Component) actions.elementAt(i); Dimension d; Dimension minSize = comp.getMinimumSize(); if (i == size - 1) d = comp.getMaximumSize(); else d = comp.getPreferredSize(); w = d.width; h = Math.min(height, d.height); if ((left < maxPosition) && (left + w > maxPosition)) { if (maxPosition - left >= minSize.width) w = maxPosition - left; } comp.setBounds(left, (fullHeight - d.height) / 2, w, h); // if (i == size - 1) // d = comp.getMaximumSize(); // else // d = comp.getPreferredSize(); // if ((left + d.width) > right) // w = right - left; // else // w = d.width; // h = Math.min (height, d.height); // comp.setBounds (left, (fullHeight - d.height)/2, w, h); left += d.width; } } }
/** Lay out the container's components. */ public void layoutContainer(Container parent) { Dimension parentSize = parent.getSize(); if (parentSize.height <= 0 || parentSize.width <= 0) return; if (!_valid) validate(); _yyyy.doLayout(parent); for (int r = 0; r < _xxxx.length; r++) { int ystart = _yyyy.getRowStart(r); int yheight = _yyyy.getRowHeight(r); _xxxx[r].doLayout(parent, ystart, yheight); } }
public void layoutContainer(Container parent) { setSizes(parent); // compute center of the circle Insets insets = parent.getInsets(); int containerWidth = parent.getSize().width - insets.left - insets.right; int containerHeight = parent.getSize().height - insets.top - insets.bottom; int xcenter = insets.left + containerWidth / 2; int ycenter = insets.top + containerHeight / 2; // compute radius of the circle int xradius = (containerWidth - maxComponentWidth) / 2; int yradius = (containerHeight - maxComponentHeight) / 2; int radius = Math.min(xradius, yradius); // lay out components along the circle int n = parent.getComponentCount(); for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { double angle = 2 * Math.PI * i / n; // center point of component int x = xcenter + (int) (Math.cos(angle) * radius); int y = ycenter + (int) (Math.sin(angle) * radius); // move component so that its center is (x, y) // and its size is its preferred size Dimension d = c.getPreferredSize(); c.setBounds(x - d.width / 2, y - d.height / 2, d.width, d.height); } } }
/** * Lay out the container's components based on current settings. The free space in the container * is divided evenly into the specified number of rows and columns in this object. * * @param parent The container to lay out */ public void layoutContainer(Container parent) { int num = parent.ncomponents; // There's no point, and handling this would mean adding special // cases. if (num == 0) return; // This is more efficient than calling getComponents(). Component[] comps = parent.component; int real_rows = rows; int real_cols = cols; if (real_rows == 0) real_rows = (num + real_cols - 1) / real_cols; else real_cols = (num + real_rows - 1) / real_rows; // We might have less than a single row. In this case we expand // to fill. if (num < real_cols) real_cols = num; Dimension d = parent.getSize(); Insets ins = parent.getInsets(); // Compute width and height of each cell in the grid. int tw = d.width - ins.left - ins.right; tw = (tw - (real_cols - 1) * hgap) / real_cols; int th = d.height - ins.top - ins.bottom; th = (th - (real_rows - 1) * vgap) / real_rows; // If the cells are too small, still try to do something. if (tw < 0) tw = 1; if (th < 0) th = 1; int x = ins.left; int y = ins.top; int i = 0; int recount = 0; while (i < num) { comps[i].setBounds(x, y, tw, th); ++i; ++recount; if (recount == real_cols) { recount = 0; y += vgap + th; x = ins.left; } else x += hgap + tw; } }
private void checkCache(Container paramContainer) { if (paramContainer == null) return; if (this.dirty) this.grid = null; int i = PlatformDefaults.getModCount(); if (this.lastModCount != i) { this.grid = null; this.lastModCount = i; } if (!paramContainer.isValid()) { if (!this.lastWasInvalid) { this.lastWasInvalid = true; int j = 0; int k = 0; Object localObject1 = this.ccMap.keySet().iterator(); while (((Iterator) localObject1).hasNext()) { ComponentWrapper localComponentWrapper = (ComponentWrapper) ((Iterator) localObject1).next(); Object localObject2 = localComponentWrapper.getComponent(); if (((localObject2 instanceof JTextArea)) || ((localObject2 instanceof JEditorPane))) k = 1; j += localComponentWrapper.getLayoutHashCode(); } if (k != 0) resetLastInvalidOnParent(paramContainer); if (j != this.lastHash) { this.grid = null; this.lastHash = j; } localObject1 = paramContainer.getSize(); if ((this.lastInvalidSize == null) || (!this.lastInvalidSize.equals(localObject1))) { if (this.grid != null) this.grid.invalidateContainerSize(); this.lastInvalidSize = ((Dimension) localObject1); } } } else this.lastWasInvalid = false; ContainerWrapper localContainerWrapper = checkParent(paramContainer); setDebug(localContainerWrapper, getDebugMillis() > 0); if (this.grid == null) this.grid = new Grid( localContainerWrapper, this.lc, this.rowSpecs, this.colSpecs, this.ccMap, this.callbackList); this.dirty = false; }
@Override public void layoutContainer(Container aContainer) { layouted .entrySet() .stream() .forEach( (entry) -> { Component comp = entry.getKey(); if (comp.isVisible()) { Dimension containerSize = aContainer.getSize(); MarginConstraints constraints = entry.getValue(); Rectangle bounds = constraints.toRectangle(containerSize.width, containerSize.height); comp.setBounds(bounds); } }); }
/** * Returns the minimum amount of space the layout needs. * * @param parent the Container for which this layout manager is being used * @return a Dimension object containing the layout's minimum size */ public Dimension minimumLayoutSize(Container parent) { Dimension rd, mbd; Insets i = getInsets(); if (contentPane != null) { rd = contentPane.getMinimumSize(); } else { rd = parent.getSize(); } if (menuBar != null && menuBar.isVisible()) { mbd = menuBar.getMinimumSize(); } else { mbd = new Dimension(0, 0); } return new Dimension( Math.max(rd.width, mbd.width) + i.left + i.right, rd.height + mbd.height + i.top + i.bottom); }
public void layoutContainer(Container target) { /* * Algorithm is as follows: - the "left-hand" components take 33% of * horizontal space - scrollPane takes the remaining space */ synchronized (target.getTreeLock()) { if (pane == null || spane == null) return; Dimension dim = target.getSize(); if (dim.height < 20) return; spane.setBounds(new Rectangle(0, 0, dim.width, dim.height)); // Dimension dim0 = new Dimension(dim.width-2, dim.height-2); // pane.setPreferredSize(dim0); // JViewport viewPort = spane.getViewport(); // viewPort.setViewSize(dim0); // paramsLayout.setReferenceSize(dim0.width, dim0.height); } }
/*--------------------------------------------------------------------------*/ private void moveComponents( Container target, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr) { synchronized (target.getTreeLock()) { switch (newAlign) { case LEFT: x += ltr ? 0 : width; break; case CENTER: x += width / 2; break; case RIGHT: x += ltr ? width : 0; break; case LEADING: break; case TRAILING: x += width; break; } for (int i = rowStart; i < rowEnd; i++) { Component m = target.getComponent(i); if (m.isVisible()) { if (ltr) { m.setLocation(x, y + (height - m.getSize().height) / 2); } else { m.setLocation( target.getSize().width - x - m.getSize().width, y + (height - m.getSize().height) / 2); } x += m.getSize().width + hgap; } } } }
/** * This method is called to lay out the given container to position and size the child * components. * * @param c The container to lay out. * @throws Error DOCUMENT ME! */ public void layoutContainer(Container c) { if (!(c instanceof JToolBar)) throw new Error("DefaultToolBarLayout can only be used on JToolBars."); Insets insets = getInsets(); Insets margin = getMargin(); int middle; if (margin != null) { insets.left += margin.left; insets.top += margin.top; insets.bottom += margin.bottom; insets.right += margin.right; } Component[] components = c.getComponents(); Dimension tdims = c.getSize(); int start = 0; Dimension pref; if (getOrientation() == SwingUtilities.HORIZONTAL) { start += insets.left; for (int i = 0; i < components.length; i++) { if (components[i] != null && components[i].isVisible()) { pref = components[i].getPreferredSize(); if (pref != null) { middle = (tdims.height - pref.height) / 2; components[i].setBounds(start, middle, pref.width, pref.height); start += pref.width; } } } } else { start += insets.top; for (int i = 0; i < components.length; i++) { if (components[i] != null && components[i].isVisible()) { pref = components[i].getPreferredSize(); if (pref != null) { middle = (tdims.width - pref.width) / 2; components[i].setBounds(middle, start, pref.width, pref.height); start += pref.height; } } } } }
public void layoutContainer(Container parent) { Dimension size = parent.getSize(); Dimension captionSize = caption.getPreferredSize(); caption.setBounds(PADDING, PADDING, captionSize.width, captionSize.height); // make all buttons the same size Dimension buttonSize = cancelButton.getPreferredSize(); buttonSize.width = Math.max(buttonSize.width, prevButton.getPreferredSize().width); buttonSize.width = Math.max(buttonSize.width, nextButton.getPreferredSize().width); // cancel button goes on far left cancelButton.setBounds( PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); // prev and next buttons are on the right prevButton.setBounds( size.width - buttonSize.width * 2 - 6 - PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); nextButton.setBounds( size.width - buttonSize.width - PADDING, size.height - buttonSize.height - PADDING, buttonSize.width, buttonSize.height); // calculate size for current page Rectangle currentPageBounds = new Rectangle(); currentPageBounds.x = PADDING; currentPageBounds.y = PADDING * 2 + captionSize.height; currentPageBounds.width = size.width - currentPageBounds.x - PADDING; currentPageBounds.height = size.height - buttonSize.height - currentPageBounds.y - PADDING * 2; for (int i = 0; i < pages.length; i++) { Component page = pages[i]; page.setBounds(currentPageBounds); page.setVisible(i == currentPage); } }
public void layoutContainer(Container target) { Insets insets = target.getInsets(); Dimension size = target.getSize(); Dimension compMax = new Dimension(0, 0); int maxheight = size.height - (insets.top + insets.bottom + vgap * 2); int nmembers = target.getComponentCount(); int visiblecount = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { ++visiblecount; Dimension d = m.getPreferredSize(); compMax.width = Math.max(compMax.width, d.width); compMax.height = Math.max(compMax.height, d.height); } } if (visiblecount > 0) { int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height); int ncols = (visiblecount + nrows - 1) / nrows; int row = 0, col = 0, currComp = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); int x = insets.left + hgap + col * (compMax.width + hgap); int y = insets.top + vgap + row * (compMax.height + vgap); m.setBounds(x, y, d.width, d.height); // move index to next component ++currComp; if (++row >= nrows) { row = 0; ++col; } } } } repaint(); }
private void setBounds(Point location, Dimension size) { if (myView != null) { if (size == null) { size = myView.getSize(); } if (location == null) { location = myView.getLocation(); } else { Component parent = myView instanceof Window ? null : myView.getParent(); if (parent != null) { SwingUtilities.convertPointFromScreen(location, parent); } } myView.setBounds(location.x, location.y, size.width, size.height); if (myView.isVisible()) { myView.invalidate(); myView.validate(); myView.repaint(); } } }
/*--------------------------------------------------------------------------*/ public void layoutContainer(Container target) { synchronized (target.getTreeLock()) { Insets insets = target.getInsets(); int maxWidth = target.getSize().width - (insets.left + insets.right + hgap * 2); int nMembers = target.getComponentCount(); int x = 0; int y = insets.top + vgap; int rowh = 0; int start = 0; boolean ltr = target.getComponentOrientation().isLeftToRight(); for (int i = 0; i < nMembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); m.setSize(d.width, d.height); if ((x == 0) || ((x + d.width) <= maxWidth)) { if (x > 0) { x += hgap; } x += d.width; rowh = Math.max(rowh, d.height); } else { moveComponents(target, insets.left, y, maxWidth - x, rowh, start, i, ltr); x = d.width; y += vgap + rowh; rowh = d.height; start = i; } } } moveComponents(target, insets.left, y, maxWidth - x, rowh, start, nMembers, ltr); } }
@Override public void layoutContainer(final Container parent) { assert parent.getComponentCount() == 2; // 1. info; 2. progress Component infoPanel = parent.getComponent(0); Component progressPanel = parent.getComponent(1); int progressPrefWidth = progressPanel.getPreferredSize().width; final Dimension size = parent.getSize(); int maxProgressWidth = (int) (size.width * 0.8); int minProgressWidth = (int) (size.width * 0.5); if (progressPrefWidth > myProgressWidth) { myProgressWidth = progressPrefWidth; } if (myProgressWidth > maxProgressWidth) { myProgressWidth = maxProgressWidth; } if (myProgressWidth < minProgressWidth) { myProgressWidth = minProgressWidth; } infoPanel.setBounds(0, 0, size.width - myProgressWidth, size.height); progressPanel.setBounds(size.width - myProgressWidth, 0, myProgressWidth, size.height); }