boolean fit = true; Dimension size;   if (this.getSize().width == 0 && this.getSize().width == 0) size = this.getPreferredSize(); else size = this.getSize();  if ((size.width > (rootContainer.getWidth() - popupLocation.x)) || (size.height > (rootContainer.getHeight() - popupLocation.y))) fit = false; if (lightWeightPopupEnabled && fit) popup = new LightWeightPopup(this); else { if (fit) popup = new MediumWeightPopup(this); else popup = new HeavyWeightPopup(this); } if (popup instanceof LightWeightPopup || popup instanceof MediumWeightPopup) { JLayeredPane layeredPane;
if ((size.width > (rootContainer.getWidth() - popupLocation.x)) || (size.height > (rootContainer.getHeight() - popupLocation.y))) fit = false; if (lightWeightPopupEnabled && fit) popup = new LightWeightPopup(this); else { if (fit) popup = new MediumWeightPopup(this); else { popup = new HeavyWeightPopup(this); setLightWeightPopupEnabled(false); } } if (popup instanceof LightWeightPopup || popup instanceof MediumWeightPopup) { JLayeredPane layeredPane;
  public void setVisible(boolean visible)  {    if (visible == isVisible())      return;    boolean old = isVisible();    this.visible = visible;    if (old != isVisible())      {	firePropertyChange("visible", old, isVisible());    if (visible)      {	    firePopupMenuWillBecomeVisible();	Container rootContainer = (Container) SwingUtilities.getRoot(invoker);            Dimension screenSize = getToolkit().getScreenSize();	boolean fit = true;	Dimension size;	// Determine the size of the popup menu	if (this.getSize().width == 0 && this.getSize().width == 0)	  size = this.getPreferredSize();	else	  size = this.getSize();	    if ((size.width > (rootContainer.getWidth() - popupLocation.x))	        || (size.height > (rootContainer.getHeight() - popupLocation.y)))	  fit = false;	if (lightWeightPopupEnabled && fit)	  popup = new LightWeightPopup(this);	else	  {	    if (fit)	      popup = new MediumWeightPopup(this);	    else	      popup = new HeavyWeightPopup(this);	  }        if (popup instanceof LightWeightPopup             || popup instanceof MediumWeightPopup)          {            JLayeredPane layeredPane;                layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();		Point p = new Point(popupLocation.x, popupLocation.y);		SwingUtilities.convertPointFromScreen(p, layeredPane);                                if (size.width + popupLocation.x > screenSize.width)                  popupLocation.x -= size.width;                if (size.height + popupLocation.y > screenSize.height)                  popupLocation.y -= size.height;                		popup.show(p.x, p.y, size.width, size.height);	      }	    else	      {		// Subtract insets of the top-level container if popup menu's		// top-left corner is inside it.		    Insets insets = rootContainer.getInsets();                if (size.width + popupLocation.x > screenSize.width)                  popupLocation.x -= size.width;                if (size.height + popupLocation.y > screenSize.height)                  popupLocation.y -= size.height;                  		    popup.show(popupLocation.x - insets.left,                           popupLocation.y - insets.top,                           size.width, size.height);          }       }    else      {	firePopupMenuWillBecomeInvisible();	popup.hide();      }  }  }