/**
   * Action method invoked when an event triggers this action.
   *
   * <p>The {@link #_compartment} instance variable defines the action to take, and the {@link
   * #_display} instance variable whether it should set visibility or note.
   *
   * <p><em>Note</em>. The {@link #_display} instance variable is really redundant. Its value is
   * implied by the operation.
   *
   * @param ae The event that triggered us.
   */
  public void actionPerformed(ActionEvent ae) {

    // Only do anything if we have a single item selected (surely this
    // should work for multiple selections as well?).

    Vector sels = Globals.curEditor().getSelectionManager().selections();

    if (sels.size() == 1) {
      Selection sel = (Selection) sels.firstElement();
      Fig f = sel.getContent();

      // Perform the action

      if (_compartment.equals("Show Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Hide Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Show Operation Compartment")
          || _compartment.equals("Hide Operation Compartment")) {
        if (f instanceof FigClass) ((FigClass) f).setOperationVisible(_display);
        if (f instanceof FigInterface) ((FigInterface) f).setOperationVisible(_display);
      } else if (_compartment.equals("Show Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Hide Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Show All Compartments")) {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      } else {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      }
    }
  }
Example #2
0
  private ArrayList<SoundSample> getSampleAsArrayList(Selection selection, Component c) {
    ArrayList<SoundSample> points = new ArrayList<SoundSample>();

    // System.err.println(c.getHeight());
    int sampleBeginIndex = selection.getBegin();
    int sampleEndIndex = selection.getEnd();

    if (!checkRange(sampleBeginIndex, sampleEndIndex)) {
      System.err.println(
          "The range of sample ("
              + sampleBeginIndex
              + " , "
              + sampleEndIndex
              + ") you are trying to visualize is invalid");
    } else {
      int selectionLength = sampleEndIndex - sampleBeginIndex + 1;
      float maxValue = myHelper.getMaxSampleValue();
      samplePerPixel = selectionLength * 1.0 / frameWidth;
      if (DEBUG) System.err.println("getSamples: sample per pixel " + samplePerPixel);

      if (selectionLength
          < frameWidth) { // if every sample can be displayed (i.e at least 1 pixel per sample)
        if (DEBUG) System.err.println("getSamples: Everything can be displayed " + selectionLength);
        int ratio = (int) Math.floor(frameWidth / selectionLength);
        if (DEBUG) System.err.println("getSamples: ratio " + ratio);
        int occupyPixels = ratio * selectionLength;
        selectionLength =
            selectionLength
                + (frameWidth - occupyPixels)
                    / ratio; // fill up the display space with a few more samples

        if (DEBUG) System.err.println("getSamples: selection length " + selectionLength);

        if (selectionLength + sampleBeginIndex - 1 > data.size()) {
          selectionLength -= selectionLength + sampleBeginIndex - 1 - data.size();
        }
        if (DEBUG) System.err.println("getSamples: Final selection length " + selectionLength);
        for (int i = 0; i < selectionLength; i++) {
          float sampleValue = data.get(sampleBeginIndex + i - 1);
          float y = ((float) Math.floor(c.getHeight() / 2) * (1 - sampleValue / maxValue));
          points.add(
              new SoundSample(new Point2D.Float(i * ratio, y), sampleValue, sampleBeginIndex + i));
        }
      } else if (selectionLength / 2 < frameWidth) { // we can sample at Nyquist rate
        // System.err.println("Sample begin " + sampleBeginIndex );

        int start = sampleBeginIndex;
        for (int pixel = 0; pixel < frameWidth; pixel++) {
          // System.err.println("Sample index " + (start+ samplePerPixel * pixel) );

          int sampleValue = data.get((int) Math.floor(start + samplePerPixel * pixel));
          // int sampleValue = findMax(start, end);
          float y =
              ((float) Math.floor(c.getHeight() / 2)
                  - (sampleValue * ((float) Math.floor(c.getHeight() / 2) / maxValue)));
          points.add(new SoundSample(new Point2D.Float(pixel, y), sampleValue, pixel));
        }
      } else { // show general contour
        int start = sampleBeginIndex;
        int end = (int) (sampleBeginIndex + this.samplePerPixel);
        int baseLine = c.getHeight() / 2;
        for (int pixel = 0; pixel < frameWidth; pixel++) {
          ArrayList<Integer> minMax = findMinMax(start, end);
          // System.err.println(minMax);
          float y = baseLine - (minMax.get(0) * 0.9f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(0), pixel));

          y = baseLine - (minMax.get(0) * 0.7f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(0) / 2, pixel));

          // System.err.print("Min y: " + y + " ");

          y = baseLine - (minMax.get(1) * 0.9f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(1) / 2, pixel));
          y = baseLine - (minMax.get(1) * 0.7f / maxValue * baseLine);
          points.add(new SoundSample(new Point2D.Float(pixel, y), minMax.get(1), pixel));

          //					if (y > c.getHeight())
          //						System.err.println("not right");
          start = end + 1;
          end = (int) (end + samplePerPixel);
        }
      }
    }
    return points;
  }
  public static void zoomToFit(Viewport2 viewport) {
    ViewDefinition viewdef = viewport.getViewDefinition();
    // if (MainFrame.getInstance().getMeshToolBar().getMode() != MeshToolBar.VIEW_ZOOM) {
    //	MainFrame.getInstance().getJPatchScreen().removeAllMouseListeners();
    //	MainFrame.getInstance().getJPatchScreen().addMouseListeners(new
    // ChangeViewMouseListener(MouseEvent.BUTTON1,ChangeViewMouseListener.ZOOM));
    //	MainFrame.getInstance().getMeshToolBar().setMode(MeshToolBar.VIEW_ZOOM);
    // } else {
    //	MainFrame.getInstance().getMeshToolBar().reset();
    // }
    Selection selection = MainFrame.getInstance().getSelection();
    float left = Float.MAX_VALUE;
    float right = -Float.MAX_VALUE;
    float bottom = Float.MAX_VALUE;
    float top = -Float.MAX_VALUE;
    Point3f p3 = new Point3f();
    Matrix4f m4View = viewdef.getScreenMatrix();
    // Matrix3f m3RotScale = new Matrix3f();
    // m4View.getRotationScale(m3RotScale);
    boolean doit = true;
    if (selection != null && !selection.isSingle()) {
      for (Iterator it = selection.getObjects().iterator(); it.hasNext(); ) {
        Object object = it.next();
        if (object instanceof ControlPoint) {
          p3.set(((ControlPoint) object).getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
        }
      }
    } else {
      ArrayList heads = MainFrame.getInstance().getModel().allHeads();
      int p = 0;
      for (Iterator it = heads.iterator(); it.hasNext(); ) {
        ControlPoint cp = (ControlPoint) it.next();
        if (!cp.isHidden()) {
          p3.set(cp.getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
          p++;
        }
      }
      doit = (p >= 2);
    }
    if (doit) {
      // System.out.println(left + " " + right + " " + top + " " + bottom + " " +
      // viewdef.getScale());
      // System.out.println(viewdef.getTranslateX() + " " + viewdef.getTranslateY());
      float centerX = (left + right) / 2f;
      float centerY = (top + bottom) / 2f;
      float dimX = viewdef.getWidth() / 2f;
      float dimY = viewdef.getHeight() / 2f;
      float sizeX = right - centerX;
      float sizeY = top - centerY;
      if (sizeX > 0 || sizeY > 0) {
        // System.out.println(centerX + ":" + centerY);

        float scaleX = dimX / sizeX;
        float scaleY = dimY / sizeY;
        float scale = Math.min(scaleX, scaleY) * 0.9f;
        // viewdef.setScale(viewdef.getScale() * scale);
        viewdef.setLock(null);
        viewdef.moveView(-centerX / dimX + 1, (dimY - centerY) / dimX, false);
        viewdef.scaleView(scale);
        // viewdef.setTranslation(centerX, centerY);
        // viewdef.computeMatrix();
        // viewport.render();
      }
    }
  }