de.matthiasmann.twl
Class PopupWindow

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.Container
          extended by de.matthiasmann.twl.PopupWindow
Direct Known Subclasses:
MenuManager, RadialPopupMenu

public class PopupWindow
extends Container

A generic pop-up window. Must not be added as a child to another Widget. While other widgets have a parent/child relationship, pop-up windows have only have a owner. When a pop-up window is open it will block all mouse and keyboard events to the UI layer of it's owner. This includes the owner, all it's children, all siblings and parents etc. If the pop-up window is hidden or disabled it will close instead. When the owner is hidden (either directly or indirectly) or removed from the GUI tree then the pop-up is also closed. To use a PopupWindow construct it with your widget as owner and add the content widget. Call openPopup to make it visible. Only one widget should be added as child to a pop-up window. This widget will occupy the whole inner area. If more then one widget is added then they will overlap.

See Also:
openPopup(), Widget.layoutChildrenFullInnerArea()

Nested Class Summary
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
PopupWindow(Widget owner)
          Creates a new pop-up window.
 
Method Summary
 boolean bindMouseDrag(java.lang.Runnable cb)
          Binds the current drag event (even if it's not yet started) to this pop-up.
 void centerPopup()
          Centers the pop-up on the screen.
 void closePopup()
          Closes this pop-up window.
protected  void escapePressed(Event evt)
          Called when the escape key was pressed.
 Widget getOwner()
           
 int getPreferredHeight()
          Returns the preferred height.
 int getPreferredWidth()
          Returns the preferred width based on it's children and preferred inner width.
 java.lang.Runnable getRequestCloseCallback()
           
protected  boolean handleEvent(Event evt)
          This method is final to ensure correct event handling for pop-ups.
protected  boolean handleEventPopup(Event evt)
          This method can be overriden to customize the event handling of a pop-up window.
 boolean isCloseOnClickedOutside()
           
 boolean isCloseOnEscape()
           
protected  boolean isMouseInside(Event evt)
          Checks whether the mouse is inside the widget or not.
 boolean isOpen()
          Checks if this pop-up window is currently open
protected  void mouseClickedOutside(Event evt)
          Called when a mouse click happened outside the pop-up window area.
 boolean openPopup()
          Opens the pop-up window with it's current size and position.
 void openPopupCentered()
          Opens the pop-up window, calls adjustSize and centers the pop-up on the screen.
 void openPopupCentered(int width, int height)
          Opens the pop-up window with the specified size and centers the pop-up on the screen.
protected  void requestPopupClose()
          Called when escape if pressed and closeOnEscape is enabled.
 void setCloseOnClickedOutside(boolean closeOnClickedOutside)
          Controls if this pop-up window should close when a mouse click happens outside of it's area.
 void setCloseOnEscape(boolean closeOnEscape)
          Controls if this pop-up should close when the escape key is pressed.
 void setRequestCloseCallback(java.lang.Runnable requestCloseCallback)
          Sets a callback to be called when requestPopupClose() is executed.
 
Methods inherited from class de.matthiasmann.twl.Container
getMinHeight, getMinWidth, getPreferredInnerHeight, getPreferredInnerWidth, layout
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, adjustSize, afterAddToGUI, allChildrenRemoved, applyTheme, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, beforeRemoveFromGUI, borderChanged, canAcceptKeyboardFocus, childAdded, childInvalidateLayout, childRemoved, childVisibilityChanged, computeSize, destroy, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, focusFirstChild, focusLastChild, focusNextChild, focusPrevChild, getActionMap, getAnimationState, getBackground, getBorderBottom, getBorderHorizontal, getBorderLeft, getBorderRight, getBorderTop, getBorderVertical, getBottom, getChild, getChildAt, getChildIndex, getGUI, getHeight, getInnerBottom, getInnerHeight, getInnerRight, getInnerWidth, getInnerX, getInnerY, getInputMap, getKeyboardFocusOrder, getMaxHeight, getMaxWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContent, getTooltipContentAt, getWidgetAt, getWidth, getX, getY, giveupKeyboardFocus, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, insertChild, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isVisible, keyboardFocusChildChanged, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, paintWidget, positionChanged, reapplyTheme, removeAllChildren, removeChild, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setEnabled, setFocusKeyEnabled, setInnerSize, setInputMap, setMaxSize, setMinSize, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, setVisible, sizeChanged, updateTintAnimation, updateTooltip, validateLayout, widgetDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopupWindow

public PopupWindow(Widget owner)
Creates a new pop-up window.

Parameters:
owner - The owner of this pop-up
Method Detail

getOwner

public Widget getOwner()

isCloseOnClickedOutside

public boolean isCloseOnClickedOutside()

setCloseOnClickedOutside

public void setCloseOnClickedOutside(boolean closeOnClickedOutside)
Controls if this pop-up window should close when a mouse click happens outside of it's area. This is useful for context menus or drop down combo boxes. Default is true.

Parameters:
closeOnClickedOutside - true if it should close on clicks outside it's area

isCloseOnEscape

public boolean isCloseOnEscape()

setCloseOnEscape

public void setCloseOnEscape(boolean closeOnEscape)
Controls if this pop-up should close when the escape key is pressed. Default is true.

Parameters:
closeOnEscape - true if it should close on escape

getRequestCloseCallback

public java.lang.Runnable getRequestCloseCallback()

setRequestCloseCallback

public void setRequestCloseCallback(java.lang.Runnable requestCloseCallback)
Sets a callback to be called when requestPopupClose() is executed. This will override the default behavior of closing the popup.

Parameters:
requestCloseCallback - the new callback or null

openPopup

public boolean openPopup()
Opens the pop-up window with it's current size and position. In order for this to work the owner must be part of the GUI tree. When a pop-up window is shown it is always visible and enabled.

Returns:
true if the pop-up window could be opened.
See Also:
getOwner(), Widget.getGUI()

openPopupCentered

public void openPopupCentered()
Opens the pop-up window, calls adjustSize and centers the pop-up on the screen.

See Also:
Widget.adjustSize(), centerPopup()

openPopupCentered

public void openPopupCentered(int width,
                              int height)
Opens the pop-up window with the specified size and centers the pop-up on the screen. If the specified size is larger then the available space then it is reduced to the available space.

Parameters:
width - the desired width
height - the desired height
See Also:
centerPopup()

closePopup

public void closePopup()
Closes this pop-up window. Keyboard focus is transfered to it's owner.


isOpen

public final boolean isOpen()
Checks if this pop-up window is currently open

Returns:
true if it is open

centerPopup

public void centerPopup()
Centers the pop-up on the screen. If the pop-up is not open then this method does nothing.

See Also:
isOpen()

bindMouseDrag

public boolean bindMouseDrag(java.lang.Runnable cb)
Binds the current drag event (even if it's not yet started) to this pop-up. The mouse drag events will be send as normal mouse move events. The optional callback will be called when the drag event is finished.

Parameters:
cb - the optional callback which should be called at the end of the bound drag.
Returns:
true if the binding was successful, false if not.

getPreferredWidth

public int getPreferredWidth()
Description copied from class: Widget
Returns the preferred width based on it's children and preferred inner width. Subclasses can overwrite this method to compute the preferred size differently.

Overrides:
getPreferredWidth in class Widget
Returns:
the preferred width.
See Also:
Widget.getPreferredInnerWidth()

getPreferredHeight

public int getPreferredHeight()
Description copied from class: Widget
Returns the preferred height. This method determines the preferred height based on it's children. Subclasses can overwrite this method to compute the preferred size differently.

Overrides:
getPreferredHeight in class Widget
Returns:
the preferred height.
See Also:
Widget.getPreferredInnerHeight()

handleEvent

protected final boolean handleEvent(Event evt)
This method is final to ensure correct event handling for pop-ups. To customize the event handling override the handleEventPopup(de.matthiasmann.twl.Event).

Overrides:
handleEvent in class Widget
Parameters:
evt - the event
Returns:
always returns true
See Also:
Widget.setFocusKeyEnabled(boolean), Widget.handleKeyStrokeAction(java.lang.String, de.matthiasmann.twl.Event), Widget.setInputMap(de.matthiasmann.twl.InputMap)

handleEventPopup

protected boolean handleEventPopup(Event evt)
This method can be overriden to customize the event handling of a pop-up window.

The default implementation calls Widget.handleEvent(de.matthiasmann.twl.Event)

Parameters:
evt - the event
Returns:
true if the event has been handled, false otherwise.

isMouseInside

protected final boolean isMouseInside(Event evt)
Description copied from class: Widget
Checks whether the mouse is inside the widget or not.

Calls Widget.isInside(int, int) with the mouse coordinates.

Overrides:
isMouseInside in class Widget
Parameters:
evt - the mouse event
Returns:
true if the widgets wants to claim this mouse event

requestPopupClose

protected void requestPopupClose()
Called when escape if pressed and closeOnEscape is enabled. Also called by the default implementation of mouseClickedOutside when closeOnClickedOutside is active.

By default it calls closePopup() except when a setRequestCloseCallback(java.lang.Runnable) had been set.

See Also:
setCloseOnEscape(boolean), mouseClickedOutside(de.matthiasmann.twl.Event)

mouseClickedOutside

protected void mouseClickedOutside(Event evt)
Called when a mouse click happened outside the pop-up window area. The default implementation calls requestPopupClose when closeOnClickedOutside is active.

Parameters:
evt - The click event
See Also:
setCloseOnClickedOutside(boolean)

escapePressed

protected void escapePressed(Event evt)
Called when the escape key was pressed. The default implementation calls requestPopupClose when closeOnEscape is active.

Parameters:
evt - The click event
See Also:
setCloseOnEscape(boolean)