Skip to content

Commit

Permalink
fix #247 (#248)
Browse files Browse the repository at this point in the history
 Move the clipboard to paste, copy.
  • Loading branch information
i-make-robots authored Jan 11, 2024
2 parents 2d03398 + 7aadd27 commit 4ea6781
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>RobotOverlord</artifactId>
<version>2.105.7</version>
<version>2.105.8</version>
<name>Robot Overlord</name>
<description>A friendly 3D user interface for controlling robots.</description>
<url>https://www.marginallyclever.com/</url>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/marginallyclever/ro3/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class Registry {
public static final ListWithEvents<Camera> cameras = new ListWithEvents<>();
private static Camera activeCamera = null;
public static final ListWithEvents<Node> selection = new ListWithEvents<>();
public static final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

public static void start() {
nodeFactory.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.FlavorEvent;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
Expand All @@ -18,26 +19,27 @@
*/
public class PasteNode extends AbstractAction {
private final Logger logger = LoggerFactory.getLogger(PasteNode.class);
private final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

public PasteNode() {
super();
putValue(Action.NAME,"Paste");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-paste-16.png"))));
putValue(SHORT_DESCRIPTION,"Paste the selected node(s).");

Registry.clipboard.addFlavorListener(this::clipboardChanged);
clipboard.addFlavorListener(this::clipboardChanged);
setEnabled(false);
}

private void clipboardChanged(FlavorEvent flavorEvent) {
// if the clipboard has changed, update the menu item
if(flavorEvent.getSource()==Registry.clipboard) {
if(flavorEvent.getSource()==clipboard) {
if(KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() == null) {
setEnabled(false);
return;
}
try {
setEnabled(Registry.clipboard.isDataFlavorAvailable(JSONHelper.JSON_FLAVOR));
setEnabled(clipboard.isDataFlavorAvailable(JSONHelper.JSON_FLAVOR));
} catch (IllegalStateException ignored) {
// if this clipboard is currently unavailable
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotUndoException;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.util.List;
Expand All @@ -20,10 +22,12 @@ public class CopyNode extends AbstractUndoableEdit {
private final Logger logger = LoggerFactory.getLogger(com.marginallyclever.ro3.apps.actions.CopyNode.class);
private final List<Node> selection;
private final Transferable before;
private final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

public CopyNode(List<Node> selection) {
super();
this.selection = selection;
this.before = Registry.clipboard.getContents(null);
this.before = clipboard.getContents(null);
execute();
}

Expand All @@ -48,7 +52,7 @@ public void execute() {
jsonWrapper.put("copied",list);
// store the json in the clipboard.
StringSelection stringSelection = new StringSelection(jsonWrapper.toString());
Registry.clipboard.setContents(stringSelection, null);
clipboard.setContents(stringSelection, null);
}

@Override
Expand All @@ -58,6 +62,6 @@ public void undo() throws CannotUndoException {
}

public void reverse() {
Registry.clipboard.setContents(before, null);
clipboard.setContents(before, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotUndoException;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,9 +20,10 @@
*/
public class PasteNode extends AbstractUndoableEdit {
private final Logger logger = LoggerFactory.getLogger(PasteNode.class);
Transferable transfer;
private final List<Node> children = new ArrayList<>();
private final List<Node> parents;
private final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
private final Transferable transfer;

/**
* Paste the copied nodes as children of the parent nodes.
Expand All @@ -29,7 +32,7 @@ public class PasteNode extends AbstractUndoableEdit {
public PasteNode(List<Node> parents) {
super();
this.parents = parents;
transfer = Registry.clipboard.getContents(null);
transfer = clipboard.getContents(null);
execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public RotateToolOneAxis(ColorRGB color) {
this.color = color;
buildMarkerMesh();
buildAngleMesh();
ringMesh.setRenderStyle(GL3.GL_LINE_LOOP);
}

private void buildAngleMesh() {
Expand Down Expand Up @@ -389,8 +390,11 @@ private void drawWhileDragging(GL3 gl,ShaderProgram shaderProgram) {

private void drawMainRingAndHandles(GL3 gl,ShaderProgram shaderProgram) {
Matrix4d m = new Matrix4d(pivotMatrix);
m.transpose();
shaderProgram.setMatrix4d(gl,"modelMatrix",m);

Matrix4d scale = MatrixHelper.createScaleMatrix4(getRingRadiusScaled());
scale.mul(m,scale);
scale.transpose();
shaderProgram.setMatrix4d(gl,"modelMatrix",scale);

float colorScale = cursorOverHandle ? 1:0.5f;
float red = color.red * colorScale / 255f;
Expand All @@ -399,6 +403,9 @@ private void drawMainRingAndHandles(GL3 gl,ShaderProgram shaderProgram) {
shaderProgram.set4f(gl, "objectColor", red, green, blue, 1.0f);
ringMesh.render(gl,1,360);

m.transpose();
shaderProgram.setMatrix4d(gl,"modelMatrix",m);

Matrix4d m2 = MatrixHelper.createScaleMatrix4(getGripRadiusScaled());
m2.m03 = getHandleLengthScaled();
m2.m13 = getHandleOffsetYScaled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javax.vecmath.Matrix4d;
import javax.vecmath.Vector3d;

@DisabledIfEnvironmentVariable(named = "CI", matches = "true", disabledReason = "headless environment")
public class CameraTest {
@Test
public void testPanTiltInverses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static org.junit.jupiter.api.Assertions.*;

@DisabledIfEnvironmentVariable(named = "CI", matches = "true", disabledReason = "headless.")
class LimbPlannerTest {
private static final Logger logger = LoggerFactory.getLogger(LimbPlannerTest.class);
Limb limb;
Expand All @@ -41,7 +40,7 @@ void setUp() throws Exception {
try {
Registry.start();
} catch(Exception e) {
e.printStackTrace();
logger.error("Failed to start Registry",e);
}
limb = build6AxisArm();

Expand Down

0 comments on commit 4ea6781

Please sign in to comment.