示例#1
0
 private Path2D.Double makeStar(int r1, int r2, int vc) {
   int or = Math.max(r1, r2);
   int ir = Math.min(r1, r2);
   double agl = 0d;
   double add = 2 * Math.PI / (vc * 2);
   Path2D.Double p = new Path2D.Double();
   p.moveTo(or * 1, or * 0);
   for (int i = 0; i < vc * 2 - 1; i++) {
     agl += add;
     int r = i % 2 == 0 ? ir : or;
     p.lineTo(r * Math.cos(agl), r * Math.sin(agl));
   }
   p.closePath();
   AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2, or, 0);
   return new Path2D.Double(p, at);
 }
示例#2
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

    // Si hay que rotar la fuente, se rota
    Font f = g.getFont();
    if (orientation == SwingConstants.VERTICAL) {
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      f = f.deriveFont(rotate);
    }

    // Si hay que pintar sombra, se hacen un monton de cosas
    if (shadow != null) {
      int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g);

      int w, h;
      if (orientation == SwingConstants.HORIZONTAL) {
        w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      } else {
        h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      }

      // La sombra del titulo
      BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = iTitulo.createGraphics();
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      g2.setFont(f);
      g2.setColor(shadow);
      g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro

      ConvolveOp cop =
          new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null);
      cop.filter(iTitulo, iSombra); // A ditorsionar

      // Por fin, pintamos el jodio titulo
      g.drawImage(
          iSombra,
          x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1
          y - 3 * matrix + desp, // para que la sombra quede pelin desplazada
          null);
    }

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }
示例#3
0
  public Shape getShape() {

    int R = Integer.parseInt(hexcolor.substring(0, 2), 16);
    int G = Integer.parseInt(hexcolor.substring(2, 4), 16);
    int B = Integer.parseInt(hexcolor.substring(4, 6), 16);
    color = new Color(R, G, B);

    Shape geom;
    if (shape.equals("circle")) {
      geom = new Ellipse2D.Float(-0.05f * size, -0.05f * size, 1.1f * size, 1.1f * size);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("square")) {
      geom = new Rectangle2D.Float(0, 0, size, size);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("roundsquare")) {
      geom = new RoundRectangle2D.Float(0, 0, size, size, size / 2, size / 2);
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("triangle")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      float height = (float) (Math.sqrt(3) * size / 2);
      path.moveTo(size / 2, size - height);
      path.lineTo(size, size);
      path.lineTo(0, size);
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size - height / 2);
    } else if (shape.equals("star")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, 0);
      path.lineTo(7 * size / 10, 3 * size / 10);
      path.lineTo(size, size / 2);
      path.lineTo(7 * size / 10, 7 * size / 10);
      path.lineTo(size / 2, size);
      path.lineTo(3 * size / 10, 7 * size / 10);
      path.lineTo(0, size / 2);
      path.lineTo(3 * size / 10, 3 * size / 10);
      path.closePath();

      AffineTransform trans = AffineTransform.getRotateInstance(Math.PI / 4, size / 2, size / 2);
      Shape shape = trans.createTransformedShape(path);

      Area area = new Area(path);
      area.add(new Area(shape));

      trans = AffineTransform.getScaleInstance(1.2, 1.2);
      shape = trans.createTransformedShape(area);
      trans = AffineTransform.getTranslateInstance(-0.1 * size, -0.1 * size);
      shape = trans.createTransformedShape(shape);

      geom = shape;

      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("octagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 4, 0);
      path.lineTo(3 * size / 4, 0);
      path.lineTo(size, size / 4);
      path.lineTo(size, 3 * size / 4);
      path.lineTo(3 * size / 4, size);
      path.lineTo(size / 4, size);
      path.lineTo(0, 3 * size / 4);
      path.lineTo(0, size / 4);
      path.closePath();
      geom = path;
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("ellipse")) {
      geom = new Ellipse2D.Float(0, 0, 3 * size / 4, size);
      center = new Point2D.Float(3 * size / 8, size / 2);
    } else if (shape.equals("cross")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 4, 0);
      path.lineTo(3 * size / 4, 0);
      path.lineTo(3 * size / 4, size / 4);
      path.lineTo(size, size / 4);
      path.lineTo(size, 3 * size / 4);
      path.lineTo(3 * size / 4, 3 * size / 4);
      path.lineTo(3 * size / 4, size);
      path.lineTo(size / 4, size);
      path.lineTo(size / 4, 3 * size / 4);
      path.lineTo(0, 3 * size / 4);
      path.lineTo(0, size / 4);
      path.lineTo(size / 4, size / 4);
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("pentagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, size);

      float x, y, a;
      for (int i = 1; i < 5; i++) {
        a = (float) ((2 * Math.PI / 5) * i);
        x = (float) (size / 2 + size / 2 * Math.sin(a));
        y = (float) (size / 2 + size / 2 * Math.cos(a));
        path.lineTo(x, y);
      }
      path.closePath();

      AffineTransform trans = AffineTransform.getScaleInstance(1.1, 1.1);
      Shape shape = trans.createTransformedShape(path);
      trans = AffineTransform.getTranslateInstance(-0.05 * size, -0.05 * size);
      shape = trans.createTransformedShape(shape);

      geom = shape;
      center = new Point2D.Float(size / 2, size / 2);
    } else if (shape.equals("hexagon")) {
      GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
      path.moveTo(size / 2, size);

      float x, y, a;
      for (int i = 1; i < 6; i++) {
        a = (float) ((2 * Math.PI / 6) * i);
        x = (float) (size / 2 + size / 2 * Math.sin(a));
        y = (float) (size / 2 + size / 2 * Math.cos(a));
        path.lineTo(x, y);
      }
      path.closePath();
      geom = path;
      center = new Point2D.Float(size / 2, size / 2);
    } else {
      geom = new Ellipse2D.Float(0, 0, size, size);
      center = new Point2D.Float(size / 2, size / 2);
    }

    return geom;
  }