FileDocCategorySizeDatePackage
VideoPanel.javaAPI DocJMF 2.1.1e8243Mon May 12 12:20:30 BST 2003jmapps.ui

VideoPanel

public class VideoPanel extends JMPanel implements ComponentListener, MouseListener, ActionListener

Fields Summary
private MediaPlayer
mediaPlayer
private Component
compVisual
private double
dScale
private PopupMenu
menuZoom
private MenuItem
menuItemZoom_1_2
private MenuItem
menuItemZoom_1_1
private MenuItem
menuItemZoom_2_1
private MenuItem
menuItemZoom_4_1
public static final String
MENU_ZOOM
public static final String
MENU_ZOOM_1_2
public static final String
MENU_ZOOM_1_1
public static final String
MENU_ZOOM_2_1
public static final String
MENU_ZOOM_4_1
Constructors Summary
public VideoPanel(MediaPlayer mediaPlayer)



          
        super ( null );

        this.setBackground ( Color.black );
        this.addComponentListener ( this );
        createPopupMenuZoom ();
        setMediaPlayer ( mediaPlayer );
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

        String      strCmd;

        strCmd = event.getActionCommand ();
        if ( strCmd.equals(MENU_ZOOM_1_2) ) {
            dScale = 0.5;
        }
        else if ( strCmd.equals(MENU_ZOOM_1_1) ) {
            dScale = 1.0;
        }
        else if ( strCmd.equals(MENU_ZOOM_2_1) ) {
            dScale = 2.0;
        }
        else if ( strCmd.equals(MENU_ZOOM_4_1) ) {
            dScale = 4.0;
        }
//        mediaPlayer.setZoomTo ( "" + dScale + "f" );
        this.invalidate ();
    
public voidaddMenuZoomActionListener(java.awt.event.ActionListener listener)

        if ( menuItemZoom_1_2 != null )
            menuItemZoom_1_2.addActionListener ( listener );
        if ( menuItemZoom_1_1 != null )
            menuItemZoom_1_1.addActionListener ( listener );
        if ( menuItemZoom_2_1 != null )
            menuItemZoom_2_1.addActionListener ( listener );
        if ( menuItemZoom_4_1 != null )
            menuItemZoom_4_1.addActionListener ( listener );
    
public voidaddNotify()

	super.addNotify();
	if (compVisual != null)
	    compVisual.addMouseListener(this);
    
private voidaddPopupMenuZoom()

        if ( compVisual == null )
            return;
        createPopupMenuZoom ();
	compVisual.add ( menuZoom );
    
public voidcomponentHidden(java.awt.event.ComponentEvent event)

    
public voidcomponentMoved(java.awt.event.ComponentEvent event)

    
public voidcomponentResized(java.awt.event.ComponentEvent event)

        resizeVisualComponent ();
    
public voidcomponentShown(java.awt.event.ComponentEvent event)

    
private voidcreatePopupMenuZoom()

        if ( menuZoom != null )
            return;

        menuZoom = new PopupMenu ( MENU_ZOOM );

        menuItemZoom_1_2 = new MenuItem ( MENU_ZOOM_1_2 );
        menuZoom.add ( menuItemZoom_1_2 );
        menuItemZoom_1_2.addActionListener ( this );

        menuItemZoom_1_1 = new MenuItem ( MENU_ZOOM_1_1 );
        menuZoom.add ( menuItemZoom_1_1 );
        menuItemZoom_1_1.addActionListener ( this );

        menuItemZoom_2_1 = new MenuItem ( MENU_ZOOM_2_1 );
        menuZoom.add ( menuItemZoom_2_1 );
        menuItemZoom_2_1.addActionListener ( this );

        menuItemZoom_4_1 = new MenuItem ( MENU_ZOOM_4_1 );
        menuZoom.add ( menuItemZoom_4_1 );
        menuItemZoom_4_1.addActionListener ( this );
    
public java.awt.ComponentgetMediaPlayer()

        return ( mediaPlayer );
    
