Java Code Examples for javax.swing.event.CaretListener

The following examples show how to use javax.swing.event.CaretListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: WikiEditPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form WikiEditPanel
 */
public WikiEditPanel(String wikiLanguage, boolean editing, boolean switchable) {
    this.wikiLanguage = wikiLanguage;
    this.switchable = switchable;
    this.wikiFormatText = "";
    this.htmlFormatText = "";
    initComponents();
    pnlButtons.setVisible(switchable);
    textCode.getDocument().addDocumentListener(new RevalidatingListener());
    textPreview.getDocument().addDocumentListener(new RevalidatingListener());
    textCode.addCaretListener(new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent e) {
            makeCaretVisible(textCode);
        }
    });
    textCode.getDocument().addDocumentListener(new EnablingListener());
    // A11Y - Issues 163597 and 163598
    UIUtils.fixFocusTraversalKeys(textCode);
    UIUtils.issue163946Hack(scrollCode);

    Spellchecker.register(textCode);
    textPreview.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    setEditing(editing);
}
 
Example 2
Source Project: netbeans   Source File: NavigatorContent.java    License: Apache License 2.0 6 votes vote down vote up
private void updateActiveEditor() {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(this);
        return;
    }
    JTextComponent c = findActivePane();
    if (c == null) {
        editorReleased();
        return;
    }
    if (activeEditor != null && activeEditor.get() == c) {
        return;
    }
    editorReleased();
    activeEditor = new WeakReference<>(c);
    wCaretL = WeakListeners.create(CaretListener.class, this, c);
    c.addCaretListener(this);
    selectCurrentNode();
}
 
Example 3
public TableViewLayoutTest() {

        super("Code example for a TableView bug");
        setUndecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        edit.setEditorKit(new CodeBugEditorKit());
        initCodeBug();
        this.getContentPane().add(new JScrollPane(edit));
        this.pack();
        this.setLocationRelativeTo(null);

        edit.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                JTextComponent textComp = (JTextComponent) e.getSource();
                try {
                    Rectangle rect = textComp.getUI().modelToView(textComp, e.getDot());
                    yCaret = rect.getY();
                    xCaret = rect.getX();
                } catch (BadLocationException ex) {
                    throw new RuntimeException("Failed to get pixel position of caret", ex);
                }
            }
        });
    }
 
Example 4
Source Project: bigtable-sql   Source File: RowColumnLabel.java    License: Apache License 2.0 6 votes vote down vote up
RowColumnLabel(ISQLEntryPanel sqlEntryPanel)
{
	super(" ", JLabel.CENTER);

	_sqlEntryPanel = sqlEntryPanel;

	sqlEntryPanel.addCaretListener(new CaretListener()
	{
		public void caretUpdate(CaretEvent e)
		{
			onCaretUpdate(e);
		}

	});

	writePosition(0,0, 0);

     setToolTipText(s_stringMgr.getString("RowColumnLabel.tooltip"));
}
 
Example 5
public SlotConstTraitDetailPanel(final DecompiledEditorPane editor) {
    slotConstEditor = new LineMarkedEditorPane();
    setLayout(new BorderLayout());
    add(new JScrollPane(slotConstEditor), BorderLayout.CENTER);
    slotConstEditor.setFont(Configuration.getSourceFont());
    slotConstEditor.changeContentType("text/flasm3");
    slotConstEditor.addCaretListener(new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent e) {
            if (ignoreCaret) {
                return;
            }
            Highlighting spec = Highlighting.searchPos(specialHilights, slotConstEditor.getCaretPosition());
            if (spec != null) {
                editor.hilightSpecial(spec.getProperties().subtype, (int) spec.getProperties().index);
                slotConstEditor.getCaret().setVisible(true);
            }
        }
    });
}
 
Example 6
Source Project: FancyBing   Source File: Comment.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Comment(Listener listener)
{
    m_listener = listener;
    m_textPane = new JTextPane();
    setFocusTraversalKeys(m_textPane);
    GuiUtil.addStyle(m_textPane, "marked", Color.white,
                     Color.decode("#38d878"), false);
    setPreferredSize();
    m_textPane.getDocument().addDocumentListener(this);
    CaretListener caretListener = new CaretListener()
        {
            public void caretUpdate(CaretEvent event)
            {
                if (m_listener == null)
                    return;
                m_listener.textSelected(m_textPane.getSelectedText());
            }
        };
    m_textPane.addCaretListener(caretListener);
    setViewportView(m_textPane);
    setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    if (Platform.isMac())
        m_normalFont = new Font("Lucida Grande", Font.PLAIN, 11);
    else
        m_normalFont = UIManager.getFont("TextPane.font");
    setMonoFont(false);
}
 
