1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| 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);
}
}
} |
Partager