Search in sources :

Example 1 with Separator

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;
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JButton(javax.swing.JButton) Component(java.awt.Component) Separator(javax.swing.JToolBar.Separator)

Example 2 with Separator

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);
}
Also used : Dimension(java.awt.Dimension) Component(java.awt.Component) Separator(javax.swing.JToolBar.Separator)

Example 3 with Separator

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);
    }
}
Also used : Dimension(java.awt.Dimension) Component(java.awt.Component) Separator(javax.swing.JToolBar.Separator)

Aggregations

Component (java.awt.Component)3 Separator (javax.swing.JToolBar.Separator)3 Dimension (java.awt.Dimension)2 JButton (javax.swing.JButton)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 JAutoToggleButton (org.freeplane.core.ui.components.JAutoToggleButton)1 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)1