guk.editIM
Class MenuHelpers

java.lang.Object
  |
  +--guk.editIM.MenuHelpers

public class MenuHelpers
extends java.lang.Object

MenuHelpers.java in guk.editIM: Simplify creation of buttons, menu items, checkboxes... Other menu related tasks.


Field Summary
(package private)  java.awt.event.ActionListener ACTIONLISTENER
          The action listener that will receive all events from menu elements generated by this class.
(package private)  java.awt.Component baseWin
          The component relative to which centerMe will center things.
(package private)  boolean REALLYDISPATCH
          Going through the event queue is broken.
(package private)  java.awt.Font theFont
          The font which is used by the setSyncFont and syncFont methods.
 
Constructor Summary
MenuHelpers(java.awt.event.ActionListener listener)
          Tell the constructor what the action listener should be.
 
Method Summary
 void centerMe(java.awt.Component compo)
          Centers the given component relative to the baseWin component.
static void fixSize(javax.swing.JComponent compo, java.awt.Dimension size)
          Force minimum, maximum and preferred size of a component to a certain value.
 java.awt.Component getBaseWin()
          Ask for the current centering base component.
 java.awt.event.ActionListener getListener()
          Retrieve the current action listener value.
 javax.swing.JButton glyphXButton(java.lang.String label, java.lang.String tooltip, java.lang.String command)
          Helper to create a mini button for special glyph functions with all settings in one go.
static java.awt.Color hueByHash(java.awt.Color c, int hash, float offs)
          Helper method: modify hue in HSB color space by some function of hash and by offset offs.
(package private)  javax.swing.JButton myJButton(java.lang.String label, int mnemonic, java.lang.String tooltip, java.lang.String command)
          Helper to create a JButton with all settings in one go.
 javax.swing.JMenuItem myJMenuItem(java.lang.String what, java.lang.String label, int mnemonic, java.lang.String tooltip, java.lang.String command)
          Generic creation of box, item or menu type menu items.
(package private)  void posting(java.lang.Object target, java.lang.Object event)
          Dispatches either by dispatchEvent or by calling actionPerformed directly if dispatchEvent is not available.
 void setBaseWin(java.awt.Component compo)
          Enable the centering functionality.
 void setListener(java.awt.event.ActionListener listener)
          Use a new action listener in the future.
 void setSyncFont(java.awt.Font font)
          Set up the font parameter for font syncing.
 void syncFont(java.awt.Component compo)
          Sync the font used by the given component: Set it to the font selected by setSyncFont.
 void tellListener(java.awt.event.ActionListener whom, java.awt.event.ActionEvent what)
          Dispatch event to ANOTHER listener, using a given ActionEvent.
 void tellListener(java.awt.event.ActionListener whom, java.lang.String what)
          Dispatch event to ANOTHER listener, giving it a new ActionEvent (with id ACTION_PERFORMED) with the specified message.
 void tellListener(java.lang.String what)
          Dispatch event to our listener, giving it a new ActionEvent (with id ACTION_PERFORMED) with the specified message.
static java.lang.String toHex(int value)
          Convert an int value into an hex String of a length which is a multiple of 4.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

REALLYDISPATCH

final boolean REALLYDISPATCH
Going through the event queue is broken. After fixing it, enable it here.

ACTIONLISTENER

java.awt.event.ActionListener ACTIONLISTENER
The action listener that will receive all events from menu elements generated by this class.

theFont

java.awt.Font theFont
The font which is used by the setSyncFont and syncFont methods.

baseWin

java.awt.Component baseWin
The component relative to which centerMe will center things.
Constructor Detail

MenuHelpers

public MenuHelpers(java.awt.event.ActionListener listener)
Tell the constructor what the action listener should be.
Parameters:
listener - The action listener that will receive all events from menu elements generated by this class.
Method Detail

setListener

public void setListener(java.awt.event.ActionListener listener)
Use a new action listener in the future.
Parameters:
listener - The action listener that will receive all events from menu elements generated here in the future.

getListener

public java.awt.event.ActionListener getListener()
Retrieve the current action listener value.
Returns:
The action listener that receives all events from menu elements generated by this class.

posting

void posting(java.lang.Object target,
             java.lang.Object event)
Dispatches either by dispatchEvent or by calling actionPerformed directly if dispatchEvent is not available. The former is better as it does not mess with the queueing and timeline.
Parameters:
target - The target, a Component or at least an ActionListener.
event - An ActionEvent (not AWTevent) or command String to be sent.

