Search in sources :

Example 6 with Language

use of com.ramussoft.gui.spell.Language in project ramus by Vitaliy-Yakovchuk.

the class HTMLEditPanel method createChecker.

private void createChecker() {
    if (checker != null) {
        checker.stopRealtimeMarkErrors();
        checker = null;
    }
    Properties ps = engine.getProperties(USER_GUI_SPELL_PROPERTIES);
    if (isSpellCheck(ps)) {
        Language language = getCurrentLanguage(ps);
        if (language != null) {
            checker = language.createTextComponentSpellChecker();
            checker.startRealtimeMarkErrors(jTextPane);
        }
    }
}
Also used : Language(com.ramussoft.gui.spell.Language) Properties(java.util.Properties)

Example 7 with Language

use of com.ramussoft.gui.spell.Language in project ramus by Vitaliy-Yakovchuk.

the class HTMLEditPanel method getCurrentLanguage.

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;
}
Also used : Language(com.ramussoft.gui.spell.Language)

Example 8 with Language

use of com.ramussoft.gui.spell.Language in project ramus by Vitaliy-Yakovchuk.

the class QualifierPlugin method getProjectPreferences.

@Override
public Preferences[] getProjectPreferences() {
    return new Preferences[] { new AbstractPreferences() {

        class Button extends JRadioButton {

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

            private Language language;

            public Button(Language language) {
                this.language = language;
            }

            public Language getLanguage() {
                return language;
            }
        }

        private JPanel component;

        private Button[] buttons;

        private JCheckBox box;

        {
            Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
            Language language = getCurrentLanguage(ps);
            Language[] languages = SpellFactory.getLanguages();
            box = new JCheckBox(GlobalResourcesManager.getString("Editor.SpellCheck"));
            box.setSelected(Options.getBoolean(TextAttributePlugin.SPELL_CHECK, true, ps));
            JPanel languagesPanel = new JPanel();
            languagesPanel.setLayout(new BoxLayout(languagesPanel, BoxLayout.Y_AXIS));
            buttons = new Button[languages.length];
            ButtonGroup group = new ButtonGroup();
            for (int i = 0; i < languages.length; i++) {
                Button button = new Button(languages[i]);
                button.setText(languages[i].getLocalizedName());
                languagesPanel.add(button);
                buttons[i] = button;
                if (languages[i].equals(language))
                    button.setSelected(true);
                group.add(button);
            }
            JScrollPane pane = new JScrollPane();
            pane.setViewportView(languagesPanel);
            component = new JPanel(new BorderLayout());
            component.add(pane, BorderLayout.CENTER);
            component.add(box, BorderLayout.NORTH);
        }

        @Override
        public JComponent createComponent() {
            return component;
        }

        @Override
        public String getTitle() {
            return GlobalResourcesManager.getString("Preferences.SpellChecking");
        }

        @Override
        public boolean save(JDialog dialog) {
            Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
            Options.setBoolean(TextAttributePlugin.SPELL_CHECK, box.isSelected(), ps);
            String l = "";
            for (Button button : buttons) if (button.isSelected()) {
                l = button.getLanguage().getName();
                break;
            }
            Options.setString(TextAttributePlugin.LANGUAGE, l, ps);
            engine.setProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES, ps);
            return true;
        }

        private Language getCurrentLanguage(Properties ps) {
            String langName = Options.getString(TextAttributePlugin.LANGUAGE, "", ps);
            Language language;
            if ((langName == null) || (langName.equals("")))
                language = SpellFactory.getDefaultLanguage();
            else
                language = SpellFactory.findLanguage(langName);
            return language;
        }
    }, new AbstractPreferences() {

        SelectableTableView tableView;

        JComboBox attributeForName = new JComboBox();

        private JPanel panel;

        {
            tableView = new SelectableTableView(framework, engine, accessor, StandardAttributesPlugin.getAttributesQualifier(engine)) {

                @Override
                protected Attribute[] getAttributes() {
                    return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine), StandardAttributesPlugin.getAttributeTypeNameAttribute(engine) };
                }
            };
            double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
            JPanel attrForName = new JPanel(new TableLayout(size));
            attrForName.add(new JLabel(GlobalResourcesManager.getString("Qualifier.AttributeForName")), "1, 1");
            attrForName.add(attributeForName, "3, 1");
            panel = new JPanel(new BorderLayout());
            panel.add(tableView.createComponent(), BorderLayout.CENTER);
            panel.add(attrForName, BorderLayout.SOUTH);
            Properties ps = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
            String ids = ps.getProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS);
            if (ids == null)
                ids = "";
            String aForName = ps.getProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME);
            StringTokenizer st = new StringTokenizer(ids, " ,");
            List<Row> rows = tableView.getComponent().getRowSet().getAllRows();
            attributeForName.addItem(null);
            while (st.hasMoreElements()) {
                String s = st.nextToken();
                Long long1 = new Long(s);
                Row row = findRow(long1, rows);
                if (row != null) {
                    tableView.setSelectedRow(row, true);
                    attributeForName.addItem(row);
                    if (s.equals(aForName))
                        attributeForName.setSelectedItem(row);
                }
            }
            attributeForName.addPopupMenuListener(new PopupMenuListener() {

                @Override
                public void popupMenuCanceled(PopupMenuEvent e) {
                }

                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                }

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    attributeForName.removeAllItems();
                    List<Row> list = tableView.getSelectedRows();
                    for (Row p : list) {
                        Attribute a = StandardAttributesPlugin.getAttribute(engine, p.getElement());
                        if (StandardAttributesPlugin.isNameType(a.getAttributeType()))
                            attributeForName.addItem(p);
                    }
                    JComboBox box = (JComboBox) e.getSource();
                    Object comp = box.getUI().getAccessibleChild(box, 0);
                    if (!(comp instanceof JPopupMenu))
                        return;
                    JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
                    Dimension size = new Dimension();
                    size.width = box.getPreferredSize().width;
                    size.height = scrollPane.getPreferredSize().height;
                    scrollPane.setPreferredSize(size);
                }
            });
        }

        @Override
        public JComponent createComponent() {
            return panel;
        }

        private Row findRow(Long long1, List<Row> rows) {
            Attribute attr = engine.getAttribute(long1.longValue());
            if (attr != null) {
                for (Row row : rows) {
                    Long long2 = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
                    if (long2 != null) {
                        if (attr.getId() == long2.longValue())
                            return row;
                    }
                }
            }
            return null;
        }

        @Override
        public String getTitle() {
            return GlobalResourcesManager.getString("Preferences.AutoaddAttributes");
        }

        @Override
        public boolean save(JDialog dialog) {
            List<Row> list = tableView.getSelectedRows();
            StringBuffer sb = new StringBuffer();
            for (Row row : list) {
                Long id = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
                if (id != null)
                    sb.append(id + " ");
            }
            Properties properties = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
            properties.setProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS, sb.toString());
            Row row = (Row) attributeForName.getSelectedItem();
            if (row != null)
                properties.setProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME, Long.toString(StandardAttributesPlugin.getAttributeId(engine, row.getElement())));
            engine.setProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES, properties);
            return true;
        }

        @Override
        public void close() {
            tableView.close();
        }
    } };
}
Also used : JPanel(javax.swing.JPanel) Attribute(com.ramussoft.common.Attribute) BoxLayout(javax.swing.BoxLayout) PopupMenuListener(javax.swing.event.PopupMenuListener) Properties(java.util.Properties) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Language(com.ramussoft.gui.spell.Language) BorderLayout(java.awt.BorderLayout) JRadioButton(javax.swing.JRadioButton) List(java.util.List) Preferences(com.ramussoft.gui.common.prefrence.Preferences) AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) TableLayout(info.clearthought.layout.TableLayout) SelectableTableView(com.ramussoft.gui.qualifier.table.SelectableTableView) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) AbstractPreferences(com.ramussoft.gui.common.prefrence.AbstractPreferences) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) StringTokenizer(java.util.StringTokenizer) ButtonGroup(javax.swing.ButtonGroup) Row(com.ramussoft.database.common.Row) JDialog(javax.swing.JDialog)

Aggregations

Language (com.ramussoft.gui.spell.Language)8 Properties (java.util.Properties)6 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 ButtonGroup (javax.swing.ButtonGroup)3 JPopupMenu (javax.swing.JPopupMenu)3 AbstractAction (javax.swing.AbstractAction)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JMenu (javax.swing.JMenu)2 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)2 Attribute (com.ramussoft.common.Attribute)1 Row (com.ramussoft.database.common.Row)1 AbstractAttributeEditor (com.ramussoft.gui.common.AbstractAttributeEditor)1 AbstractPreferences (com.ramussoft.gui.common.prefrence.AbstractPreferences)1 Preferences (com.ramussoft.gui.common.prefrence.Preferences)1 SelectableTableView (com.ramussoft.gui.qualifier.table.SelectableTableView)1 TableLayout (info.clearthought.layout.TableLayout)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 List (java.util.List)1