Пример #1
0
 private void computeSize(boolean immediate) {
   hidePopup();
   Bounds bounds;
   CircuitState circState = circuitState;
   if (circState == null) {
     bounds = Bounds.create(0, 0, 50, 50);
   } else {
     bounds = circState.getCircuit().getAppearance().getAbsoluteBounds();
   }
   int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
   int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
   Size dim;
   if (canvasPane == null) {
     dim = new Size(width, height);
   } else {
     dim = canvasPane.supportPreferredSize(width, height);
   }
   if (!immediate) {
     Bounds old = oldPreferredSize;
     if (old != null
         && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE
         && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
       return;
     }
   }
   oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
   setPreferredSize(dim);
   revalidate();
 }
Пример #2
0
  //
  // graphics methods
  //
  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int asc = fm.getAscent();

    painter.drawBounds();

    String s0;
    String type = getType(painter.getAttributeSet());
    if (type.equals("zero")) s0 = Strings.get("extenderZeroLabel");
    else if (type.equals("one")) s0 = Strings.get("extenderOneLabel");
    else if (type.equals("sign")) s0 = Strings.get("extenderSignLabel");
    else if (type.equals("input")) s0 = Strings.get("extenderInputLabel");
    else s0 = "???"; // should never happen
    String s1 = Strings.get("extenderMainLabel");
    Bounds bds = painter.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
    int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
    GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);

    BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
    BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
    painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
    painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
    if (type.equals("input")) painter.drawPort(2);
  }
Пример #3
0
 static void drawALU(Graphics g, Bounds bds) {
   int wid = bds.getWidth();
   int ht = bds.getHeight();
   int x0 = bds.getX();
   int x1 = x0 + wid;
   int y0 = bds.getY();
   int y1 = y0 + ht;
   int xp[] = {x0, x1, x1, x0, x0, x0 + 20, x0};
   int yp[] = {y0, y0 + 30, y1 - 30, y1, y1 - 40, y1 - 50, y1 - 60};
   GraphicsUtil.switchToWidth(g, 2);
   g.drawPolygon(xp, yp, 7);
 }
Пример #4
0
 static void configureLabel(Instance instance, boolean isRectangular, Location control) {
   Object facing = instance.getAttributeValue(StdAttr.FACING);
   Bounds bds = instance.getBounds();
   int x;
   int y;
   int halign;
   if (facing == Direction.NORTH || facing == Direction.SOUTH) {
     x = bds.getX() + bds.getWidth() / 2 + 2;
     y = bds.getY() - 2;
     halign = TextField.H_LEFT;
   } else { // west or east
     y = isRectangular ? bds.getY() - 2 : bds.getY();
     if (control != null && control.getY() == bds.getY()) {
       // the control line will get in the way
       x = control.getX() + 2;
       halign = TextField.H_LEFT;
     } else {
       x = bds.getX() + bds.getWidth() / 2;
       halign = TextField.H_CENTER;
     }
   }
   instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, TextField.V_BASELINE);
 }
Пример #5
0
  private void paintBase(InstancePainter painter) {
    GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;

    Object shape = painter.getGateShape();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int width = bds.getWidth();
    int height = bds.getHeight();
    if (facing == Direction.NORTH || facing == Direction.SOUTH) {
      int t = width;
      width = height;
      height = t;
    }
    if (negated != 0) {
      width -= 10;
    }

    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
      PainterShaped.paintInputLines(painter, this);
    } else if (negated != 0) {
      for (int i = 0; i < inputs; i++) {
        int negatedBit = (negated >> i) & 1;
        if (negatedBit == 1) {
          Location in = getInputOffset(attrs, i);
          Location cen = in.translate(facing, 5);
          painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY());
        }
      }
    }

    g.setColor(baseColor);
    g.translate(loc.getX(), loc.getY());
    double rotate = 0.0;
    if (facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      Graphics2D g2 = (Graphics2D) g;
      g2.rotate(rotate);
    }

    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
      paintRectangular(painter, width, height);
    } else if (shape == AppPreferences.SHAPE_DIN40700) {
      paintDinShape(painter, width, height, inputs);
      // SHAPE_SHAPED
    } else {
      if (negateOutput) {
        g.translate(-10, 0);
        paintShape(painter, width - 10, height);
        painter.drawDongle(5, 0);
        g.translate(10, 0);
      } else {
        paintShape(painter, width, height);
      }
    }

    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-loc.getX(), -loc.getY());

    painter.drawLabel();
  }
Пример #6
0
 public void drawRectangle(Bounds bds, String label) {
   context.drawRectangle(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), label);
 }