/** * Set <CODE>Vector</CODE> of <CODE>String</CODE>s describing the cursor location from the cursor * location; this is invoked when the cursor location changes or the cursor display status changes */ public void setCursorStringVector() { synchronized (cursorStringVector) { cursorStringVector.removeAllElements(); float[][] cursor = new float[3][1]; double[] cur = getCursor(); cursor[0][0] = (float) cur[0]; cursor[1][0] = (float) cur[1]; cursor[2][0] = (float) cur[2]; Enumeration maps = display.getMapVector().elements(); while (maps.hasMoreElements()) { try { ScalarMap map = (ScalarMap) maps.nextElement(); DisplayRealType dreal = map.getDisplayScalar(); DisplayTupleType tuple = dreal.getTuple(); int index = dreal.getTupleIndex(); if (tuple != null && (tuple.equals(Display.DisplaySpatialCartesianTuple) || (tuple.getCoordinateSystem() != null && tuple .getCoordinateSystem() .getReference() .equals(Display.DisplaySpatialCartesianTuple)))) { float[] fval = new float[1]; if (tuple.equals(Display.DisplaySpatialCartesianTuple)) { fval[0] = cursor[index][0]; } else { float[][] new_cursor = tuple.getCoordinateSystem().fromReference(cursor); fval[0] = new_cursor[index][0]; } float[] dval = map.inverseScaleValues(fval); RealType real = (RealType) map.getScalar(); // WLH 31 Aug 2000 Real r = new Real(real, dval[0]); Unit overrideUnit = map.getOverrideUnit(); Unit rtunit = real.getDefaultUnit(); // units not part of Time string // DRM 2003-08-19: don't check for equality since toString // may be different if (overrideUnit != null && // !overrideUnit.equals(rtunit) && (!Unit.canConvert(rtunit, CommonUnit.secondsSinceTheEpoch) || rtunit.getAbsoluteUnit().equals(rtunit))) { dval[0] = (float) overrideUnit.toThis((double) dval[0], rtunit); r = new Real(real, dval[0], overrideUnit); } String valueString = r.toValueString(); // WLH 27 Oct 2000 String s = map.getScalarName() + " = " + valueString; // String s = real.getName() + " = " + valueString; cursorStringVector.addElement(s); } // end if (tuple != null && ...) } catch (VisADException e) { } } // end while(maps.hasMoreElements()) } // end synchronized (cursorStringVector) render_trigger(); }
/** * Set display Unit to override default Unit of Scalar; MUST be called before any data are * displayed * * @param unit unit that data will be displayed with * @throws VisADException <CODE>unit</CODE> is not convertable with the default unit or scalar is * not a RealType. */ public void setOverrideUnit(Unit unit) throws VisADException { if (!(Scalar instanceof RealType)) { throw new UnitException("Scalar is not RealType"); } Unit rtunit = ((RealType) Scalar).getDefaultUnit(); if (!Unit.canConvert(unit, rtunit)) { throw new UnitException("unit not convertable with RealType default"); } if (unit != null) { overrideUnit = unit; override_offset = overrideUnit.toThis(0.0, rtunit); override_scale = overrideUnit.toThis(1.0, rtunit) - override_offset; } }
/** 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); } } }