コード例 #1
0
  private void zoomTo(double percent) {
    // Find the new resolution
    // Number of point / Display Width / zoom
    double res = (wave.getNbOfPoints() / (getInnerWidth() - 0.1));
    if (res <= 1) res = Math.round(res - 0.2);
    else if (res <= 10) res -= 2;
    else res = res / (percent / 100);

    setResolution(res);
  }
コード例 #2
0
  public void draw(Graphics g) {

    // backup current style
    Color c = g.getColor();
    Font f = g.getFont();
    Shape clip = g.getClip();

    // Draw Backgound
    g.setColor(backgroundColor);
    g.fillRect(0, 0, getWidth(), getHeight());

    // g.setClip(paddingLeft, paddingRight, getWidth()-paddingLeft-paddingRight,
    // getHeight()-paddingTop-paddingBottom);

    // Prepare positioning
    int defX = getInnerX();
    int defY = getInnerY();
    int defWidth = getInnerWidth();
    int defHeight = getInnerHeight();
    ;
    int half = defHeight / 2;

    // Draw Half line
    g.setColor(centerLineColor);
    g.drawLine(defX, defY + half, defX + defWidth, defY + half);

    int avgY = 0;
    //		int lastAvgY = 0;
    if (wave != null) {
      /*
       * Initialise positioning
       */
      int x = 0;
      int y = 0;
      int lastY = 0;

      /*
       * Y Ratio
       * 255 = 100
       * defHeight   = x
       *
       * defHeight * 100 / 255 = Percent Result
       * Percent Result / 100 to find the multiplicator
       */
      double yRatio = Sample.getYRatio(wave, defHeight); // (double)defHeight / (double)255;	

      /*
       * Number of point to read
       *
       *  That depend of the resolution (point per pixel)
       */
      int point2read = 1;
      if (resolution > 1) point2read = (int) Math.ceil(resolution);

      // Adjust start Display
      int startOffset = 0;
      if (xOffset > 0 && point2read > 0) startOffset = (point2read * xOffset);
      else if (xOffset > 0) startOffset = xOffset;

      ArrayList<SampleRange> ranges =
          SampleRange.getList(wave, point2read, startOffset, point2read * defWidth);
      for (int i = 0; i < ranges.size(); i++) {
        SampleRange range = ranges.get(i);

        // set y, min, max and averageY
        y = (int) range.getAverage(1);
        int min = (int) range.getMinimum(1);
        int max = (int) range.getMaximum(1);
        avgY = (int) range.getAverage(1);

        // inverse display and resize with yRatio
        y = (int) ((double) (y * -1) * yRatio);
        max = (int) ((double) (max * -1) * yRatio);
        min = (int) ((double) (min * -1) * yRatio);
        avgY = (int) ((double) (avgY * -1) * yRatio);

        // set space between point
        int xSpace = 1;
        if (resolution < 1) {
          xSpace = (int) Math.floor(10 - (resolution * 10)) * 10;
          if (xSpace < 10) xSpace = 10;
        }

        // draw lines
        g.setColor(waveColor);
        // join
        if (resolution < 25)
          g.drawLine(defX + x, defY + half + y, defX + x - xSpace, defY + half + lastY);
        // fill
        g.drawLine(defX + x, defY + half + min, defX + x, defY + half + max);

        // if resolution is negative, the draw point
        if (resolution < 1) {
          // draw point
          g.setColor(pointColor);
          g.fillOval(defX + x - 2, defY + half + y - 2, 4, 4);
        } else if (resolution > 1) {
          // draw average
          g.setColor(waveAverageColor);
          if (max < 0 && min > 0) {
            int avgmin, avgmax;
            avgmax = avgY - ((max - avgY) / 2);
            avgmin = avgY - ((min + avgY) / 2);
            g.drawLine(defX + x, defY + half + avgmin, defX + x, defY + half + avgmax);
          } else if (max < 1) g.drawLine(defX + x, defY + half + min, defX + x, defY + half + avgY);
          else if (min > 0) g.drawLine(defX + x, defY + half + max, defX + x, defY + half + avgY);

          // save Average
          //						lastAvgY = avgY;
        }

        // save y
        lastY = y;

        // add xSpace to x
        x += xSpace;
      }
    }

    // restore saved style
    g.setClip(clip);
    g.setColor(c);
    g.setFont(f);
  }
コード例 #3
0
 /** @param resolution the resolution to set */
 public void setResolution(double newResolution) {
   this.resolution = newResolution;
   if (this.resolution < 0.1) this.resolution = 0.1;
   if (this.resolution > wave.getData().getDataSize() / 30)
     this.resolution = wave.getData().getDataSize() / 30;
 }