Esempio n. 1
0
  /**
   * This is called to paint within the EditCanvas
   *
   * @param g Graphics
   * @param c DisplayCanvas to paint on.
   */
  public void paint(Graphics g, DisplayCanvas c) {
    Rectangle nb = transformOutput(c, getBounds());
    if (!getActive()) {
      Rectangle r = getBounds();
      g.setColor(Color.lightGray);
      g.fillRect(r.x, r.y, r.width, r.height);
    }

    draw((Graphics2D) g, nb.x, nb.y, nb.width, nb.height);

    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).getShowParams()) {
      int xoff = 0;
      FontMetrics fm = g.getFontMetrics();
      g.setColor(Color.black);
      for (int i = 0; i < paramIds.length; i++) {
        String s = paramIds[i];
        if (i > 0) {
          s = ", " + s;
        }
        g.drawString(s, nb.x + xoff, nb.y + nb.height + fm.getMaxDescent() + fm.getMaxAscent() + 4);
        xoff += fm.stringWidth(s);
      }
    }
    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).shouldShowAlignmentPoints()) {
      paintRectPoint(g, c);
    }
  }
Esempio n. 2
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();
  }
Esempio n. 3
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
  public void paintComponent(Graphics screen) {
    if (inactive == null) {
      inactive = new Image[BUTTON_COUNT];
      rollover = new Image[BUTTON_COUNT];
      active = new Image[BUTTON_COUNT];

      int IMAGE_SIZE = 33;

      for (int i = 0; i < BUTTON_COUNT; i++) {
        inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        Graphics g = inactive[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null);

        rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = rollover[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null);

        active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = active[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null);
      }

      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
    }
    Dimension size = getSize();
    if ((offscreen == null) || (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      y1 = 0;
      y2 = BUTTON_HEIGHT;

      x1 = new int[buttonCount];
      x2 = new int[buttonCount];

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); // getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
    int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
    g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);

    screen.drawImage(offscreen, 0, 0, null);
  }
Esempio n. 5
0
  @Override
  public void paintComponent(Graphics screen) {
    // this data is shared by all EditorToolbar instances
    if (buttonImages == null) {
      loadButtons();
    }

    // this happens once per instance of EditorToolbar
    if (stateImage == null) {
      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
      y1 = 0;
      y2 = BUTTON_HEIGHT;
      x1 = new int[buttonCount];
      x2 = new int[buttonCount];
    }

    Dimension size = getSize();
    if ((offscreen == null) ||
        (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2 || i == 6) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
      
      // Serial button must be on the right
      x1[SERIAL] = width - BUTTON_WIDTH - 14;
      x2[SERIAL] = width - 14;
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); //getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
     * 
     * whereas I love the Java2D API. --jdf. lol.
     * 
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    if (currentRollover != -1) {
      int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
      String status = shiftPressed ? titleShift[currentRollover] : (controlPressed ? titleControl[currentRollover] : title[currentRollover]);
           
      if (currentRollover != SERIAL)
        g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
      else {
      	// Pending
		if(editor.serialMonitor.isOpenPending!=null)
			if(editor.serialMonitor.isOpenPending)
				status += " (Monitor will open after upload)";
  		
        int statusX = x1[SERIAL] - BUTTON_GAP;
        statusX -= g.getFontMetrics().stringWidth(status);
        g.drawString(status, statusX, statusY);
      }
    }

    screen.drawImage(offscreen, 0, 0, null);
    
    if (!isEnabled()) {
      screen.setColor(new Color(0,0,0,100));
      screen.fillRect(0, 0, getWidth(), getHeight());
  	}
  }