Exemplo n.º 1
0
  /**
   * Set the {@link ucar.visad.display.DisplayMaster}
   *
   * @param master The display master
   */
  protected void setDisplayMaster(DisplayMaster master) {
    super.setDisplayMaster(master);

    try {
      NavigatedDisplay navDisplay = (NavigatedDisplay) master;

      if (tmpVertRangeUnit != null) {
        navDisplay.setVerticalRangeUnit(tmpVertRangeUnit);
      }

      if (tmpVerticalRange != null) {
        navDisplay.setVerticalRange(tmpVerticalRange[0], tmpVerticalRange[1]);
      }

      navDisplay.setCursorStringOn(false);
      final RubberBandBox rbb = navDisplay.getRubberBandBox();
      if (rbb != null) {
        rbb.addAction(
            new ActionImpl("Box Change") {
              public void doAction() throws VisADException, RemoteException {
                Gridded2DSet bounds = rbb.getBounds();
                if (bounds != null) {
                  rubberBandBoxChanged();
                }
              }
            });
      }
    } catch (Exception e) {
      logException("setDisplayMaster", e);
    }
  }
Exemplo n.º 2
0
 /**
  * Zoom and center all of the MapViewManager-s at the given rect
  *
  * @param pr The projection rect to zoom and center to
  * @param viewManagers ViewManagers to center
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void center(ProjectionRect pr, List viewManagers) throws VisADException, RemoteException {
   for (int i = 0; i < viewManagers.size(); i++) {
     ViewManager viewManager = (ViewManager) viewManagers.get(i);
     if (!(viewManager instanceof MapViewManager)) {
       continue;
     }
     NavigatedDisplay navDisplay =
         (NavigatedDisplay) ((MapViewManager) viewManager).getMapDisplay();
     navDisplay.setMapArea(pr);
   }
 }
Exemplo n.º 3
0
 /**
  * Center the view managers in the list to the given point
  *
  * @param el Point to center to
  * @param viewManagers ViewManagers to center
  * @throws RemoteException On badness
  * @throws VisADException On badness
  */
 public void center(EarthLocation el, List viewManagers) throws VisADException, RemoteException {
   for (int i = 0; i < viewManagers.size(); i++) {
     ViewManager viewManager = (ViewManager) viewManagers.get(i);
     if (!(viewManager instanceof MapViewManager)) {
       continue;
     }
     NavigatedDisplay navDisplay =
         (NavigatedDisplay) ((MapViewManager) viewManager).getMapDisplay();
     navDisplay.center(el);
   }
 }
Exemplo n.º 4
0
  /**
   * Respond to <code>ControlEvent</code>s.
   *
   * @param e <code>ControlEvent</code> to respond to
   */
  protected void handleControlChanged(ControlEvent e) {
    checkHistoryMatrix();

    NavigatedDisplay navDisplay = getNavigatedDisplay();

    if ((lastVerticalRangeUnit != null) && (lastVerticalRange != null)) {
      if (!(Misc.equals(lastVerticalRangeUnit, navDisplay.getVerticalRangeUnit())
          && Arrays.equals(lastVerticalRange, navDisplay.getVerticalRange()))) {
        verticalRangeChanged();
      }
    }

    lastVerticalRangeUnit = navDisplay.getVerticalRangeUnit();
    lastVerticalRange = navDisplay.getVerticalRange();
    super.handleControlChanged(e);
  }
Exemplo n.º 5
0
  /**
   * Set the vertical range unit from the preference
   *
   * @param nd navigated display to set the unit on
   * @throws RemoteException problem with remote display
   * @throws VisADException problem with local display
   */
  protected void setVerticalRangeUnitPreference(NavigatedDisplay nd)
      throws VisADException, RemoteException {
    Unit u = null;

    try {
      u =
          ucar.visad.Util.parseUnit(
              getIdv().getObjectStore().get(IdvConstants.PREF_VERTICALUNIT, "m"));
    } catch (Exception exc) {
      u = null;
    }

    if (u != null) {
      double[] range = nd.getVerticalRange();
      Unit defaultUnit = nd.getVerticalRangeUnit();

      if (!u.equals(defaultUnit) && Unit.canConvert(u, defaultUnit)) {
        range = u.toThis(range, defaultUnit);
        nd.setVerticalRangeUnit(u);
        nd.setVerticalRange(range[0], range[1]);
      }
    }
  }
