// Installs CurrentLineHilighter for the given JTextComponent
 public static void install(JTextComponent c) {
   try {
     Object obj = c.getHighlighter().addHighlight(0, 0, painter);
     c.putClientProperty(LINE_HIGHLIGHT, obj);
     c.addCaretListener(caretListener);
     c.addMouseListener(mouseListener);
   } catch (BadLocationException ex) {
   }
 }
 public MarkOccurrencesHighlighter(Document doc) {
   rp = new RequestProcessor(MarkOccurrencesHighlighter.class);
   bag = new OffsetsBag(doc);
   weakDoc = new WeakReference<Document>((Document) doc);
   DataObject dobj = NbEditorUtilities.getDataObject(weakDoc.get());
   if (dobj != null) {
     EditorCookie pane = dobj.getLookup().lookup(EditorCookie.class);
     JEditorPane[] panes = pane.getOpenedPanes();
     if (panes != null && panes.length > 0) {
       comp = panes[0];
       comp.addCaretListener(this);
     }
   }
 }
Example #3
0
  /**
   * Create a line number component for a text component.
   *
   * @param argComponent the related text component
   * @param argMinimumDisplayDigits the number of digits used to calculate the minimum width of the
   *     component.
   */
  public TextLineNumber(JTextComponent argComponent, int argMinimumDisplayDigits) {
    component = argComponent;

    setFont(argComponent.getFont());

    setBorderGap(5);
    setCurrentLineForeground(Color.RED);
    setDigitAlignment(RIGHT);
    setMinimumDisplayDigits(argMinimumDisplayDigits);

    argComponent.getDocument().addDocumentListener(this);
    argComponent.addCaretListener(this);
    argComponent.addPropertyChangeListener("font", this);
  }