Horus Doc || Java GUI Reference || Doxygen's quick Index  

MediaApp Class Reference

Inheritance diagram for MediaApp::

SampleApp ViewerModeListener FrameNavigatorUser List of all members.

Public Methods

void handleOpenSeq ()
 This function is called by _bmenu if the associated menu item is selected. More...

void handleLightweightRenderer (boolean b)
void handleLoop (boolean loop)
void handleAutoPlay (boolean play)
void controllerUpdate (ControllerEvent ce)
void handleExit ()
 This function is called by _bmenu if the associated menu item is selected. More...

void handleStart ()
void handleStop ()
void handleContinue ()
void handleStep ()
void viewerModeChanged (ViewerModeEvent e)
 Implementation of ViewerModeListener. More...

void handleFrameChanged (int newFrame)
 Implementation of FrameNavigatorUser. More...


Static Public Methods

void main (String[] args)
 main is called when this is used as an application. More...


Protected Methods

boolean buildSample (JFrame parent, JApplet applet, String[] args)

Member Function Documentation

void MediaApp::main String    args[] [inline, static]
 

main is called when this is used as an application.

This function has to be overloaded in the "leaf node" application itself.

Reimplemented from SampleApp.

00048 {
00049     MediaApp app = new MediaApp();
00050     app.doMain(args);
00051 
00052     // doMain will call buildSample
00053 }

void MediaApp::handleOpenSeq   [inline]
 

This function is called by _bmenu if the associated menu item is selected.

00058 {
00059     _fc.setFileFilter(_imSeqFilter);
00060     int returnVal = _fc.showOpenDialog(this);
00061     if (returnVal != JFileChooser.APPROVE_OPTION)
00062         return;
00063     File file =_fc.getSelectedFile();
00064 
00065     try {
00066         if(_proc != null) _proc.close();
00067         if(_jmframe != null) _jmframe.setTitle("Sequence (closed)");
00068 
00069         URL url = new URL("file:/"+file.getPath());
00070         System.out.println(url);
00071         _proc = Manager.createProcessor(url);
00072         _proc.addControllerListener((ControllerListener)this);
00073         _proc.configure();
00074     }
00075     catch (NoProcessorException e) {
00076         ErrorStreamArea.println("Error: " + e);
00077     }
00078     catch (MalformedURLException e) {
00079         ErrorStreamArea.println("Error:" + e);
00080     }
00081     catch (IOException e) {
00082         ErrorStreamArea.println("Error:" + e);
00083     }
00084 }

void MediaApp::handleLightweightRenderer boolean    b [inline]
 

00087 {
00088     Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(b));
00089 }

void MediaApp::handleLoop boolean    loop [inline]
 

00092 {
00093     _loop = loop;
00094 }

void MediaApp::handleAutoPlay boolean    play [inline]
 

00097 {
00098     _autoPlay = play;
00099 }

void MediaApp::controllerUpdate ControllerEvent    ce [inline]
 

00103 {
00104     if (ce instanceof ConfigureCompleteEvent) {
00105         _proc.setContentDescriptor(null);
00106 
00107         // Obtain the track controls.
00108         TrackControl tc[] = _proc.getTrackControls();
00109         if (tc == null) {
00110             ErrorStreamArea.println("Failed to obtain track controls from the processor.");
00111             return;
00112         }
00113 
00114         // Search for the track control for the video track.
00115         TrackControl videoTrack = null;
00116         for (int i = 0; i < tc.length; i++) {
00117             if (tc[i].getFormat() instanceof VideoFormat) {
00118                 videoTrack = tc[i];
00119                 break;
00120             }
00121         }
00122         if (videoTrack == null) {
00123             ErrorStreamArea.println("The input media does not contain a video track.");
00124             return;
00125         }
00126 
00127         VideoFormat format = (VideoFormat)videoTrack.getFormat();
00128         _frameRate = format.getFrameRate();
00129         OutputStreamArea.println("Video format: " + format);
00130 
00131         // Instantiate and set the frame access codec to the data flow path.
00132         try {
00133             Codec codec[] = { /*new PreAccessCodec(),*/
00134                     new PostAccessCodec()};
00135             videoTrack.setCodecChain(codec);
00136         }
00137         catch (UnsupportedPlugInException e) {
00138             ErrorStreamArea.println("The process does not support effects.");
00139         }
00140 
00141         _proc.prefetch();
00142     }
00143     else if (ce instanceof DurationUpdateEvent) {
00144         Time duration = _proc.getDuration();
00145         if(duration == Duration.DURATION_UNKNOWN)
00146             ErrorStreamArea.println("DURATION_UNKNOWN");
00147         _nrFrames = (int)(duration.getSeconds() * _frameRate);
00148     }
00149     else if (ce instanceof RealizeCompleteEvent) {
00150         Control ctrl = _proc.getControl("javax.media.control.FramePositioningControl");
00151         _posCtrl = (FramePositioningControl)ctrl;
00152 
00153         Control[] ctrls = _proc.getControls();
00154         for(int i=0; i<ctrls.length; i++) System.out.println(ctrls[i]);
00155         //System.out.println(_posCtrl.getControlComponent());
00156     }
00157     else if (ce instanceof PrefetchCompleteEvent) {
00158         final Component seqView = _proc.getVisualComponent();
00159         final Component ctrl = _proc.getControlPanelComponent();
00160 
00161         final Runnable doShowComponents = new Runnable() {
00162             public void run() { showVideoComponents(seqView, ctrl); }
00163         };
00164 
00165         SwingUtilities.invokeLater(doShowComponents);
00166 
00167         if(_autoPlay) handleStart();
00168     }
00169     else if (ce instanceof EndOfMediaEvent) {
00170         if(_loop)
00171             handleStart();
00172         else
00173             handleStop();
00174         //System.err.println("End Of Media");
00175     }
00176 }

