All Methods
zio package

context

zio
Class ZPicture


java.lang.Object

  extended byzio.ZObject

      extended byzio.ZPicture


public class ZPicture
extends ZObject

A program writeable image area. Images written after the window has been constructed will be cropped if they are larger than the existing area.

If a size() suffix is used, that will be the size. If a minSize() suffix is used an initial image must also be given and the size will be formed from the largest dimensions available.

It is an error to provide no size guidance at setup time. An initial image (obtained by using showImage() as if it were a suffix) is sufficient.

There is a mechanism for responding to mouse clicks and knowing where on the image the mouse click was performed. See the action method.

Sample use

 ZPicture pic = 
    new ZPicture().showImage(InOut.readImage("MyPicture.jpg") );
 

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

Constructor Summary
ZPicture()
          Creates a ZPicture with no image..
 
Method Summary
protected  void action(boolean isLeftButton, java.awt.Point point)
          For execution when user clicks the mouse over the picture.
 ZPicture 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.
 ZPicture expandH()
          Suffix that enables horizontal stretching.
 ZPicture expandV()
          Suffix that enables vertical stretching.
 ZPicture minSize(java.awt.Dimension minSize)
          Suffix that sets the minimum size.
 ZPicture showImage(java.awt.image.BufferedImage image)
          Display a picture.
 ZPicture size(java.awt.Dimension desiredSize)
          Suffix that sets the 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

ZPicture


public ZPicture()
Creates a ZPicture with no image..

Method Detail

debug


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

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

minSize


public final ZPicture minSize(java.awt.Dimension minSize)
Suffix that sets the minimum size. With this suffix the size of an image is obtained by comparing the dimensions set here with those of the initial image, if any. The larger dimensions will be chosen.

Parameters:
minSize - the desired minimum size

size


public final ZPicture size(java.awt.Dimension desiredSize)
Suffix that sets the size. This suffix fixes the amount of screen real estate that the ZPicture object will fill. This suffix overrides any other size determiner.

Parameters:
desiredSize - the desired minimum size

expandH


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


expandV


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


showImage


public final ZPicture showImage(java.awt.image.BufferedImage image)
Display a picture. If used as a suffix, the image given here will be a size determiner. If used after window setup, the image will be cropped, if necessary, to fit within the existing (possibly stretched) area.

Parameters:
image - the image to be displayed

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 picture. 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