Checkstyle, comment
Clément DAVID [Mon, 11 Jan 2010 16:00:33 +0000 (17:00 +0100)]
13 files changed:
scilab/modules/xcos/src/java/org/scilab/modules/graph/ScilabGraph.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/SuperBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/EventInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/EventOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ExplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ExplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ImplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ImplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosCanvas.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosComponent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosConstants.java

index 167f8a8..8b47424 100644 (file)
@@ -21,6 +21,7 @@ import org.scilab.modules.gui.tab.Tab;
 import org.scilab.modules.gui.utils.UIElementMapper;
 import org.scilab.modules.gui.window.ScilabWindow;
 import org.scilab.modules.xcos.utils.XcosComponent;
+import org.scilab.modules.xcos.utils.XcosConstants;
 
 import com.mxgraph.swing.mxGraphComponent;
 import com.mxgraph.swing.handler.mxRubberband;
@@ -74,7 +75,7 @@ public class ScilabGraph extends mxGraph {
 
                        if (!redoInAction) {
                                undoManager.undoableEditHappened((mxUndoableEdit) evt
-                                               .getProperty("edit"));
+                                               .getProperty(XcosConstants.EVENT_CHANGE_EDIT));
                                incrementUndoCounter();
                        }
                }
@@ -85,7 +86,7 @@ public class ScilabGraph extends mxGraph {
         */
        private mxIEventListener selectionHandler = new mxIEventListener() {
                public void invoke(Object source, mxEventObject evt) {
-                       List<mxUndoableChange> changes = ((mxUndoableEdit) evt.getProperty("edit")).getChanges();
+                       List<mxUndoableChange> changes = ((mxUndoableEdit) evt.getProperty(XcosConstants.EVENT_CHANGE_EDIT)).getChanges();
                        setSelectionCells(getSelectionCellsForChanges(changes));
                }
        };
index 8d18e85..dd62f3d 100644 (file)
@@ -516,7 +516,7 @@ public class BasicBlock extends XcosUIDObject {
         */
        if (getParentDiagram() instanceof SuperBlockDiagram) {
            SuperBlock parentBlock = ((SuperBlockDiagram) getParentDiagram()).getContainer();
-           parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, "block", parentBlock));
+           parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, XcosConstants.EVENT_BLOCK_UPDATED, parentBlock));
        }
        
     }
@@ -559,7 +559,7 @@ public class BasicBlock extends XcosUIDObject {
                                        // Now read new Block
                                    BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
                                    updateBlockSettings(modifiedBlock);
-                                   getParentDiagram().fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, "block", currentBlock));
+                                   getParentDiagram().fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, currentBlock));
                                    setLocked(false);
                                }
                        });
index 0a677e0..6c35028 100644 (file)
@@ -46,6 +46,7 @@ import org.scilab.modules.xcos.port.input.ExplicitInputPort;
 import org.scilab.modules.xcos.port.input.ImplicitInputPort;
 import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
 import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
