Exemplo n.º 1
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
Exemplo n.º 2
0
  // Countdown Paint Handler
  public void paint(Graphics g) {
    FontMetrics fm = g.getFontMetrics();

    int strWidth = fm.stringWidth(countString);

    int appletWidth = size().width;

    g.drawString(countString, (appletWidth - strWidth) / 2, 20);
  }
Exemplo n.º 3
0
  public void CalculateSize(Graphics g) {
    oldwidth = sx2 - sx1;
    oldheight = sy2 - sy1;
    Font testfont;

    testfont = new Font("TimesRoman", Font.PLAIN, 100);
    g.setFont(testfont);
    int width = g.getFontMetrics().stringWidth(short_name);
    int height = g.getFontMetrics().getHeight();
    double xratio = ((double) (oldwidth)) / ((double) width);
    double yratio = ((double) (oldheight)) / ((double) height);
    double fsize;
    if (xratio > yratio) {
      // use yratio to calculate size
      fsize = 100.0 * yratio;
    } else fsize = 100.0 * xratio;
    if (fsize < 1.0) fsize = 1.0;
    fsize = fsize * Caption.FontScale;
    currfont = new Font("TimesRoman", Font.PLAIN, (int) fsize);

    g.setFont(currfont);
    xoff = (sx2 - sx1 - g.getFontMetrics().stringWidth(short_name)) / 2;
    yoff = g.getFontMetrics().getDescent();
  }
Exemplo n.º 4
0
 public static void showName(Graphics g, String name) {
   FontMetrics metrics = g.getFontMetrics(countryName);
   int nameWidth = metrics.stringWidth(name);
   int boxWidth = nameWidth + 20;
   int xName = 950 - nameWidth;
   int xBox = xName - 10;
   Expo.setColor(g, Expo.white);
   Expo.fillRectangle(g, xBox, 50, xBox + boxWidth, 120);
   Expo.setColor(g, Expo.black);
   Expo.drawRectangle(g, xBox, 50, xBox + boxWidth, 120);
   for (int j = 1; j <= 5; j++) {
     Expo.drawLine(g, xBox + j, 120 + j, xBox + boxWidth + j, 120 + j);
     Expo.drawLine(g, xBox + boxWidth + j, 50 + j, xBox + boxWidth + j, 120 + j);
   }
   Expo.drawRectangle(g, xBox + 1, 51, xBox + boxWidth + 1, 121);
   g.setFont(countryName);
   g.drawString(name, xName, 100);
   Expo.delay(2000); // Wait 2 second before showing next flag.
 }
Exemplo n.º 5
0
  public void update(Graphics g) {
    Dimension d = size();
    if (d.width < 1 || d.height < 1) return;

    if ((offscreen == null)
        || (d.width != offscreensize.width)
        || (d.height != offscreensize.height)) {
      offscreen = createImage(d.width, d.height);
      offscreensize = d;
      offGraphics = offscreen.getGraphics();
    }

    offGraphics.setColor(getBackground());
    offGraphics.fillRect(0, 0, d.width, d.height);
    Font font = new Font("Dialog", Font.PLAIN, 10);
    offGraphics.setFont(font);
    fm = offGraphics.getFontMetrics();
    paint(offGraphics);
    g.drawImage(offscreen, 0, 0, null);
  }
Exemplo n.º 6
0
  /** 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;
    }
  }