-
-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added actions for aligning entities in the designer (#2577)
- Loading branch information
Showing
59 changed files
with
2,438 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...gin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/AlignBottomAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.entities.Anchor; | ||
import com.willwinder.ugs.nbp.designer.entities.Entity; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionEvent; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionListener; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager; | ||
import com.willwinder.ugs.nbp.designer.logic.Controller; | ||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.services.LocalizingService; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Point2D; | ||
import java.util.List; | ||
|
||
/** | ||
* An action for aligning objects | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
@ActionID( | ||
category = LocalizingService.CATEGORY_DESIGNER, | ||
id = "AlignBottomAction") | ||
@ActionRegistration( | ||
iconBase = AlignBottomAction.SMALL_ICON_PATH, | ||
displayName = "Align bottom", | ||
lazy = false) | ||
public class AlignBottomAction extends AbstractDesignAction implements SelectionListener { | ||
public static final String SMALL_ICON_PATH = "img/alignbottom.svg"; | ||
public static final String LARGE_ICON_PATH = "img/alignbottom24.svg"; | ||
private final transient Controller controller; | ||
|
||
public AlignBottomAction() { | ||
putValue("menuText", "Align bottom"); | ||
putValue(NAME, "Align bottom"); | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SHORT_DESCRIPTION, "Align the objects at the bottom of the first selected entity"); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
|
||
this.controller = ControllerFactory.getController(); | ||
SelectionManager selectionManager = controller.getSelectionManager(); | ||
selectionManager.addSelectionListener(this); | ||
onSelectionEvent(new SelectionEvent()); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
List<Entity> selection = controller.getSelectionManager().getSelection(); | ||
Entity entity = selection.get(0); | ||
Point2D destination = entity.getPosition(Anchor.BOTTOM_CENTER); | ||
|
||
UndoActionList actionList = new UndoActionList(); | ||
for (int i = 1; i < selection.size(); i++) { | ||
Point2D position = selection.get(i).getPosition(Anchor.BOTTOM_CENTER); | ||
actionList.add(new MoveAction(List.of(selection.get(i)), new Point2D.Double(0, destination.getY() - position.getY()))); | ||
} | ||
|
||
actionList.redo(); | ||
controller.getUndoManager().addAction(actionList); | ||
} | ||
|
||
@Override | ||
public void onSelectionEvent(SelectionEvent selectionEvent) { | ||
SelectionManager selectionManager = controller.getSelectionManager(); | ||
setEnabled(selectionManager.getSelection().size() > 1); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...gin-designer/src/main/java/com/willwinder/ugs/nbp/designer/actions/AlignCenterAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.entities.Anchor; | ||
import com.willwinder.ugs.nbp.designer.entities.Entity; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionEvent; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionListener; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager; | ||
import com.willwinder.ugs.nbp.designer.logic.Controller; | ||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.services.LocalizingService; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Point2D; | ||
import java.util.List; | ||
|
||
/** | ||
* An action for aligning objects | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
@ActionID( | ||
category = LocalizingService.CATEGORY_DESIGNER, | ||
id = "AlignCenterAction") | ||
@ActionRegistration( | ||
iconBase = AlignCenterAction.SMALL_ICON_PATH, | ||
displayName = "Align center", | ||
lazy = false) | ||
public class AlignCenterAction extends AbstractDesignAction implements SelectionListener { | ||
public static final String SMALL_ICON_PATH = "img/aligncenter.svg"; | ||
public static final String LARGE_ICON_PATH = "img/aligncenter24.svg"; | ||
private final transient Controller controller; | ||
|
||
public AlignCenterAction() { | ||
putValue("menuText", "Align center"); | ||
putValue(NAME, "Align center"); | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SHORT_DESCRIPTION, "Align the objects in center of the first selected entity"); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
|
||
this.controller = ControllerFactory.getController(); | ||
SelectionManager selectionManager = controller.getSelectionManager(); | ||
selectionManager.addSelectionListener(this); | ||
onSelectionEvent(new SelectionEvent()); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
List<Entity> selection = controller.getSelectionManager().getSelection(); | ||
Entity entity = selection.get(0); | ||
Point2D destination = entity.getCenter(); | ||
|
||
UndoActionList actionList = new UndoActionList(); | ||
for (int i = 1; i < selection.size(); i++) { | ||
Point2D position = selection.get(i).getPosition(Anchor.CENTER); | ||
actionList.add(new MoveAction(List.of(selection.get(i)), new Point2D.Double(destination.getX() - position.getX(), 0))); | ||
} | ||
|
||
actionList.redo(); | ||
controller.getUndoManager().addAction(actionList); | ||
} | ||
|
||
@Override | ||
public void onSelectionEvent(SelectionEvent selectionEvent) { | ||
SelectionManager selectionManager = controller.getSelectionManager(); | ||
setEnabled(selectionManager.getSelection().size() > 1); | ||
} | ||
} |
Oops, something went wrong.