use of org.freeplane.core.ui.components.OneTouchCollapseResizer.ComponentCollapseListener in project freeplane by freeplane.
the class CollapseableBoxBuilder method createBox.
public Box createBox(final Component component, final Direction direction) {
Box resisableComponent = direction.createBox();
UIComponentVisibilityDispatcher.install(frameController, resisableComponent, propertyNameBase);
final UIComponentVisibilityDispatcher dispatcher = UIComponentVisibilityDispatcher.dispatcher(resisableComponent);
final String sizePropertyName = dispatcher.getPropertyName() + ".size";
final boolean expanded = dispatcher.isVisible();
OneTouchCollapseResizer resizer = new OneTouchCollapseResizer(direction);
dispatcher.setResizer(resizer);
switch(direction) {
case RIGHT:
case DOWN:
resisableComponent.add(resizer);
resisableComponent.add(component);
break;
default:
resisableComponent.add(component);
resisableComponent.add(resizer);
break;
}
if (resizeable) {
try {
int size = ResourceController.getResourceController().getIntProperty(sizePropertyName, DEFAULT_SIZE);
if (size <= 10) {
size = DEFAULT_SIZE;
}
direction.setPreferredSize(component, size);
} catch (Exception e) {
// blindly accept
}
resizer.addResizerListener(new ResizerListener() {
public void componentResized(ResizeEvent event) {
if (event.getComponent().equals(component)) {
ResourceController.getResourceController().setProperty(sizePropertyName, String.valueOf(direction.getPreferredSize(component)));
}
}
});
} else
resizer.setSliderLocked(true);
resizer.addCollapseListener(new ComponentCollapseListener() {
public void componentCollapsed(ResizeEvent event) {
if (event.getComponent().equals(component)) {
dispatcher.setProperty(false);
}
}
public void componentExpanded(ResizeEvent event) {
if (event.getComponent().equals(component)) {
dispatcher.setProperty(true);
}
}
});
resizer.setExpanded(expanded);
return resisableComponent;
}
Aggregations