rickard 6 днів тому
батько
коміт
8b12a9a43d

+ 2 - 9
jme3-core/src/com/jme3/gde/core/assets/AssetDataNode.java

@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2009-2010 jMonkeyEngine
+ *  Copyright (c) 2009-2025 jMonkeyEngine
  *  All rights reserved.
  * 
  *  Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,7 @@ public class AssetDataNode extends DataNode implements AssetNameHolder {
         if (key == null) {
             return sheet;
         }
-        
+
         Sheet.Set set = Sheet.createPropertiesSet();
         set.setName("AssetKey");
         set.setDisplayName("Conversion Settings");
@@ -100,11 +100,4 @@ public class AssetDataNode extends DataNode implements AssetNameHolder {
         return null;
     }
 
-    @Override
-    public void setAssetName(String name) {
-        // AssetDataNode's asset name is derived from the underlying asset key
-        // and typically shouldn't be changed directly
-        // This method is required by the interface but doesn't need implementation
-        // for the drag-and-drop use case
-    }
 }

+ 29 - 4
jme3-core/src/com/jme3/gde/core/dnd/AssetNameHolder.java

@@ -1,6 +1,33 @@
 /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ *  Copyright (c) 2009-2025 jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 package com.jme3.gde.core.dnd;
 
@@ -11,6 +38,4 @@ package com.jme3.gde.core.dnd;
 public interface AssetNameHolder {
 
     String getAssetName();
-
-    void setAssetName(String name);
 }

+ 52 - 44
jme3-core/src/com/jme3/gde/core/dnd/SceneViewerDropTargetListener.java

@@ -1,9 +1,37 @@
 /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ *  Copyright (c) 2009-2025 jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 package com.jme3.gde.core.dnd;
 
+import com.jme3.gde.core.assets.AssetDataNode;
 import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent;
 import com.jme3.math.Vector2f;
 import java.awt.Cursor;
@@ -19,8 +47,9 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
- * Handles dropping Materials or Spatial from the AssetBrowser to the
- * SceneViewer
+ * Handles dropping Materials or Spatial from the AssetBrowser and Projects tab
+ * to the SceneViewer
+ *
  * @author rickard
  */
 public class SceneViewerDropTargetListener implements DropTargetListener {
@@ -57,8 +86,7 @@ public class SceneViewerDropTargetListener implements DropTargetListener {
     @Override
     public void drop(final DropTargetDropEvent dtde) {
         this.rootPanel.setCursor(Cursor.getDefaultCursor());
-
-        AssetNameHolder transferableObj = null;
+        String assetKey = null;
         Transferable transferable = null;
         DataFlavor flavor = null;
 
@@ -69,71 +97,51 @@ public class SceneViewerDropTargetListener implements DropTargetListener {
             flavor = flavors[0];
             // What does the Transferable support
             if (transferable.isDataFlavorSupported(flavor)) {
-                transferableObj = (AssetNameHolder) dtde.getTransferable().getTransferData(flavor);
+                Object o = dtde.getTransferable().getTransferData(flavor);
+                if (o instanceof AssetNameHolder assetNameHolder) {
+                    assetKey = assetNameHolder.getAssetName();
+                } else if (o instanceof AssetDataNode assetDataNode) {
+                    assetKey = assetDataNode.getAssetName();
+                }
             }
 
         } catch (UnsupportedFlavorException | IOException ex) {
             Logger.getLogger(SceneViewerDropTargetListener.class.getName()).log(Level.WARNING, "Non-supported flavor {0}", transferable);
         }
 
-        if (transferable == null || transferableObj == null) {
+        if (transferable == null || assetKey == null) {
             return;
         }
 
         final int dropYLoc = dtde.getLocation().y;
         final int dropXLoc = dtde.getLocation().x;
 
-        if (flavor instanceof SpatialDataFlavor) {
-            rootPanel.addModel(transferableObj.getAssetName(), new Vector2f(dropXLoc, dropYLoc));
-        } else if (flavor instanceof MaterialDataFlavor) {
-            rootPanel.applyMaterial(transferableObj.getAssetName(), new Vector2f(dropXLoc, dropYLoc));
-        } else {
-            // Handle generic flavors by determining asset type from file extension
-            String assetName = transferableObj.getAssetName();
-            if (assetName != null) {
-                String extension = getFileExtension(assetName);
-                if (isModelExtension(extension)) {
-                    rootPanel.addModel(assetName, new Vector2f(dropXLoc, dropYLoc));
-                } else if (isMaterialExtension(extension)) {
-                    rootPanel.applyMaterial(assetName, new Vector2f(dropXLoc, dropYLoc));
-                }
-            }
+        if (flavor instanceof SpatialDataFlavor || isModelExtension(assetKey)) {
+            rootPanel.addModel(assetKey, new Vector2f(dropXLoc, dropYLoc));
+        } else if (flavor instanceof MaterialDataFlavor || isMaterialExtension(assetKey)) {
+            rootPanel.applyMaterial(assetKey, new Vector2f(dropXLoc, dropYLoc));
         }
 
     }
 
-    /**
-     * Extracts the file extension from an asset name.
-     * @param filename The asset filename
-     * @return The file extension in lowercase, or empty string if no extension
-     */
-    private String getFileExtension(String filename) {
-        if (filename == null) {
-            return "";
-        }
-        int lastDotIndex = filename.lastIndexOf('.');
-        if (lastDotIndex == -1 || lastDotIndex == filename.length() - 1) {
-            return "";
-        }
-        return filename.substring(lastDotIndex + 1).toLowerCase();
-    }
-
     /**
      * Determines if the file extension represents a model/spatial asset.
+     *
      * @param extension The file extension
      * @return true if the extension is for model files
      */
-    private boolean isModelExtension(String extension) {
-        return "j3o".equals(extension);
+    private boolean isModelExtension(String assetKey) {
+        return assetKey.endsWith("j3o");
     }
 
     /**
      * Determines if the file extension represents a material asset.
-     * @param extension The file extension  
+     *
+     * @param extension The file extension
      * @return true if the extension is for material files
      */
-    private boolean isMaterialExtension(String extension) {
-        return "j3m".equals(extension);
+    private boolean isMaterialExtension(String assetKey) {
+        return assetKey.endsWith("j3m");
     }
 
 }