Пример #1
0
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D copy = (Graphics2D) g.create();
   if (dragging) {
     copy.drawImage(imageBuffer, 0, 0, null);
     if (objectDragging == SelectedForm.LINE) {
       Line l = (Line) objectDragged;
       copy.setColor(l.getColor());
       copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
     } else if (objectDragging == SelectedForm.SQUARE) {
       Square sq = (Square) objectDragged;
       copy.setColor(sq.getColor());
       copy.drawRect(
           sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
     } else if (objectDragging == SelectedForm.CIRCLE) {
       Circle c = (Circle) objectDragged;
       copy.setColor(c.getColor());
       copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
     } else if (objectDragging == SelectedForm.POLYLINE) {
       Polyline poly = (Polyline) objectDragged;
       copy.setColor(poly.getColor());
       poly.fill();
       int[] XIS = poly.getX();
       int[] YSP = poly.getY();
       copy.drawPolyline(XIS, YSP, poly.getN());
       copy.drawLine(
           XIS[poly.getN() - 1], YSP[poly.getN() - 1], poly.getActualX(), poly.getActualY());
     }
   } else {
     copy.drawImage(imageBuffer, 0, 0, null);
   }
   copy.dispose();
 }
Пример #2
0
  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid || dataSize < 1) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);
    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    if (dataSize > 1) g.drawPolyline(xPoints, yPoints, dataSize);
    else g.drawLine(xPoints[0], yPoints[0], xPoints[0], yPoints[0]);

    if (bVertical) {
      if (bRight) {
        g.rotate(-deg90);
      } else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
Пример #3
0
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(Color.WHITE);
   g2.setStroke(STROKE_INNER);
   g2.drawPolyline(px, py, px.length);
 }
Пример #4
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
Пример #5
0
 public void drawPolyline(int[] polyline) {
   int nPoints = polyline.length / 2;
   int[] xPoints = new int[polyline.length / 2];
   int[] yPoints = new int[polyline.length / 2];
   for (int i = 0; i < nPoints; i++) {
     xPoints[i] = polyline[2 * i + 0] + xOffset;
     yPoints[i] = polyline[2 * i + 1] + yOffset;
   }
   gc.drawPolyline(xPoints, yPoints, nPoints);
 }
Пример #6
0
 /**
  * Render the graph
  *
  * @param g2d
  */
 public void render(Graphics2D g2d) {
   // changed graphics context
   if (g2d != oldG2d) {
     defaultStroke = g2d.getStroke();
     g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     oldG2d = g2d;
   }
   // render axes
   axes.render(g2d);
   // render graph line
   g2d.setColor(color);
   g2d.setStroke(stroke);
   g2d.drawPolyline(lineX, lineY, numPoints);
   g2d.setStroke(defaultStroke);
   // render pick line
   if ((pickX[0] > Axes.LEFT_MARGIN) && (pickX[0] < (width - Axes.RIGHT_MARGIN))) {
     g2d.setColor(pickColor);
     g2d.drawPolyline(pickX, pickY, 2);
   }
 }
Пример #7
0
  /** Draw poly line. */
  private void drawLine(int[]... coord) {
    int[] x = new int[coord.length];
    for (int i = 0; i < coord.length; i++) {
      x[i] = coord[i][0];
    }

    int[] y = new int[coord.length];
    for (int i = 0; i < coord.length; i++) {
      y[i] = coord[i][1];
    }

    g2d.drawPolyline(x, y, coord.length);
  }
Пример #8
0
 @Override
 /**
  * ************************************************************************** paint Function
  * Function paints a Polyline to the screen using the java SWING library
  * **************************************************************************
  */
 public void paint(Graphics g) {
   // TODO Auto-generated method stub
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(this.strokeColor);
   g2.drawPolyline(this.xPoints, this.yPoints, this.nPoints);
 }
