コード例 #1
0
  /** setup current visual state of button */
  public void update() {
    RenderableBlock rb = workspace.getEnv().getRenderableBlock(getBlockID());

    if (rb != null) {
      int x = 5;
      int y = 7;

      if (rb.getBlock().isCommandBlock()) {
        y -= 2;
        x -= 3;
      }

      if (rb.getBlock().isDataBlock() || rb.getBlock().isFunctionBlock()) {
        x += 6;
        y -= 2;
      }

      if (rb.getBlock().isInfix() && rb.getBlock().getSocketAt(0) != null) {
        if (!rb.getBlock().getSocketAt(0).hasBlock()) {
          x += 30;
        } else {
          if (rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)) != null) {
            x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width + 2;
          }
        }
        y += 2;
        x += 1;
      }

      x = rb.rescale(x);
      y = rb.rescale(y);

      setLocation(x, y);
      setSize(rb.rescale(14), rb.rescale(14));

      if (isActive()) {
        setText("?");
        this.setForeground(new Color(255, 255, 0));
      } else {
        setText("?");
        this.setForeground(Color.lightGray);
      }
      rb.setComponentZOrder(this, 0);
    }
  }