All Methods
zio package

context

zio
Class ZBox


java.lang.Object

  extended byzio.ZObject

      extended byzio.ZBox


public class ZBox
extends ZObject

Use this class to make colored boxes which are optionally expandable. There is an action method which is invoked whenver there is a mouseclick over the box. Make a subclass and override this method if you want something interesting to happen then.

The actual Swing object that this class creates is a JPanel. Since you have direct access to that object (through the getJPanel() method) you can use this class for AWT drawings as well. In that case you must change either the background or the foreground color as, by default, they will be the same.

Some of your layouts may require you to have both an object and some space expand in the same slice. With normal use of ZRow and ZCol this would be impossible. With a box that is colored the same as the slice's background color, you can get around that restriction.

Do not put other Swing entities into the panel returned by getJPanel(). The ZRow, ZCol, and ZComponent methods are provided so that you can place other Swing objects into your window under a consistent layout management.

Version:
Jul 22, 2005
Author:
copyright 2005 by J Adrian Zimmer
Licensed under the Open Software License version 2.1
See Also:
Dimension , Color

Constructor Summary
ZBox()
          Creates a box By default, the width and length of this box are both one twelfth the height of the screen (measured in pixels) and the color is the same default color that is used to write text (usually black).
 
Method Summary
protected  void action(boolean isLeftButton, java.awt.Point point)
          For execution when user clicks the mouse over the ZBox.
 ZBox background(java.awt.Color c)
          Suffix that sets the background color.
 ZBox color(java.awt.Color c)
          Sets the background color of the ZBox.
 ZBox debug(java.lang.String debugId)
          Suffix that creates debug output.
protected  void enableMouseAction()
          Method for causing the action() method to be executed upon mouse clicks.
 ZBox expandH()
          Suffix that enables horizontal stretching.
 ZBox expandV()
          Suffix that enables vertical stretching.
 ZBox foreground(java.awt.Color c)
          Suffix that sets the foreground color.
 javax.swing.JPanel getJPanel()
          Get a reference to the underlying JPanel.
 ZBox size(java.awt.Dimension desiredSize)
          Suffix that overrides the default size.
 
Methods inherited from class zio.ZObject
getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZBox


public ZBox()
Creates a box By default, the width and length of this box are both one twelfth the height of the screen (measured in pixels) and the color is the same default color that is used to write text (usually black).

In Swing or AWT parlance, this implies the default background color of a box is the same as the default foreground color.

Method Detail

color


public final ZBox color(java.awt.Color c)
Sets the background color of the ZBox. Need not be used as a suffix but when it is used as a suffix the effect is the same as the background suffix

Parameters:
c - the desired color

foreground


public final ZBox foreground(java.awt.Color c)
Suffix that sets the foreground color. The foreground color is the color of any AWT generated drawing on the ZBox.

Parameters:
c - the desired foreground color

background


public final ZBox background(java.awt.Color c)
Suffix that sets the background color. The effect is identical to the color suffix.

Parameters:
c - the desired background color

size


public final ZBox size(java.awt.Dimension desiredSize)
Suffix that overrides the default size.

Parameters:
desiredSize - the desired size

expandH


public final ZBox expandH()
Suffix that enables horizontal stretching. Use this to allow your box to be streched in a horizontal direction when the user resizes your window.


expandV


public final ZBox expandV()
Suffix that enables vertical stretching. Use this to allow your box to be streched in a vertical direction when the user resizes your window.


debug


public final ZBox debug(java.lang.String debugId)
Suffix that creates debug output.

Parameters:
debugId - a string to identify this component in the debug output

getJPanel


public final javax.swing.JPanel getJPanel()
Get a reference to the underlying JPanel.

Returns:
the JPanel controlled by this object

enableMouseAction


protected void enableMouseAction()
Method for causing the action() method to be executed upon mouse clicks. Has no discernable effect unless the action() method is overridden in a subclass.


action


protected void action(boolean isLeftButton,
                      java.awt.Point point)
For execution when user clicks the mouse over the ZBox. In this base class the action() method does nothing and is not invoked.

To cause this method to be invoked whenever the user clicks the mouse,

  1. override the method in a subclass, and
  2. in the your subclass's constructor, execute enableMouseAction()
You can also execute suffixes inside this constructor rather than waiting for an object to be created. (When overriding a ZObject class, it is usually easier to use suffixes this way.)

The point passed to action() has the upper lefthand corner of the component as its origin. The y coordinate is positive in a downward direction.

Parameters:
isLeftButton - true when the clicked button was the left or "first" button
point - coordinates of the point where the left mouse button was released
See Also:
Point

author
context