Search in sources :

Example 71 with DocumentListener

use of javax.swing.event.DocumentListener in project knime-core by knime.

the class VariableFileReaderNodeDialog method createSettingsPanel.

private JPanel createSettingsPanel() {
    JButton advanced = new JButton("Advanced...");
    int buttonHeight = advanced.getPreferredSize().height;
    m_hasRowHeaders = new JCheckBox("read row IDs");
    m_hasRowHeaders.setToolTipText("Check if the file contains row IDs" + " in the first column");
    m_hasColHeaders = new JCheckBox("read column headers");
    m_hasColHeaders.setToolTipText("Check if the file contains column" + " headers in the first line");
    JLabel deliLabel = new JLabel("Column delimiter:");
    m_delimField = new JComboBox();
    m_delimField.setMaximumSize(new Dimension(70, buttonHeight));
    m_delimField.setMinimumSize(new Dimension(70, buttonHeight));
    m_delimField.setPreferredSize(new Dimension(70, buttonHeight));
    m_delimField.setEditable(true);
    Delimiter[] selDelims = DEFAULT_DELIMS;
    m_delimField.setModel(new DefaultComboBoxModel(selDelims));
    deliLabel.setToolTipText("Specify the data delimiter character(s)");
    m_delimField.setToolTipText("Specify the data delimiter character(s)");
    m_cStyleComment = new JCheckBox("Java-style comments");
    m_cStyleComment.setToolTipText("Check to add support for '//' and " + "\"'/*' and '*/'\" comment");
    m_singleLineComment = new JTextField(2);
    m_singleLineComment.setMaximumSize(new Dimension(55, buttonHeight));
    m_singleLineComment.setMinimumSize(new Dimension(55, buttonHeight));
    m_singleLineComment.setPreferredSize(new Dimension(55, buttonHeight));
    JLabel commentLabel = new JLabel("Single line comment:");
    m_ignoreWS = new JCheckBox("ignore spaces and tabs");
    m_ignoreWS.setToolTipText("If checked, whitespaces (spaces and tabs)" + " will be discarded (if not quoted)");
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, 3));
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Basic Settings"));
    // top row
    Box rowBox = Box.createHorizontalBox();
    rowBox.add(m_hasRowHeaders);
    rowBox.add(Box.createGlue());
    Box delimBox = Box.createHorizontalBox();
    delimBox.add(Box.createHorizontalStrut(4));
    delimBox.add(deliLabel);
    delimBox.add(Box.createHorizontalStrut(3));
    delimBox.add(m_delimField);
    delimBox.add(Box.createGlue());
    Box advBox = Box.createHorizontalBox();
    advBox.add(Box.createGlue());
    advBox.add(advanced);
    advBox.add(Box.createGlue());
    // middle row
    Box colBox = Box.createHorizontalBox();
    colBox.add(m_hasColHeaders);
    colBox.add(Box.createGlue());
    Box wsBox = Box.createHorizontalBox();
    wsBox.add(m_ignoreWS);
    wsBox.add(Box.createGlue());
    // bottom row
    Box pValBox = Box.createHorizontalBox();
    // placeholder
    pValBox.add(new JLabel(""));
    pValBox.add(Box.createGlue());
    Box cCmtBox = Box.createHorizontalBox();
    cCmtBox.add(m_cStyleComment);
    cCmtBox.add(Box.createGlue());
    Box slcBox = Box.createHorizontalBox();
    slcBox.add(commentLabel);
    slcBox.add(Box.createHorizontalStrut(3));
    slcBox.add(m_singleLineComment);
    slcBox.add(Box.createGlue());
    // now fill the grid: first row
    panel.add(rowBox);
    panel.add(delimBox);
    panel.add(advBox);
    // second row
    panel.add(colBox);
    panel.add(wsBox);
    panel.add(new JLabel(""));
    // third row
    panel.add(pValBox);
    panel.add(cCmtBox);
    panel.add(slcBox);
    int componentsHeight = (2 * COMP_HEIGHT) + 30 + buttonHeight;
    panel.setMaximumSize(new Dimension(PANEL_WIDTH, componentsHeight));
    advanced.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            advancedSettings();
        }
    });
    m_hasRowHeaders.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            rowHeadersSettingsChanged();
        }
    });
    m_hasColHeaders.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            colHeadersSettingsChanged();
        }
    });
    m_cStyleComment.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            commentSettingsChanged();
        }
    });
    m_delimField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            delimSettingsChanged();
        }
    });
    m_ignoreWS.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            ignoreWSChanged();
        }
    });
    m_singleLineComment.getDocument().addDocumentListener(new DocumentListener() {

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

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

        @Override
        public void removeUpdate(final DocumentEvent e) {
            commentSettingsChanged();
        }
    });
    // add a panel for the errors:
    m_errorLabel = new JLabel("");
    m_errorLabel.setForeground(Color.red);
    m_errorDetail = new JLabel("");
    m_errorDetail.setForeground(Color.red);
    JPanel errorBox = new JPanel();
    errorBox.setLayout(new BoxLayout(errorBox, BoxLayout.X_AXIS));
    errorBox.add(Box.createHorizontalGlue());
    errorBox.add(m_errorLabel);
    // reserve a certain height for the (in the beginning invisible) label
    errorBox.add(Box.createVerticalStrut(17));
    errorBox.add(Box.createHorizontalGlue());
    JPanel detailBox = new JPanel();
    detailBox.setLayout(new BoxLayout(detailBox, BoxLayout.X_AXIS));
    detailBox.add(Box.createHorizontalGlue());
    detailBox.add(m_errorDetail);
    // reserve a certain height for the (in the beginning invisible) label
    detailBox.add(Box.createVerticalStrut(17));
    detailBox.add(Box.createHorizontalGlue());
    JPanel result = new JPanel();
    result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS));
    result.add(panel);
    result.add(errorBox);
    result.add(detailBox);
    return result;
}
Also used : JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) Delimiter(org.knime.core.util.tokenizer.Delimiter) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener)

