public void redo() {
   if (undoManager.canRedo()) {
     undoManager.redo();
   }
   statusLine = "Redo";
   notifyObservers();
 }
Esempio n. 2
0
  public synchronized boolean addEdit(UndoableEdit edit) {
    if (DEBUG) System.out.println("ChangeManager.addEdit( " + edit + ")");
    boolean result = false;
    validated = false;

    if (compoundEdit == null) {
      if (DEBUG) System.out.println("super.addEdit( " + edit + ")");

      if (edit instanceof UndoableDesignerEdit
          && !(editToBeUndone() instanceof UndoableDesignerEdit)) {
        super.discardAllEdits();
      } else if (!(edit instanceof UndoableDesignerEdit)
          && editToBeUndone() instanceof UndoableDesignerEdit) {
        super.discardAllEdits();
      }

      if (edit instanceof UndoablePluginEditAbstact
          && !(editToBeUndone() instanceof UndoablePluginEditAbstact)) {
        super.discardAllEdits();
      } else if (!(edit instanceof UndoablePluginEditAbstact)
          && editToBeUndone() instanceof UndoablePluginEditAbstact) {
        super.discardAllEdits();
      }

      result = super.addEdit(edit);

      fireStateChanged(new ChangeEvent(this));
    } else {
      result = compoundEdit.addEdit(edit);
    }

    return result;
  }
 public void undo() {
   if (undoManager.canUndo()) {
     undoManager.undo();
   }
   statusLine = "Undo";
   notifyObservers();
 }
Esempio n. 4
0
 public void redo() {
   try {
     if (undo != null && undo.canRedo()) {
       undo.redo();
       refreshEnabledStatus();
     }
   } catch (CannotRedoException ignore) {
   }
 }
  /**
   * Refreshes the undo/redo icons with the last action performed.
   *
   * @param oUndoManager, the manager to use to check for undo/redo possibilities.
   */
  public void refreshUndoRedo(UndoManager oUndoManager) {

    // refresh undo
    pbUndo.setToolTipText(oUndoManager.getUndoPresentationName());
    pbUndo.setEnabled(oUndoManager.canUndo());

    // refresh redo
    pbRedo.setToolTipText(oUndoManager.getRedoPresentationName());
    pbRedo.setEnabled(oUndoManager.canRedo());
  }
Esempio n. 6
0
 void refreshEnabledStatus() {
   if (undo != null) {
     if (undo.canRedo()) {
       redoMenuItem.setEnabled(true);
     }
     if (undo.canUndo()) {
       undoMenuItem.setEnabled(true);
     }
   }
 }
Esempio n. 7
0
 public void undoableEditHappened(UndoableEditEvent e) {
   UndoManager mgr = Undo.getCurrentUndoMgr();
   if (mgr != null && mgr.canRedo()) {
     setToolTipText(mgr.getRedoPresentationName());
     setEnabled(true);
   } else {
     setToolTipText(tipStr);
     setEnabled(false);
   }
 }
Esempio n. 8
0
 public void actionPerformed(ActionEvent e) {
   UndoManager undo = menu.getCurScoreObject().manager;
   try {
     undo.undo();
     menu.setCurSaveFlag(false);
     p.repaint();
   } catch (CannotUndoException ex) {
     // System.out.println("Unable to undo: " + ex);
     // ex.printStackTrace();
   }
 }
 public void actionPerformed(ActionEvent e) {
   JMenuItem source = (JMenuItem) (e.getSource());
   if (source.getText().equals("元に戻す")) {
     if (undo.canUndo()) {
       undo.undo();
     }
   } else if (source.getText().equals("やり直し")) {
     if (undo.canRedo()) {
       undo.redo();
     }
   }
 }
Esempio n. 10
0
 public String check(JComponent component) {
   UndoManager undoManager =
       ((LayerManagerProxy)
               JUMPWorkbench.getInstance().getFrame().getActiveInternalFrame())
           .getLayerManager()
           .getUndoableEditReceiver()
           .getUndoManager();
   if (component != null)
     component.setToolTipText(undoManager.getUndoPresentationName());
   return (!undoManager.canUndo())
       ? I18N.get(
           "com.vividsolutions.jump.workbench.ui.plugin.UndoPlugIn.nothing-to-undo")
       : null;
 }
