FileDocCategorySizeDatePackage
CDMPanel.javaAPI DocJMF 2.1.1e8523Mon May 12 12:20:30 BST 2003jmapps.registry

CDMPanel

public class CDMPanel extends JMPanel implements ActionListener, VectorEditor

Fields Summary
Panel
panelLeft
Button
buttonDetect
VectorPanel
panelDevices
Vector
deviceVector
Vector
deviceArray
Vector
devices
TextArea
textArea
int
type
Constructors Summary
public CDMPanel()



      
        super();

        Panel   panel;
        Label   label;

        setLayout ( new GridLayout(1,2,6,6) );
        panelLeft = new Panel ( new BorderLayout(6,6) );
        this.add ( panelLeft );
        panel = new Panel ( new FlowLayout(FlowLayout.LEFT) );
        panelLeft.add ( panel, BorderLayout.SOUTH );
        buttonDetect = new Button ( JMFI18N.getResource("jmfregistry.capture.detect") );
        buttonDetect.addActionListener ( this );
        panel.add ( buttonDetect );

        createPanelDevices ();

        panel = new Panel ( new BorderLayout() );
        this.add ( panel );

        label = new Label ( JMFI18N.getResource("jmfregistry.capture.details.label") );
        panel.add ( label, BorderLayout.NORTH );
        textArea = new TextArea ();
        textArea.setEditable ( false );
        panel.add ( textArea, BorderLayout.CENTER );
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

        String  strAction;

        strAction = event.getActionCommand ();
        if ( strAction.equals(buttonDetect.getActionCommand()) )
            detectDevices ();
    
public booleanaddToList(int code, java.lang.String value)

        // Register the device
        try {
            String className = value;
            Class pic = Class.forName(className);
            Object instance = pic.newInstance();
	    
            if (instance instanceof CaptureDeviceInfo) {
                CaptureDeviceInfo cdi = (CaptureDeviceInfo) instance;
                if (cdi.getName() != null  ||  cdi.getLocator() != null) {
                    if (CaptureDeviceManager.addDevice(cdi)) {
                        return true;
                    }
                }
            }
        }
        catch (Exception e) {
            System.err.println(e);
        }
        catch (Error er) {
            System.err.println(er);
        }
	
        return false;
    
public voidcommit(int code)

	int i;
	for (i = 0; i < devices.size(); i++)
	    CaptureDeviceManager.removeDevice((CaptureDeviceInfo) devices.elementAt(i));
	for (i = 0; i < deviceVector.size(); i++) {
	    String name = (String) deviceVector.elementAt(i);
	    for (int j = 0; j < devices.size(); j++) {
		if (((CaptureDeviceInfo)devices.elementAt(j)).getName().equals(name)) {
		    CaptureDeviceManager.addDevice((CaptureDeviceInfo)devices.elementAt(j));
		    break;
		}
	    }
	}
        try {
            CaptureDeviceManager.commit();
        }
        catch (IOException ioe) {
            System.err.println("CaptureDeviceManager.commit() - " + ioe);
        }
    
private voidcreatePanelDevices()

        if ( panelDevices != null )
            panelLeft.remove ( panelDevices );
        panelDevices = new VectorPanel ( JMFI18N.getResource("jmfregistry.capture.vector.label"), this, 0 );
        panelLeft.add ( panelDevices, BorderLayout.CENTER );
        panelLeft.validate();
    
