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

📄 saveasdialog.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                monitor, this );            }            dlgProgress.setVisible ( true );            threadProgress = new ProgressThread ( processor, dlgProgress );            threadProgress.start ();        }        catch ( Exception exception ) {//            stopSaving ();            boolSaving = false;//            exception.printStackTrace ();            MessageDialog.createErrorDialogModeless ( frameOwner, null, exception );        }        setCursor ( Cursor.getDefaultCursor() );        this.dispose ();    }    /**    * This method overwrites the ActionListener method to process events    * from buttons, track pages, and Progress dialog.    * @param    event    action event    */    public void actionPerformed ( ActionEvent event ) {        String        strCmd;        Object        objectSource;        strCmd = event.getActionCommand ();        if ( strCmd.equals(ACTION_CANCEL) ) {            stopSaving();            this.dispose ();        }        else if ( strCmd.equals(ACTION_SAVE) ) {            doSave ();        }        else if ( (strCmd.equals(ProgressDialog.ACTION_ABORT) ||                            strCmd.equals(ProgressDialog.ACTION_STOP) )                            && boolSaving == true ) {            stopSaving ();        }        else if ( strCmd.equals(ProgressDialog.ACTION_PAUSE)  &&  boolSaving == true ) {            processor.stop ();            dlgProgress.setPauseButtonText ( ProgressDialog.ACTION_RESUME );            threadProgress.pauseThread ();        }        else if ( strCmd.equals(ProgressDialog.ACTION_RESUME)  &&  boolSaving == true ) {            processor.start ();            dlgProgress.setPauseButtonText ( ProgressDialog.ACTION_PAUSE );            threadProgress.resumeThread ();        }        else if ( strCmd.equals(AudioFormatChooser.ACTION_TRACK_ENABLED) ) {            objectSource = event.getSource ();            if ( objectSource instanceof TrackPanelAudio )                tabControl.setPageImage ( (Panel)objectSource, imageAudioEn );        }        else if ( strCmd.equals(AudioFormatChooser.ACTION_TRACK_DISABLED) ) {            objectSource = event.getSource ();            if ( objectSource instanceof TrackPanelAudio )                tabControl.setPageImage ( (Panel)objectSource, imageAudioDis );        }        else if ( strCmd.equals(VideoFormatChooser.ACTION_TRACK_ENABLED) ) {            objectSource = event.getSource ();            if ( objectSource instanceof TrackPanelVideo )                tabControl.setPageImage ( (Panel)objectSource, imageVideoEn );        }        else if ( strCmd.equals(VideoFormatChooser.ACTION_TRACK_DISABLED) ) {            objectSource = event.getSource ();            if ( objectSource instanceof TrackPanelVideo )                tabControl.setPageImage ( (Panel)objectSource, imageVideoDis );        }    }    /**    * This method overwrites the ItemListener method to monitor the users choice    * of the media type, and notify track pages about the change.    * @param    event    item state changed event    */    public void itemStateChanged ( ItemEvent event ) {        Object              objectSource;        objectSource = event.getSource ();        if ( objectSource == comboContentType ) {            changeContentType ();        }    }    /**    * If the user closes dialog using system menu, it does the cleanup.    * @param    event    window event    */    public void windowClosing ( WindowEvent event ) {        stopSaving();        this.dispose ();    }    /**    * This method looks for ControllerErrorEvent, and displays the Error dialog.    * @param    event    controller event    */    public void controllerUpdate ( ControllerEvent event ) {        if ( event instanceof ControllerErrorEvent ) {            strFailMessage = ((ControllerErrorEvent)event).getMessage ();            if ( boolSaving == true ) {                stopSaving ();                MessageDialog.createErrorDialogModeless ( frameOwner,                                JMFI18N.getResource("jmstudio.error.processor.savefile")                                + "\n" + JMFI18N.getResource("jmstudio.error.controller")                                + "\n" + strFailMessage );            }            else {                MessageDialog.createErrorDialogModeless ( frameOwner,                                JMFI18N.getResource("jmstudio.error.controller")                                + "\n" + strFailMessage );            }        }        else if ( event instanceof EndOfMediaEvent ) {            if ( boolSaving == true )                stopSaving();        }    }    /**     * This method monitors the process of saving file for end of file, and     * possible errors. It also does a cleanup, when one of those events occurs.     * @param    event    file write event     */    public void dataSinkUpdate ( DataSinkEvent event ) {        if ( event instanceof EndOfStreamEvent ) {            closeDataSink();//            MessageDialog.createInfoDialog ( frameOwner, "File has been saved." );        }        else if ( event instanceof DataSinkErrorEvent ) {            stopSaving ();            MessageDialog.createErrorDialogModeless ( frameOwner,                        JMFI18N.getResource("jmstudio.error.processor.writefile") );        }    }    private void closeDataSink() {	synchronized (this) {	    if (dataSink != null)		dataSink.close();	    dataSink = null;	}    }    /**     * This method cleans up after the completion of the file save procedure.     */    private void stopSaving () {        boolSaving = false;        if ( threadProgress != null ) {            threadProgress.terminateNormaly ();            threadProgress = null;        }        if ( dlgProgress != null ) {            dlgProgress.dispose ();            dlgProgress = null;        }        if ( processor != null ) {            processor.stop ();            processor.close ();        }    }    /**    * This method waits untill the processor enter the specified state, or    * some failure occurs.    * @param    nState    the state of processor (see Processor and Player constants)    * @return   true if the state was reached, false otherwise    */    Object stateLock = new Object();    boolean stateFailed = false;        private synchronized boolean waitForState(Processor p, int state) {        p.addControllerListener(new StateListener());        stateFailed = false;	        if (state == Processor.Configured) {            p.configure();        }        else if (state == Processor.Realized) {            p.realize();        }        while (p.getState() < state && !stateFailed) {	    synchronized (stateLock) {            try {                stateLock.wait();            }            catch (InterruptedException ie) {                return false;            }	    }        }	    return ( !stateFailed );    }    /**    * This method is called whenever user makes the choice of the target media    * type. It notifies all track pages about the change.    */    private void changeContentType () {        Enumeration         enumPanels;        TrackPanelVideo    panelVideo;        TrackPanelAudio    panelAudio;        String              strValue;        strValue = comboContentType.getSelectedItem ();        if ( strValue.equals(STR_MSVIDEO) ) {            strContentType = FileTypeDescriptor.MSVIDEO;            strContentTypeExt = "avi";        }        else if ( strValue.equals(STR_QUICKTIME) ) {            strContentType = FileTypeDescriptor.QUICKTIME;            strContentTypeExt = "mov";        }        else if ( strValue.equals(STR_AIFF) ) {            strContentType = FileTypeDescriptor.AIFF;            strContentTypeExt = "aif";        }        else if ( strValue.equals(STR_GSM) ) {            strContentType = FileTypeDescriptor.GSM;            strContentTypeExt = "gsm";        }        else if ( strValue.equals(STR_WAVE) ) {            strContentType = FileTypeDescriptor.WAVE;            strContentTypeExt = "wav";        }        else if ( strValue.equals(STR_BASIC_AUDIO) ) {            strContentType = FileTypeDescriptor.BASIC_AUDIO;            strContentTypeExt = "au";        }        else if ( strValue.equals(STR_MPEG_AUDIO) ) {            strContentType = FileTypeDescriptor.MPEG_AUDIO;            strContentTypeExt = "mp3";        }        else {            strContentType = strValue;            strContentTypeExt = "movie";        }//        System.err.println("ChangeContentType = " + strContentType);        if ( processor.setContentDescriptor(new FileTypeDescriptor(strContentType)) == null) {            System.err.println ( "Error setting content descriptor on processor" );        }        enumPanels = hashtablePanelsVideo.elements ();        while ( enumPanels.hasMoreElements() ) {            panelVideo = (TrackPanelVideo) enumPanels.nextElement ();            panelVideo.setContentType ( strContentType );        }        enumPanels = hashtablePanelsAudio.elements ();        while ( enumPanels.hasMoreElements() ) {            panelAudio = (TrackPanelAudio) enumPanels.nextElement ();            panelAudio.setContentType ( strContentType );        }    }    class StateListener implements ControllerListener {        public void controllerUpdate ( ControllerEvent ce ) {            if (ce instanceof ControllerClosedEvent)                stateFailed = true;            if (ce instanceof ControllerEvent)                synchronized (stateLock) {                    stateLock.notifyAll();                }        }    }}

⌨️ 快捷键说明

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