Esempio n. 11
0
  /** Undo the last change. */
  public synchronized void undo() {
    if (DEBUG) System.out.println("ChangeManager.undo()");
    super.undo();
    validated = false;

    fireStateChanged(new ChangeEvent(this));
  }
  private void jEnterCombatButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jEnterCombatButtonActionPerformed
    CombatEntity selected = getSelectedEntity();
    if (selected == null) {
      if (LOGGER.isLoggable(Level.WARNING)) {
        LOGGER.log(Level.WARNING, "Join Combat button was pressed when there was no selection.");
      }
      return;
    }

    if (isInCombat(selected)) {
      if (LOGGER.isLoggable(Level.WARNING)) {
        LOGGER.log(Level.WARNING, "Join Combat button was pressed while in combat");
      }
      return;
    }

    int roll = (Integer) jEnterCombatTick.getValue();

    CombatEntityAction action =
        new EntityJoinCombatAction(
            worldModel.getCombatModel().getPositionModel().getCurrentTick(),
            jJoinDescription.getText(),
            roll);

    worldModel.getCombatModel().joinCombat(selected, roll);
    undoManager.addEdit(new EnterCombatUndoableEdit(selected, roll, action));
    selected.addAction(action);

    jJoinDescription.setText("");
  } // GEN-LAST:event_jEnterCombatButtonActionPerformed
Esempio n. 13
0
  public void endCompound() {
    if (DEBUG) System.out.println("ChangeManager.endCompound()");

    compoundEdit.end();

    if ((editToBeUndone() instanceof UndoableDesignerEdit) && compoundEdit.isSignificant()) {
      super.discardAllEdits();
    } else if ((editToBeUndone() instanceof UndoablePluginEditAbstact)
        && compoundEdit.isSignificant()) {
      super.discardAllEdits();
    }

    super.addEdit(compoundEdit);

    compoundEdit = null;

    fireStateChanged(new ChangeEvent(this));
  }
 @Action(enabledProperty = REDO_ENABLED)
 public void redo() {
   try {
     undo.redo();
   } catch (CannotUndoException ex) {
     Logger.getLogger(ApplicationActions.class).error(ex);
     Toolkit.getDefaultToolkit().beep();
   }
   updateUndoActions();
 }
 public void setValue(int row, int column, int value) {
   ICell cell = grid.getICell(row, column);
   if (cell.isUnSet()) {
     cell.setValue(value);
     undoManager.addEdit(new SetValueCommand(cell));
     statusLine = "The cell " + cell.mkString() + " was successfully set";
   } else {
     statusLine = "The cell " + cell.mkString() + " is already set";
   }
   notifyObservers();
 }
Esempio n. 16
0
 /** Die Methode schliest den dummy Compound falls es ein "Space oder Enter" gedrueckt wird */
 public void keyTyped(KeyEvent e) {
   char keyChar = e.getKeyChar();
   if (keyChar == ' ' || keyChar == '\n') {
     // Falls Req Req Compound schliessen und an
     // Req Manager uebergeben
     if (ReqOROpt) {
       if (myReqCompound.isInProgress()) {
         myReqCompound.end();
         myReqField.addEdit(myReqCompound);
       }
       // sonst Opt Compound schliessen und an
       // Opt Manager uebergeben
     } else {
       if (myOptCompound.isInProgress()) {
         myOptCompound.end();
         myOptField.addEdit(myOptCompound);
       }
     }
   }
 }
Esempio n. 17
0
 @Override
 public void setActive(boolean mode, StateRenderer2D source) {
   if (!mode && element != null) {
     MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
     changeEvent.setChangedObject(element);
     changeEvent.setSourceMap(pivot);
     AddObjectEdit edit = new AddObjectEdit(element);
     undoManager.addEdit(edit);
     element.setFinished(true);
     pivot.warnChangeListeners(changeEvent);
   }
 }
