@Override
 public final Collection<Handle> createSecondaryHandles() {
   LinkedList<Handle> list = new LinkedList<Handle>();
   if (((ConnectionFigure) getOwner()).getLiner() == null && savedLiner == null) {
     int index = getBezierNodeIndex();
     BezierFigure f = getBezierFigure();
     BezierPath.Node v = f.getNode(index);
     if ((v.mask & BezierPath.C1_MASK) != 0 && (index != 0 || f.isClosed())) {
       list.add(new BezierControlPointHandle(f, index, 1));
     }
     if ((v.mask & BezierPath.C2_MASK) != 0 && (index < f.getNodeCount() - 1 || f.isClosed())) {
       list.add(new BezierControlPointHandle(f, index, 2));
     }
     if (index > 0 || f.isClosed()) {
       int i = (index == 0) ? f.getNodeCount() - 1 : index - 1;
       v = f.getNode(i);
       if ((v.mask & BezierPath.C2_MASK) != 0) {
         list.add(new BezierControlPointHandle(f, i, 2));
       }
     }
     if (index < f.getNodeCount() - 2 || f.isClosed()) {
       int i = (index == f.getNodeCount() - 1) ? 0 : index + 1;
       v = f.getNode(i);
       if ((v.mask & BezierPath.C1_MASK) != 0) {
         list.add(new BezierControlPointHandle(f, i, 1));
       }
     }
   }
   return list;
 }
Exemplo n.º 2
0
 public void printLoop(int n, float x[], float y[]) {
   // Need to swap the y component
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_draw.add(P);
   poly_draw_color.add(curColor);
 }
Exemplo n.º 3
0
  void createBend(int bendx, int bendy) {
    Bend bn = null;
    int index = 0;
    if (bends == null) {
      if (driver.nearpln(bendx, bendy, fromX, fromY, toX, toY)) {
        bends = new LinkedList<Bend>();
        bn = new Bend(bendx, bendy);
        if (fromX == toX) // if line vertical
        bn.x = fromX;
        if (fromY == toY) // if line horizontal
        bn.y = fromY;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
        return;
      }
    } else {
      int x = fromX;
      int y = fromY;
      Object[] oa = bends.toArray();
      for (Object o : oa) {
        Bend b = (Bend) o;
        if (sameBend(bendx, bendy, b)) {
          bn = b;
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        if (driver.nearpln(bendx, bendy, x, y, b.x, b.y)) {
          bn = new Bend(bendx, bendy);
          if (x == b.x) // if line vertical
          bn.x = x;
          if (y == b.y) // if line horizontal
          bn.y = y;
          bends.add(index, bn);
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        x = b.x;
        y = b.y;
        index++;
      }

      if (driver.nearpln(bendx, bendy, x, y, toX, toY)) {
        bn = new Bend(bendx, bendy);
        if (x == toX) // if line vertical
        bn.x = x;
        if (y == toY) // if line horizontal
        bn.y = y;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
      }
    }
  }
 public java.util.List<Figure> findFigures(Rectangle2D.Double r) {
   LinkedList<Figure> c = new LinkedList<Figure>(quadTree.findIntersects(r));
   switch (c.size()) {
     case 0:
       // fall through
     case 1:
       return c;
     default:
       return sort(c);
   }
 }
 public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) {
   LinkedList<Figure> contained = new LinkedList<Figure>();
   for (Figure f : children) {
     Rectangle2D r = f.getBounds();
     if (AttributeKeys.TRANSFORM.get(f) != null) {
       r = AttributeKeys.TRANSFORM.get(f).createTransformedShape(r).getBounds2D();
     }
     if (f.isVisible() && bounds.contains(r)) {
       contained.add(f);
     }
   }
   return contained;
 }
 public Collection<Handle> createHandles(SVGPathFigure pathFigure, int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case 0:
       for (int i = 0, n = path.size(); i < n; i++) {
         handles.add(new BezierNodeHandle(this, i, pathFigure));
       }
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       break;
     default:
       break;
   }
   return handles;
 }
