Java Code Examples for javax.swing.undo.AbstractUndoableEdit

The following are top voted examples for showing how to use javax.swing.undo.AbstractUndoableEdit. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SweetHome3D   File: HomeController.java   View source code 6 votes vote down vote up
/**
 * Deletes items and post a cut operation to undo support.
 */
public void cut(List<? extends Selectable> items)
{
	// Start a compound edit that deletes items and changes presentation name
	UndoableEditSupport undoSupport = getUndoableEditSupport();
	undoSupport.beginUpdate();
	getPlanController().deleteItems(items);
	// Add a undoable edit to change presentation name
	undoSupport.postEdit(new AbstractUndoableEdit()
	{
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(HomeController.class, "undoCutName");
		}
	});
	// End compound edit
	undoSupport.endUpdate();
}
 
Example 2
Project: SweetHome3D   File: HomeController.java   View source code 6 votes vote down vote up
/**
 * Paste the furniture in clipboard to the selected group in home.
 * @since 5.0
 */
public void pasteToGroup()
{
	// Start a compound edit that adds furniture
	UndoableEditSupport undoSupport = getUndoableEditSupport();
	undoSupport.beginUpdate();
	List<HomePieceOfFurniture> addedFurniture = Home.getFurnitureSubList(getView().getClipboardItems());
	adjustFurnitureSizeAndElevation(addedFurniture, true);
	getFurnitureController().addFurnitureToGroup(addedFurniture,
			(HomeFurnitureGroup) this.home.getSelectedItems().get(0));
	undoSupport.postEdit(new AbstractUndoableEdit()
	{
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(HomeController.class, "undoPasteToGroupName");
		}
	});
	
	// End compound edit
	undoSupport.endUpdate();
}
 
Example 3
Project: opensim-gui   File: ExplorerTopComponent.java   View source code 6 votes vote down vote up
public static void addUndoableEdit(AbstractUndoableEdit aUndoableEdit)
{
    getDefault().getUndoRedoManager().addEdit(aUndoableEdit);
    TopComponent tc = ViewDB.getCurrentModelWindow();
    if (tc==null){ // No gfx window
        tc = getDefault();
    } 
    if (tc==null) return;   // No tc to piggyback on
    final TopComponent tcf = tc;
    if (java.awt.EventQueue.isDispatchThread()) {
        tcf.requestActive();
    }
    else {
        SwingUtilities.invokeLater(new Runnable(){

        @Override
        public void run() {
            tcf.requestActive();
        }
    });
    }
 }
 
