ANIMATOR : Remove possible error 36/18236/1
authorseongwon.shim <seongwon.shim@samsung.com>
Wed, 19 Mar 2014 07:04:40 +0000 (16:04 +0900)
committerseongwon.shim <seongwon.shim@samsung.com>
Wed, 19 Mar 2014 07:04:40 +0000 (16:04 +0900)
Add defense code for possible error by static analyzer

Change-Id: I5bec8e85d6ae3292b3f3154e24ce70d2eb2f52f9
Signed-off-by: seongwon.shim <seongwon.shim@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/gef/command/ActoinAnimationGroupChangeCommand.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/gef/command/ActoinAnimationGroupCreateCommand.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/gef/command/AnimationPathCurveCreateCommand.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/gef/command/AnimationPathMoveCommand.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/gef/viewer/AnimatorBrowserViewer.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimationPathModel.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorModelManager.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/TransformationProperty.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/io/AnimatorFileWriter.java

index 9f7b2aa..16e3abe 100644 (file)
@@ -99,15 +99,18 @@ public class ActoinAnimationGroupChangeCommand extends Command {
         AnimatorTrigger trigger = animatorModelManager.getAnimatorTrigger(eventName, selelectModel);
 
         beforeActionAnimation = (AnimatorActionAnimation) trigger.getChild(selectBarIndex);
-        if (afterActionAnimation == null)
+        if (afterActionAnimation == null) {
             afterActionAnimation =
                     animatorModelManager
                             .createAnimatorActionAnimation(groupId,
                                                            convertActionAnimationGroupTypes(type),
                                                            time, trigger);
+        }
 
-        trigger.removeChild(beforeActionAnimation);
-        trigger.addChild(selectBarIndex, afterActionAnimation);
+        if(afterActionAnimation != null) {
+               trigger.removeChild(beforeActionAnimation);
+               trigger.addChild(selectBarIndex, afterActionAnimation);
+        }
     }
 
     /*
index 8eb11d2..05c2b80 100644 (file)
@@ -90,14 +90,17 @@ public class ActoinAnimationGroupCreateCommand extends Command {
     public void execute() {
         AnimatorModelManager animatorModelManager = AnimatorModelManager.getInstance(appManager);
         AnimatorTrigger trigger = animatorModelManager.getAnimatorTrigger(eventName, selelectModel);
-        if (actionAnimation == null)
+        if (actionAnimation == null) {
             actionAnimation =
                     animatorModelManager
                             .createAnimatorActionAnimation(groupId,
                                                            convertActionAnimationGroupTypes(type),
                                                            time, trigger);
+        }
 
-        trigger.addChild(actionAnimation);
+        if(actionAnimation != null) {
+               trigger.addChild(actionAnimation);
+        }
     }
 
     /*
index 39b0587..24a4041 100644 (file)
@@ -23,6 +23,7 @@
 
 package org.tizen.webuibuilder.animator.gef.command;
 
+import org.tizen.webuibuilder.animator.model.AnimationPathCurve;
 import org.tizen.webuibuilder.animator.model.AnimatorModelManager;
 import org.tizen.webuibuilder.animator.utils.AnimatorUtils;
 
@@ -32,12 +33,15 @@ import org.tizen.webuibuilder.animator.utils.AnimatorUtils;
 public class AnimationPathCurveCreateCommand extends AnimationPathCommand {
 
     public void execute() {
-        AnimatorModelManager animatorModelManager =
+       AnimatorModelManager animatorModelManager =
                  AnimatorModelManager.getInstance(AnimatorUtils.getAppManager());
         
-        getModel().insertCurveToModel(animatorModelManager.getModelFactory(), getIndex(), getCurveIndex(),
-                                      getModel().getCurve(getIndex(), getCurveIndex()));
-        super.execute();
+       AnimationPathCurve curve = getModel().getCurve(getIndex(), getCurveIndex());
+       if(curve != null) {
+               getModel().insertCurveToModel(animatorModelManager.getModelFactory(), getIndex(), getCurveIndex(),
+                               curve);
+       }
+       super.execute();
     }
 
     public void undo() {
index 6c08b16..1ede457 100644 (file)
@@ -41,8 +41,10 @@ public class AnimationPathMoveCommand extends AnimationPathCommand {
             getModel().setKeyFrameToModel(getIndex(), p.x, p.y);
         } else {
             setOldCurve(getModel().getCurveFromModel(getIndex(), getCurveIndex()));
-            getModel().setCurveToModel(getIndex(), getCurveIndex(),
-                                       getModel().getCurve(getIndex(), getCurveIndex()));
+            AnimationPathCurve curve = getModel().getCurve(getIndex(), getCurveIndex());
+            if(curve != null) {
+               getModel().setCurveToModel(getIndex(), getCurveIndex(), curve);
+            }
         }
         super.execute();
     }
index d74feda..8f4444d 100644 (file)
@@ -395,11 +395,11 @@ public class AnimatorBrowserViewer extends HoverBrowserViewer {
             if (part.getPartId() != null && !part.getPartId().isEmpty()) {
                 WidgetPosition pos = widgetPositions.get(part.getPartId());
                 if (pos != null) {
-                    if (isFireEvent) {
-                        ((AnimatorPart)part).setAnimationVisualPosition(pos);
-                    } else {
-                        ((AnimatorPart)part).setAnimationVisualPosition(pos);
-                    }
+//                    if (isFireEvent) {
+                       ((AnimatorPart)part).setAnimationVisualPosition(pos);
+//                    } else {
+//                        ((AnimatorPart)part).setAnimationVisualPosition(pos);
+//                    }
                 }
             }
 
@@ -432,22 +432,24 @@ public class AnimatorBrowserViewer extends HoverBrowserViewer {
             /*
              * Add the first keyframe in Selector
              */