Exemplo n.º 7
0
  // createericlist with a String signature is used to process a String
  // containing a sequence of GAIGS structures
  // createericlist creates the list of graphics primitives for these snapshot(s).
  // After creating these lists, that are then appended to l, the list of snapshots,
  // Also must return the number of snapshots loaded from the string
  public /*synchronized*/ int createericlist(String structString) {
    int numsnaps = 0;
    if (debug) System.out.println("In create eric " + structString);
    StringTokenizer st = new StringTokenizer(structString, "\r\n");
    while (st.hasMoreTokens()) {
      numsnaps++; // ??
      String tempString;
      LinkedList tempList = new LinkedList();
      StructureType strct;
      tempString = st.nextToken();
      try {
        boolean headers = true;
        while (headers) {
          headers = false;
          if (tempString.toUpperCase().startsWith("VIEW")) {
            tempString = HandleViewParams(tempString, tempList, st);
            headers = true;
          }
          if (tempString.toUpperCase().startsWith("FIBQUESTION ")
              || tempString.toUpperCase().startsWith("MCQUESTION ")
              || tempString.toUpperCase().startsWith("MSQUESTION ")
              || tempString.toUpperCase().startsWith("TFQUESTION ")) {
            tempString = add_a_question(tempString, st);
            headers = true;
          }
        }

        if (tempString.toUpperCase().equals("STARTQUESTIONS")) {
          numsnaps--; // questions don't count as snapshots
          readQuestions(st);
          break;
        }
        // After returning from HandleViewParams, tempString should now contain
        // the line with the structure type and possible additional text height info
        StringTokenizer structLine = new StringTokenizer(tempString, " \t");
        String structType = structLine.nextToken();
        if (debug) System.out.println("About to assign structure" + structType);
        strct = assignStructureType(structType);
        strct.loadTextHeights(structLine, tempList, this);
        strct.loadLinesPerNodeInfo(st, tempList, this);

        strct.loadTitle(st, tempList, this);
        strct.loadStructure(st, tempList, this);
        strct.calcDimsAndStartPts(tempList, this);
        strct.drawTitle(tempList, this);
        strct.drawStructure(tempList, this);
      } catch (VisualizerLoadException e) {
        System.out.println(e.toString());
      }
      //             // You've just created a snapshot.  Need to insure that "**" is appended
      //             // to the URLList for this snapshot IF no VIEW ALGO line was parsed in the
      //             // string for the snapshot.  This could probably best be done in the
      //             // HandleViewParams method
      list_of_snapshots.append(tempList);
      Snaps++;
    }
    return (numsnaps);
  } // createericlist(string)
Exemplo n.º 8
0
  @Override
  public Collection<Action> getActions(Point2D.Double p) {
    LinkedList<Action> actions = new LinkedList<Action>();
    if (get(TRANSFORM) != null) {
      ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.odg.Labels");
      actions.add(
          new AbstractAction(labels.getString("edit.removeTransform.text")) {
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent evt) {
              willChange();
              fireUndoableEditHappened(TRANSFORM.setUndoable(ODGAttributedFigure.this, null));
              changed();
            }
          });
    }
    return actions;
  }
Exemplo n.º 9
0
 @Override
 public Collection<Handle> createHandles(int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case -1: // Mouse hover handles
       handles.add(new BezierOutlineHandle(this, true));
       break;
     case 0:
       handles.add(new BezierOutlineHandle(this));
       for (int i = 0, n = path.size(); i < n; i++) {
         handles.add(new BezierNodeHandle(this, i));
       }
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       handles.add(new BezierScaleHandle(this));
       break;
   }
   return handles;
 }
Exemplo n.º 10
0
 private Drawing createDrawing() {
   DefaultDrawing drawing = new DefaultDrawing();
   LinkedList<InputFormat> inputFormats = new LinkedList<InputFormat>();
   inputFormats.add(new SVGInputFormat());
   inputFormats.add(new SVGZInputFormat());
   inputFormats.add(new ImageInputFormat(new SVGImageFigure()));
   inputFormats.add(new TextInputFormat(new SVGTextFigure()));
   LinkedList<OutputFormat> outputFormats = new LinkedList<OutputFormat>();
   outputFormats.add(new SVGOutputFormat());
   outputFormats.add(new ImageOutputFormat());
   drawing.setInputFormats(inputFormats);
   drawing.setOutputFormats(outputFormats);
   return drawing;
 }
Exemplo n.º 11
0
  public void paint(Graphics g) {
    // do normal painting first
    super.paint(g);

    // draw polys
    ListIterator<Polygon> II = poly_draw.listIterator(0);
    ListIterator<Color> CC = poly_draw_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.drawPolygon(P);
    }

    // fill polys
    II = poly_fill.listIterator(0);
    CC = poly_fill_color.listIterator(0);
    while (II.hasNext()) {
      Polygon P = II.next();
      Color C = CC.next();
      g.setColor(C);
      g.fillPolygon(P);
    }
  }