Exemplo n.º 6
0
  /**
   * An implementation of the the DisplayListener interface. This method turns on/off the wait
   * cursor when it gets a WAIT_ON or WAIT_OFF event. It also, when it receives a FRAME_DONE event
   * for the fist time, calls <code>firstFrameDone</code> on the {@link DisplayControl}s
   *
   * @param de The <code>DisplayEvent</code>
   * @throws RemoteException
   * @throws VisADException
   */
  public void displayChanged(DisplayEvent de) throws VisADException, RemoteException {
    if (getIsDestroyed()) {
      return;
    }

    int eventId = de.getId();
    InputEvent inputEvent = de.getInputEvent();

    if ((inputEvent instanceof MouseEvent) && (eventId == DisplayEvent.MOUSE_PRESSED)) {
      mousePressedTime = System.currentTimeMillis();
      getViewpointControl().setAutoRotate(false);
      startMoveMatrix = getProjectionControl().getMatrix();

      MouseEvent mouseEvent = (MouseEvent) inputEvent;

      mouseStartPoint = new Point(mouseEvent.getX(), mouseEvent.getY());

      if ((mouseEvent.getClickCount() > 1) && mouseEvent.isShiftDown()) {
        NavigatedDisplay navDisplay = getNavigatedDisplay();
        double[] box =
            navDisplay.getSpatialCoordinatesFromScreen(mouseEvent.getX(), mouseEvent.getY());

        navDisplay.center(navDisplay.getEarthLocation(box));
      }
    }

    if ((eventId == DisplayEvent.MOUSE_PRESSED) || (eventId == DisplayEvent.MOUSE_DRAGGED)) {
      mouseMovedTime = System.currentTimeMillis();

      MouseEvent mouseEvent = (MouseEvent) inputEvent;
      int[][][] functionMap = getMaster().getMouseFunctionMap();

      if (functionMap != null) {
        int ctrlIdx = (GuiUtils.isControlKey(mouseEvent) ? 1 : 0);
        int shiftIdx = (mouseEvent.isShiftDown() ? 1 : 0);
        int mouseIdx =
            ((SwingUtilities.isLeftMouseButton(mouseEvent)
                    && !SwingUtilities.isRightMouseButton(mouseEvent))
                ? 0
                : (SwingUtilities.isMiddleMouseButton(mouseEvent)
                    ? 1
                    : ((SwingUtilities.isRightMouseButton(mouseEvent)
                            && !SwingUtilities.isLeftMouseButton(mouseEvent))
                        ? 2
                        : 1)));
        int function = functionMap[mouseIdx][ctrlIdx][shiftIdx];

        if (function == MouseHelper.CURSOR_TRANSLATE) {
          if (cursorReadoutWindow == null) {
            cursorReadoutWindow = new CursorReadoutWindow(this);
          }

          cursorReadoutWindow.handleMousePressedOrDragged(mouseEvent);
        }
      }
    } else if (eventId == DisplayEvent.MOUSE_RELEASED) {
      MouseEvent mouseEvent = (MouseEvent) inputEvent;

      if (cursorReadoutWindow != null) {
        cursorReadoutWindow.handleMouseReleased(mouseEvent);
        cursorReadoutWindow = null;
      }

      Point mouseStart = mouseStartPoint;

      if (mouseStart != null) {
        Point toPoint = new Point(mouseEvent.getX(), mouseEvent.getY());
        double distance = GuiUtils.distance(mouseStart.x, mouseStart.y, toPoint.x, toPoint.y);
        long deltaTime = System.currentTimeMillis() - mouseMovedTime;

        if (System.currentTimeMillis() - mousePressedTime > 0) {
          double speed = distance / (System.currentTimeMillis() - mousePressedTime);

          if ((distance > 50) && (deltaTime < 200) && (speed > 0.5)) {
            double[] endMatrix = getProjectionControl().getMatrix();

            mouseFlicked(mouseStart, toPoint, startMoveMatrix, endMatrix, speed);
          }
        }
      }

      mouseMovedTime = -1;
    }

    super.displayChanged(de);
  }