Examples of Graphics


Examples of java.awt.Graphics

    public int print(Graphics base, PageFormat format, int pageIndex) {
      if (pageIndex >= circuits.size()) return Printable.NO_SUCH_PAGE;
     
      Circuit circ = circuits.get(pageIndex);
      CircuitState circState = proj.getCircuitState(circ);
      Graphics g = base.create();
      Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
      FontMetrics fm = g.getFontMetrics();
      String head = (header != null && !header.equals(""))
        ? format(header, pageIndex + 1, circuits.size(),
            circ.getName())
        : null;
      int headHeight = (head == null ? 0 : fm.getHeight());

      // Compute image size
      double imWidth = format.getImageableWidth();
      double imHeight = format.getImageableHeight();
     
      // Correct coordinate system for page, including
      // translation and possible rotation.
      Bounds bds = circ.getBounds(g).expand(4);
      double scale = Math.min(imWidth / bds.getWidth(),
          (imHeight - headHeight) / bds.getHeight());
      if (g2 != null) {
        g2.translate(format.getImageableX(), format.getImageableY());
        if (rotateToFit && scale < 1.0 / 1.1) {
          double scale2 = Math.min(imHeight / bds.getWidth(),
              (imWidth - headHeight) / bds.getHeight());
          if (scale2 >= scale * 1.1) { // will rotate
            scale = scale2;
            if (imHeight > imWidth) { // portrait -> landscape
              g2.translate(0, imHeight);
              g2.rotate(-Math.PI / 2);
            } else { // landscape -> portrait
              g2.translate(imWidth, 0);
              g2.rotate(Math.PI / 2);
            }
            double t = imHeight;
            imHeight = imWidth;
            imWidth = t;
          }
        }
      }
     
      // Draw the header line if appropriate
      if (head != null) {
        g.drawString(head,
            (int) Math.round((imWidth - fm.stringWidth(head)) / 2),
            fm.getAscent());
        if (g2 != null) {
          imHeight -= headHeight;
          g2.translate(0, headHeight);
        }
      }
     
      // Now change coordinate system for circuit, including
      // translation and possible scaling
      if (g2 != null) {
        if (scale < 1.0) {
          g2.scale(scale, scale);
          imWidth /= scale;
          imHeight /= scale;
        }
        double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
        g2.translate(-bds.getX() + dx, -bds.getY());
      }
     
      // Ensure that the circuit is eligible to be drawn
      Rectangle clip = g.getClipBounds();
      clip.add(bds.getX(), bds.getY());
      clip.add(bds.getX() + bds.getWidth(),
          bds.getY() + bds.getHeight());
      g.setClip(clip);
     
      // And finally draw the circuit onto the page
      ComponentDrawContext context = new ComponentDrawContext(
          proj.getFrame().getCanvas(), circ, circState,
          base, g, printerView);
      Collection<Component> noComps = Collections.emptySet();
      circ.draw(context, noComps);
      g.dispose();
      return Printable.PAGE_EXISTS;
    }
View Full Code Here

Examples of java.awt.Graphics

    HashMap<CircuitState,CircuitState> stateMap = new HashMap<CircuitState,CircuitState>();
    for (CircuitState s : state.getSubstates()) {
      addSubstates(stateMap, s, s);
    }
   
    Graphics g = context.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    for (Entry e : data) {
      if (e.state == state) {
        Location p = e.loc;
        g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
      } else if (stateMap.containsKey(e.state)) {
        CircuitState substate = stateMap.get(e.state);
        Component subcirc = substate.getSubcircuit();
        Bounds b = subcirc.getBounds();
        g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
      }
    }
    GraphicsUtil.switchToWidth(g, 1);
  }
View Full Code Here

Examples of java.awt.Graphics

    }
    Location offset = findAnchorLocation();
    g.translate(-offset.getX(), -offset.getY());
    for (CanvasObject shape : getObjectsFromBottom()) {
      if (!(shape instanceof AppearanceElement)) {
        Graphics dup = g.create();
        shape.paint(dup, null);
        dup.dispose();
      }
    }
    g.translate(offset.getX(), offset.getY());
    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
View Full Code Here

Examples of java.awt.Graphics

    setPaintInputLines(true);
  }

  @Override
  public void paintIconShaped(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    GraphicsUtil.drawCenteredArc(g,   0, -5, 22, -9053);
    GraphicsUtil.drawCenteredArc(g,   0, 23, 2290, -53);
    GraphicsUtil.drawCenteredArc(g, -129, 16, -30, 60);
    g.drawOval(16, 8, 4, 4);
  }
View Full Code Here