Esempio n. 18
0
  @Override()
  public void displayConfig(WSDLComponent component, UndoManager undoManager) {
    UndoCounter undoCounter = new UndoCounter();
    WSDLModel model = component.getModel();

    model.addUndoableEditListener(undoCounter);

    JPanel profConfigPanel = new Kerberos(component, this);
    DialogDescriptor dlgDesc = new DialogDescriptor(profConfigPanel, getDisplayName());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);

    dlg.setVisible(true);
    if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
      for (int i = 0; i < undoCounter.getCounter(); i++) {
        if (undoManager.canUndo()) {
          undoManager.undo();
        }
      }
    }

    model.removeUndoableEditListener(undoCounter);
  }
  /**
   * If this <code>UndoManager</code> is <code>inProgress</code>, redoes the last significant <code>
   * UndoableEdit</code> at <code>indexOfNextAdd</code> or after, and all insignificant edits up to
   * it. Updates <code>indexOfNextAdd</code> accordingly.
   *
   * <p>If not <code>inProgress</code>, <code>indexOfNextAdd</code> is ignored and super's routine
   * is called.
   */
  public synchronized void redo() throws CannotRedoException {
    if (this.isInProgress()) {
      UndoableEdit edit = editToBeRedone();

      if (edit instanceof UndoManager) {
        UndoManager manager = (UndoManager) edit;

        while (manager.canRedo()) {
          manager.redo();
        }

        indexOfNextAdd++;
        return;
      }

      if (edit == null) {
        throw new CannotRedoException();
      }
      redoTo(edit);
    } else {
      super.redo();
    }
  }
Esempio n. 20
0
  public void discardAllEdits() {
    if (DEBUG) System.out.println("ChangeManager.discardAllEdits()");
    super.discardAllEdits();

    syncMark = null;
    saveMark = null;
    parseMark = null;
    validateMark = null;
    validated = false;

    compoundEdit = null;

    fireStateChanged(new ChangeEvent(this));
  }
Esempio n. 21
0
  protected Application() throws Exception {
    UIUtil.runUITaskNow(
        new Runnable() {
          public void run() {
            Thread.currentThread()
                .setUncaughtExceptionHandler(
                    new UncaughtExceptionHandler() {
                      public void uncaughtException(Thread thread, Throwable exception) {
                        Application.getInstance()
                            .showUnhandledErrorDialog(
                                LanguageBundle.getString("general.errors.uncaughtexception.title"),
                                LanguageBundle.getString(
                                    "general.errors.uncaughtexception.message"),
                                exception);
                      }
                    });
          }
        });

    String applicationClassName = "";
    switch (Platform.getOS()) {
      case MAC:
        applicationClassName = Registry.getProperty("application_classname_osx");
        break;
      case WIN:
        applicationClassName = Registry.getProperty("application_classname_windows");
        break;
      case NIX:
        applicationClassName = Registry.getProperty("application_classname_linux");
        break;
    }
    platformApplication = (IApplication) Class.forName(applicationClassName).newInstance();

    UIUtil.setUpLAF();

    resourceEditActions.put(ResourceType.SNU, new EditSnuAction());
    resourceEditActions.put(ResourceType.VIDEO, new EditVideoAction());
    resourceEditActions.put(ResourceType.IMAGE, new EditImageAction());
    resourceEditActions.put(ResourceType.TEXT, new EditTextAction());
    resourceEditActions.put(ResourceType.SOUND, new EditSoundAction());
    resourceEditActions.put(ResourceType.INTERFACE, new EditInterfaceAction());
    resourceEditActions.put(ResourceType.PROJECT, new ProjectEditAction());

    undoManager = new UndoManager();
    undoManager.setLimit(999);

    UIManager.put("AbstractUndoableEdit.undoText", "");
    UIManager.put("AbstractUndoableEdit.redoText", "");
  }
  /**
   * If this UndoManager is inProgress, undo the last significant UndoableEdit before
   * indexOfNextAdd, and all insignificant edits back to it. Updates indexOfNextAdd accordingly.
   *
   * <p>If not inProgress, indexOfNextAdd is ignored and super's routine is called.
   */
  public synchronized void undo() throws CannotUndoException {
    //        System.out.println("appel a undo");
    if (this.isInProgress()) {
      UndoableEdit edit = editToBeUndone();

      //            System.out.println("\tedit to undone : " + edit);

      if (edit instanceof UndoManager) {
        UndoManager manager = (UndoManager) edit;
        //                System.out.println("\tindexOfNextAdd : " + indexOfNextAdd);

        while (manager.canUndo()) {
          manager.undo();
        }

        //            System.out.println("gogo affichage de edits : ");
        //            for (int i = 0; i < this.edits.size(); i++)
        //                System.out.println("\t" + this.edits.elementAt(i).getClass());
        //                System.out.println("\tindexOfNextAdd : " + indexOfNextAdd);
        indexOfNextAdd--;

        return;
      }
      if (edit == null) {
        throw new CannotUndoException();
      }
      undoTo(edit);

      //            System.out.println("gigi affichage de edits : ");
      //            for (int i = 0; i < this.edits.size(); i++)
      //                System.out.println("\t" + this.edits.elementAt(i).getClass());

    } else {
      super.undo();
    }
  }
