Example usage for javax.swing.event DocumentListener DocumentListener

List of usage examples for javax.swing.event DocumentListener DocumentListener

Introduction

In this page you can find the example usage for javax.swing.event DocumentListener DocumentListener.

Prototype

DocumentListener

Source Link

Usage

From source file:org.domainmath.gui.MainFrame.java

public void dirty() {
    areaFileTab.getDocument().addDocumentListener(new DocumentListener() {

        @Override/*from   ww  w  . j  a va2 s  .  co m*/
        public void insertUpdate(DocumentEvent e) {
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            if (fileTab.getTabRunCount() > 0) {
                String n = fileTab.getTitleAt(fileTab.getSelectedIndex());
                if (!n.endsWith("*")) {
                    fileTab.setTitleAt(fileTab.getSelectedIndex(), n + "*");
                }
            }
        }
    });
}

From source file:org.esa.snap.smart.configurator.ui.PerformancePanel.java

PerformancePanel(PerformanceOptionsPanelController controller) {

    this.controller = controller;

    confOptimizer = ConfigurationOptimizer.getInstance();

    initComponents();//from   w ww . j a va 2 s . com

    DocumentListener textFieldListener = new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            controller.changed();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            controller.changed();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            controller.changed();
        }
    };

    vmParametersTextField.getDocument().addDocumentListener(textFieldListener);
    cachePathTextField.getDocument().addDocumentListener(textFieldListener);
    nbThreadsTextField.getDocument().addDocumentListener(textFieldListener);
    defaultTileSizeTextField.getDocument().addDocumentListener(textFieldListener);
    cacheSizeTextField.getDocument().addDocumentListener(textFieldListener);
}

From source file:org.gitools.ui.app.analysis.groupcomparison.wizard.GroupComparisonGroupingPage.java

public GroupComparisonGroupingPage(Heatmap heatmap, DimensionGroupEnum groupingType) {
    super();/*from   w  w  w . jav a 2  s.c om*/

    this.heatmap = heatmap;
    this.groupingType = groupingType;

    setLogo(IconUtils.getImageIconResourceScaledByHeight(IconNames.LOGO_METHOD, 96));

    layerCb.setModel(new DefaultComboBoxModel(heatmap.getLayers().getIds()));
    layerCb.setSelectedItem(heatmap.getLayers().getTopLayer().getId());

    groupsTable.setModel(tableModel);

    setTitle("Group selection");
    TableColumnModel columnModel = groupsTable.getColumnModel();
    columnModel.getColumn(2).setPreferredWidth(50);
    columnModel.getColumn(2).setCellEditor(new SpinnerCellEditor(new SpinnerNumberModel()));
    columnModel.getColumn(2).getCellEditor().addCellEditorListener(new CellEditorListener() {
        @Override
        public void editingStopped(ChangeEvent e) {
            tableModel.fireTableDataChanged();
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            tableModel.fireTableDataChanged();
        }
    });
    groupsTable.setRowHeight(25);

    groupsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateControls();
        }
    });

    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeSelected();
        }
    });

    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (getSelectedGroupingType().equals(DimensionGroupEnum.Annotation)) {
                //TODO: create Dialog with removedItems
            } else if (getSelectedGroupingType().equals(DimensionGroupEnum.Free)) {
                createFreeGroup();
            } else if (getSelectedGroupingType().equals(DimensionGroupEnum.Value)) {
                createValueGroup();
            }
            updateControls();
        }
    });

    dimensionCb.setModel(new DefaultComboBoxModel(new String[] { "Columns", "Rows" }));

    mergeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            performMerge();
        }
    });
    splitButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            performSplit();
        }
    });
    dimensionCb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            initGroups();
        }
    });

    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            initGroups();
        }
    };
    annotationRadioButton.addActionListener(listener);
    valueRadioButton.addActionListener(listener);
    noConstraintRadioButton.addActionListener(listener);

    ActionListener nullConversionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    };
    nullDiscardRadioButton.addActionListener(nullConversionListener);
    nullConversionRadioButton.addActionListener(nullConversionListener);

    nullConversionTextArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            updateControls();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateControls();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateControls();
        }
    });

    updateControls();

    layerCb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    });
}

