001: /*
002: * @(#)DemoJMFJ3DVR.java 1.0, 1 May 2000
003: *
004: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
005: *
006: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
007: * royalty free, license to use, modify and redistribute this
008: * software in source and binary code form,
009: * provided that i) this copyright notice and license appear on all copies of
010: * the software; and ii) Licensee does not utilize the software in a manner
011: * which is disparaging to Silvere Martin-Michiellot.
012: *
013: * This software is provided "AS IS," without a warranty of any kind. ALL
014: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
015: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
016: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
017: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
018: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
020: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
021: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
022: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
023: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
024: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
025: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
026: *
027: * This software is not designed or intended for use in on-line control of
028: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
029: * the design, construction, operation or maintenance of any nuclear
030: * facility. Licensee represents and warrants that it will not use or
031: * redistribute the Software for such purposes.
032: *
033: * @Author: Silvere Martin-Michiellot
034: *
035: */
036:
037: package com.db.media.in;
038:
039: import javax.media.*;
040: import javax.media.format.*;
041: import javax.media.control.*;
042: import java.awt.*;
043: import java.awt.event.*;
044: import java.io.File;
045: import javax.swing.*;
046: import javax.media.j3d.*;
047: import com.sun.j3d.utils.universe.SimpleUniverse;
048: import com.sun.j3d.utils.geometry.Cylinder;
049:
050: /*
051: * This is the demo program to render live video on a 3D cylinder
052: * surface
053: */
054:
055: public class DemoJMFJ3DVR extends JFrame implements ActionListener {
056:
057: private JMenuItem printItem;
058: private JMenuItem saveItem;
059: private JMenuItem quitItem;
060:
061: private Canvas3D canvas3D;
062:
063: private SimpleUniverse simpleUniverse;
064:
065: private class AppPanel extends JPanel {
066:
067: public BranchGroup createSceneGraph(String args[]) {
068: // Create the root of the branch graph
069:
070: BranchGroup objRoot;
071:
072: objRoot = new BranchGroup();
073: //this is the place you have to put your code to
074: //DISPLAY SOMETHING in the Canvas3D
075:
076: return objRoot;
077:
078: }
079:
080: // Create the Canvas3D (both on-screen and off-screen)
081: private void createCanvas3D(String[] args) {
082:
083: String url = null;
084: boolean dc = true;
085: J3DVideoRenderer j3DVideoRenderer;
086:
087: // Create Canvas3D
088: GraphicsConfiguration config = SimpleUniverse
089: .getPreferredConfiguration();
090:
091: canvas3D = new Canvas3D(config);
092: canvas3D.setSize(600, 450);
093:
094: // Create a simple scene and attach it to the virtual universe
095: BranchGroup scene = createSceneGraph(args);
096: simpleUniverse = new SimpleUniverse(canvas3D);
097: // This will move the ViewPlatform back a bit so the
098: // objects in the scene can be viewed.
099: simpleUniverse.getViewingPlatform()
100: .setNominalViewingTransform();
101: simpleUniverse.addBranchGraph(scene);
102:
103: BranchGroup objects = new BranchGroup();
104:
105: //create a new appearance on a surface
106: Appearance appearance = new Appearance();
107: Cylinder cyl = new Cylinder(0.5f, 2.0f, appearance);
108: objects.addChild(cyl);
109:
110: simpleUniverse.addBranchGraph(objects);
111:
112: int i = 0;
113:
114: while (i < args.length) {
115: if (args[i].equals("-m")) {
116: i++;
117: if (i >= args.length) {
118: printUsage();
119: System.exit(0);
120: }
121:
122: url = args[i];
123:
124: if (!(url.startsWith("file:") || url
125: .startsWith("http:"))) {
126: url = "file:" + url;
127: }
128: } else if (args[i].equals("-c")) {
129: i++;
130: if (i >= args.length) {
131: printUsage();
132: System.exit(0);
133: }
134:
135: dc = new Boolean(args[i]).booleanValue();
136: }
137: i++;
138: }
139:
140: if (url == null) {
141: try {
142: Class cls = Class.forName("DemoJMFJ3DVR");
143: url = cls.getResource("Behfar.mov").toString();
144: } catch (Exception ex) {
145: ex.printStackTrace();
146: }
147: }
148:
149: System.out.println("url = " + url);
150:
151: setLayout(new BorderLayout());
152:
153: j3DVideoRenderer = new J3DVideoRenderer(url, canvas3D,
154: appearance);
155: System.out.println("video processor start");
156:
157: }
158:
159: private AppPanel(String args[]) {
160: setLayout(new BorderLayout());
161:
162: // Create Canvas3D and scene graph
163: createCanvas3D(args);
164: add("Center", canvas3D);
165: }
166:
167: }
168:
169: public void actionPerformed(ActionEvent event) {
170:
171: Object target = event.getSource();
172:
173: if (target == quitItem) {
174: simpleUniverse.removeAllLocales();
175: System.exit(0);
176: }
177:
178: }
179:
180: private JMenuBar createMenuBar() {
181:
182: JMenuBar menuBar = new JMenuBar();
183: JMenu fileMenu = new JMenu("File");
184: quitItem = new JMenuItem("Quit");
185: quitItem.addActionListener(this );
186: fileMenu.add(quitItem);
187: menuBar.add(fileMenu);
188:
189: return menuBar;
190:
191: }
192:
193: private DemoJMFJ3DVR(String args[]) {
194:
195: this .setTitle("Canvas3D Video Test");
196:
197: // Create and initialize menu bar
198: JPopupMenu.setDefaultLightWeightPopupEnabled(false);
199: this .setJMenuBar(createMenuBar());
200:
201: // Handle the close event
202: this .addWindowListener(new WindowAdapter() {
203: public void windowClosing(WindowEvent winEvent) {
204: System.exit(0);
205: }
206: });
207:
208: // Add main panel to top-level frame and make it visible
209: this .getContentPane().add(new AppPanel(args));
210: this .pack();
211: this .setVisible(true);
212:
213: }
214:
215: public static void main(String[] args) {
216:
217: new DemoJMFJ3DVR(args);
218:
219: }
220:
221: public static void printUsage() {
222:
223: System.out.println("java DemoJMFJ3DVR [-m <url-of-the-movie>]");
224: System.out
225: .println("e.g. java DemoJMFJ3DVR -m file:/home/media/video/gun.mov");
226:
227: }
228:
229: }
|