Search in sources :

Example 1 with StringGetter

use of com.ramussoft.gui.common.StringGetter 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 StringGetter

use of com.ramussoft.gui.common.StringGetter 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)

Example 3 with StringGetter

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

the class AttributeEditorDialog method init.

protected void init(Engine engine, Attribute attribute, Element element, GUIFramework framework, AccessRules rules, Object value) {
    String t = GlobalResourcesManager.getString("AttributeEditorDialog.Title") + " - ";
    String name = framework.getSystemAttributeName(attribute);
    if (name == null)
        name = attribute.getName();
    setTitle(t + element.getName() + " | " + name);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    panel = new AttributeEditorPanel() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void close() {
            super.close();
            AttributeEditorDialog.this.setVisible(false);
            AttributeEditorDialog.this.closed();
        }

        @Override
        protected String getSavePrefix() {
            return "1";
        }

        @Override
        public boolean apply() {
            boolean apply = super.apply();
            if (apply)
                onApply(this.value);
            return apply;
        }
    };
    AttributePlugin p = framework.findAttributePlugin(attribute);
    attributeEditor = p.getAttributeEditor(engine, rules, element, attribute, "attributeEditorDialog", null);
    panel.setAttributeEditor(attributeEditor, engine, attribute, element, rules.canUpdateElement(element.getId(), attribute.getId()), value);
    JPanel panel = new JPanel(new BorderLayout()) {

        /**
         */
        private static final long serialVersionUID = -8409626746568642304L;

        @Override
        protected boolean processKeyBinding(final KeyStroke ks, final KeyEvent e, final int condition, final boolean pressed) {
            if (!ks.isOnKeyRelease() && ks.getKeyCode() == KeyEvent.VK_ENTER && e.isControlDown()) {
                AttributeEditorDialog.this.panel.ok();
                return false;
            }
            if (!ks.isOnKeyRelease() && ks.getKeyCode() == KeyEvent.VK_ESCAPE) {
                AttributeEditorDialog.this.panel.cancel();
                return false;
            }
            return super.processKeyBinding(ks, e, condition, pressed);
        }
    };
    panel.add(this.panel, BorderLayout.CENTER);
    Action[] actions = attributeEditor.getActions();
    if (actions.length > 0) {
        JToolBar bar = new JToolBar();
        for (Action action : actions) if (action != null) {
            String command = (String) action.getValue(Action.ACTION_COMMAND_KEY);
            JButton button = bar.add(action);
            button.setFocusable(false);
            if (action.getValue(Action.SHORT_DESCRIPTION) == null) {
                String text = null;
                text = p.getString(command);
                if (text == null) {
                    StringGetter getter = (StringGetter) action.getValue(StringGetter.ACTION_STRING_GETTER);
                    if (getter != null)
                        text = getter.getString(command);
                    else
                        text = GlobalResourcesManager.getString(command);
                }
                if (text != null)
                    button.setToolTipText(text);
            }
        } else
            bar.addSeparator();
        panel.add(bar, BorderLayout.NORTH);
    }
    this.setContentPane(panel);
    setEditsAction(panel);
    pack();
    setLocationRelativeTo(null);
    Options.loadOptions(this);
    this.panel.loadPreferences();
    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            AttributeEditorDialog.this.panel.cancel();
            Options.saveOptions(AttributeEditorDialog.this);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) Action(javax.swing.Action) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JToolBar(javax.swing.JToolBar) StringGetter(com.ramussoft.gui.common.StringGetter) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke)

Example 4 with StringGetter

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

the class SelectableTableView method createToolBar.

public JToolBar createToolBar() {
    JToolBar bar = new JToolBar();
    for (Action action : getActions()) {
        if (action != null) {
            String command = (String) action.getValue(Action.ACTION_COMMAND_KEY);
            JButton button = bar.add(action);
            button.setFocusable(false);
            if (action.getValue(Action.SHORT_DESCRIPTION) == null) {
                String text = null;
                StringGetter getter = (StringGetter) action.getValue(StringGetter.ACTION_STRING_GETTER);
                if (getter != null)
                    text = getter.getString(command);
                else
                    text = GlobalResourcesManager.getString(command);
                if (text != null)
                    button.setToolTipText(text);
            }
        } else
            bar.addSeparator();
    }
    return bar;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JButton(javax.swing.JButton) JToolBar(javax.swing.JToolBar) StringGetter(com.ramussoft.gui.common.StringGetter)

Aggregations

StringGetter (com.ramussoft.gui.common.StringGetter)4 Action (javax.swing.Action)4 JButton (javax.swing.JButton)3 AbstractAction (javax.swing.AbstractAction)2 JPanel (javax.swing.JPanel)2 JToolBar (javax.swing.JToolBar)2 KeyStroke (javax.swing.KeyStroke)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 CDecorateableAction (bibliothek.gui.dock.common.intern.action.CDecorateableAction)1 Orientation (bibliothek.gui.dock.title.DockTitle.Orientation)1 ActionDescriptor (com.ramussoft.gui.common.ActionDescriptor)1 AttributePlugin (com.ramussoft.gui.common.AttributePlugin)1 PopupTrigger (com.ramussoft.gui.common.PopupTrigger)1 TabView (com.ramussoft.gui.common.TabView)1 ViewPlugin (com.ramussoft.gui.common.ViewPlugin)1 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)1 BorderLayout (java.awt.BorderLayout)1