Example 7
Source Project: netbeans   Source File: SearchBar.java    License: Apache License 2.0 5 votes vote down vote up
private CaretListener createCaretListenerForComponent() {
    return new CaretListener() {

        @Override
        public void caretUpdate(CaretEvent e) {
            if (SearchBar.getInstance().isVisible()) {
                int num = SearchBar.getInstance().getNumOfMatches();
                SearchBar.getInstance().showNumberOfMatches(null, num);
            }
        }
    };
}
 
Example 8
Source Project: netbeans   Source File: TaskPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form TaskPanel
 */
public TaskPanel (LocalTask task) {
    this.task = task;
    initComponents();
    updateReadOnlyField(headerField);
    Font font = new JLabel().getFont();
    headerField.setFont(font.deriveFont((float) (font.getSize() * 1.7)));

    mainScrollPane.getVerticalScrollBar().setUnitIncrement(10);
    
    privateNotesField.addCaretListener(new CaretListener() {
        @Override
        public void caretUpdate (CaretEvent e) {
            makeCaretVisible(privateNotesField);
        }
    });
    // A11Y - Issues 163597 and 163598
    UIUtils.fixFocusTraversalKeys(privateNotesField);
    initSpellChecker();

    attachmentsPanel = new AttachmentsPanel(this);
    attachmentsSection.setContent(attachmentsPanel);
    
    GroupLayout layout = (GroupLayout) attributesPanel.getLayout();
    dueDatePicker = UIUtils.createDatePickerComponent();
    scheduleDatePicker = new SchedulePicker();
    layout.replace(dummyDueDateField, dueDatePicker.getComponent());
    dueDateLabel.setLabelFor(dueDatePicker.getComponent());
    layout.replace(dummyScheduleDateField, scheduleDatePicker.getComponent());
    scheduleDateLabel.setLabelFor(scheduleDatePicker.getComponent());
    attachListeners();
}
 
Example 9
/**
 * Maps {@code JTextComponent.addCaretListener(CaretListener)} through queue
 */
public void addCaretListener(final CaretListener caretListener) {
    runMapping(new MapVoidAction("addCaretListener") {
        @Override
        public void map() {
            ((JTextComponent) getSource()).addCaretListener(caretListener);
        }
    });
}
 
Example 10
/**
 * Maps {@code JTextComponent.removeCaretListener(CaretListener)}
 * through queue
 */
public void removeCaretListener(final CaretListener caretListener) {
    runMapping(new MapVoidAction("removeCaretListener") {
        @Override
        public void map() {
            ((JTextComponent) getSource()).removeCaretListener(caretListener);
        }
    });
}
 
Example 11
Source Project: lippen-network-tool   Source File: IPV4Field.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addCaretListener(CaretListener listener) {
    if (this.ipFields != null) {
        for (JIPV4Field field : this.ipFields) {
            field.addCaretListener(listener);
        }
    }
}
 
Example 12
Source Project: lippen-network-tool   Source File: IPV4Field.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void removeCaretListener(CaretListener listener) {
    if (this.ipFields != null) {
        for (JIPV4Field field : this.ipFields) {
            field.removeCaretListener(listener);
        }
    }
}
 
Example 13
protected void fireCaretEvent() {
	Object[] listeners = listenerList.getListenerList();
	for (int i = listeners.length - 2; i >= 0; i--) {
		if (listeners[i] == CaretListener.class) {
			((CaretListener) listeners[i + 1]).caretUpdate(caretEvent);
		}
	}
}
 
Example 14
Source Project: groovy   Source File: ConsoleTextEditor.java    License: Apache License 2.0 5 votes vote down vote up
private void disableMatchingHighlighter() {
    for (CaretListener cl : textEditor.getCaretListeners()) {
        if (cl instanceof MatchingHighlighter) {
            textEditor.removeCaretListener(cl);
        }
    }
}
 
Example 15
@Override
public void validateValue() {

    Amf3Importer importer = new Amf3Importer();
    String textVal = editor.getText();
    try {
        if (!textVal.trim().isEmpty()) {
            importer.stringToAmf(textVal);
        }
    } catch (IOException | Amf3ParseException ex) {

        if (ex instanceof Amf3ParseException) {
            Amf3ParseException ape = (Amf3ParseException) ex;
            if (ape.line > 0) {
                editor.gotoLine((int) ape.line);
            }
        }
        final CaretListener cl = new CaretListener() {
            @Override
            public void caretUpdate(CaretEvent e) {
                errorLabel.setVisible(false);
                editor.removeCaretListener(this);
            }
        };
        editor.addCaretListener(cl);
        errorLabel.setText("<html>" + AppStrings.translate("error") + ":" + ex.getMessage() + "</html>");
        errorLabel.setVisible(true);
        throw new IllegalArgumentException("Invalid AMF value", ex);
    }
}
 
