Ignore:
Timestamp:
06/24/13 13:38:40 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/visualization/Viewer.java

    r84 r85  
    11package com.framsticks.visualization;
    22
     3import com.framsticks.util.io.Encoding;
    34import com.sun.j3d.loaders.IncorrectFormatException;
    45import com.sun.j3d.loaders.ParsingErrorException;
     
    1819import java.io.*;
    1920
    20 // import org.apache.log4j.Logger;
     21import org.apache.log4j.Logger;
    2122
    2223public class Viewer {
    2324
    24     // private static Logger log = Logger.getLogger(Viewer.class);
     25        private static Logger log = Logger.getLogger(Viewer.class);
    2526
    26     Canvas3D canvas3d;
    27     SimpleUniverse universe;
     27        Canvas3D canvas3d;
     28        SimpleUniverse universe;
    2829
    29     public Viewer() {
    30         super();
     30        public Viewer() {
     31                super();
    3132
    32         init();
    33     }
     33                init();
     34        }
    3435
    3536        public BranchGroup createSceneGraph() {
    36         // Create the root of the branch graph
    37         BranchGroup objRoot = new BranchGroup();
     37                // Create the root of the branch graph
     38                BranchGroup objRoot = new BranchGroup();
    3839
    39         // Create a Transform group to scale all objects so they
    40         // appear in the scene.
    41         TransformGroup objScale = new TransformGroup();
    42         Transform3D t3d = new Transform3D();
    43         t3d.setScale(0.7);
    44         objScale.setTransform(t3d);
    45         objRoot.addChild(objScale);
     40                // Create a Transform group to scale all objects so they
     41                // appear in the scene.
     42                TransformGroup objScale = new TransformGroup();
     43                Transform3D t3d = new Transform3D();
     44                t3d.setScale(0.7);
     45                objScale.setTransform(t3d);
     46                objRoot.addChild(objScale);
    4647
    47         TransformGroup objTrans = new TransformGroup();
    48         objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    49         objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    50         objScale.addChild(objTrans);
     48                TransformGroup objTrans = new TransformGroup();
     49                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
     50                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
     51                objScale.addChild(objTrans);
    5152
    52         String filename = "/visualization/models/cylinder.obj";
    53         int flags = ObjectFile.RESIZE;
    54         flags |= ObjectFile.TRIANGULATE;
    55         flags |= ObjectFile.STRIPIFY;
     53                String filename = "/visualization/models/cylinder.obj";
     54                int flags = ObjectFile.RESIZE;
     55                flags |= ObjectFile.TRIANGULATE;
     56                flags |= ObjectFile.STRIPIFY;
    5657                double creaseAngle = 60.0;
    5758                ObjectFile f = new ObjectFile(flags,
    58                 (float) (creaseAngle * Math.PI / 180.0));
    59         Scene s = null;
    60         try {
     59                                (float) (creaseAngle * Math.PI / 180.0));
     60                Scene s = null;
     61                try {
    6162                        InputStream is = this.getClass().getResourceAsStream(filename);
    62             s = f.load(new InputStreamReader(is));
    63         } catch (FileNotFoundException e) {
    64             System.err.println(e);
    65             System.exit(1);
    66         } catch (ParsingErrorException e) {
    67             System.err.println(e);
    68             System.exit(1);
    69         } catch (IncorrectFormatException e) {
    70             System.err.println(e);
    71             System.exit(1);
    72         }
     63                        s = f.load(new InputStreamReader(is, Encoding.getDefaultCharset()));
     64                } catch (FileNotFoundException | ParsingErrorException | IncorrectFormatException e) {
     65                        log.fatal("fatal error", e);
     66                        return null;
     67                }
    7368
    74         objTrans.addChild(s.getSceneGroup());
     69                objTrans.addChild(s.getSceneGroup());
    7570
    76         BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
     71                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    7772
    78         Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    79         Background bgNode = new Background(bgColor);
    80         bgNode.setApplicationBounds(bounds);
    81         objRoot.addChild(bgNode);
     73                Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
     74                Background bgNode = new Background(bgColor);
     75                bgNode.setApplicationBounds(bounds);
     76                objRoot.addChild(bgNode);
    8277
    83         return objRoot;
    84     }
     78                return objRoot;
     79        }
    8580
    86     private void init() {
     81        private void init() {
    8782
    88             JTextPane textPane = new JTextPane();
    89         textPane.setEditable(false);
     83                JTextPane textPane = new JTextPane();
     84                textPane.setEditable(false);
    9085
    91         GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
     86                GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    9287
    93         // Create a Canvas3D using the preferred configuration
    94         canvas3d = new Canvas3D(config);
     88                // Create a Canvas3D using the preferred configuration
     89                canvas3d = new Canvas3D(config);
    9590
    96         // Create simple universe with view branch
    97         universe = new SimpleUniverse(canvas3d);
    98         BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
     91                // Create simple universe with view branch
     92                universe = new SimpleUniverse(canvas3d);
     93                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    9994
    100         // add mouse behaviours to the ViewingPlatform
    101         ViewingPlatform viewingPlatform = universe.getViewingPlatform();
     95                // add mouse behaviours to the ViewingPlatform
     96                ViewingPlatform viewingPlatform = universe.getViewingPlatform();
    10297
    103         PlatformGeometry platformGeometry = new PlatformGeometry();
     98                PlatformGeometry platformGeometry = new PlatformGeometry();
    10499
    105         // Set up the ambient light
    106         Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    107         AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    108         ambientLightNode.setInfluencingBounds(bounds);
    109         platformGeometry.addChild(ambientLightNode);
     100                // Set up the ambient light
     101                Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
     102                AmbientLight ambientLightNode = new AmbientLight(ambientColor);
     103                ambientLightNode.setInfluencingBounds(bounds);
     104                platformGeometry.addChild(ambientLightNode);
    110105
    111         // Set up the directional lights
    112         Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    113         Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    114         Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
    115         Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
     106                // Set up the directional lights
     107                Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
     108                Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
     109                Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
     110                Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
    116111
    117         DirectionalLight light1 = new DirectionalLight(light1Color,
    118                 light1Direction);
    119         light1.setInfluencingBounds(bounds);
    120         platformGeometry.addChild(light1);
     112                DirectionalLight light1 = new DirectionalLight(light1Color,
     113                                light1Direction);
     114                light1.setInfluencingBounds(bounds);
     115                platformGeometry.addChild(light1);
    121116
    122         DirectionalLight light2 = new DirectionalLight(light2Color,
    123                 light2Direction);
    124         light2.setInfluencingBounds(bounds);
    125         platformGeometry.addChild(light2);
     117                DirectionalLight light2 = new DirectionalLight(light2Color,
     118                                light2Direction);
     119                light2.setInfluencingBounds(bounds);
     120                platformGeometry.addChild(light2);
    126121
    127         viewingPlatform.setPlatformGeometry(platformGeometry);
     122                viewingPlatform.setPlatformGeometry(platformGeometry);
    128123
    129         viewingPlatform.setNominalViewingTransform();
     124                viewingPlatform.setNominalViewingTransform();
    130125
    131         // Ensure at least 5 msec per frame (i.e., < 200Hz)
    132         universe.getViewer().getView().setMinimumFrameCycleTime(5);
     126                // Ensure at least 5 msec per frame (i.e., < 200Hz)
     127                universe.getViewer().getView().setMinimumFrameCycleTime(5);
    133128
    134         BranchGroup scene = new BranchGroup();
    135         BranchGroup content = createSceneGraph();
     129                BranchGroup scene = new BranchGroup();
     130                BranchGroup content = createSceneGraph();
    136131
    137         // canvas3d.addMouseListener(behaviour);
    138         TransformGroup transformGroup = new TransformGroup(new Transform3D());
    139         transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    140         transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    141         MouseRotate behaviour = new MouseRotate();
    142         behaviour.setTransformGroup(transformGroup);
    143         transformGroup.addChild(behaviour);
    144         // behaviour.addListener(canvas3d);
    145         // behaviour.initialize();
    146         behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
    147         transformGroup.addChild(content);
    148         // transformGroup.addChild(behaviour);
    149         scene.addChild(transformGroup);
     132                // canvas3d.addMouseListener(behaviour);
     133                TransformGroup transformGroup = new TransformGroup(new Transform3D());
     134                transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
     135                transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
     136                MouseRotate behaviour = new MouseRotate();
     137                behaviour.setTransformGroup(transformGroup);
     138                transformGroup.addChild(behaviour);
     139                // behaviour.addListener(canvas3d);
     140                // behaviour.initialize();
     141                behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
     142                transformGroup.addChild(content);
     143                // transformGroup.addChild(behaviour);
     144                scene.addChild(transformGroup);
    150145
    151         universe.addBranchGraph(scene);
     146                universe.addBranchGraph(scene);
    152147                canvas3d.startRenderer();
    153148                Dimension d = new Dimension(500, 500);
    154149                canvas3d.setMinimumSize(d);
    155150                canvas3d.setSize(d);
    156     }
     151        }
    157152
    158     public Component getViewComponent() {
    159         return canvas3d;
    160     }
     153        public Component getViewComponent() {
     154                return canvas3d;
     155        }
    161156
    162157
Note: See TracChangeset for help on using the changeset viewer.