org.johndavidtaylor.beans.beanpeeler
Class BeanPeeler

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byorg.johndavidtaylor.beans.beanpeeler.BeanPeeler
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.Serializable

public class BeanPeeler
extends java.awt.Frame
implements java.beans.PropertyChangeListener

Introspects a bean and allows customisation

BeanPeeler is a property sheet allowing you to customize javabeans. It's similar to the property sheets that you get in IDEs such as Netbeans' Forte that you use to customise components before you drop them onto a form. It examines a bean for any read/write properties and constructs a property sheet using dropdown boxes for properties such as booleans which have discrete values and textboxes for strings and numbers.

Usage:

MyBean mb = new MyBean();
BeanPeeler bp = new BeanPeeler(mb);
mb.addPropertyChangeListener(bp); //if appropriate
bp.show();

BeanPeeler bp2 = new BeanPeeler(mb, BeanPeeler.ENABLE_OK); //disable Cancel and apply buttons
bp2.showAndWait(); // if you want a modal dialog

Version:
1.2 removed the warning dialog and added a getError method - far less trouble, 1.1.1
Author:
JTAYLOR3
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
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
static int ENABLE_APPLY
          Show Apply button
static int ENABLE_CANCEL
          Show Cancel button
static int ENABLE_OK
          Show OK button
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
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
BeanPeeler(java.lang.Object bean)
          Constructs a new BeanPeeler to edit the given bean.
BeanPeeler(java.lang.Object bean, int options)
          Constructs a new BeanPeeler to edit the given bean.
 
Method Summary
 java.awt.Color getBackground()
          Getter for property background.
 java.lang.Object getBean()
          Getter for property bean.
 java.util.Vector getErrors()
          As properties are added to the sheet certain exceptions and warnings may arise.
 java.awt.Font getFont()
          Getter for property font.
 java.awt.Color getForeground()
          Getter for property foreground.
 java.lang.String getLastError()
          Returns the last warning posted when creating the dialog - @see getErrors()
 java.awt.Dimension getPaintAreaSize()
          Getter for property paintAreaSize.
 boolean getProcessNames()
           
 java.lang.String getTitle()
          Getter for property title.
 boolean isFollowInheritanceTree()
          Getter for property followInheritanceTree.
 boolean isVerbose()
          Getter for property verbose.
 void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent)
          The bean we're editing has changed....
 void setBackground(java.awt.Color background)
          Setter for property background.
 void setBean(java.lang.Object bean)
          Setter for property bean.
 void setFollowInheritanceTree(boolean followInheritanceTree)
          Setter for property followInheritanceTree.
 void setFont(java.awt.Font font)
          Setter for property font.
 void setForeground(java.awt.Color foreground)
          Setter for property foreground.
 void setPaintAreaSize(java.awt.Dimension paintAreaSize)
          Setter for property paintAreaSize.
 void setProcessNames(boolean processNames)
          Attempts to make the labels more attractive by parsing the names.
 void setTitle(java.lang.String title)
          Setter for property title.
 void setVerbose(boolean verbose)
          Setter for property verbose.
 void showAndWait()
          Use instead of Window.show() if you want a modal dialog
protected  void warn(java.lang.String msg)
           
protected  void warn(java.lang.String msg, java.lang.Exception e)
           
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, isResizable, isUndecorated, paramString, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFontMetrics, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
postEvent
 

Field Detail

ENABLE_OK

public static final int ENABLE_OK
Show OK button

See Also:
Constant Field Values

ENABLE_CANCEL

public static final int ENABLE_CANCEL
Show Cancel button

See Also:
Constant Field Values

ENABLE_APPLY

public static final int ENABLE_APPLY
Show Apply button

See Also:
Constant Field Values
Constructor Detail

BeanPeeler

public BeanPeeler(java.lang.Object bean)
Constructs a new BeanPeeler to edit the given bean.

Parameters:
bean - The bean to be edited.

BeanPeeler

public BeanPeeler(java.lang.Object bean,
                  int options)
Constructs a new BeanPeeler to edit the given bean.

Parameters:
bean - The bean to be edited.
options - the allowed options for the buttons (see fields list) = usual bitwise or
Method Detail

showAndWait

public void showAndWait()
Use instead of Window.show() if you want a modal dialog


getBean

public java.lang.Object getBean()
Getter for property bean.

Returns:
Value of property bean.

setBean

public void setBean(java.lang.Object bean)
Setter for property bean.

Parameters:
bean - New value of property bean.

getTitle

public java.lang.String getTitle()
Getter for property title.

Returns:
Value of property title.

setTitle

public void setTitle(java.lang.String title)
Setter for property title.
You don't want to be stuck with my title now do you?

Parameters:
title - New value of property title.

getProcessNames

public boolean getProcessNames()

setProcessNames

public void setProcessNames(boolean processNames)
Attempts to make the labels more attractive by parsing the names. "_" become spaces, words are broken at capitals etc.


getLastError

public java.lang.String getLastError()
Returns the last warning posted when creating the dialog - @see getErrors()

Returns:
Last error posted

getErrors

public java.util.Vector getErrors()
As properties are added to the sheet certain exceptions and warnings may arise. This method allows you to inspect them.

Returns:
A List containing all the posted warnings.

warn

protected void warn(java.lang.String msg,
                    java.lang.Exception e)

warn

protected void warn(java.lang.String msg)

getBackground

public java.awt.Color getBackground()
Getter for property background.

Returns:
Value of property background.

setBackground

public void setBackground(java.awt.Color background)
Setter for property background.

Parameters:
background - New value of property background.

getForeground

public java.awt.Color getForeground()
Getter for property foreground.

Returns:
Value of property foreground.

setForeground

public void setForeground(java.awt.Color foreground)
Setter for property foreground.

Parameters:
foreground - New value of property foreground.

getFont

public java.awt.Font getFont()
Getter for property font.

Specified by:
getFont in interface java.awt.MenuContainer
Returns:
Value of property font.

setFont

public void setFont(java.awt.Font font)
Setter for property font.

Parameters:
font - New value of property font.

getPaintAreaSize

public java.awt.Dimension getPaintAreaSize()
Getter for property paintAreaSize.

Returns:
Value of property paintAreaSize.

setPaintAreaSize

public void setPaintAreaSize(java.awt.Dimension paintAreaSize)
Setter for property paintAreaSize.

Parameters:
paintAreaSize - New value of property paintAreaSize.

isVerbose

public boolean isVerbose()
Getter for property verbose.

Returns:
Value of property verbose.

setVerbose

public void setVerbose(boolean verbose)
Setter for property verbose.

Parameters:
verbose - New value of property verbose.

isFollowInheritanceTree

public boolean isFollowInheritanceTree()
Getter for property followInheritanceTree.

Returns:
Value of property followInheritanceTree.

setFollowInheritanceTree

public void setFollowInheritanceTree(boolean followInheritanceTree)
Setter for property followInheritanceTree.

Parameters:
followInheritanceTree - New value of property followInheritanceTree.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent)
The bean we're editing has changed....

Specified by:
propertyChange in interface java.beans.PropertyChangeListener


Copyright © 2001-2003 John Taylor's Stuff. All Rights Reserved.