Exemplo n.º 12
0
  public int createericlist(Element snap) {
    int numsnaps = 0;

    StructureCollection structs = new StructureCollection();
    LinkedList tempList = new LinkedList();

    try {
      load_snap_from_xml(snap, structs, tempList);

      structs.calcDimsAndStartPts(tempList, this);
      structs.drawTitle(tempList, this);
      structs.drawStructure(tempList, this);

    } catch (VisualizerLoadException e) {
      System.out.println(e.toString());
    }

    list_of_snapshots.append(tempList);
    Snaps++;

    return numsnaps; // this.. isnt used, and isnt what it says it is.
  } // createericlist(element)
Exemplo n.º 13
0
 public Collection<Handle> createHandles(int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel % 2) {
     case -1: // Mouse hover handles
       handles.add(new BoundsOutlineHandle(this, false, true));
       break;
     case 0:
       handles.add(new BoundsOutlineHandle(this));
       handles.add(new MoveHandle(this, RelativeLocator.northWest()));
       handles.add(new MoveHandle(this, RelativeLocator.northEast()));
       handles.add(new MoveHandle(this, RelativeLocator.southWest()));
       handles.add(new MoveHandle(this, RelativeLocator.southEast()));
       handles.add(new FontSizeHandle(this));
       handles.add(new LinkHandle(this));
       break;
     case 1:
       TransformHandleKit.addTransformHandles(this, handles);
       break;
   }
   return handles;
 }
Exemplo n.º 14
0
 @Override
 public Collection<Handle> createHandles(int detailLevel) {
   LinkedList<Handle> handles = new LinkedList<Handle>();
   switch (detailLevel) {
     case -1:
       handles.add(new BoundsOutlineHandle(this, false, true));
       break;
     case 0:
       handles.add(new BoundsOutlineHandle(this));
       handles.add(new MoveHandle(this, RelativeLocator.northWest()));
       handles.add(new MoveHandle(this, RelativeLocator.northEast()));
       handles.add(new MoveHandle(this, RelativeLocator.southWest()));
       handles.add(new MoveHandle(this, RelativeLocator.southEast()));
       handles.add(new FontSizeHandle(this));
       break;
   }
   return handles;
 }
