package com.avanttic.rtf; import java.awt.Font; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; import javax.swing.text.BadLocationException; import javax.swing.text.BoxView; import javax.swing.text.Element; import javax.swing.text.LabelView; import javax.swing.text.View; public class AvtView extends BoxView { public static final int AREA_SHIFT = 36; //half inch public AvtView(Element elem) { super(elem, View.Y_AXIS); setInsets((short)0, (short)AREA_SHIFT, (short)0, (short)0); } public void paint(Graphics g, Shape alloc) { Rectangle a = alloc instanceof Rectangle ? (Rectangle)alloc : alloc.getBounds(); // Diseņa el texto a la derecha de los bullet super.paint(g, a); AvtDocument.ListElement elem = (AvtDocument.ListElement)getElement(); AvtDocument doc = (AvtDocument)getDocument(); int n = getViewCount(); //Rectangle clip = g.getClipBounds(); View v = getView(0); while (v.getViewCount() > 0) { v = v.getView(0); } Font f = doc.getFont(v.getAttributes()); g.setFont(f); //String s = "999."; String s = null; if (elem.type == AvtDocument.TYPE_BULLET) { s = "\u2022 "; } int w = g.getFontMetrics(f).stringWidth(s); int getLeftInset = getLeftInset(); int x = a.x + getLeftInset - (1 * w); int y = a.y + getTopInset(); for (int i = 0; i < n; i++) { y = a.y + getTopInset() + getOffset(Y_AXIS, i); v = getView(i); // Localiza la primera LabelView de Paragrafo while (v.getViewCount() > 0) { v = v.getView(0); } if (v instanceof LabelView) { y += ((LabelView)v).getGlyphPainter().getAscent((LabelView)v); } //s = (i + elem.start) + "."; if (elem.type == AvtDocument.TYPE_BULLET) { s = "\u2022"; } g.drawString(s, x, y); // System.out.println("la position de x est: "+x); // System.out.println("la position de y est: "+y); } } }