Esempio n. 23
0
  @Override
  public void mousePressed(MouseEvent event, StateRenderer2D source) {

    if (event.getButton() != MouseEvent.BUTTON1) {

      if (element != null) {
        MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
        changeEvent.setChangedObject(element);
        changeEvent.setSourceMap(pivot);
        AddObjectEdit edit = new AddObjectEdit(element);
        element.setFinished(true);

        undoManager.addEdit(edit);
        pivot.warnChangeListeners(changeEvent);
        element = null;

        if (associatedSwitch != null) associatedSwitch.doClick();
      }

      super.mousePressed(event, source);
      return;
    }

    LocationType lt = source.getRealWorldLocation(event.getPoint());

    if (element == null) {
      element = new PathElement(pivot.getMapGroup(), pivot, lt);
      element.setFill(fill);
      element.setShape(fill);
      pivot.addObject(element);
      element.addPoint(0, 0, 0, false);
      MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_ADDED);
      changeEvent.setChangedObject(element);
      changeEvent.setSourceMap(pivot);
      pivot.warnChangeListeners(changeEvent);
    } else {
      double[] offsets =
          element.getCenterLocation().getOffsetFrom(source.getRealWorldLocation(event.getPoint()));
      element.addPoint(-offsets[1], -offsets[0], 0, false);

      MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
      changeEvent.setChangedObject(element);
      changeEvent.setSourceMap(pivot);
      pivot.warnChangeListeners(changeEvent);
    }
  }
Esempio n. 24
0
 /** Orders to cancel all Undoable edits. */
 public void cancelUndo() {
   undoManager.die();
 }
Esempio n. 25
0
  public CodeTextPanel(Border bb, String title, String text) {
    super(new GridLayout(1, 1));
    if (bb != null) {
      Border b = BorderFactory.createTitledBorder(bb, title);
      setBorder(b);
    }

    JScrollPane p = new JScrollPane(area);
    add(p);
    p.setBorder(BorderFactory.createEmptyBorder());
    setText(text);

    area.setFont(new Font("Courier", Font.PLAIN, 13));
    // area.setEditable(false);

    UndoManager m = new UndoManager();
    // area.setundoManager = new UndoManager();
    Document doc = area.getDocument();
    doc.addUndoableEditListener((UndoableEditEvent e) -> m.addEdit(e.getEdit()));

    InputMap im = area.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = area.getActionMap();

    im.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "Undo");
    im.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "Redo");

    am.put(
        "Undo",
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              if (m.canUndo()) {
                m.undo();
              }
            } catch (CannotUndoException exp) {
              exp.printStackTrace();
            }
          }
        });
    am.put(
        "Redo",
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              if (m.canRedo()) {
                m.redo();
              }
            } catch (CannotUndoException exp) {
              exp.printStackTrace();
            }
          }
        });

    // setWordWrap(true);
  }
