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.
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations