コード例 #1
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
 @Override
 public void paintInstance(InstancePainter painter) {
   paintBase(painter);
   if (!painter.isPrintView() || painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
     painter.drawPorts();
   }
 }
コード例 #2
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
 @Override
 public void paintInstance(InstancePainter painter) {
   painter.getGraphics().setColor(Color.BLACK);
   paintBase(painter);
   painter.drawPorts();
   painter.drawLabel();
 }
コード例 #3
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
  private void paintBase(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    g.translate(x, y);
    double rotate = 0.0;
    if (facing != null && facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      ((Graphics2D) g).rotate(rotate);
    }

    Object shape = painter.getGateShape();
    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
      paintRectangularBase(g, painter);
    } else if (shape == AppPreferences.SHAPE_DIN40700) {
      int width = painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW ? 20 : 30;
      PainterDin.paintAnd(painter, width, 18, true);
    } else {
      PainterShaped.paintNot(painter);
    }

    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
  }
コード例 #4
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
 protected void paintRectangular(InstancePainter painter, int width, int height) {
   int don = negateOutput ? 10 : 0;
   AttributeSet attrs = painter.getAttributeSet();
   painter.drawRectangle(-width, -height / 2, width - don, height, getRectangularLabel(attrs));
   if (negateOutput) {
     painter.drawDongle(-5, 0);
   }
 }
コード例 #5
0
ファイル: PullResistor.java プロジェクト: pavelfatin/logisim
 //
 // graphics methods
 //
 @Override
 public void paintIcon(InstancePainter painter) {
   Icon icon;
   if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
     icon = ICON_SHAPED;
   } else {
     icon = ICON_RECTANGULAR;
   }
   icon.paintIcon(painter.getDestination(), painter.getGraphics(), 2, 2);
 }
コード例 #6
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
  protected void paintIconRectangular(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    g.drawRect(1, 2, 16, 16);
    if (negateOutput) {
      g.drawOval(16, 8, 4, 4);
    }

    String label = getRectangularLabel(painter.getAttributeSet());
    GraphicsUtil.drawCenteredText(g, label, 9, 8);
  }
コード例 #7
0
ファイル: PullResistor.java プロジェクト: pavelfatin/logisim
 @Override
 public void paintInstance(InstancePainter painter) {
   Location loc = painter.getLocation();
   int x = loc.getX();
   int y = loc.getY();
   Graphics g = painter.getGraphics();
   g.translate(x, y);
   Value pull = getPullValue(painter.getAttributeSet());
   Value actual = painter.getPort(0);
   paintBase(painter, pull, pull.getColor(), actual.getColor());
   g.translate(-x, -y);
   painter.drawPorts();
 }
コード例 #8
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);
  }
コード例 #9
0
ファイル: Ground.java プロジェクト: IsThisSparta/Logisim
  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());

    Direction from = painter.getAttributeValue(StdAttr.FACING);
    int degrees = Direction.EAST.toDegrees() - from.toDegrees();
    double radians = Math.toRadians((degrees + 360) % 360);
    g.rotate(radians);

    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    if (!isGhost && painter.getShowState()) {
      g.setColor(painter.getPort(0).getColor());
    }
    g.drawLine(0, 0, 5, 0);

    GraphicsUtil.switchToWidth(g, 1);
    if (!isGhost && painter.shouldDrawColor()) {
      BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
      g.setColor(Value.repeat(Value.FALSE, width.getWidth()).getColor());
    }
    g.drawLine(6, -8, 6, 8);
    g.drawLine(9, -5, 9, 5);
    g.drawLine(12, -2, 12, 2);

    g.dispose();
  }
コード例 #10
0
ファイル: PullResistor.java プロジェクト: pavelfatin/logisim
  private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
    boolean color = painter.shouldDrawColor();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    GraphicsUtil.switchToWidth(g, 3);
    if (color && inColor != null) g.setColor(inColor);
    if (facing == Direction.EAST) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.WEST) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.NORTH) {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    } else {
      GraphicsUtil.drawText(
          g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    }

    double rotate = 0.0;
    if (g instanceof Graphics2D) {
      rotate = Direction.SOUTH.toRadians() - facing.toRadians();
      if (rotate != 0.0) ((Graphics2D) g).rotate(rotate);
    }
    g.drawLine(0, -30, 0, -26);
    g.drawLine(-6, -30, 6, -30);
    if (color && outColor != null) g.setColor(outColor);
    g.drawLine(0, -4, 0, 0);
    g.setColor(baseColor);
    GraphicsUtil.switchToWidth(g, 2);
    if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
      int[] xp = {0, -5, 5, -5, 5, -5, 0};
      int[] yp = {-25, -23, -19, -15, -11, -7, -5};
      g.drawPolyline(xp, yp, xp.length);
    } else {
      g.drawRect(-5, -25, 10, 20);
    }
    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
  }
