home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 6.3 KB | 230 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import java.awt.*;
- import java.awt.event.*;
-
- import quicktime.*;
- import quicktime.app.*;
- import quicktime.app.display.*;
- import quicktime.app.anim.*;
- import quicktime.io.*;
- import quicktime.std.movies.*;
- import quicktime.std.*;
- import quicktime.std.image.*;
- /**
- * A simple panel of AWT objects to demonstrate how AWT can be used to control a
- * QuickTime movie.
- */
- public class ControlPanel extends Panel implements Errors, StdQTConstants {
- //_________________________ CLASS METHODS
- public ControlPanel (Compositor c, JavaTextDrawer t) throws QTException
- {
- this.comp = c;
- this.jText = t;
- // this.layerUpdater = updater;
-
- GridBagLayout gb = new GridBagLayout();
- setLayout (gb);
- setFont (new Font("Helvetica", Font.BOLD, 10));
-
- GridBagConstraints cons = new GridBagConstraints();
- cons.fill = GridBagConstraints.HORIZONTAL;
- cons.gridheight = 1;
- cons.insets = new Insets (2, 2, 2, 2);
- cons.gridwidth = 2;
- cons.gridy = 0;
- cons.gridx = 0;
- add (rateLabel, cons);
-
- cons.gridx = 2;
- add (rateField, cons);
-
- cons.gridx = 4;
- add (scaleLabel, cons);
-
- cons.gridx = 6;
- add (scaleField, cons);
-
- cons.gridy = 1;
- cons.gridx = 0;
- add (preflightCheck, cons);
-
- cons.gridx = 2;
- add (recordMovieButton, cons);
-
- cons.gridx = 4;
- add (recordLabel, cons);
-
- cons.gridx = 6;
- add (recordField, cons);
-
- cons.gridy = 2;
- cons.gridx = 3;
- add (changeColorButton, cons);
-
- //set recordmovie
- recMovie = new MovieRecording();
- recMovie.setCodec();
-
- changeColorButton.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- jText.doWork();
- }
- });
-
-
- rateField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- comp.getTimer().setRate (new Float (str).floatValue());
- }
- });
- scaleField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- try {
- comp.getTimer().rescheduleTickle(new Integer (str).intValue(), 1);
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
- recordField.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- String str = new String (event.getActionCommand());
- numRecordFrames = new Integer (str).intValue();
- }
- });
-
- recordMovieButton.addActionListener (new ActionListener () {
- public void actionPerformed (ActionEvent event) {
- try {
- FileDialog fd = new FileDialog (ImageCompositing.pm, "Save Movie As...", FileDialog.SAVE);
- fd.show();
- if(fd.getFile() == null)
- throw new QTIOException (userCanceledErr, "");
- QTFile f = new QTFile(fd.getDirectory() + fd.getFile());
- Movie theMovie = Movie.createMovieFile (f,
- kMoviePlayer,
- createMovieFileDeleteCurFile | createMovieFileDontCreateResFile);
-
- preflightCheck.setState(false); // recording disables preflight
-
- //Setup the record movie class
- recMovie.setMovie(theMovie, new CleanupMovie (f));
- recMovie.recordMode (numRecordFrames);
- comp.setRecordMovie (recMovie);
-
- System.out.println ("Start Recording");
-
- } catch (QTException e) {
- if (e.errorCode() != userCanceledErr)
- e.printStackTrace();
- }
- }
- });
-
-
- //for preflighting
- preflightCheck.addItemListener (new ItemListener () {
- public void itemStateChanged (ItemEvent ev) {
- try {
- if (((Checkbox)ev.getItemSelectable()).getState()) {
- recMovie.setPreflighting(true);
- comp.setRecordMovie (recMovie);
- }
- else {
- recMovie.setPreflighting(false);
- }
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
- });
-
- }
-
-
- private class CleanupMovie implements RecordMovieCallback {
- CleanupMovie (QTFile f) {
- this.f = f;
- }
-
- private QTFile f;
-
- public void finish (Movie m) {
- try {
- OpenMovieFile outStream = OpenMovieFile.asWrite (f);
- m.addResource (outStream, movieInDataForkResID, f.getName());
- outStream.close();
- } catch (QTException e) {
- e.printStackTrace();
- }
- System.out.println ("Finished Recording");
- }
- }
-
- private class MovieRecording extends RecordMovie {
- // we record at 2 frames a second
- int framesPerSecond = 10;
-
- MovieRecording() throws QTException {
- super();
- }
-
- public void setCodec() throws QTException{
- setCompressionSettings (framesPerSecond,
- codecNormalQuality,
- codecNormalQuality,
- 0,
- kAnimationCodecType,
- CodecComponent.bestSpeedCodec);
-
- }
-
- }
-
-
- public void setDisplay () throws QTException {
- rateField.setText (Float.toString (comp.getTimer().getRate()));
- scaleField.setText (Integer.toString (comp.getTimer().getScale()));
- recordField.setText (Integer.toString (numRecordFrames));
- }
-
- //_________________________ INSTANCE VARIABLES
- private Label rateLabel = new Label ("Playback Rate:", Label.RIGHT);
- private TextField rateField = new TextField (8);
-
- private Button changeColorButton = new Button ("Text Colour");
-
- private Label scaleLabel = new Label ("Scale (fps):", Label.RIGHT);
- private TextField scaleField = new TextField (8);
-
- private Compositor comp;
- private JavaTextDrawer jText;
- private Button recordMovieButton = new Button("Record Movie");
- private Label recordLabel = new Label ("Record Frames:", Label.RIGHT);
- private TextField recordField = new TextField (8);
- private Checkbox preflightCheck = new Checkbox ("Preflight", false);
-
- private boolean selected = false;
- private MovieRecording recMovie;
- private int numRecordFrames = 10;
- int keyFrameRate = 0;
- //_________________________ INSTANCE METHODS
- /**
- * @return a Dimension object which defines the minimum size
- */
- public Dimension getMinimumSize() { return new Dimension (0, 100); }
-
- /**
- * @return a Dimension object which defines the preferred size
- */
- public Dimension getPreferredSize() { return getMinimumSize(); }
- }
-