コード例 #1
0
  private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {

    s.defaultReadObject();

    fSelection = CollectionsFactory.current().createList(); // could use lazy initialization instead
    if (drawing() != null) {
      drawing().addDrawingChangeListener(this);
    }
    fSelectionListeners = CollectionsFactory.current().createList();
  }
コード例 #2
0
 /** Adds a foreground. */
 public void addForeground(Painter painter) {
   if (fForegrounds == null) {
     fForegrounds = CollectionsFactory.current().createList(3);
   }
   fForegrounds.add(painter);
   repaint();
 }
コード例 #3
0
  /** Returns a FigureEnumeration of connectionfigures attached to this figure */
  public FigureEnumeration getConnectionFigures(Figure inFigure) {
    // If no figure or figure is non connectable, just return null
    if (inFigure == null || !inFigure.canConnect()) {
      return null;
    }

    // if (inFigure instanceof ConnectionFigure)
    //  return null;

    List result = CollectionsFactory.current().createList(5);
    FigureEnumeration figures = drawing().figures();

    // Find all connection figures
    while (figures.hasNextFigure()) {
      Figure f = figures.nextFigure();

      if ((f instanceof ConnectionFigure) && !(isFigureSelected(f))) {
        ConnectionFigure cf = (ConnectionFigure) f;

        if (cf.startFigure().includes(inFigure) || cf.endFigure().includes(inFigure)) {
          result.add(f);
        }
      }
    }

    return new FigureEnumerator(result);
  }
コード例 #4
0
 /**
  * Gets the handles of the figure. It returns the normal PolyLineHandles but adds
  * ChangeConnectionHandles at the start and end.
  */
 public HandleEnumeration handles() {
   List handles = CollectionsFactory.current().createList(fPoints.size());
   handles.add(new ChangeConnectionStartHandle(this));
   for (int i = 1; i < fPoints.size() - 1; i++) {
     handles.add(new PolyLineHandle(this, locator(i), i));
   }
   handles.add(new ChangeConnectionEndHandle(this));
   return new HandleEnumerator(handles);
 }
コード例 #5
0
  /**
   * Gets the currently selected figures in Z order.
   *
   * @see #selection
   * @return a FigureEnumeration with the selected figures. The enumeration represents a snapshot of
   *     the current selection.
   */
  public FigureEnumeration selectionZOrdered() {
    List result = CollectionsFactory.current().createList(selectionCount());
    FigureEnumeration figures = drawing().figures();

    while (figures.hasNextFigure()) {
      Figure f = figures.nextFigure();
      if (isFigureSelected(f)) {
        result.add(f);
      }
    }
    return new ReverseFigureEnumerator(result);
  }
コード例 #6
0
  public StandardDrawingView(DrawingEditor editor, int width, int height) {
    setAutoscrolls(true);
    counter++;
    fEditor = editor;
    fViewSize = new Dimension(width, height);
    setSize(width, height);
    fSelectionListeners = CollectionsFactory.current().createList();
    addFigureSelectionListener(editor());
    setLastClick(new Point(0, 0));
    fConstrainer = null;
    fSelection = CollectionsFactory.current().createList();
    // JFC/Swing uses double buffering automatically as default
    setDisplayUpdate(createDisplayUpdate());
    // TODO: Test FastBufferedUpdateStrategy with JFC/Swing double buffering
    // setDisplayUpdate(new FastBufferedUpdateStrategy());
    setBackground(Color.lightGray);

    addMouseListener(createMouseListener());
    addMouseMotionListener(createMouseMotionListener());
    addKeyListener(createKeyListener());
  }
コード例 #7
0
 /** Gets an enumeration of the currently active handles. */
 protected HandleEnumeration selectionHandles() {
   if (fSelectionHandles == null) {
     fSelectionHandles = CollectionsFactory.current().createList();
     FigureEnumeration fe = selection();
     while (fe.hasNextFigure()) {
       Figure figure = fe.nextFigure();
       HandleEnumeration kk = figure.handles();
       while (kk.hasNextHandle()) {
         fSelectionHandles.add(kk.nextHandle());
       }
     }
   }
   return new HandleEnumerator(fSelectionHandles);
 }
コード例 #8
0
  /**
   * Inserts a FigureEnumeration of figures and translates them by the given offset. This function
   * is used to insert figures from clipboards (cut/copy)
   *
   * @return enumeration which has been added to the drawing. The figures in the enumeration can
   *     have changed during adding them (e.g. they could have been decorated).
   */
  public FigureEnumeration insertFigures(FigureEnumeration fe, int dx, int dy, boolean bCheck) {
    if (fe == null) {
      return FigureEnumerator.getEmptyEnumeration();
    }

    List vCF = CollectionsFactory.current().createList(10);
    InsertIntoDrawingVisitor visitor = new InsertIntoDrawingVisitor(drawing());

    while (fe.hasNextFigure()) {
      Figure figure = fe.nextFigure();
      if (figure instanceof ConnectionFigure) {
        vCF.add(figure);
      } else if (figure != null) {
        figure.moveBy(dx, dy);
        figure.visit(visitor);
      }
    }

    FigureEnumeration ecf = new FigureEnumerator(vCF);

    while (ecf.hasNextFigure()) {
      ConnectionFigure cf = (ConnectionFigure) ecf.nextFigure();
      Figure sf = cf.startFigure();
      Figure ef = cf.endFigure();

      if (figureExists(sf, drawing().figures())
          && figureExists(ef, drawing().figures())
          && (!bCheck || cf.canConnect(sf, ef))) {

        if (bCheck) {
          Point sp = sf.center();
          Point ep = ef.center();
          Connector fStartConnector = cf.startFigure().connectorAt(ep.x, ep.y);
          Connector fEndConnector = cf.endFigure().connectorAt(sp.x, sp.y);

          if (fEndConnector != null && fStartConnector != null) {
            cf.connectStart(fStartConnector);
            cf.connectEnd(fEndConnector);
            cf.updateConnection();
          }
        }

        cf.visit(visitor);
      }
    }

    addToSelectionAll(visitor.getInsertedFigures());
    return visitor.getInsertedFigures();
  }
コード例 #9
0
  /** Clears the current selection. */
  public void clearSelection() {
    // there is nothing selected - bug fix ID 628818
    if (selectionCount() == 0) {
      // avoid unnecessary selection changed event when nothing has to be cleared
      return;
    }

    FigureEnumeration fe = selection();
    while (fe.hasNextFigure()) {
      fe.nextFigure().invalidate();
    }
    fSelection = CollectionsFactory.current().createList();
    fSelectionHandles = null;
    fireSelectionChanged();
  }
コード例 #10
0
 /** Create a new StorageFormatManager. */
 public StorageFormatManager() {
   myStorageFormats = CollectionsFactory.current().createList();
 }