Search in sources :

Example 1 with CDecorateableAction

use of bibliothek.gui.dock.common.intern.action.CDecorateableAction in project ramus by Vitaliy-Yakovchuk.

the class GUIPluginFactory method addActions.

private void addActions(String id, final View view, final DefaultCDockable dockable, Action[] actions) {
    for (final Action action : actions) if (action == null) {
        dockable.addSeparator();
    } else {
        ImageIcon icon = (ImageIcon) action.getValue(Action.SMALL_ICON);
        if (icon == null) {
            icon = new ImageIcon(getClass().getResource("/com/ramussoft/gui/icon.png"));
        }
        final String command = (String) action.getValue(Action.ACTION_COMMAND_KEY);
        String text = null;
        if (view instanceof TabView) {
            text = ((TabView) view).getString(command);
        }
        if (text == null)
            text = findPluginForViewId(id).getString(command);
        if (text == null) {
            StringGetter getter = (StringGetter) action.getValue(StringGetter.ACTION_STRING_GETTER);
            if (getter != null)
                text = getter.getString(command);
        }
        final CDecorateableAction button;
        if (action.getValue(Action.SELECTED_KEY) == null) {
            final PopupTrigger trigger = (PopupTrigger) action.getValue(POPUP_MENU);
            if (trigger == null)
                button = new CButton(text, icon) {

                    @Override
                    protected void action() {
                        java.awt.event.ActionEvent e = new java.awt.event.ActionEvent(view, 0, command);
                        action.actionPerformed(e);
                    }
                };
            else {
                button = new CPanelPopup() {

                    @Override
                    public void openPopup(PanelPopupWindow window) {
                        super.openPopup(window);
                    }

                    @Override
                    protected void openDialog(JComponent item, Orientation orientation) {
                        JPanel menu = (JPanel) getContent();
                        menu.removeAll();
                        for (Action action : trigger.getPopupActions()) menu.add(new JButton(action));
                        menu.revalidate();
                        menu.repaint();
                        super.openDialog(item, orientation);
                    }
                };
                ((CPanelPopup) button).setContent(new JPanel(new GridLayout(0, 1, 0, 0)));
                button.setText(text);
                button.setIcon(icon);
            }
        } else {
            button = new CCheckBox(text, icon) {

                @Override
                protected void changed() {
                    java.awt.event.ActionEvent e = new java.awt.event.ActionEvent(view, 0, command);
                    action.putValue(Action.SELECTED_KEY, isSelected());
                    action.actionPerformed(e);
                }
            };
            action.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (Action.SELECTED_KEY.equals(evt.getPropertyName())) {
                        ((CCheckBox) button).setSelected((Boolean) evt.getNewValue());
                    }
                }
            });
            ((CCheckBox) button).setSelected((Boolean) action.getValue(Action.SELECTED_KEY));
        }
        String tooltip = (String) action.getValue(Action.LONG_DESCRIPTION);
        if (tooltip == null)
            tooltip = (String) action.getValue(Action.SHORT_DESCRIPTION);
        if (tooltip == null)
            tooltip = text;
        if (tooltip != null)
            button.setTooltip(tooltip);
        KeyStroke stroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
        if (stroke != null)
            button.setAccelerator(stroke);
        actionButtons.put(action, button);
        button.setEnabled(action.isEnabled());
        dockable.addAction(button);
        action.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("enabled")) {
                    button.setEnabled((Boolean) evt.getNewValue());
                }
            }
        });
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) AbstractAction(javax.swing.AbstractAction) CDecorateableAction(bibliothek.gui.dock.common.intern.action.CDecorateableAction) Action(javax.swing.Action) PropertyChangeListener(java.beans.PropertyChangeListener) PanelPopupWindow(bibliothek.gui.dock.common.action.panel.PanelPopupWindow) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) JButton(javax.swing.JButton) StringGetter(com.ramussoft.gui.common.StringGetter) CPanelPopup(bibliothek.gui.dock.common.action.CPanelPopup) GridLayout(java.awt.GridLayout) CCheckBox(bibliothek.gui.dock.common.action.CCheckBox) CDecorateableAction(bibliothek.gui.dock.common.intern.action.CDecorateableAction) CButton(bibliothek.gui.dock.common.action.CButton) PropertyChangeEvent(java.beans.PropertyChangeEvent) TabView(com.ramussoft.gui.common.TabView) PopupTrigger(com.ramussoft.gui.common.PopupTrigger) JComponent(javax.swing.JComponent) Orientation(bibliothek.gui.dock.title.DockTitle.Orientation) KeyStroke(javax.swing.KeyStroke)

