Beispiel #1
0
  public void actionPerformed(ActionEvent ae) {
    if (map != null) {
      Proj proj = (Proj) map.getProjection();
      DataBounds bounds = provider.getDataBounds();

      if (bounds != null) {
        java.awt.geom.Point2D center = bounds.getCenter();
        if (center != null) {
          proj.setCenter((float) center.getY(), (float) center.getX());
          LatLonPoint llp1 = new LatLonPoint(bounds.getMax().getY(), bounds.getMin().getX());

          LatLonPoint llp2 = new LatLonPoint(bounds.getMin().getY(), bounds.getMax().getX());

          // 1.1 buffers the edges for viewing a little, a
          // little zommed out.
          proj.setScale(ProjMath.getScale(llp1, llp2, proj) * 1.1f);
          map.setProjection(proj);
        }
      } else {
        String complaint =
            "Can't move map over data: " + provider.getName() + " isn't ready.  Add to map?";
        if (infoDelegator != null) {
          infoDelegator.displayMessage("Go Over Data", complaint);
        } else {
          Debug.error(complaint);
        }
      }
    }
  }
Beispiel #2
0
  /** Clean the surface all the painting is taking place over. */
  public void cleanMap(MouseEvent e) {
    Object obj = e.getSource();
    if (!(obj instanceof MapBean)) {
      return;
    }

    // Could call repaint(), but I think we should paint in this
    // thread...
    MapBean map = (MapBean) obj;
    // Gets the buffer cleaned out.
    map.setBufferDirty(true);
    map.paintChildren(map.getGraphics());
  }
Beispiel #3
0
 /**
  * If the map isn't rotated, this provides the same coordinates as the getX() and getY() methods
  * would. If the map is rotated, this method provides the projected coordinates of the MouseEvent,
  * i.e. the location of the MouseEvent in the non-rotated pixel space of the projection.
  *
  * @return Point2D coordinates of location of mouse position
  */
 public Point2D getProjectedLocation() {
   if (map != null) {
     return map.getNonRotatedLocation(this);
   } else {
     return new Point2D.Double(getX(), getY());
   }
 }
  /**
   * Add the projection background color to the base level of the Java 3D map. The MapHandler
   * provides the MapBean and therefore the projection.
   *
   * @param bg The feature to be added to the Sea attribute
   * @param mh The feature to be added to the Sea attribute
   */
  protected void addSea(Group bg, MapHandler mh) {
    MapBean map = (MapBean) mh.get("com.bbn.openmap.MapBean");
    if (map != null) {
      Debug.message("3d", "LayerMapContent: putting down sea.");
      Color seaColor = map.getBackground();

      Projection proj = map.getProjection();

      // Make the background strech a screen around the current
      // map, all directions.
      int width = proj.getWidth();
      int height = proj.getHeight();

      java.awt.geom.GeneralPath background =
          // OMGraphic.createBoxShape(0, 0, width, height);
          OMGraphicAdapter.createBoxShape(-width, -height, width * 3, height * 3);

      addTo(bg, OMGraphicUtil.createShape3D(background, 0, seaColor, true));
    }
  }
  /**
   * Function to add a specific message to the map
   *
   * @param message
   */
  public void setMarker(MsiMessageExtended message) {
    this.message = message;
    this.msiLocation = message.msiMessage.getLocation().getCenter();
    LatLonPoint center = (LatLonPoint) mapBean.getCenter();
    GeoLocation geoCenter = new GeoLocation(center.getLatitude(), center.getLongitude());
    double bearing = Calculator.bearing(geoCenter, msiLocation, Heading.RL);

    Projection projection = mapBean.getProjection();
    Point2D projectedMSI =
        projection.forward(msiLocation.getLatitude(), msiLocation.getLongitude());

    Point2D origin = new Point2D.Double(mapBean.getWidth() * 0.5f, mapBean.getHeight() * 0.5f);
    Line2D direction = new Line2D.Double(origin, projectedMSI);

    double boxWidth = mapBean.getWidth() - IMAGE_SIZE / 2;
    double boxHeight = mapBean.getHeight() - IMAGE_SIZE / 2;
    Line2D topFrame = new Line2D.Double(IMAGE_SIZE / 2, IMAGE_SIZE / 2, boxWidth, IMAGE_SIZE / 2);
    Line2D rightFrame = new Line2D.Double(boxWidth, IMAGE_SIZE / 2, boxWidth, boxHeight);
    Line2D bottomFrame = new Line2D.Double(IMAGE_SIZE / 2, boxHeight, boxWidth, boxHeight);
    Line2D leftFrame = new Line2D.Double(IMAGE_SIZE / 2, IMAGE_SIZE / 2, IMAGE_SIZE / 2, boxHeight);

    boolean intersects = false;

    if (intersects(direction, topFrame)) intersects = true;
    if (intersects(direction, rightFrame)) intersects = true;
    if (intersects(direction, bottomFrame)) intersects = true;
    if (intersects(direction, leftFrame)) intersects = true;

    if (!intersects) return;

    int x = Math.round((float) intersection.getX());
    int y = Math.round((float) intersection.getY());

    directionRaster = new CenterRaster(x, y, directionImage);
    directionRaster.setRotationAngle(Math.toRadians(bearing));

    markerRaster = new CenterRaster(x, y, markerImage);

    add(markerRaster);
    add(directionRaster);
  }
