示例#1
0
    private void paintToImage(
        final BufferedImage img, final int x, final int y, final int width, final int height) {
      // clear the prior image
      Graphics2D imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.Clear);
      imgG.setColor(Color.black);
      imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);

      final int adjX = (int) (x + blur + offsetX + (insets.left * distance));
      final int adjY = (int) (y + blur + offsetY + (insets.top * distance));
      final int adjW = (int) (width - (insets.left + insets.right) * distance);
      final int adjH = (int) (height - (insets.top + insets.bottom) * distance);

      // let the delegate paint whatever they want to be blurred
      imgG.setComposite(AlphaComposite.DstAtop);
      if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();

      // blur the prior image back into the same pixels
      imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.DstAtop);
      imgG.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      imgG.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      imgG.drawImage(img, blurOp, 0, 0);

      if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();
    }
示例#2
0
  /**
   * Returns the specified image as icon.
   *
   * @param name name of icon
   * @return icon
   */
  public static ImageIcon icon(final String name) {
    ImageIcon ii = ICONS.get(name);
    if (ii != null) return ii;

    Image img;
    if (GUIConstants.scale > 1) {
      // choose large image or none
      final URL url =
          GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null;

      if (url == null) {
        // resize low-res image if no hi-res image exists
        img = get(url(name));
        final int w = (int) (img.getWidth(null) * GUIConstants.scale);
        final int h = (int) (img.getHeight(null) * GUIConstants.scale);
        final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        img = tmp;
      } else {
        img = get(url);
      }
    } else {
      img = get(name);
    }
    ii = new ImageIcon(img);
    ICONS.put(name, ii);
    return ii;
  }
示例#3
0
 private static Image getImage(ResizableIcon icon, int size) {
   icon.setDimension(new Dimension(size, size));
   if (icon instanceof AsynchronousLoading) {
     AsynchronousLoading async = (AsynchronousLoading) icon;
     if (async.isLoading()) {
       final CountDownLatch latch = new CountDownLatch(1);
       final boolean[] status = new boolean[1];
       AsynchronousLoadListener all =
           new AsynchronousLoadListener() {
             @Override
             public void completed(boolean success) {
               status[0] = success;
               latch.countDown();
             }
           };
       async.addAsynchronousLoadListener(all);
       try {
         latch.await();
       } catch (InterruptedException ignored) {
       }
       async.removeAsynchronousLoadListener(all);
       if (!status[0]) {
         return null;
       }
       if (async.isLoading()) {
         return null;
       }
     }
   }
   Image result = FlamingoUtilities.getBlankImage(size, size);
   Graphics2D g2d = (Graphics2D) result.getGraphics().create();
   icon.paintIcon(null, g2d, 0, 0);
   g2d.dispose();
   return result;
 }
示例#4
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
 public static BufferedImage resize(BufferedImage image, int width, int height) {
   BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
   Graphics2D g2d = (Graphics2D) bi.createGraphics();
   g2d.addRenderingHints(
       new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
   g2d.drawImage(image, 0, 0, width, height, null);
   g2d.dispose();
   return bi;
 }
  /** Draws this handle. */
  public void draw(Graphics2D g) {
    Graphics2D gg = (Graphics2D) g.create();
    gg.transform(view.getDrawingToViewTransform());
    for (Connector c : connectors) {
      c.draw(gg);
    }

    gg.dispose();
    drawCircle(g, (getTarget() == null) ? Color.red : Color.green, Color.black);
  }
示例#7
0
 public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w, h);
   g2.drawImage(bi, -x, -y, null); // this);
   g2.dispose();
   return image;
 }
示例#8
0
 public static BufferedImage scaleImage(BufferedImage bi, double scale) {
   int w1 = (int) (Math.round(scale * bi.getWidth()));
   int h1 = (int) (Math.round(scale * bi.getHeight()));
   BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w1, h1);
   g2.drawImage(bi, 0, 0, w1, h1, null); // this);
   g2.dispose();
   return image;
 }