From source file:org.interreg.docexplore.ServerConfigPanel.java

public ServerConfigPanel(final File config, final File serverDir) throws Exception {
    super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));

    this.serverDir = serverDir;
    this.books = new Vector<Book>();
    this.bookList = new JList(new DefaultListModel());

    JPanel listPanel = new JPanel(new BorderLayout());
    listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel")));
    bookList.setOpaque(false);//from   w  w  w . j  a  v  a 2s  .  com
    bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bookList.setCellRenderer(new ListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Book book = (Book) value;
            JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>");
            label.setOpaque(true);
            if (isSelected) {
                label.setBackground(TextToolbar.styleHighLightedBackground);
                label.setForeground(Color.white);
            }
            if (book.deleted)
                label.setForeground(Color.red);
            else if (!book.used)
                label.setForeground(Color.gray);
            return label;
        }
    });
    bookList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            setFields((Book) bookList.getSelectedValue());
        }
    });
    JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(500, 300));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    listPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) {
        public void actionPerformed(ActionEvent e) {
            final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory());
            if (inFile == null)
                return;

            try {
                final File tmpDir = new File(serverDir, "tmp");
                tmpDir.mkdir();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.unzip(inFile, tmpDir, progress);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);

                File tmpFile = new File(tmpDir, "index.tmp");
                ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile));
                String bookFile = input.readUTF();
                String bookName = input.readUTF();
                String bookDesc = input.readUTF();
                input.close();

                new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc,
                        new File(tmpDir, bookFile));
                FileUtils.cleanDirectory(tmpDir);
                FileUtils.deleteDirectory(tmpDir);
                updateBooks();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    }));
    listPanel.add(importPanel, BorderLayout.SOUTH);
    add(listPanel);

    JPanel setupPanel = new JPanel(
            new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));
    setupPanel.setBorder(
            BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel")));
    usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel"));
    usedBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book != null) {
                book.used = usedBox.isSelected();
                bookList.repaint();
            }
        }
    });
    setupPanel.add(usedBox);

    JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel")));
    nameField = new JTextField(50);
    nameField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.name = nameField.getText();
            bookList.repaint();
        }
    });
    fieldPanel.add(nameField);

    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel")));
    descField = new JTextPane();
    //descField.setWrapStyleWord(true);
    descField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.desc = descField.getText();
        }
    });
    scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(420, 50));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    fieldPanel.add(scrollPane);

    setupPanel.add(fieldPanel);

    exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) {
        public void actionPerformed(ActionEvent e) {
            File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory());
            if (file == null)
                return;
            final Book book = (Book) bookList.getSelectedValue();
            final File indexFile = new File(serverDir, "index.tmp");
            try {
                final File outFile = file;
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile));
                out.writeUTF(book.bookFile.getName());
                out.writeUTF(book.name);
                out.writeUTF(book.desc);
                out.close();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir },
                                    outFile, progress, 0, 1, 9);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
            if (indexFile.exists())
                indexFile.delete();
        }
    });
    deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.deleted = !book.deleted;
            bookList.repaint();
        }
    });

    JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    actionsPanel.add(exportButton);
    actionsPanel.add(deleteButton);
    setupPanel.add(actionsPanel);

    add(setupPanel);

    JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    optionsPanel
            .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel")));
    JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    timeoutField = new JTextField(5);
    timeoutPanel.add(timeoutField);
    timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel")));
    optionsPanel.add(timeoutPanel);
    add(optionsPanel);

    updateBooks();
    setFields(null);

    final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>";
    String idle = StringUtils.getTagContent(xml, "idle");
    if (idle != null)
        try {
            timeoutField.setText("" + Integer.parseInt(idle));
        } catch (Throwable e) {
        }
}

From source file:org.languagetool.gui.ConfigurationDialog.java

