예제 #1
0
파일: ChannelView.java 프로젝트: usgs/xmax
 /**
  * @param x time coordinate of point (in pixels inside graph area panel)
  * @return Set of events in this point
  */
 public Set<IEvent> getEvents(int x) {
   Set<EventWrapper> eventWrappers = graphAreaPanel.getEvents(x);
   if (eventWrappers == null) return null;
   Set<IEvent> ret = new HashSet<IEvent>();
   for (EventWrapper eventWrapper : eventWrappers) {
     ret.add(eventWrapper.getEvent());
   }
   return ret;
 }
예제 #2
0
파일: ChannelView.java 프로젝트: usgs/xmax
    public void paint(Graphics g) {
      logger.debug("Repainting " + this);
      super.paint(g);
      // maxValue = Integer.MIN_VALUE;
      // minValue = Integer.MAX_VALUE;
      height = this.getHeight();
      width = this.getWidth();
      IScaleModeState scaleMode = graphPanel.getScaleMode();
      IMeanState meanState = graphPanel.getMeanState();
      IOffsetState offsetState = graphPanel.getOffsetState();
      scaleMode.init(
          graphs,
          (graphPanel.getOverlayState() == true) || (graphPanel.getSelectState() == true)
              ? graphPanel.getCurrentChannelShowSet()
              : graphPanel.getChannelShowSet(),
          graphPanel.getTimeRange(),
          meanState,
          height);

      // lg.debug("scaleMode Initialized:" + scaleMode.getStateName() + scaleMode.getMaxValue() +
      // scaleMode.getMinValue());
      if (scaleMode.getMinValue() != Double.POSITIVE_INFINITY
          && scaleMode.getMaxValue() != Double.NEGATIVE_INFINITY) {
        axis.setRange(scaleMode.getMinValue(), scaleMode.getMaxValue());
      }
      // Offset step is 1/20 of graph height
      offsetState.setShift((scaleMode.getMaxValue() - scaleMode.getMinValue()) / 20);
      logger.debug(
          "Set ChannelView "
              + this
              + " boundaries: "
              + scaleMode.getMaxValue()
              + "-"
              + scaleMode.getMinValue());
      // Graph's number, used to separate graphs then overlay mode is activated
      int graphNum = 0;
      Color segmentColor = null;
      if (graphPanel.initialPaint) {
        System.out.print("...");
      }

      for (PlotData data : graphs) {
        int i = 0;

        // strokes for previous pixel
        List<Stroke> yprev = new ArrayList<Stroke>();
        for (PlotDataPoint[] points : data.getPixels()) {
          int j = 0;
          for (PlotDataPoint point : points) {
            // add previous stroke to list if list has unsuffisient length
            if (yprev.size() == j || yprev.get(j) == null) {
              yprev.add(j, new Stroke());
            }
            Stroke current = new Stroke();
            if (point.getSegmentNumber() >= 0) {
              segmentColor =
                  graphPanel
                      .getColorMode()
                      .getSegmentColor(
                          graphNum + point.getSegmentNumber(),
                          graphNum + point.getRawDataProviderNumber(),
                          graphNum + point.getContinueAreaNumber(),
                          data.getTraceColor());
              if (point.getSegmentNumber() == 0 && data.getLabelColor() == null) {
                data.setLabelColor(segmentColor);
              }
              g.setColor(segmentColor);
              // reinit previous stroke if color differs
              if ((yprev.get(j).color != null) && (yprev.get(j).color != segmentColor)) {
                yprev.set(j, new Stroke());
              }
              current.color = segmentColor;
              current.top =
                  scaleMode.getY(
                      meanState.getValue(
                          offsetState.getValue(point.getTop(), point.getSegmentNumber()),
                          data.getMeanValue()));
              current.bottom =
                  scaleMode.getY(
                      meanState.getValue(
                          offsetState.getValue(point.getBottom(), point.getSegmentNumber()),
                          data.getMeanValue()));
              // lg.debug("Drawing pixel " + j + ": " + point.getTop() + "-" + point.getBottom() +
              // ", " + current);
              g.drawLine(i, current.top, i, current.bottom);
              if (i > 0) {
                // fill vertical gaps
                if (current.bottom < yprev.get(j).top) {
                  // lg.debug("Fill gap at top: " +  yprev.get(j).top + "-" + current.bottom);
                  g.drawLine(i - 1, yprev.get(j).top, i, current.bottom);
                }
                if (current.top > yprev.get(j).bottom) {
                  // lg.debug("Fill gap at bottom: " + yprev.get(j).bottom + "-" + current.top);
                  g.drawLine(i - 1, yprev.get(j).bottom, i, current.top);
                }
              }
              yprev.set(j, current);
            } else {
              // we have gap, set previous values to it's default
              yprev.set(j, new Stroke());
            }
            // drawing events
            // long currentTime = getTime(i);
            for (EventWrapper eventWrapper : point.getEvents()) {
              logger.debug("drawing event front");
              g.setColor(eventWrapper.getEvent().getColor());
              if (eventWrapper.getEvent().getType().equals("ARRIVAL")
                  && graphPanel.getPhaseState()) {
                // drawing phases
                if (graphPanel
                        .getSelectedEarthquakes()
                        .contains(eventWrapper.getEvent().getParameterValue("EARTHQUAKE"))
                    && graphPanel
                        .getSelectedPhases()
                        .contains(eventWrapper.getEvent().getParameterValue("PHASE"))) {
                  g.drawLine(i, getHeight(), i, 0);
                  g.drawString(
                      (String) eventWrapper.getEvent().getParameterValue("PHASE"),
                      i + 2,
                      getHeight() - 5);
                }
              } else if (eventWrapper.getEvent().getType().equals("PICK")
                  && graphPanel.getPickState()) {
                // drawing picks
                g.drawLine(i, getHeight(), i, 0);
                Polygon p = new Polygon();
                p.addPoint(i, 0);
                p.addPoint(i + 4, 4);
                p.addPoint(i, 8);
                g.fillPolygon(p);
              } else {
                paintCustomEvent(g, eventWrapper, i, current.top, current.bottom);
                g.setColor(segmentColor);
              }
            }
            j++;
          }
          while (j < yprev.size()) {
            yprev.set(j, new Stroke());
            j++;
          }
          i++;
        }
        graphNum++;
      }

      if (plotDataProviders != null) {
        logger.debug("drawing channel labels");
        g.setFont(GraphPanel.getAxisFont());
        fontHeight = g.getFontMetrics().getHeight();
        int i = 1;
        for (PlotData data : graphs) {
          g.setColor(data.getLabelColor());
          g.drawString(
              data.getLabel()
                  + (plotDataProviders.get(i - 1).isRotated()
                      ? " (ROT "
                          + plotDataProviders.get(i - 1).getRotation().getRotationAngleText()
                          + ")"
                      : ""),
              (plotDataProviders.get(i - 1).isRotated() ? getWidth() - 150 : getWidth() - 120),
              i++ * fontHeight);
        }
        // drawing Y axis labels
        g.setColor(Color.BLACK);
        if (scaleMode.getMaxValue() != Double.POSITIVE_INFINITY
            && scaleMode.getMaxValue() != Double.NEGATIVE_INFINITY
            && !Double.isInfinite(scaleMode.getMinValue())) {
          g.drawString(new Double(scaleMode.getMaxValue()).toString(), 10, fontHeight);
        }
        if (scaleMode.getMinValue() != Double.POSITIVE_INFINITY
            && scaleMode.getMinValue() != Double.NEGATIVE_INFINITY
            && !Double.isInfinite(scaleMode.getMinValue())) {
          g.drawString(new Double(scaleMode.getMinValue()).toString(), 10, getHeight() - 10);
        }
        // drawing marks
        for (MarkPosition mp : markPositions) {
          Image image = graphPanel.getMarkPositionImage();
          g.drawImage(
              image,
              graphPanel.getXposition(mp.getTime()) - image.getHeight(this) / 2,
              graphPanel.getScaleMode().getY(mp.getValue()) - image.getHeight(this) / 2,
              this);
        }
      }
      logger.debug("Repainting end " + this);
    }