FileDocCategorySizeDatePackage
FixedGlassPane.javaAPI DocExample4602Fri Jan 17 07:33:24 GMT 2003None

FixedGlassPane

public class FixedGlassPane extends JPanel implements MouseListener, MouseMotionListener, FocusListener

Fields Summary
Toolkit
toolkit
JMenuBar
menuBar
Container
contentPane
boolean
inDrag
boolean
needToRedispatch
Constructors Summary
public FixedGlassPane(JMenuBar mb, Container cp)


       
    toolkit = Toolkit.getDefaultToolkit();
    menuBar = mb;
    contentPane = cp;
    addMouseListener(this);
    addMouseMotionListener(this);
    addFocusListener(this);
  
Methods Summary
public voidfocusGained(java.awt.event.FocusEvent fe)

 
public voidfocusLost(java.awt.event.FocusEvent fe)

 if (isVisible()) requestFocus(); 
public voidmouseClicked(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmouseDragged(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmouseEntered(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmouseExited(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmouseMoved(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmousePressed(java.awt.event.MouseEvent e)

    if (needToRedispatch) redispatchMouseEvent(e);
  
public voidmouseReleased(java.awt.event.MouseEvent e)

    if (needToRedispatch) {
      redispatchMouseEvent(e);
      inDrag = false;
    }
  
private voidredispatchMouseEvent(java.awt.event.MouseEvent e)

    boolean inButton = false;
    boolean inMenuBar = false;
    Point glassPanePoint = e.getPoint();
    Component component = null;
    Container container = contentPane;
    Point containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, 
                                      contentPane);
    int eventID = e.getID();

    if (containerPoint.y < 0) {
      inMenuBar = true;
      container = menuBar;
      containerPoint = SwingUtilities.convertPoint(this, glassPanePoint,
                                      menuBar);
      testForDrag(eventID);
    } 

    //XXX: If the event is from a component in a popped-up menu,
    //XXX: then the container should probably be the menu's
    //XXX: JPopupMenu, and containerPoint should be adjusted
    //XXX: accordingly.
    component = SwingUtilities.getDeepestComponentAt(container,
                                        containerPoint.x,
                                        containerPoint.y);

    if (component == null) {
      return;
    }
    else {
      inButton = true;
      testForDrag(eventID);
    }

    if (inMenuBar || inButton || inDrag) {
      Point componentPoint = SwingUtilities.convertPoint(this, glassPanePoint, 
                                                         component);
      component.dispatchEvent(new MouseEvent(component,
                                             eventID,
                                             e.getWhen(),
                                             e.getModifiers(),
                                             componentPoint.x,
                                             componentPoint.y,
                                             e.getClickCount(),
                                             e.isPopupTrigger()));
    }
  
public voidsetNeedToRedispatch(boolean need)

    needToRedispatch = need;
  
public voidsetVisible(boolean v)

    // Make sure we grab the focus so that key events don't go astray.
    if (v) requestFocus();
    super.setVisible(v);
  
private voidtestForDrag(int eventID)

    if (eventID == MouseEvent.MOUSE_PRESSED) {
      inDrag = true;
    }