示例#9
0
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
      public Example(BufferedImage image) {
        // copy image
        int width = image.getWidth();
        int height = image.getHeight();
        this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = this.image.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();

        // create icon
        if (Math.max(width, height) > ICON_SIZE) {
          double scale = Math.min((double) ICON_SIZE / width, (double) ICON_SIZE / height);
          width *= scale;
          height *= scale;
        }
        BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        g2 = buf.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(image, 0, 0, width, height, null);
        g2.dispose();
        this.icon = new ImageIcon(buf);
      }
示例#11
0
  /**
   * Writes this map to a JPG file.
   *
   * @param filename the path and name of the file to create.
   */
  public void writeToJPGFile(String filename) throws IOException {

    this.prepareToDraw();

    BufferedImage buffImage =
        new BufferedImage(p.getWidth(), p.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = buffImage.createGraphics();
    try {
      p.draw(graphics2D);
      System.out.println("Writing picture to " + filename);
      ImageIO.write(buffImage, "JPG", new File(filename));
    } finally {
      graphics2D.dispose();
    }
  }
    public static Image createImage(final JTree tree) {
      final TreeSelectionModel model = tree.getSelectionModel();
      final TreePath[] paths = model.getSelectionPaths();

      int count = 0;
      final List<ChangesBrowserNode> nodes = new ArrayList<ChangesBrowserNode>();
      for (final TreePath path : paths) {
        final ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
          nodes.add(node);
          count += node.getCount();
        }
      }

      for (TreePath path : paths) {
        final ChangesBrowserNode element = (ChangesBrowserNode) path.getLastPathComponent();
        boolean child = false;
        for (final ChangesBrowserNode node : nodes) {
          if (node.isNodeChild(element)) {
            child = true;
            break;
          }
        }

        if (!child) {
          if (element.isLeaf()) count++;
        } else if (!element.isLeaf()) {
          count -= element.getCount();
        }
      }

      final JLabel label = new JLabel(VcsBundle.message("changes.view.dnd.label", count));
      label.setOpaque(true);
      label.setForeground(tree.getForeground());
      label.setBackground(tree.getBackground());
      label.setFont(tree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return image;
    }
示例#13
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.setPaint(Objects.nonNull(c) ? c.getBackground() : Color.WHITE);
   g2.fillRect(x, y, getIconWidth(), getIconHeight());
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(ELLIPSE_COLOR);
   g2.translate(x, y);
   int size = list.size();
   for (int i = 0; i < size; i++) {
     float alpha = isRunning ? (i + 1) / (float) size : .5f;
     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
     g2.fill(list.get(i));
   }
   // g2.translate(-x, -y);
   g2.dispose();
 }
示例#14
0
  @Override
  public void draw(Graphics2D g) {
    double opacity = get(OPACITY);
    opacity = Math.min(Math.max(0d, opacity), 1d);
    if (opacity != 0d) {
      if (opacity != 1d) {
        Rectangle2D.Double drawingArea = getDrawingArea();

        Rectangle2D clipBounds = g.getClipBounds();
        if (clipBounds != null) {
          Rectangle2D.intersect(drawingArea, clipBounds, drawingArea);
        }

        if (!drawingArea.isEmpty()) {

          BufferedImage buf =
              new BufferedImage(
                  (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()),
                  (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()),
                  BufferedImage.TYPE_INT_ARGB);
          Graphics2D gr = buf.createGraphics();
          gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY());
          gr.translate((int) -drawingArea.x, (int) -drawingArea.y);
          gr.setRenderingHints(g.getRenderingHints());
          drawFigure(gr);
          gr.dispose();
          Composite savedComposite = g.getComposite();
          g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity));
          g.drawImage(
              buf,
              (int) drawingArea.x,
              (int) drawingArea.y,
              2 + (int) drawingArea.width,
              2 + (int) drawingArea.height,
              null);
          g.setComposite(savedComposite);
        }
      } else {
        drawFigure(g);
      }
    }
  }
    void paintSkin(Skin skin, Graphics _g, int dx, int dy, int dw, int dh, State state) {
      assert SwingUtilities.isEventDispatchThread();

      updateProgress();
      if (!isDone()) {
        Graphics2D g = (Graphics2D) _g.create();
        skin.paintSkinRaw(g, dx, dy, dw, dh, startState);
        float alpha;
        if (isForward) {
          alpha = progress;
        } else {
          alpha = 1 - progress;
        }
        g.setComposite(AlphaComposite.SrcOver.derive(alpha));
        skin.paintSkinRaw(g, dx, dy, dw, dh, state);
        g.dispose();
      } else {
        skin.paintSkinRaw(_g, dx, dy, dw, dh, state);
      }
    }
