com.tecnick.jwtm
Class ConnectorButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by com.tecnick.jwtm.ConnectorButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class ConnectorButton
extends java.awt.Panel

Title: ConnectorButton Class

Description: Class to create image buttons and behaviour for tree connector


Copyright (c) 2002-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
Project homepage: http://jxhtmledit.sourceforge.net
License: http://www.gnu.org/copyleft/gpl.html GPL 2

Version:
1.1.003
Author:
Nicola Asuni [www.tecnick.com].
See Also:
Serialized Form

Nested Class Summary
(package private)  class ConnectorButton.connectorButtonMouseAdapter
          Inner class for handling mouse events.
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String actionCommand
          action command to be returned to the listener
protected  java.awt.event.ActionListener actionListener
          the action listener (for events)
private  java.applet.AudioClip audio_click
          audio clip for button click event
private  java.applet.AudioClip audio_over
          audio clip for mouse over event
private  int bh
          height of background image in pixels
static int BOTTOM
          constant BOTTOM
private  java.awt.Graphics bufferGraphics
          graphics for double buffering
private  int bw
          width of background image in pixels
static int CENTER
          constant CENTER
private  java.awt.Color col_off_bck
          background color for mouse-off state
private  java.awt.Color col_off_line
          line color for mouse-off state
private  java.awt.Color col_on_bck
          background color for mouse-on state
private  java.awt.Color col_on_line
          line color for mouse-on state
private  java.awt.Color col_over_bck
          background color for mouse-over state
private  java.awt.Color col_over_line
          line color for mouse-over state
private  int connector_height
          connector height (must be equal to button height)
private  int connector_min_width
          connector block minimum width
private  boolean connector_opened
          true if element is a closed node
private  int connector_width
          connector final width
private  int connectorID
          menu item id to be returned on event as actionCommand
private  int current_action
          current button action to send to listener -1 means no action
private  int direction
          connector direction (right = left-to-right)
private  int first_line_x
          first connector line position
private  boolean first_node
          true if element is a first node
private  int h_line_lenght
          horizontal line lenght
private  int h_line_y
          first connector line position
private  int ih
          height of internal button icon image in pixels
private  float imageScale
          float parameter to scale the image size
private  java.awt.Image img
          current button icon
private  java.awt.Image img_bg
          current background button image
private  java.awt.Image img_bg_off
          button background image for normal state
private  java.awt.Image img_bg_on
          button background image for button pressed
private  java.awt.Image img_bg_over
          button background image for mouse over
private  java.awt.Image img_off
          button icon for normal state
private  java.awt.Image img_on
          button icon for button pressed
private  java.awt.Image img_over
          button icon for mouse over
private  int item_level
          node level
private  int iw
          width of internal button icon image in pixels
private  int ix
          horizontal position of internal button icon image
private  int iy
          vertical position of internal button icon image
private  boolean last_node
          true if element is a last node
static int LEFT
          constant LEFT
private  int line_width
          connector line width in pixels (0 = no line)
private  java.awt.Image offscreen
          offscreen image to handle double buffering
static int RIGHT
          constant RIGHT
private static long serialVersionUID
          serialVersionUID
static int TOP
          constant TOP
private  int v_line_lenght
          vertical line lenght
private  boolean[] vertical_connector
          connector height (same as button height)
 
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
ConnectorButton(int w, int h, int lw, int l, boolean isnode, boolean f, boolean n, boolean[] dvc)
          Build a clickable connector for the menu tree.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          Adds the specified action listener to receive action events from this button.
 void addNotify()
          Creates the Panel's peer.
protected  void connectorButton_Closed(boolean sound_on)
          Gets called when the mouse crosses out of the button area.
protected  void connectorButton_MouseOver(boolean sound_on)
          Gets called when the mouse crosses into the button area.
protected  void connectorButton_Opened(boolean sound_on)
          Gets called when the mouse button is pressed.
protected  void fireActionEvent(int actiontype)
          Fire an action event to the listeners.
 java.lang.String getActionCommand()
          Returns the command name of the action event fired by this button.
 int getConnectorID()
          Get connectorID (unique numeric identifier for current component)
 boolean getNodeStatus()
          Get the current node status.
 void paint(java.awt.Graphics g)
          Draw button elements (border, image and label) at calculated positions.
 void removeActionListener(java.awt.event.ActionListener l)
          Removes the specified action listener so it no longer receives action events from this button.
 void resize()
          Set button size and images coordinates.
 void setActionCommand(java.lang.String command)
          Sets the command name of the action event fired by this button.
 void setAudioStateClips(java.applet.AudioClip a, java.applet.AudioClip b)
          Set the audio clip to play when the button is pushed.
 void setBgImage(java.awt.Image i)
          Set the current background image to be shown.
