// Data structure to keep track of one client in the GodClient. // what a mess. import java.awt.*; import FixedNumberFont; public class GodClientInfo extends Object { // data about client public int id, x, y; public long lastTime; // display information int screenX, screenY; FixedNumberFont bigFont, smallFont; Rectangle boundingBox, frame; Point timeP, xP, yP, idP; int border = 4, whiteBorder = 16, leading = -8; // These values depend on information above and font size (hack hack) // They are also calculated in the bounding box, but only *after* the // first one has been created. static final int infoWidth = 126; static final int infoHeight = 185; public GodClientInfo(int n, int nx, int ny, FixedNumberFont f1, FixedNumberFont f2) { id = n; x = nx; y = ny; bigFont = f1; smallFont = f2; int width = bigFont.getWidth(); int height = bigFont.getHeight(); // frame is the black border around the data frame = new Rectangle(whiteBorder, whiteBorder + smallFont.getHeight(), width + 2 * border, 3 * height + 2 * leading + 2 * border); // find the offsets of the text info timeP = new Point(whiteBorder + border + (width - smallFont.getWidth()) / 2, whiteBorder); xP = new Point(whiteBorder + border, smallFont.getHeight() + border + whiteBorder); idP = new Point(whiteBorder + border, smallFont.getHeight() + border + (height+leading) + whiteBorder); yP = new Point(whiteBorder + border, smallFont.getHeight() + border + 2*(height+leading) + whiteBorder); setScreenPosition(x, y); } // recalculate the bounding box, depending on our screen position public void setScreenPosition(int x, int y) { int width = bigFont.getWidth(); int height = bigFont.getHeight(); // adjust leading screenX = x; screenY = y; boundingBox = new Rectangle(screenX, screenY, frame.width + 2*whiteBorder, frame.height + smallFont.getHeight() + 2*whiteBorder); } public void setTime(long t) { lastTime = t; } // render in pieces public void render(Graphics g, Color frameColor) { g.setColor(frameColor); g.fillRect(screenX + frame.x, screenY + frame.y, frame.width, frame.height); bigFont.drawNumber(g, x % 1000, screenX + xP.x, screenY + xP.y); bigFont.drawNumber(g, id % 1000, screenX + idP.x, screenY + idP.y); bigFont.drawNumber(g, y % 1000, screenX + yP.x, screenY + yP.y); smallFont.drawNumber(g, (int)((lastTime/10) % 100000), screenX + timeP.x, screenY + timeP.y); } }