org.merlotxml.merlot
Class SizeableJPopupMenuByHeight

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPopupMenu
                  extended byorg.merlotxml.merlot.SizeableJPopupMenuByHeight
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.MenuElement, java.io.Serializable

public class SizeableJPopupMenuByHeight
extends javax.swing.JPopupMenu

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPopupMenu
javax.swing.JPopupMenu.AccessibleJPopupMenu, javax.swing.JPopupMenu.Separator
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  double maximumHeight
          The maximum number height allowed in a menu
static java.lang.String MORE
          More Menu Text - makes changing text easier later
protected  double myHeight
          Manually keep track of height - getPreferredSize/getSize seems to only work properly after the menu has been dispayed at least once.
static int TASKBAR_HEIGHT
          Take into account most window managers have a task or system bar always on top on the bottom of the screen.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SizeableJPopupMenuByHeight()
           
SizeableJPopupMenuByHeight(java.lang.String label)
           
 
Method Summary
 javax.swing.JMenuItem add(javax.swing.Action a)
          TEMPORARY - Move to State model once you get height algorithm working Differences between JMenu and JPopup menu make the algorithm somewhat tempermental and a bit unpredictable.
 javax.swing.JMenuItem add(javax.swing.JMenuItem menuItem)
          Override the JPopupMenu functionality, try to provide illusion of a single menu.
 javax.swing.JMenuItem add(java.lang.String string)
          Override the JPopupMenu functionality ....
 void addSeparator()
          Override the JPopup Menu
 void finalize()
          Additional work needed to finalize and free up memory.
 java.util.Vector getAllSubComponents()
          Get all Components **MINUS THE MORE BUTTONS** Use vectors, they are easier to work with when working with heavily dynamic stuff.
 java.awt.Component getComponentAtIndex(int i)
          Override the JPopupMenu functionality
 int getComponentIndex(java.awt.Component c)
          Override the JPopupMenu functionality
 JMoreMenu getMoreMenu()
          Convenience helper - get one of the sub-menus if you want to manipulate it directly (For Example - insert a static item.)
 javax.swing.MenuElement[] getSubElements()
          Override the JPopupMenu functionality
 void insert(javax.swing.Action a, int index)
          Override the JPopupMenu functionality NOTE - CODE A MUCH MORE COMPLEX THAN I WOULD LIKE.
 void insert(java.awt.Component c, int index)
          Override the JPopupMenu functionality
 void insert(java.lang.String string, int index)
          Convenience method.
 void insertStatic(java.awt.Component c)
          Used to forcibly insert items at the end of the primary menu.
 void remove(java.awt.Component c)
          Override the JPopupMenu functionality.
 void remove(int pos)
          Override the JPopupMenu functionality For simplicities sake, do not reshuffle menu for now.
 void removeAll()
          Override JPopupMenu functionality.
 void setBorderPainted(boolean b)
          Override the JPopupMenu functionality
 void setMaximumHeight(double aHeight)
          Set the maximum height of this menu
 void setSelected(java.awt.Component c)
          Override the JPopupMenu functionality
 void show(java.awt.Component invoker, int x, int y)
          Show - Over the JPopupMenu functionality - try to guard against menu going off the screen.
 int SizeableGetItemCount()
          I ran out of ideas on how to get it to be invisible, so I added some little helpers.
 
Methods inherited from class javax.swing.JPopupMenu
addPopupMenuListener, createActionChangeListener, createActionComponent, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getComponent, getDefaultLightWeightPopupEnabled, getInvoker, getLabel, getMargin, getPopupMenuListeners, getSelectionModel, getUI, getUIClassID, isBorderPainted, isLightWeightPopupEnabled, isPopupTrigger, isVisible, menuSelectionChanged, pack, paintBorder, paramString, processFocusEvent, processKeyEvent, processKeyEvent, processMouseEvent, removePopupMenuListener, setDefaultLightWeightPopupEnabled, setInvoker, setLabel, setLightWeightPopupEnabled, setLocation, setPopupSize, setPopupSize, setSelectionModel, setUI, setVisible, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TASKBAR_HEIGHT

public static final int TASKBAR_HEIGHT
Take into account most window managers have a task or system bar always on top on the bottom of the screen. Empirically determined value.

See Also:
Constant Field Values

MORE

public static final java.lang.String MORE
More Menu Text - makes changing text easier later

See Also:
Constant Field Values

myHeight