Exemplo n.º 15
0
  public void actionPerformed(ActionEvent e) {
    String s = e.getActionCommand();

    diag.jpm = null;

    if (s.equals("Edit Upstream Port Name")) {

      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit upstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  upStreamPort);

      if (ans != null /* && ans.length() > 0 */) {
        Block b = diag.blocks.get(new Integer(fromId));
        // upStreamPort = ans;
        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == fromId
                  && a.upStreamPort != null
                  && a.upStreamPort.equals(ans)
                  && !(upStreamPort.equals(ans))
              || a.toId == fromId && a.downStreamPort != null && a.downStreamPort.equals(ans))
            found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // upStreamPort = "";
          // return;
        }
        upStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_IN_BLOCK) || b instanceof IIPBlock) {
          MyOptionPane.showMessageDialog(driver.frame, "Upstream port must be blank");
          upStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Edit Downstream Port Name") && endsAtBlock) {
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit downstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  downStreamPort);

      if (ans != null /* && ans.length() > 0 */) {

        Block b = diag.blocks.get(new Integer(toId));

        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == toId && a.upStreamPort != null && a.upStreamPort.equals(ans)
              || a.toId == toId
                  && a.downStreamPort != null
                  && a.downStreamPort.equals(ans)
                  && !(downStreamPort.equals(ans))) found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // downStreamPort = "";
          // return;
        }

        downStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_OUT_BLOCK)) {
          MyOptionPane.showMessageDialog(driver.frame, "Downstream port must be blank");
          downStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Set Capacity")) {

      String capString = null;
      if (capacity == 0) capString = "";
      else capString = Integer.toString(capacity);
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Set Capacity",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  capString);
      if ((ans != null) && (ans.length() > 0)) {
        capacity = Integer.parseInt(ans);
        if (capLegend == null) {
          diag.xa = 2; // get around fudge in DrawFBP
          diag.ya = 2; // get around fudge in DrawFBP
          capLegend = (LegendBlock) diag.driver.createBlock(Block.Types.LEGEND_BLOCK, false);

          int x = toX;
          int y = toY;
          if (bends != null) {
            Bend bd = bends.peek();
            x = bd.x;
            y = bd.y;
          }

          capLegend.cx = (fromX + x) / 2;
          capLegend.cy = (fromY + y) / 2 + 20;
          if (fromX == x) capLegend.cx -= 20;
        }
        capLegend.description = "(" + capacity + ")";
      }
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Remove Capacity")) {
      capacity = 0;
      diag.delBlock(capLegend, false);
      capLegend = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Upstream Port Automatic / Normal")) {
      if (upStreamPort == null || !upStreamPort.equals("*")) upStreamPort = "*";
      else upStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Downstream Port Automatic / Normal")) {
      if (downStreamPort == null || !downStreamPort.equals("*")) downStreamPort = "*";
      else downStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle DropOldest")) {
      dropOldest = !dropOldest;

    } else if (s.equals("Drag Tail")) {
      tailMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag Head")) {
      headMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag New or Existing Bend")) {
      createBend(driver.curx, driver.cury);

    } else if (s.equals("Add Extra Arrowhead")) {
      Point p = new Point(driver.curx, driver.cury);
      int fx = fromX;
      int fy = fromY;
      int tx, ty;
      if (bends != null) {
        for (Bend bend : bends) {
          tx = bend.x;
          ty = bend.y;
          if (pointInLine(p, fx, fy, tx, ty)) {
            extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
            return;
          }
          fx = tx;
          fy = ty;
        }
      }
      tx = toX;
      ty = toY;
      if (pointInLine(p, fx, fy, tx, ty))
        extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
      return;

    } else if (s.equals("Remove Extra Arrowhead")) {
      extraArrowhead = null;
      return;

    } else if (s.equals("Delete")) {

      if (JOptionPane.YES_OPTION
          == MyOptionPane.showConfirmDialog(
              driver.frame,
              "Do you want to delete this arrow?",
              "Delete arrow",
              JOptionPane.YES_NO_OPTION)) {
        diag.delArrow(this);

        diag.changed = true;
        diag.currentArrow = null;
      }

      driver.frame.repaint();
      diag.foundArrow = null;
    }
    // if (s.equals("Exit")) {
    //	diag.foundArrow = null;
    //	driver.frame.repaint();
    // }
  }
Exemplo n.º 16
0
 public void printPoly(int n, float x[], float y[]) {
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_fill.add(P);
   poly_fill_color.add(curColor);
 }
Exemplo n.º 17
0
  public static List<BezierPath> fromPathData(String str) throws IOException {
    LinkedList<BezierPath> paths = new LinkedList<BezierPath>();

    BezierPath path = null;
    Point2D.Double p = new Point2D.Double();
    Point2D.Double c1 = new Point2D.Double();
    Point2D.Double c2 = new Point2D.Double();
    StreamTokenizer tt = new StreamTokenizer(new StringReader(str));
    tt.resetSyntax();
    tt.parseNumbers();
    tt.whitespaceChars(0, ' ');
    tt.whitespaceChars(',', ',');

    char nextCommand = 'M';
    char command = 'M';
    while (tt.nextToken() != StreamTokenizer.TT_EOF) {
      if (tt.ttype > 0) {
        command = (char) tt.ttype;
      } else {
        command = nextCommand;
        tt.pushBack();
      }

      BezierPath.Node node;
      switch (command) {
          // moveto
        case 'M':
          if (path != null) {
            paths.add(path);
          }
          path = new BezierPath();

          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.moveTo(p.x, p.y);
          nextCommand = 'L';
          break;
        case 'm':
          if (path != null) {
            paths.add(path);
          }
          path = new BezierPath();

          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.moveTo(p.x, p.y);
          nextCommand = 'l';

          // close path
          break;
        case 'Z':
        case 'z':
          p.x = path.get(0).x[0];
          p.y = path.get(0).y[0];
          path.setClosed(true);

          // lineto
          break;
        case 'L':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'L';

          break;
        case 'l':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'l';

          break;
        case 'H':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'H';

          break;
        case 'h':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'h';

          break;
        case 'V':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'V';

          break;
        case 'v':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.lineTo(p.x, p.y);
          nextCommand = 'v';

          // curveto
          break;
        case 'C':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.y = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.y = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.curveTo(c1.x, c1.y, c2.x, c2.y, p.x, p.y);
          nextCommand = 'C';

          break;
        case 'c':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.x = p.x + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.y = p.y + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.x = p.x + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.y = p.y + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.curveTo(c1.x, c1.y, c2.x, c2.y, p.x, p.y);
          nextCommand = 'c';

          break;
        case 'S':
          node = path.get(path.size() - 1);
          c1.x = node.x[0] * 2d - node.x[1];
          c1.y = node.y[0] * 2d - node.y[1];
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.y = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.curveTo(c1.x, c1.y, c2.x, c2.y, p.x, p.y);
          nextCommand = 'S';

          break;
        case 's':
          node = path.get(path.size() - 1);
          c1.x = node.x[0] * 2d - node.x[1];
          c1.y = node.y[0] * 2d - node.y[1];
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.x = p.x + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c2.y = p.y + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.curveTo(c1.x, c1.y, c2.x, c2.y, p.x, p.y);
          nextCommand = 's';

          // quadto
          break;
        case 'Q':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.y = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.quadTo(c1.x, c1.y, p.x, p.y);
          nextCommand = 'Q';

          break;
        case 'q':
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.x = p.x + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          c1.y = p.y + tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.quadTo(c1.x, c1.y, p.x, p.y);
          nextCommand = 'q';

          break;
        case 'T':
          node = path.get(path.size() - 1);
          c1.x = node.x[0] * 2d - node.x[1];
          c1.y = node.y[0] * 2d - node.y[1];
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x = tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y = tt.nval;
          path.quadTo(c1.x, c1.y, p.x, p.y);
          nextCommand = 'T';

          break;
        case 't':
          node = path.get(path.size() - 1);
          c1.x = node.x[0] * 2d - node.x[1];
          c1.y = node.y[0] * 2d - node.y[1];
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.x += tt.nval;
          if (tt.nextToken() != StreamTokenizer.TT_NUMBER) throw new IOException("Number expected");
          p.y += tt.nval;
          path.quadTo(c1.x, c1.y, p.x, p.y);
          nextCommand = 's';

          break;
        default:
          throw new IOException("Illegal command: " + command);
      }
    }
    if (path != null) {
      paths.add(path);
    }
    return paths;
  }
