1 19 24 25 package org.netbeans.core.output2; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import javax.swing.*; 31 import javax.swing.text.*; 32 import java.awt.*; 33 34 42 class ExtPlainView extends PlainView { 43 private final Segment SEGMENT = new Segment(); 44 45 46 private static final boolean antialias = Boolean.getBoolean ("swing.aatext") || "Aqua".equals (UIManager.getLookAndFeel().getID()); 49 private static Map hintsMap = null; 50 51 static final Map getHints() { 52 if (hintsMap == null) { 53 hintsMap = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); if (hintsMap == null) { 56 hintsMap = new HashMap (); 57 if (antialias) 58 hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 59 } 60 } 61 return hintsMap; 62 } 63 64 65 ExtPlainView(Element elem) { 66 super (elem); 67 } 68 69 public void paint(Graphics g, Shape allocation) { 70 ((Graphics2D)g).addRenderingHints(getHints()); 71 super.paint(g, allocation); 72 } 73 74 protected int drawSelectedText(Graphics g, int x, 75 int y, int p0, int p1) throws BadLocationException { 76 77 Document doc = getDocument(); 78 if (doc instanceof OutputDocument) { 79 Segment s = SwingUtilities.isEventDispatchThread() ? SEGMENT : 80 new Segment(); 81 doc.getText(p0, p1 - p0, s); 82 g.setColor(getColorForLocation(p0, doc, true)); 83 int ret = Utilities.drawTabbedText(s, x, y, g, this, p0); 84 if (g.getColor() == WrappedTextView.selectedLinkFg || g.getColor() == WrappedTextView.selectedImportantLinkFg) { 85 underline(g, s, x, p0, y); 88 } 89 return ret; 90 } else { 91 return super.drawUnselectedText (g, x, y, p0, p1); 92 } 93 } 94 95 96 protected int drawUnselectedText(Graphics g, int x, int y, 97 int p0, int p1) throws BadLocationException { 98 Document doc = getDocument(); 99 if (doc instanceof OutputDocument) { 100 Segment s = SwingUtilities.isEventDispatchThread() ? SEGMENT : 101 new Segment(); 102 doc.getText(p0, p1 - p0, s); 103 g.setColor(getColorForLocation(p0, doc, false)); 104 int ret = Utilities.drawTabbedText(s, x, y, g, this, p0); 105 if (g.getColor() == WrappedTextView.selectedLinkFg || g.getColor() == WrappedTextView.selectedImportantLinkFg) { 106 underline(g, s, x, p0, y); 109 } 110 return ret; 111 } else { 112 return super.drawUnselectedText (g, x, y, p0, p1); 113 } 114 } 115 116 private void underline(Graphics g, Segment s, int x, int p0, int y) { 117 int wid = g.getFontMetrics().charWidth(' '); char[] txt = s.array; 119 int txtOffset = s.offset; 120 int txtCount = s.count; 121 int n = s.offset + s.count; 122 int tabCount = 0; 123 int wsCount = 0; 124 for (int i = s.offset; i < n; i++) { 125 if (txt[i] == '\t') { x = (int) nextTabStop((float) x, 127 p0 + i - txtOffset); 128 tabCount++; 129 } else if (Character.isWhitespace(txt[i])) { 130 x += wid; 131 wsCount++; 132 } else { 133 break; 134 } 135 } 136 int end = x + (wid * (txtCount - (wsCount + tabCount + 1))); 137 if (end > x) { 138 g.drawLine (x, y+1, end, y+1); 139 } 140 } 141 142 private static Color getColorForLocation (int start, Document d, boolean selected) { 143 OutputDocument od = (OutputDocument) d; 144 int line = od.getElementIndex (start); 145 boolean hyperlink = od.getLines().isHyperlink(line); 146 boolean important = hyperlink ? od.getLines().isImportantHyperlink(line) : false; 147 boolean isErr = od.getLines().isErr(line); 148 149 return hyperlink ? 150 (important ? 151 (selected ? 152 WrappedTextView.selectedImportantLinkFg : 153 WrappedTextView.unselectedImportantLinkFg) : 154 (selected ? 155 WrappedTextView.selectedLinkFg : 156 WrappedTextView.unselectedLinkFg)) : 157 (selected ? 158 (isErr ? 159 WrappedTextView.selectedErr : 160 WrappedTextView.selectedFg) : 161 (isErr ? 162 WrappedTextView.unselectedErr : 163 WrappedTextView.unselectedFg)); 164 } 165 166 } 167 | Popular Tags |