本文整理汇总了Java中javax.swing.text.DefaultHighlighter类的典型用法代码示例。如果您正苦于以下问题:Java DefaultHighlighter类的具体用法?Java DefaultHighlighter怎么用?Java DefaultHighlighter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultHighlighter类属于javax.swing.text包,在下文中一共展示了DefaultHighlighter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FindSupport
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
private FindSupport(TopComponent tc) {
this.tc = tc;
bar = new FindBar(this);
ActionMap actionMap = tc.getActionMap();
CallbackSystemAction a = SystemAction.get(org.openide.actions.FindAction.class);
actionMap.put(a.getActionMapKey(), new FindAction(true));
actionMap.put(FIND_NEXT_ACTION, new FindAction(true));
actionMap.put(FIND_PREVIOUS_ACTION, new FindAction(false));
// Hack ensuring the same shortcuts as editor
JEditorPane pane = new JEditorPane();
for (Action action : pane.getEditorKitForContentType("text/x-java").getActions()) { // NOI18N
Object name = action.getValue(Action.NAME);
if (FIND_NEXT_ACTION.equals(name) || FIND_PREVIOUS_ACTION.equals(name)) {
reuseShortcut(action);
}
}
// PENDING the colors below should not be hardcoded
highlighterAll = new DefaultHighlighter.DefaultHighlightPainter(new Color(255,180,66));
highlighterCurrent = new DefaultHighlighter.DefaultHighlightPainter(new Color(176,197,227));
pattern = Pattern.compile("$^"); // NOI18N
}
示例2: highligher
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
public void highligher(int row) {
int[] line = new int[1000];
line[0] = 0;
for (int i = 0, lineNo = 0; i < jTextPane1.getText().length(); i++) {
if (jTextPane1.getText().charAt(i) == '\n') {
line[++lineNo] = i;
}
}
try {
jTextPane1.getHighlighter().removeAllHighlights();
jTextPane1.setCaretPosition(line[row]);
jTextPane1.getHighlighter().addHighlight(line[row], line[row + 1], new DefaultHighlighter.DefaultHighlightPainter(new Color(0xFF3333)));
} catch (Exception ex) {
System.err.println(ex);
}
}
示例3: loadDisassembler
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
public void loadDisassembler() {
asm.jTextAreaDisassembler.getHighlighter().removeAllHighlights();
String s = asm.jTextAreaDisassembler.getText(), line = "";
int selectIndex = 0;
try {
while (s.indexOf(":", selectIndex) != -1) {
line = s.substring(s.indexOf(":", selectIndex) + 1, s.indexOf("\n", selectIndex) == -1 ? s.length() : s.indexOf("\n", selectIndex));
selectIndex = line.length() + selectIndex + 2;
if (!CRC8(line).equalsIgnoreCase("00")) {
asm.jTextAreaDisassembler.getHighlighter().addHighlight(selectIndex - line.length() - 2, selectIndex, new DefaultHighlighter.DefaultHighlightPainter(Color.RED));
}
if (line.substring(6, 8).equalsIgnoreCase("00")) {
for (int i = 0; i < line.substring(8, line.length() - 2).length() / 2; i++) {
asm.matrix.memory[asm.engine.convertToNum(line.substring(2, 6)) + i] = asm.engine.convertToNum(line.substring(8 + (i * 2), 10 + (i * 2)));
}
}
}
disasemble();
} catch (Exception e) {
try {
asm.jTextAreaDisassembler.getHighlighter().addHighlight(selectIndex - line.length(), selectIndex, new DefaultHighlighter.DefaultHighlightPainter(Color.RED));
} catch (Exception ex) {
}
System.out.println(e);
}
}
示例4: highligher
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
public void highligher(int row){
int[] line=new int[1000];
line[0]=0;
for (int i = 0,lineNo=0; i < jTextPane1.getText().length(); i++) {
if(jTextPane1.getText().charAt(i)=='\n'){
line[++lineNo]=i;
}
}
try {
jTextPane1.getHighlighter().removeAllHighlights();
jTextPane1.setCaretPosition(line[row]);
jTextPane1.getHighlighter().addHighlight(line[row], line[row+1], new DefaultHighlighter.DefaultHighlightPainter(new Color(0xFF3333)));
} catch (Exception ex) {
System.err.println(ex);
}
}
示例5: useSelectedTextColor
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
/**
* Determines whether the SelectedTextColor should be used for painting text
* foreground for the specified highlight.
*
* Returns true only if the highlight painter for the specified highlight
* is the swing painter (whether inner class of javax.swing.text.DefaultHighlighter
* or com.sun.java.swing.plaf.windows.WindowsTextUI) and its background color
* is null or equals to the selection color of the text component.
*
* This is a hack for fixing both bugs 4761990 and 5003294
*/
public static boolean useSelectedTextColor(Highlighter.Highlight h, JTextComponent c) {
Highlighter.HighlightPainter painter = h.getPainter();
String painterClass = painter.getClass().getName();
if (painterClass.indexOf("javax.swing.text.DefaultHighlighter") != 0 &&
painterClass.indexOf("com.sun.java.swing.plaf.windows.WindowsTextUI") != 0) {
return false;
}
try {
DefaultHighlighter.DefaultHighlightPainter defPainter =
(DefaultHighlighter.DefaultHighlightPainter) painter;
if (defPainter.getColor() != null &&
!defPainter.getColor().equals(c.getSelectionColor())) {
return false;
}
} catch (ClassCastException e) {
return false;
}
return true;
}
示例6: pane
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
/** Constructs an antialias-capable JTextPane with a DefaultHighlighter associated with it.
* @param attributes - see {@link edu.mit.csail.sdg.alloy4.OurUtil#make OurUtil.make(component, attributes...)}
*/
public static JTextPane pane(Object... attributes) {
JTextPane ans = new JTextPane() {
static final long serialVersionUID = 0;
@Override public void paint(Graphics gr) {
if (antiAlias && gr instanceof Graphics2D) {
((Graphics2D)gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
super.paint(gr);
}
};
OurUtil.make(ans, attributes);
ans.setHighlighter(new DefaultHighlighter());
map.put(ans, Boolean.TRUE);
return ans;
}
示例7: addHighlight
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
int start = info.start;
int end = info.end;
if (start == -1 && end == -1)
return;
if (start == -1)
start = end;
if (end == -1)
end = start;
try {
h.addHighlight(info.start, info.end,
new DefaultHighlighter.DefaultHighlightPainter(c));
if (info.pos != -1) {
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
h.addHighlight(info.pos, info.pos + 1,
new DefaultHighlighter.DefaultHighlightPainter(c2));
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例8: highlight
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if ( scroll ) {
if ( comp.getCaretPosition()< i || comp.getCaretPosition()>j ) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
示例9: highlight
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
}
catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
示例10: highlightText
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
/**
* Highlights the words of the given text in HTML pane.
*/
private void highlightText(String highlightedText)
{
DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(
new Color(255, 204, 51));
this.helpEditorPane.getHighlighter().removeAllHighlights();
if (highlightedText != null)
{
ArrayList<String> highlightedWords = new ArrayList<String>();
for (String highlightedWord : highlightedText.split("\\s"))
{
if (highlightedWord.length() > 0)
{
highlightedWords.add(highlightedWord);
}
}
highlightWords(this.helpEditorPane.getDocument().getDefaultRootElement(),
highlightedWords.toArray(new String[highlightedWords.size()]), highlightPainter);
}
}
示例11: highlightErrorLines
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
/**
* Highlights the lines of the original file that contain detected errors.
*/
private void highlightErrorLines() {
String text = originalFileDisplayTextArea.getText();
String[] lines = text.split("\n");
for (int i = 0; i < lines.length; i++)
{
if (lines[i].contains(" <ERROR #"))
{
try
{
int startIndex = originalFileDisplayTextArea.getLineStartOffset(i);
int endIndex = originalFileDisplayTextArea.getLineEndOffset(i);
Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(new Color(250, 170, 170));
originalFileDisplayTextArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
}
catch (BadLocationException ex)
{
ex.printStackTrace();
}
}
}
}
示例12: searchWord
import javax.swing.text.DefaultHighlighter; //导入依赖的package包/类
private synchronized void searchWord(JTextArea textArea,String serchpattern){
Document doc = textArea.getDocument();
String targetString = null;
try {
targetString = doc.getText(0, doc.getLength());
} catch (BadLocationException e1) {
logger.debug(e1);
}
int pos = targetString.indexOf(serchpattern, movePos);
if(pos > -1){
Highlighter highlighter = textArea.getHighlighter();
try {
highlighter.addHighlight(pos, pos + serchpattern.length(), DefaultHighlighter.DefaultPainter);
textArea.setCaretPosition(pos);
movePos = pos + serchpattern.length();
} catch (BadLocationException e) {
logger.debug(e);
}
}else{
movePos = 0;
}
}