use of com.ramussoft.gui.common.AbstractAttributeEditor in project ramus by Vitaliy-Yakovchuk.
the class SectorColorAttributePlugin method getAttributeEditor.
@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
if (old != null)
old.close();
return new AbstractAttributeEditor() {
private PaintSector.Pin pin;
private JColorChooser component;
private Color color;
{
component = new JColorChooser();
}
@Override
public Object setValue(Object value) {
this.pin = (PaintSector.Pin) value;
color = pin.getSector().getColor();
component.setColor(color);
return value;
}
@Override
public Object getValue() {
return pin;
}
@Override
public void apply(Engine engine, Element element, Attribute attribute, Object value) {
SectorColorAttributePlugin.this.apply(component.getColor(), pin);
}
@Override
public JComponent getComponent() {
return component;
}
@Override
public boolean isSaveAnyway() {
return !color.equals(component.getColor());
}
};
}
use of com.ramussoft.gui.common.AbstractAttributeEditor in project ramus by Vitaliy-Yakovchuk.
the class ColorAttributePlugin method getAttributeEditor.
@Override
public AttributeEditor getAttributeEditor(Engine engine, AccessRules rules, Element element, Attribute attribute, final String prefix, AttributeEditor old) {
if (old != null)
old.close();
return new AbstractAttributeEditor() {
private JColorChooser chooser = new JColorChooser();
@Override
public Object setValue(Object value) {
if (value != null)
chooser.setColor((Color) value);
else
chooser.setColor(Color.black);
return chooser.getColor();
}
@Override
public Object getValue() {
return chooser.getColor();
}
@Override
public JComponent getComponent() {
Options.loadOptions(prefix + "ColorEditor", chooser);
return chooser;
}
@Override
public void close() {
super.close();
Options.saveOptions(prefix + "ColorEditor", chooser);
}
};
}
use of com.ramussoft.gui.common.AbstractAttributeEditor in project ramus by Vitaliy-Yakovchuk.
the class FunctionOwnerAttributePlugin method getAttributeEditor.
@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, Attribute attribute, AttributeEditor old) {
if (old != null)
old.close();
return new AbstractAttributeEditor() {
private SelectOwner component = new SelectOwner();
@Override
public Object setValue(Object value) {
DataPlugin plugin = NDataPluginFactory.getDataPlugin(engine.getQualifier(element.getQualifierId()), engine, rules);
component.setFunction((Function) plugin.findRowByGlobalId(element.getId()));
return value;
}
@Override
public Object getValue() {
Row row = component.getOwner();
if (row != null)
return row.getElement().getId();
return null;
}
@Override
public JComponent getComponent() {
return component;
}
};
}
use of com.ramussoft.gui.common.AbstractAttributeEditor in project ramus by Vitaliy-Yakovchuk.
the class SectorFontAttributePlugin method getAttributeEditor.
@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
if (old != null)
old.close();
return new AbstractAttributeEditor() {
private PaintSector.Pin pin;
private JFontChooser component;
private Font font;
{
component = new JFontChooser();
ResourceLoader.setJComponentsText(component);
}
@Override
public Object setValue(Object value) {
this.pin = (PaintSector.Pin) value;
font = pin.getSector().getFont();
component.setSelFont(font);
return value;
}
@Override
public Object getValue() {
return pin;
}
@Override
public JComponent getComponent() {
return component;
}
@Override
public void apply(Engine engine, Element element, Attribute attribute, Object value) {
PaintSector sector = pin.getSector();
sector.setFont(component.getSelFont());
sector.copyVisual(Sector.VISUAL_COPY_ADDED);
pin.getSector().getMovingArea().getRefactor().setUndoPoint();
}
@Override
public boolean isSaveAnyway() {
return !font.equals(component.getSelFont());
}
};
}
use of com.ramussoft.gui.common.AbstractAttributeEditor in project ramus by Vitaliy-Yakovchuk.
the class TextAttributePlugin method getAttributeEditor.
@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
if (old != null)
old.close();
return new AbstractAttributeEditor() {
private TextPanelWithLinksDetector area = new TextPanelWithLinksDetector(TextAttributePlugin.this);
protected JTextComponentSpellChecker checker;
private Object value;
private JPopupMenu createSelectLanguageMenu() {
JMenu lMenu = new JMenu(GlobalResourcesManager.getString("Editor.Language"));
Language[] languages = SpellFactory.getLanguages();
final Properties ps = engine.getProperties(USER_GUI_SPELL_PROPERTIES);
Language dLanguage = getCurrentLanguage(ps);
ButtonGroup group = new ButtonGroup();
for (Language l : languages) {
final String ln = l.getName();
JRadioButtonMenuItem item = new JRadioButtonMenuItem(new AbstractAction(l.getLocalizedName()) {
/**
*/
private static final long serialVersionUID = -6106361308637383251L;
@Override
public void actionPerformed(ActionEvent e) {
ps.setProperty(LANGUAGE, ln);
saveProperties(engine, ps);
}
});
lMenu.add(item);
if ((dLanguage != null) && (dLanguage.equals(l)))
item.setSelected(true);
group.add(item);
}
JPopupMenu menu = new JPopupMenu();
JCheckBoxMenuItem item = new JCheckBoxMenuItem(GlobalResourcesManager.getString("Editor.SpellCheck"));
item.setSelected(isSpellCheck(ps));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Options.setBoolean(SPELL_CHECK, !isSpellCheck(ps), ps);
saveProperties(engine, ps);
}
});
menu.add(item);
menu.add(lMenu);
return menu;
}
private void saveProperties(final Engine engine, final Properties ps) {
engine.setProperties(USER_GUI_SPELL_PROPERTIES, ps);
if (checker != null) {
checker.stopRealtimeMarkErrors();
checker = null;
}
createChecker();
}
private boolean isSpellCheck(final Properties ps) {
return Options.getBoolean(SPELL_CHECK, true, ps);
}
private void createChecker() {
Properties ps = engine.getProperties(USER_GUI_SPELL_PROPERTIES);
if (isSpellCheck(ps)) {
Language language = getCurrentLanguage(ps);
if (language != null) {
checker = language.createTextComponentSpellChecker();
checker.startRealtimeMarkErrors(area);
}
}
}
private Language getCurrentLanguage(Properties ps) {
String langName = Options.getString(LANGUAGE, "", ps);
Language language;
if ((langName == null) || (langName.equals("")))
language = SpellFactory.getDefaultLanguage();
else
language = SpellFactory.findLanguage(langName);
return language;
}
@Override
public JComponent getComponent() {
JScrollPane pane = new JScrollPane();
pane.setViewportView(area);
boolean canEdit = rules.canUpdateElement(element.getId(), attribute.getId());
area.setEditable(canEdit);
area.setComponentPopupMenu(createSelectLanguageMenu());
createChecker();
return pane;
}
@Override
public Object getValue() {
String res = area.getText();
return ((res.equals("")) && (value == null)) ? null : res;
}
@Override
public Object setValue(Object value) {
this.value = value;
area.setText((String) value);
return value;
}
@Override
public void close() {
if (checker != null) {
checker.stopRealtimeMarkErrors();
checker = null;
}
}
@Override
public JComponent getLastComponent() {
return area;
}
};
}
Aggregations