Example 16
Source Project: FancyBing   Source File: GtpShell.java    License: GNU General Public License v3.0 4 votes vote down vote up
public GtpShell(Frame owner, Listener listener,
                MessageDialogs messageDialogs)
{
    super(owner, i18n("TIT_SHELL"));
    m_messageDialogs = messageDialogs;
    m_listener = listener;
    Preferences prefs = Preferences.userNodeForPackage(getClass());
    m_historyMin = prefs.getInt("history-min", 2000);
    m_historyMax = prefs.getInt("history-max", 3000);
    JPanel panel = new JPanel(new BorderLayout());
    getContentPane().add(panel, BorderLayout.CENTER);
    m_gtpShellText = new GtpShellText(m_historyMin, m_historyMax, false);
    CaretListener caretListener = new CaretListener()
        {
            public void caretUpdate(CaretEvent event)
            {
                if (m_listener == null)
                    return;
                // Call the callback only if the selected text has changed.
                // This avoids that the callback is called multiple times
                // if the caret position changes, but the text selection
                // was null before and after the change (see also bug
                // #2964755)
                String selectedText = m_gtpShellText.getSelectedText();
                if (! ObjectUtil.equals(selectedText, m_selectedText))
                {
                    m_listener.textSelected(selectedText);
                    m_selectedText = selectedText;
                }
            }
        };
    m_gtpShellText.addCaretListener(caretListener);
    m_scrollPane =
        new JScrollPane(m_gtpShellText,
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    if (Platform.isMac())
        // Default Apple L&F uses no border, but Quaqua 3.7.4 does
        m_scrollPane.setBorder(null);
    panel.add(m_scrollPane, BorderLayout.CENTER);
    panel.add(createCommandInput(), BorderLayout.SOUTH);
    setMinimumSize(new Dimension(160, 112));
    pack();
}
 
Example 17
Source Project: pumpernickel   Source File: EditMenuControls.java    License: MIT License 4 votes vote down vote up
private void registerAction(EditCommand<AbstractAction> command,
		final Selection selection, final boolean requiresEdits) {
	final AbstractAction action = new EditMenuAction(
			(String) command.getValue(AbstractAction.ACTION_COMMAND_KEY));
	PropertyChangeListener pcl = new PropertyChangeListener() {

		JTextComponent textComponent;
		CaretListener caretListener = new CaretListener() {

			@Override
			public void caretUpdate(CaretEvent e) {
				refresh();
			}

		};

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			Component c = KeyboardFocusManager
					.getCurrentKeyboardFocusManager().getFocusOwner();

			if (c == textComponent)
				return;

			JTextComponent jtc = c instanceof JTextComponent ? ((JTextComponent) c)
					: null;

			if (textComponent != null)
				textComponent.removeCaretListener(caretListener);

			textComponent = jtc;

			if (textComponent != null)
				textComponent.addCaretListener(caretListener);

			refresh();
		}

		private void refresh() {
			if (textComponent == null) {
				action.setEnabled(false);
			} else if (!textComponent.isEditable() && requiresEdits) {
				action.setEnabled(false);
			} else if (selection == null) {
				action.setEnabled(true);
			} else {
				action.setEnabled(selection.accepts(textComponent));
			}
		}

	};
	KeyboardFocusManager.getCurrentKeyboardFocusManager()
			.addPropertyChangeListener("focusOwner", pcl);
	command.install(action);
	registerAction(action);
}
 
Example 18
Source Project: bigtable-sql   Source File: DefaultSQLEntryPanel.java    License: Apache License 2.0 4 votes vote down vote up
public void addCaretListener(CaretListener lis)
{
	_comp.addCaretListener(lis);
}
 
Example 19
Source Project: bigtable-sql   Source File: DefaultSQLEntryPanel.java    License: Apache License 2.0 4 votes vote down vote up
public void removeCaretListener(CaretListener lis)
{
	_comp.removeCaretListener(lis);
}
 
Example 20
/**
 * Adds a caret change listener to this text area.
 * 
 * @param listener
 *            The listener
 */
public final void addCaretListener(CaretListener listener) {
	listenerList.add(CaretListener.class, listener);
}
 
Example 21
/**
 * Removes a caret change listener from this text area.
 * 
 * @param listener
 *            The listener
 */
public final void removeCaretListener(CaretListener listener) {
	listenerList.remove(CaretListener.class, listener);
}
 
Example 22
Source Project: bigtable-sql   Source File: ISQLEntryPanel.java    License: Apache License 2.0 votes vote down vote up
void addCaretListener(CaretListener lis); 
Example 23
Source Project: bigtable-sql   Source File: ISQLEntryPanel.java    License: Apache License 2.0 votes vote down vote up
void removeCaretListener(CaretListener lis);