Пример #1
0
 /**
  * Returns the image that matches the position of the mouse event.
  *
  * @param evt Mouse event
  * @return Image at mouse position, or {@code null} if there is no image at the mouse position
  * @since 6392
  */
 public ImageEntry getPhotoUnderMouse(MouseEvent evt) {
   if (data != null) {
     for (int idx = data.size() - 1; idx >= 0; --idx) {
       ImageEntry img = data.get(idx);
       if (img.getPos() == null) {
         continue;
       }
       Point p = Main.map.mapView.getPoint(img.getPos());
       Rectangle r;
       if (useThumbs && img.hasThumbnail()) {
         Dimension d = scaledDimension(img.getThumbnail());
         r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
       } else {
         r =
             new Rectangle(
                 p.x - icon.getIconWidth() / 2,
                 p.y - icon.getIconHeight() / 2,
                 icon.getIconWidth(),
                 icon.getIconHeight());
       }
       if (r.contains(evt.getPoint())) {
         return img;
       }
     }
   }
   return null;
 }
Пример #2
0
 /**
  * Prepare the string that is displayed if layer information is requested.
  *
  * @return String with layer information
  */
 private String infoText() {
   int tagged = 0;
   int newdata = 0;
   int n = 0;
   if (data != null) {
     n = data.size();
     for (ImageEntry e : data) {
       if (e.getPos() != null) {
         tagged++;
       }
       if (e.hasNewGpsData()) {
         newdata++;
       }
     }
   }
   return "<html>"
       + trn("{0} image loaded.", "{0} images loaded.", n, n)
       + ' '
       + trn("{0} was found to be GPS tagged.", "{0} were found to be GPS tagged.", tagged, tagged)
       + (newdata > 0
           ? "<br>"
               + trn("{0} has updated GPS data.", "{0} have updated GPS data.", newdata, newdata)
           : "")
       + "</html>";
 }
Пример #3
0
    @Override
    protected void finish() {
      if (!errorMessages.isEmpty()) {
        JOptionPane.showMessageDialog(
            Main.parent, formatErrorMessages(), tr("Error"), JOptionPane.ERROR_MESSAGE);
      }
      if (layer != null) {
        Main.main.addLayer(layer);
        layer.hook_up_mouse_events(); // Main.map.mapView should exist
        // now. Can add mouse listener
        Main.map.mapView.addPropertyChangeListener(layer);
        if (Main.map.getToggleDialog(ImageViewerDialog.class) == null) {
          ImageViewerDialog.newInstance();
          Main.map.addToggleDialog(ImageViewerDialog.getInstance());
        }

        if (!cancelled && layer.data.size() > 0) {
          boolean noGeotagFound = true;
          for (ImageEntry e : layer.data) {
            if (e.getPos() != null) {
              noGeotagFound = false;
            }
          }
          if (noGeotagFound) {
            new CorrelateGpxWithImages(layer).actionPerformed(null);
          }
        }
      }
    }
Пример #4
0
 private String infoText() {
   int i = 0;
   for (ImageEntry e : data)
     if (e.getPos() != null) {
       i++;
     }
   return trn("{0} image loaded.", "{0} images loaded.", data.size(), data.size())
       + " "
       + trn("{0} was found to be GPS tagged.", "{0} were found to be GPS tagged.", i, i);
 }
Пример #5
0
    @Override
    protected void finish() {
      if (!errorMessages.isEmpty()) {
        JOptionPane.showMessageDialog(
            Main.parent, formatErrorMessages(), tr("Error"), JOptionPane.ERROR_MESSAGE);
      }
      if (layer != null) {
        Main.main.addLayer(layer);

        if (!canceled && layer.data != null && !layer.data.isEmpty()) {
          boolean noGeotagFound = true;
          for (ImageEntry e : layer.data) {
            if (e.getPos() != null) {
              noGeotagFound = false;
            }
          }
          if (noGeotagFound) {
            new CorrelateGpxWithImages(layer).actionPerformed(null);
          }
        }
      }
    }
Пример #6
0
 @Override
 public void visitBoundingBox(BoundingXYVisitor v) {
   for (ImageEntry e : data) {
     v.visit(e.getPos());
   }
 }
Пример #7
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);
        }
      }
    }
  }
Пример #8
0
  @Override
  public void paint(Graphics2D g, MapView mv, Bounds bounds) {
    int width = Main.map.mapView.getWidth();
    int height = Main.map.mapView.getHeight();
    Rectangle clip = g.getClipBounds();
    if (useThumbs) {
      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);

        for (ImageEntry e : data) {
          if (e.getPos() == null) {
            continue;
          }
          Point p = mv.getPoint(e.getPos());
          if (e.thumbnail != null) {
            Dimension d = scaledDimension(e.thumbnail);
            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.thumbnail, 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 {
      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());

        if (e.thumbnail != null) {
          Dimension d = scaledDimension(e.thumbnail);
          g.setColor(new Color(128, 0, 0, 122));
          g.fillRect(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
        } else {
          if (e.getExifImgDir() != null) {
            double arrowlength = 25;
            double arrowwidth = 18;

            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.setColor(Color.white);
            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);
          }

          selectedIcon.paintIcon(
              mv, g, p.x - selectedIcon.getIconWidth() / 2, p.y - selectedIcon.getIconHeight() / 2);
        }
      }
    }
  }