return new WrapLabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { return new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { return new BoxView(elem, View.Y_AXIS);
@Override public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) { super.insertUpdate(e, a, f); resetBreakSpots(); }
@Override public void paint(Graphics g, Shape allocation) { Rectangle r = (allocation instanceof Rectangle) ? (Rectangle) allocation : allocation.getBounds(); Color oldColor = g.getColor(); Integer lineNumber = getLineNumber(); Color highlightColor = highlight.getHighlight(lineNumber); if (highlightColor != null) { g.setColor(highlightColor); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(oldColor); } // r.x += NUMBERS_WIDTH; super.paint(g, r); FontMetrics metrics = g.getFontMetrics(); g.setColor(Color.GRAY); String lineNumberString = lineNumber.toString(); int width = metrics.stringWidth(lineNumberString); int numberX = r.x - width - 9 + NUMBERS_WIDTH; int numberY = r.y + metrics.getAscent(); g.drawString(lineNumberString, numberX, numberY); g.setColor(oldColor); // System.out.println("Drawing line for " + lineNumber + " @ " + numberX // +"," + numberY); // r.x -= NUMBERS_WIDTH; }
@Override public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) { super.removeUpdate(e, a, f); resetBreakSpots(); }
public void paintChild(Graphics g, Rectangle r, int n) { boolean line0 = false; // kludge if (r.x == 3) { // kludge line0 = true; // kludge r.x = 33; // kludge } // kludge super.paintChild(g, r, n); if (line0) r.x = 3; // kludge int previousLineCount = getPreviousLineCount(); String formattedNumber; final int numberX = r.x - getLeftInset(); final int numberY = r.y + r.height - 3; // was 5 if (n > 0) { // This seems to set n > 0 if there is wrapping. Don't put out // a bogus line number formattedNumber = " "; } else { formattedNumber = Integer.toString(previousLineCount + n + 1); while (formattedNumber.length() < 3) { formattedNumber = " " + formattedNumber; } } g.drawString(formattedNumber, numberX, numberY); }
/** * Overriden to disable line wrap. */ @Override public void layout(int width, int height) { super.layout(Short.MAX_VALUE, height); }
@Override public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) { if (isOutside(e)) { // workaround for performance issue in 1.7.0_45 return; } super.removeUpdate(e, a, f); resetBreakSpots(); }
@Override public void paintChild(Graphics g, Rectangle r, int n) { super.paintChild(g, r, n); if (viewFactory.isLineNumbersVisible()) { if (n == 0) { g.setColor(Color.gray); int lineAscent = g.getFontMetrics().getAscent(); g.setFont(numberFont); //int numberAscent = g.getFontMetrics().getAscent(); int lineNumber = getDocument(). getDefaultRootElement(). getElementIndex(getStartOffset()); int numberX = r.x - getLeftInset(); //int numberY = r.y + g.getFontMetrics().getAscent(); int numberY = r.y + lineAscent; g.drawString(Integer.toString(lineNumber + 1), numberX, numberY); } } } }
@Override protected void layout(int width, int height) { super.layout(Short.MAX_VALUE, height); } }
@Override public View create(Element elem) { String kind = elem.getName(); if (kind != null) { if (kind.equals(AbstractDocument.ContentElementName)) { return new WrapLabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { return new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { return new BoxView(elem, View.Y_AXIS); } else if (kind.equals(StyleConstants.ComponentElementName)) { return new ComponentView(elem); } else if (kind.equals(StyleConstants.IconElementName)) { return new IconView(elem); } } return new LabelView(elem); } }
/** * Gives notification that something was removed from the document * in a location that this view is responsible for. * * @param changes the change information from the associated document * @param a the current allocation of the view * @param f the factory to use to rebuild if the view has children * @see View#removeUpdate */ @Override public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) { super.removeUpdate(changes, adjustAllocation(a), f); updateVisibilityModel(); } }
@Override public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) { if (isOutside(e)) { // workaround for performance issue in 1.7.0_45 return; } super.insertUpdate(e, a, f); resetBreakSpots(); }
/** * Renders using the given rendering surface and area on that surface. * The view may need to do layout and create child views to enable * itself to render into the given allocation. * * @param g the rendering surface to use * @param a the allocated region to render into * * @see View#paint */ @Override public void paint(Graphics g, Shape a) { Rectangle r = (Rectangle) a; g.clipRect(r.x, r.y, r.width, r.height); super.paint(g, adjustAllocation(a)); }
super.paintChild(g, r, n);
@Override public View create(Element elem) { String kind = elem.getName(); View view = null; if (kind == null) { // default to text display view = new LabelView(elem); } else if (kind.equals(AbstractDocument.ContentElementName)) { view = new LabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { view = new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { view = new BoxView(elem, View.Y_AXIS); } else if (kind.equals(StyleConstants.ComponentElementName)) { view = new ComponentView(elem); } else if (kind.equals(StyleConstants.IconElementName)) { view = new IconView(elem); } return view; } }
/** * Gives notification that something was inserted into the document * in a location that this view is responsible for. * * @param changes the change information from the associated document * @param a the current allocation of the view * @param f the factory to use to rebuild if the view has children * @see View#insertUpdate */ @Override public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) { super.insertUpdate(changes, adjustAllocation(a), f); updateVisibilityModel(); }
@Override public void paint(Graphics g, Shape a) { boolean isEmpty = getDocument().getLength() < 2; Color bgColor = (Color)getAttributes().getAttribute(Attribute.CUSTOM_BACKGROUND); if (bgColor == null && getAttributes().containsAttribute(Attribute.HIGHLIGHT_LINE, true)) { bgColor = MyStyleConstants.getHighlightBackground(getAttributes()); } if (bgColor == null && getAttributes().containsAttribute(Attribute.EVEN, true)) { bgColor = MyStyleConstants.getBackground2(getAttributes()); } if (bgColor != null && !isEmpty) { g.setColor(bgColor); Rectangle r = a.getBounds(); g.fillRect(0, r.y, getContainer().getWidth(), r.height); } Color separatorColor = MyStyleConstants.getSeparatorColor(getAttributes()); if (separatorColor != null && !isEmpty) { g.setColor(separatorColor); Rectangle r = a.getBounds(); g.drawLine(0, r.y, getContainer().getWidth(), r.y); if (bgColor != null) { g.drawLine(0, r.y+r.height, getContainer().getWidth(), r.y+r.height); } } super.paint(g, a); }
/** * @see javax.swing.text.ViewFactory#create(javax.swing.text.Element) */ public View create(Element elem) { String kind = elem.getName(); if (kind != null) { if (kind.equals(AbstractDocument.ContentElementName)) { return new TwoToneLabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { return new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { return new BoxView(elem, View.Y_AXIS); } else if (kind.equals(StyleConstants.ComponentElementName)) { return new ComponentView(elem); } else if (kind.equals(StyleConstants.IconElementName)) { return new IconView(elem); } // endif } // endif // default to text display return new TwoToneLabelView(elem); } }
@Override public View create(Element elem) { String kind = elem.getName(); if (kind != null) { if (kind.equals(AbstractDocument.ContentElementName)) { return new WrapLabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { return new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { return new BoxView(elem, View.Y_AXIS); } else if (kind.equals(StyleConstants.ComponentElementName)) { return new ComponentView(elem); } else if (kind.equals(StyleConstants.IconElementName)) { return new IconView(elem); } } // default to text display return new LabelView(elem); } }
public View create(Element elem) { String kind = elem.getName(); View view = null; if (kind == null) { // default to text display view = new LabelView(elem); } else if (kind.equals(AbstractDocument.ContentElementName)) { view = new LabelView(elem); } else if (kind.equals(AbstractDocument.ParagraphElementName)) { view = new ParagraphView(elem); } else if (kind.equals(AbstractDocument.SectionElementName)) { view = new BoxView(elem, View.Y_AXIS); } else if (kind.equals(StyleConstants.ComponentElementName)) { view = new ComponentView(elem); } else if (kind.equals(StyleConstants.IconElementName)) { view = new IconView(elem); } return view; } }