Examples of Graphics


Examples of java.awt.Graphics

  // user interface methods
  //
  @Override
  public void drawGhost(ComponentDrawContext context,
      Color color, int x, int y, AttributeSet attrs) {
    Graphics g = context.getGraphics();
    Object dir = attrs.getValue(Wire.dir_attr);
    int len = attrs.getValue(Wire.len_attr).intValue();

    g.setColor(color);
    GraphicsUtil.switchToWidth(g, 3);
    if (dir == Wire.VALUE_HORZ) {
      g.drawLine(x, y, x + len, y);
    } else {
      g.drawLine(x, y, x, y + len);
    }
  }
View Full Code Here

Examples of java.awt.Graphics

  //
  // user interface features
  // 
  @Override
  public void paintGhost(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Color fg = g.getColor();
    int v = fg.getRed() + fg.getGreen() + fg.getBlue();
    Composite oldComposite = null;
    if (g instanceof Graphics2D && v > 50) {
      oldComposite = ((Graphics2D) g).getComposite();
      Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
View Full Code Here

Examples of java.awt.Graphics

        back = label.indexOf('\\', back + 2);
      }
     
      int x = bds.getX() + bds.getWidth() / 2;
      int y = bds.getY() + bds.getHeight() / 2;
      Graphics g = painter.getGraphics().create();
      double angle = Math.PI / 2 - (up.toRadians() - defaultFacing.toRadians()) - facing.toRadians();
      if (g instanceof Graphics2D && Math.abs(angle) > 0.01) {
        Graphics2D g2 = (Graphics2D) g;
        g2.rotate(angle, x, y);
      }
      g.setFont(font);
      if (lines == 1 && !backs) {
        GraphicsUtil.drawCenteredText(g, label, x, y);
      } else {
        FontMetrics fm = g.getFontMetrics();
        int height = fm.getHeight();
        y = y - (height * lines - fm.getLeading()) / 2 + fm.getAscent();
        back = label.indexOf('\\');
        while (back >= 0 && back <= label.length() - 2) {
          char c = label.charAt(back + 1);
          if (c == 'n') {
            String line = label.substring(0, back);
            GraphicsUtil.drawText(g, line, x, y,
                GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
            y += height;
            label = label.substring(back + 2);
            back = label.indexOf('\\');
          } else if (c == '\\') {
            label = label.substring(0, back) + label.substring(back + 1);
            back = label.indexOf('\\', back + 1);
          } else {
            back = label.indexOf('\\', back + 2);
          }
        }
        GraphicsUtil.drawText(g, label, x, y,
            GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
      }
      g.dispose();
    }
  }
View Full Code Here

Examples of java.awt.Graphics

    }
  }

  @Override
  public void paintIcon(ComponentDrawContext c, int x, int y) {
    Graphics g = c.getGraphics();
    g.fillRect(x + 2, y + 1, 9, 2);
    g.drawRect(x + 2, y + 3, 15, 12);
    g.setColor(Color.lightGray);
    g.drawLine(x + 4, y + 2, x + 8, y + 2);
    for (int y_offs = y + 6; y_offs < y + 15; y_offs += 3) {
      g.drawLine(x + 4, y_offs, x + 14, y_offs);
    }
  }
View Full Code Here