示例#16
0
 static void fillRect(
     final Graphics g,
     final Component c,
     final Color color,
     final int x,
     final int y,
     final int w,
     final int h) {
   if (!(g instanceof Graphics2D)) {
     return;
   }
   final Graphics2D cg = (Graphics2D) g.create();
   try {
     if (color instanceof UIResource && isWindowTextured(c) && color.equals(SystemColor.window)) {
       cg.setComposite(AlphaComposite.Src);
       cg.setColor(resetAlpha(color));
     } else {
       cg.setColor(color);
     }
     cg.fillRect(x, y, w, h);
   } finally {
     cg.dispose();
   }
 }
示例#17
0
  private void paintUnzoomedTile(
      final Image tileImage, final int x, final int y, final int dx, final int dy) {
    TileType tileType = getUnzoomedTileType(x, y);
    switch (tileType) {
      case WORLD:
        Tile tile = tileProvider.getTile(x, y);
        if (tile.hasLayer(NotPresent.INSTANCE) && (surroundingTileProvider != null)) {
          surroundingTileProvider.paintTile(tileImage, x, y, dx, dy);
        }
        TileRenderer tileRenderer = tileRendererRef.get();
        tileRenderer.setTile(tile);
        tileRenderer.renderTile(tileImage, dx, dy);
        break;
      case BORDER:
        int colour;
        switch (((Dimension) tileProvider).getBorder()) {
          case WATER:
            colour = colourScheme.getColour(BLK_WATER);
            break;
          case LAVA:
            colour = colourScheme.getColour(BLK_LAVA);
            break;
          case VOID:
            colour = VoidRenderer.getColour();
            break;
          default:
            throw new InternalError();
        }
        Graphics2D g2 = (Graphics2D) tileImage.getGraphics();
        try {
          g2.setColor(new Color(colour));
          g2.fillRect(dx, dy, TILE_SIZE, TILE_SIZE);

          // Draw border lines
          g2.setColor(Color.BLACK);
          g2.setStroke(
              new BasicStroke(
                  2,
                  BasicStroke.CAP_BUTT,
                  BasicStroke.JOIN_BEVEL,
                  0.0f,
                  new float[] {4.0f, 4.0f},
                  0.0f));
          if (tileProvider.isTilePresent(x, y - 1)) {
            g2.drawLine(dx + 1, dy + 1, dx + TILE_SIZE - 1, dy + 1);
          }
          if (tileProvider.isTilePresent(x + 1, y)) {
            g2.drawLine(dx + TILE_SIZE - 1, dy + 1, dx + TILE_SIZE - 1, dy + TILE_SIZE - 1);
          }
          if (tileProvider.isTilePresent(x, y + 1)) {
            g2.drawLine(dx + 1, dy + TILE_SIZE - 1, dx + TILE_SIZE - 1, dy + TILE_SIZE - 1);
          }
          if (tileProvider.isTilePresent(x - 1, y)) {
            g2.drawLine(dx + 1, dy + 1, dx + 1, dy + TILE_SIZE - 1);
          }
        } finally {
          g2.dispose();
        }
        break;
      case WALL:
        if (surroundingTileProvider != null) {
          surroundingTileProvider.paintTile(tileImage, x, y, dx, dy);
        }
        g2 = (Graphics2D) tileImage.getGraphics();
        try {
          if (surroundingTileProvider == null) {
            // A surrounding tile provider would have completely
            // filled the image, but since there isn't one we have
            // to make sure of that ourselves
            g2.setColor(new Color(VoidRenderer.getColour()));
            g2.fillRect(dx, dy, TILE_SIZE, TILE_SIZE);
          }
          g2.setColor(new Color(colourScheme.getColour(BLK_BEDROCK)));
          TileType neighbourType = getUnzoomedTileType(x, y - 1);
          if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
            g2.fillRect(dx, dy, TILE_SIZE, 16);
          }
          neighbourType = getUnzoomedTileType(x + 1, y);
          if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
            g2.fillRect(dx + TILE_SIZE - 16, dy, 16, TILE_SIZE);
          }
          neighbourType = getUnzoomedTileType(x, y + 1);
          if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
            g2.fillRect(dx, dy + TILE_SIZE - 16, TILE_SIZE, 16);
          }
          neighbourType = getUnzoomedTileType(x - 1, y);
          if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
            g2.fillRect(dx, dy, 16, TILE_SIZE);
          }
        } finally {
          g2.dispose();
        }
        break;
      case SURROUNDS:
        if (surroundingTileProvider != null) {
          surroundingTileProvider.paintTile(tileImage, x, y, dx, dy);
        }
        break;
      default:
        throw new InternalError();
    }
  }
