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 }
/** * 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; }
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); } }
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); } }
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); } }
/** * 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; }
/** 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; }
/** 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(); } }
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); } }
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); } }
/** * 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); } }
/** * 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(); } } } }