Esempio n. 26
0
 @Override
 public void undoableEditHappened(UndoableEditEvent arg0) {
   undo.addEdit(arg0.getEdit());
 }
  /** add an undoableEdit to the manager */
  public synchronized boolean addEdit(UndoableEdit anEdit) {
    System.out.println("appel à addEdit : " + anEdit);
    //        System.out.println("addEdit .. " + (anEdit != null ? anEdit.getClass() : "") );
    //        System.out.println("\tisInProgress ? " + this.isInProgress());
    //        System.out.println("\tgroup mode   ? " + this.groupActivated);
    //
    //        System.out.println("affichage de edits : ");
    //        for (int i = 0; i < this.edits.size(); i++)
    //            System.out.println("\t" + this.edits.elementAt(i).getClass());

    if (!this.isInProgress()) return false;

    System.out.println("groupActivated : " + this.groupActivated);

    if (this.groupActivated) {
      if (!(this.editToBeUndone() instanceof UndoManager)) {
        System.out.println("\teditToBeUndone is NOT NOT an UndoManager");
        UndoManager newManager = new UndoManager();
        newManager.setLimit(this.limit); // attention, la limite peut poser de graves problemes
        // super.addEdit(newManager);
        this.edits.add(newManager);

        indexOfNextAdd = edits.size();
        System.out.println("\tindexOfNextAdd : " + indexOfNextAdd);
      }

      if (this.editToBeUndone() instanceof UndoManager) {
        System.out.println("\teditToBeUndone is an UndoManager");
        ((UndoManager) this.editToBeUndone()).addEdit(anEdit);
        //                System.out.println("\tindexOfNextAdd : " + indexOfNextAdd);

        //        System.out.println("gaga affichage de edits : ");
        //        for (int i = 0; i < this.edits.size(); i++)
        //            System.out.println("\t" + this.edits.elementAt(i).getClass());

        return true;
      } else {
        //                System.out.println("\teditToBeUndone is NOT an UndoManager");

        if (this.edits.size() > 0) {
          System.out.println("\ta");
          ((UndoManager) this.edits.elementAt(this.edits.size() - 1)).addEdit(anEdit);
        } else {
          System.out.println("\tb");
          this.edits.add(anEdit);
        }
        return true;
      }
      // throw new RuntimeException("gros probleme dans l'undoManager"); }
    } else {
      System.out.println("\tajout simple");
      boolean retVal;

      // Trim from the indexOfNextAdd to the end, as we'll
      // never reach these edits once the new one is added.
      trimEdits(indexOfNextAdd, edits.size() - 1);

      ///////////////
      if (!this.isInProgress()) {
        return false;
      } else {
        UndoableEdit last = lastEdit();

        // If this is the first subedit received, just add it.
        // Otherwise, give the last one a chance to absorb the new
        // one.  If it won't, give the new one a chance to absorb
        // the last one.

        System.out.println("\t\tlast : " + (last == null ? "null" : last.getClass()));
        if (last == null) {
          System.out.println("\t\taddElement");
          edits.addElement(anEdit);
        } else // if (last instanceof UndoManager)//!last.addEdit(anEdit) || )
        {
          System.out.println("\t\ti");
          if (anEdit.replaceEdit(last)) {
            edits.removeElementAt(edits.size() - 1);
            System.out.println("\t\tj");
          }
          System.out.println(
              "il ajoute quand meme ce connard !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
          edits.addElement(anEdit);
        }

        retVal = true;
      }
      ///////////////

      if (this.isInProgress()) {
        retVal = true;
      }

      // Maybe super added this edit, maybe it didn't (perhaps
      // an in progress compound edit took it instead. Or perhaps
      // this UndoManager is no longer in progress). So make sure
      // the indexOfNextAdd is pointed at the right place.
      indexOfNextAdd = edits.size();

      System.out.println("indexofNextAdd : " + indexOfNextAdd);

      // Enforce the limit
      trimForLimit();

      return retVal;
    }
  }
 /**
  * Sending end() to an UndoManager turns it into a plain old (ended) CompoundEdit.
  *
  * <p>Calls super's end() method (making inProgress false), then sends die() to the unreachable
  * edits at indexOfNextAdd and beyond, in the reverse of the order in which they were added.
  */
 public synchronized void end() {
   super.end();
   this.trimEdits(indexOfNextAdd, edits.size() - 1);
 }
 private void updateUndoActions() {
   setRedoEnabled(undo.canRedo());
   setUndoEnabled(undo.canUndo());
 }
 public void discardAllEdits() {
   undo.discardAllEdits();
 }