public java.awt.DimensiongetPreferredSize()

        Dimension   dim;

        if ( compVisual == null  ||  mediaPlayer == null ) {
            dim = new Dimension ( 320, 0 );
        }
        else {
//            dim = mediaPlayer.getPreferredSize ();
            dim = compVisual.getPreferredSize ();
            dim.width = (int)(dim.width * dScale);
            dim.height = (int)(dim.height * dScale);
        }
        return ( dim );
    
public java.awt.ComponentgetVisualComponent()

        return ( mediaPlayer.getVisualComponent() /*compVisual*/ );
    
public doublegetZoom()

        return ( dScale );
    
public voidmouseClicked(java.awt.event.MouseEvent event)

        if ( event.isPopupTrigger() )
            menuZoom.show ( compVisual, event.getX(), event.getY() );
    
public voidmouseEntered(java.awt.event.MouseEvent event)

    
public voidmouseExited(java.awt.event.MouseEvent event)

    
public voidmousePressed(java.awt.event.MouseEvent event)

        if ( event.isPopupTrigger() ) {
            menuZoom.show ( compVisual, event.getX(), event.getY() );
	}
    
public voidmouseReleased(java.awt.event.MouseEvent event)

        if ( event.isPopupTrigger() ) {
            menuZoom.show ( compVisual, event.getX(), event.getY() );
	}
    
public voidremoveMenuZoomActionListener(java.awt.event.ActionListener listener)

        if ( menuItemZoom_1_2 != null )
            menuItemZoom_1_2.removeActionListener ( listener );
        if ( menuItemZoom_1_1 != null )
            menuItemZoom_1_1.removeActionListener ( listener );
        if ( menuItemZoom_2_1 != null )
            menuItemZoom_2_1.removeActionListener ( listener );
        if ( menuItemZoom_4_1 != null )
            menuItemZoom_4_1.removeActionListener ( listener );
    
public voidremoveNotify()

	super.removeNotify();
	if (compVisual != null)
	    compVisual.removeMouseListener(this);
    
public voidresizeVisualComponent()

        Dimension   dimThis;

        dimThis = this.getSize ();
        if ( mediaPlayer != null  &&  mediaPlayer.getParent() == this )
            mediaPlayer.setBounds ( 0, 0, dimThis.width, dimThis.height );
        else if ( compVisual != null  &&  compVisual.getParent() == this )
            compVisual.setBounds ( 0, 0, dimThis.width, dimThis.height );
        this.validate ();
    
public voidsetMediaPlayer(javax.media.bean.playerbean.MediaPlayer mediaPlayer)

        int             i;
        MonitorControl  mc;
        Control         controls [];
        Panel           mainPanel;
        Panel           currentPanel;
        Panel           newPanel;
        Component       compControl;

        this.removeAll ();
        if ( compVisual != null ) // previous one
            compVisual.removeMouseListener ( this );

        this.mediaPlayer = mediaPlayer;
        compVisual = mediaPlayer.getVisualComponent ();
        if ( compVisual == null ) {
            mc = (MonitorControl) mediaPlayer.getControl ( "javax.media.control.MonitorControl" );
            if ( mc != null ) {
                controls = mediaPlayer.getControls ();
                mainPanel = new Panel ( new BorderLayout() );
                currentPanel = mainPanel;
                for ( i = 0;  i < controls.length;  i++ ) {
                    if ( !(controls[i] instanceof MonitorControl) )
                        continue;
                    mc = (MonitorControl) controls[i];
                    mc.setEnabled ( true );
                    compControl = mc.getControlComponent();
                    if ( compControl == null )
                        continue;
                    currentPanel.add ( compControl, BorderLayout.CENTER );
                    newPanel = new Panel ( new BorderLayout() );
                    currentPanel.add ( newPanel, BorderLayout.SOUTH );
                    currentPanel = newPanel;
                }
                compVisual = mainPanel;
                this.add ( mainPanel );
            }
        }
        else {
            this.add ( mediaPlayer );
        }

        if ( compVisual == null )
            return;

        resizeVisualComponent ();
        addPopupMenuZoom ();
    
public voidsetZoom(double dScale)

        this.dScale = dScale;