Exemplo n.º 18
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public /*synchronized*/ boolean execute(int sAt) {

    // The commented-out variables below are remnants from legacy
    // code -- they appear to be no longer needed.

    //         String urlTemp="";
    //         int z=0;
    //         int idx;
    //         int urlid;
    //         boolean showURL=false;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in abored attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives
    SnapAt = sAt;

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }
    BufferedImage buff = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) buff.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    // 	if(no_mouse_drag){
    // 	    if(first_paint_call){
    // // 		horizoff = (my_width - (int)(0.25 * my_width) -
    // // 			    GaigsAV.preferred_width) / 2;
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		first_paint_call = false;
    // 	    }else{
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		no_mouse_drag = false;
    // 	    }
    // 	}

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    int x;

    list_of_snapshots.reset();
    x = 0;
    LinkedList lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    Shape mask = createMask(buff.getWidth(), buff.getHeight());

    g2.setColor(Color.BLACK);
    g2.fill(mask);

    my_image = buff;
    repaint();

    return animation_done;
  }
Exemplo n.º 19
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public boolean animate(int sAt, boolean forward) {

    int x;
    LinkedList lt = null;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in aborted attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }

    // First capture the new image in a buffer called image2
    SnapAt = sAt;
    BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Next capture the image we are coming from in a buffer called image1
    SnapAt = (forward ? sAt - 1 : sAt + 1);
    BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time?
    g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g1.setColor(Color.WHITE);
    g1.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Now slide from image1 to image2

    // From the gaff Visualizer by Chris Gaffney
    //        double step = 4;	// Adjust this for more/less granularity between images
    double step = 40; // Adjust this for more/less granularity between images

    Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height);
    Graphics2D g2d = (Graphics2D) buffer.getGraphics();

    AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0);
    //        AffineTransform orig = g2d.getTransform();

    Shape mask = createMask(my_width, my_height);

    for (double i = 0; i < my_width; i += step) {
      if (i + step > my_width) // last time through loop, so adjust transform
      trans =
            AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0);
      g2d.transform(trans);
      g2d.drawImage(image1, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      AffineTransform last = g2d.getTransform();
      g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0));
      g2d.drawImage(image2, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      g2d.setTransform(last);

      this.my_image = buffer;
      repaint();

      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {

      }
    }
    Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height);
    b.getGraphics().drawImage(buffer, 0, 0, null);
    this.my_image = b;

    return animation_done;
  }