Beispiel #6
0
  /**
   * Given a MouseEvent, check the source, and if it's a MapBean, then grab the projection and
   * java.awt.Graphics from it to use for generation and rendering of the EditableOMGraphic objects.
   *
   * @param e MouseEvent
   * @param firmPaint true if the graphic is being rendered at rest, with fill colors and true
   *     colors, with the grab point if the state allows it. If false, then the fill color will not
   *     be used, and just the graphic will be drawn. Use false for graphics that are moving.
   */
  public void redraw(MouseEvent e, boolean firmPaint, boolean drawXOR) {
    if (DEBUG) {
      Debug.output("EditableOMGraphic.redraw(" + (firmPaint ? "firmPaint)" : ")"));
    }

    if (e == null) {
      if (lastMouseEvent == null) {
        return;
      }
      e = lastMouseEvent;
    }

    Object obj = e.getSource();
    if (!(obj instanceof MapBean)) {
      return;
    }

    MapBean map = (MapBean) obj;
    Graphics g = map.getGraphics();

    OMGraphic graphic = getGraphic();

    if (firmPaint) {
      // So, with a firm paint, we want to clean the screen. If
      // the map is being buffered, we need to clean out the
      // buffer, which is why we set the Request paint to true,
      // to get the image rebuilt. Otherwise, a copy of the
      // graphic remains.
      map.setBufferDirty(true);
      graphic.generate(getProjection());
      map.repaint();
    } else {
      // If we get here, we are painting a moving object, so we
      // only want to do the outline to make it as fast as
      // possible.
      holder.setFrom(graphic);
      DrawingAttributes.DEFAULT.setTo(graphic);

      modifyOMGraphicForEditRender();
      graphic.regenerate(getProjection());

      if (drawXOR) {
        g.setXORMode(Color.lightGray);
        g.setColor((Color) graphic.getDisplayPaint());

        render(g);
      }

      GrabPoint gp = getMovingPoint();
      if (gp != null) {
        gp.set(e.getX(), e.getY());
        if (gp instanceof OffsetGrabPoint) {
          ((OffsetGrabPoint) gp).moveOffsets();
        }
        setGrabPoints();
      }
    }

    if (!firmPaint) {
      generate(getProjection());
      render(g);
      holder.setTo(graphic);
    }

    resetOMGraphicAfterEditRender();
    g.dispose();

    lastMouseEvent = e;
  }
 /**
  * Constructor used in creating the directional icons in MSI
  *
  * @param mapBean
  */
 MsiDirectionalIcon(MapBean mapBean) {
   super();
   setVague(true);
   this.mapBean = mapBean;
   mapBean.addProjectionListener(this);
 }
Beispiel #8
0
 /**
  * Get the Lat/Lon for the x/y point, in the current projection of the MapBean that sent the
  * MouseEvent. Could be null if the MouseEvent did not originate from a MapBean.
  */
 public Point2D getLatLon() {
   if (map != null) {
     return map.getCoordinates(this);
   } else return null;
 }
Beispiel #9
0
 public boolean mapIsRotated() {
   return (map != null && map.getRotationAngle() != 0.0);
 }
Beispiel #10
0
  public void actionPerformed(ActionEvent ae) {
    Debug.message("saveimage", "SaveAsImageMenuItem: actionPerformed");

    if (mapHandler == null) {
      Debug.output("SaveAsImageMenuItem: mapHandler = null, returning");
      return;
    }

    MapBean mb = (MapBean) mapHandler.get("com.bbn.openmap.MapBean");

    if (mb != null) {
      Debug.message("saveimage", "MapBean found, creating image");
      try {

        while (true) {
          SaveAsImageFileChooser chooser =
              new SaveAsImageFileChooser(mb.getWidth(), mb.getHeight());

          int returnVal = chooser.showSaveDialog(getParent());
          if (returnVal == JFileChooser.APPROVE_OPTION) {
            String filename = chooser.getSelectedFile().getAbsolutePath();
            if (formatter == null) {
              break;
            }

            filename = checkFileName(filename, formatter.getFormatLabel().toLowerCase());
            if (filename == null) {
              // This is the reason for the while
              // loop, the name didn't really pass
              // muster, so we'll try again.
              continue;
            }

            int imageHeight = chooser.getImageHeight();
            int imageWidth = chooser.getImageWidth();

            byte[] imageBytes = formatter.getImageFromMapBean(mb, imageWidth, imageHeight);
            FileOutputStream binFile = new FileOutputStream(filename);
            binFile.write(imageBytes);
            binFile.close();
            if (Debug.debugging("saveimage")) {
              com.bbn.openmap.proj.Projection proj = mb.getProjection();
              Debug.output(
                  "Created image at "
                      + filename
                      + "where projection covers "
                      + proj.getUpperLeft()
                      + " to "
                      + proj.getLowerRight());
            }
            break;
          } else if (returnVal == JFileChooser.CANCEL_OPTION) {
            break;
          }
        }
      } catch (IOException e) {
        Debug.error("SaveAsImageMenuItem: " + e);
      }
    }
    return;
  }