private void createNonOfficeElements(GridBagConstraints cons, JPanel portPanel) {
    serverCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiRunOnPort")));
    serverCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("guiRunOnPort")));
    serverCheckbox.setSelected(config.getRunServer());
    portPanel.add(serverCheckbox, cons);
    serverCheckbox.addActionListener(new ActionListener() {
        @Override/*from  w  w w  .j  av a2s  .  c  o m*/
        public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            serverPortField.setEnabled(serverCheckbox.isSelected());
            serverSettingsCheckbox.setEnabled(serverCheckbox.isSelected());
        }
    });
    serverCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setRunServer(serverCheckbox.isSelected());
        }
    });

    serverPortField = new JTextField(Integer.toString(config.getServerPort()));
    serverPortField.setEnabled(serverCheckbox.isSelected());
    serverSettingsCheckbox = new JCheckBox(Tools.getLabel(messages.getString("useGUIConfig")));
    serverPortField.setMinimumSize(new Dimension(100, 25)); // without this the box is just a few pixels small, but why?
    cons.gridx = 1;
    portPanel.add(serverPortField, cons);
    serverPortField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            try {
                int serverPort = Integer.parseInt(serverPortField.getText());
                if (serverPort > -1 && serverPort < MAX_PORT) {
                    serverPortField.setForeground(null);
                    config.setServerPort(serverPort);
                } else {
                    serverPortField.setForeground(Color.RED);
                }
            } catch (NumberFormatException ex) {
                serverPortField.setForeground(Color.RED);
            }
        }
    });

    cons.gridx = 0;
    cons.gridy = 10;
    serverSettingsCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("useGUIConfig")));
    serverSettingsCheckbox.setSelected(config.getUseGUIConfig());
    serverSettingsCheckbox.setEnabled(config.getRunServer());
    serverSettingsCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setUseGUIConfig(serverSettingsCheckbox.isSelected());
        }
    });
    portPanel.add(serverSettingsCheckbox, cons);
}

From source file:org.languagetool.gui.ConfigurationDialog.java

private void createOfficeElements(GridBagConstraints cons, JPanel portPanel) {
    int numParaCheck = config.getNumParasToCheck();
    JRadioButton[] radioButtons = new JRadioButton[3];
    ButtonGroup numParaGroup = new ButtonGroup();
    radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph")));
    radioButtons[0].setActionCommand("ParagraphCheck");

    radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText")));
    radioButtons[1].setActionCommand("FullTextCheck");

    radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs")));
    radioButtons[2].setActionCommand("NParagraphCheck");
    radioButtons[2].setSelected(true);//from   www  . ja v a 2 s  .c  om

    JTextField numParaField = new JTextField(Integer.toString(5), 2);
    numParaField.setEnabled(radioButtons[2].isSelected());
    numParaField.setMinimumSize(new Dimension(30, 25));

    for (int i = 0; i < 3; i++) {
        numParaGroup.add(radioButtons[i]);
    }

    if (numParaCheck == 0) {
        radioButtons[0].setSelected(true);
        numParaField.setEnabled(false);
    } else if (numParaCheck < 0) {
        radioButtons[1].setSelected(true);
        numParaField.setEnabled(false);
    } else {
        radioButtons[2].setSelected(true);
        numParaField.setText(Integer.toString(numParaCheck));
        numParaField.setEnabled(true);
    }

    radioButtons[0].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(0);
        }
    });

    radioButtons[1].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(-1);
        }
    });

    radioButtons[2].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numParaCheck = Integer.parseInt(numParaField.getText());
            if (numParaCheck < 1)
                numParaCheck = 1;
            else if (numParaCheck > 99)
                numParaCheck = 99;
            config.setNumParasToCheck(numParaCheck);
            numParaField.setForeground(Color.BLACK);
            numParaField.setText(Integer.toString(numParaCheck));
            numParaField.setEnabled(true);
        }
    });

    numParaField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            try {
                int numParaCheck = Integer.parseInt(numParaField.getText());
                if (numParaCheck > 0 && numParaCheck < 99) {
                    numParaField.setForeground(Color.BLACK);
                    config.setNumParasToCheck(numParaCheck);
                } else {
                    numParaField.setForeground(Color.RED);
                }
            } catch (NumberFormatException ex) {
                numParaField.setForeground(Color.RED);
            }
        }
    });

    JLabel textChangedLabel = new JLabel(Tools.getLabel(messages.getString("guiTextChangeLabel")));
    cons.gridy++;
    portPanel.add(textChangedLabel, cons);

    cons.gridy++;
    cons.insets = new Insets(0, 30, 0, 0);
    for (int i = 0; i < 3; i++) {
        portPanel.add(radioButtons[i], cons);
        if (i < 2)
            cons.gridy++;
    }
    cons.gridx = 1;
    portPanel.add(numParaField, cons);

    JCheckBox noMultiResetbox = new JCheckBox(Tools.getLabel(messages.getString("guiNoMultiReset")));
    noMultiResetbox.setSelected(config.isNoMultiReset());
    noMultiResetbox.setEnabled(config.isResetCheck());
    noMultiResetbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setNoMultiReset(noMultiResetbox.isSelected());
        }
    });

    JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck")));
    resetCheckbox.setSelected(config.isResetCheck());
    resetCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setDoResetCheck(resetCheckbox.isSelected());
            noMultiResetbox.setEnabled(resetCheckbox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    JLabel dummyLabel = new JLabel(" ");
    //    cons.gridy++;
    //    portPanel.add(dummyLabel, cons);
    cons.gridy++;
    portPanel.add(resetCheckbox, cons);

    cons.insets = new Insets(0, 30, 0, 0);
    cons.gridx = 0;
    cons.gridy++;
    portPanel.add(noMultiResetbox, cons);

    JCheckBox fullTextCheckAtFirstBox = new JCheckBox(
            Tools.getLabel(messages.getString("guiCheckFullTextAtFirst")));
    fullTextCheckAtFirstBox.setSelected(config.doFullCheckAtFirst());
    fullTextCheckAtFirstBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setFullCheckAtFirst(fullTextCheckAtFirstBox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    cons.gridy++;
    //    JLabel dummyLabel2 = new JLabel(" ");
    //    portPanel.add(dummyLabel2, cons);
    cons.gridy++;
    portPanel.add(fullTextCheckAtFirstBox, cons);

    JCheckBox isMultiThreadBox = new JCheckBox(Tools.getLabel(messages.getString("guiIsMultiThread")));
    isMultiThreadBox.setSelected(config.isMultiThread());
    isMultiThreadBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setMultiThreadLO(isMultiThreadBox.isSelected());
        }
    });
    cons.gridy++;
    JLabel dummyLabel3 = new JLabel(" ");
    portPanel.add(dummyLabel3, cons);
    cons.gridy++;
    portPanel.add(isMultiThreadBox, cons);

}