Examples of java.awt.Graphics

    state.setPort(CARRY, carry ? Value.TRUE : Value.FALSE, DELAY);
  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    RegisterData state = (RegisterData) painter.getData();
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();

    // determine text to draw in label
    String a;
    String b = null;
    if (painter.getShowState()) {
      int val = state == null ? 0 : state.value;
      String str = StringUtil.toHexString(width, val);
      if (str.length() <= 4) {
        a = str;
      } else {
        int split = str.length() - 4;
        a = str.substring(0, split);
        b = str.substring(split);
      }
    } else {
      a = Strings.get("counterLabel");
      b = Strings.get("registerWidthLabel", "" + widthVal.getWidth());
    }

    // draw boundary, label
    painter.drawBounds();
    painter.drawLabel();

    // draw input and output ports
    if (b == null) {
      painter.drawPort(IN,  "D", Direction.EAST);
      painter.drawPort(OUT, "Q", Direction.WEST);
    } else {
      painter.drawPort(IN);
      painter.drawPort(OUT);
    }
    g.setColor(Color.GRAY);
    painter.drawPort(LD);
    painter.drawPort(CARRY);
    painter.drawPort(CLR, "0", Direction.SOUTH);
    painter.drawPort(CT, Strings.get("counterEnableLabel"), Direction.EAST);
    g.setColor(Color.BLACK);
    painter.drawClock(CK, Direction.NORTH);

    // draw contents
    if (b == null) {
      GraphicsUtil.drawText(g, a, bds.getX() + 15, bds.getY() + 4,
View Full Code Here

Examples of java.awt.Graphics

        facing.reverse(), select.getWidth() == 1 ? 10 : 20);
  }

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
    int outputs = 1 << select.getWidth();

    // draw stubs for select and enable ports
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      Location pt = painter.getInstance().getPortLocation(outputs);
      g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      int len = outputs == 2 ? 6 : 4;
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
   
    // draw "0"
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = 3;
      y0 = 15;
      halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
      x0 = 10;
      y0 = 15;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = 10;
      y0 = bds.getHeight() - 3;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getWidth() - 3;
      y0 = 15;
      halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0,
        halign, GraphicsUtil.V_BASELINE);
   
    // draw trapezoid, "Decd", and ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing.reverse(), outputs == 2 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "Decd",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
View Full Code Here

Examples of java.awt.Graphics

    if (!painter.shouldDrawColor()) {
      int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
      color = new Color(hue, hue, hue);
    }
   
    Graphics g = painter.getGraphics();
    int depress;
    if (val == Value.TRUE) {
      x += DEPTH;
      y += DEPTH;
      Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC);
      if (labelLoc == Io.LABEL_CENTER || labelLoc == Direction.NORTH
          || labelLoc == Direction.WEST) {
        depress = DEPTH;
      } else {
        depress = 0;
      }
     
      Object facing = painter.getAttributeValue(StdAttr.FACING);
      if (facing == Direction.NORTH || facing == Direction.WEST) {
        Location p = painter.getLocation();
        int px = p.getX();
        int py = p.getY();
        GraphicsUtil.switchToWidth(g, Wire.WIDTH);
        g.setColor(Value.TRUE_COLOR);
        if (facing == Direction.NORTH) g.drawLine(px, py, px, py + 10);
        else                          g.drawLine(px, py, px + 10, py);
        GraphicsUtil.switchToWidth(g, 1);
      }
     
      g.setColor(color);
      g.fillRect(x, y, w - DEPTH, h - DEPTH);
      g.setColor(Color.BLACK);
      g.drawRect(x, y, w - DEPTH, h - DEPTH);
    } else {
      depress = 0;
      int[] xp = new int[] { x, x + w - DEPTH, x + w, x + w, x + DEPTH, x };
      int[] yp = new int[] { y, y, y + DEPTH, y + h, y + h, y + h - DEPTH };
      g.setColor(color.darker());
      g.fillPolygon(xp, yp, xp.length);
      g.setColor(color);
      g.fillRect(x, y, w - DEPTH, h - DEPTH);
      g.setColor(Color.BLACK);
      g.drawRect(x, y, w - DEPTH, h - DEPTH);
      g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
      g.drawPolygon(xp, yp, xp.length);
    }
   
    g.translate(depress, depress);
    g.setColor(painter.getAttributeValue(Io.ATTR_LABEL_COLOR));
    painter.drawLabel();
    g.translate(-depress, -depress);
    painter.drawPorts();
  }
View Full Code Here

Examples of java.awt.Graphics

    }
    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);
    } else { // SHAPE_SHAPED
      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();
  }
View Full Code Here

Examples of java.awt.Graphics

  }
 
  protected abstract void paintIconShaped(InstancePainter painter);
 
  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);
  }
View Full Code Here

Examples of java.awt.Graphics

    GraphicsUtil.drawCenteredText(g, label, 9, 8);
  }

  @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 {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.