bibliothek.gui.dock.common.action
Class CPanelPopup

java.lang.Object
  extended by bibliothek.gui.dock.common.action.CAction
      extended by bibliothek.gui.dock.common.intern.action.CDecorateableAction
          extended by bibliothek.gui.dock.common.action.CPanelPopup

public class CPanelPopup
extends CDecorateableAction

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

Nested Class Summary
static class CPanelPopup.ButtonBehavior
          When the popup should show up if the action is displayed as button.
static class CPanelPopup.MenuBehavior
          Tells how a CPanelPopup behaves if it is a child of a menu.
 class CPanelPopup.PanelPopup
          A custom action shows some dialog or window when triggered
 
Field Summary
static ActionType<CPanelPopup.PanelPopup> PANEL_POPUP
          the kind of action this class represents
 
Constructor Summary
CPanelPopup()
          Creates a new action.
 
Method Summary
 void closePopup()
          Makes the current popup invisible.
protected  DialogWindow createDialogWindow(Component owner)
          Creates a new window which will be used as popup for this CPanelPopup.
protected  MenuWindow createMenuWindow(JPopupMenu menu)
          Creates a new window which will be used as popup for this CPanelPopup.
 CPanelPopup.ButtonBehavior getButtonBehavior()
          Tells how this action behaves if displayed as button.
 JComponent getContent()
          Gets the contents of this action.
 CPanelPopup.MenuBehavior getMenuBehavior()
          Tells how this action behaves if in a menu.
 boolean isCloseOnFocusLost()
          Tells whether the window is automatically closed if the focus is lost.
 boolean isOpen()
          Tells whether the content of this action is currently being showed.
protected  void onMenuItemTrigger(Dockable dockable)
          Called if the menu-item representing this action has been hit.
protected  void onMenuTrigger(JPopupMenu menu)
          Called if a menu is opening a submenu in which the content is to be shown.
protected  void onMousePressed(JComponent item, DockTitle.Orientation orientation)
          Called if the mouse is pressed on the button item of of a DockTitle which has orientation orientation.
protected  void onMouseReleased(JComponent item, DockTitle.Orientation orientation)
          Called if the mouse is released of the button item of of a DockTitle which has orientation orientation.
protected  void onTrigger(JComponent item, DockTitle.Orientation orientation)
          Called if the button item of a DockTitle which has orientation orientation was triggered.
protected  void openDialog(JComponent item, DockTitle.Orientation orientation)
          Opens a new undecorated dialog below or aside of item.
 void openPopup(PanelPopupWindow window)
          Informs this CPanelPopup that its content is shown and allows this to handle the closing event.
 void setButtonBehavior(CPanelPopup.ButtonBehavior button)
          Tells this action how to handle buttons.
 void setCloseOnFocusLost(boolean closeOnFocusLost)
          Whether the window should be closed if focus is lost.
 void setContent(JComponent content)
          Sets the component that is shown on a popup dialog/menu/window... by this CPanelPopup.
 void setMenuBehavior(CPanelPopup.MenuBehavior menu)
          Tells this action how to behave if it is in a menu.
 
Methods inherited from class bibliothek.gui.dock.common.intern.action.CDecorateableAction
getAccelerator, getDisabledIcon, getIcon, getText, getTooltip, init, isEnabled, setAccelerator, setDisabledIcon, setEnabled, setIcon, setText, setTooltip
 
Methods inherited from class bibliothek.gui.dock.common.action.CAction
init, intern
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PANEL_POPUP

public static final ActionType<CPanelPopup.PanelPopup> PANEL_POPUP
the kind of action this class represents

Constructor Detail

CPanelPopup

public CPanelPopup()
Creates a new action.

Method Detail

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(JComponent item,
                              DockTitle.Orientation orientation)
Called if the mouse is pressed on the button item of of a DockTitle which has orientation orientation.

Parameters:
item - the pressed component
orientation - the orientation of the title

onMouseReleased

protected void onMouseReleased(JComponent item,
                               DockTitle.Orientation orientation)
Called if the mouse is released of the button item of of a DockTitle which has orientation orientation.

Parameters:
item - the released component
orientation - the orientation of the title

onTrigger

protected void onTrigger(JComponent item,
                         DockTitle.Orientation orientation)
Called if the button item of a DockTitle which has orientation orientation was triggered.

Parameters:
item - the triggered button
orientation - the orientation of the title

openDialog

protected void openDialog(JComponent item,
                          DockTitle.Orientation orientation)
Opens a new undecorated dialog below or aside of item. This method does nothing if isOpen() return true.

Parameters:
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