11/*
2- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
2+ * Copyright (c) 2009-2025 jMonkeyEngine
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are
7+ * met:
8+ *
9+ * * Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ *
12+ * * Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+ * may be used to endorse or promote products derived from this software
18+ * without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431 */
532package com .jme3 .gde .core .dnd ;
633
34+ import com .jme3 .gde .core .assets .AssetDataNode ;
735import com .jme3 .gde .core .sceneviewer .SceneViewerTopComponent ;
836import com .jme3 .math .Vector2f ;
937import java .awt .Cursor ;
1947import java .util .logging .Logger ;
2048
2149/**
22- * Handles dropping Materials or Spatial from the AssetBrowser to the
23- * SceneViewer
50+ * Handles dropping Materials or Spatial from the AssetBrowser and Projects tab
51+ * to the SceneViewer
52+ *
2453 * @author rickard
2554 */
2655public class SceneViewerDropTargetListener implements DropTargetListener {
@@ -57,8 +86,7 @@ public void dragExit(final DropTargetEvent dte) {
5786 @ Override
5887 public void drop (final DropTargetDropEvent dtde ) {
5988 this .rootPanel .setCursor (Cursor .getDefaultCursor ());
60-
61- AssetNameHolder transferableObj = null ;
89+ String assetKey = null ;
6290 Transferable transferable = null ;
6391 DataFlavor flavor = null ;
6492
@@ -69,26 +97,51 @@ public void drop(final DropTargetDropEvent dtde) {
6997 flavor = flavors [0 ];
7098 // What does the Transferable support
7199 if (transferable .isDataFlavorSupported (flavor )) {
72- transferableObj = (AssetNameHolder ) dtde .getTransferable ().getTransferData (flavor );
100+ Object o = dtde .getTransferable ().getTransferData (flavor );
101+ if (o instanceof AssetNameHolder assetNameHolder ) {
102+ assetKey = assetNameHolder .getAssetName ();
103+ } else if (o instanceof AssetDataNode assetDataNode ) {
104+ assetKey = assetDataNode .getAssetName ();
105+ }
73106 }
74107
75108 } catch (UnsupportedFlavorException | IOException ex ) {
76109 Logger .getLogger (SceneViewerDropTargetListener .class .getName ()).log (Level .WARNING , "Non-supported flavor {0}" , transferable );
77110 }
78111
79- if (transferable == null || transferableObj == null ) {
112+ if (transferable == null || assetKey == null ) {
80113 return ;
81114 }
82115
83116 final int dropYLoc = dtde .getLocation ().y ;
84117 final int dropXLoc = dtde .getLocation ().x ;
85118
86- if (flavor instanceof SpatialDataFlavor ) {
87- rootPanel .addModel (transferableObj . getAssetName () , new Vector2f (dropXLoc , dropYLoc ));
88- } else if (flavor instanceof MaterialDataFlavor ) {
89- rootPanel .applyMaterial (transferableObj . getAssetName () , new Vector2f (dropXLoc , dropYLoc ));
119+ if (flavor instanceof SpatialDataFlavor || isModelExtension ( assetKey ) ) {
120+ rootPanel .addModel (assetKey , new Vector2f (dropXLoc , dropYLoc ));
121+ } else if (flavor instanceof MaterialDataFlavor || isMaterialExtension ( assetKey ) ) {
122+ rootPanel .applyMaterial (assetKey , new Vector2f (dropXLoc , dropYLoc ));
90123 }
91124
92125 }
93126
127+ /**
128+ * Determines if the asset key represents a model/spatial asset by checking its file extension.
129+ *
130+ * @param assetKey The asset key (typically a filename or path); this method checks if it ends with the model file extension.
131+ * @return true if the asset key is for model files
132+ */
133+ private boolean isModelExtension (String assetKey ) {
134+ return assetKey .endsWith ("j3o" );
135+ }
136+
137+ /**
138+ * Determines if the asset key represents a material asset by checking its file extension.
139+ *
140+ * @param assetKey The asset key (typically a filename or path); this method checks if it ends with the material file extension.
141+ * @return true if the asset key is for material files
142+ */
143+ private boolean isMaterialExtension (String assetKey ) {
144+ return assetKey .endsWith ("j3m" );
145+ }
146+
94147}
0 commit comments