tellListener

public void tellListener(java.lang.String what)
Dispatch event to our listener, giving it a new ActionEvent (with id ACTION_PERFORMED) with the specified message.
Parameters:
The - string that will be used to generate the sent action event.

tellListener

public void tellListener(java.awt.event.ActionListener whom,
                         java.lang.String what)
Dispatch event to ANOTHER listener, giving it a new ActionEvent (with id ACTION_PERFORMED) with the specified message.
Parameters:
whom - The listener that should be notified.
what - The string that will be used to generate the sent action event.

tellListener

public void tellListener(java.awt.event.ActionListener whom,
                         java.awt.event.ActionEvent what)
Dispatch event to ANOTHER listener, using a given ActionEvent.
Parameters:
whom - The listener that should be notified.
what - The ActionEvent to be sent.

setBaseWin

public void setBaseWin(java.awt.Component compo)
Enable the centering functionality.
Parameters:
compo - The component relative to which centerMe will center things

getBaseWin

public java.awt.Component getBaseWin()
Ask for the current centering base component.
Returns:
compo The component relative to which centerMe will center things

setSyncFont

public void setSyncFont(java.awt.Font font)
Set up the font parameter for font syncing.
Parameters:
font - An arbitrary font.

syncFont

public void syncFont(java.awt.Component compo)
Sync the font used by the given component: Set it to the font selected by setSyncFont.
Parameters:
compo - A component that you want to use the font selected by setSyncFont.

myJMenuItem

public javax.swing.JMenuItem myJMenuItem(java.lang.String what,
                                         java.lang.String label,
                                         int mnemonic,
                                         java.lang.String tooltip,
                                         java.lang.String command)
Generic creation of box, item or menu type menu items. Helper to create a JMenuItem or JCheckBoxMenuItem or JMenu, with all settings in one go. Values for what: box, item, or menu. The action listener is always ACTIONLISTENER. Initially, input methods are disabled for the component.
Parameters:
what - can be "box", "item" or "menu" to select what type of item (JCheckBoxMenuItem, JMenuItem, JMenu) we need.
label - The text for the item. If null, a default is used.
mnemonic - The key code that should be used as mnemonic. Use -1 to indicate no mnemonic.
tooltip - The tool tip text, if any (null otherwise).
command - The action command that should be used. For a menu, null should be used here.

glyphXButton

public javax.swing.JButton glyphXButton(java.lang.String label,
                                        java.lang.String tooltip,
                                        java.lang.String command)
Helper to create a mini button for special glyph functions with all settings in one go. The action listener is always ACTIONLISTENER. Initially, input methods are disabled for the component.
Parameters:
label - The text that the button should show
tooltip - The tool tip for the button
command - the action command for the button.

myJButton

javax.swing.JButton myJButton(java.lang.String label,
                              int mnemonic,
                              java.lang.String tooltip,
                              java.lang.String command)
Helper to create a JButton with all settings in one go. Input Methods will be initially disabled. The action listener is always ACTIONLISTENER.
Parameters:
label - The text for the item. If null, a default is used.
mnemonic - The key code that should be used as mnemonic. Use -1 to indicate no mnemonic.
tooltip - The tool tip text, if any (null otherwise).
command - The action command that should be used.

fixSize

public static void fixSize(javax.swing.JComponent compo,
                           java.awt.Dimension size)
Force minimum, maximum and preferred size of a component to a certain value.
Parameters:
compo - The component that will have the size hints changed.
size - The new value for the size hints.

toHex

public static java.lang.String toHex(int value)
Convert an int value into an hex String of a length which is a multiple of 4.
Parameters:
value - An integer value, preferrably 0..65535
Returns:
A string representation of the argument, which will be a multiple of 4 characters long and hexadecimal.

centerMe

public void centerMe(java.awt.Component compo)
Centers the given component relative to the baseWin component. Use setBaseWin() to set the baseWin value.
Parameters:
compo - A component that should be centered relative to the component given to setBaseWin() (if none is known, nothing will happen).

hueByHash

public static java.awt.Color hueByHash(java.awt.Color c,
                                       int hash,
                                       float offs)
Helper method: modify hue in HSB color space by some function of hash and by offset offs.
Parameters:
c - input color, will be somewhat trimmed
hash - arbitrary integer as seed for the hue modification
offs - offset to the hue