示例#18
0
  @Override
  public void paintTile(
      final Image tileImage, final int x, final int y, final int imageX, final int imageY) {
    try {
      if (zoom == 0) {
        paintUnzoomedTile(tileImage, x, y, imageX, imageY);
      } else {
        Graphics2D g2 = (Graphics2D) tileImage.getGraphics();
        try {
          BufferedImage surroundingTileImage = null;
          final Color waterColour = new Color(colourScheme.getColour(BLK_WATER));
          final Color lavaColour = new Color(colourScheme.getColour(BLK_LAVA));
          final Color voidColour = new Color(VoidRenderer.getColour());
          final Color bedrockColour = new Color(colourScheme.getColour(BLK_BEDROCK));
          final int scale = 1 << -zoom;
          final int subSize = TILE_SIZE / scale;
          for (int dx = 0; dx < scale; dx++) {
            for (int dy = 0; dy < scale; dy++) {
              TileType tileType = getUnzoomedTileType(x * scale + dx, y * scale + dy);
              switch (tileType) {
                case WORLD:
                  Tile tile = tileProvider.getTile(x * scale + dx, y * scale + dy);
                  if (tile.hasLayer(NotPresent.INSTANCE)) {
                    if (surroundingTileProvider != null) {
                      if (surroundingTileImage == null) {
                        surroundingTileImage =
                            new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_INT_ARGB);
                        surroundingTileProvider.paintTile(surroundingTileImage, x, y, 0, 0);
                      }
                      g2.drawImage(
                          surroundingTileImage,
                          imageX + dx * subSize,
                          imageY + dy * subSize,
                          imageX + (dx + 1) * subSize,
                          imageY + (dy + 1) * subSize,
                          imageX + dx * subSize,
                          imageY + dy * subSize,
                          imageX + (dx + 1) * subSize,
                          imageY + (dy + 1) * subSize,
                          null);
                    } else {
                      g2.setColor(voidColour);
                      g2.fillRect(imageX + dx * subSize, imageY + dy * subSize, subSize, subSize);
                    }
                  }
                  TileRenderer tileRenderer = tileRendererRef.get();
                  tileRenderer.setTile(tile);
                  tileRenderer.renderTile(tileImage, dx * subSize, dy * subSize);
                  break;
                case BORDER:
                  Color colour;
                  switch (((Dimension) tileProvider).getBorder()) {
                    case WATER:
                      colour = waterColour;
                      break;
                    case LAVA:
                      colour = lavaColour;
                      break;
                    case VOID:
                      colour = voidColour;
                      break;
                    default:
                      throw new InternalError();
                  }
                  g2.setColor(colour);
                  g2.fillRect(imageX + dx * subSize, imageY + dy * subSize, subSize, subSize);

                  // Draw border lines
                  g2.setColor(Color.BLACK);
                  g2.setStroke(
                      new BasicStroke(
                          2,
                          BasicStroke.CAP_BUTT,
                          BasicStroke.JOIN_BEVEL,
                          0.0f,
                          new float[] {4.0f, 4.0f},
                          0.0f));
                  if (tileProvider.isTilePresent(x * scale + dx, y * scale + dy - 1)) {
                    g2.drawLine(
                        imageX + dx * subSize,
                        imageY + dy * subSize,
                        imageX + (dx + 1) * subSize - 1,
                        imageY + dy * subSize);
                  }
                  if (tileProvider.isTilePresent(x * scale + dx + 1, y * scale + dy)) {
                    g2.drawLine(
                        imageX + (dx + 1) * subSize - 1,
                        imageY + dy * subSize,
                        imageX + (dx + 1) * subSize - 1,
                        imageY + (dy + 1) * subSize - 1);
                  }
                  if (tileProvider.isTilePresent(x * scale + dx, y * scale + dy + 1)) {
                    g2.drawLine(
                        imageX + dx * subSize,
                        imageY + (dy + 1) * subSize - 1,
                        imageX + (dx + 1) * subSize - 1,
                        imageY + (dy + 1) * subSize - 1);
                  }
                  if (tileProvider.isTilePresent(x * scale + dx - 1, y * scale + dy)) {
                    g2.drawLine(
                        imageX + dx * subSize,
                        imageY + dy * subSize,
                        imageX + dx * subSize,
                        imageY + (dy + 1) * subSize - 1);
                  }
                  break;
                case SURROUNDS:
                case WALL:
                  if (surroundingTileProvider != null) {
                    if (surroundingTileImage == null) {
                      surroundingTileImage =
                          new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_INT_ARGB);
                      surroundingTileProvider.paintTile(surroundingTileImage, x, y, 0, 0);
                    }
                    g2.drawImage(
                        surroundingTileImage,
                        imageX + dx * subSize,
                        imageY + dy * subSize,
                        imageX + (dx + 1) * subSize,
                        imageY + (dy + 1) * subSize,
                        imageX + dx * subSize,
                        imageY + dy * subSize,
                        imageX + (dx + 1) * subSize,
                        imageY + (dy + 1) * subSize,
                        null);
                  } else {
                    g2.setColor(voidColour);
                    g2.fillRect(imageX + dx * subSize, imageY + dy * subSize, subSize, subSize);
                  }
                  if (tileType == TileType.WALL) {
                    g2.setColor(bedrockColour);
                    TileType neighbourType =
                        getUnzoomedTileType(x * scale + dx, y * scale + dy - 1);
                    int wallWidth = Math.max(subSize / 8, 1);
                    if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
                      g2.fillRect(imageX + dx * subSize, imageY + dy * subSize, subSize, wallWidth);
                    }
                    neighbourType = getUnzoomedTileType(x * scale + dx + 1, y * scale + dy);
                    if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
                      g2.fillRect(
                          imageX + (dx + 1) * subSize - wallWidth,
                          imageY + dy * subSize,
                          wallWidth,
                          subSize);
                    }
                    neighbourType = getUnzoomedTileType(x * scale + dx, y * scale + dy + 1);
                    if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
                      g2.fillRect(
                          imageX + dx * subSize,
                          imageY + (dy + 1) * subSize - wallWidth,
                          subSize,
                          wallWidth);
                    }
                    neighbourType = getUnzoomedTileType(x * scale + dx - 1, y * scale + dy);
                    if ((neighbourType == TileType.WORLD) || (neighbourType == TileType.BORDER)) {
                      g2.fillRect(imageX + dx * subSize, imageY + dy * subSize, wallWidth, subSize);
                    }
                  }
                  break;
              }
            }
          }
        } finally {
          g2.dispose();
        }
      }
    } catch (Throwable e) {
      // Log at debug level because this tends to happen when zooming in
      // and out, probably due to some state getting out of sync. It
      // doesn't so far appear to have any visible consequences.
      logger.error("Exception while generating image for tile at " + x + ", " + y, e);
    }
  }