Example 4
Project: opensim-gui   File: ExperimentalForceSetNode.java   View source code 6 votes vote down vote up
void setColorUI(final Color color, boolean allowUndo) {
    final Color oldColor = getColor();
    if (allowUndo){
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
            @Override
           public void undo() throws CannotUndoException {
               super.undo();
               setColorUI(oldColor, false);
           }
            @Override
           public void redo() throws CannotRedoException {
               super.redo();
               setColorUI(color, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }
    motionDisplayer.setDefaultForceColor(color);
    ViewDB.repaintAll();
    refreshNode();
}
 
Example 5
Project: opensim-gui   File: ExperimentalForceSetNode.java   View source code 6 votes vote down vote up
void setForceScaleFactorUI(final double newFactor, boolean allowUndo)
{
    final double oldForceScaleFactor = getForceScaleFactor();
    if (allowUndo){
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
           @Override
           public void undo() throws CannotUndoException {
               super.undo();
               setForceScaleFactorUI(oldForceScaleFactor, false);
           }
           @Override
           public void redo() throws CannotRedoException {
               super.redo();
               setForceScaleFactorUI(newFactor, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }       
    ///motionDisplayer.setScaleFactor(newFactor);
    ViewDB.repaintAll();
    refreshNode();
}
 
Example 6
Project: opensim-gui   File: ExperimentalMarkerSetNode.java   View source code 6 votes vote down vote up
void setColorUI(final Color color, boolean allowUndo) {
    final Color oldColor = getColor();
    if (allowUndo){
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
            @Override
           public void undo() throws CannotUndoException {
               super.undo();
               setColorUI(oldColor, false);
           }
            @Override
           public void redo() throws CannotRedoException {
               super.redo();
               setColorUI(color, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }
    motionDisplayer.setDefaultExperimentalMarkerColor(color);
    ViewDB.repaintAll();
    refreshNode();
}
 
Example 7
Project: opensim-gui   File: ExperimentalMarkerSetNode.java   View source code 6 votes vote down vote up
void setMarkerScaleFactorUI(final double newFactor, boolean allowUndo)
{
    final double oldMarkerScaleFactor = getMarkerScaleFactor();
    if (allowUndo){
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
           @Override
           public void undo() throws CannotUndoException {
               super.undo();
               setMarkerScaleFactorUI(oldMarkerScaleFactor, false);
           }
           @Override
           public void redo() throws CannotRedoException {
               super.redo();
               setMarkerScaleFactorUI(newFactor, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }       
    motionDisplayer.setExperimentalMarkerScaleFactor(newFactor);
    ViewDB.repaintAll();
    refreshNode();
}
 
Example 8
Project: opensim-gui   File: MarkerAdapter.java   View source code 6 votes vote down vote up
private void setBodyName(final String bodyName, boolean enableUndo) {
    final String oldName = getBodyName();
    if (bodyName.equals(oldName)) return; // Nothing to do
    //marker.setParentFrameName(bodyName); 
    // The following line calls setParentFrame
    context.setBody(marker, model.getBodySet().get(bodyName), true);
    updateDisplay();
    if (enableUndo){
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
           public void undo() throws CannotUndoException {
               super.undo();
               setBodyName(oldName, false);
           }
           public void redo() throws CannotRedoException {
               super.redo();
               setBodyName(bodyName, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }
}
 
Example 9
Project: opensim-gui   File: MarkerAdapter.java   View source code 6 votes vote down vote up
private void setOffset(final ArrayDouble newOffset, boolean enableUndo) {
    Vec3 rOffest = marker.get_location();
    final ArrayDouble oldOffset = new ArrayDouble(3);
    for(int i=0; i<3; i++) oldOffset.set(i, rOffest.get(i));
     marker.set_location(newOffset.getAsVec3());
    updateDisplay(); 
    if (enableUndo){
         AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
           public void undo() throws CannotUndoException {
               super.undo();
               setOffset(oldOffset, false);
           }
           public void redo() throws CannotRedoException {
               super.redo();
               setOffset(newOffset, true);
           }
        };
        ExplorerTopComponent.addUndoableEdit(auEdit);            
    }
}
 
Example 10
Project: SweetHome3D   File: HomeController.java   View source code 5 votes vote down vote up
/**
 * Adds items to home.
 */
private void addPastedItems(final List<? extends Selectable> items, float dx, float dy,
		final boolean isDropInPlanView, final String presentationNameKey)
{
	if (items.size() > 1 || (items.size() == 1 && !(items.get(0) instanceof Compass)))
	{
		// Always use selection mode after a drop or a paste operation
		getPlanController().setMode(PlanController.Mode.SELECTION);
		// Start a compound edit that adds walls, furniture, rooms, dimension lines, polylines and labels to home
		UndoableEditSupport undoSupport = getUndoableEditSupport();
		undoSupport.beginUpdate();
		List<HomePieceOfFurniture> addedFurniture = Home.getFurnitureSubList(items);
		adjustFurnitureSizeAndElevation(addedFurniture, dx == 0 && dy == 0);
		getPlanController().moveItems(items, dx, dy);
		if (isDropInPlanView && this.preferences.isMagnetismEnabled() && items.size() == 1
				&& addedFurniture.size() == 1)
		{
			// Adjust piece when it's dropped in plan view  
			getPlanController().adjustMagnetizedPieceOfFurniture((HomePieceOfFurniture) items.get(0), dx, dy);
		}
		getPlanController().addItems(items);
		undoSupport.postEdit(new AbstractUndoableEdit()
		{
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(HomeController.class, presentationNameKey);
			}
		});
		
		// End compound edit
		undoSupport.endUpdate();
	}
}
 
Example 11
Project: SweetHome3D   File: HomeController.java   View source code 5 votes vote down vote up
/**
 * Toggles visibility of the background image and posts an undoable operation.
 */
private void toggleBackgroundImageVisibility(final String presentationName)
{
	final Level selectedLevel = this.home.getSelectedLevel();
	doToggleBackgroundImageVisibility();
	UndoableEdit undoableEdit = new AbstractUndoableEdit()
	{
		@Override
		public void undo() throws CannotUndoException
		{
			super.undo();
			home.setSelectedLevel(selectedLevel);
			doToggleBackgroundImageVisibility();
		}
		
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			home.setSelectedLevel(selectedLevel);
			doToggleBackgroundImageVisibility();
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(HomeController.class, presentationName);
		}
	};
	getUndoableEditSupport().postEdit(undoableEdit);
}
 
Example 12
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Unlocks home base plan.
 */
public void unlockBasePlan()
{
	if (this.home.isBasePlanLocked())
	{
		final boolean allLevelsSelection = this.home.isAllLevelsSelection();
		List<Selectable> selection = this.home.getSelectedItems();
		final Selectable[] selectedItems = selection.toArray(new Selectable[selection.size()]);
		
		this.home.setBasePlanLocked(false);
		this.home.setAllLevelsSelection(false);
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				home.setBasePlanLocked(true);
				selectAndShowItems(Arrays.asList(selectedItems), allLevelsSelection);
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				home.setBasePlanLocked(false);
				selectAndShowItems(Arrays.asList(selectedItems), false);
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoUnlockBasePlan");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 13
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable reverse wall operation, about <code>walls</code>.
 */
private void postReverseSelectedWallsDirection(final Wall[] walls, List<Selectable> oldSelection)
{
	final boolean allLevelsSelection = home.isAllLevelsSelection();
	final Selectable[] oldSelectedItems = oldSelection.toArray(new Selectable[oldSelection.size()]);
	UndoableEdit undoableEdit = new AbstractUndoableEdit()
	{
		@Override
		public void undo() throws CannotUndoException
		{
			super.undo();
			doReverseWallsDirection(walls);
			selectAndShowItems(Arrays.asList(oldSelectedItems), allLevelsSelection);
		}
		
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			doReverseWallsDirection(walls);
			selectAndShowItems(Arrays.asList(oldSelectedItems), allLevelsSelection);
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(PlanController.class, "undoReverseWallsDirectionName");
		}
	};
	this.undoSupport.postEdit(undoableEdit);
}
 
Example 14
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable split wall operation.
 */
private void postSplitSelectedWall(final JoinedWall splitJoinedWall, final JoinedWall firstJoinedWall,
		final JoinedWall secondJoinedWall, List<Selectable> oldSelection, final boolean oldBasePlanLocked,
		final boolean oldAllLevelsSelection)
{
	final Selectable[] oldSelectedItems = oldSelection.toArray(new Selectable[oldSelection.size()]);
	final boolean newBasePlanLocked = this.home.isBasePlanLocked();
	UndoableEdit undoableEdit = new AbstractUndoableEdit()
	{
		@Override
		public void undo() throws CannotUndoException
		{
			super.undo();
			doDeleteWalls(new JoinedWall[] { firstJoinedWall, secondJoinedWall }, oldBasePlanLocked);
			doAddWalls(new JoinedWall[] { splitJoinedWall }, oldBasePlanLocked);
			selectAndShowItems(Arrays.asList(oldSelectedItems), oldAllLevelsSelection);
		}
		
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			doDeleteWalls(new JoinedWall[] { splitJoinedWall }, newBasePlanLocked);
			doAddWalls(new JoinedWall[] { firstJoinedWall, secondJoinedWall }, newBasePlanLocked);
			selectAndShowItems(Arrays.asList(new Wall[] { firstJoinedWall.getWall() }), false);
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(PlanController.class, "undoSplitWallName");
		}
	};
	this.undoSupport.postEdit(undoableEdit);
}
 
Example 15
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Changes the style of items and posts an undoable change style operation.
 */
private void modifyTextStyle(final Selectable[] items, final TextStyle[] oldStyles, final TextStyle[] styles)
{
	final boolean allLevelsSelection = home.isAllLevelsSelection();
	List<Selectable> oldSelection = this.home.getSelectedItems();
	final Selectable[] oldSelectedItems = oldSelection.toArray(new Selectable[oldSelection.size()]);
	
	doModifyTextStyle(items, styles);
	UndoableEdit undoableEdit = new AbstractUndoableEdit()
	{
		@Override
		public void undo() throws CannotUndoException
		{
			super.undo();
			doModifyTextStyle(items, oldStyles);
			selectAndShowItems(Arrays.asList(oldSelectedItems), allLevelsSelection);
		}
		
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			doModifyTextStyle(items, styles);
			selectAndShowItems(Arrays.asList(oldSelectedItems), allLevelsSelection);
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(PlanController.class, "undoModifyTextStyleName");
		}
	};
	this.undoSupport.postEdit(undoableEdit);
}
 
Example 16
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Toggles the viewability of the selected level.
 * @since 5.0
 */
public void toggleSelectedLevelViewability()
{
	final Level selectedLevel = this.home.getSelectedLevel();
	selectedLevel.setViewable(!selectedLevel.isViewable());
	undoSupport.postEdit(new AbstractUndoableEdit()
	{
		@Override
		public void undo() throws CannotUndoException
		{
			super.undo();
			setSelectedLevel(selectedLevel);
			selectedLevel.setViewable(!selectedLevel.isViewable());
		}
		
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			setSelectedLevel(selectedLevel);
			selectedLevel.setViewable(!selectedLevel.isViewable());
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(PlanController.class, "undoModifyLevelName");
		}
	});
}
 
Example 17
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Adds <code>items</code> to home and post an undoable operation.
 */
public void addItems(final List<? extends Selectable> items)
{
	// Start a compound edit that adds walls, furniture, rooms, dimension lines and labels to home
	this.undoSupport.beginUpdate();
	addFurniture(Home.getFurnitureSubList(items));
	addWalls(Home.getWallsSubList(items));
	addRooms(Home.getRoomsSubList(items));
	addPolylines(Home.getPolylinesSubList(items));
	addDimensionLines(Home.getDimensionLinesSubList(items));
	addLabels(Home.getLabelsSubList(items));
	this.home.setSelectedItems(items);
	
	// Add a undoable edit that will select all the items at redo
	undoSupport.postEdit(new AbstractUndoableEdit()
	{
		@Override
		public void redo() throws CannotRedoException
		{
			super.redo();
			home.setSelectedItems(items);
		}
		
		@Override
		public String getPresentationName()
		{
			return preferences.getLocalizedString(PlanController.class, "undoAddItemsName");
		}
	});
	// End compound edit
	undoSupport.endUpdate();
}
 
Example 18
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>label</code> angle change.
 */
private void postLabelRotation(final Label label, final float oldAngle)
{
	final float newAngle = label.getAngle();
	if (newAngle != oldAngle)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				label.setAngle(oldAngle);
				selectAndShowItems(Arrays.asList(new Label[] { label }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				label.setAngle(newAngle);
				selectAndShowItems(Arrays.asList(new Label[] { label }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoLabelRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 19
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support an elevation change on <code>label</code>. 
 */
private void postLabelElevation(final Label label, final float oldElevation)
{
	final float newElevation = label.getElevation();
	if (newElevation != oldElevation)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				label.setElevation(oldElevation);
				selectAndShowItems(Arrays.asList(new Label[] { label }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				label.setElevation(newElevation);
				selectAndShowItems(Arrays.asList(new Label[] { label }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class,
						oldElevation < newElevation ? "undoLabelRaiseName" : "undoLabelLowerName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 20
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation of a (<code>dx</code>, <code>dy</code>) move 
 * of <code>movedItems</code>.
 */
private void postItemsMove(List<? extends Selectable> movedItems, List<? extends Selectable> oldSelection,
		final float dx, final float dy)
{
	if (dx != 0 || dy != 0)
	{
		// Store the moved items in an array
		final Selectable[] itemsArray = movedItems.toArray(new Selectable[movedItems.size()]);
		final boolean allLevelsSelection = home.isAllLevelsSelection();
		final Selectable[] oldSelectedItems = oldSelection.toArray(new Selectable[oldSelection.size()]);
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				doMoveAndShowItems(itemsArray, oldSelectedItems, -dx, -dy, allLevelsSelection);
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				doMoveAndShowItems(itemsArray, itemsArray, dx, dy, allLevelsSelection);
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoMoveSelectionName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 21
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>room</code> resizing.
 */
private void postRoomResize(final Room room, final float oldX, final float oldY, final int pointIndex)
{
	float[] roomPoint = room.getPoints()[pointIndex];
	final float newX = roomPoint[0];
	final float newY = roomPoint[1];
	if (newX != oldX || newY != oldY)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				moveRoomPoint(room, oldX, oldY, pointIndex);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				moveRoomPoint(room, newX, newY, pointIndex);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoRoomResizeName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 22
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>room</code> name offset change.
 */
private void postRoomNameOffset(final Room room, final float oldNameXOffset, final float oldNameYOffset)
{
	final float newNameXOffset = room.getNameXOffset();
	final float newNameYOffset = room.getNameYOffset();
	if (newNameXOffset != oldNameXOffset || newNameYOffset != oldNameYOffset)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				room.setNameXOffset(oldNameXOffset);
				room.setNameYOffset(oldNameYOffset);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				room.setNameXOffset(newNameXOffset);
				room.setNameYOffset(newNameYOffset);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoRoomNameOffsetName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 23
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>room</code> name angle change.
 */
private void postRoomNameRotation(final Room room, final float oldNameAngle)
{
	final float newNameAngle = room.getNameAngle();
	if (newNameAngle != oldNameAngle)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				room.setNameAngle(oldNameAngle);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				room.setNameAngle(newNameAngle);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoRoomNameRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 24
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>room</code> area offset change.
 */
private void postRoomAreaOffset(final Room room, final float oldAreaXOffset, final float oldAreaYOffset)
{
	final float newAreaXOffset = room.getAreaXOffset();
	final float newAreaYOffset = room.getAreaYOffset();
	if (newAreaXOffset != oldAreaXOffset || newAreaYOffset != oldAreaYOffset)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				room.setAreaXOffset(oldAreaXOffset);
				room.setAreaYOffset(oldAreaYOffset);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				room.setAreaXOffset(newAreaXOffset);
				room.setAreaYOffset(newAreaYOffset);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoRoomAreaOffsetName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 25
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>room</code> area angle change.
 */
private void postRoomAreaRotation(final Room room, final float oldAreaAngle)
{
	final float newAreaAngle = room.getAreaAngle();
	if (newAreaAngle != oldAreaAngle)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				room.setAreaAngle(oldAreaAngle);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				room.setAreaAngle(newAreaAngle);
				selectAndShowItems(Arrays.asList(new Room[] { room }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoRoomAreaRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 26
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support an angle change on <code>piece</code>. 
 */
private void postPieceOfFurnitureRotation(final HomePieceOfFurniture piece, final float oldAngle,
		final boolean oldDoorOrWindowBoundToWall)
{
	final float newAngle = piece.getAngle();
	if (newAngle != oldAngle)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				piece.setAngle(oldAngle);
				if (piece instanceof HomeDoorOrWindow)
				{
					((HomeDoorOrWindow) piece).setBoundToWall(oldDoorOrWindowBoundToWall);
				}
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				piece.setAngle(newAngle);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoPieceOfFurnitureRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 27
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support an elevation change on <code>piece</code>. 
 */
private void postPieceOfFurnitureElevation(final HomePieceOfFurniture piece, final float oldElevation)
{
	final float newElevation = piece.getElevation();
	if (newElevation != oldElevation)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				piece.setElevation(oldElevation);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				piece.setElevation(newElevation);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, oldElevation < newElevation
						? "undoPieceOfFurnitureRaiseName" : "undoPieceOfFurnitureLowerName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 28
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support a power modification on <code>light</code>. 
 */
private void postLightPowerModification(final HomeLight light, final float oldPower)
{
	final float newPower = light.getPower();
	if (newPower != oldPower)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				light.setPower(oldPower);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { light }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				light.setPower(newPower);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { light }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoLightPowerModificationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 29
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>piece</code> name offset change.
 */
private void postPieceOfFurnitureNameOffset(final HomePieceOfFurniture piece, final float oldNameXOffset,
		final float oldNameYOffset)
{
	final float newNameXOffset = piece.getNameXOffset();
	final float newNameYOffset = piece.getNameYOffset();
	if (newNameXOffset != oldNameXOffset || newNameYOffset != oldNameYOffset)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				piece.setNameXOffset(oldNameXOffset);
				piece.setNameYOffset(oldNameYOffset);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				piece.setNameXOffset(newNameXOffset);
				piece.setNameYOffset(newNameYOffset);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoPieceOfFurnitureNameOffsetName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 30
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>piece</code> name angle change.
 */
private void postPieceOfFurnitureNameRotation(final HomePieceOfFurniture piece, final float oldNameAngle)
{
	final float newNameAngle = piece.getNameAngle();
	if (newNameAngle != oldNameAngle)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				piece.setNameAngle(oldNameAngle);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				piece.setNameAngle(newNameAngle);
				selectAndShowItems(Arrays.asList(new HomePieceOfFurniture[] { piece }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoPieceOfFurnitureNameRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 31
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>dimensionLine</code> offset change.
 */
private void postDimensionLineOffset(final DimensionLine dimensionLine, final float oldOffset)
{
	final float newOffset = dimensionLine.getOffset();
	if (newOffset != oldOffset)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				dimensionLine.setOffset(oldOffset);
				selectAndShowItems(Arrays.asList(new DimensionLine[] { dimensionLine }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				dimensionLine.setOffset(newOffset);
				selectAndShowItems(Arrays.asList(new DimensionLine[] { dimensionLine }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoDimensionLineOffsetName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 32
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Posts an undoable operation about <code>polyline</code> resizing.
 */
private void postPolylineResize(final Polyline polyline, final float oldX, final float oldY, final int pointIndex)
{
	float[] polylinePoint = polyline.getPoints()[pointIndex];
	final float newX = polylinePoint[0];
	final float newY = polylinePoint[1];
	if (newX != oldX || newY != oldY)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				polyline.setPoint(oldX, oldY, pointIndex);
				selectAndShowItems(Arrays.asList(new Polyline[] { polyline }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				polyline.setPoint(newX, newY, pointIndex);
				selectAndShowItems(Arrays.asList(new Polyline[] { polyline }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoPolylineResizeName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 33
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support a north direction change on <code>compass</code>. 
 */
private void postCompassRotation(final Compass compass, final float oldNorthDirection)
{
	final float newNorthDirection = compass.getNorthDirection();
	if (newNorthDirection != oldNorthDirection)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				compass.setNorthDirection(oldNorthDirection);
				selectAndShowItems(Arrays.asList(new Compass[] { compass }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				compass.setNorthDirection(newNorthDirection);
				selectAndShowItems(Arrays.asList(new Compass[] { compass }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoCompassRotationName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 34
Project: SweetHome3D   File: PlanController.java   View source code 5 votes vote down vote up
/**
 * Post to undo support a size change on <code>compass</code>. 
 */
private void postCompassResize(final Compass compass, final float oldDiameter)
{
	final float newDiameter = compass.getDiameter();
	if (newDiameter != oldDiameter)
	{
		UndoableEdit undoableEdit = new AbstractUndoableEdit()
		{
			@Override
			public void undo() throws CannotUndoException
			{
				super.undo();
				compass.setDiameter(oldDiameter);
				selectAndShowItems(Arrays.asList(new Compass[] { compass }));
			}
			
			@Override
			public void redo() throws CannotRedoException
			{
				super.redo();
				compass.setDiameter(newDiameter);
				selectAndShowItems(Arrays.asList(new Compass[] { compass }));
			}
			
			@Override
			public String getPresentationName()
			{
				return preferences.getLocalizedString(PlanController.class, "undoCompassResizeName");
			}
		};
		this.undoSupport.postEdit(undoableEdit);
	}
}
 
Example 35
Project: MPL   File: AbstractUndoableBnEdit.java   View source code 5 votes vote down vote up
public AbstractUndoableBnEdit(UndoableBnStyledDocument doc) {
  this.doc = checkNotNull(doc, "doc == null!");
  try {
    Field hasBeenDone = AbstractUndoableEdit.class.getDeclaredField("hasBeenDone");
    hasBeenDone.setAccessible(true);
    hasBeenDone.setBoolean(this, false);
  } catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) {
    throw new UndeclaredThrowableException(ex);
  }
}
 
Example 36
Project: sqlpower-library   File: TestUndoManager.java   View source code 5 votes vote down vote up
public void testAllowCompoundEdit()
{
	UndoableEdit stubEdit1 = new AbstractUndoableEdit(); 
	UndoableEdit stubEdit2 = new AbstractUndoableEdit(); 
	UndoableEdit stubEdit3 = new AbstractUndoableEdit(); 
	CompoundEdit ce = new CompoundEdit();
	ce.addEdit(stubEdit1);
	ce.addEdit(stubEdit2);
	ce.addEdit(stubEdit3);
	ce.end();
	undoManager.addEdit(ce);
	assertTrue(undoManager.canUndo());
}
 
Example 37
Project: tellervo   File: Clean.java   View source code 5 votes vote down vote up
public static AbstractUndoableEdit clean(Sample s) {
	Clean c = new Clean(s);
	c.cleanSample();

	// return undo
	return c;
}
 
Example 38
Project: tellervo   File: Reverse.java   View source code 5 votes vote down vote up
public static AbstractUndoableEdit reverse(Sample s) {
Reverse r = new Reverse(s);

// can't just call redo(), because that calls super.redo() -- hmm...
reverseSample(s);
s.setModified();
s.fireSampleMetadataChanged();

return r; // return the undo
   }
 
Example 39
Project: opensim-gui   File: ViewDB.java   View source code 5 votes vote down vote up
public void dragSelectedObjects(final OpenSimObject clickedObject, final double dragVector[], boolean supportUndo) {
   DragObjectsEvent evnt = new DragObjectsEvent(clickedObject, dragVector);
   //System.out.println("drg vec"+dragVector[0]+" "+dragVector[1]+" "+dragVector[2]);
   // undo is a drag in the opposite direction!
   AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
        public boolean canUndo() {
            return true;
        }
        public boolean canRedo() {
            return true;
        }
        public void undo() throws CannotUndoException {
            super.undo();
            final double[] negativeDrag=new double[3];
            for(int i=0;i<3;i++) negativeDrag[i]=-dragVector[i];
            dragSelectedObjects(clickedObject, negativeDrag, false);
        }
        public void redo() throws CannotRedoException {
            super.redo();
            dragSelectedObjects(clickedObject, dragVector, true);
        }

        @Override
        public String getRedoPresentationName() {
            return "Redo Drag object(s)";
         }

        @Override
        public String getUndoPresentationName() {
            return "Undo Drag object(s)";
        }
        
    };
   if (supportUndo)
     ExplorerTopComponent.addUndoableEdit(auEdit);
   setChanged();  
   notifyObservers(evnt);
}
 
Example 40
Project: opensim-gui   File: DisplayGeometryDisplayer.java   View source code 5 votes vote down vote up
public void setDisplayPreferenceGUI(final DecorativeGeometry.Representation newPref, boolean allowUndo) {
    if (allowUndo){
        final DecorativeGeometry.Representation oldPref = displayGeometry.getRepresentation();
        AbstractUndoableEdit auEdit = new AbstractUndoableEdit(){
           public boolean canUndo() {
               return true;
           }
           public boolean canRedo() {
               return true;
           }
           public void undo() throws CannotUndoException {
               super.undo();
               // Change display
               setDisplayPreferenceGUI(oldPref, false);
               // Change model
           }
           public void redo() throws CannotRedoException {
               super.redo();
               // Change display
               setDisplayPreferenceGUI(newPref, false);
               // Change model
           }
            public String getPresentationName() {
                return "Display Preference Change";
            }

       };
        ExplorerTopComponent.addUndoableEdit(auEdit);
    }
    displayGeometry.setRepresentation(newPref);
    applyDisplayPreferenceToActor();
    Modified();
    ViewDB.getInstance().renderAll();
}