@@ -431,7 +432,7 @@ public final class SuperBlock extends BasicBlock {
                updateExportedExplicitOutputPort();
                updateExportedImplicitOutputPort();
                updateExportedEventOutputPort();
-               getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, "block", this));
+               getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, XcosConstants.EVENT_BLOCK_UPDATED, this));
        }
 
        private void updateExportedExplicitInputPort() {
index 5361279..bffdc9c 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -56,7 +57,7 @@ public final class EventInBlock extends ContextUpdate {
        double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
        if(oldValue != newValue){
-           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_EVENT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_EVENT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
        }
     }
 
index 98d3300..5eb0e6c 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -56,7 +57,7 @@ public final class EventOutBlock extends ContextUpdate {
        double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
        if(oldValue != newValue){
-           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_EVENT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_EVENT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
        }
     }
 
index 1992806..3ab3cad 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -55,7 +56,7 @@ public final class ExplicitInBlock extends ContextUpdate {
        double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
        if(oldValue != newValue){
-           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_EXPLICIT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_EXPLICIT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
        }
     }
 
index 9ff6574..bb6c02b 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -56,7 +57,7 @@ public final class ExplicitOutBlock extends ContextUpdate {
        double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
        if(oldValue != newValue){
-           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_EXPLICIT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_EXPLICIT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
        }
     }
 
index b31a07d..bf877cc 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -56,7 +57,7 @@ public final class ImplicitInBlock extends ContextUpdate {
                double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
                if(oldValue != newValue){
-                   getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_IMPLICIT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+                   getParentDiagram().fireEvent(new mxEventObject(XcosEvent.IN_IMPLICIT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
                }
            }
 
index ede1a5a..6ce9d4d 100644 (file)
@@ -16,6 +16,7 @@ import org.scilab.modules.hdf5.scilabTypes.ScilabDouble;
 import org.scilab.modules.hdf5.scilabTypes.ScilabType;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
 
 import com.mxgraph.util.mxEventObject;
@@ -56,7 +57,7 @@ public final class ImplicitOutBlock extends ContextUpdate {
        double newValue = ((ScilabDouble)getIntegerParameters()).getRealPart()[0][0];
 
        if(oldValue != newValue){
-           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_IMPLICIT_VALUE_UPDATED, "old", oldValue, "new", newValue));
+           getParentDiagram().fireEvent(new mxEventObject(XcosEvent.OUT_IMPLICIT_VALUE_UPDATED, XcosConstants.EVENT_CHANGE_OLD, oldValue, XcosConstants.EVENT_CHANGE_NEW, newValue));
        }
     }
 
index 85e3088..9910132 100644 (file)
@@ -93,6 +93,7 @@ import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
 import org.scilab.modules.xcos.port.output.OutputPort;
 import org.scilab.modules.xcos.utils.BlockPositioning;
 import org.scilab.modules.xcos.utils.ConfigXcosManager;
+import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosDialogs;
 import org.scilab.modules.xcos.utils.XcosEvent;
 import org.scilab.modules.xcos.utils.XcosFileType;
@@ -622,7 +623,7 @@ public class XcosDiagram extends ScilabGraph {
            public void invoke(Object source, mxEventObject evt) {
                getModel().beginUpdate();
                refresh();
-               BasicBlock updatedBlock = (BasicBlock) evt.getProperty("block");
+               BasicBlock updatedBlock = (BasicBlock) evt.getProperty(XcosConstants.EVENT_BLOCK_UPDATED);
                BlockPositioning.updateBlockView(updatedBlock);
                getModel().endUpdate();
            }
@@ -723,14 +724,14 @@ public class XcosDiagram extends ScilabGraph {
      */
     private class SuperBlockUpdateTracker implements mxIEventListener {
        public void invoke(Object source, mxEventObject evt) {
-           assert evt.getProperty("block") instanceof SuperBlock;
-           SuperBlock updatedBlock = (SuperBlock) evt.getProperty("block");
+           assert evt.getProperty(XcosConstants.EVENT_BLOCK_UPDATED) instanceof SuperBlock;
+           SuperBlock updatedBlock = (SuperBlock) evt.getProperty(XcosConstants.EVENT_BLOCK_UPDATED);
            updatedBlock.setRealParameters(BlockWriter
                    .convertDiagramToMList(updatedBlock.getChild()));
            if (updatedBlock.getParentDiagram() instanceof SuperBlockDiagram) {
                SuperBlock parentBlock = ((SuperBlockDiagram) updatedBlock
                        .getParentDiagram()).getContainer();
-               parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, "block", parentBlock));
+               parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, XcosConstants.EVENT_BLOCK_UPDATED, parentBlock));
            }
            BlockPositioning.updateBlockView(updatedBlock);
            refresh();
@@ -914,7 +915,7 @@ public class XcosDiagram extends ScilabGraph {
      */
    private class UndoUpdateTracker implements mxIEventListener {
         public void invoke(Object source, mxEventObject evt) {
-            List<mxUndoableChange> changes = ((mxUndoableEdit) evt.getProperty("edit")).getChanges();
+            List<mxUndoableChange> changes = ((mxUndoableEdit) evt.getProperty(XcosConstants.EVENT_CHANGE_EDIT)).getChanges();
             Object[] changedCells = getSelectionCellsForChanges(changes);
             getModel().beginUpdate();
             for (Object object : changedCells) {
index f777bd4..5214794 100644 (file)
@@ -1,3 +1,15 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Clément DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
 package org.scilab.modules.xcos.utils;
 
 import java.awt.AlphaComposite;
@@ -12,8 +24,25 @@ import com.mxgraph.swing.view.mxInteractiveCanvas;
 import com.mxgraph.util.mxConstants;
 import com.mxgraph.util.mxUtils;
 
+/**
+ * Painter for each vertex and edge
+ */
 public class XcosCanvas extends mxInteractiveCanvas {
 
+       /** Default constructor */
+       public XcosCanvas() { }
+       
+       /**
+        * Draw the vertex
+        * 
+        * @param x horizontal coordinate
+        * @param y vertical coordinate
+        * @param w width
+        * @param h height
+        * @param style All the style of the associated vertex
+        * @return always null
+        */
+       @Override
        public Object drawVertex(int x, int y, int w, int h,
                        Hashtable<String, Object> style) {
 
@@ -117,6 +146,19 @@ public class XcosCanvas extends mxInteractiveCanvas {
                return null;
        }
 
+       /**
+        * Draws a rectangle for the given parameters.
+        * 
+        * @param x X-coordinate of the shape.
+        * @param y Y-coordinate of the shape.
+        * @param w Width of the shape.
+        * @param h Height of the shape.
+        * @param fillColor Optional fill color of the shape.
+        * @param fillPaint Optional paint of the shape.
+        * @param penColor Optional stroke color.
+        * @param shadow Boolean indicating if a shadow should be painted.
+        * @param rounded Boolean indicating if the rectangle is rounded.
+        */
        public void drawRect(int x, int y, int w, int h, Color fillColor,
                        Paint fillPaint, Color penColor, boolean shadow, boolean rounded) {
                super.drawRect(x, y, w, h, fillColor, fillPaint, penColor, shadow,
index 44c6b0f..63cdfd6 100644 (file)
@@ -1,3 +1,15 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Clément DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
 package org.scilab.modules.xcos.utils;
 
 import java.awt.Dimension;
@@ -11,24 +23,33 @@ import com.mxgraph.swing.mxGraphComponent;
 import com.mxgraph.view.mxGraph;
 import com.mxgraph.view.mxGraphView;
 
-public class XcosComponent extends mxGraphComponent{
+/**
+ * Customize the default component
+ * @see java.awt.Component
+ */
+public class XcosComponent extends mxGraphComponent {
 
     private static final long serialVersionUID = 1592816691330208090L;
+    private static final int ZOOM_BORDER = 20; // px
 
+    /**
+     * Construct the component with the associated graph
+     * @param graph The associated graph
+     */
     public XcosComponent(mxGraph graph) {
        super(graph);
        
        addComponentListener(new ComponentListener() {
            
            public void componentShown(ComponentEvent arg0) {
-               if(getGraph() instanceof PaletteDiagram) {
-                   ((PaletteDiagram)getGraph()).updateDiagram(getSize().getWidth());
+               if (getGraph() instanceof PaletteDiagram) {
+                   ((PaletteDiagram) getGraph()).updateDiagram(getSize().getWidth());
                }               
            }
            
            public void componentResized(ComponentEvent arg0) {
-               if(getGraph() instanceof PaletteDiagram) {
-                   ((PaletteDiagram)getGraph()).updateDiagram(getSize().getWidth());
+               if (getGraph() instanceof PaletteDiagram) {
+                   ((PaletteDiagram) getGraph()).updateDiagram(getSize().getWidth());
                }               
            }
            
@@ -40,14 +61,20 @@ public class XcosComponent extends mxGraphComponent{
        });
     }
 
-    public XcosCanvas createCanvas()
-    {
+    /**
+     * Create the associated canvas
+     * @return the canvas
+     */
+    public XcosCanvas createCanvas() {
        return new XcosCanvas();
     }
     
+    /**
+     * @return The filename
+     */
     public String toString() {
-       if(getGraph() instanceof PaletteDiagram) {
-           String fileName = ((PaletteDiagram)getGraph()).getName();
+       if (getGraph() instanceof PaletteDiagram) {
+           String fileName = ((PaletteDiagram) getGraph()).getName();
            return fileName.substring(0, fileName.lastIndexOf('.'));
        } else {
            return super.toString();
@@ -62,10 +89,10 @@ public class XcosComponent extends mxGraphComponent{
        Rectangle preference = (Rectangle) view.getBounds(graph.getChildCells(graph.getDefaultParent())).getRectangle().clone();
        
        // Feeling values to keep the zoom smart 
-       preference.x -= 20;
-       preference.y += 20;
-       preference.width += 40;
-       preference.height += 40;
+       preference.x -= ZOOM_BORDER;
+       preference.y += ZOOM_BORDER;
+       preference.width += 2 * ZOOM_BORDER;
+       preference.height += 2 * ZOOM_BORDER;
        
        Dimension actual = viewport.getSize();
 
index dbea5a3..39141b1 100644 (file)
@@ -2,10 +2,13 @@ package org.scilab.modules.xcos.utils;
 
 import com.mxgraph.util.mxConstants;
 
-public class XcosConstants extends mxConstants{
+/**
+ * Contains all the constants used trough the source code.
+ */
+public class XcosConstants extends mxConstants {
 
-    public static int PALETTE_BLOCK_WIDTH = 100;
-    public static int PALETTE_BLOCK_HEIGHT = 100;
+    public static final int PALETTE_BLOCK_WIDTH = 100;
+    public static final int PALETTE_BLOCK_HEIGHT = 100;
 
     public static final int PALETTE_HMARGIN = 5;
     public static final int PALETTE_VMARGIN = 5;
@@ -13,11 +16,19 @@ public class XcosConstants extends mxConstants{
     /**
      * Defines the key for flip image .
      */
-    public static String STYLE_FLIP = "flip";
+    public static final String STYLE_FLIP = "flip";
 
     /**
      * Defines the key for mirror image .
      */
-    public static String STYLE_MIRROR = "mirror";
-
+    public static final String STYLE_MIRROR = "mirror";
+    
+    /* Events */
+    public static final String EVENT_CHANGE_EDIT = "edit";   
+    public static final String EVENT_BLOCK_UPDATED = "block";
+    public static final String EVENT_CHANGE_OLD = "old";
+    public static final String EVENT_CHANGE_NEW = "new";
+    
+    /** This class is a static singleton, thus it must not be instantiated */
+    public XcosConstants() { }
 }