private  void setButtonComponents(java.applet.AudioClip sound, java.awt.Color foreground, java.awt.Color background, java.awt.Image bg, java.awt.Image icon)
          Set and repaint button components
 void setConnectorID(int id)
          Set connectorID (unique numeric identifier for current component)
 void setDirection(int a)
          Set the connector direction (left-to-right or right-to-left).
 void setEnable(boolean a)
          Enables or disables this component, depending on the value of the parameter b.
 void setImage(java.awt.Image i)
          Set the current image icon to be shown.
 void setImageScale(double f)
          Scale the image to the given value (1.0 = 100%).
 void setImageScale(float pct)
          Scale the image to the given value (1.0 = 100%).
 void setNodeStatus(boolean status)
          Set the current node status (open/closed)
 void setStateBgImages(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
          Set the background state images (one image for each button/mouse state).
 void setStateColors(java.awt.Color ba, java.awt.Color bb, java.awt.Color bc, java.awt.Color la, java.awt.Color lb, java.awt.Color lc)
          Set the button colors for each state (mouse off/on/over)
 void setStateImages(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
          Set the state images (one image for each node/folder state)
 
Methods inherited from class java.awt.Panel
getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serialVersionUID

See Also:
Constant Field Values

bufferGraphics

private java.awt.Graphics bufferGraphics
graphics for double buffering


offscreen

private java.awt.Image offscreen
offscreen image to handle double buffering


actionCommand

protected java.lang.String actionCommand
action command to be returned to the listener


actionListener

protected java.awt.event.ActionListener actionListener
the action listener (for events)


connectorID

private int connectorID
menu item id to be returned on event as actionCommand


LEFT

public static final int LEFT
constant LEFT

See Also:
Constant Field Values

TOP

public static final int TOP
constant TOP

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
constant RIGHT

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
constant BOTTOM

See Also:
Constant Field Values

CENTER

public static final int CENTER
constant CENTER

See Also:
Constant Field Values

img

private java.awt.Image img
current button icon


img_off

private java.awt.Image img_off
button icon for normal state


img_on

private java.awt.Image img_on
button icon for button pressed


img_over

private java.awt.Image img_over
button icon for mouse over


img_bg

private java.awt.Image img_bg
current background button image


img_bg_off

private java.awt.Image img_bg_off
button background image for normal state


img_bg_on

private java.awt.Image img_bg_on
button background image for button pressed


img_bg_over

private java.awt.Image img_bg_over
button background image for mouse over


imageScale

private float imageScale
float parameter to scale the image size


audio_click

private java.applet.AudioClip audio_click
audio clip for button click event


audio_over

private java.applet.AudioClip audio_over
audio clip for mouse over event


direction

private int direction
connector direction (right = left-to-right)


ix

private int ix
horizontal position of internal button icon image


iy

private int iy
vertical position of internal button icon image


iw

private int iw
width of internal button icon image in pixels


ih

private int ih
height of internal button icon image in pixels


bw

private int bw
width of background image in pixels


bh

private int bh
height of background image in pixels


col_off_bck

private java.awt.Color col_off_bck
background color for mouse-off state


col_over_bck

private java.awt.Color col_over_bck
background color for mouse-over state


col_on_bck

private java.awt.Color col_on_bck
background color for mouse-on state


col_off_line

private java.awt.Color col_off_line
line color for mouse-off state


col_over_line

private java.awt.Color col_over_line
line color for mouse-over state


col_on_line

private java.awt.Color col_on_line
line color for mouse-on state


line_width

private int line_width
connector line width in pixels (0 = no line)


connector_min_width

private int connector_min_width
connector block minimum width


connector_width

private int connector_width
connector final width


connector_height

private int connector_height
connector height (must be equal to button height)


vertical_connector

private boolean[] vertical_connector
connector height (same as button height)


item_level

private int item_level
node level


first_node

private boolean first_node
true if element is a first node


last_node

private boolean last_node
true if element is a last node


connector_opened

private boolean connector_opened
true if element is a closed node


first_line_x

private int first_line_x
first connector line position


h_line_y

private int h_line_y
first connector line position


h_line_lenght

private int h_line_lenght
horizontal line lenght


v_line_lenght

private int v_line_lenght
vertical line lenght


current_action

private int current_action
current button action to send to listener -1 means no action

Constructor Detail

ConnectorButton

public ConnectorButton(int w,
                       int h,
                       int lw,
                       int l,
                       boolean isnode,
                       boolean f,
                       boolean n,
                       boolean[] dvc)
Build a clickable connector for the menu tree.

Parameters:
w - connector minimum width
h - connector height (same as button height)
lw - connector line width in pixels (0 = no line)
l - item level (indentation level)
isnode - true if it's a node
f - true if is the first element
n - true if element is a last node
dvc - array of vertical connectors to display
Method Detail

addNotify

public void addNotify()
Creates the Panel's peer. The peer allows you to modify the appearance of the panel without changing its functionality.

Overrides:
addNotify in class java.awt.Panel

setStateColors

public void setStateColors(java.awt.Color ba,
                           java.awt.Color bb,
                           java.awt.Color bc,
                           java.awt.Color la,
                           java.awt.Color lb,
                           java.awt.Color lc)
Set the button colors for each state (mouse off/on/over)

Parameters:
ba - background button color when mouse is off
bb - background button color when mouse is over
bc - background button color when button is clicked
la - foreground line color when mouse is off
lb - foreground line color when mouse is over
lc - foreground line color when button is clicked

setConnectorID

public void setConnectorID(int id)
Set connectorID (unique numeric identifier for current component)

Parameters:
id - button ID

getConnectorID

public int getConnectorID()
Get connectorID (unique numeric identifier for current component)

Returns:
connectorID

getNodeStatus

public boolean getNodeStatus()
Get the current node status.

Returns:
status Current Status (true = closed; false = opened)

setNodeStatus

public void setNodeStatus(boolean status)
Set the current node status (open/closed)

Parameters:
status - New status (true = closed; false = opened).

setDirection

public void setDirection(int a)
Set the connector direction (left-to-right or right-to-left).

Parameters:
a - TOP, LEFT, RIGHT or BOTTOM

setAudioStateClips

public void setAudioStateClips(java.applet.AudioClip a,
                               java.applet.AudioClip b)
Set the audio clip to play when the button is pushed.

Parameters:
a - audio clip when button is clicked
b - audio clip when mouse is over

setStateImages

public void setStateImages(java.awt.Image imgoff,
                           java.awt.Image imgon,
                           java.awt.Image imgover)
Set the state images (one image for each node/folder state)

Parameters:
imgoff - button icon image when mouse is off
imgon - button icon image when button is pressed
imgover - button icon image when mouse is off

setStateBgImages

public void setStateBgImages(java.awt.Image imgoff,
                             java.awt.Image imgon,
                             java.awt.Image imgover)
Set the background state images (one image for each button/mouse state).

Parameters:
imgoff - button background image when mouse is off
imgon - button background image when button is pressed
imgover - button background image when mouse is off

setImage

public void setImage(java.awt.Image i)
Set the current image icon to be shown.

Parameters:
i - Button Image

setBgImage

public void setBgImage(java.awt.Image i)
Set the current background image to be shown.

Parameters:
i - Button Background Image

setImageScale

public void setImageScale(double f)
Scale the image to the given value (1.0 = 100%).

Parameters:
f - float

setImageScale

public void setImageScale(float pct)
Scale the image to the given value (1.0 = 100%).

Parameters:
pct - float

setEnable

public void setEnable(boolean a)
Enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Parameters:
a - If true, this component is enabled; otherwise this component is disabled

resize

public void resize()
Set button size and images coordinates.


paint

public void paint(java.awt.Graphics g)
Draw button elements (border, image and label) at calculated positions.

Overrides:
paint in class java.awt.Container
Parameters:
g - the graphic area when diplay button elements

setActionCommand

public void setActionCommand(java.lang.String command)
Sets the command name of the action event fired by this button.

Parameters:
command - The name of the action event command fired by this button

getActionCommand

public java.lang.String getActionCommand()
Returns the command name of the action event fired by this button.

Returns:
the action command name

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this button.

Parameters:
l - the action listener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so it no longer receives action events from this button.

Parameters:
l - the action listener

fireActionEvent

protected void fireActionEvent(int actiontype)
Fire an action event to the listeners.

Parameters:
actiontype - ActionEvent.ACTION_PERFORMED

connectorButton_Opened

protected void connectorButton_Opened(boolean sound_on)
Gets called when the mouse button is pressed. Repaint button setting images and colors.

Parameters:
sound_on - boolean to turn off sound

connectorButton_MouseOver

protected void connectorButton_MouseOver(boolean sound_on)
Gets called when the mouse crosses into the button area. Repaint button setting images and colors.

Parameters:
sound_on - boolean to turn off sound

connectorButton_Closed

protected void connectorButton_Closed(boolean sound_on)
Gets called when the mouse crosses out of the button area. Repaint button setting images and colors.

Parameters:
sound_on - boolean to turn off sound

setButtonComponents

private void setButtonComponents(java.applet.AudioClip sound,
                                 java.awt.Color foreground,
                                 java.awt.Color background,
                                 java.awt.Image bg,
                                 java.awt.Image icon)
Set and repaint button components

Parameters:
sound - audioclip to play
foreground - foreground color
background - background color
bg - background image
icon - image icon