Пример #9
0
  private void renderPolyLine(Graphics2D g2) {

    // Iterate through the associated polygon and draw lines from
    // point to point; this will bypass the associated errors in using
    // a generalPath, too. Because it's a polyline, the object isn't
    // closed, and we don't do anything for fills.

    Polygon2D p = (Polygon2D) baseShape;
    int[] newX = new int[p.npoints];
    int[] newY = new int[p.npoints];
    for (int loop = 0; loop < p.npoints; loop++) {
      newX[loop] = (int) Math.round(p.xpoints[loop]);
      newY[loop] = (int) Math.round(p.ypoints[loop]);
    }
    g2.drawPolyline(newX, newY, p.npoints);
  }
  private void drawPaths() {
    if (!doShowPaths) return;

    Color tempColor;
    Set<String> playerNames = ((CTWorld) Simulator.pworld).getPlayerNames();
    Iterator<String> iterator = playerNames.iterator();

    // Draw paths
    PolylinePath tempPolylinePath;
    while (iterator.hasNext()) {
      String name = (String) iterator.next();
      if (agentPathExists(name)) {
        tempPolylinePath = getAgentPolyline(name);
        tempColor = getColor(((CTWorld) Simulator.pworld).getPlayerColour(name));
        ((Graphics2D) backBuffer).setStroke(new BasicStroke(2.0f));
        ((Graphics2D) backBuffer).setColor(tempColor);
        ((Graphics2D) backBuffer)
            .drawPolyline(tempPolylinePath.x, tempPolylinePath.y, tempPolylinePath.x.length);
      }
    }
    return;
  }
Пример #11
0
 public void draw(SelectedForm type, Object form) {
   Graphics2D copy = imageBuffer.createGraphics();
   if (antiAliasing && type != SelectedForm.POLYLINE)
     copy.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (type == SelectedForm.LINE) {
     Line l = (Line) form;
     copy.setColor(l.getColor());
     copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
   } else if (type == SelectedForm.SQUARE) {
     Square sq = (Square) form;
     copy.setColor(sq.getColor());
     copy.drawRect(sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
   } else if (type == SelectedForm.CIRCLE) {
     Circle c = (Circle) form;
     copy.setColor(c.getColor());
     copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
   } else if (type == SelectedForm.ERASER) {
     Eraser e = (Eraser) form;
     e.adjustPreferedSize(e.getP1());
     copy.fillOval(e.getP1().x, e.getP1().y, e.getSize(), e.getSize());
   } else if (type == SelectedForm.CANPAINT) {
     CanPaint cp = (CanPaint) form;
     floodFill(cp.getP().x, cp.getP().y, cp.getActualColor(), cp.getReplacementColor());
   } else if (type == SelectedForm.POLYLINE) {
     Polyline poly = (Polyline) form;
     copy.setColor(poly.getColor());
     poly.fill();
     int[] XIS = poly.getX();
     int[] YSP = poly.getY();
     copy.drawPolyline(XIS, YSP, poly.getN());
   } else if (type == SelectedForm.PEN) {
     Pen pen = (Pen) form;
     copy.setColor(pen.getColor());
     copy.drawLine(pen.getP1().x, pen.getP1().y, pen.getP2().x, pen.getP2().y);
   }
   copy.dispose();
   repaint();
 }
Пример #12
0
  @Override
  public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    int width = mv.getWidth();
    int height = mv.getHeight();
    Rectangle clip = g.getClipBounds();
    if (useThumbs) {
      if (!thumbsLoaded) {
        startLoadThumbs();
      }

      if (null == offscreenBuffer
          || offscreenBuffer.getWidth() != width // reuse the old buffer if possible
          || offscreenBuffer.getHeight() != height) {
        offscreenBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        updateOffscreenBuffer = true;
      }

      if (updateOffscreenBuffer) {
        Graphics2D tempG = offscreenBuffer.createGraphics();
        tempG.setColor(new Color(0, 0, 0, 0));
        Composite saveComp = tempG.getComposite();
        tempG.setComposite(AlphaComposite.Clear); // remove the old images
        tempG.fillRect(0, 0, width, height);
        tempG.setComposite(saveComp);

        if (data != null) {
          for (ImageEntry e : data) {
            if (e.getPos() == null) {
              continue;
            }
            Point p = mv.getPoint(e.getPos());
            if (e.hasThumbnail()) {
              Dimension d = scaledDimension(e.getThumbnail());
              Rectangle target =
                  new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
              if (clip.intersects(target)) {
                tempG.drawImage(
                    e.getThumbnail(), target.x, target.y, target.width, target.height, null);
              }
            } else { // thumbnail not loaded yet
              icon.paintIcon(
                  mv, tempG, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2);
            }
          }
        }
        updateOffscreenBuffer = false;
      }
      g.drawImage(offscreenBuffer, 0, 0, null);
    } else if (data != null) {
      for (ImageEntry e : data) {
        if (e.getPos() == null) {
          continue;
        }
        Point p = mv.getPoint(e.getPos());
        icon.paintIcon(mv, g, p.x - icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2);
      }
    }

    if (currentPhoto >= 0 && currentPhoto < data.size()) {
      ImageEntry e = data.get(currentPhoto);

      if (e.getPos() != null) {
        Point p = mv.getPoint(e.getPos());

        int imgWidth;
        int imgHeight;
        if (useThumbs && e.hasThumbnail()) {
          Dimension d = scaledDimension(e.getThumbnail());
          imgWidth = d.width;
          imgHeight = d.height;
        } else {
          imgWidth = selectedIcon.getIconWidth();
          imgHeight = selectedIcon.getIconHeight();
        }

        if (e.getExifImgDir() != null) {
          // Multiplier must be larger than sqrt(2)/2=0.71.
          double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85);
          double arrowwidth = arrowlength / 1.4;

          double dir = e.getExifImgDir();
          // Rotate 90 degrees CCW
          double headdir = (dir < 90) ? dir + 270 : dir - 90;
          double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90;
          double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90;

          double ptx = p.x + Math.cos(Math.toRadians(headdir)) * arrowlength;
          double pty = p.y + Math.sin(Math.toRadians(headdir)) * arrowlength;

          double ltx = p.x + Math.cos(Math.toRadians(leftdir)) * arrowwidth / 2;
          double lty = p.y + Math.sin(Math.toRadians(leftdir)) * arrowwidth / 2;

          double rtx = p.x + Math.cos(Math.toRadians(rightdir)) * arrowwidth / 2;
          double rty = p.y + Math.sin(Math.toRadians(rightdir)) * arrowwidth / 2;

          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setColor(new Color(255, 255, 255, 192));
          int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx};
          int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty};
          g.fillPolygon(xar, yar, 4);
          g.setColor(Color.black);
          g.setStroke(new BasicStroke(1.2f));
          g.drawPolyline(xar, yar, 3);
        }

        if (useThumbs && e.hasThumbnail()) {
          g.setColor(new Color(128, 0, 0, 122));
          g.fillRect(p.x - imgWidth / 2, p.y - imgHeight / 2, imgWidth, imgHeight);
        } else {
          selectedIcon.paintIcon(mv, g, p.x - imgWidth / 2, p.y - imgHeight / 2);
        }
      }
    }
  }
