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
Beispiel #2
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);
       }
     }
   }
 }
 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();
 }
 @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);
   }
 }
  @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);
    }
  }
  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));
  }
Beispiel #7
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);
  }
Beispiel #8
0
 @Override
 public void undoableEditHappened(UndoableEditEvent arg0) {
   undo.addEdit(arg0.getEdit());
 }
 public void undoableEditHappened(UndoableEditEvent e) {
   undo.addEdit(e.getEdit());
 }
Beispiel #10
0
 public void addEdit(UndoableEdit edit) {
   if (undo != null) {
     undo.addEdit(edit);
   }
 }
Beispiel #11
0
 /*
  * (non-Javadoc)
  *
  * @see javax.swing.event.UndoableEditListener#undoableEditHappened(javax.swing.event.UndoableEditEvent)
  */
 public void undoableEditHappened(UndoableEditEvent arg0) {
   UndoableEdit edit = arg0.getEdit();
   undoManager.addEdit(edit);
 }