コード例 #11
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
 @Override
 public final void paintIcon(InstancePainter painter) {
   Graphics g = painter.getGraphics();
   g.setColor(Color.black);
   if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
     Icon iconRect = getIconRectangular();
     if (iconRect != null) {
       iconRect.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       paintIconRectangular(painter);
     }
   } else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
     Icon iconDin = getIconDin40700();
     if (iconDin != null) {
       iconDin.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       paintIconRectangular(painter);
     }
   } else {
     Icon iconShaped = getIconShaped();
     if (iconShaped != null) {
       iconShaped.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       paintIconShaped(painter);
     }
   }
 }
コード例 #12
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
 private void paintRectangularBase(Graphics g, InstancePainter painter) {
   GraphicsUtil.switchToWidth(g, 2);
   if (painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW) {
     g.drawRect(-20, -9, 14, 18);
     GraphicsUtil.drawCenteredText(g, RECT_LABEL, -13, 0);
     g.drawOval(-6, -3, 6, 6);
   } else {
     g.drawRect(-30, -9, 20, 18);
     GraphicsUtil.drawCenteredText(g, RECT_LABEL, -20, 0);
     g.drawOval(-10, -5, 9, 9);
   }
   GraphicsUtil.switchToWidth(g, 1);
 }
コード例 #13
0
ファイル: NotGate.java プロジェクト: pavelfatin/logisim
 //
 // painting methods
 //
 @Override
 public void paintIcon(InstancePainter painter) {
   Graphics g = painter.getGraphics();
   g.setColor(Color.black);
   if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
     if (toolIconRect != null) {
       toolIconRect.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       g.drawRect(0, 2, 16, 16);
       GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
       g.drawOval(16, 8, 4, 4);
     }
   } else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
     if (toolIconDin != null) {
       toolIconDin.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       g.drawRect(0, 2, 16, 16);
       GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
       g.drawOval(16, 8, 4, 4);
     }
   } else {
     if (toolIcon != null) {
       toolIcon.paintIcon(painter.getDestination(), g, 2, 2);
     } else {
       int[] xp = new int[4];
       int[] yp = new int[4];
       xp[0] = 15;
       yp[0] = 10;
       xp[1] = 1;
       yp[1] = 3;
       xp[2] = 1;
       yp[2] = 17;
       xp[3] = 15;
       yp[3] = 10;
       g.drawPolyline(xp, yp, 4);
       g.drawOval(15, 8, 4, 4);
     }
   }
 }
コード例 #14
0
ファイル: Ground.java プロジェクト: IsThisSparta/Logisim
 @Override
 public void paintInstance(InstancePainter painter) {
   drawInstance(painter, false);
   painter.drawPorts();
 }
コード例 #15
0
ファイル: Negator.java プロジェクト: jianc65/logisim
 @Override
 public void paintInstance(InstancePainter painter) {
   painter.drawBounds();
   painter.drawPort(IN);
   painter.drawPort(OUT, "-x", Direction.WEST);
 }
コード例 #16
0
ファイル: TransmissionGate.java プロジェクト: r0the/logisim
  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Bounds bds = painter.getBounds();
    Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    boolean flip =
        (facing == Direction.SOUTH || facing == Direction.WEST)
            == (powerLoc == Wiring.GATE_TOP_LEFT);

    int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
    if (flip) {
      degrees += 180;
    }

    double radians = Math.toRadians((degrees + 360) % 360);

    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
    g.translate(bds.getX(), bds.getY());
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    Color gate0 = g.getColor();
    Color gate1 = gate0;
    Color input = gate0;
    Color output = gate0;
    Color platform = gate0;
    if (!isGhost && painter.getShowState()) {
      gate0 = painter.getPort(GATE0).getColor();
      gate1 = painter.getPort(GATE0).getColor();
      input = painter.getPort(INPUT).getColor();
      output = painter.getPort(OUTPUT).getColor();
      platform = computeOutput(painter).getColor();
    }

    g.setColor(flip ? input : output);
    g.drawLine(0, 20, 11, 20);
    g.drawLine(11, 13, 11, 27);

    g.setColor(flip ? output : input);
    g.drawLine(29, 20, 40, 20);
    g.drawLine(29, 13, 29, 27);

    g.setColor(gate0);
    g.drawLine(20, 35, 20, 40);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawOval(18, 30, 4, 4);
    g.drawLine(10, 30, 30, 30);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);

    g.setColor(gate1);
    g.drawLine(20, 9, 20, 0);
    GraphicsUtil.switchToWidth(g, 1);
    g.drawLine(10, 10, 30, 10);

    g.setColor(platform);
    g.drawLine(9, 12, 31, 12);
    g.drawLine(9, 28, 31, 28);
    // arrow
    if (flip) {
      g.drawLine(18, 17, 21, 20);
      g.drawLine(18, 23, 21, 20);
    } else {
      g.drawLine(22, 17, 19, 20);
      g.drawLine(22, 23, 19, 20);
    }

    g.dispose();
  }
コード例 #17
0
ファイル: PullResistor.java プロジェクト: pavelfatin/logisim
 @Override
 public void paintGhost(InstancePainter painter) {
   Value pull = getPullValue(painter.getAttributeSet());
   paintBase(painter, pull, null, null);
 }
コード例 #18
0
ファイル: AbstractGate.java プロジェクト: EricStudley/logisim
  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();
  }