Search in sources :

Example 6 with CaretListener

use of javax.swing.event.CaretListener in project intellij-community by JetBrains.

the class HgInitDialog method init.

@Override
protected void init() {
    super.init();
    setTitle(HgVcsMessages.message("hg4idea.init.dialog.title"));
    if (myProject != null && (!myProject.isDefault())) {
        mySelectedDir = myProject.getBaseDir();
    }
    mySelectWhereToCreateRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            myTextFieldBrowser.setEnabled(true);
            updateEverything();
        }
    });
    myCreateRepositoryForTheRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            myTextFieldBrowser.setEnabled(false);
            updateEverything();
        }
    });
    myTextFieldBrowser.getTextField().addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            updateEverything();
        }
    });
    myTextFieldBrowser.addBrowseFolderListener(HgVcsMessages.message("hg4idea.init.destination.directory.title"), HgVcsMessages.message("hg4idea.init.destination.directory.description"), myProject, myFileDescriptor);
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 7 with CaretListener

use of javax.swing.event.CaretListener in project intellij-community by JetBrains.

the class AbstractCreateVirtualEnvDialog method registerValidators.

protected void registerValidators(final FacetValidatorsManager validatorsManager) {
    myDestination.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            validatorsManager.validate();
        }
    });
    myDestination.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            validatorsManager.validate();
        }
    });
    myName.addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent event) {
            validatorsManager.validate();
        }
    });
    myDestination.getTextField().addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent event) {
            validatorsManager.validate();
        }
    });
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 8 with CaretListener

use of javax.swing.event.CaretListener 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)

Example 9 with CaretListener

use of javax.swing.event.CaretListener in project boosters-lab by taedixon.

the class TscPane method initActions.

private void initActions(ResourceManager iMan) {
    if (defPanel == null) {
        defPanel = createDefinePanel();
    }
    if (commandPanel == null) {
        commandPanel = createCommandPanel(iMan);
    }
    this.addKeyListener(new java.awt.event.KeyAdapter() {

        public void keyReleased(java.awt.event.KeyEvent evt) {
            textBoxKeyReleased(evt);
        }
    });
    lastFocus = this;
    this.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
            lastFocus = TscPane.this;
        }

        @Override
        public void focusLost(FocusEvent arg0) {
        // nothing
        }
    });
    this.addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent eve) {
            if (commandList.isVisible()) {
                JTextPane area = (JTextPane) eve.getSource();
                int cPos = eve.getDot();
                // weed out carriage return characters
                String txt = area.getText();
                if (txt == null) {
                    return;
                }
                // $NON-NLS-1$ //$NON-NLS-2$
                txt = txt.replace("\r", "");
                String searchTxt = txt.substring(0, cPos);
                int tagPos = searchTxt.lastIndexOf('<');
                if (tagPos < 0) {
                    return;
                }
                if ((txt.length() - tagPos >= 4)) {
                    String tag = txt.substring(tagPos, tagPos + 4);
                    int index = commandList.getNextMatch(tag, 0, Position.Bias.Forward);
                    commandList.setSelectedIndex(index);
                    setCommandExtras(index, txt.substring(tagPos, txt.length()));
                }
            }
        }
    });
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) java.awt.event(java.awt.event)

Example 10 with CaretListener

use of javax.swing.event.CaretListener in project tetrad by cmu-phil.

the class TetradLogArea method buildSetupLoggingComponent.

/**
 * The component used to config logging.
 */
public static JPanel buildSetupLoggingComponent() {
    // build yes/no combo box.
    JComboBox activateCombo = new JComboBox(new String[] { "No", "Yes" });
    activateCombo.setMaximumSize(activateCombo.getPreferredSize());
    activateCombo.setSelectedItem(TetradLogger.getInstance().isLogging() ? "Yes" : "No");
    activateCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            TetradLogger.getInstance().setLogging("Yes".equals(combo.getSelectedItem()));
        }
    });
    String saveLocation = TetradLogger.getInstance().getLoggingDirectory();
    final JTextField saveField = new JTextField(saveLocation);
    saveField.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextField field = (JTextField) e.getSource();
            try {
                TetradLogger.getInstance().setLoggingDirectory(field.getText());
            } catch (IllegalArgumentException ex) {
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), ex.getMessage());
            }
        }
    });
    JButton chooseButton = new JButton(" ... ");
    chooseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String saveLocation = TetradLogger.getInstance().getLoggingDirectory();
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setCurrentDirectory(new File(saveLocation));
            int ret = chooser.showOpenDialog(JOptionUtils.centeringComp());
            if (ret == JFileChooser.APPROVE_OPTION) {
                File selectedFile = chooser.getSelectedFile();
                Preferences.userRoot().put("loggingDirectory", selectedFile.getAbsolutePath());
                saveField.setText(selectedFile.getAbsolutePath());
            }
        }
    });
    chooseButton.setBorder(new EtchedBorder());
    JTextField prefixField = new JTextField(TetradLogger.getInstance().getLoggingFilePrefix());
    prefixField.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            JTextField field = (JTextField) e.getSource();
            String text = field.getText();
            if (!text.matches("[a-zA-Z_]*")) {
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Spaces, numbers, and special characters (" + "except underlines) in filenames will be " + "ignored. You might want to delete them.", "Friendly Detail Message", JOptionPane.WARNING_MESSAGE);
            }
            TetradLogger.getInstance().setLoggingFilePrefix(text);
        }
    });
    // Do Layout.
    Box b1 = Box.createVerticalBox();
    b1.add(createLogToBox());
    b1.add(Box.createVerticalStrut(5));
    Box b4 = Box.createHorizontalBox();
    b4.add(new JLabel("Output Directory:"));
    b4.add(Box.createHorizontalGlue());
    b1.add(b4);
    Box b5 = Box.createHorizontalBox();
    b5.add(saveField);
    b5.add(chooseButton);
    b1.add(b5);
    b1.add(Box.createVerticalStrut(5));
    Box b6 = Box.createHorizontalBox();
    b6.add(new JLabel("File Prefix:"));
    b6.add(Box.createHorizontalGlue());
    b1.add(b6);
    Box b7 = Box.createHorizontalBox();
    b7.add(prefixField);
    b1.add(b7);
    b1.add(Box.createVerticalStrut(5));
    Box b8 = Box.createHorizontalBox();
    b8.add(new JLabel("<html>" + "Output will be written to sequentially numbered files, using the<br>" + "given file prefix, in the given directory." + "</html>"));
    b1.add(b8);
    JPanel panel = new JPanel();
    panel.add(b1, BorderLayout.CENTER);
    return panel;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) ActionEvent(java.awt.event.ActionEvent) EtchedBorder(javax.swing.border.EtchedBorder) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener) File(java.io.File)

Aggregations

CaretEvent (javax.swing.event.CaretEvent)12 CaretListener (javax.swing.event.CaretListener)12 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 DocumentEvent (javax.swing.event.DocumentEvent)3 Dimension (java.awt.Dimension)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 File (java.io.File)2 JPanel (javax.swing.JPanel)2 EtchedBorder (javax.swing.border.EtchedBorder)2 DocumentListener (javax.swing.event.DocumentListener)2 BadLocationException (javax.swing.text.BadLocationException)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Frame (java.awt.Frame)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Panel (java.awt.Panel)1