From source file:org.languagetool.gui.ConfigurationDialog.java

private JPanel getSpecialRuleValuePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.gridx = 0;//from   w  w  w  . j  av a2s . c om
    cons.gridy = 0;
    cons.weightx = 0.0f;
    cons.anchor = GridBagConstraints.WEST;

    List<JCheckBox> ruleCheckboxes = new ArrayList<JCheckBox>();
    List<JLabel> ruleLabels = new ArrayList<JLabel>();
    List<JTextField> ruleValueFields = new ArrayList<JTextField>();

    for (int i = 0; i < configurableRules.size(); i++) {
        Rule rule = configurableRules.get(i);
        JCheckBox ruleCheckbox = new JCheckBox(rule.getDescription());
        ruleCheckboxes.add(ruleCheckbox);
        ruleCheckbox.setSelected(getEnabledState(rule));
        cons.insets = new Insets(3, 0, 0, 0);
        panel.add(ruleCheckbox, cons);

        cons.insets = new Insets(0, 24, 0, 0);
        cons.gridy++;
        JLabel ruleLabel = new JLabel(rule.getConfigureText());
        ruleLabels.add(ruleLabel);
        ruleLabel.setEnabled(ruleCheckbox.isSelected());
        panel.add(ruleLabel, cons);

        cons.gridx++;
        int value = config.getConfigurableValue(rule.getId());
        if (config.getConfigurableValue(rule.getId()) < 0) {
            value = rule.getDefaultValue();
        }
        JTextField ruleValueField = new JTextField(Integer.toString(value), 2);
        ruleValueFields.add(ruleValueField);
        ruleValueField.setEnabled(ruleCheckbox.isSelected());
        ruleValueField.setMinimumSize(new Dimension(35, 25)); // without this the box is just a few pixels small, but why?
        panel.add(ruleValueField, cons);

        ruleCheckbox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
                ruleValueField.setEnabled(ruleCheckbox.isSelected());
                ruleLabel.setEnabled(ruleCheckbox.isSelected());
                if (ruleCheckbox.isSelected()) {
                    config.getEnabledRuleIds().add(rule.getId());
                    config.getDisabledRuleIds().remove(rule.getId());
                } else {
                    config.getEnabledRuleIds().remove(rule.getId());
                    config.getDisabledRuleIds().add(rule.getId());
                }
            }
        });

        ruleValueField.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                try {
                    int num = Integer.parseInt(ruleValueField.getText());
                    if (num < rule.getMinConfigurableValue()) {
                        num = rule.getMinConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else if (num > rule.getMaxConfigurableValue()) {
                        num = rule.getMaxConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else {
                        ruleValueField.setForeground(null);
                    }
                    config.setConfigurableValue(rule.getId(), num);
                } catch (Exception ex) {
                    ruleValueField.setForeground(Color.RED);
                }
            }
        });

        cons.gridx = 0;
        cons.gridy++;

    }
    return panel;
}

