Browse Source

fixing codacy issues

rickard 3 years ago
parent
commit
56d2080da6

+ 21 - 18
jme3-core/src/com/jme3/gde/core/assets/ExternalChangeScanner.java

@@ -41,6 +41,12 @@ import com.jme3.gde.core.util.datatransfer.MaterialDataFromOriginal;
 import com.jme3.gde.core.util.datatransfer.MeshDataFromOriginal;
 import com.jme3.gde.core.util.datatransfer.TransformDataFromOriginal;
 import com.jme3.scene.Spatial;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import org.netbeans.api.progress.ProgressHandle;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
@@ -48,11 +54,6 @@ import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObjectNotFoundException;
 import org.openide.util.Exceptions;
 
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.Callable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 /**
  * This class scans for external changes of a j3o models original file and tries
  * to update the data when it changed.
@@ -106,25 +107,25 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
         if (!userNotified.getAndSet(true)) {
             //TODO: execute on separate thread?
             java.awt.EventQueue.invokeLater(() -> {
-                final String NO_OPTION = "No";
-                final String ALL_OPTION = "All";
-                final String MESH_OPTION = "Only mesh data";
-                NotifyDescriptor.Confirmation mesg =
+                final String noOption = "No";
+                final String allOption = "All";
+                final String meshOption = "Only mesh data";
+                final NotifyDescriptor.Confirmation message =
                         new NotifyDescriptor.Confirmation("Original file for "
                                 + assetDataObject.getName() + " changed\nTry "
                                 + "and reapply data to j3o file?",
                                 "Original file changed",
                                 NotifyDescriptor.YES_NO_CANCEL_OPTION,
                                 NotifyDescriptor.QUESTION_MESSAGE);
-                mesg.setOptions(new Object[]{ALL_OPTION, MESH_OPTION,
-                        NO_OPTION});
-                DialogDisplayer.getDefault().notify(mesg);
-                if (mesg.getValue().equals(NO_OPTION)) {
+                message.setOptions(new Object[]{allOption, meshOption,
+                        noOption});
+                DialogDisplayer.getDefault().notify(message);
+                if (message.getValue().equals(noOption)) {
                     userNotified.set(false);
                     return;
                 }
                 SceneApplication.getApplication().enqueue((Callable<Void>) () -> {
-                    applyExternalData(mesg.getValue().equals(MESH_OPTION));
+                    applyExternalData(message.getValue().equals(meshOption));
                     return null;
                 });
                 userNotified.set(false);
@@ -135,8 +136,9 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
         }
     }
 
-    private void applyExternalData(boolean onlyMeshData) {
-        ProgressHandle handle = ProgressHandle.createHandle("Updating file "
+    private void applyExternalData(final boolean onlyMeshData) {
+        final ProgressHandle handle = ProgressHandle.createHandle("Updating "
+                + "file "
                 + "data");
         handle.start();
         try {
@@ -247,8 +249,9 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
     }
 
     @Override
-    public void assetDataPropertyChanged(String property, String before,
-                                         String after) {
+    public void assetDataPropertyChanged(final String property,
+                                         final String before,
+                                         final String after) {
         if (SpatialUtil.ORIGINAL_PATH.equals(property)) {
             LOGGER.log(Level.INFO, "Notified about change in AssetData "
                     + "properties for {0}", assetDataObject.getName());

+ 14 - 3
jme3-core/src/com/jme3/gde/core/util/TaggedSpatialFinder.java

@@ -1,6 +1,7 @@
 package com.jme3.gde.core.util;
 
 import com.jme3.scene.Spatial;
+
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -13,6 +14,14 @@ public class TaggedSpatialFinder {
     private static final Logger LOGGER =
             Logger.getLogger(TaggedSpatialFinder.class.getName());
 
+    /**
+     * Finds a previously marked spatial in the supplied root Spatial, creates
+     * the name and path to be looked for from the given needle Spatial.
+     *
+     * @param root   supplied root Spatial
+     * @param needle
+     * @return found spatial
+     */
     public Spatial find(final Spatial root, final Spatial needle) {
         if (needle == null) {
             LOGGER.log(Level.WARNING, "Trying to find null needle for {0}",
@@ -34,9 +43,11 @@ public class TaggedSpatialFinder {
         }
         final SpatialHolder holder = new SpatialHolder();
         root.depthFirstTraversal(spatial -> {
-            String spName = spatial.getUserData(SpatialUtil.ORIGINAL_NAME);
-            String spPath = spatial.getUserData(SpatialUtil.ORIGINAL_PATH);
-            if (name.equals(spName) && path.equals(spPath) && clazz.isInstance(spatial)) {
+            final String spatialName =
+                    spatial.getUserData(SpatialUtil.ORIGINAL_NAME);
+            final String spPath =
+                    spatial.getUserData(SpatialUtil.ORIGINAL_PATH);
+            if (name.equals(spatialName) && path.equals(spPath) && clazz.isInstance(spatial)) {
                 if (holder.spatial == null) {
                     holder.spatial = spatial;
                 } else {

+ 29 - 17
jme3-core/src/com/jme3/gde/core/util/datatransfer/AnimationDataFromOriginal.java

@@ -6,6 +6,7 @@ import com.jme3.gde.core.scene.ApplicationLogHandler;
 import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.scene.Spatial;
 import com.jme3.util.clone.Cloner;
+
 import java.util.Collection;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -40,23 +41,9 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
                     //where UserData "AttachedBone" == Bone and move it
                     // to new Bone
                     final AnimComposer myAnimControl =
-                            mySpatial.getControl(AnimComposer.class);
-
-                    if (myAnimControl != null) {
-                        mySpatial.removeControl(myAnimControl);
-                    }
+                            getAndRemoveControl(mySpatial);
 
-                    myAnimControl.cloneFields(new Cloner(),
-                            animComposer.jmeClone());
-                    copyAnimClips(myAnimControl, animComposer);
-                    if (mySpatial.getControl(AnimComposer.class) == null) {
-                        LOGGER.log(Level.FINE, "Adding control for {0}",
-                                mySpatial.getName());
-                        mySpatial.addControl(myAnimControl);
-                    } else {
-                        LOGGER.log(Level.FINE, "Control for {0} was added"
-                                + " automatically", mySpatial.getName());
-                    }
+                    updateAndAddControl(mySpatial, myAnimControl, animComposer);
 
                     LOGGER.log(ApplicationLogHandler.LogLevel.FINE,
                             "Updated animation for {0}",
@@ -70,7 +57,32 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
         });
     }
 
-    private void copyAnimClips(final AnimComposer control, final AnimComposer original) {
+    private AnimComposer getAndRemoveControl(Spatial spatial) {
+        final AnimComposer myAnimControl =
+                mySpatial.getControl(AnimComposer.class);
+        if (myAnimControl != null) {
+            mySpatial.removeControl(myAnimControl);
+        }
+        return myAnimControl;
+    }
+
+    private void updateAndAddControl(Spatial spatial, AnimComposer newControl
+            , AnimComposer originalCOntrol) {
+        newControl.cloneFields(new Cloner(),
+                originalCOntrol.jmeClone());
+        copyAnimClips(newControl, originalCOntrol);
+        if (spatial.getControl(AnimComposer.class) == null) {
+            LOGGER.log(Level.FINE, "Adding control for {0}",
+                    spatial.getName());
+            spatial.addControl(newControl);
+        } else {
+            LOGGER.log(Level.FINE, "Control for {0} was added"
+                    + " automatically", spatial.getName());
+        }
+    }
+
+    private void copyAnimClips(final AnimComposer control,
+                               final AnimComposer original) {
         final Collection<AnimClip> clips = original.getAnimClips();
         for (AnimClip c : clips) {
             control.addAnimClip(c);

+ 1 - 0
jme3-core/src/com/jme3/gde/core/util/datatransfer/MaterialDataFromOriginal.java

@@ -5,6 +5,7 @@ import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.SceneGraphVisitorAdapter;
 import com.jme3.scene.Spatial;
+
 import java.util.logging.Logger;
 
 /**

+ 1 - 1
jme3-core/src/com/jme3/gde/core/util/datatransfer/TransformDataFromOriginal.java

@@ -12,7 +12,7 @@ import java.util.logging.Logger;
  * Copies Transform data (translation, rotation, scale) from an updated
  * spatial to the original.
  */
-public class TransformDataFromOriginal implements SpatialDataTransferInterface {
+public final class TransformDataFromOriginal implements SpatialDataTransferInterface {
 
     private static final Logger LOGGER =
             Logger.getLogger(AnimationDataFromOriginal.class.getName());