示例#19
0
  public MapPanel(ClientGameBoard gl) {
    super();

    _dismiss = false;
    gameLogic = gl;
    gameLogic._mapPanel = this;
    _hexes = new ArrayList<Hex>();
    vertexContents = new Hashtable<CoordPair, Pair>();
    roadContents = new Hashtable<Pair, Integer>();
    portContents = new Hashtable<Pair, BoardObject.type>();

    diceImage = new BufferedImage(582, 98, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = diceImage.createGraphics();
    g.drawImage(BoardObject.images.get(BoardObject.type.DICE), null, null);
    g.dispose();

    rings = gameLogic.getNumRings();

    hexleft =
        100
            - (int)
                (radius
                    + (Math.floor(rings / 2) * radius + Math.floor((rings - 1) / 2) * radius * 2));
    if (rings % 2 == 0) {
      hexleft -= radius / 2;
    }

    hextop = 300 - (int) (radius * 0.866 + (rings - 1) * 2 * (radius * 0.866));

    double border = 0.4;

    HashMap<Pair, Pair> hexData = gameLogic.getHexInfo(); // call the gamelogic

    Pair currCoord = gameLogic.getStartPoint();

    Pair topCoord = currCoord;

    int ring = 0;

    int currentDir = 5;
    int current = 0;
    int[][] directions = {{1, 1}, {0, 2}, {-1, 1}, {-1, -1}, {0, -2}, {1, -1}};

    int[][] HexCoordDirections = {{2, 1}, {0, 2}, {-2, 1}, {-2, -1}, {0, -2}, {2, -1}};

    Hex top =
        new Hex(
            100,
            300,
            radius,
            (BoardObject.type) (hexData.get(currCoord).getA()),
            (Integer) (hexData.get(currCoord).getB()));
    Hex curr = top;

    _hexes.add(top);
    while (true) {
      if (current == ring) {
        currentDir++;
        current = 0;
      }
      if (currentDir > 5) {
        currentDir = 0;
        current = 0;
        ring++;
        if (ring < rings) {
          topCoord = new Pair(currCoord.getA(), (Double) (currCoord.getB()) - 2);
          currCoord = topCoord;

          top =
              new Hex(
                  curr.getX(),
                  (curr.getY() - 2 * (Math.cos(Math.PI / 6) * (curr.getRadius() + border))),
                  curr.getRadius(),
                  (BoardObject.type) (hexData.get(currCoord).getA()),
                  (Integer) (hexData.get(currCoord).getB()));
          curr = top;

        } else {
          break;
        }
      }
      currCoord.setA((Object) ((Double) (currCoord.getA()) + HexCoordDirections[currentDir][0]));
      currCoord.setB((Object) ((Double) (currCoord.getB()) + HexCoordDirections[currentDir][1]));

      curr =
          new Hex(
              (curr.getX() + directions[currentDir][0] * (curr.getRadius() + border) * 3 / 2),
              (curr.getY()
                  + directions[currentDir][1]
                      * (Math.cos(Math.PI / 6) * (curr.getRadius() + border))),
              curr.getRadius(),
              (BoardObject.type) (hexData.get(currCoord).getA()),
              (Integer) (hexData.get(currCoord).getB()));
      _hexes.add(curr);

      current++;
    }

    addMouseListener(this);
    addMouseMotionListener(this);
  }
示例#20
0
  /**
   * Creates new frame image from current data (and previous frames as specified by their
   * disposition codes).
   */
  protected void setPixels() {
    // expose destination image's pixels as int array
    int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

    // fill in starting image contents based on last image's dispose code
    if (lastDispose > 0) {
      if (lastDispose == 3) {
        // use image before last
        int n = frameCount - 2;
        if (n > 0) {
          lastImage = getFrame(n - 1);
        } else {
          lastImage = null;
        }
      }

      if (lastImage != null) {
        int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
        System.arraycopy(prev, 0, dest, 0, width * height);
        // copy pixels

        if (lastDispose == 2) {
          // fill last image rect area with background color
          Graphics2D g = image.createGraphics();
          Color c = null;
          if (transparency) {
            c = new Color(0, 0, 0, 0); // assume background is transparent

          } else {
            c = new Color(lastBgColor); // use given background color
          }
          g.setColor(c);
          g.setComposite(AlphaComposite.Src); // replace area

          g.fill(lastRect);
          g.dispose();
        }
      }
    }

    // copy each source line to the appropriate place in the destination
    int pass = 1;
    int inc = 8;
    int iline = 0;
    for (int i = 0; i < ih; i++) {
      int line = i;
      if (interlace) {
        if (iline >= ih) {
          pass++;
          switch (pass) {
            case 2:
              iline = 4;
              break;
            case 3:
              iline = 2;
              inc = 4;
              break;
            case 4:
              iline = 1;
              inc = 2;
          }
        }
        line = iline;
        iline += inc;
      }
      line += iy;
      if (line < height) {
        int k = line * width;
        int dx = k + ix; // start of line in dest

        int dlim = dx + iw; // end of dest line

        if ((k + width) < dlim) {
          dlim = k + width; // past dest edge
        }
        int sx = i * iw; // start of line in source

        while (dx < dlim) {
          // map color and insert in destination
          int index = ((int) pixels[sx++]) & 0xff;
          int c = act[index];
          if (c != 0) {
            dest[dx] = c;
          }
          dx++;
        }
      }
    }
  }
示例#21
0
 /** [Advanced] */
 public void dispose() {
   Graphics2D g = getG();
   if (g != null) g.dispose();
 }
示例#22
0
    @Override
    protected void paintComponent(Graphics g) {
      JRibbonFrame ribbonFrame = (JRibbonFrame) SwingUtilities.getWindowAncestor(this);
      if (!ribbonFrame.isShowingKeyTips()) return;

      // don't show keytips on inactive windows
      if (!ribbonFrame.isActive()) return;

      Collection<KeyTipManager.KeyTipLink> keyTips =
          KeyTipManager.defaultManager().getCurrentlyShownKeyTips();
      if (keyTips != null) {
        Graphics2D g2d = (Graphics2D) g.create();
        RenderingUtils.installDesktopHints(g2d);

        for (KeyTipManager.KeyTipLink keyTip : keyTips) {
          // don't display keytips on components in popup panels
          if (SwingUtilities.getAncestorOfClass(JPopupPanel.class, keyTip.comp) != null) continue;

          // don't display key tips on hidden components
          Rectangle compBounds = keyTip.comp.getBounds();
          if (!keyTip.comp.isShowing()
              || (compBounds.getWidth() == 0)
              || (compBounds.getHeight() == 0)) continue;

          Dimension pref =
              KeyTipRenderingUtilities.getPrefSize(g2d.getFontMetrics(), keyTip.keyTipString);

          Point prefCenter = keyTip.prefAnchorPoint;
          Point loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, this);
          Container bandControlPanel =
              SwingUtilities.getAncestorOfClass(AbstractBandControlPanel.class, keyTip.comp);
          if (bandControlPanel != null) {
            // special case for controls in threesome
            // ribbon band rows
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.TOP_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = 0;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = 0;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.MID_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight() / 2;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight() / 2;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.BOTTOM_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight();
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight();
            }
          }

          KeyTipRenderingUtilities.renderKeyTip(
              g2d,
              this,
              new Rectangle(
                  loc.x - pref.width / 2, loc.y - pref.height / 2, pref.width, pref.height),
              keyTip.keyTipString,
              keyTip.enabled);
        }

        g2d.dispose();
      }
    }