Search in sources :

Example 31 with Highlighter

use of javax.swing.text.Highlighter in project EditCalculateAndChart by mathhobbit.

the class TextAreaMouseListener method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    JTextArea area = TEdit.getTextArea();
    Highlighter hilite = area.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();
    if (hilites != null && hilites.length > 0) {
        TEdit.setEnabled("Delete", true);
        TEdit.setEnabled("Calc", true);
    } else {
        TEdit.setEnabled("Delete", false);
        TEdit.setEnabled("Calc", false);
    }
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
Also used : JTextArea(javax.swing.JTextArea) Highlighter(javax.swing.text.Highlighter)

Example 32 with Highlighter

use of javax.swing.text.Highlighter in project EditCalculateAndChart by mathhobbit.

the class Replace_Action method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JTextArea area = TEdit.getTextArea();
    if (area.getText().length() == 0) {
        // JOptionPane.showMessageDialog((Component)TEdit,"There is nothing to replace!");
        JOptionPane.showMessageDialog((Component) TEdit, "There is nothing to replace!", "Replace", JOptionPane.INFORMATION_MESSAGE, myIcon);
        return;
    }
    JTextField source = new JTextField();
    JTextField target = new JTextField();
    Object[] message = { "Source:", source, "Target:", target };
    int option = JOptionPane.showConfirmDialog(TEdit.getFrame(), message, "Replace", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, myIcon);
    if (option != JOptionPane.OK_OPTION)
        return;
    String src = source.getText();
    String trgt = target.getText();
    if (src.contentEquals(""))
        return;
    Highlighter hilite = area.getHighlighter();
    Highlighter.Highlight[] hilites = hilite.getHighlights();
    int Shift = 0;
    String txt = area.getText();
    if (hilites != null && hilites.length > 0) {
        for (Highlighter.Highlight hilite1 : hilites) {
            // txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()))
            area.replaceRange(txt.substring(hilite1.getStartOffset(), hilite1.getEndOffset()).replace(src, trgt), hilite1.getStartOffset() - Shift, hilite1.getEndOffset() - Shift);
            Shift = Shift - (src.length() - trgt.length());
        }
    } else {
        txt = txt.replace(src, trgt);
        area.setText(txt);
    }
}
Also used : JTextArea(javax.swing.JTextArea) JTextField(javax.swing.JTextField) Highlighter(javax.swing.text.Highlighter)

Example 33 with Highlighter

use of javax.swing.text.Highlighter in project cayenne by apache.

the class JCayenneTextPane method removeHighlightText.

public void removeHighlightText() {
    imageError = false;
    Highlighter highlighter = pane.getHighlighter();
    removeHighlightText(highlighter);
}
Also used : Highlighter(javax.swing.text.Highlighter)

Example 34 with Highlighter

use of javax.swing.text.Highlighter in project workcraft by workcraft.

the class HighlightUtils method highlightText.

private static Object highlightText(JTextComponent textComponent, int fromPos, int toPos, Color color, boolean drawsLayeredHighlights) {
    if ((color != null) && (textComponent != null) && (toPos > fromPos)) {
        DefaultHighlighter highlighter = (DefaultHighlighter) textComponent.getHighlighter();
        highlighter.setDrawsLayeredHighlights(drawsLayeredHighlights);
        Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(color);
        try {
            return highlighter.addHighlight(Math.max(fromPos, 0), Math.min(toPos, textComponent.getText().length()), painter);
        } catch (BadLocationException e) {
        }
    }
    return null;
}
Also used : DefaultHighlighter(javax.swing.text.DefaultHighlighter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 35 with Highlighter

use of javax.swing.text.Highlighter in project bytecode-viewer by Konloch.

the class FileViewer method highlight.

public void highlight(JTextComponent textComp, String pattern) {
    if (pattern.isEmpty()) {
        textComp.getHighlighter().removeAllHighlights();
        return;
    }
    try {
        Highlighter hilite = textComp.getHighlighter();
        hilite.removeAllHighlights();
        javax.swing.text.Document doc = textComp.getDocument();
        String text = doc.getText(0, doc.getLength());
        int pos = 0;
        if (!check.isSelected()) {
            pattern = pattern.toLowerCase();
            text = text.toLowerCase();
        }
        // 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(), painter);
            pos += pattern.length();
        }
    } catch (Exception e) {
        new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }
}
Also used : IOException(java.io.IOException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Aggregations

Highlighter (javax.swing.text.Highlighter)68 BadLocationException (javax.swing.text.BadLocationException)40 DefaultHighlighter (javax.swing.text.DefaultHighlighter)37 Matcher (java.util.regex.Matcher)12 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)10 JTextArea (javax.swing.JTextArea)9 Document (javax.swing.text.Document)9 Point (java.awt.Point)6 File (java.io.File)6 PatternSyntaxException (java.util.regex.PatternSyntaxException)5 DefaultHighlightPainter (javax.swing.text.DefaultHighlighter.DefaultHighlightPainter)5 Editor (omega.ui.component.Editor)5 StringTokenizer (java.util.StringTokenizer)4 JTextComponent (javax.swing.text.JTextComponent)4 Highlight (omega.instant.support.Highlight)4 IOException (java.io.IOException)3 ImageIcon (javax.swing.ImageIcon)3 AbstractErrorHighlighter (omega.instant.support.AbstractErrorHighlighter)3 JavaSyntaxParserGutterIconInfo (omega.instant.support.java.parser.JavaSyntaxParserGutterIconInfo)3 SquiggleUnderlineHighlightPainter (org.fife.ui.rsyntaxtextarea.SquiggleUnderlineHighlightPainter)3