/** * Gets the number of contained components. Consistent with the iterator * returned by {@link #getComponentIterator()}. * * @return the number of contained components (zero, one or two) */ @Override public int getComponentCount() { int count = 0; if (getFirstComponent() != null) { count++; } if (getSecondComponent() != null) { count++; } return count; }
/** * Sets the second component of this split panel. Depending on the direction * the second component is shown at the bottom or to the right. * * @param c * The component to use as second component */ public void setSecondComponent(Component c) { if (getSecondComponent() == c) { // Nothing to do return; } if (getSecondComponent() != null) { // detach old removeComponent(getSecondComponent()); } getState().secondChild = c; if (c != null) { super.addComponent(c); } }
@Override public Component next() { if (!hasNext()) { return null; } i++; if (i == 1) { return (getFirstComponent() == null ? getSecondComponent() : getFirstComponent()); } else if (i == 2) { return getSecondComponent(); } return null; }
/** * Add a component into this container. The component is added to the right * or under the previous component. * * @param c * the component to be added. */ @Override public void addComponent(Component c) { if (getFirstComponent() == null) { setFirstComponent(c); } else if (getSecondComponent() == null) { setSecondComponent(c); } else { throw new UnsupportedOperationException( "Split panel can contain only two components"); } }
@Override public void replaceComponent(Component oldComponent, Component newComponent) { if (oldComponent == getFirstComponent()) { setFirstComponent(newComponent); } else if (oldComponent == getSecondComponent()) { setSecondComponent(newComponent); } }
/** * Removes the component from this container. * * @param c * the component to be removed. */ @Override public void removeComponent(Component c) { super.removeComponent(c); if (c == getFirstComponent()) { getState().firstChild = null; } else if (c == getSecondComponent()) { getState().secondChild = null; } }
Component secondComponent = getSecondComponent(); if (firstComponent != null) { Element childElement = designContext.createElement(firstComponent);