public void register(final ComputedTrajectorySet cts) { if (cts == null) return; cts.getInitialPos().addRockListener(this); cts.getInitialVel().addRockListener(this); // cts.getCurrentPos().addRockListener(this); // cts.getCurrentSpeed().addRockListener(this); }
@SuppressWarnings("unchecked") private static CompoundEdit reset( final ComputedTrajectorySet cts, final BroomPromptModel broom, final boolean outPosition) { final RockSet<Pos> ipos = cts.getInitialPos(); final RockSet<Vel> ivel = cts.getInitialVel(); // store the initial state: final PosMemento[] pm = new PosMemento[RockSet.ROCKS_PER_SET]; for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--) pm[i16] = new PosMemento(ipos, i16, ipos.getRock(i16).p()); final IndexMemento bi = new IndexMemento(broom, broom.getIdx16()); final HandleMemento bh = new HandleMemento(broom, broom.getOutTurn()); final XYMemento bxy = new XYMemento(broom, broom.getBroom()); final SplitMemento bs = new SplitMemento(broom, broom.getSplitTimeMillis().getValue()); final boolean preS = cts.getSuspended(); cts.setSuspended(true); try { // reset: RockSet.allZero(ivel); broom.setIdx16(-1); if (outPosition) RockSetUtils.allOut(ipos); else RockSetUtils.allHome(ipos); broom.setIdx16(1); broom.setBroom(new Point2D.Double(0, 0)); broom.getSplitTimeMillis().setValue(3300); } finally { cts.setSuspended(preS); } // create a compound edit final CompoundEdit ce = new CompoundEdit(); ce.addEdit(new UndoableMemento(new SuspendMemento(cts, preS), new SuspendMemento(cts, true))); for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--) ce.addEdit(new UndoableMemento(pm[i16], new PosMemento(ipos, i16, ipos.getRock(i16).p()))); ce.addEdit(new UndoableMemento(bi, new IndexMemento(broom, broom.getIdx16()))); ce.addEdit(new UndoableMemento(bh, new HandleMemento(broom, broom.getOutTurn()))); ce.addEdit(new UndoableMemento(bxy, new XYMemento(broom, broom.getBroom()))); ce.addEdit( new UndoableMemento(bs, new SplitMemento(broom, broom.getSplitTimeMillis().getValue()))); ce.addEdit(new UndoableMemento(new SuspendMemento(cts, true), new SuspendMemento(cts, preS))); ce.end(); return ce; }