use of bibliothek.gui.dock.common.action.CPanelPopup 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());
}
}
});
}
}
Aggregations