Example 72 with DocumentListener

use of javax.swing.event.DocumentListener in project knime-core by knime.

the class DialogComponentAuthentication method updateNoListener.

private static void updateNoListener(final JTextField txtField, final String text) {
    final AbstractDocument doc = (AbstractDocument) txtField.getDocument();
    DocumentListener[] listeners = doc.getDocumentListeners();
    for (DocumentListener listener : listeners) {
        doc.removeDocumentListener(listener);
    }
    txtField.setText(text);
    for (DocumentListener listener : listeners) {
        doc.addDocumentListener(listener);
    }
}
Also used : AbstractDocument(javax.swing.text.AbstractDocument) DocumentListener(javax.swing.event.DocumentListener)

Example 73 with DocumentListener

use of javax.swing.event.DocumentListener in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.

private Composite createJSONEditorComposite(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    if (isWindows()) {
        Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
        gridLayout.horizontalSpacing = 0;
        embedComposite.setLayout(gridLayout);
        embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Frame frame = SWT_AWT.new_Frame(embedComposite);
        Panel heavyWeightPanel = new Panel();
        heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
        frame.add(heavyWeightPanel);
        frame.setFocusTraversalKeysEnabled(false);
        // Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
        // This reduces flicker on resize in RSyntaxTextArea
        JApplet applet = new JApplet();
        JRootPane root = applet.getRootPane();
        Container contentPane = root.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        heavyWeightPanel.add(applet);
        m_textArea = new RSyntaxTextArea(10, 60);
        m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        m_textArea.setCodeFoldingEnabled(true);
        m_textArea.setAntiAliasingEnabled(true);
        RTextScrollPane sp = new RTextScrollPane(m_textArea);
        sp.setDoubleBuffered(true);
        m_textArea.setText(m_jsonDocument);
        m_textArea.setEditable(true);
        m_textArea.setEnabled(true);
        contentPane.add(sp);
        Dimension size = sp.getPreferredSize();
        embedComposite.setSize(size.width, size.height);
        // forward focus to RSyntaxTextArea
        embedComposite.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent e) {
                ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                    @Override
                    public void run() {
                        m_textArea.requestFocus();
                        m_textArea.setCaretPosition(m_caretPosition);
                    }
                });
            }

            @Override
            public void focusLost(final FocusEvent e) {
            // do nothing
            }
        });
        // delete content of status line, when something is inserted or deleted
        m_textArea.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(final DocumentEvent arg0) {
                if (!composite.isDisposed()) {
                    composite.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (m_statusLine != null && !m_statusLine.isDisposed()) {
                                m_statusLine.setText("");
                                updateModelFromJson();
                            }
                        }
                    });
                }
            }

            @Override
            public void insertUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }

            @Override
            public void removeUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }
        });
        // remember caret position
        m_textArea.addCaretListener(new CaretListener() {

            @Override
            public void caretUpdate(final CaretEvent arg0) {
                m_caretPosition = arg0.getDot();
            }
        });
    } else {
        m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        layoutData.widthHint = 600;
        layoutData.heightHint = 400;
        m_text.setLayoutData(layoutData);
        m_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                m_jsonDocument = m_text.getText();
                if (m_statusLine != null && !m_statusLine.isDisposed()) {
                    m_statusLine.setText("");
                    updateModelFromJson();
                }
            }
        });
        m_text.setText(m_jsonDocument);
    }
    // add status line
    m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
    GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
    int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
    statusGridData.heightHint = maxHeight + 5;
    // seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
    statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
    m_statusLine.setLayoutData(statusGridData);
    compareNodeIDs();
    return composite;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) DocumentListener(javax.swing.event.DocumentListener) Frame(java.awt.Frame) ModifyListener(org.eclipse.swt.events.ModifyListener) BoxLayout(javax.swing.BoxLayout) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) JApplet(javax.swing.JApplet) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Container(java.awt.Container) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) Point(org.eclipse.swt.graphics.Point) Panel(java.awt.Panel) CaretListener(javax.swing.event.CaretListener) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) JRootPane(javax.swing.JRootPane) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Aggregations

DocumentListener (javax.swing.event.DocumentListener)73 DocumentEvent (javax.swing.event.DocumentEvent)70 JTextField (javax.swing.JTextField)24 ActionEvent (java.awt.event.ActionEvent)21 ActionListener (java.awt.event.ActionListener)19 JLabel (javax.swing.JLabel)19 JPanel (javax.swing.JPanel)18 Dimension (java.awt.Dimension)16 JButton (javax.swing.JButton)13 JCheckBox (javax.swing.JCheckBox)13 GridBagLayout (java.awt.GridBagLayout)9 ChangeEvent (javax.swing.event.ChangeEvent)9 GridBagConstraints (java.awt.GridBagConstraints)8 Box (javax.swing.Box)8 ChangeListener (javax.swing.event.ChangeListener)8 BoxLayout (javax.swing.BoxLayout)7 ZapTextField (org.zaproxy.zap.utils.ZapTextField)7 BorderLayout (java.awt.BorderLayout)6 Insets (java.awt.Insets)6 FocusEvent (java.awt.event.FocusEvent)6