Ejemplo n.º 1
0
 /**
  * Set color of axis scales; color must be float[3] with red,
  * green and blue components; DisplayScalar must be XAxis,
  * YAxis or ZAxis.  Preferred method is to use <CODE>AxisScale.setColor<CODE>
  * methods.
  * @param  color  array of R,G,B values of color.
  * @throws  VisADException  non-spatial DisplayScalar or wrong length
  *                          of color array
  * @see #getAxisScale()
  * @see visad.AxisScale#setColor(Color color)
  * @see visad.AxisScale#setColor(float[] color)
  */
 public void setScaleColor(float[] color) throws VisADException {
   if (!DisplayScalar.equals(Display.XAxis)
       && !DisplayScalar.equals(Display.YAxis)
       && !DisplayScalar.equals(Display.ZAxis)) {
     throw new DisplayException(
         "ScalarMap.setScaleColor: DisplayScalar " + "must be XAxis, YAxis or ZAxis");
   }
   if (color == null || color.length != 3) {
     throw new DisplayException("ScalarMap.setScaleColor: color is " + "null or wrong length");
   }
   // DRM 10-Oct 2000
   axisScale.setColor(color);
 }
Ejemplo n.º 2
0
  /**
   * set aspect ratio of XAxis, YAxis & ZAxis in ScalarMaps rather than matrix (i.e., don't distort
   * text fonts); won't work for spherical, polar, cylindrical coordinates
   *
   * @param aspect ratios; 3 elements for Java3D, 2 for Java2D
   * @throws VisADException a VisAD error occurred
   * @throws RemoteException an RMI error occurred
   */
  void setAspectCartesian(double[] aspect) throws VisADException, RemoteException {
    double asp = Double.NaN;
    if (DisplayScalar.equals(Display.XAxis)) asp = aspect[0];
    if (DisplayScalar.equals(Display.YAxis)) asp = aspect[1];
    if (DisplayScalar.equals(Display.ZAxis)) asp = aspect[2];
    if (asp == asp) {
      isScaled = DisplayScalar.getRange(displayRange);
      displayRange[0] *= asp;
      displayRange[1] *= asp;
      computeScaleAndOffset();

      makeScale();
      // needs work in AxisScale ****
    }
    // note XAxis, YAxis and ZAxis have no unit, so cannot be setRangeByUnits()
  }
Ejemplo n.º 3
0
 ScalarMap(ScalarType scalar, DisplayRealType display_scalar, boolean needNonNullScalar)
     throws VisADException {
   if (scalar == null && needNonNullScalar) {
     throw new DisplayException("ScalarMap: scalar is null");
   }
   if (display_scalar == null) {
     throw new DisplayException("ScalarMap: display_scalar is null");
   }
   if (display_scalar.equals(Display.List)) {
     throw new DisplayException("ScalarMap: display_scalar may not be List");
   }
   boolean text = display_scalar.getText();
   if (scalar != null) {
     /* WLH 15 June 2000
           if (text && !(scalar instanceof TextType)) {
             throw new DisplayException("ScalarMap: RealType scalar cannot be " +
                                        "used with TextType display_scalar");
           }
     */
     if (!text && !(scalar instanceof RealType)) {
       throw new DisplayException(
           "ScalarMap: TextType scalar cannot be " + "used with RealType display_scalar");
     }
   }
   control = null;
   Scalar = scalar;
   DisplayScalar = display_scalar;
   display = null;
   ScalarIndex = -1;
   DisplayScalarIndex = -1;
   isScaled = DisplayScalar.getRange(displayRange);
   isManual = false;
   dataRange[0] = Double.NaN;
   dataRange[1] = Double.NaN;
   defaultUnitRange[0] = dataRange[0];
   defaultUnitRange[1] = dataRange[1];
   OldTick = Long.MIN_VALUE;
   NewTick = Long.MIN_VALUE + 1;
   tickFlag = false;
   if (Scalar != null) scalarName = Scalar.getName();
   if (DisplayScalar.equals(Display.XAxis)
       || DisplayScalar.equals(Display.YAxis)
       || DisplayScalar.equals(Display.ZAxis)) {
     axisScale = new AxisScale(this);
   }
 }
