Ejemplo n.º 1
0
  /**
   * ------------------------------------------------------ Deletes and copies the parts that are
   * selected in the given to this clipboard.
   *
   * @param editor the editor that contians the selected parts to cut
   * @see MiEditor#getSelectedParts
   * @see MiPart#isSelected ------------------------------------------------------
   */
  public void cutSelectionToClipBoard(MiEditor editor) {
    MiParts selectedParts = new MiParts();
    editor.getSelectedParts(selectedParts);

    for (int i = 0; i < selectedParts.size(); ++i) {
      if (!selectedParts.get(i).isCopyable()) {
        selectedParts.removeElementAt(i);
        --i;
      }
    }
    for (int i = 0; i < selectedParts.size(); ++i) {
      MiPart part = selectedParts.elementAt(i);
      editor.deSelect(part);
    }

    MiNestedTransaction nestedTransaction = new MiNestedTransaction(Mi_CUT_DISPLAY_NAME);
    MiSystem.getTransactionManager().startTransaction(nestedTransaction);

    // MiDeletePartsCommand deleteCmd = new MiDeletePartsCommand(editor, selectedParts, true);

    MiParts pastableSelectedParts = MiUtility.makeCopyOfNetwork(selectedParts);
    MiDeletePartsCommand deleteCmd =
        MiSystem.getCommandBuilder().getDeletePartsCommand().create(editor, selectedParts, true);
    MiChangeContentsTransaction replaceCmd =
        new MiChangeContentsTransaction(this, pastableSelectedParts);

    MiSystem.getTransactionManager().appendTransaction(Mi_CUT_DISPLAY_NAME, replaceCmd, deleteCmd);

    deleteCmd.doit(editor, true);
    replaceCmd.doit(this, pastableSelectedParts, true);

    dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION);

    MiSystem.getTransactionManager().commitTransaction(nestedTransaction);
  }
Ejemplo n.º 2
0
  /**
   * ------------------------------------------------------ Copies the given part to this clipboard.
   *
   * @param part the part to copy to the clipboard
   *     ------------------------------------------------------
   */
  public void copyToClipBoard(MiPart part) {
    MiParts parts = new MiParts();
    parts.addElement(part.deepCopy());

    MiChangeContentsTransaction cmd = new MiChangeContentsTransaction(this, parts);
    cmd.doit(this, parts, true);
    MiSystem.getTransactionManager().appendTransaction(cmd);
    dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION);
  }
Ejemplo n.º 3
0
  /**
   * ------------------------------------------------------ Copies the parts that are selected in
   * the given to this clipboard.
   *
   * @param editor the editor that contians the selected parts to copy
   * @see MiEditor#getSelectedParts
   * @see MiPart#isSelected ------------------------------------------------------
   */
  public void copySelectionToClipBoard(MiEditor editor) {
    MiParts selectedObjects = new MiParts();
    editor.getSelectedParts(selectedObjects);

    for (int i = 0; i < selectedObjects.size(); ++i) {
      if (!selectedObjects.get(i).isCopyable()) {
        selectedObjects.removeElementAt(i);
        --i;
      }
    }

    selectedObjects = MiUtility.makeCopyOfNetwork(selectedObjects);

    MiChangeContentsTransaction cmd = new MiChangeContentsTransaction(this, selectedObjects);
    cmd.doit(this, selectedObjects, true);
    MiSystem.getTransactionManager().appendTransaction(cmd);
    dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION);
  }
Ejemplo n.º 4
0
  /**
   * ------------------------------------------------------ Deletes the given part and then copies
   * the given part to this clipboard.
   *
   * @param part the part to cut to the clipboard
   *     ------------------------------------------------------
   */
  public void cutToClipBoard(MiPart part) {
    MiParts parts = new MiParts();
    parts.addElement(part);

    // MiDeletePartsCommand deleteCmd = new MiDeletePartsCommand(part.getContainingEditor(), parts,
    // true);
    MiDeletePartsCommand deleteCmd =
        MiSystem.getCommandBuilder()
            .getDeletePartsCommand()
            .create(part.getContainingEditor(), parts, true);

    MiChangeContentsTransaction replaceCmd = new MiChangeContentsTransaction(this, parts);

    MiiTransaction openTransaction =
        MiSystem.getTransactionManager()
            .startTransaction(new MiNestedTransaction(Mi_CUT_DISPLAY_NAME, replaceCmd, deleteCmd));

    deleteCmd.doit(part.getContainingEditor(), true);
    replaceCmd.doit(this, parts, true);

    dispatchAction(Mi_CLIPBOARD_NOW_HAS_DATA_ACTION);

    MiSystem.getTransactionManager().commitTransaction(openTransaction);
  }
Ejemplo n.º 5
0
 /**
  * ------------------------------------------------------ Undoes this transaction. This undoes any
  * changes that were made by the changes encapsulated by this transaction.
  *
  * @implements MiiTransaction#undo ------------------------------------------------------
  */
 public void undo() {
   doit(clipBoard, newContents, false);
 }
Ejemplo n.º 6
0
 /**
  * ------------------------------------------------------ Redoes this transaction. This is only
  * valid after an undo. This redoes the changes encapsulated by this transaction that were undone
  * by the undo() method.
  *
  * @implements MiiTransaction#redo ------------------------------------------------------
  */
 public void redo() {
   doit(clipBoard, newContents, true);
 }
Ejemplo n.º 7
0
 /**
  * ------------------------------------------------------ Undoes or Redoes this transaction. This
  * method creates a new transaction and adds it to the system-wide queue of undoable transactions.
  *
  * @param clipBoard the clipboard
  * @param newContents the graphics this transaction influences
  * @param replaceWithNewContents true if the graphics this transaction influences are to replace
  *     the current contents of the clipboard. false if any old contents previously recorded here
  *     are to be the contents of the clipboard
  *     ------------------------------------------------------
  */
 public void processCommand(
     MiContainer clipBoard, MiParts newContents, boolean replaceWithNewContents) {
   doit(clipBoard, newContents, replaceWithNewContents);
   MiSystem.getTransactionManager()
       .appendTransaction(new MiChangeContentsTransaction(clipBoard, newContents));
 }