use of javax.swing.JToolBar.Separator in project freeplane by freeplane.
the class ToolbarComponentProvider method createComponent.
/* (non-Javadoc)
* @see org.freeplane.core.ui.menubuilders.menu.ComponentProvider#createComponent(org.freeplane.core.ui.menubuilders.generic.Entry)
*/
@Override
public Component createComponent(Entry entry) {
final EntryAccessor entryAccessor = new EntryAccessor();
final Object existingComponent = entryAccessor.getComponent(entry);
if (existingComponent != null)
return (Component) existingComponent;
final AFreeplaneAction action = entryAccessor.getAction(entry);
Component component;
if (action != null) {
if (action.isSelectable()) {
component = new JAutoToggleButton(action);
} else {
component = new JButton(action);
}
} else if (entry.builders().contains("separator")) {
component = new Separator();
} else
component = null;
return component;
}
use of javax.swing.JToolBar.Separator in project freeplane by freeplane.
the class ToolbarLayout method preferredLayoutSize.
public Dimension preferredLayoutSize(final Container container) {
final int maxWidth = container.getParent().getWidth();
int width = 0;
int heigth = 0;
int blockWidth = 0;
int blockHeight = 0;
int lastBlockWidth = 0;
int lastBlockHeight = 0;
for (int i = 0; ; i++) {
final Component component = i < container.getComponentCount() ? container.getComponent(i) : null;
if (component == null || component instanceof Separator) {
if (lastBlockWidth + blockWidth > maxWidth) {
width = Math.max(width, lastBlockWidth);
heigth += lastBlockHeight;
lastBlockWidth = blockWidth;
lastBlockHeight = blockHeight;
} else {
lastBlockWidth += blockWidth;
lastBlockHeight = Math.max(blockHeight, lastBlockHeight);
}
blockWidth = 0;
blockHeight = 0;
}
if (component == null) {
width = Math.max(width, lastBlockWidth);
heigth += lastBlockHeight;
break;
}
final Dimension compPreferredSize = component.getPreferredSize();
blockWidth += compPreferredSize.width;
blockHeight = Math.max(compPreferredSize.height, blockHeight);
}
return new Dimension(width, heigth);
}
use of javax.swing.JToolBar.Separator in project freeplane by freeplane.
the class ToolbarLayout method layoutContainer.
public void layoutContainer(final Container container) {
if (!container.isVisible())
return;
final int maxWidth = container.getParent().getWidth();
int heigth = 0;
int blockWidth = 0;
int blockHeight = 0;
int lastBlockWidth = 0;
int lastBlockHeight = 0;
int lastBlockStart = 0;
int lastBlockFinish = 0;
for (int i = 0; ; i++) {
final Component component = i < container.getComponentCount() ? container.getComponent(i) : null;
if (component == null || component instanceof Separator) {
if (i > container.getComponentCount() || lastBlockWidth + blockWidth > maxWidth) {
int x = 0;
for (int j = lastBlockStart; j < lastBlockFinish; j++) {
final Component c = container.getComponent(j);
final Dimension cPreferredSize = c.getPreferredSize();
c.setBounds(x, heigth, cPreferredSize.width, lastBlockHeight);
x += cPreferredSize.width;
}
heigth += lastBlockHeight;
lastBlockWidth = blockWidth;
lastBlockHeight = blockHeight;
lastBlockStart = lastBlockFinish;
} else {
lastBlockWidth += blockWidth;
lastBlockHeight = Math.max(blockHeight, lastBlockHeight);
}
lastBlockFinish = i;
blockWidth = 0;
blockHeight = 0;
}
if (component == null) {
if (lastBlockStart == container.getComponentCount()) {
break;
}
lastBlockFinish = container.getComponentCount();
continue;
}
final Dimension compPreferredSize = component.getPreferredSize();
blockWidth += compPreferredSize.width;
blockHeight = Math.max(compPreferredSize.height, blockHeight);
}
}
Aggregations