Ejemplo n.º 4
0
 /**
  * explicitly set the range of data (RealType) values; used for linear map from Scalar to
  * DisplayScalar values; if neither this nor setRangeByUnits is invoked, then the range will be
  * computed from the initial values of Data objects linked to the Display by autoscaling logic; if
  * the range of data values is (0.0, 1.0), for example, this method may be invoked with low = 1.0
  * and hi = 0.0 to invert the display scale .
  *
  * @param low lower range value (see notes above)
  * @param hi upper range value (see notes above)
  * @param remoteId id of remote scale
  * @throws VisADException VisAD error
  * @throws RemoteException Java RMI error
  */
 public void setRange(double low, double hi, int remoteId) throws VisADException, RemoteException {
   if (DisplayScalar.equals(Display.Animation)) {
     System.err.println("Warning: setRange on " + "ScalarMap to Display.Animation has no effect.");
     return;
   }
   isManual = true;
   setRange(null, low, hi, false, remoteId);
   if (scale == scale && offset == offset) {
     incTick(); // did work, so wake up Display
   } else {
     isManual = false; // didn't work, so don't lock out auto-scaling
   }
 }
Ejemplo n.º 5
0
 public boolean badRange() {
   // WLH 15 Feb 2002
   boolean bad = (isScaled && (scale != scale || offset != offset));
   if (DisplayScalar.equals(Display.Animation)) {
     if (control != null) {
       Set set = ((AnimationControl) control).getSet();
       bad |= (set == null);
     } else {
       bad = true;
     }
   }
   return bad;
   // return (isScaled && (scale != scale || offset != offset));
 }
Ejemplo n.º 6
0
 // WLH 22 August 2001
 public boolean doInitialize() {
   if (DisplayScalar.equals(Display.IsoContour)) {
     if (control != null) {
       float[] lowhibase = new float[3];
       boolean[] dashes = new boolean[1];
       float[] levs = ((ContourControl) control).getLevels(lowhibase, dashes);
       return (levs == null);
     } else {
       return false;
     }
   } else {
     return isScaled && !isManual;
   }
 }