void MediaApp::handleExit   [inline]
 

This function is called by _bmenu if the associated menu item is selected.

00182 {
00183     System.exit(0);
00184 }

void MediaApp::handleStart   [inline]
 

00187 {
00188     _nrDisplayed = 0;
00189     _startTime = System.currentTimeMillis();
00190     _statField.setText("running");
00191     _proc.setMediaTime(new Time(0.0));
00192     _proc.start();
00193 
00194     _refreshTimer.setRepeats(true);
00195     _refreshTimer.start();
00196 }

void MediaApp::handleStop   [inline]
 

00199 {
00200     _statField.setText("stopping");
00201     _refreshTimer.stop();
00202     _proc.stop();
00203 }

void MediaApp::handleContinue   [inline]
 

00207 {
00208     _nrDisplayed = 0;
00209     _startTime = System.currentTimeMillis();
00210     _statField.setText("running");
00211     _proc.start();
00212 
00213     _refreshTimer.setRepeats(true);
00214     _refreshTimer.start();
00215 }

void MediaApp::handleStep   [inline]
 

00218 {
00219     handleFrameChanged(++_curFrame);
00220 
00221     _refreshTimer.setRepeats(false);
00222     _refreshTimer.start();
00223 }

void MediaApp::viewerModeChanged ViewerModeEvent    e [inline]
 

Implementation of ViewerModeListener.

Reimplemented from ViewerModeListener.

00228 {
00229     JInternalFrame[] frames = _desktop.getAllFrames();
00230     for (int i=0; i<frames.length; i++) {
00231         CanvasViewer v = (CanvasViewer)frames[i].getClientProperty("Hx.Viewer");
00232         if(v != null) v.setMode(e.getMode(), e.getSubMode());
00233     }
00234 }

void MediaApp::handleFrameChanged int    newFrame [inline]
 

Implementation of FrameNavigatorUser.

Reimplemented from FrameNavigatorUser.

00239 {
00240     double sec = ((double)newFrame) / _frameRate;
00241     _proc.setMediaTime(new Time(sec));
00242     System.out.println("*setting frame "+newFrame+" (secs: "+sec+")");
00243 
00244     //int n = _posCtrl.seek(newFrame);
00245     //int n = _posCtrl.skip(1);
00246     //System.out.println("*seeking frame "+newFrame+" (retn: "+n+")");
00247     //System.out.println("*skiping 1 frame (retn: "+n+")");
00248     //System.out.println(_posCtrl.FRAME_UNKNOWN);
00249     /*if (_running) {
00250         _moveToFrame = newFrame;
00251         _frameNav.updateStatus(newFrame);
00252     } else {
00253         doOneFrame(newFrame, true);
00254     }*/
00255 }

boolean MediaApp::buildSample JFrame    parent,
JApplet    applet,
String    args[]
[inline, protected, virtual]
 

Reimplemented from SampleApp.

