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());
}
}
});
}
}
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);
}
}
}
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);
}
});
}
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;
}
Aggregations