Пример #13
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension size = getSize();
    // Limit the minimum size of coordinate system
    if (size.height < MIN_COORD_AXIS.height) size.height = MIN_COORD_AXIS.height;
    if (size.width < MIN_COORD_AXIS.width) size.width = MIN_COORD_AXIS.width;

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Draw coordinate
    g2.setPaint(Color.BLACK);
    final int AXIS_HEIGHT = size.height - TOP_SPACE - BOTTOM_SPACE;
    final int AXIS_WIDTH = size.width - RIGHT_SPACE - LEFT_SPACE;
    // Draw axis Y
    g2.draw(new Line2D.Float(LEFT_SPACE, TOP_SPACE, LEFT_SPACE, AXIS_HEIGHT));
    // Draw axis X
    g2.draw(new Line2D.Float(LEFT_SPACE, AXIS_HEIGHT, AXIS_WIDTH, AXIS_HEIGHT));
    // Draw coordinate arrows
    // Y coordinate arrow
    g2.draw(
        new Line2D.Float(
            LEFT_SPACE, TOP_SPACE, LEFT_SPACE + ARROW_HALF_WIDTH, TOP_SPACE + ARROW_LENGTH));
    g2.draw(
        new Line2D.Float(
            LEFT_SPACE, TOP_SPACE, LEFT_SPACE - ARROW_HALF_WIDTH, TOP_SPACE + ARROW_LENGTH));
    // X coordinate arrow
    g2.draw(
        new Line2D.Float(
            AXIS_WIDTH, AXIS_HEIGHT, AXIS_WIDTH - ARROW_LENGTH, AXIS_HEIGHT + ARROW_HALF_WIDTH));
    g2.draw(
        new Line2D.Float(
            AXIS_WIDTH, AXIS_HEIGHT, AXIS_WIDTH - ARROW_LENGTH, AXIS_HEIGHT - ARROW_HALF_WIDTH));
    // Draw scale
    // Scale Y
    final int nInternalSpaceY = (AXIS_HEIGHT - ARROW_LENGTH) / (PanelCoverage.m_nScaleNumber + 2);
    for (int i = 1; i < PanelCoverage.m_nScaleNumber + 1; i++) {
      int nScalePos = AXIS_HEIGHT - i * nInternalSpaceY;
      if (i % 2 == 0) {
        g2.draw(
            new Line2D.Float(LEFT_SPACE, nScalePos, LEFT_SPACE + SCALE_LARGE_LENGTH, nScalePos));
        g2.drawString(Integer.toString(i / 2 * 10) + "%", STRING_Y_AXIS_LEFT_PADDING, nScalePos);
      } else
        g2.draw(
            new Line2D.Float(LEFT_SPACE, nScalePos, LEFT_SPACE + SCALE_SHORT_LENGTH, nScalePos));
    }
    // Scale X
    final int nWalkLength = TestExeModel.getWalkLength();

    if (this.m_arrayStages == null) computeStages(nWalkLength);

    final int internalSpaceX = (AXIS_WIDTH - ARROW_LENGTH) / (PanelCoverage.m_nScaleNumber + 1);
    int[] arrayScaleXPos = new int[m_arrayStages.length];
    int[] arraySScaleYPos = new int[m_arrayStages.length];
    int[] arrayTScaleYPos = new int[m_arrayStages.length];
    int[] arrayTPScaleYPos = new int[m_arrayStages.length];
    int[] arrayAScaleYPos = new int[m_arrayStages.length];
    final int AXIS_Y_LENGTH = AXIS_HEIGHT - TOP_SPACE - ARROW_LENGTH;
    for (int i = 0; i < m_arrayStages.length; i++) {
      int nScaleposY = AXIS_HEIGHT;
      int nScaleposX = LEFT_SPACE + (i + 1) * internalSpaceX;
      if (i % 2 != 0)
        g2.draw(
            new Line2D.Float(nScaleposX, nScaleposY - SCALE_LARGE_LENGTH, nScaleposX, nScaleposY));
      else
        g2.draw(
            new Line2D.Float(nScaleposX, nScaleposY - SCALE_SHORT_LENGTH, nScaleposX, nScaleposY));
      arrayScaleXPos[i] = nScaleposX;
      if (isCoverageDrawable(i)) {
        arraySScaleYPos[i] =
            (int) ((double) AXIS_HEIGHT - ((double) AXIS_Y_LENGTH * m_covS.get(i) / 100.0));
        arrayTScaleYPos[i] =
            (int) ((double) AXIS_HEIGHT - ((double) AXIS_Y_LENGTH * m_covT.get(i) / 100.0));
        arrayTPScaleYPos[i] =
            (int) ((double) AXIS_HEIGHT - ((double) AXIS_Y_LENGTH * m_covTP.get(i) / 100.0));
        arrayAScaleYPos[i] =
            (int) ((double) AXIS_HEIGHT - ((double) AXIS_Y_LENGTH * m_covA.get(i) / 100.0));
      }
      // Draw scale text
      g2.drawString(Integer.toString(m_arrayStages[i]), nScaleposX, nScaleposY + 16);
    }
    // System.out.println(isCoverageDrawable(i));
    if (isCoverageDrawable(1)) {
      arraySScaleYPos[0] =
          arrayTScaleYPos[0] = arrayTPScaleYPos[0] = arrayAScaleYPos[0] = AXIS_HEIGHT;
      arrayScaleXPos[0] = LEFT_SPACE;
      // Draw line chart for state coverage
      boolean[] bShowCoverage = Parameter.getCoverageOption();

      // State coverage
      if (bShowCoverage[0]) {
        g2.setColor(Color.BLACK);
        g2.drawPolyline(arrayScaleXPos, arraySScaleYPos, m_covS.size());
      }
      // Transition coverage
      if (bShowCoverage[1]) {
        g2.setColor(Color.ORANGE);
        g2.drawPolyline(arrayScaleXPos, arrayTScaleYPos, m_covT.size());
      }
      // Transition pair coverage
      if (bShowCoverage[2]) {
        g2.setColor(Color.CYAN);
        g2.drawPolyline(arrayScaleXPos, arrayTPScaleYPos, m_covTP.size());
      }
      // Action coverage
      if (bShowCoverage[3]) {
        g2.setColor(Color.YELLOW);
        g2.drawPolyline(arrayScaleXPos, arrayAScaleYPos, m_covA.size());
      }
    }
  }
