Java Code Examples for javax.swing.event.CaretEvent#getSource()

The following examples show how to use javax.swing.event.CaretEvent#getSource() . 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 File: GUIController.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
	int cursor = e.getDot();
	JTextPane textPane = (JTextPane)e.getSource();
	TokenPositionAnalysis analysis = getAnalysisForCharIndex(cursor);
	Highlighter highlighter = textPane.getHighlighter();
	HighlightPainter painter = new DefaultHighlightPainter(Color.orange);
	try {
		highlighter.removeAllHighlights();
		if ( analysis!=null ) {
			highlighter.addHighlight(analysis.charIndexStart, analysis.charIndexStop+1, painter);
		}
		scope.injectNLConsole.setText(analysis!=null ? analysis.wsAnalysis : "");
		scope.injectNLConsole.setCaretPosition(0);
		scope.alignConsole.setText(analysis!=null ? analysis.alignAnalysis : "");
		scope.alignConsole.setCaretPosition(0);
	}
	catch (Exception ex) {
		ex.printStackTrace(System.err);
	}
}
 
Example 2
Source File: EditorCurrentLineHighlighter.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent evt) {
  JTextComponent comp = (JTextComponent) evt.getSource();
  if (comp != null) {
    if (comp.getSelectionStart() != comp.getSelectionEnd()) {
      // cancel line highlighting if selection exists
      removeLineHighlight(comp);
      comp.repaint();
      return;
    }
    int pos = comp.getCaretPosition();
    Element elem = Utilities.getParagraphElement(comp, pos);
    int start = elem.getStartOffset();
    int end = elem.getEndOffset();
    Document doc = comp.getDocument();
    Element root = doc.getDefaultRootElement();
    int line = root.getElementIndex(pos);
    Debug.log(5, "LineHighlight: Caret at " + pos + " line " + line + " for " + start + "-" + end);
    if (SikulixIDE.getStatusbar() != null) {
      SikulixIDE.getStatusbar().setCaretPosition(line + 1, pos - start + 1);
    }
    removeLineHighlight(comp);
    try {
      highlight = comp.getHighlighter().addHighlight(start, end, painter);
      comp.repaint();
    } catch (BadLocationException ex) {
      Debug.error(me + "Problem while highlighting line %d\n%s", pos, ex.getMessage());
    }
  }
}
 
Example 3
Source File: POMModelPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void caretUpdate(CaretEvent e) {
    JTextComponent cc = currentComponent != null ? currentComponent.get() : null;
    if (e.getSource() != cc) {
        ((JTextComponent)e.getSource()).removeCaretListener(this);
        //just a double check we do't get a persistent leak here..
        return;
    }
    currentDot = e.getDot();
    caretTask.schedule(1000);
}
 
Example 4
Source File: ToolsInternalFrame.java    From chipster with MIT License 5 votes vote down vote up
public void caretUpdate(CaretEvent e) {
	Object source = e.getSource();
	
	// Custom delimeter field
	if (source == customDelimField) {
		if (customDelimRadioButton.isSelected()) {
			String customDelim = customDelimField.getText();
			if (customDelim != null && customDelim.length() > 0) {
				this.setDelim(customDelim);
			} else {
				customDelimField.setForeground(Color.BLACK);
			}	
		}
	}
}