source: java/main/src/main/java/com/framsticks/visualization/Viewer.java @ 100

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 4.9 KB
Line 
1package com.framsticks.visualization;
2
3import com.framsticks.util.io.Encoding;
4import com.sun.j3d.loaders.IncorrectFormatException;
5import com.sun.j3d.loaders.ParsingErrorException;
6import com.sun.j3d.loaders.Scene;
7import com.sun.j3d.loaders.objectfile.ObjectFile;
8import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
9import com.sun.j3d.utils.universe.PlatformGeometry;
10import com.sun.j3d.utils.universe.SimpleUniverse;
11import com.sun.j3d.utils.universe.ViewingPlatform;
12
13import javax.media.j3d.*;
14import javax.swing.*;
15import javax.vecmath.Color3f;
16import javax.vecmath.Point3d;
17import javax.vecmath.Vector3f;
18import java.awt.*;
19import java.io.*;
20
21import org.apache.logging.log4j.Logger;
22import org.apache.logging.log4j.LogManager;
23
24public class Viewer {
25
26        private static Logger log = LogManager.getLogger(Viewer.class);
27
28        Canvas3D canvas3d;
29        SimpleUniverse universe;
30
31        public Viewer() {
32                super();
33
34                init();
35        }
36
37        public BranchGroup createSceneGraph() {
38                // Create the root of the branch graph
39                BranchGroup objRoot = new BranchGroup();
40
41                // Create a Transform group to scale all objects so they
42                // appear in the scene.
43                TransformGroup objScale = new TransformGroup();
44                Transform3D t3d = new Transform3D();
45                t3d.setScale(0.7);
46                objScale.setTransform(t3d);
47                objRoot.addChild(objScale);
48
49                TransformGroup objTrans = new TransformGroup();
50                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
51                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
52                objScale.addChild(objTrans);
53
54                String filename = "/visualization/models/cylinder.obj";
55                int flags = ObjectFile.RESIZE;
56                flags |= ObjectFile.TRIANGULATE;
57                flags |= ObjectFile.STRIPIFY;
58                double creaseAngle = 60.0;
59                ObjectFile f = new ObjectFile(flags,
60                                (float) (creaseAngle * Math.PI / 180.0));
61                Scene s = null;
62                try {
63                        InputStream is = this.getClass().getResourceAsStream(filename);
64                        s = f.load(new InputStreamReader(is, Encoding.getDefaultCharset()));
65                } catch (FileNotFoundException | ParsingErrorException | IncorrectFormatException e) {
66                        log.fatal("fatal error", e);
67                        return null;
68                }
69
70                objTrans.addChild(s.getSceneGroup());
71
72                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
73
74                Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
75                Background bgNode = new Background(bgColor);
76                bgNode.setApplicationBounds(bounds);
77                objRoot.addChild(bgNode);
78
79                return objRoot;
80        }
81
82        private void init() {
83
84                JTextPane textPane = new JTextPane();
85                textPane.setEditable(false);
86
87                GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
88
89                // Create a Canvas3D using the preferred configuration
90                canvas3d = new Canvas3D(config);
91
92                // Create simple universe with view branch
93                universe = new SimpleUniverse(canvas3d);
94                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
95
96                // add mouse behaviours to the ViewingPlatform
97                ViewingPlatform viewingPlatform = universe.getViewingPlatform();
98
99                PlatformGeometry platformGeometry = new PlatformGeometry();
100
101                // Set up the ambient light
102                Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
103                AmbientLight ambientLightNode = new AmbientLight(ambientColor);
104                ambientLightNode.setInfluencingBounds(bounds);
105                platformGeometry.addChild(ambientLightNode);
106
107                // Set up the directional lights
108                Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
109                Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
110                Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
111                Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
112
113                DirectionalLight light1 = new DirectionalLight(light1Color,
114                                light1Direction);
115                light1.setInfluencingBounds(bounds);
116                platformGeometry.addChild(light1);
117
118                DirectionalLight light2 = new DirectionalLight(light2Color,
119                                light2Direction);
120                light2.setInfluencingBounds(bounds);
121                platformGeometry.addChild(light2);
122
123                viewingPlatform.setPlatformGeometry(platformGeometry);
124
125                viewingPlatform.setNominalViewingTransform();
126
127                // Ensure at least 5 msec per frame (i.e., < 200Hz)
128                universe.getViewer().getView().setMinimumFrameCycleTime(5);
129
130                BranchGroup scene = new BranchGroup();
131                BranchGroup content = createSceneGraph();
132
133                // canvas3d.addMouseListener(behaviour);
134                TransformGroup transformGroup = new TransformGroup(new Transform3D());
135                transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
136                transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
137                MouseRotate behaviour = new MouseRotate();
138                behaviour.setTransformGroup(transformGroup);
139                transformGroup.addChild(behaviour);
140                // behaviour.addListener(canvas3d);
141                // behaviour.initialize();
142                behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
143                transformGroup.addChild(content);
144                // transformGroup.addChild(behaviour);
145                scene.addChild(transformGroup);
146
147                universe.addBranchGraph(scene);
148                canvas3d.startRenderer();
149                Dimension d = new Dimension(500, 500);
150                canvas3d.setMinimumSize(d);
151                canvas3d.setSize(d);
152        }
153
154        public Component getViewComponent() {
155                return canvas3d;
156        }
157
158
159}
Note: See TracBrowser for help on using the repository browser.