⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saveasdialog.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)SaveAsDialog.java	1.9 00/05/12 * * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */package jmapps.jmstudio;import java.lang.*;import java.lang.reflect.*;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.media.*;import javax.media.control.*;import javax.media.format.*;import javax.media.protocol.*;import javax.media.datasink.*;import com.sun.media.util.JMFI18N;import com.sun.media.ui.TabControl;import com.sun.media.ui.PlayerWindow;import com.sun.media.ui.AudioFormatChooser;import com.sun.media.ui.VideoFormatChooser;import jmapps.util.*;import jmapps.ui.*;/*** This class is used to create modeless SaveAs dialog. Instanciating the class* opens the dialog. It uses TabControl to allow user specify the parameters* for each audio and video track. Classes TrackPanelAudio and TrackPanelVideo* are used to compose the pages of the TabControl. When user presses "OK" button* it calls system FileDialog. After specifying the target file, it creates* Progress dialog, that allows to monitor the progress of saving media to the* file, pause, resume and abort the process.*/public class SaveAsDialog extends JMDialog implements ControllerListener,                                                DataSinkListener, ItemListener {    private JMAppsCfg       cfgJMApps;    private String          inputURL;    private DataSource      dataSource = null;    private Processor       processor = null;    private DataSink        dataSink = null;    private TrackControl    arrTrackControls [];    private int             nAudioTrackCount = 0;    private int             nVideoTrackCount = 0;    private String          strContentType = null;    private String          strContentTypeExt = null;    private boolean         boolSaving = false;    private ProgressDialog  dlgProgress = null;    private ProgressThread  threadProgress = null;    private Format          captureFormat = null;    private TabControl      tabControl;    private Hashtable       hashtablePanelsAudio = new Hashtable ();    private Hashtable       hashtablePanelsVideo = new Hashtable ();    private Button          buttonSave;    private Button          buttonCancel;    private Choice          comboContentType;    private Image           imageAudioEn = null;    private Image           imageAudioDis = null;    private Image           imageVideoEn = null;    private Image           imageVideoDis = null;    private String          strFailMessage = null;    private ContentDescriptor []       supportedCDs;    private static final String    STR_MSVIDEO = JMFI18N.getResource("jmstudio.saveas.type.msvideo");    private static final String    STR_QUICKTIME = JMFI18N.getResource("jmstudio.saveas.type.quicktime");    private static final String    STR_AIFF = JMFI18N.getResource("jmstudio.saveas.type.aiff");    private static final String    STR_GSM = JMFI18N.getResource("jmstudio.saveas.type.gsm");    private static final String    STR_WAVE = JMFI18N.getResource("jmstudio.saveas.type.wave");    private static final String    STR_BASIC_AUDIO = JMFI18N.getResource("jmstudio.saveas.type.basicaudio");    private static final String    STR_MPEG_AUDIO = JMFI18N.getResource("jmstudio.saveas.type.mpegaudio");    /**    * This constructor creates object SaveAsDialog, fills it with controls    * does the layout, displays it on the screen, and returns.    * The dialog stays on the screen untill user presses button "OK" or "Cancel".    * @param    frame      parent frame    * @param    inputURL   source of the media    * @param    format     possible capture format    */    public SaveAsDialog ( Frame frame, String inputURL, Format format, JMAppsCfg cfgJMApps ) {        super ( frame, JMFI18N.getResource("jmstudio.saveas.title"), false );        this.cfgJMApps = cfgJMApps;        this.inputURL = inputURL;        this.captureFormat = format;        try {            init();        }        catch (Exception e) {            e.printStackTrace();        }    }    /**    * This constructor creates object SaveAsDialog, fills it with controls    * does the layout, displays it on the screen, and returns.    * The dialog stays on the screen untill user presses button "OK" or "Cancel".    * @param    frame      parent frame    * @param    inputURL   source of the media    * @param    format     possible capture format    */    public SaveAsDialog ( Frame frame, DataSource dataSource, JMAppsCfg cfgJMApps ) {        super ( frame, JMFI18N.getResource("jmstudio.saveas.title"), false );        this.cfgJMApps = cfgJMApps;        this.dataSource = dataSource;        this.inputURL = "Capture";        try {            init();        }        catch (Exception e) {            e.printStackTrace();        }    }    /**    * This method is called from the constructor. It performs all required    * initialization, creates all controls, does the layout and puts the dialog    * on the screen.    * @exception    Exception    */    private void init () throws Exception {        int             i;        Frame           frame;        Point           point;        Panel           panel;        Panel           panelButtons;        JMPanel         panelBorder;        MediaLocator    mediaSource;        Format          format;        boolean         boolResult;        Dimension       dim;        imageAudioEn = ImageArea.loadImage ( "audio.gif", this, true );        imageAudioDis = ImageArea.loadImage ( "audio-disabled.gif", this, true );        imageVideoEn = ImageArea.loadImage ( "video.gif", this, true );        imageVideoDis = ImageArea.loadImage ( "video-disabled.gif", this, true );        frameOwner.setCursor ( new Cursor(Cursor.WAIT_CURSOR) );        if (dataSource == null) {            try {                mediaSource = new MediaLocator ( inputURL );                dataSource = Manager.createDataSource ( mediaSource );                // If its a capture datasource, set the format as specified by JMStudio                if (captureFormat != null && dataSource instanceof CaptureDevice) {                    FormatControl [] fcs = ((CaptureDevice)dataSource).getFormatControls();                        if (fcs != null && fcs.length > 0) {                            fcs[0].setFormat(captureFormat);                        }                }            }            catch ( Exception exception ) {                MessageDialog.createErrorDialog ( frameOwner,						  JMFI18N.getResource("jmstudio.error.datasource.createfor")						  + " \'" + inputURL + "\'.", exception );                frameOwner.setCursor ( Cursor.getDefaultCursor() );                throw exception;            }        }        strContentType = dataSource.getContentType ();        try {            processor = Manager.createProcessor ( dataSource );        }        catch ( NoPlayerException exception ) {            MessageDialog.createErrorDialog ( frameOwner,                        JMFI18N.getResource("jmstudio.error.processor.create"),                        exception );            frameOwner.setCursor ( Cursor.getDefaultCursor() );            throw exception;        }        processor.addControllerListener ( this );        // wait for processor to be configured        boolResult = waitForState ( processor, Processor.Configured );        if ( boolResult == false ) {//            MessageDialog.createErrorDialog ( frameOwner,//                        JMFI18N.getResource("jmstudio.error.processor.configure")//                        + "\n" + strFailMessage );            frameOwner.setCursor ( Cursor.getDefaultCursor() );            return;        }        supportedCDs = processor.getSupportedContentDescriptors();        arrTrackControls = processor.getTrackControls ();        for ( i = 0;  i < arrTrackControls.length;  i++ ) {            format = arrTrackControls[i].getFormat ();            if ( format instanceof VideoFormat )                nVideoTrackCount++;            if ( format instanceof AudioFormat )                nAudioTrackCount++;        }        this.setLayout ( new BorderLayout() );        panelBorder = new JMPanel ( new BorderLayout(6,6) );        panelBorder.setEmptyBorder ( 6, 6, 6, 6 );        panelBorder.setBackground ( Color.lightGray );        this.add ( panelBorder, BorderLayout.CENTER );        panel = createPanelGeneral ();        panelBorder.add ( panel, BorderLayout.NORTH );        panel = createPanelProperties ();        panelBorder.add ( panel, BorderLayout.CENTER );        panel = new JMPanel ( new FlowLayout(FlowLayout.CENTER) );        panelBorder.add ( panel, BorderLayout.SOUTH );        panelButtons = createButtonPanel ( new String[] { ACTION_SAVE, ACTION_CANCEL } );        panel.add ( panelButtons );        changeContentType ();        this.pack ();        dim = this.getSize ();        dim.width += 64;        this.setSize ( dim );        this.addWindowListener ( this );        this.setResizable ( false );        this.setVisible ( true );        frameOwner.setCursor ( Cursor.getDefaultCursor() );    }    /**    * This method is used by method init() to create the panel that contains    * TabControl and its pages TrackPanelAudio or TrackPanelVideo for each track.    * @return       created panel    * @exception    Exception    */    private Panel createPanelProperties () throws Exception {        int                     i;        int                     nIndexAudio;        int                     nIndexVideo;        int                     nCount;        Panel                   panel;        TrackPanelAudio         panelAudio;        TrackPanelVideo         panelVideo;        Format                  format;        String                  strTitle;        String                  strAudio = JMFI18N.getResource("jmstudio.saveas.audio");        String                  strVideo = JMFI18N.getResource("jmstudio.saveas.video");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -