public void render(int w, int h, Graphics2D g2) {
FontRenderContext frc = g2.getFontRenderContext();
Font f = new Font("sansserif",Font.BOLD,32);
String s = new String("JAVA");
TextLayout tl = new TextLayout(s, f, frc);
double sw = tl.getBounds().getWidth();
double sh = tl.getBounds().getHeight();
double sx = (w-40)/sw;
double sy = (h-40)/sh;
AffineTransform Tx = AffineTransform.getScaleInstance(sx, sy);
Shape shape = tl.getOutline(Tx);
sw = shape.getBounds().getWidth();
sh = shape.getBounds().getHeight();
Tx = AffineTransform.getTranslateInstance(w/2-sw/2, h/2+sh/2);
shape = Tx.createTransformedShape(shape);
Rectangle r = shape.getBounds();
if (doClip) {
g2.clip(shape);
}
if (clipType.equals("Lines")) {
g2.setColor(BLACK);
g2.fill(r);
g2.setColor(YELLOW);
g2.setStroke(new BasicStroke(1.5f));
for (int j = r.y; j < r.y + r.height; j=j+3) {
Line2D line = new Line2D.Float( (float) r.x, (float) j,
(float) (r.x+r.width), (float) j);
g2.draw(line);
}
} else if (clipType.equals("Image")) {
g2.drawImage(img, r.x, r.y, r.width, r.height, null);
} else if (clipType.equals("TP")) {
g2.setPaint(texture);
g2.fill(r);
} else if (clipType.equals("GP")) {
g2.setPaint(new GradientPaint(0,0,BLUE,w,h,YELLOW));
g2.fill(r);
} else if (clipType.equals("Text")) {
g2.setColor(BLACK);
g2.fill(shape.getBounds());
g2.setColor(CYAN);
f = new Font("serif",Font.BOLD,10);
tl = new TextLayout("java", f, frc);
sw = tl.getBounds().getWidth();
int x = r.x;
int y = (int) (r.y + tl.getAscent());
sh = r.y + r.height;
while ( y < sh ) {
tl.draw(g2, x, y);
if ((x += (int) sw) > (r.x+r.width)) {
x = r.x;
y += (int) tl.getAscent();
}
}
}
g2.setClip(new Rectangle(0, 0, w, h));