Skip to content

Commit 14d2632

Browse files
authored
Merge pull request #642 from neph1/fix_multi_select
Allow node actions on multiple selected nodes (Delete, etc)
2 parents eaf2e3d + 10918e2 commit 14d2632

File tree

5 files changed

+190
-157
lines changed

5 files changed

+190
-157
lines changed

jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
7979
private static final Logger logger = Logger.getLogger(SceneExplorerTopComponent.class.getName());
8080
private static SceneExplorerTopComponent instance;
8181
private static final String PREFERRED_ID = "SceneExplorerTopComponent";
82-
// private final Result<AbstractSceneExplorerNode> nodeSelectionResult;
83-
private AbstractSceneExplorerNode selectedSpatial;
84-
private AbstractSceneExplorerNode lastSelected;
82+
83+
private AbstractSceneExplorerNode[] selectedSpatials;
84+
private AbstractSceneExplorerNode[] lastSelected;
8585
private final Map<String, MaterialChangeProvider> materialChangeProviders = new HashMap<>();
8686
private final Map<String, List<MaterialChangeListener>> materialChangeListeners = new HashMap<>();
87-
private transient ExplorerManager explorerManager = new ExplorerManager();
87+
88+
private final transient ExplorerManager explorerManager = new ExplorerManager();
8889

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

151152
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
152-
if (selectedSpatial == null) {
153+
if (selectedSpatials == null) {
153154
return;
154155
}
155-
SwingUtilities.invokeLater(() -> {
156-
Node rootNode = SceneExplorerTopComponent.findInstance().getExplorerManager().getRootContext();
157-
if (rootNode instanceof JmeNode jmeNode) {
158-
SceneApplication.getApplication().enqueue(new RefreshJmeSpatial(jmeNode, selectedSpatial.getName()));
159-
} else {
160-
selectedSpatial.refresh(false);
161-
}
162-
});
163-
156+
for (AbstractSceneExplorerNode node: selectedSpatials) {
157+
node.refresh(false);
158+
}
164159
}//GEN-LAST:event_jButton1ActionPerformed
165160
// Variables declaration - do not modify//GEN-BEGIN:variables
166161
private javax.swing.JScrollPane explorerScrollPane;
@@ -188,13 +183,13 @@ public static synchronized SceneExplorerTopComponent getDefault() {
188183
* @return
189184
*/
190185
public static synchronized SceneExplorerTopComponent findInstance() {
191-
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
192-
if (win == null) {
186+
TopComponent window = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
187+
if (window == null) {
193188
logger.warning(
194189
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
195190
return getDefault();
196191
}
197-
if (win instanceof SceneExplorerTopComponent sceneExplorerTopComponent) {
192+
if (window instanceof SceneExplorerTopComponent sceneExplorerTopComponent) {
198193
return sceneExplorerTopComponent;
199194
}
200195
logger.warning(
@@ -227,27 +222,20 @@ public void componentClosed() {
227222
SceneApplication.getApplication().removeSceneListener(this);
228223
// TODO add custom code on component closing
229224
}
230-
225+
231226
void writeProperties(java.util.Properties p) {
232-
// better to version settings since initial version as advocated at
233-
// http://wiki.apidesign.org/wiki/PropertyFiles
227+
// Required. Do not remove.
234228
p.setProperty("version", "1.0");
235-
// TODO store your settings
236229
}
237-
230+
238231
Object readProperties(java.util.Properties p) {
232+
// Required. Do not remove.
239233
if (instance == null) {
240234
instance = this;
241235
}
242-
instance.readPropertiesImpl(p);
243236
return instance;
244237
}
245238

246-
private void readPropertiesImpl(java.util.Properties p) {
247-
// TODO read your settings according to their version
248-
249-
}
250-
251239
@Override
252240
protected String preferredID() {
253241
return PREFERRED_ID;
@@ -263,18 +251,16 @@ public ExplorerManager getExplorerManager() {
263251
return explorerManager;
264252
}
265253

266-
public void setSelectedNode(AbstractSceneExplorerNode node) {
267-
selectedSpatial = node;
268-
if (node != null) {
269-
lastSelected = node;
254+
public void setSelectedNode(AbstractSceneExplorerNode[] nodes) {
255+
selectedSpatials = nodes;
256+
if (nodes != null) {
257+
lastSelected = nodes;
270258
}
271259
try {
272-
if (node != null) {
273-
explorerManager.setSelectedNodes(new Node[]{node});
274-
// setActivatedNodes(new Node[]{node});
260+
if (nodes != null) {
261+
explorerManager.setSelectedNodes(nodes);
275262
} else {
276263
explorerManager.setSelectedNodes(new Node[]{});
277-
// setActivatedNodes(new Node[]{});
278264
}
279265
} catch (PropertyVetoException ex) {
280266
Exceptions.printStackTrace(ex);
@@ -309,11 +295,11 @@ public void sceneClosed(SceneRequest request) {
309295
@Override
310296
public void previewCreated(PreviewRequest request) {
311297
}
312-
298+
313299
/**
314300
* @return the selectedSpatial
315301
*/
316-
public AbstractSceneExplorerNode getLastSelected() {
302+
public AbstractSceneExplorerNode[] getLastSelected() {
317303
return lastSelected;
318304
}
319305

jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/MotionPathPopup.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2010 jMonkeyEngine
2+
* Copyright (c) 2009-2024 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -107,14 +107,20 @@ public void actionPerformed(ActionEvent e) {
107107
Vector3f pos;
108108

109109
SceneToolController controller = SceneApplication.getApplication().getStateManager().getState(SceneToolController.class);
110-
if (controller != null && (!controller.getCursorLocation().equals(Vector3f.ZERO))) { // Vector3f.ZERO means not yet clicked
110+
// Vector3f.ZERO means not yet clicked
111+
if (controller != null && (!controller.getCursorLocation().equals(Vector3f.ZERO))) {
111112
pos = controller.getCursorLocation().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0); // Shifting up so a) Netbeans isn't merging Waypoints and b) it's visible
112113
} else {
113-
AbstractSceneExplorerNode node = SceneExplorerTopComponent.findInstance().getLastSelected();
114-
if (node instanceof JmeVector3f) { // null instanceof JmeVector3f == false
115-
pos = ((JmeVector3f)node).getVector3f().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0);
114+
AbstractSceneExplorerNode[] nodes = SceneExplorerTopComponent.findInstance().getLastSelected();
115+
if(nodes == null || nodes.length == 0) {
116+
return;
117+
}
118+
final AbstractSceneExplorerNode node = nodes[0];
119+
if (node instanceof JmeVector3f jmeVector3f) {
120+
pos = jmeVector3f.getVector3f().clone().addLocal(0, jmeMotionPath.getDebugBoxExtents() * 3f, 0);
116121
} else {
117-
pos = new Vector3f(0f, 1.0f, 0f); // Default is a bit over the Center
122+
// Default is a bit over the Center
123+
pos = new Vector3f(0f, 1.0f, 0f);
118124
}
119125
}
120126

0 commit comments

Comments
 (0)