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