FileDocCategorySizeDatePackage
ButtonComp.javaAPI DocJMF 2.1.1e8761Mon May 12 12:20:50 BST 2003com.sun.media.ui

ButtonComp

public class ButtonComp extends BasicComp implements MouseListener

Fields Summary
Image[]
imageNormal
Image[]
imageActive
Image[]
imageDown
Image[]
imageDisabled
static final int
NORMAL
static final int
ACTIVE
static final int
DOWN
static final int
DISABLED
int
width
int
height
boolean
state
boolean
mouseIn
boolean
mouseDown
boolean
mouseUp
boolean
mouseClick
int
visualState
private PopupMenu
menuPopup
private ContPressThread
threadContPress
private boolean
boolContPress
private boolean
boolPopup
private boolean
boolDoAction
private static final int
POPUP_DELAY
Constructors Summary
public ButtonComp(String label, String imgNormal0, String imgActive0, String imgDown0, String imgDisabled0, String imgNormal1, String imgActive1, String imgDown1, String imgDisabled1)

    

      
		       
		       
		       
		       
		       
		       
		       
		        
        super(label);

        // Two images each
        imageNormal = new Image[2];
        imageActive = new Image[2];
        imageDown = new Image[2];
        imageDisabled = new Image[2];

        // Load the images
        imageNormal[0] = fetchImage(imgNormal0);
        imageNormal[1] = fetchImage(imgNormal1);
        imageActive[0] = fetchImage(imgActive0);
        imageActive[1] = fetchImage(imgActive1);
        imageDown[0] = fetchImage(imgDown0);
        imageDown[1] = fetchImage(imgDown1);
        imageDisabled[0] = fetchImage(imgDisabled0);
        imageDisabled[1] = fetchImage(imgDisabled1);

        width = imageNormal[0].getWidth( this );
        height = imageNormal[0].getHeight( this );
        visualState = NORMAL;
        setSize(width, height);
        setVisible(true);
        addMouseListener(this);
    
Methods Summary
public voidaction()

        if ( boolDoAction == false )
            return;
        state = !state;
        informListener();
    
public java.awt.DimensiongetPreferredSize()

        return new Dimension(width, height);
    
public booleangetValue()

        return state;
    
public voidmouseActivity()


        if (isEnabled()) {
            if (mouseIn) {
                if (mouseDown) {
                    visualState = DOWN;
                    if (mouseUp) {
                        action();
                        visualState = ACTIVE;
                    }
                }
                else {
                    visualState = ACTIVE;
                }
            }
            else {
                visualState = NORMAL;
            }
        }
        else {
            visualState = DISABLED;
        }
        repaint();
    
public voidmouseClicked(java.awt.event.MouseEvent e)

        int modifier = e.getModifiers();
        if ((modifier & InputEvent.BUTTON2_MASK) == 0
                        &&  (modifier & InputEvent.BUTTON3_MASK) == 0 ) {
            mouseClick = true;
            mouseActivity();
            mouseClick = false;
        }
    
public voidmouseEntered(java.awt.event.MouseEvent e)

        mouseIn = true;
        mouseActivity();
    
public voidmouseExited(java.awt.event.MouseEvent e)

        mouseIn = false;
        mouseActivity();

        if ( threadContPress != null ) {
            threadContPress.stopNormaly ();
            threadContPress = null;
        }
    
public voidmousePressed(java.awt.event.MouseEvent e)

        int modifier = e.getModifiers();
        if ((modifier & InputEvent.BUTTON2_MASK) == 0
                        &&  (modifier & InputEvent.BUTTON3_MASK) == 0 ) {
            mouseDown = true;
            mouseUp = false;
            mouseActivity();

            if ( boolContPress == true  ||  boolPopup == true ) {
                if ( threadContPress != null )
                    threadContPress.stopNormaly ();
                threadContPress = new ContPressThread ( this );
                if ( boolPopup == true )
                    threadContPress.setDelayedPress ( POPUP_DELAY );
                threadContPress.start ();
            }
            boolDoAction = true;
        }
    
public voidmouseReleased(java.awt.event.MouseEvent e)

        int modifier = e.getModifiers();
        if ((modifier & InputEvent.BUTTON2_MASK) == 0
                        &&  (modifier & InputEvent.BUTTON3_MASK) == 0 ) {
            mouseUp = true;
            mouseActivity();
            mouseUp = false;
            mouseDown = false;

            if ( threadContPress != null ) {
                threadContPress.stopNormaly ();
                threadContPress = null;
            }
        }
    
public voidpaint(java.awt.Graphics g)

        int index = state? 1:0;
        Image image = null;

        switch (visualState) {
            case NORMAL:
                image = imageNormal[index];
                break;
            case ACTIVE:
                image = imageActive[index];
                break;
            case DOWN:
                image = imageDown[index];
                break;
            case DISABLED:
                image = imageDisabled[index];
                break;
        }
        if (image != null)
            g.drawImage(image, 0, 0, this);
    
protected voidprocessContPress()

        if ( boolContPress == true )
            informListener ();
        else if ( boolPopup == true  &&  mouseIn  &&  mouseDown ) {
            boolDoAction = false;
            processMousePopup ();
        }
    
protected voidprocessMouseEvent(java.awt.event.MouseEvent event)

        super.processMouseEvent ( event );

        if ( event.isPopupTrigger() ) {
            processMousePopup ();
        }
    
protected voidprocessMousePopup()

//      Dimension    dim;

        if ( menuPopup != null ) {
//          dim = this.getSize ();
            menuPopup.show ( this, 0, height );
        }
    
public voidsetContMousePress(boolean boolSet)

        boolContPress = boolSet;
    
public voidsetEnabled(boolean value)

        super.setEnabled(value);
        if (value == false) {
            visualState = DISABLED;
            //setCursor( new Cursor(Cursor.DEFAULT_CURSOR) );
        }
        else {
            if (mouseIn) {
                if (mouseDown)
                    visualState = DOWN;
                else
                    visualState = ACTIVE;
            }
            else {
                visualState = NORMAL;
                //setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
        }
        repaint();
    
public voidsetMousePopup(boolean boolPopup)

        this.boolPopup = boolPopup;
    
public voidsetPopupMenu(java.awt.PopupMenu menuPopup)

	if (menuPopup != null) {
            setMousePopup ( true );
            this.menuPopup = menuPopup;
            this.add ( menuPopup );
	} else if (this.menuPopup != null) {
	    setMousePopup(false);
	    remove(this.menuPopup);
	    this.menuPopup = null;
	}
    
public voidsetValue(boolean newState)

        if (state != newState) {
            state = newState;
            repaint();
        }