Search in sources :

Example 1 with AbstractAttributeEditor

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());
        }
    };
}
Also used : AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Attribute(com.ramussoft.common.Attribute) Color(java.awt.Color) Element(com.ramussoft.common.Element) JColorChooser(javax.swing.JColorChooser) Engine(com.ramussoft.common.Engine)

Example 2 with AbstractAttributeEditor

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);
        }
    };
}
Also used : AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) Color(java.awt.Color) JColorChooser(javax.swing.JColorChooser)

Example 3 with AbstractAttributeEditor

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;
        }
    };
}
Also used : AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) SelectOwner(com.ramussoft.pb.idef.frames.SelectOwner) Row(com.ramussoft.pb.Row) DataPlugin(com.ramussoft.pb.DataPlugin)

Example 4 with AbstractAttributeEditor

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());
        }
    };
}
Also used : AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Attribute(com.ramussoft.common.Attribute) JFontChooser(com.ramussoft.pb.frames.components.JFontChooser) Element(com.ramussoft.common.Element) Font(java.awt.Font) Engine(com.ramussoft.common.Engine)

Example 5 with AbstractAttributeEditor

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;
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) JTextComponentSpellChecker(org.dts.spell.swing.JTextComponentSpellChecker) Properties(java.util.Properties) AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) Language(com.ramussoft.gui.spell.Language) ActionListener(java.awt.event.ActionListener)

Aggregations

AbstractAttributeEditor (com.ramussoft.gui.common.AbstractAttributeEditor)8 Element (com.ramussoft.common.Element)5 Attribute (com.ramussoft.common.Attribute)4 Engine (com.ramussoft.common.Engine)4 PaintSector (com.ramussoft.pb.idef.elements.PaintSector)4 DataPlugin (com.ramussoft.pb.DataPlugin)2 Row (com.ramussoft.pb.Row)2 Pin (com.ramussoft.pb.idef.elements.PaintSector.Pin)2 Color (java.awt.Color)2 JColorChooser (javax.swing.JColorChooser)2 DataLoader (com.dsoft.utils.DataLoader)1 ChartDataFramework (com.ramussoft.chart.ChartDataFramework)1 ChartDataPlugin (com.ramussoft.chart.ChartDataPlugin)1 ChartSource (com.ramussoft.chart.ChartSource)1 ElementSource (com.ramussoft.chart.ElementSource)1 FilterSource (com.ramussoft.chart.FilterSource)1 QualifierSource (com.ramussoft.chart.QualifierSource)1 TableChartPersistent (com.ramussoft.chart.core.TableChartPersistent)1 Qualifier (com.ramussoft.common.Qualifier)1 Language (com.ramussoft.gui.spell.Language)1