From source file:org.languagetool.gui.LanguageToolSupport.java

private void init() {
    try {// w w w .  j  a va2 s .  c  o  m
        config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, null);
    } catch (IOException ex) {
        throw new RuntimeException("Could not load configuration", ex);
    }

    Language defaultLanguage = config.getLanguage();
    if (defaultLanguage == null) {
        defaultLanguage = Languages.getLanguageForLocale(Locale.getDefault());
    }

    /**
     * Warm-up: we have a lot of lazy init in LT, which causes the first check to
     * be very slow (several seconds) for languages with a lot of data and a lot of
     * rules. We just assume that the default language is the language that the user
     * often uses and init the LT object for that now, not just when it's first used.
     * This makes the first check feel much faster:
     */
    reloadLanguageTool(defaultLanguage);

    checkExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            t.setPriority(Thread.MIN_PRIORITY);
            t.setName(t.getName() + "-lt-background");
            return t;
        }
    });

    check = new AtomicInteger(0);

    this.textComponent.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), false);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            recalculateSpans(e.getOffset(), e.getLength(), true);
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            mustDetectLanguage = config.getAutoDetect();
            if (backgroundCheckEnabled) {
                checkDelayed(null);
            }
        }
    });

    mouseListener = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent me) {
        }

        @Override
        public void mousePressed(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            if (me.isPopupTrigger()) {
                showPopup(me);
            }
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    };
    this.textComponent.addMouseListener(mouseListener);

    actionListener = e -> _actionPerformed(e);

    mustDetectLanguage = config.getAutoDetect();
    if (!this.textComponent.getText().isEmpty() && backgroundCheckEnabled) {
        checkImmediately(null);
    }
}

From source file:org.nekorp.workflow.desktop.view.DatosClienteView.java

