public void annihilate() {
   try {
     display.removeReference(selector);
     display.removeReference(line);
   } catch (Exception e) {
     LogUtil.logException("DragLine.annihilate", e);
   }
 }
  public void refreshDisplay() throws VisADException, RemoteException {
    if (display == null) return;

    synchronized (displayedThings) {
      for (DataReference ref : displayedThings) {
        display.removeReference(ref);
        display.addReference(ref, colorMaps.get(ref));
      }
    }
  }
  public void reorderDataRefsById(final List<String> dataRefIds) {
    if (dataRefIds == null) throw new NullPointerException("");

    synchronized (displayedThings) {
      try {
        displayedThings.clear();
        for (String refId : dataRefIds) {
          DataReference ref = idToRef.get(refId);
          ConstantMap[] color = colorMaps.get(ref);
          display.removeReference(ref);
          display.addReference(ref, color);
        }
      } catch (Exception e) {
      }
    }
  }
  public void removeRef(final DataReference thing) throws VisADException, RemoteException {
    if (display == null) return;

    synchronized (displayedThings) {
      displayedThings.remove(thing);
      colorMaps.remove(thing);
      idToRef.remove(thing.getName());
      display.removeReference(thing);
    }
  }
Пример #5
0
    private void toggleDisplay(LocalDisplay dpy, boolean showFirstGIF) {
      java.util.Vector v = dpy.getRenderers();

      final int size = v.size();
      if (size != 2) {
        System.err.println("Expected 2 DataRenderers, but Display has " + size);
        return;
      }

      ((DataRenderer) v.get(0)).toggle(showFirstGIF);
      ((DataRenderer) v.get(1)).toggle(!showFirstGIF);
    }
    public DragLine(
        final MultiSpectralDisplay msd,
        final String controlId,
        final ConstantMap[] color,
        float[] YRANGE)
        throws Exception {
      if (msd == null)
        throw new NullPointerException("must provide a non-null MultiSpectralDisplay");
      if (controlId == null) throw new NullPointerException("must provide a non-null control ID");
      if (color == null) throw new NullPointerException("must provide a non-null color");

      this.controlId = controlId;
      this.multiSpectralDisplay = msd;
      this.YRANGE = YRANGE;
      lastSelectedValue = multiSpectralDisplay.getWaveNumber();

      for (int i = 0; i < color.length; i++) {
        mappings[i] = (ConstantMap) color[i].clone();
      }
      mappings[4] = new ConstantMap(-0.5, Display.YAxis);

      Gridded1DSet domain = multiSpectralDisplay.getDomainSet();

      domainType = multiSpectralDisplay.getDomainType();
      rangeType = multiSpectralDisplay.getRangeType();
      tupleType = new RealTupleType(domainType, rangeType);

      selector = new DataReferenceImpl(selectorId);
      line = new DataReferenceImpl(lineId);

      display = multiSpectralDisplay.getDisplay();

      display.addReferences(
          new GrabLineRendererJ3D(domain),
          new DataReference[] {selector},
          new ConstantMap[][] {mappings});
      display.addReference(line, cloneMappedColor(color));

      addReference(selector);
    }
    public RubberBandBox(final MultiSpectralDisplay msd, final ScalarMap x, final ScalarMap y)
        throws VisADException, RemoteException {
      RealType domainType = msd.getDomainType();
      RealType rangeType = msd.getRangeType();

      LocalDisplay display = msd.getDisplay();

      rubberBand = new DataReferenceImpl(hashCode() + RBB);
      rubberBand.setData(
          new RealTuple(
              new RealTupleType(domainType, rangeType), new double[] {Double.NaN, Double.NaN}));

      display.addReferences(
          new RubberBandBoxRendererJ3D(domainType, rangeType, 1, 1),
          new DataReference[] {rubberBand},
          null);

      xmap = x;
      ymap = y;

      this.addReference(rubberBand);
    }
  public void addRef(final DataReference thing, final Color color)
      throws VisADException, RemoteException {
    if (display == null) return;

    synchronized (displayedThings) {
      ConstantMap[] colorMap = makeColorMap(color);

      displayedThings.add(thing);
      idToRef.put(thing.getName(), thing);
      ConstantMap[] constMaps;
      if (data.hasBandNames()) {
        constMaps = new ConstantMap[colorMap.length + 2];
        System.arraycopy(colorMap, 0, constMaps, 0, colorMap.length);
        constMaps[colorMap.length] = new ConstantMap(1f, Display.PointMode);
        constMaps[colorMap.length + 1] = new ConstantMap(5f, Display.PointSize);
      } else {
        constMaps = colorMap;
      }
      colorMaps.put(thing, constMaps);

      display.addReference(thing, constMaps);
    }
  }
 public void displayChanged(final DisplayEvent e) throws VisADException, RemoteException {
   // TODO: write a method like isChannelUpdate(EVENT_ID)? or maybe just
   // deal with a super long if-statement and put an "OR MOUSE_RELEASED"
   // up here?
   if (e.getId() == DisplayEvent.MOUSE_RELEASED_CENTER) {
     float val = (float) display.getDisplayRenderer().getDirectAxisValue(domainType);
     setWaveNumber(val);
     if (displayControl != null) displayControl.handleChannelChange(val);
   } else if (e.getId() == DisplayEvent.MOUSE_PRESSED_LEFT) {
     if (e.getInputEvent().isControlDown()) {
       xmap.setRange(initialRangeX[0], initialRangeX[1]);
       ymap.setRange(initialRangeY[0], initialRangeY[1]);
     }
   } else if (e.getId() == DisplayEvent.MOUSE_RELEASED) {
     float val = getSelectorValue(channelSelector);
     if (val != waveNumber) {
       // TODO: setWaveNumber needs to be rethought, as it calls
       // setSelectorValue which is redundant in the cases of dragging
       // or clicking
       setWaveNumber(val);
       if (displayControl != null) displayControl.handleChannelChange(val);
     }
   }
 }
 public float getSelectedValue() {
   float val = (float) display.getDisplayRenderer().getDirectAxisValue(domainType);
   if (Float.isNaN(val)) val = lastSelectedValue;
   return val;
 }
  private void init() throws VisADException, RemoteException {

    HydraDataSource source = (HydraDataSource) dataChoice.getDataSource();

    // TODO revisit this, may want to move method up to base class HydraDataSource
    if (source instanceof SuomiNPPDataSource) {
      data = ((SuomiNPPDataSource) source).getMultiSpectralData(dataChoice);
    }

    if (source instanceof MultiSpectralDataSource) {
      data = ((MultiSpectralDataSource) source).getMultiSpectralData(dataChoice);
    }

    waveNumber = data.init_wavenumber;

    try {
      spectrum = data.getSpectrum(new int[] {1, 1});
    } catch (Exception e) {
      LogUtil.logException("MultiSpectralDisplay.init", e);
    }

    domainSet = (Gridded1DSet) spectrum.getDomainSet();
    initialRangeX = getXRange(domainSet);
    initialRangeY = data.getDataRange();

    domainType = getDomainType(spectrum);
    rangeType = getRangeType(spectrum);

    master = new XYDisplay(DISP_NAME, domainType, rangeType);

    setDisplayMasterAttributes(master);

    // set up the x- and y-axis
    xmap = new ScalarMap(domainType, Display.XAxis);
    ymap = new ScalarMap(rangeType, Display.YAxis);

    xmap.setRange(initialRangeX[0], initialRangeX[1]);
    ymap.setRange(initialRangeY[0], initialRangeY[1]);

    display = master.getDisplay();
    display.addMap(xmap);
    display.addMap(ymap);
    display.addDisplayListener(this);

    new RubberBandBox(this, xmap, ymap);

    if (displayControl == null) { // - add in a ref for the default spectrum, ie no DisplayControl
      DataReferenceImpl spectrumRef = new DataReferenceImpl(hashCode() + "_spectrumRef");
      spectrumRef.setData(spectrum);
      addRef(spectrumRef, Color.WHITE);
    }

    if (data.hasBandNames()) {
      bandSelectComboBox = new JComboBox(data.getBandNames().toArray());
      bandSelectComboBox.setSelectedItem(data.init_bandName);
      bandSelectComboBox.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String bandName = (String) bandSelectComboBox.getSelectedItem();
              if (bandName == null) return;

              HashMap<String, Float> bandMap = data.getBandNameMap();
              if (bandMap == null) return;

              if (!bandMap.containsKey(bandName)) return;

              setWaveNumber(bandMap.get(bandName));
            }
          });
    }
  }