protected double myHeight
Manually keep track of height - getPreferredSize/getSize seems to only work properly after the menu has been dispayed at least once.


maximumHeight

protected double maximumHeight
The maximum number height allowed in a menu

Constructor Detail

SizeableJPopupMenuByHeight

public SizeableJPopupMenuByHeight()

SizeableJPopupMenuByHeight

public SizeableJPopupMenuByHeight(java.lang.String label)
Method Detail

finalize

public void finalize()
Additional work needed to finalize and free up memory.


add

public javax.swing.JMenuItem add(javax.swing.Action a)
TEMPORARY - Move to State model once you get height algorithm working Differences between JMenu and JPopup menu make the algorithm somewhat tempermental and a bit unpredictable. Move into a STATE pattern with message forwarding once you get the algorithm working.


add

public javax.swing.JMenuItem add(javax.swing.JMenuItem menuItem)
Override the JPopupMenu functionality, try to provide illusion of a single menu. TEMPORARY - Two methods are temporary, move to a STATE pattern once you get the height algorithm working.


add

public javax.swing.JMenuItem add(java.lang.String string)
Override the JPopupMenu functionality .... same disclaimer as above


addSeparator

public void addSeparator()
Override the JPopup Menu


getComponentIndex

public int getComponentIndex(java.awt.Component c)
Override the JPopupMenu functionality


getComponentAtIndex

public java.awt.Component getComponentAtIndex(int i)
Override the JPopupMenu functionality


getSubElements

public javax.swing.MenuElement[] getSubElements()
Override the JPopupMenu functionality


insert

public void insert(javax.swing.Action a,
                   int index)
Override the JPopupMenu functionality NOTE - CODE A MUCH MORE COMPLEX THAN I WOULD LIKE. CONTINUE TO SEARCH FOR A BETTER WAY TO INTEGRATE JPOPUPMENU AND JMENU. The subtle differences between the two is what made this code a nightmare to code up and debug!!!!


insert

public void insert(java.awt.Component c,
                   int index)
Override the JPopupMenu functionality


insert

public void insert(java.lang.String string,
                   int index)
Convenience method. JPopupMenu does not have a insert(String) however, it makes things very convenient


remove

public void remove(java.awt.Component c)
Override the JPopupMenu functionality. For simplicity, do not reshuffle the menu item for now. Remove is not used as often as add/insert.


remove

public void remove(int pos)
Override the JPopupMenu functionality For simplicities sake, do not reshuffle menu for now. Remove is not used as often as add/insert algorithms


removeAll

public void removeAll()
Override JPopupMenu functionality. Take into account aut


getAllSubComponents

public java.util.Vector getAllSubComponents()
Get all Components **MINUS THE MORE BUTTONS** Use vectors, they are easier to work with when working with heavily dynamic stuff.


show

public void show(java.awt.Component invoker,
                 int x,
                 int y)
Show - Over the JPopupMenu functionality - try to guard against menu going off the screen. If the max Height is larger than screen area however, we're fried, set the menu size smaller. WARNING - The code here is not very complex, but a bit deceiving Getting this code **CORRECT** is a lot tricker than it looks, primarily due to the fact you don't have easy access to the internal co-ordinate system and associated maniuplation routines. In addition, the getPreferredSize call doesn't seem to work properly until the menu has been displayed at least once. If you don't believe, uncomment out the System.out.println calls and watch what happens (left in for debugging later). Most of this code is work-around of known problems in Swing with a couple of sequence dependent items. (must be called at the appropriate time). When making mods, proceed with MUCH CAUTION!.


setSelected

public void setSelected(java.awt.Component c)
Override the JPopupMenu functionality


setBorderPainted

public void setBorderPainted(boolean b)
Override the JPopupMenu functionality


SizeableGetItemCount

public int SizeableGetItemCount()
I ran out of ideas on how to get it to be invisible, so I added some little helpers. Get Item count but do not include the automatically created more menus. I could not get the getComponentCount to work transparently.


setMaximumHeight

public void setMaximumHeight(double aHeight)
Set the maximum height of this menu


getMoreMenu

public JMoreMenu getMoreMenu()
Convenience helper - get one of the sub-menus if you want to manipulate it directly (For Example - insert a static item.)


insertStatic

public void insertStatic(java.awt.Component c)
Used to forcibly insert items at the end of the primary menu. Useful if you have items that you don't want who knows how many levels deep in the more structure.