@Override
public void iniciaVista() {
    initComponents();/*from ww  w.j av  a 2 s.c  om*/
    bindComponents();
    searchModel = new ClienteSearchJListModel();
    search.setModel(searchModel);
    //esto resuelve el problema de regresar el foco a la caja de texto.
    search.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (search.hasFocus()) {
                nombreCliente.requestFocus();
            }
        }
    });
    this.nombreCliente.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            actualizarNombreCliente();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            actualizarNombreCliente();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            actualizarNombreCliente();
        }
    });
    this.cancelIcon.add(iconProvider.getIcon(cancelSearchIconRaw));
    this.searchIcon.add(iconProvider.getIcon(searchIconRaw));
}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep2(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("configuration.transfer.options", "Optionen"), localeDelegate.getMessage(
                    "dbtransfer.import.step2.1", "Bitte w\u00e4hlen Sie die Import Optionen aus.")) {

        @Override/*from   www .  j ava  2s.  c  o  m*/
        public void prepare() {
            Map<TransferOption, Serializable> exportOptions = TransferOption
                    .copyOptionMap(importTransferObject.getTransferOptions());

            chbxIncludeUser.setEnabled(exportOptions.containsKey(TransferOption.INCLUDES_USER));
            chbxIncludeUser.setText(sDefaultIncludeUserText + (chbxIncludeUser.isEnabled() ? ""
                    : " (" + localeDelegate.getMessage("dbtransfer.import.step2.2",
                            "nicht in Konfigurationsdatei enthalten") + ")"));
            chbxIncludeLDAP.setEnabled(exportOptions.containsKey(TransferOption.INCLUDES_USER));
            chbxIncludeLDAP.setText(sDefaultIncludeLDAPText + (chbxIncludeLDAP.isEnabled() ? ""
                    : " (" + localeDelegate.getMessage("dbtransfer.import.step2.2",
                            "nicht in Konfigurationsdatei enthalten") + ")"));
            chbxIncludeObjectimport.setEnabled(exportOptions.containsKey(TransferOption.INCLUDES_USER));
            chbxIncludeObjectimport
                    .setText(sDefaultIncludeObjectimportText + (chbxIncludeObjectimport.isEnabled() ? ""
                            : " (" + localeDelegate.getMessage("dbtransfer.import.step2.2",
                                    "nicht in Konfigurationsdatei enthalten") + ")"));

            tfAlternativeDBLogin.setEnabled(chbxAlternativeDBLogin.isSelected());
            pfAlternativeDBPassword.setEnabled(chbxAlternativeDBLogin.isSelected());

            this.setComplete(validateStep2());
        }
    };
    utils.initJPanel(step, new double[] { 30, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL },
            new double[] { 20, 20, 20, 20, 20, 20, 20, TableLayout.PREFERRED });

    sDefaultIncludeUserText = localeDelegate.getMessage("dbtransfer.import.step2.3", "Benutzer importieren");
    sDefaultIncludeLDAPText = localeDelegate.getMessage("configuration.transfer.import.option.ldap",
            "LDAP Konfiguration importieren");
    sDefaultIncludeObjectimportText = localeDelegate
            .getMessage("configuration.transfer.import.option.objectimport", "Objektimport importieren");
    chbxIncludeUser.setText(sDefaultIncludeUserText);
    chbxIncludeLDAP.setText(sDefaultIncludeLDAPText);
    chbxIncludeObjectimport.setText(sDefaultIncludeObjectimportText);
    chbxAlternativeDBLogin.setText(
            localeDelegate.getMessage("dbtransfer.import.step2.5", "verwende alternativen Datenbanklogin"));

    final JLabel lbAlternativeDBLogin = new JLabel(
            localeDelegate.getMessage("dbtransfer.import.step2.7", "Login"));
    final JLabel lbAlternativeDBPassword = new JLabel(
            localeDelegate.getMessage("dbtransfer.import.step2.8", "Passwort"));

    step.add(chbxIncludeUser, "0,0,2,0");
    step.add(chbxIncludeLDAP, "0,1,2,1");
    step.add(chbxIncludeObjectimport, "0,2,2,2");
    step.add(chbxAlternativeDBLogin, "0,4,2,4");
    step.add(lbAlternativeDBLogin, "1,5,l,c");
    step.add(tfAlternativeDBLogin, "2,5,l,c");
    step.add(lbAlternativeDBPassword, "1,6,l,c");
    step.add(pfAlternativeDBPassword, "2,6,l,c");
    //      step.add(lbWarningWhenNoStructureChange, "0,7,3,0");

    ActionListener validateAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            step.setComplete(validateStep2());
        }
    };
    chbxIncludeUser.addActionListener(validateAction);
    chbxIncludeLDAP.addActionListener(validateAction);
    chbxIncludeObjectimport.addActionListener(validateAction);
    chbxAlternativeDBLogin.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tfAlternativeDBLogin.setText("");
            tfAlternativeDBLogin.setEnabled(chbxAlternativeDBLogin.isSelected());
            pfAlternativeDBPassword.setText("");
            pfAlternativeDBPassword.setEnabled(chbxAlternativeDBLogin.isSelected());
            step.setComplete(validateStep2());
        }
    });
    tfAlternativeDBLogin.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }
    });
    pfAlternativeDBPassword.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            step.setComplete(validateStep2());
        }
    });

    return step;
}