Package javax.swing.text

Examples of javax.swing.text.Highlighter$HighlightPainter


   * @see #getMarkAllHighlightColor
   * @see #setMarkAllHighlightColor
   */
  public int markAll(String toMark, boolean matchCase, boolean wholeWord,
          boolean regex) {
    Highlighter h = getHighlighter();
    int numMarked = 0;
    if (toMark!=null && !toMark.equals(markedWord) && h!=null) {
      if (markAllHighlights!=null)
        clearMarkAllHighlights();
      else
        markAllHighlights = new ArrayList(10);
      int caretPos = getCaretPosition();
      markedWord = toMark;
      setCaretPosition(0);
      SearchContext context = new SearchContext();
      context.setSearchFor(toMark);
      context.setMatchCase(matchCase);
      context.setRegularExpression(regex);
      context.setSearchForward(true);
      context.setWholeWord(wholeWord);
      boolean found = SearchEngine.find(this, context);
      while (found) {
        int start = getSelectionStart();
        int end = getSelectionEnd();
        try {
          markAllHighlights.add(h.addHighlight(start, end,
                    markAllHighlightPainter));
        } catch (BadLocationException ble) {
          ble.printStackTrace();
        }
        numMarked++;
View Full Code Here


    codeEditor.setText("");
    codeEditorLines.clear();
    codeEditor.setEditable(false);

    Highlighter hl = codeEditor.getHighlighter();
    Object o = null;
    try {
      o = hl.addHighlight(0, 0, CURRENT_LINE_MARKER);
    } catch (BadLocationException e1) {
    }
    currentLineTag = o;

    o = null;
    try {
      o = hl.addHighlight(0, 0, SELECTED_LINE_MARKER);
    } catch (BadLocationException e1) {
    }
    selectedLineTag = o;

    codeEditor.getComponentPopupMenu().addPopupMenuListener(new PopupMenuListener() {
      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        /* Disable breakpoint actions */
        actionAddBreakpoint.setEnabled(false);
        actionRemoveBreakpoint.setEnabled(false);

        int line = getCodeEditorMouseLine();
        if (line < 1) {
          return;
        }

        /* Configure breakpoint menu options */
        /* XXX TODO We should ask for the file specified in the firmware, not
         * the actual file on disk. */
        int address =
          CodeUI.this.mote.getExecutableAddressOf(displayedFile, line);
        if (address < 0) {
          return;
        }
        final int start = codeEditorLines.get(line);
        int end = codeEditorLines.get(line+1);
        Highlighter hl = codeEditor.getHighlighter();
        try {
          hl.changeHighlight(selectedLineTag, start, end);
        } catch (BadLocationException e1) {
        }
        boolean hasBreakpoint =
          CodeUI.this.mote.breakpointExists(address);
        if (!hasBreakpoint) {
          actionAddBreakpoint.setEnabled(true);
          actionAddBreakpoint.putValue("WatchpointMote", CodeUI.this.mote);
          actionAddBreakpoint.putValue("WatchpointFile", displayedFile);
          actionAddBreakpoint.putValue("WatchpointLine", new Integer(line));
          actionAddBreakpoint.putValue("WatchpointAddress", new Integer(address));
        } else {
          actionRemoveBreakpoint.setEnabled(true);
          actionRemoveBreakpoint.putValue("WatchpointMote", CodeUI.this.mote);
          actionRemoveBreakpoint.putValue("WatchpointFile", displayedFile);
          actionRemoveBreakpoint.putValue("WatchpointLine", new Integer(line));
          actionRemoveBreakpoint.putValue("WatchpointAddress", new Integer(address));
        }
      }
      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        Highlighter hl = codeEditor.getHighlighter();
        try {
          hl.changeHighlight(selectedLineTag, 0, 0);
        } catch (BadLocationException e1) {
        }
      }
      public void popupMenuCanceled(PopupMenuEvent e) {
      }
View Full Code Here

    displayNoCode(true);
  }

  public void updateBreakpoints() {
    Highlighter hl = codeEditor.getHighlighter();

    for (Object breakpointsLineTag: breakpointsLineTags) {
      hl.removeHighlight(breakpointsLineTag);
    }
    breakpointsLineTags.clear();

    for (Watchpoint w: mote.getBreakpoints()) {
      if (!w.getCodeFile().equals(displayedFile)) {
        continue;
      }

      final int start = codeEditorLines.get(w.getLineNumber());
      int end = codeEditorLines.get(w.getLineNumber()+1);
      try {
        breakpointsLineTags.add(hl.addHighlight(start, end, BREAKPOINTS_MARKER));
      } catch (BadLocationException e1) {
      }
    }
  }
View Full Code Here

   */
  private void displayLine(int lineNumber, boolean markCurrent) {
    try {
      if (markCurrent) {
        /* remove previous highlight */
        Highlighter hl = codeEditor.getHighlighter();
        hl.changeHighlight(currentLineTag, 0, 0);
      }

      if (lineNumber >= 0) {
        final int start = codeEditorLines.get(lineNumber);
        int end = codeEditorLines.get(lineNumber+1);
        if (markCurrent) {
          /* highlight code */
          Highlighter hl = codeEditor.getHighlighter();
          hl.changeHighlight(currentLineTag, start, end);
        }

        /* ensure visible */
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
View Full Code Here

    // Creates highlights around all occurrences of pattern in textComp
    protected void highlight(Pattern pattern, Color color) {
        Highlighter.HighlightPainter highlightPainter = new MyHighlightPainter(color);

        Highlighter hilite = getHighlighter();

        try {

            int start = 0;

            for (String line : getText().split("\n")){
                Matcher matcher = pattern.matcher(line);
                while(matcher.find()){
                    hilite.addHighlight(start + matcher.start(), start + matcher.end(), highlightPainter);
                }
                start += line.length() + 1;
            }

        } catch (BadLocationException e) {
View Full Code Here

    }

    // Removes only our private highlights
    protected void removeHighlights() {
        Highlighter hilite = getHighlighter();
        for ( Highlighter.Highlight h : hilite.getHighlights()){
            if (h.getPainter() instanceof MyHighlightPainter){
                hilite.removeHighlight(h);
            }
        }
    }
View Full Code Here

    // Creates highlights around all occurrences of pattern in textComp
    public void highlight(JTextComponent textComp, String pattern, Color color) {
        Highlighter.HighlightPainter highlightPainter = new MyHighlightPainter(color);
   
        try {
            Highlighter hilite = textComp.getHighlighter();
            javax.swing.text.Document doc = textComp.getDocument();
            String text = doc.getText(0, doc.getLength());
            int pos = 0;

            // Search for pattern
            while ((pos = text.indexOf(pattern, pos)) >= 0) {
                // Create highlighter using private painter and apply around pattern
                hilite.addHighlight(pos, pos+pattern.length(), highlightPainter);
                pos += pattern.length();
            }
        } catch (BadLocationException e) {

        }
View Full Code Here

        }
    }
   
    // Removes only our private highlights
    public void removeHighlights(JTextComponent textComp) {
        Highlighter hilite = textComp.getHighlighter();
        hilite.removeAllHighlights();
    }
View Full Code Here

    public void highlight(JTextComponent textComp, String pattern, Color color) {
        Highlighter.HighlightPainter highlightPainter = new MyHighlightPainter(color);

        try {
            Highlighter hilite = textComp.getHighlighter();
            javax.swing.text.Document doc = textComp.getDocument();
            String text = doc.getText(0, doc.getLength());
            int pos = 0;

            // Search for pattern
            while ((pos = text.indexOf(pattern, pos)) >= 0) {
                // Create highlighter using private painter and apply around pattern
                hilite.addHighlight(pos, pos + pattern.length(), highlightPainter);
                pos += pattern.length();
            }
        } catch (BadLocationException e) {
        }
    }
View Full Code Here

        }
    }

    // Removes only our private highlights
    public void removeHighlights(JTextComponent textComp) {
        Highlighter hilite = textComp.getHighlighter();
        hilite.removeAllHighlights();
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.Highlighter$HighlightPainter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.