/** * Gets the menu at the specified position in the menu bar. * * @param index an int giving the position in the menu bar, where * 0 is the first position * @return the SMenu at that position */ public SMenu getMenu(int index) { SComponent c = super.getComponent(index); if (c instanceof SMenu) return (SMenu) c; return null; }
@Override public void write(Device d, SLayoutManager l) throws IOException { SContainer c = l.getContainer(); for (int i = 0; i < c.getComponentCount(); i++) c.getComponent(i).write(d); } }
/** * CAVEAT this did not work yet... We need to clone the layout manager as * well, so SLayoutManager must be Cloneable */ @Override public Object clone() { try { SContainer erg = (SContainer) super.clone(); // uiuiui, layout manager must be cloned as well,... // componentList and constraintList contain references to the // original components / constraints erg.getComponentList().clear(); erg.getConstraintList().clear(); for (int i = 0; i < getComponentCount(); i++) { erg.addComponent((SComponent) getComponent(i).clone()); } return erg; } catch (Exception e) { log.error("Unable to clone container", e); return null; } }
@Override public SComponent getComponent(String name) { if ("frame".equals(name)) { int count = container.getComponentCount(); if (count > 0) { return container.getComponent(0); } else { throw new IllegalStateException("The root container contains " + count + " components but a root container can not contain more than 1 component."); } } if ("windows".equals(name)) { if (container instanceof SRootContainer) { return ((SRootContainer) container).getWindowsPane(); } } return null; }
/** * Removes the component at the given position from the container. * * @param index remove the component at position <i>index</i> * from this container */ public void remove(int index) { SComponent c = getComponent(index); remove(c); }
/** * remove the dialog, that is on top of the stack. * * @return the dialog, that is popped from the stack. */ public SWindow popWindow() { int count = windowsPane.getComponentCount(); if (count < 1) { throw new IllegalStateException("there's no window left!"); } SWindow window = (SWindow) windowsPane.getComponent(count - 1); removeWindow(window); LOG.debug("pop window = " + window.getName()); return window; }
@Override protected void setRecursivelyVisible(boolean recursivelyVisible) { super.setRecursivelyVisible(recursivelyVisible); boolean childrenVisible = recursivelyVisible && isVisible() && isShowingChildren(); for (int i = 0; i < getComponentCount(); i++) { getComponent(i).setRecursivelyVisible(childrenVisible); } }
/** * Sets a new layout manager. * * @param l * new layout manager */ public void setLayout(SLayoutManager l) { SLayoutManager oldVal = this.layout; if (layout != null) { for (int i = 0; i < getComponentCount(); i++) { layout.removeComponent(getComponent(i)); } layout.setContainer(null); } layout = l; if (layout != null) { for (int i = 0; i < getComponentCount(); i++) { layout.addComponent(getComponent(i), getConstraintAt(i), i); } layout.setContainer(this); } propertyChangeSupport.firePropertyChange("layoutManager", oldVal, this.layout); }
/** * Flips to the first card of the container. * * @param parent the name of the parent container * in which to do the layout. */ public void first(SContainer parent) { checkLayout(parent); for (int i = 0; i < parent.getComponentCount(); i++) if (i > 0) parent.getComponent(i).setVisible(false); else parent.getComponent(i).setVisible(true); container.setRecursivelyVisible(container.isRecursivelyVisible()); }
/** * Flips to the last card of the container. * * @param parent the name of the parent container * in which to do the layout. */ public void last(SContainer parent) { checkLayout(parent); int ncomponents = parent.getComponentCount(); for (int i = 0; i < ncomponents; i++) { if (i < ncomponents - 1) parent.getComponent(i).setVisible(false); else parent.getComponent(i).setVisible(true); } container.setRecursivelyVisible(container.isRecursivelyVisible()); }
/** * Sets the parent frame. * * @param f parent frame */ @Override protected void setParentFrame(SFrame f) { if (f != super.getParentFrame()) { super.setParentFrame(f); for (int i = 0; i < getComponentCount(); i++) { getComponent(i).setParentFrame(getParentFrame()); } } }
/** * Flips to the next card of the specified container. If the * currently visible card is the last one, this method flips to the * first card in the layout. * * @param parent the name of the parent container * in which to do the layout. */ public void next(SContainer parent) { checkLayout(parent); int ncomponents = parent.getComponentCount(); for (int i = 0; i < ncomponents; i++) { SComponent comp = parent.getComponent(i); if (comp.isVisible()) { comp.setVisible(false); comp = parent.getComponent((i + 1 < ncomponents) ? i + 1 : 0); comp.setVisible(true); return; } } container.setRecursivelyVisible(container.isRecursivelyVisible()); }
/** * Flips to the previous card of the specified container. If the * currently visible card is the first one, this method flips to the * last card in the layout. * * @param parent the name of the parent container * in which to do the layout. */ public void previous(SContainer parent) { checkLayout(parent); int ncomponents = parent.getComponentCount(); for (int i = 0; i < ncomponents; i++) { SComponent comp = parent.getComponent(i); if (comp.isVisible()) { comp.setVisible(false); comp = parent.getComponent((i > 0) ? i - 1 : ncomponents - 1); comp.setVisible(true); return; } } container.setRecursivelyVisible(container.isRecursivelyVisible()); }
/** * Renders a container using its Layout manager or fallback just one after another. */ public static void renderContainer(Device d, SContainer c) throws IOException { final SLayoutManager layout = c.getLayout(); if (layout == null) { d.print("<tbody><tr><td>"); // just write out the components one after another for (int i = 0; i < c.getComponentCount(); i++) { c.getComponent(i).write(d); } d.print("</td></tr></tbody>"); } else { layout.write(d); } }
/** * Flips to the component that was added to this layout with the * specified <code>name</code>, using <code>addLayoutComponent</code>. * If no such component exists, then nothing happens. * * @param parent the name of the parent container * in which to do the layout. * @param name the component name. */ public void show(SContainer parent, Object name) { checkLayout(parent); SComponent next = (SComponent) tab.get(name); if ((next != null) && !next.isVisible()) { for (int i = 0; i < parent.getComponentCount(); i++) parent.getComponent(i).setVisible(false); next.setVisible(true); } container.setRecursivelyVisible(container.isRecursivelyVisible()); }