Webber: A Website Construction Application
DrawStringBuffer.java
// Implementation of a cache for Graphics.drawString()
package library;
import java.awt.Graphics;
public class DrawStringBuffer {
private String buffer; // String buffer
private Graphics g; // Graphics context
private int x, y; // String start point
// Create a buffer and/or append a string
public void drawString(String s, int x, int y, Graphics g) {
if (buffer==null) { // Create a new buffer
buffer = s; this.g = g; // Set string and context
this.x = x; this.y = y; // Set string start point
} else buffer += s; // Append string to buffer
}
// Draw current string and empty the buffer
public void flush() {
if (buffer!=null) { // String in buffer?
g.drawString(buffer, x, y); // Draw the string
buffer = null; // Empty the buffer
}
}
}
Go To:
Source Code