Search in sources :

Example 1 with CaretEvent

use of javax.swing.event.CaretEvent in project ORFpred by JonathanFeenstra.

the class ORFHighlighter method addClickListener.

/**
 * Voegt CaretListener toe aan JTextPane die het BLAST dialoogvenster opent
 * bij het klikken op een gemarkeerd ORF.
 *
 * @param seqTextPane de te beluisteren JTextPane
 */
public void addClickListener(JTextPane seqTextPane) {
    for (CaretListener clickListener : seqTextPane.getCaretListeners()) {
        seqTextPane.removeCaretListener(clickListener);
    }
    seqTextPane.addCaretListener((CaretEvent e) -> {
        try {
            if (isHighlighted[e.getDot()]) {
                EventQueue.invokeLater(() -> {
                    if (positionToORF.containsKey(e.getDot())) {
                        targetGUI.showORFPopUp(positionToORF.get(e.getDot()));
                    }
                });
            }
        } catch (Exception ex) {
        // Negeer: er wordt buiten de tekst geklikt
        }
    });
    addHoverListener(seqTextPane);
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) BadLocationException(javax.swing.text.BadLocationException) CompoundNotFoundException(org.biojava.nbio.core.exceptions.CompoundNotFoundException)

Example 2 with CaretEvent

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

the class SetupLoggingAction method buildSetupLoggingComponent.

/**
 * The component used to config logging.
 */
private static JComponent 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);
        }
    });
    // JCheckBox automatic = new JCheckBox("Automatically display log output.");
    // Boolean b = TetradLogger.getInstance().isAutomaticLogDisplayEnabled();
    // automatic.setSelected(b != null && b);
    // automatic.setHorizontalTextPosition(AbstractButton.LEFT);
    // automatic.addActionListener(new ActionListener(){
    // public void actionPerformed(ActionEvent e) {
    // JCheckBox box = (JCheckBox)e.getSource();
    // TetradLogger.getInstance().setAutomaticLogDisplayEnabled(box.isSelected());
    // }
    // });
    // Box automaticBox = Box.createHorizontalBox();
    // automaticBox.add(automatic);
    // automaticBox.add(Box.createHorizontalGlue());
    // Do Layout.
    Box b1 = Box.createVerticalBox();
    // Box b2 = Box.createHorizontalBox();
    // b2.add(new JLabel("Activate Logging: "));
    // b2.add(Box.createHorizontalStrut(5));
    // b2.add(activateCombo);
    // b2.add(Box.createHorizontalGlue());
    // 
    // b1.add(b2);
    // b1.add(Box.createVerticalStrut(5));
    b1.add(createLogToBox());
    b1.add(Box.createVerticalStrut(5));
    // b1.add(automaticBox);
    // b1.add(Box.createVerticalStrut(10));
    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, with one output file<br>" + "generated per search." + "</html>"));
    b1.add(b8);
    return b1;
}
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)

Example 3 with CaretEvent

use of javax.swing.event.CaretEvent in project gate-core by GateNLP.