Example 2 with CDecorateableAction

use of bibliothek.gui.dock.common.intern.action.CDecorateableAction in project ramus by Vitaliy-Yakovchuk.

the class GUIPluginFactory method initActions.

private void initActions(final String id, final View view, final DefaultCDockable dockable) {
    Action[] actions = view.getActions();
    addActions(id, view, dockable, actions);
    dockable.addSeparator();
    view.addViewTitleListener(new ViewTitleListener() {

        @Override
        public void titleChanged(ViewTitleEvent event) {
            dockable.setTitleText(event.getNewTitle());
        }
    });
    view.addActionChangeListener(new ActionChangeAdapter() {

        @Override
        public void actionsAdded(ActionChangeEvent event) {
            Action[] actions = event.getActions();
            List<Action> list = new ArrayList<Action>();
            for (Action a : actions) {
                if (a != null)
                    list.add(a);
            }
            addActions(id, view, dockable, list.toArray(new Action[list.size()]));
        }

        @Override
        public void actionsRemoved(ActionChangeEvent event) {
            for (Action a : event.getActions()) if (a != null) {
                CDecorateableAction button = actionButtons.remove(a);
                if (button != null)
                    dockable.removeAction(button);
            }
        }
    });
}
Also used : AbstractAction(javax.swing.AbstractAction) CDecorateableAction(bibliothek.gui.dock.common.intern.action.CDecorateableAction) Action(javax.swing.Action) ViewTitleEvent(com.ramussoft.gui.common.event.ViewTitleEvent) ActionChangeAdapter(com.ramussoft.gui.common.event.ActionChangeAdapter) ActionChangeEvent(com.ramussoft.gui.common.event.ActionChangeEvent) CDecorateableAction(bibliothek.gui.dock.common.intern.action.CDecorateableAction) List(java.util.List) ArrayList(java.util.ArrayList) ViewTitleListener(com.ramussoft.gui.common.event.ViewTitleListener)

Aggregations

CDecorateableAction (bibliothek.gui.dock.common.intern.action.CDecorateableAction)2 AbstractAction (javax.swing.AbstractAction)2 Action (javax.swing.Action)2 CButton (bibliothek.gui.dock.common.action.CButton)1 CCheckBox (bibliothek.gui.dock.common.action.CCheckBox)1 CPanelPopup (bibliothek.gui.dock.common.action.CPanelPopup)1 PanelPopupWindow (bibliothek.gui.dock.common.action.panel.PanelPopupWindow)1 Orientation (bibliothek.gui.dock.title.DockTitle.Orientation)1 PopupTrigger (com.ramussoft.gui.common.PopupTrigger)1 StringGetter (com.ramussoft.gui.common.StringGetter)1 TabView (com.ramussoft.gui.common.TabView)1 ActionChangeAdapter (com.ramussoft.gui.common.event.ActionChangeAdapter)1 ActionChangeEvent (com.ramussoft.gui.common.event.ActionChangeEvent)1 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)1 ViewTitleEvent (com.ramussoft.gui.common.event.ViewTitleEvent)1 ViewTitleListener (com.ramussoft.gui.common.event.ViewTitleListener)1 GridLayout (java.awt.GridLayout)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1