Пример #14
0
	/**
	 * @param g2
	 * @throws IOException
	 */
	private void drawTransition(Map<String, Node> nodes, Graphics2D g2) throws IOException {
		g2.setStroke(DEFAULT_LINE_STROKE);
		g2.setColor(DEFAULT_LINE_STROKE_COLOR);
		for (Node node : nodes.values()) {
			for (Transition transition : node.getTransitions()) {
				String to = transition.getTo();
				Node toNode = nodes.get(to);
				List<Point> trace = new LinkedList<Point>(transition.getLineTrace());
				int len = trace.size() + 2;
				trace.add(0, new Point(node.getCenterX(), node.getCenterY()));
				trace.add(new Point(toNode.getCenterX(), toNode.getCenterY()));
				int[] xPoints = new int[len];
				int[] yPoints = new int[len];
				for (int i = 0; i < len; i++) {
					xPoints[i] = trace.get(i).x;
					yPoints[i] = trace.get(i).y;
				}
				final int taskGrow = 4;
				final int smallGrow = -2;
				int grow = 0;
				if (nodeInfos.get(node.getType()) != null) {
					grow = smallGrow;
				} else {
					grow = taskGrow;
				}
				Point p = GeometryUtils.getRectangleLineCrossPoint(node.getRectangle(), new Point(xPoints[1],
						yPoints[1]), grow);
				if (p != null) {
					xPoints[0] = p.x;
					yPoints[0] = p.y;
				}
				if (nodeInfos.get(toNode.getType()) != null) {
					grow = smallGrow;
				} else {
					grow = taskGrow;
				}
				p = GeometryUtils.getRectangleLineCrossPoint(toNode.getRectangle(), new Point(xPoints[len - 2],
						yPoints[len - 2]), grow);
				if (p != null) {
					xPoints[len - 1] = p.x;
					yPoints[len - 1] = p.y;
				}
				g2.drawPolyline(xPoints, yPoints, len);
				drawArrow(g2, xPoints[len - 2], yPoints[len - 2], xPoints[len - 1], yPoints[len - 1]);
				String label = transition.getLabel();
				if (label != null && label.length() > 0) {
					int cx, cy;
					if (len % 2 == 0) {
						cx = (xPoints[len / 2 - 1] + xPoints[len / 2]) / 2;
						cy = (yPoints[len / 2 - 1] + yPoints[len / 2]) / 2;
					} else {
						cx = xPoints[len / 2];
						cy = yPoints[len / 2];
					}
					Point labelPoint = transition.getLabelPosition();
					if (labelPoint != null) {
						cx += labelPoint.x;
						cy += labelPoint.y;
					}
					cy -= RECT_OFFSET_Y + RECT_OFFSET_Y / 2;
					g2.drawString(label, cx, cy);
				}
			}
		}
	}
