/** * This paints the entire plot. It calls the draw methods of all the attached axis and data sets. * The order of drawing is - Axis first, data legends next, data last. * * @params g Graphics state. */ public void paint(Graphics g) { int i; Graphics lg = g.create(); Rectangle r = bounds(); /* The r.x and r.y returned from bounds is relative to the ** parents space so set them equal to zero. */ r.x = 0; r.y = 0; if (DefaultBackground == null) DefaultBackground = this.getBackground(); if (DataBackground == null) DataBackground = this.getBackground(); // System.out.println("Graph2D paint method called!"); if (!paintAll) return; r.x += borderLeft; r.y += borderTop; r.width -= borderLeft + borderRight; r.height -= borderBottom + borderTop; paintFirst(lg, r); if (!axis.isEmpty()) r = drawAxis(lg, r); else { if (clearAll) { Color c = g.getColor(); g.setColor(DataBackground); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(c); } drawFrame(lg, r.x, r.y, r.width, r.height); } paintBeforeData(lg, r); if (!dataset.isEmpty()) { datarect.x = r.x; datarect.y = r.y; datarect.width = r.width; datarect.height = r.height; for (i = 0; i < dataset.size(); i++) { ((DataSet) dataset.elementAt(i)).draw_data(lg, r); } } paintLast(lg, r); lg.dispose(); }
/** The method to call when the thread starts */ public void run() { boolean draw = true; FontMetrics fm; Rectangle r; int sw = 0; int sa = 0; int x = 0; int y = 0; setPriority(Thread.MIN_PRIORITY); while (true) { if (newmessage != null && draw) { message = newmessage; newmessage = null; } if (lg == null) { lg = g2d.getGraphics(); if (lg != null) lg = lg.create(); } if (lg != null) { if (f != null) lg.setFont(f); fm = lg.getFontMetrics(lg.getFont()); sw = fm.stringWidth(message); sa = fm.getAscent(); } else { draw = false; } if (draw) { lg.setColor(foreground); r = g2d.bounds(); x = r.x + (r.width - sw) / 2; y = r.y + (r.height + sa) / 2; lg.drawString(message, x, y); g2d.repaint(); try { sleep(visible); } catch (Exception e) { } } else { if (lg != null) { lg.setColor(g2d.getBackground()); lg.drawString(message, x, y); g2d.repaint(); } try { sleep(invisible); } catch (Exception e) { } } draw = !draw; } }