Class CPanelPopup


public class CPanelPopup extends CDecorateableAction<CPanelPopup.PanelPopup>
This action shows some kind of popup (for example a JDialog) filled with any content the client likes. This action is intended to be shown as button in a title, but can also be used as menu item in a menu.
Clients may override the various onXYZ-methods and create and show their custom popup. In such a case they should call openPopup(PanelPopupWindow) to ensure that only one window is open at a time.
As long as the user works on the popup-window it does not close automatically, clients can call closePopup() to explicitly close it. The window closes automatically if it loses the focus, clients can call setCloseOnFocusLost(boolean) to change that behavior.
Note: this action does not support being child of a drop down menu
Author:
Benjamin Sigg
  • Field Details

  • Constructor Details

    • CPanelPopup

      public CPanelPopup()
      Creates a new action.
  • Method Details

    • setContent

      public void setContent(JComponent content)
      Sets the component that is shown on a popup dialog/menu/window... by this CPanelPopup.
      Parameters:
      content - the content, may be null
    • getContent

      public JComponent getContent()
      Gets the contents of this action.
      Returns:
      the contents
    • setMenuBehavior

      public void setMenuBehavior(CPanelPopup.MenuBehavior menu)
      Tells this action how to behave if it is in a menu. This may not have an effect if the action already is part of a menu.
      Parameters:
      menu - the behavior, not null
    • getMenuBehavior

      public CPanelPopup.MenuBehavior getMenuBehavior()
      Tells how this action behaves if in a menu.
      Returns:
      the behavior, not null
    • setButtonBehavior

      public void setButtonBehavior(CPanelPopup.ButtonBehavior button)
      Tells this action how to handle buttons.
      Parameters:
      button - when to open a popup
    • getButtonBehavior

      public CPanelPopup.ButtonBehavior getButtonBehavior()
      Tells how this action behaves if displayed as button.
      Returns:
      the behavior, not null
    • setCloseOnFocusLost

      public void setCloseOnFocusLost(boolean closeOnFocusLost)
      Whether the window should be closed if focus is lost.
      Parameters:
      closeOnFocusLost - true if it should close automatically
    • isCloseOnFocusLost

      public boolean isCloseOnFocusLost()
      Tells whether the window is automatically closed if the focus is lost.
      Returns:
      whether the popup is closed automatically
    • openPopup

      public void openPopup(PanelPopupWindow window)
      Informs this CPanelPopup that its content is shown and allows this to handle the closing event.
      Parameters:
      window - the window
      Throws:
      IllegalArgumentException - if PanelPopupWindow.isOpen() return false
    • closePopup

      public void closePopup()
      Makes the current popup invisible.
    • isOpen

      public boolean isOpen()
      Tells whether the content of this action is currently being showed.
      Returns:
      true if the content is visible
    • onMousePressed

      protected void onMousePressed(Dockable dockable, JComponent item, DockTitle.Orientation orientation)
      Called if the mouse is pressed on the button item of of a DockTitle which has orientation orientation.
      Parameters:
      dockable - the element for which this panel is shown
      item - the pressed component
      orientation - the orientation of the title
    • onMouseReleased

      protected void onMouseReleased(Dockable dockable, JComponent item, DockTitle.Orientation orientation)
      Called if the mouse is released of the button item of of a DockTitle which has orientation orientation.
      Parameters:
      dockable - the element for which this panel is shown
      item - the released component
      orientation - the orientation of the title
    • onTrigger

      protected void onTrigger(Dockable dockable, JComponent item, DockTitle.Orientation orientation)
      Called if the button item of a DockTitle which has orientation orientation was triggered.
      Parameters:
      dockable - the element for which this panel is shown
      item - the triggered button
      orientation - the orientation of the title
    • openDialog

      protected void openDialog(Dockable dockable, JComponent item, DockTitle.Orientation orientation)
      Opens a new undecorated dialog below or aside of item. This method does nothing if isOpen() return true.
      Parameters:
      dockable - the element for which this panel is shown
      item - the owner of the new dialog
      orientation - the orientation of the title which shows item
    • onMenuItemTrigger

      protected void onMenuItemTrigger(Dockable dockable)
      Called if the menu-item representing this action has been hit.
      Parameters:
      dockable - the source of the event
    • createDialogWindow

      protected DialogWindow createDialogWindow(Component owner)
      Creates a new window which will be used as popup for this CPanelPopup.
      Parameters:
      owner - the owner of the window
      Returns:
      the new window, not null
    • onMenuTrigger

      protected void onMenuTrigger(JPopupMenu menu)
      Called if a menu is opening a submenu in which the content is to be shown.
      Parameters:
      menu - the new parent of the content
    • createMenuWindow

      protected MenuWindow createMenuWindow(JPopupMenu menu)
      Creates a new window which will be used as popup for this CPanelPopup.
      Parameters:
      menu - the owner of the window
      Returns:
      the new window, not null
    • executeOneDockableHasFocus

      protected void executeOneDockableHasFocus(Dockable dockable, Runnable run)
      Calls run once the owning Dockable of this action has the focus
      Parameters:
      dockable - the element for which this panel is shown
      run - some piece of code to run, usually it will open the popup-dialog created by createDialogWindow(Component). Should be called by the EDT.