Search in sources :

Example 1 with ViewPlugin

use of com.ramussoft.gui.common.ViewPlugin in project ramus by Vitaliy-Yakovchuk.

the class PlugableFrame method createToolBars.

@SuppressWarnings("unchecked")
private void createToolBars() {
    toolBarsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    for (Object object : toolBarActions) {
        Entry<String, Object> entry = (Entry<String, Object>) object;
        List<Action> list = (List) entry.getValue();
        JToolBar toolBar = new JToolBar();
        for (Action a : list) {
            if (a == null)
                toolBar.addSeparator();
            else {
                AbstractButton button;
                if (a.getValue(Action.SELECTED_KEY) == null)
                    button = toolBar.add(a);
                else {
                    ButtonGroup group = (ButtonGroup) a.getValue(BUTTON_GROUP);
                    button = new JToggleButton(a);
                    button.setToolTipText(button.getText());
                    button.setText(null);
                    toolBar.add(button);
                    Boolean added = (Boolean) a.getValue(BUTTON_GROUP_ADDED);
                    if (added == null)
                        added = Boolean.FALSE;
                    if ((group != null) && (!added.booleanValue())) {
                        group.add(button);
                        a.putValue(BUTTON_GROUP_ADDED, Boolean.TRUE);
                    }
                }
                button.setFocusable(false);
            }
        }
        toolBars.put(entry.getKey(), toolBar);
        toolBarsPanel.add(toolBar);
    }
    for (ViewPlugin p : plugins) {
        for (JToolBar bar : p.getToolBars()) {
            toolBarsPanel.add(bar);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) Action(javax.swing.Action) FlowLayout(java.awt.FlowLayout) AbstractButton(javax.swing.AbstractButton) JToolBar(javax.swing.JToolBar) Entry(java.util.Map.Entry) JToggleButton(javax.swing.JToggleButton) ButtonGroup(javax.swing.ButtonGroup) ArrayList(java.util.ArrayList) List(java.util.List) ViewPlugin(com.ramussoft.gui.common.ViewPlugin)

Example 2 with ViewPlugin

use of com.ramussoft.gui.common.ViewPlugin in project ramus by Vitaliy-Yakovchuk.

the class PlugableFrame method initActions.

private void initActions() {
    for (ViewPlugin plugin : plugins) {
        ActionDescriptor[] actionDescriptors = plugin.getActionDescriptors();
        for (ActionDescriptor actionDescriptor : actionDescriptors) {
            Action action = actionDescriptor.getAction();
            if (action != null) {
                String command = (String) action.getValue(Action.ACTION_COMMAND_KEY);
                String des = plugin.getString(getActionShortDescriptionKey(command));
                if (des == null) {
                    des = plugin.getString(getActionName(command));
                    if (des == null) {
                        StringGetter getter = (StringGetter) action.getValue(StringGetter.ACTION_STRING_GETTER);
                        if (getter != null)
                            des = getter.getString(getActionName(command));
                    }
                }
                action.putValue(Action.SHORT_DESCRIPTION, des);
                String value = plugin.getString(getActionName(command));
                if (value == null)
                    value = command;
                action.putValue(Action.NAME, value);
                des = plugin.getString(getActionLongDescriptionKey(command));
                if (des == null)
                    des = (String) action.getValue(Action.SHORT_DESCRIPTION);
                action.putValue(Action.LONG_DESCRIPTION, des);
                if (actionDescriptor.getActionLevel().equals(ActionLevel.VIEW)) {
                    viewActions.put(command, action);
                    action.setEnabled(false);
                }
            }
            add(actionDescriptor, plugin);
        }
    }
}
Also used : Action(javax.swing.Action) ActionDescriptor(com.ramussoft.gui.common.ActionDescriptor) StringGetter(com.ramussoft.gui.common.StringGetter) ViewPlugin(com.ramussoft.gui.common.ViewPlugin)

Aggregations

ViewPlugin (com.ramussoft.gui.common.ViewPlugin)2 Action (javax.swing.Action)2 ActionDescriptor (com.ramussoft.gui.common.ActionDescriptor)1 StringGetter (com.ramussoft.gui.common.StringGetter)1 FlowLayout (java.awt.FlowLayout)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 AbstractButton (javax.swing.AbstractButton)1 ButtonGroup (javax.swing.ButtonGroup)1 JPanel (javax.swing.JPanel)1 JToggleButton (javax.swing.JToggleButton)1 JToolBar (javax.swing.JToolBar)1