private voiddetectDevices()

        // Check if VFWAuto or SunVideoAuto is available
        Class       directAudio = null;
        Class       autoAudio = null;
        Class       autoVideo = null;
        Class       autoVideoPlus = null;
        Object      instanceAudio;
        Object      instanceVideo;
        Object      instanceVideoPlus;
        PopupWait   popupWait;

        try {
            directAudio = Class.forName("DirectSoundAuto");
        }
        catch (Exception e) {
        }

        try {
            autoAudio = Class.forName("JavaSoundAuto");
        }
        catch (Exception e) {
        }

        try {
            autoVideo = Class.forName("VFWAuto");
        }
        catch (Exception e) {
        }

        if (autoVideo == null) {
            try {
                autoVideo = Class.forName("SunVideoAuto");
            }
            catch (Exception ee) {
            }
            try {
                autoVideoPlus = Class.forName("SunVideoPlusAuto");
            }
            catch (Exception ee) {
            }
        }
	if (autoVideo == null) {
	    try {
		autoVideo = Class.forName("V4LAuto");
	    } catch (Exception eee) {
	    }
	}

        if ( directAudio == null && autoAudio == null  &&
	     autoVideo == null  &&  autoVideoPlus == null )
            return;

        popupWait = new PopupWait ( getFrame(),
                        JMFI18N.getResource("jmstudio.mssg.capturequery")
                        + "\n" + JMFI18N.getResource("jmfregistry.appname") + " "
                        + JMFI18N.getResource("jmstudio.mssg.lookingcapture") );
        popupWait.setVisible ( true );

        try {
            if ( directAudio != null )
                instanceAudio = directAudio.newInstance ();
            if ( autoAudio != null )
                instanceAudio = autoAudio.newInstance ();
            if ( autoVideo != null )
                instanceVideo = autoVideo.newInstance ();
            if (autoVideoPlus != null)
                instanceVideoPlus = autoVideoPlus.newInstance ();
        }
        catch ( ThreadDeath td ) {
            popupWait.dispose();
            throw td;
        }
        catch (Throwable t) {
            MessageDialog.createErrorDialog ( new Frame(), JMFI18N.getResource("jmstudio.error.capturequery") );
        }

        popupWait.dispose();
        createPanelDevices ();
    
public java.util.VectorgetList(int code)

        devices = CaptureDeviceManager.getDeviceList(null);
	devices = (Vector) devices.clone();
        deviceVector = new Vector(10);
        Enumeration enum = devices.elements();

        while (enum.hasMoreElements()) {
            CaptureDeviceInfo cdi = (CaptureDeviceInfo) enum.nextElement();
            deviceVector.addElement(cdi.getName());
        }
        return deviceVector;
    
private java.lang.StringprintFormats(java.lang.Object fa)

        if (! (fa instanceof Format[])) {
            return "null";
        }
        else {
            Format [] formats = (Format []) fa;
            String text = "";
            for (int i = 0; i < formats.length; i++) {
                text += i + ". " + formats[i].getClass().getName() + "\n  " + formats[i] + "\n";
            }
            return text;
        }
    
public voidselectedIndex(int code, int index)

        String                  text = "";
        String                  name = null;
        CaptureDeviceInfo       cdi = null;

        if ( index >= 0 )
            name = (String) deviceVector.elementAt ( index );
        if ( name != null )
            cdi = CaptureDeviceManager.getDevice ( name );
        if (cdi != null) {
            text += JMFI18N.getResource("jmfregistry.details.name") + " = "
                        + cdi.getName() + "\n\n";
            text += JMFI18N.getResource("jmfregistry.details.locator") + " = "
                        + cdi.getLocator() + "\n\n";
            text += JMFI18N.getResource("jmfregistry.details.outformats")
                        + "---->\n\n" + printFormats(cdi.getFormats()) + "\n\n";
        }
      	textArea.setText(text);
    
public voidsetList(int code, java.util.Vector v)

	deviceVector = v;
    
public java.util.VectorstringArrayToVector(java.lang.String[] array)

        Vector v = new Vector();
        if (array != null)
            for (int i = 0; i < array.length; i++)
                v.addElement(array[i]);
        return v;
    
public java.lang.String[]vectorToStringArray(java.util.Vector v)

        String [] sa = new String[v.size()];
        Enumeration e = v.elements();
        int i = 0;

        while (e.hasMoreElements())
            sa[i++] = (String) e.nextElement();
        return sa;