source: java/main/src/main/java/com/framsticks/visualization/ViewerTest.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 3.5 KB
Line 
1package com.framsticks.visualization;
2
3import com.sun.j3d.utils.universe.*;
4import com.sun.j3d.utils.geometry.ColorCube;
5import org.apache.log4j.Logger;
6
7import javax.media.j3d.*;
8import javax.swing.*;
9import javax.vecmath.*;
10import java.awt.*;
11import java.awt.event.ComponentEvent;
12import java.awt.event.ComponentListener;
13
14/**
15 * Author: Piotr Śniegowski
16 */
17@SuppressWarnings("serial")
18public class ViewerTest extends JPanel {
19        private static final Logger log = Logger.getLogger(ViewerTest.class.getName());
20
21        private SimpleUniverse univ = null;
22        private BranchGroup scene = null;
23
24        public BranchGroup createSceneGraph() {
25                // Create the root of the branch graph
26                BranchGroup objRoot = new BranchGroup();
27
28                // Create the TransformGroup node and initialize it to the
29                // identity. Enable the TRANSFORM_WRITE capability so that
30                // our behavior code can modify it at run time. Add it to
31                // the root of the subgraph.
32                TransformGroup objTrans = new TransformGroup();
33                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
34                objRoot.addChild(objTrans);
35
36                // Create a simple Shape3D node; add it to the scene graph.
37                objTrans.addChild(new ColorCube(0.4));
38
39                // Create a new Behavior object that will perform the
40                // desired operation on the specified transform and add
41                // it into the scene graph.
42                Transform3D yAxis = new Transform3D();
43                Alpha rotationAlpha = new Alpha(-1, 4000);
44
45                RotationInterpolator rotator =
46                                new RotationInterpolator(rotationAlpha, objTrans, yAxis,
47                                                0.0f, (float) Math.PI * 2.0f);
48                BoundingSphere bounds =
49                                new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
50                rotator.setSchedulingBounds(bounds);
51                objRoot.addChild(rotator);
52
53                // Have Java 3D perform optimizations on this scene graph.
54                objRoot.compile();
55
56                return objRoot;
57        }
58
59        private Canvas3D createUniverse() {
60                // Get the preferred graphics configuration for the default screen
61                GraphicsConfiguration config =
62                                SimpleUniverse.getPreferredConfiguration();
63
64                // Create a Canvas3D using the preferred configuration
65                final Canvas3D c = new Canvas3D(config) {
66                        @Override
67                        public void paint(Graphics graphics) {
68                                super.paint(graphics);
69                                Toolkit.getDefaultToolkit().sync();
70                        }
71
72                        @Override
73                        public void postRender() {
74                                super.postRender();
75                                //log.info("postRender()");
76                        }
77                        @Override
78                        public void postSwap() {
79                                super.postSwap();
80                                //log.info("postSwap()");
81                        }
82                };
83
84
85                c.addComponentListener(new ComponentListener() {
86                        @Override
87                        public void componentResized(ComponentEvent componentEvent) {
88                        }
89
90                        @Override
91                        public void componentMoved(ComponentEvent componentEvent) {
92                        }
93
94                        @Override
95                        public void componentShown(ComponentEvent componentEvent) {
96                                log.info("shown");
97                                c.startRenderer();
98                        }
99
100                        @Override
101                        public void componentHidden(ComponentEvent componentEvent) {
102                                log.info("hidden");
103                                c.stopRenderer();
104                        }
105                });
106
107                // Create simple universe with view branch
108                univ = new SimpleUniverse(c);
109
110                // This will move the ViewPlatform back a bit so the
111                // objects in the scene can be viewed.
112                univ.getViewingPlatform().setNominalViewingTransform();
113
114                // Ensure at least 5 msec per frame (i.e., < 200Hz)
115                univ.getViewer().getView().setMinimumFrameCycleTime(16);
116
117                return c;
118        }
119
120        public ViewerTest() {
121
122                this.setLayout(new java.awt.BorderLayout());
123
124                this.setPreferredSize(new java.awt.Dimension(250, 250));
125
126                Canvas3D c = createUniverse();
127                c.setSize(100, 100);
128                this.add(c, java.awt.BorderLayout.CENTER);
129
130                // Create the content branch and add it to the universe
131                scene = createSceneGraph();
132                univ.addBranchGraph(scene);
133        }
134}
Note: See TracBrowser for help on using the repository browser.