Ejemplo n.º 7
0
  /** set range used for linear map from Scalar to DisplayScalar values */
  private synchronized void setRange(
      DataShadow shadow, double low, double hi, boolean unit_flag, int remoteId)
      throws VisADException, RemoteException {
    int i = ScalarIndex;
    if (shadow != null) {
      // WLH - 23 Sept 99
      if (DisplayScalar.equals(Display.Latitude) || DisplayScalar.equals(Display.Longitude)) {
        Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
        Unit display_unit = DisplayScalar.getDefaultUnit();
        if (data_unit != null && display_unit != null && Unit.canConvert(data_unit, display_unit)) {
          dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
          dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
        } else {
          if (i < 0 || i >= shadow.ranges[0].length) return;
          dataRange[0] = shadow.ranges[0][i];
          dataRange[1] = shadow.ranges[1][i];
        }
      } else {
        if (i < 0 || i >= shadow.ranges[0].length) return;
        dataRange[0] = shadow.ranges[0][i];
        dataRange[1] = shadow.ranges[1][i];
      }
    } else if (unit_flag) {
      Unit data_unit = (Scalar instanceof RealType) ? ((RealType) Scalar).getDefaultUnit() : null;
      Unit display_unit = DisplayScalar.getDefaultUnit();
      if (data_unit == null || display_unit == null) {
        throw new UnitException("ScalarMap.setRangeByUnits: null Unit");
      }
      dataRange[0] = data_unit.toThis(displayRange[0], display_unit);
      dataRange[1] = data_unit.toThis(displayRange[1], display_unit);
      /*
      System.out.println("data_unit = " + data_unit + " display_unit = " + display_unit);
      System.out.println("dataRange = " + dataRange[0] + " " + dataRange[1] +
      " displayRange = " + displayRange[0] + " " + displayRange[1]);
      */
    } else {
      dataRange[0] = low;
      dataRange[1] = hi;
      // WLH 31 Aug 2000
      // manual range is in overrideUnit. so convert to Scalar default Unit
      if (overrideUnit != null) {
        dataRange[0] = (dataRange[0] - override_offset) / override_scale;
        dataRange[1] = (dataRange[1] - override_offset) / override_scale;
      }
    }
    /*
    if (shadow != null || remoteId != VisADEvent.LOCAL_SOURCE) {
      System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                         " to " + dataRange[1] + " " + display.getName());
    }
    */
    // at this point dataRange is range for Scalar default Unit
    //   even if (overrideUnit != null)
    // DRM 17 Feb 2006 - so set the defaultUnitRange to be these values.
    defaultUnitRange[0] = dataRange[0];
    defaultUnitRange[1] = dataRange[1];
    if (defaultUnitRange[0] == defaultUnitRange[1]) {
      double half = defaultUnitRange[0] / 2000.0;
      if (half < 0.5) half = 0.5;
      defaultUnitRange[0] -= half;
      defaultUnitRange[1] += half;
    }

    if (isScaled) {
      computeScaleAndOffset();
    } else { // if (!isScaled)
      if (dataRange[0] == Double.MAX_VALUE || dataRange[1] == -Double.MAX_VALUE) {
        dataRange[0] = Double.NaN;
        dataRange[1] = Double.NaN;
      }

      // WLH 31 Aug 2000
      if (overrideUnit != null) {
        // now convert dataRange to overrideUnit
        dataRange[0] = defaultUnitRange[0] * override_scale + override_offset;
        dataRange[1] = defaultUnitRange[1] * override_scale + override_offset;
      }
    }
    /*
    System.out.println(Scalar + " -> " + DisplayScalar + " range: " + dataRange[0] +
                       " to " + dataRange[1] + " scale: " + scale + " " + offset);
    */
    if (DisplayScalar.equals(Display.Animation) && shadow != null) {
      if (control != null && ((AnimationControl) control).getComputeSet()) {
        Set set = shadow.animationSampling;
        /* DRM: 04 Jan 2003
        if (set == null) {
          return;
        }
        */
        ((AnimationControl) control).setSet(set, true);
      }
    } else if (DisplayScalar.equals(Display.IsoContour)) {
      if (control != null) {

        // WLH 10 July 2002
        // don't set if application has called control.setLevels()
        float[] lowhibase = new float[3];
        boolean[] dashes = new boolean[1];

        boolean public_set = ((ContourControl) control).getPublicSet();
        if (!public_set) {
          boolean[] bvalues = new boolean[2];
          float[] values = new float[5];
          ((ContourControl) control).getMainContours(bvalues, values);
          if (shadow == null) {
            // don't set surface value for auto-scale
            values[0] = (float) dataRange[0]; // surfaceValue
          }
          // CTR: 29 Jul 1999: interval should never be zero
          float f = (float) (dataRange[1] - dataRange[0]) / 10.0f;
          if (f != 0.0f) values[1] = f; // contourInterval
          values[2] = (float) dataRange[0]; // lowLimit
          values[3] = (float) dataRange[1]; // hiLimit
          values[4] = (float) dataRange[0]; // base
          ((ContourControl) control).setMainContours(bvalues, values, true, true);
        }
      }
    } else if (DisplayScalar.equals(Display.XAxis)
        || DisplayScalar.equals(Display.YAxis)
        || DisplayScalar.equals(Display.ZAxis)) {
      if (dataRange[0] != Double.MAX_VALUE
          && dataRange[1] != -Double.MAX_VALUE
          && dataRange[0] == dataRange[0]
          && dataRange[1] == dataRange[1]
          && dataRange[0] != dataRange[1]
          && scale == scale
          && offset == offset) {
        if (display != null) {
          makeScale();
        } else {
          scale_flag = true;
        }
        back_scale_flag = true;
      }
    }

    if (dataRange[0] == dataRange[0] && dataRange[1] == dataRange[1] && ListenerVector != null) {
      ScalarMapEvent evt;
      evt =
          new ScalarMapEvent(
              this, (shadow == null ? ScalarMapEvent.MANUAL : ScalarMapEvent.AUTO_SCALE), remoteId);
      Vector listeners_clone = null;
      synchronized (ListenerVector) {
        listeners_clone = (Vector) ListenerVector.clone();
      }
      Enumeration listeners = listeners_clone.elements();
      while (listeners.hasMoreElements()) {
        ScalarMapListener listener = (ScalarMapListener) listeners.nextElement();
        listener.mapChanged(evt);
      }
    }
  }