-            if (keyFrame.getDelay() == selector.getDelay()) {
+            if (Double.compare(keyFrame.getDelay(),selector.getDelay()) == 0) {
                 updateAnimationFWAndDetect(selector, currentAnimationGroupId, pointTime);
+            } else {
+               updateAnimationFW(selector, currentAnimationGroupId, pointTime);
             }
             /*
              * Add the last keyframe in Selector
              */
-            else if (keyFrame.getDelay() + keyFrame.getDuration() == selector.getDelay()
-                    + selector.getDuration()) {
+            /*else if (Double.compare(keyFrame.getDelay() + keyFrame.getDuration(), selector.getDelay()
+                    + selector.getDuration()) == 0) {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
             /*
              * Add the middle keyframe in Selector
              */
-            else {
+            /*else {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
         }
 
         /*
@@ -486,21 +488,23 @@ public class AnimatorBrowserViewer extends HoverBrowserViewer {
              */
             if (keyFrame.getDelay() < selector.getDelay()) {
                 updateAnimationFWAndDetect(selector, currentAnimationGroupId, pointTime);
+            } else {
+               updateAnimationFW(selector, currentAnimationGroupId, pointTime);
             }
             /*
              * Remove the last keyframe in Selector (KeyFrame's delay + duration) > (Selector's
              * delay + duration)
              */
-            else if (keyFrame.getDelay() + keyFrame.getDuration() > selector.getDelay()
+            /*else if (keyFrame.getDelay() + keyFrame.getDuration() > selector.getDelay()
                     + selector.getDuration()) {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
             /*
              * Remove the middle keyframe in Selector
              */
-            else {
+            /*else {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
         }
 
         /*
@@ -524,15 +528,17 @@ public class AnimatorBrowserViewer extends HoverBrowserViewer {
             // Add to front
             if (0.0 <= pointTime && pointTime < delay) {
                 updateAnimationFWAndDetect(selector, currentAnimationGroupId, pointTime);
+            } else {
+               updateAnimationFW(selector, currentAnimationGroupId, pointTime);
             }
             // Add to middle
-            else if (delay < pointTime && pointTime < duration) {
+            /*else if (delay < pointTime && pointTime < duration) {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
             // Add to end
-            else {
+            /*else {
                 updateAnimationFW(selector, currentAnimationGroupId, pointTime);
-            }
+            }*/
         }
 
         /*
index 60a9b44..b4f715f 100644 (file)
@@ -85,23 +85,25 @@ public class AnimationPathModel implements IPropertySource {
             if ((frame.getCurveFrameSize() > 0) && (i + 1 < mergedFrames.size())) {
 
                 AnimatorFrame nextFrame = getNextFrame(mergedFrames, i);
+                if(nextFrame != null) {
+                    left = getPixelProperty(frame, Constants.translateX, translateInDesigner.width);
+                    top = getPixelProperty(frame, Constants.translateY, translateInDesigner.height);
 
-                left = getPixelProperty(frame, Constants.translateX, translateInDesigner.width);
-                top = getPixelProperty(frame, Constants.translateY, translateInDesigner.height);
+                    Point location = new Point(left, top);
 
-                Point location = new Point(left, top);
+                    PointList pointList =
+                            getCurveFramePoints(frame, nextFrame, translateInDesigner.width,
+                                                translateInDesigner.height);
 
-                PointList pointList =
-                        getCurveFramePoints(frame, nextFrame, translateInDesigner.width,
-                                            translateInDesigner.height);
+                    if(pointList != null) {
+                       List<AnimatorFrame> curves = getCurveFrames(modelFactory, pointList, location, frame, nextFrame);
 
-                List<AnimatorFrame> curves = getCurveFrames(modelFactory, pointList, location, frame, nextFrame);
-
-                curves.remove(curves.size() - 1);
-
-                interpolateTransformProperties(curves, propertiesUsed, frame, nextFrame);
-                frames.addAll(curves);
+                        curves.remove(curves.size() - 1);
 
+                        interpolateTransformProperties(curves, propertiesUsed, frame, nextFrame);
+                        frames.addAll(curves);
+                    }
+                }
             }
             i++;
 
@@ -556,7 +558,7 @@ public class AnimationPathModel implements IPropertySource {
         return p.getTranslated(-pos.x, -pos.y);
     }
 
-    private class CssValueForLocation {
+    private static class CssValueForLocation {
         int left = 0;
         int top = 0;
         int width = 0;
index 46ee5fb..017e36a 100644 (file)
@@ -1393,7 +1393,9 @@ public class AnimatorModelManager implements ISelectionListener, IPageDataSetLis
                 NodeList heads = editDoc.getElementsByTagName("head");
                 if (heads == null) {
                     Element newElmHead = editDoc.createElement("head");
-                    editDoc.insertBefore(newElmHead, editDoc.getFirstChild());
+                    if(newElmHead != null) {
+                       editDoc.insertBefore(newElmHead, editDoc.getFirstChild());
+                    }
                 }
                 Element elm = (Element) heads.item(0);
 
index a19daa5..01c97db 100644 (file)
@@ -79,7 +79,7 @@ public class TransformationProperty {
             builder.append(rotateZ);
             builder.append(") ");
         }
-        if (rotateY != null) {
+        if (rotateX != null) {
             builder.append("rotateX(");
             builder.append(rotateX);
             builder.append(") ");
index b09be06..50644b6 100644 (file)
@@ -116,17 +116,23 @@ public class AnimatorFileWriter {
             if (jsFile.exists()) {
                 jsFile.delete();
             }
-
             return;
         }
 
+        FileWriter fw = null;
         try {
-            FileWriter fw = new FileWriter(modelJsFilePath);
+            fw = new FileWriter(modelJsFilePath);
             fw.write(fileModel);
-            fw.close();
-
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+               try {
+                if (fw != null) {
+                       fw.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
     }
 
@@ -235,6 +241,7 @@ public class AnimatorFileWriter {
      * @param rootPart
      */
     public static void writeCssFileModel(AppManager appManager, Part rootPart) {
+       FileWriter fw = null;
         try {
             String animationCssString = getAnimatorKeyFrameString(rootPart);
 
@@ -251,12 +258,18 @@ public class AnimatorFileWriter {
                 return;
             }
 
-            FileWriter fw = new FileWriter(modelCssFilePath);
+            fw = new FileWriter(modelCssFilePath);
             fw.write(animationCssString.toString());
-            fw.close();
-
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+               try {
+                if (fw != null) {
+                       fw.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
     }