Пример #15
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);

    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }

    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    g.setColor(Color.yellow);
    for (int i = 0; i < starNum; i++) {
      if (!GameOver)
        drawStar(getX(star[i].getXPos()), getYNormal(star[i].getYPos()), 0.0, 1.0, 1.0);
    }

    g.setColor(Color.white);
    for (int i = 0; i < missle.length; i++) {
      if (missle[i].getActive() && !GameOver) {

        drawCircle(
            getX(missle[i].getXPos()),
            getYNormal(missle[i].getYPos()),
            0.0,
            1.0,
            1.0,
            missle[i].getWidth());
      }
    }
    if (!GameOver) {
      if (!rocketRight)
        drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, 1.0, 1.0);
      else drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, -1.0, 1.0);
    }
    if (ff) {
      drawCircle(getX(rocketXPos), getYNormal(rocketYPos), 0, ffsize, ffsize, ffwidth);
    }

    g.setColor(Color.BLACK);
    g.drawString("Lives: " + lives, 115, 43);
    g.drawString("Score: " + score, 50, 43);

    if (GameOver) {
      g.setColor(Color.WHITE);
      g.drawString("GAMEOVER", getWidth2() / 2, getHeight2() / 2);
      g.drawString("HighScore: " + highscore, getWidth2() / 2, getHeight2() / 2 - 20);
    }

    gOld.drawImage(image, 0, 0, null);
  }
Пример #16
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
Пример #17
0
 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
   g2d.drawPolyline(xPoints, yPoints, nPoints);
 }
 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
   hostGraphics.drawPolyline(xPoints, yPoints, nPoints);
 }