FileDocCategorySizeDatePackage
PerTypePanel.javaAPI DocJMF 2.1.1e9524Mon May 12 12:20:30 BST 2003jmapps.registry

PerTypePanel

public class PerTypePanel extends JMPanel implements VectorEditor

Fields Summary
VectorPanel
panelPlugIns
Vector
pluginVector
Vector
pluginArray
TextArea
textArea
int
type
private static boolean
jdkInit
private static Method
forName3ArgsM
private static Method
getSystemClassLoaderM
private static ClassLoader
systemClassLoader
private static Method
getContextClassLoaderM
static final String[]
pluginTypes
Constructors Summary
public PerTypePanel(int type)


    
          
        super();

        Panel   panel;
        Label   label;

        this.type = type;
        setLayout ( new GridLayout(1,2,6,6) );

        panelPlugIns = new VectorPanel ( pluginTypes[type], (VectorEditor)this, type );
        add ( panelPlugIns );

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

        label = new Label ( JMFI18N.getResource("jmfregistry.plugin.details.label") );
        panel.add ( label, BorderLayout.NORTH );
        textArea = new TextArea ();
        textArea.setEditable ( false );
        panel.add ( textArea, BorderLayout.CENTER );
    
Methods Summary
public booleanaddToList(int code, java.lang.String value)

        // Register the plugin
        try {
            String className = value;
            // Class pic = Class.forName(className);
            Class pic = getClassForName(className);
            Object instance = pic.newInstance();
            Format [] inputs = null;
            Format [] outputs = null;
            int type;
	    
            if (instance instanceof Demultiplexer) {
                type = PlugInManager.DEMULTIPLEXER;
                inputs = ((Demultiplexer)instance).getSupportedInputContentDescriptors();
                outputs = new Format[0];
            }
            else if (instance instanceof javax.media.Renderer) {
                type = PlugInManager.RENDERER;
                inputs = ((javax.media.Renderer)instance).getSupportedInputFormats();
                outputs = new Format[0];
            }
            else if (instance instanceof Multiplexer) {
                type = PlugInManager.MULTIPLEXER;
                inputs = new Format[0];
                outputs = ((Multiplexer)instance).getSupportedOutputContentDescriptors(null);
            }
            else if (instance instanceof Effect) {
                type = PlugInManager.EFFECT;
                inputs = ((Effect)instance).getSupportedInputFormats();
                outputs = ((Effect)instance).getSupportedOutputFormats(null);
            }
            else if (instance instanceof Codec) {
                type = PlugInManager.CODEC;
                inputs = ((Codec)instance).getSupportedInputFormats();
                outputs = ((Codec)instance).getSupportedOutputFormats(null);
            }
            else
                type = 0;

            if (instance instanceof DynamicPlugIn) {
                inputs = ((DynamicPlugIn)instance).getBaseInputFormats();
                outputs = ((DynamicPlugIn)instance).getBaseOutputFormats();
            }
	    
            if (type != 0) {
                if ( PlugInManager.addPlugIn(className, inputs, outputs, type) )
                    return true;
            }
        }
        catch (Exception e) {
            System.err.println(e);
        }
	
        return false;
    
private static booleancheckIfJDK12()

        if (jdkInit)
            return (forName3ArgsM != null);

        jdkInit = true;
        try {
            forName3ArgsM = Class.class.getMethod ( "forName", new Class[] {
                String.class, boolean.class, ClassLoader.class
		    });
            getSystemClassLoaderM = ClassLoader.class.getMethod ( "getSystemClassLoader", null );
            // TODO: may need to invoke RuntimePermission("getClassLoader") privilege
            systemClassLoader = (ClassLoader) getSystemClassLoaderM.invoke ( ClassLoader.class, null );
            getContextClassLoaderM = Thread.class.getMethod ( "getContextClassLoader", null );
        }
        catch (Throwable t) {
            forName3ArgsM = null;
            return false;
        }
        return true;
    
public voidcommit(int code)

        PlugInManager.setPlugInList(pluginVector, type);
        try {
            PlugInManager.commit();
        }
        catch (IOException ioe) {
            System.err.println("PlugInManager.commit() - " + ioe);
        }
    
static java.lang.ClassgetClassForName(java.lang.String className)

        /**
         *  Note: if we don't want this functionality
         *  just replace it with Class.forName(className)
         */

        try {
            return Class.forName(className);
        }
        catch (Exception e) {
            if (!checkIfJDK12())
                throw new ClassNotFoundException(e.getMessage());
        }
        catch (Error e) {
            if ( !checkIfJDK12() )
                throw e;
        }

        /**
         *  In jdk1.2 application, when you have jmf.jar in the ext directory and
         *  you want to access a class that is not in jmf.jar but is in the CLASSPATH,
         *  you have to load it using the the system class loader.
         */
        try {
            return (Class) forName3ArgsM.invoke(Class.class, new Object[] {
                className, new Boolean(true), systemClassLoader
            });
        }
        catch (Throwable e) {
        }

        /**
         *  In jdk1.2 applet, when you have jmf.jar in the ext directory and
         *  you want to access a class that is not in jmf.jar but applet codebase,
         *  you have to load it using the the context class loader.
         */
        try {
            // TODO: may need to invoke RuntimePermission("getClassLoader") privilege
            ClassLoader contextClassLoader = (ClassLoader) getContextClassLoaderM.invoke ( Thread.currentThread(), null );
            return (Class) forName3ArgsM.invoke(Class.class, new Object[] {
                className, new Boolean(true), contextClassLoader
            });
        }
        catch (Exception e) {
            throw new ClassNotFoundException ( e.getMessage() );
        }
        catch (Error e) {
            throw e;
        }
    
public java.util.VectorgetList(int code)

        pluginVector = PlugInManager.getPlugInList(null, null, type);
        if (pluginVector == null)
            pluginVector = new Vector(1);
        return pluginVector;
    
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  name = null;
        String  text = "";
        Object  input = null;
        Object  output = null;

        if ( index >= 0 )
            name = (String) pluginVector.elementAt(index);

        if ( name != null )
            input = PlugInManager.getSupportedInputFormats(name, type);
        if (input != null) {
            text += JMFI18N.getResource("jmfregistry.details.informats")
                                + "---->\n\n" + printFormats(input) + "\n\n";
        }

        if ( name != null )
            output = PlugInManager.getSupportedOutputFormats(name, type);
        if (output != null) {
            text += JMFI18N.getResource("jmfregistry.details.outformats")
                                + "--->\n\n" + printFormats(output) + "\n\n";
        }
      	textArea.setText(text);
    
public voidsetList(int code, java.util.Vector v)

        pluginVector = 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;