QJCC homepage

biz.chitec.quarterback.swing
Class DesktopFrameSelector

java.lang.Object
  extended bybiz.chitec.quarterback.swing.DesktopFrameSelector

public class DesktopFrameSelector
extends java.lang.Object

General keyboard-based sector for internal frames of a desktop pane. This class emulates the keyboard-based frame selection dialogs of the usual desktop environments. It is attached to a JDesktopPane and will, as soon as its activation key stroke is pressed, show a small popup menu with all internal frames' names shown. If one of the frames' names is clicked, that frame is made active.

Almost always you will only have one instance of DesktopFrameSelector in your program. If you do not plan to make the key stroke configurable, you can instanciate the selector once and then forget about it.

Version:
$Id: d4083a4e83e248bb7145216439a8ee6060e9b6c1 $
Author:
cantamen/Dirk Hillbrecht 2007. Released under LGPL or GPL+library exception

Nested Class Summary
private static class DesktopFrameSelector.FrameAction
          Action for the menu items of the popup menu.
 
Field Summary
private  javax.swing.JDesktopPane desktoppane
           
private  javax.swing.KeyStroke keystroke
           
private  java.lang.Object oldaction
           
private  SelectableJPopupMenu pm
           
 
Constructor Summary
DesktopFrameSelector(javax.swing.JDesktopPane desktoppanex)
          Initialize a frame selector for a desktop pane.
DesktopFrameSelector(javax.swing.JDesktopPane desktoppanex, javax.swing.KeyStroke keystrokex)
          Initialize a frame selector for a desktop pane and with an activation key stroke.
 
Method Summary
private  java.util.List getFrameActions()
          Return the list of frame actions needed for the frames in the desktop pane.
 void populateJMenu(javax.swing.JMenu jm)
          Populates the given JMenu with the frame action entries.
 void setKeyStroke(javax.swing.KeyStroke keystrokex)
          Set or change the activation key stroke for the selector.
private  void showPopupMenu()
          Show the popup menu with the selection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

desktoppane

private javax.swing.JDesktopPane desktoppane

pm

private SelectableJPopupMenu pm

keystroke

private javax.swing.KeyStroke keystroke

oldaction

private java.lang.Object oldaction
Constructor Detail

DesktopFrameSelector

public DesktopFrameSelector(javax.swing.JDesktopPane desktoppanex,
                            javax.swing.KeyStroke keystrokex)
Initialize a frame selector for a desktop pane and with an activation key stroke. The selector is initialized but unshown. It will be activated if the given key stroke is detected.

Parameters:
desktoppanex - Desktop pane to prepare the selection for
keystrokex - Key stroke to activate the selector with

DesktopFrameSelector

public DesktopFrameSelector(javax.swing.JDesktopPane desktoppanex)
Initialize a frame selector for a desktop pane. The selector is initialized but unshown. It cannot be activated until setKeyStroke(KeyStroke) has been called and the activation key stroke has been set. Use this constructor if you want to define the key stroke independently from the instance creation.

Parameters:
desktoppanex - Desktop pane to prepare the selection for
Method Detail

setKeyStroke

public void setKeyStroke(javax.swing.KeyStroke keystrokex)
Set or change the activation key stroke for the selector. Use this method to set the key stroke independently from instantiation or to change the key stroke. Setting the key stroke means potentially overwriting an input map entry. If you change the key stroke, the old mapping of the old setting will be restored.

Parameters:
keystrokex - Activation key stroke or null if the selector should be not activateable

getFrameActions

private java.util.List getFrameActions()
Return the list of frame actions needed for the frames in the desktop pane. If less than two windows are in the list, return an empty list. Never returns null.

Returns:
List of FrameActions to activate the windows. Empty if less than two frames. Never null!

showPopupMenu

private void showPopupMenu()
Show the popup menu with the selection. Three-stage: (1) get frames, titles and sort them alphabetically, (2) populate internal JPopupMenu, (3) show menu and make currently selected window the selected item in the menu. Last one is tricky and can only be performed with a SelectableJPopupMenu:


populateJMenu

public void populateJMenu(javax.swing.JMenu jm)
Populates the given JMenu with the frame action entries. If there are less than two windows, the menu is left empty.

Parameters:
jm - Menu to put actions in. All current entries are removed.

QJCC homepage