1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
AbstractSplitPanel
is base class for a component container that
* can contain two components. The components are split by a divider element.
*
* @author Vaadin Ltd.
* @since 6.5
*/
public abstract class AbstractSplitPanel extends AbstractComponentContainer {
// TODO use Unit in AbstractSplitPanelState and remove these
private Unit posUnit;
private Unit posMinUnit;
private Unit posMaxUnit;
private AbstractSplitPanelRpc rpc = new AbstractSplitPanelRpc() {
@Override
public void splitterClick(MouseEventDetails mouseDetails) {
fireEvent(new SplitterClickEvent(AbstractSplitPanel.this,
mouseDetails));
}
@Override
public void setSplitterPosition(float position) {
getSplitterState().position = position;
}
};
public AbstractSplitPanel() {
registerRpc(rpc);
setSplitPosition(50, Unit.PERCENTAGE, false);
setSplitPositionLimits(0, Unit.PERCENTAGE, 100, Unit.PERCENTAGE);
}
/**
* Modifiable and Serializable Iterator for the components, used by
* {@link AbstractSplitPanel#getComponentIterator()}.
*/
private class ComponentIterator implements Iteratortrue
if locked, false
otherwise.
*/
public void setLocked(boolean locked) {
getSplitterState().locked = locked;
}
/**
* Is the SplitPanel handle locked (user not allowed to change split
* position by dragging).
*
* @return true
if locked, false
otherwise.
*/
public boolean isLocked() {
return getSplitterState(false).locked;
}
/**
* SplitterClickListener
interface for listening for
* SplitterClickEvent
fired by a SplitPanel
.
*
* @see SplitterClickEvent
* @since 6.2
*/
public interface SplitterClickListener extends ConnectorEventListener {
public static final Method clickMethod = ReflectTools.findMethod(
SplitterClickListener.class, "splitterClick",
SplitterClickEvent.class);
/**
* SplitPanel splitter has been clicked
*
* @param event
* SplitterClickEvent event.
*/
public void splitterClick(SplitterClickEvent event);
}
public static class SplitterClickEvent extends ClickEvent {
public SplitterClickEvent(Component source,
MouseEventDetails mouseEventDetails) {
super(source, mouseEventDetails);
}
}
public void addSplitterClickListener(SplitterClickListener listener) {
addListener(EventId.CLICK_EVENT_IDENTIFIER, SplitterClickEvent.class,
listener, SplitterClickListener.clickMethod);
}
/**
* @deprecated As of 7.0, replaced by
* {@link #addSplitterClickListener(SplitterClickListener)}
**/
@Deprecated
public void addListener(SplitterClickListener listener) {
addSplitterClickListener(listener);
}
public void removeSplitterClickListener(SplitterClickListener listener) {
removeListener(EventId.CLICK_EVENT_IDENTIFIER,
SplitterClickEvent.class, listener);
}
/**
* @deprecated As of 7.0, replaced by
* {@link #removeSplitterClickListener(SplitterClickListener)}
**/
@Deprecated
public void removeListener(SplitterClickListener listener) {
removeSplitterClickListener(listener);
}
@Override
protected AbstractSplitPanelState getState() {
return (AbstractSplitPanelState) super.getState();
}
@Override
protected AbstractSplitPanelState getState(boolean markAsDirty) {
return (AbstractSplitPanelState) super.getState(markAsDirty);
}
private SplitterState getSplitterState() {
return ((AbstractSplitPanelState) super.getState()).splitterState;
}
private SplitterState getSplitterState(boolean markAsDirty) {
return ((AbstractSplitPanelState) super.getState(markAsDirty)).splitterState;
}
/*
* (non-Javadoc)
*
* @see com.vaadin.ui.AbstractComponent#readDesign(org.jsoup.nodes .Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void readDesign(Element design, DesignContext designContext) {
// handle default attributes
super.readDesign(design, designContext);
// handle custom attributes, use default values if no explicit value
// set
// There is no setter for reversed, so it will be handled using
// setSplitPosition.
boolean reversed = false;
if (design.hasAttr("reversed")) {
reversed = DesignAttributeHandler.readAttribute("reversed",
design.attributes(), Boolean.class);
setSplitPosition(getSplitPosition(), reversed);
}
if (design.hasAttr("split-position")) {
SizeWithUnit splitPosition = SizeWithUnit.parseStringSize(
design.attr("split-position"), Unit.PERCENTAGE);
setSplitPosition(splitPosition.getSize(), splitPosition.getUnit(),
reversed);
}
if (design.hasAttr("min-split-position")) {
SizeWithUnit minSplitPosition = SizeWithUnit.parseStringSize(
design.attr("min-split-position"), Unit.PERCENTAGE);
setMinSplitPosition(minSplitPosition.getSize(),
minSplitPosition.getUnit());
}
if (design.hasAttr("max-split-position")) {
SizeWithUnit maxSplitPosition = SizeWithUnit.parseStringSize(
design.attr("max-split-position"), Unit.PERCENTAGE);
setMaxSplitPosition(maxSplitPosition.getSize(),
maxSplitPosition.getUnit());
}
// handle children
if (design.children().size() > 2) {
throw new DesignException(
"A split panel can contain at most two components.");
}
for (Element childElement : design.children()) {
Component childComponent = designContext.readDesign(childElement);
if (childElement.hasAttr(":second")) {
setSecondComponent(childComponent);
} else {
addComponent(childComponent);
}
}
}
@Override
protected Collectionsummaryrefslogtreecommitdiffstats |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|