Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow node actions on multiple selected nodes (Delete, etc) #642

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
private static final Logger logger = Logger.getLogger(SceneExplorerTopComponent.class.getName());
private static SceneExplorerTopComponent instance;
private static final String PREFERRED_ID = "SceneExplorerTopComponent";
// private final Result<AbstractSceneExplorerNode> nodeSelectionResult;
private AbstractSceneExplorerNode selectedSpatial;
private AbstractSceneExplorerNode lastSelected;

private AbstractSceneExplorerNode[] selectedSpatials;
private AbstractSceneExplorerNode[] lastSelected;
private final Map<String, MaterialChangeProvider> materialChangeProviders = new HashMap<>();
private final Map<String, List<MaterialChangeListener>> materialChangeListeners = new HashMap<>();
private transient ExplorerManager explorerManager = new ExplorerManager();

private final transient ExplorerManager explorerManager = new ExplorerManager();

public SceneExplorerTopComponent() {
initComponents();
Expand Down Expand Up @@ -149,18 +150,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if (selectedSpatial == null) {
if (selectedSpatials == null) {
return;
}
SwingUtilities.invokeLater(() -> {
Node rootNode = SceneExplorerTopComponent.findInstance().getExplorerManager().getRootContext();
if (rootNode instanceof JmeNode jmeNode) {
SceneApplication.getApplication().enqueue(new RefreshJmeSpatial(jmeNode, selectedSpatial.getName()));
} else {
selectedSpatial.refresh(false);
}
});

for (AbstractSceneExplorerNode node: selectedSpatials) {
node.refresh(false);
}
}//GEN-LAST:event_jButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane explorerScrollPane;
Expand Down Expand Up @@ -188,13 +183,13 @@ public static synchronized SceneExplorerTopComponent getDefault() {
* @return
*/
public static synchronized SceneExplorerTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
TopComponent window = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (window == null) {
logger.warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof SceneExplorerTopComponent sceneExplorerTopComponent) {
if (window instanceof SceneExplorerTopComponent sceneExplorerTopComponent) {
return sceneExplorerTopComponent;
}
logger.warning(
Expand Down Expand Up @@ -227,27 +222,20 @@ public void componentClosed() {
SceneApplication.getApplication().removeSceneListener(this);
// TODO add custom code on component closing
}

void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
// Required. Do not remove.
p.setProperty("version", "1.0");
// TODO store your settings
}

Object readProperties(java.util.Properties p) {
// Required. Do not remove.
if (instance == null) {
instance = this;
}
instance.readPropertiesImpl(p);
return instance;
}

private void readPropertiesImpl(java.util.Properties p) {
// TODO read your settings according to their version

}

@Override
protected String preferredID() {
return PREFERRED_ID;
Expand All @@ -263,18 +251,16 @@ public ExplorerManager getExplorerManager() {
return explorerManager;
}

public void setSelectedNode(AbstractSceneExplorerNode node) {
selectedSpatial = node;
if (node != null) {
lastSelected = node;
public void setSelectedNode(AbstractSceneExplorerNode[] nodes) {
selectedSpatials = nodes;
if (nodes != null) {
lastSelected = nodes;
}
try {
if (node != null) {
explorerManager.setSelectedNodes(new Node[]{node});
// setActivatedNodes(new Node[]{node});
if (nodes != null) {
explorerManager.setSelectedNodes(nodes);
} else {
explorerManager.setSelectedNodes(new Node[]{});
// setActivatedNodes(new Node[]{});
}
} catch (PropertyVetoException ex) {
Exceptions.printStackTrace(ex);
Expand Down Expand Up @@ -309,11 +295,11 @@ public void sceneClosed(SceneRequest request) {
@Override
public void previewCreated(PreviewRequest request) {
}

/**
* @return the selectedSpatial
*/
public AbstractSceneExplorerNode getLastSelected() {
public AbstractSceneExplorerNode[] getLastSelected() {
return lastSelected;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2010 jMonkeyEngine
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -107,14 +107,20 @@ public void actionPerformed(ActionEvent e) {
Vector3f pos;

SceneToolController controller = SceneApplication.getApplication().getStateManager().getState(SceneToolController.class);
if (controller != null && (!controller.getCursorLocation().equals(Vector3f.ZERO))) { // Vector3f.ZERO means not yet clicked
// Vector3f.ZERO means not yet clicked
if (controller != null && (!controller.getCursorLocation().equals(Vector3f.ZERO))) {
pos = controller.getCursorLocation().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0); // Shifting up so a) Netbeans isn't merging Waypoints and b) it's visible
} else {
AbstractSceneExplorerNode node = SceneExplorerTopComponent.findInstance().getLastSelected();
if (node instanceof JmeVector3f) { // null instanceof JmeVector3f == false
pos = ((JmeVector3f)node).getVector3f().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0);
AbstractSceneExplorerNode[] nodes = SceneExplorerTopComponent.findInstance().getLastSelected();
if(nodes == null || nodes.length == 0) {
return;
}
final AbstractSceneExplorerNode node = nodes[0];
if (node instanceof JmeVector3f jmeVector3f) {
pos = jmeVector3f.getVector3f().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0);
} else {
pos = new Vector3f(0f, 1.0f, 0f); // Default is a bit over the Center
// Default is a bit over the Center
pos = new Vector3f(0f, 1.0f, 0f);
}
}

Expand Down
Loading
Loading