Search in sources :

Example 1 with JAutoToggleButton

use of org.freeplane.core.ui.components.JAutoToggleButton 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 JAutoToggleButton

use of org.freeplane.core.ui.components.JAutoToggleButton in project freeplane by freeplane.

the class TranslatedElementFactory method createToggleButton.

public static JToggleButton createToggleButton(Action action, String labelKey) {
    final JToggleButton component = action != null ? new JAutoToggleButton(action) : new JAutoToggleButton();
    final String text = TextUtils.getRawText(labelKey);
    LabelAndMnemonicSetter.setLabelAndMnemonic(component, text);
    TranslatedElement.TEXT.setKey(component, labelKey);
    createTooltip(component, labelKey + ".tooltip");
    return component;
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) JToggleButton(javax.swing.JToggleButton)

Example 3 with JAutoToggleButton

use of org.freeplane.core.ui.components.JAutoToggleButton in project freeplane by freeplane.

the class TranslatedElementFactory method createToggleButtonWithIcon.

public static JToggleButton createToggleButtonWithIcon(final String iconKey, String tooltipKey) {
    final JToggleButton button = new JAutoToggleButton();
    createTooltip(button, tooltipKey);
    return addIcon(button, iconKey);
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) JToggleButton(javax.swing.JToggleButton)

Example 4 with JAutoToggleButton

use of org.freeplane.core.ui.components.JAutoToggleButton in project freeplane by freeplane.

the class JToolbarComponentBuilderTest method createsToolbarButtonWithSelectableAction.

@Test
public void createsToolbarButtonWithSelectableAction() {
    Entry actionEntry = new Entry();
    final AFreeplaneAction action = Mockito.mock(AFreeplaneAction.class);
    when(action.isSelectable()).thenReturn(true);
    new EntryAccessor().setAction(actionEntry, action);
    Entry toolbarEntry = new Entry();
    final FreeplaneToolBar toolbar = new FreeplaneToolBar("toolbar", SwingConstants.HORIZONTAL);
    new EntryAccessor().setComponent(toolbarEntry, toolbar);
    toolbarEntry.addChild(actionEntry);
    final JToolbarComponentBuilder toolbarActionGroupBuilder = new JToolbarComponentBuilder();
    toolbarActionGroupBuilder.visit(actionEntry);
    JAutoToggleButton button = (JAutoToggleButton) new EntryAccessor().getComponent(actionEntry);
    assertThat(button.getAction(), CoreMatchers.<Action>equalTo(action));
    assertThat(button.getParent(), CoreMatchers.equalTo((Container) toolbar));
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Container(java.awt.Container) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) FreeplaneToolBar(org.freeplane.core.ui.components.FreeplaneToolBar) JToolbarComponentBuilder(org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder) Test(org.junit.Test)

Example 5 with JAutoToggleButton

use of org.freeplane.core.ui.components.JAutoToggleButton in project freeplane by freeplane.

the class MenuBuilder method addButton.

private void addButton(final String category, final Action action, final String key, final int position) {
    final AbstractButton button;
    assert action != null;
    if (action.getClass().getAnnotation(SelectableAction.class) != null) {
        button = new JAutoToggleButton(action);
    } else {
        button = new JButton(action);
    }
    addElement(category, button, key, position);
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) AbstractButton(javax.swing.AbstractButton) JButton(javax.swing.JButton)

Aggregations

JAutoToggleButton (org.freeplane.core.ui.components.JAutoToggleButton)6 JButton (javax.swing.JButton)3 JToggleButton (javax.swing.JToggleButton)3 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)2 FreeplaneToolBar (org.freeplane.core.ui.components.FreeplaneToolBar)2 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)2 Component (java.awt.Component)1 Container (java.awt.Container)1 AbstractButton (javax.swing.AbstractButton)1 JComboBox (javax.swing.JComboBox)1 JToolBar (javax.swing.JToolBar)1 Separator (javax.swing.JToolBar.Separator)1 ResourceController (org.freeplane.core.resources.ResourceController)1 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)1 JToolbarComponentBuilder (org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder)1 DefaultConditionRenderer (org.freeplane.features.filter.condition.DefaultConditionRenderer)1 Controller (org.freeplane.features.mode.Controller)1 ModeController (org.freeplane.features.mode.ModeController)1 FrameController (org.freeplane.features.ui.FrameController)1 Test (org.junit.Test)1