Examples of java.awt.Graphics

          if (label == null || label.equals("")) {
            y += bds.getHeight() / 2;
          } else {
            y += 3 * bds.getHeight() / 4;
          }
          Graphics g = painter.getGraphics();
          for (int i = 0; i < len; i++) {
            String s = data.get(len - 1 - i).toHexString();
            GraphicsUtil.drawCenteredText(g, s, x, y);
            x += 10;
          }
        }
      } else {
        Bounds bds = painter.getBounds();
        int x = bds.getX() + bds.getWidth() / 2;
        int y = bds.getY();
        int h = bds.getHeight();
        Graphics g = painter.getGraphics();
        Object label = painter.getAttributeValue(StdAttr.LABEL);
        if (label == null || label.equals("")) {
          String a = Strings.get("shiftRegisterLabel1");
          GraphicsUtil.drawCenteredText(g, a, x, y + h / 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);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();

    // draw select and enable inputs
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      Location sel = painter.getInstance().getPortLocation(outputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      int len = outputs == 2 ? 6 : 4;
      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" next to first input
    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, "DMX" label, and ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing.reverse(), select.getWidth() == 1 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "DMX",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
View Full Code Here

Examples of java.awt.Graphics

    State data = getState(painter);
    long ticks = painter.getTickCount();
    Bounds bds = painter.getBounds();
    boolean showState = painter.getShowState();
    Graphics g = painter.getGraphics();
    int rows = data.rows;
    int cols = data.cols;
    for (int j = 0; j < rows; j++) {
      for (int i = 0; i < cols; i++) {
        int x = bds.getX() + 10 * i;
        int y = bds.getY() + 10 * j;
        if (showState) {
          Value val = data.get(j, i, ticks);
          Color c;
          if (val == Value.TRUE) c = onColor;
          else if (val == Value.FALSE) c = offColor;
          else c = Value.ERROR_COLOR;
          g.setColor(c);
         
          if (drawSquare) g.fillRect(x, y, 10, 10);
          else g.fillOval(x + 1, y + 1, 8, 8);
        } else {
          g.setColor(Color.GRAY);
          g.fillOval(x + 1, y + 1, 8, 8);
        }
      }
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 2);
    g.drawRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawPorts();
  }
View Full Code Here

Examples of java.awt.Graphics

    paintShape(painter);
  }

  @Override
  public void paintIcon(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Icon icon = isInverter ? ICON_INVERTER : ICON_BUFFER;
    if (icon != null) {
      icon.paintIcon(painter.getDestination(), g, 2, 2);
    } else {
      int x = isInverter ? 0 : 2;
      g.setColor(Color.BLACK);
      int[] xp = new int[] { x + 15, x + 1, x + 1, x + 15 };
      int[] yp = new int[] { 10,     3,     17,    10 };
      g.drawPolyline(xp, yp, 4);
      if (isInverter) g.drawOval(x + 13, 8, 4, 4);
      g.setColor(Value.FALSE_COLOR);
      g.drawLine(x + 8, 14, x + 8, 18);
    }
  }
View Full Code Here

Examples of java.awt.Graphics

  @Override
  public void paintInstance(InstancePainter painter) {
    Direction face = painter.getAttributeValue(StdAttr.FACING);

    Graphics g = painter.getGraphics();

    // draw control wire
    GraphicsUtil.switchToWidth(g, 3);
    Location pt0 = painter.getInstance().getPortLocation(2);
    Location pt1;
    if (painter.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
      pt1 = pt0.translate(face, 0, 6);
    } else {
      pt1 = pt0.translate(face, 0, -6);
    }
    if (painter.getShowState()) {
      g.setColor(painter.getPort(2).getColor());
    }
    g.drawLine(pt0.getX(), pt0.getY(), pt1.getX(), pt1.getY());

    // draw triangle
    g.setColor(Color.BLACK);
    paintShape(painter);

    // draw input and output pins
    if (!painter.isPrintView()) {
      painter.drawPort(0);
View Full Code Here

Examples of java.awt.Graphics

    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    double rotate = 0.0;
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    if (facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      ((Graphics2D) g).rotate(rotate);
    }

    if (isInverter) {
      PainterShaped.paintNot(painter);
    } else {
      GraphicsUtil.switchToWidth(g, 2);
      int d = isInverter ? 10 : 0;
      int[] xp = new int[] { -d, -19 - d, -19 - d, -d };
      int[] yp = new int[] {  0,  -7,       7,      0 };
      g.drawPolyline(xp, yp, 4);
      // if (isInverter) g.drawOval(-9, -4, 9, 9);
    }
   
    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
  }
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.