List of usage examples for java.awt Container getComponents
public Component[] getComponents()
From source file:com.quinsoft.zeidon.objectbrowser.WindowBoundsRestorer.java
private void getBounds(String key, Component c) { key = key + c.getName();/*from w w w. jav a 2 s . c om*/ String position = String.format("%d,%d,%d,%d", c.getX(), c.getY(), c.getWidth(), c.getHeight()); properties.setProperty(key, position); if (c instanceof Container) { key = key + "/"; Container container = (Container) c; for (Component child : container.getComponents()) getBounds(key, child); } }
From source file:com.quinsoft.zeidon.objectbrowser.WindowBoundsRestorer.java
private void setBounds(String key, Component c) { key = key + c.getName();//from w w w. j a va 2 s . co m String position = properties.getProperty(key); if (c.getName() != null && !StringUtils.isBlank(position)) { String[] nums = position.split(","); c.setBounds(Integer.parseInt(nums[0]), Integer.parseInt(nums[1]), Integer.parseInt(nums[2]), Integer.parseInt(nums[3])); } if (c instanceof Container) { key = key + "/"; Container container = (Container) c; for (Component child : container.getComponents()) setBounds(key, child); } }
From source file:com.eviware.soapui.utils.ContainerWalker.java
private java.util.List<Component> findAllComponentsIn(Container container) { java.util.List<Component> components = new ArrayList<Component>(); for (Component component : container.getComponents()) { components.add(component);//w w w. j av a 2 s. c o m if (component instanceof Container) { components.addAll(findAllComponentsIn((Container) component)); } } return components; }
From source file:EntryLayout.java
/** * Lays out the container in the specified panel. This is a row-column type * layout; find x, y, width and height of each Component. * /*from ww w. j a v a 2 s .co m*/ * @param parent * The Container whose children we are laying out. */ public void layoutContainer(Container parent) { if (!validWidths) return; Component[] components = parent.getComponents(); Dimension contSize = parent.getSize(); int x = 0; for (int i = 0; i < components.length; i++) { int row = i / COLUMNS; int col = i % COLUMNS; Component c = components[i]; Dimension d = c.getPreferredSize(); int colWidth = (int) (contSize.width * widthPercentages[col]); if (col == 0) { x = hpad; } else { x += hpad * (col - 1) + (int) (contSize.width * widthPercentages[col - 1]); } int y = vpad * (row) + (row * heights[row]) + (heights[row] - d.height); Rectangle r = new Rectangle(x, y, colWidth, d.height); c.setBounds(r); } }
From source file:OverlayLayout.java
/** * Calculates the minimum size dimensions for the specified * container, given the components it contains. * * @param parent the component to be laid out * @return the minimum size computed for the parent. * @see #preferredLayoutSize/* w w w . ja v a2 s .c o m*/ */ public Dimension minimumLayoutSize(final Container parent) { synchronized (parent.getTreeLock()) { final Insets ins = parent.getInsets(); final Component[] comps = parent.getComponents(); int height = 0; int width = 0; for (int i = 0; i < comps.length; i++) { if ((comps[i].isVisible() == false) && this.ignoreInvisible) { continue; } final Dimension pref = comps[i].getMinimumSize(); if (pref.height > height) { height = pref.height; } if (pref.width > width) { width = pref.width; } } return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom); } }
From source file:OverlayLayout.java
/** * Calculates the preferred size dimensions for the specified * container, given the components it contains. * * @param parent the container to be laid out * @return the preferred size computed for the parent. * @see #minimumLayoutSize// www . j a v a 2 s. c o m */ public Dimension preferredLayoutSize(final Container parent) { synchronized (parent.getTreeLock()) { final Insets ins = parent.getInsets(); final Component[] comps = parent.getComponents(); int height = 0; int width = 0; for (int i = 0; i < comps.length; i++) { if ((comps[i].isVisible() == false) && this.ignoreInvisible) { continue; } final Dimension pref = comps[i].getPreferredSize(); if (pref.height > height) { height = pref.height; } if (pref.width > width) { width = pref.width; } } return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom); } }
From source file:EntryLayout.java
/** * Compute the size of the whole mess. Serves as the guts of * preferredLayoutSize() and minimumLayoutSize(). * /* w ww . java2 s .c om*/ * @param parent * The container in which to do the layout. * @param hp * The horizontal padding (may be zero) * @param vp * The Vertical Padding (may be zero). */ protected Dimension computeLayoutSize(Container parent, int hp, int vp) { if (!validWidths) return null; Component[] components = parent.getComponents(); Dimension contSize = parent.getSize(); int preferredWidth = 0, preferredHeight = 0; widths = new int[COLUMNS]; heights = new int[components.length / COLUMNS]; // System.out.println("Grid: " + widths.length + ", " + heights.length); int i; // Pass One: Compute largest widths and heights. for (i = 0; i < components.length; i++) { int row = i / widthPercentages.length; int col = i % widthPercentages.length; Component c = components[i]; Dimension d = c.getPreferredSize(); widths[col] = Math.max(widths[col], d.width); heights[row] = Math.max(heights[row], d.height); } // Pass two: agregate them. for (i = 0; i < widths.length; i++) preferredWidth += widths[i] + hp; for (i = 0; i < heights.length; i++) preferredHeight += heights[i] + vp; // Finally, pass the sums back as the actual size. return new Dimension(preferredWidth, preferredHeight); }
From source file:net.sf.jabref.gui.search.SearchBar.java
private void paintBackgroundWhite(Container container) { container.setBackground(Color.WHITE); for (Component component : container.getComponents()) { component.setBackground(Color.WHITE); if (component instanceof Container) { paintBackgroundWhite((Container) component); }//ww w . j a va 2 s . com } }
From source file:OverlayLayout.java
/** * Lays out the specified container./*from www. j a v a2 s .co m*/ * * @param parent the container to be laid out */ public void layoutContainer(final Container parent) { synchronized (parent.getTreeLock()) { final Insets ins = parent.getInsets(); final Rectangle bounds = parent.getBounds(); final int width = bounds.width - ins.left - ins.right; final int height = bounds.height - ins.top - ins.bottom; final Component[] comps = parent.getComponents(); for (int i = 0; i < comps.length; i++) { final Component c = comps[i]; if ((comps[i].isVisible() == false) && this.ignoreInvisible) { continue; } c.setBounds(ins.left, ins.top, width, height); } } }
From source file:fr.duminy.jbackup.swing.ProgressPanelTest.java
private void checkState(TaskState taskState, Long value, Long maxValue, Throwable error, Future<?> task) { assertThat(panel.getBorder()).isExactlyInstanceOf(TitledBorder.class); assertThatPanelHasTitle(panel, TITLE); JPanelFixture progressPanel = new JPanelFixture(robot(), panel); robot().settings().componentLookupScope(ComponentLookupScope.ALL); JProgressBarFixture progressBar = progressPanel.progressBar(); robot().settings().componentLookupScope(ComponentLookupScope.SHOWING_ONLY); String expectedMessage;/*ww w . ja va 2 s . c o m*/ final boolean taskInProgress; switch (taskState) { case NOT_STARTED: taskInProgress = false; progressBar.requireIndeterminate().requireText("Not started"); assertThat(panel.isFinished()).as("isFinished").isFalse(); break; case TASK_DEFINED: taskInProgress = false; break; case STARTED: taskInProgress = (task != null); progressBar.requireIndeterminate().requireText("Estimating total size"); assertThat(panel.isFinished()).as("isFinished").isFalse(); break; case TOTAL_SIZE_COMPUTED: case PROGRESS: taskInProgress = (task != null); int iValue; int iMaxValue; if (maxValue > Integer.MAX_VALUE) { iValue = Utils.toInteger(value, maxValue); iMaxValue = Integer.MAX_VALUE; } else { iValue = value.intValue(); iMaxValue = maxValue.intValue(); } expectedMessage = format("%s/%s written (%1.2f %%)", byteCountToDisplaySize(value), byteCountToDisplaySize(maxValue), Utils.percent(value, maxValue)); progressBar.requireDeterminate().requireValue(iValue).requireText(expectedMessage); assertThat(progressBar.component().getMinimum()).isEqualTo(0); assertThat(progressBar.component().getMaximum()).isEqualTo(iMaxValue); assertThat(panel.isFinished()).as("isFinished").isFalse(); break; case FINISHED: default: taskInProgress = false; if (error == null) { progressBar.requireDeterminate().requireText("Finished"); } else { expectedMessage = error.getMessage(); if (expectedMessage == null) { expectedMessage = error.getClass().getSimpleName(); } progressBar.requireDeterminate().requireText("Error : " + expectedMessage); } assertThat(panel.isFinished()).as("isFinished").isTrue(); break; } Container parent = null; if (!TaskState.FINISHED.equals(taskState)) { // checks progress panel is visible parent = panel.getParent(); assertThat(parent).isNotNull(); assertThat(parent.getComponents()).contains(panel); } if (taskInProgress) { assertThat(panel.isFinished()).isFalse(); assertThat(task.isCancelled()).as("task cancelled").isFalse(); // cancel the task JButtonFixture cancelButton = progressPanel.button(); cancelButton.requireText("").requireToolTip("Cancel the task"); assertThat(cancelButton.component().getIcon()).isNotNull(); cancelButton.click(); // checks progress panel is not visible assertThat(panel.isFinished()).isTrue(); assertThat(panel.getParent()).isNull(); assertThat(parent.getComponents()).doesNotContain(panel); assertThat(task.isCancelled()).as("task cancelled").isTrue(); assertThat(((TestableTask) task).getMayInterruptIfRunning()).as("MayInterruptIfRunning").isFalse(); } else { // check no cancel button is visible if the task has been defined requireCancelButton(progressPanel, taskState == TaskState.TASK_DEFINED); } }