/**
  * Checks if the given segment is in the visible area. NOTE: This will return true for a small
  * number of non-visible segments.
  *
  * @param ls The segment to check
  * @return true if the segment is visible
  */
 protected boolean isSegmentVisible(Node n1, Node n2) {
   Point p1 = mv.getPoint(n1);
   Point p2 = mv.getPoint(n2);
   if ((p1.x < 0) && (p2.x < 0)) return false;
   if ((p1.y < 0) && (p2.y < 0)) return false;
   if ((p1.x > mv.getWidth()) && (p2.x > mv.getWidth())) return false;
   if ((p1.y > mv.getHeight()) && (p2.y > mv.getHeight())) return false;
   return true;
 }
Beispiel #2
0
  /** Restores the previous settings in the download dialog. */
  public void restoreSettings() {
    cbDownloadOsmData.setSelected(Main.pref.getBoolean("download.osm", true));
    cbDownloadGpxData.setSelected(Main.pref.getBoolean("download.gps", false));
    cbNewLayer.setSelected(Main.pref.getBoolean("download.newlayer", false));
    cbStartup.setSelected(isAutorunEnabled());
    int idx = Main.pref.getInteger("download.tab", 0);
    if (idx < 0 || idx > tpDownloadAreaSelectors.getTabCount()) {
      idx = 0;
    }
    tpDownloadAreaSelectors.setSelectedIndex(idx);

    if (Main.isDisplayingMapView()) {
      MapView mv = Main.map.mapView;
      currentBounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
      boundingBoxChanged(currentBounds, null);
    } else {
      Bounds bounds = getSavedDownloadBounds();
      if (bounds != null) {
        currentBounds = bounds;
        boundingBoxChanged(currentBounds, null);
      }
    }
  }
 /**
  * Checks if the given node is in the visible area.
  *
  * @param n The node to check for visibility
  * @return true if the node is visible
  */
 protected boolean isNodeVisible(Node n) {
   Point p = mv.getPoint(n);
   return !((p.x < 0) || (p.y < 0) || (p.x > mv.getWidth()) || (p.y > mv.getHeight()));
 }
Beispiel #4
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);
        }
      }
    }
  }