the class SearchExpressionsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent arg0) {
    String[] values1 = { "Number", "Person" };
    String[] values2 = { "Any character", "The beginning of a line", "The end of a line", "All letters", "Letter uppercase", "Letter lowercase", "Letter titlecase", "Letter modifier", "Letter other", "All Numbers", "Number decimal digit", "Number letter", "Number other", "All punctuations", "Punctuation connector", "Punctuation dash", "Punctuation open", "Punctuation close", "Punctuation initial quote", "Punctuation final quote", "Punctuation other", "All symbols", "Symbol math", "Symbol currency", "Symbol modifier", "Symbol other", "All separators", "Separator space", "Separator line", "Separator paragraph", "All Marks", "Mark nonspacing", "Mark spacing combining", "Mark enclosing", "All others", "Other control", "Other format", "Other surrogate", "Other private use", "Other not assigned", "Any character except Category", "Category1 and/or Category2", "Category1 and Category2" };
    String[] values3 = { "Either the selection or X", "Once or not at all", "Zero or more times", "One or more times", "Capturing group", "Non-capturing group" };
    final JTextField modifiedTextField = new JTextField(25);
    modifiedTextField.setText(sourceTextField.getText());
    JPanel vspace1 = new JPanel();
    vspace1.setSize(0, 5);
    final JList<String> list1 = new JList<String>(values1);
    list1.setVisibleRowCount(Math.min(10, values1.length));
    list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp1 = new JScrollPane(list1);
    final JButton b1 = new JButton("Replace search expression");
    b1.setEnabled(false);
    JPanel vspace2 = new JPanel();
    vspace2.setSize(0, 5);
    final JList<String> list2 = new JList<String>(values2);
    list2.setVisibleRowCount(Math.min(10, values2.length));
    list2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp2 = new JScrollPane(list2);
    final JButton b2 = new JButton("Insert at the caret position");
    b2.setEnabled(false);
    JPanel vspace3 = new JPanel();
    vspace3.setSize(0, 5);
    final JList<String> list3 = new JList<String>(values3);
    list3.setVisibleRowCount(Math.min(10, values3.length));
    list3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane jsp3 = new JScrollPane(list3);
    final JButton b3 = new JButton("Modify the selection");
    b3.setEnabled(false);
    modifiedTextField.addCaretListener(new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent e) {
            list3.setEnabled(modifiedTextField.getSelectedText() != null);
        }
    });
    Object[] messageObjects = { "Current search expression:", modifiedTextField, vspace1, jsp1, b1, vspace2, jsp2, b2, vspace3, jsp3, b3 };
    String[] options = { "OK", "Cancel" };
    final JOptionPane optionPane = new JOptionPane(messageObjects, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, "Cancel");
    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list1.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list1.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                modifySearchExpression(list1.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list1.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list1.getSelectedValue() != null) {
                b1.setEnabled(true);
            } else {
                b1.setEnabled(false);
            }
        }
    });
    b2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list2.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list2.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                modifySearchExpression(list2.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list2.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list2.getSelectedValue() != null) {
                b2.setEnabled(true);
            } else {
                b2.setEnabled(false);
            }
        }
    });
    b3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifySearchExpression(list3.getSelectedValue().toString(), modifiedTextField);
        }
    });
    list3.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2 && list3.isEnabled()) {
                modifySearchExpression(list3.getSelectedValue().toString(), modifiedTextField);
            }
        }
    });
    list3.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (list3.getSelectedValue() != null) {
                b3.setEnabled(true);
            } else {
                b3.setEnabled(false);
            }
        }
    });
    annotationEditorWindow.setVisible(false);
    JDialog optionDialog = optionPane.createDialog(gate.gui.MainFrame.getInstance(), "GATE search expression builder");
    modifiedTextField.setCaretPosition(sourceTextField.getSelectionStart() == sourceTextField.getCaretPosition() ? sourceTextField.getSelectionEnd() : sourceTextField.getSelectionStart());
    modifiedTextField.moveCaretPosition(sourceTextField.getCaretPosition());
    modifiedTextField.requestFocus();
    optionDialog.setVisible(true);
    Object selectedValue = optionPane.getValue();
    if (selectedValue != null && selectedValue.equals("OK")) {
        if (searchRegExpChk != null) {
            searchRegExpChk.setSelected(true);
        }
        sourceTextField.setText(modifiedTextField.getText());
    }
    annotationEditorWindow.setVisible(true);
}
Also used : CaretEvent(javax.swing.event.CaretEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener)

Example 4 with CaretEvent

use of javax.swing.event.CaretEvent in project yyl_example by Relucent.

the class Command method registerListener.

private void registerListener() {
    txtDebug.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
                e.setKeyCode(27);
            }
            if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
                try {
                    String str = doc.getText(execOffset, doc.getLength() - execOffset);
                    exec(str + "\n");
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

        public void keyTyped(KeyEvent e) {
        // System.out.println(e.getKeyChar());
        }
    });
    doc.addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
        }

        public void removeUpdate(DocumentEvent e) {
        }
    });
    txtDebug.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
                caret.setDot(execOffset);
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) CaretEvent(javax.swing.event.CaretEvent) DocumentListener(javax.swing.event.DocumentListener) CaretListener(javax.swing.event.CaretListener) KeyAdapter(java.awt.event.KeyAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 5 with CaretEvent

use of javax.swing.event.CaretEvent in project jadx by skylot.

the class AbstractCodeArea method addCaretActions.

private void addCaretActions() {
    Caret caret = getCaret();
    if (caret instanceof DefaultCaret) {
        ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    }
    this.addFocusListener(new FocusListener() {

        // fix caret missing bug.
        // when lost focus set visible to false,
        // and when regained set back to true will force
        // the caret to be repainted.
        @Override
        public void focusGained(FocusEvent e) {
            caret.setVisible(true);
        }

        @Override
        public void focusLost(FocusEvent e) {
            caret.setVisible(false);
        }
    });
    addCaretListener(new CaretListener() {

        int lastPos = -1;

        String lastText = "";

        @Override
        public void caretUpdate(CaretEvent e) {
            int pos = getCaretPosition();
            if (lastPos != pos) {
                lastPos = pos;
                lastText = highlightCaretWord(lastText, pos);
            }
        }
    });
}
Also used : CaretEvent(javax.swing.event.CaretEvent) CaretListener(javax.swing.event.CaretListener) DefaultCaret(javax.swing.text.DefaultCaret) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret) Point(java.awt.Point)

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