00265 {
00266     OutputStreamArea out = new OutputStreamArea(10, 60, false);
00267     ErrorStreamArea errorText = new ErrorStreamArea(parent, 4, 60);
00268 
00269     OutputStreamArea.println("Building "+getSampleName()+" GUI...");
00270 
00271     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
00272     parent.setBounds(0, 0, screenSize.width - 50, screenSize.height - 50);
00273 
00274     _refreshTimer = createRefreshTimer(100);
00275 
00276     // Create FileChooser, for loading sequences
00277 
00278     _fc = new JFileChooser("\\videos");
00279     _imSeqFilter = new ImSeqFilter();
00280     _fc.addChoosableFileFilter(_imSeqFilter);
00281 
00282     // Create desktop
00283     _desktop = new JDesktopPane();
00284     //_desktop.putClientProperty("JDesktopPane.dragMode", "outline");
00285     parent.getContentPane().add(_desktop);
00286     int x, y;
00287 
00288     // Create frame for text output
00289 
00290     JInternalFrame outFrame = new JInternalFrame("Output",
00291                                                  true, false, true, true);
00292     outFrame.getContentPane().add(out);
00293     //outFrame.addInternalFrameListener(this);
00294     outFrame.pack();
00295     // Should be based on desktop, but that is not packed yet.
00296     x = parent.getSize().width - outFrame.getSize().width;
00297     y = parent.getSize().height - outFrame.getSize().height;
00298     y = y - 65; // allow space for status bar
00299     outFrame.setLocation(x, y);
00300     _desktop.add(outFrame);
00301     outFrame.setVisible(true);
00302 
00303     //_fixedFrames.add(outFrame);
00304 
00305     // Create frame for errors
00306 
00307     JInternalFrame errFrame = new JInternalFrame("Errors",
00308                                                  true, false, true, true);
00309     errFrame.getContentPane().add(errorText);
00310     //errFrame.addInternalFrameListener(this);
00311     errFrame.pack();
00312     errFrame.setLocation(x, y - errFrame.getSize().height);
00313     _desktop.add(errFrame);
00314     errFrame.setVisible(true);
00315     //_fixedFrames.add(errFrame);
00316 
00317 
00318     // Add ViewerControlBar to desktop
00319 
00320     _vcb = new ViewerControlBar();
00321     _vcb.addViewerModeListener(this);
00322     JInternalFrame vcbFrame = new JInternalFrame("ViewerControlBar",
00323                                                  false, false, false, true);
00324     vcbFrame.getContentPane().add(_vcb);
00325     //vcbFrame.addInternalFrameListener(this);
00326     vcbFrame.pack();
00327     _desktop.add(vcbFrame);
00328     vcbFrame.setVisible(true);
00329 
00330     // Should be based on desktop, but that is not packed yet.
00331     x = parent.getSize().width - vcbFrame.getSize().width;
00332     y = 0;
00333     vcbFrame.setLocation(x, y);
00334     //_fixedFrames.add(vcbFrame);
00335 
00336     // Add FrameNavigator
00337 
00338     _frameNav = new SimpleFrameNavigator(this, 0, 0, 720, 1);
00339     JInternalFrame navFrame = new JInternalFrame("FrameNavigator",
00340                                                  true, false, false, true);
00341 
00342     JPanel butPanel = new JPanel();
00343 
00344     JButton b1 = new JButton("Start");
00345     b1.setToolTipText("Start playing");
00346     b1.addActionListener(new AbstractAction() {
00347         public void actionPerformed(ActionEvent e) {
00348             handleStart();
00349         }});
00350     butPanel.add(b1);
00351 
00352     JButton b2 = new JButton("Stop");
00353     b2.setToolTipText("Stop playing");
00354     b2.addActionListener(new AbstractAction() {
00355         public void actionPerformed(ActionEvent e) {
00356             handleStop();
00357         }});
00358     butPanel.add(b2);
00359 
00360     JButton b3 = new JButton("Cont");
00361     b3.setToolTipText("Continue playing");
00362     b3.addActionListener(new AbstractAction() {
00363         public void actionPerformed(ActionEvent e) {
00364             handleContinue();
00365         }});
00366     butPanel.add(b3);
00367 
00368     JButton b4 = new JButton("Step");
00369     b4.setToolTipText("Step one frame");
00370     b4.addActionListener(new AbstractAction() {
00371         public void actionPerformed(ActionEvent e) {
00372             handleStep();
00373         }});
00374     butPanel.add(b4);
00375 
00376     _statField = new JTextField("Status     ");
00377     _statField.setEditable(false);
00378     butPanel.add(_statField);
00379 
00380     _fpsField = new JTextField("xxxxxx fps   ");
00381     _fpsField.setEditable(false);
00382     butPanel.add(_fpsField);
00383 
00384     navFrame.getContentPane().add(_frameNav, BorderLayout.CENTER);
00385     navFrame.getContentPane().add(butPanel, BorderLayout.SOUTH);
00386     //navFrame.addInternalFrameListener(this);
00387     navFrame.pack();
00388     _desktop.add(navFrame);
00389     navFrame.setVisible(true);
00390 
00391     // Should be based on desktop, but that is not packed yet.
00392     x = parent.getSize().width - navFrame.getSize().width;
00393     y = vcbFrame.getSize().height;
00394     navFrame.setLocation(x, y);
00395     //_fixedFrames.add(navFrame);
00396 
00397 
00398     // Create ExtMenuBar:
00399 
00400     _bmenu = new ExtMenuBar(this);
00401     _bmenu.addMenu("File");
00402     _bmenu.addMenuItem("File", "Open Sequence", "handleOpenSeq");
00403     _bmenu.addSeparator("File");
00404     _bmenu.addMenuItem("File", "Exit", "handleExit");
00405 
00406     _bmenu.addMenu("Preferences");
00407     _bmenu.addCheckBoxItem("Preferences", "Use Lightweight Renderer",
00408         "handleLightweightRenderer", true);
00409     _bmenu.addCheckBoxItem("Preferences", "Continous Loop",
00410         "handleLoop", _loop);
00411     _bmenu.addCheckBoxItem("Preferences", "Auto Play",
00412         "handleAutoPlay", _autoPlay);
00413 
00414     parent.setJMenuBar(_bmenu);
00415 
00416     //_windowMenu = new JMenu("Windows");
00417     //_bmenu.add(_windowMenu);
00418     //updateWindowMenu();
00419 
00420 //    handleSystemLF();
00421 
00422     Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
00423 
00424     OutputStreamArea.println("Done.");
00425     out.capture();
00426 
00427     return true;
00428 }


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:23 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001