Package java.awt

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


    }
    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

  }
 
  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

    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

    Bounds bds = painter.getBounds();
    BitWidth dataWidth = painter.getAttributeValue(StdAttr.WIDTH);
    int width = dataWidth == null ? 8 : dataWidth.getWidth();
    int len = (width + 3) / 4;

    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    if (len > 4) {
      g.drawRect(bds.getX(), bds.getY() + 3, bds.getWidth(), 25);
    } else {
      int wid = 7 * len + 2;
      g.drawRect(bds.getX() + (bds.getWidth() - wid) / 2, bds.getY() + 4, wid, 15);
    }
    g.setColor(Color.BLACK);
  }
View Full Code Here

        g.fillRect(1, 1, 22, 22);
      }

      // draw tool icon
      g.setColor(Color.BLACK);
      Graphics g_copy = g.create();
      ComponentDrawContext c = new ComponentDrawContext(destination,
          null, null, g, g_copy);
      tool.paintIcon(c, 2, 2);
      g_copy.dispose();
    }
View Full Code Here

    setIconNames("nandGate.gif", "nandGateRect.gif", "dinNandGate.gif");
  }

  @Override
  public void paintIconShaped(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    int[] xp = new int[] { 8, 0, 0, 8 };
    int[] yp = new int[] { 2, 2, 18, 18 };
    g.drawPolyline(xp, yp, 4);
    GraphicsUtil.drawCenteredArc(g, 8, 10, 8, -90, 180);
    g.drawOval(16, 8, 4, 4);
  }
View Full Code Here

    return XorGate.FACTORY.getRectangularLabel(attrs);
  }
 
  @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,  -89, 16, -30, 60);
    GraphicsUtil.drawCenteredArc(g, -109, 16, -30, 60);
    g.drawOval(16, 8, 4, 4);
  }
View Full Code Here

    state.setPort(OUT, Value.createKnown(dataWidth, data.value), 4);
  }

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

    String text = attrs.getText();
    if (text == null || text.equals("")) return;
   
    int halign = attrs.getHorizontalAlign();
    int valign = attrs.getVerticalAlign();
    Graphics g = painter.getGraphics();
    Font old = g.getFont();
    g.setFont(attrs.getFont());
    GraphicsUtil.drawText(g, text, 0, 0, halign, valign);
   
    String textTrim = text.endsWith(" ") ? text.substring(0, text.length() - 1) : text;
    Bounds newBds;
    if (textTrim.equals("")) {
      newBds = Bounds.EMPTY_BOUNDS;
    } else {
      Rectangle bdsOut = GraphicsUtil.getTextBounds(g, textTrim, 0, 0,
          halign, valign);
      newBds = Bounds.create(bdsOut).expand(4);
    }
    if (attrs.setOffsetBounds(newBds)) {
      Instance instance = painter.getInstance();
      if (instance != null) instance.recomputeBounds();
    }
       
    g.setFont(old);
  }
View Full Code Here

TOP

Related Classes of java.awt.Graphics

Copyright © 2018 www.massapicom. 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.