/** Removes the Object identified by the specified id from this Surface's {@link Layout}. */ @Override public void requestRemove(String id) { Node<T> node = layout.getNode(id); if (node == null) { return; } List<Node<T>> affectedNodes = engine.requestRemoveElement(this, node); if (!affectedNodes.isEmpty()) { engine.adjustWeights(this); // Signal the client to remove the object associated with the removed "node". node.force( this, /* isMoveOperation() ? ChangeType.REMOVE_RETAIN : */ ChangeType.REMOVE_DISCARD); for (Node<T> n : affectedNodes) { n.set(this, ChangeType.RESIZE_RELOCATE); } removeNodeReferences(node); getPathIterator().assemblePaths(layout.getRoot()); } else { ////////// VETO REMOVE ///////// } }
/** * Begins an "Add" operation which will be "answered" as a response through the {@link * SurfaceListener} interface. * * <p>The {@link MosaicEngine} will respond to this request via the {@link SurfaceListener} * interface's methods to instruct the client as to what exact changes need to be made, this * allows the client to be totally passive with regard to necessary changes to affect the change * in its layout. */ @Override public void requestAdd(T source, String sourceID, T target, Position p) { validateAddParams(source, sourceID, target, p); Node<T> newNode = new Node<>(source, sourceID, 0, 0, 0, 0, 0, Double.MAX_VALUE, 0, Double.MAX_VALUE, 0, 0); engine.requestAddElement(this, newNode, getNode(layout.get(target)), p); }
/** Called by client code to begin a layout cycle. */ @Override public void requestLayout() { if (engine == null) { throw new IllegalStateException("This surface has not been added to a MosaicEngine"); } engine.requestLayout(this); }
/** * Stage one of an incremental programmatic move of an object from one location in the layout to * another. This begins a transaction of sorts which must either end with a call to {@link * #requestMoveCommit(Object, String)} or {@link #requestMoveReject(Object, String)}. The layout * engine will allow no other mutative effects until either of the above two methods are called, * signalling the end of the move operation. * * <p>First, {@link ChangeType#MOVE_BEGIN} will be sent to the client which then can adjust the * presentation of the moved object to be viewed as a "ghost" object. * * <p>Next, this specific phase will detach the object to be moved from its surrounding layout and * signal the layout to be altered via the {@link SurfaceListener} interface to adjust surrounding * objects within the layout to affect the specified object's removal. A specific {@link * ChangeType} will be issued called {@link ChangeType#ANIMATE_RESIZE_RELOCATE} for all objects * which this removal will affect, giving the client the opportunity to animate the positional * changes incurred during this phase. * * @param source the object to be moved. * @see #requestMove(Object, Object, Position) * @see #requestMoveTest(Object, Object, Position) * @see #requestMoveCommit(Object, Object, Position) * @see #requestMoveReject(Object) * @see #requestMoveCancel() */ @Override public void requestMoveBegin(T source) { if (locked) return; setLocked(true); engine.beginDropElement(this, layout.getNode(layout.get(source))); if (layoutCopy.get(source).equals(layoutCopy.getRoot().stringID)) { nodeCursor = interimLayoutSnapshot.getRoot().stringID; } }
/** * Stage two of an incremental programmatic move of an object from one location in the layout to * another. This will signal the engine to respond with a test drop location and size for the * source object and a test drop mutation for the target object. * * @param source the object being moved. * @param target the object sharing its boundaries to provide a drop location * @param p the quadrant of the target object specifying the drop location. * @see #requestMove(Object, Object, Position) * @see #requestMoveBegin(Object) * @see #requestMoveCommit(Object, Object, Position) * @see #requestMoveReject(Object) * @see #requestMoveCancel() */ @Override public void requestMoveTest(T source, T target, Position p) { if (!locked) return; engine.testDropElement( this, interimLayoutSnapshot, layoutCopy.getNode(layoutCopy.get(source)), layout.getNode(layout.get(target)), p); }
/** * One of two possible last stages of the move operation. This indicates that the move operation * should conclude with the object specified being moved back to its original position and any * other objects affected by operations during the "move operation" to be restored to their * original location/dimensions. * * <p>The engine will respond through the {@link SurfaceListener} interface with location * instructions for the source object and any other objects necessary. The last instruction will * be a {@link ChangeType#MOVE_END} which should signal the client to restore/remove any ghosting * effects on the object representing the moved object. * * @param source the object being moved. * @see #requestMove(Object, Object, Position) * @see #requestMoveBegin(Object) * @see #requestMoveTest(Object, Object, Position) * @see #requestMoveCommit(Object, Object, Position) * @see #requestMoveReject(Object) */ @Override public void requestMoveCancel(T source) { engine.cancelDropElement(this, layoutCopy.getNode(layoutCopy.get(source))); setLocked(false); }