public static void drawWave (Graphics g, Wave wave,
                        int x, int y, int width, int height,
			int viewStart, int viewEnd,
			boolean selected,
                        int selectStart, int selectEnd)
  {
    double[] w;

    if (wave != null && (w = wave.getWave()) != null) {
      double samplePosition = viewStart;
      double sampleIncrement = (viewEnd - viewStart + 1) / (double) width;
      double amplitudeRatio = -(height/2-1) / wave.getMaxAmplitude();

      if (selected) {
        int x1 = sampleNoToCoord (selectStart, width,
	                          wave.length(), viewStart, viewEnd);
        if (x1 < width) {
          if (x1 < 0) x1 = 0;
	  int x2 = sampleNoToCoord (selectEnd, width, wave.length(), 
	                                       viewStart, viewEnd);
	  if (x2 >= width) x2 = width - 1;
          g.setColor (selectedBgColor);
          g.fillRect (x + x1, y, x2 - x1 + 1, height - 1);
        }
      }

      g.setColor (axisColor);
      g.drawLine (x, y+height/2, x+width-1, y+height/2);

      g.setColor (waveColor);

      double sum;

      int oldV = (int)(w[(int)samplePosition] * amplitudeRatio) +
                       height/2;
      int cx = x;
      for (int i = 1; i < width; i++, cx++) {
        samplePosition += sampleIncrement;
        int v = (int)(w[(int)samplePosition] * amplitudeRatio) +
	              height/2;
        g.drawLine (cx, oldV + y, cx+1, v + y);
	oldV = v;
      }
    }
    else {
      g.setColor (axisColor);
      g.drawLine (x, y+height/2, x+width-1, y+height/2);
    }


  }