com.miginfocom.ashape
Class AShapeUtil

java.lang.Object
  extended by com.miginfocom.ashape.AShapeUtil

public class AShapeUtil
extends java.lang.Object

Utility methods for handling AShapes and RootAShapes.

Also contains a few static methods for setting the most common interactions, such as mouse over -> cursor change.

Also provide some default RootAShapes. These should be used mostly for testing though since they may change at any time in the future.


Field Summary
static java.lang.String DEFAULT_BACKGROUND_SHAPE_NAME
           
static java.lang.String DEFAULT_CONTAINER_SHAPE_NAME
           
static java.lang.String DEFAULT_MAIN_TEXT_SHAPE_NAME
           
static java.lang.String DEFAULT_OUTLINE_SHAPE_NAME
           
static java.lang.String DEFAULT_SHADOW_SHAPE_NAME
           
static java.lang.String DEFAULT_SHADOW_SHAPE_SHAPE_NAME
           
static java.lang.String DEFAULT_TITLE_TEXT_SHAPE_NAME
           
 
Constructor Summary
AShapeUtil()
           
 
Method Summary
static java.util.List addEnterExitCommands(AShape shape, CommandSet inCmd, CommandSet outCmd, boolean onlyIfTopMost)
          A convenience method for setting commands that should be run when the mouse enters and/or exits a shape.
static void addEnterExitOverride(AShape moShape, AShape target, PropertyKey property, java.lang.Object o, boolean onlyIfTopMost, boolean removeForExit)
          Convenience method for adding a mouse enter, and possibly exit, interaction pair with override set/reset.
static void addMouseCommand(AShape shape, PropertyKey trigger, boolean exclusive, CommandSet cmd, CommandSet resetCmd, boolean onlyIfTopMost, boolean consume)
          Convenience method for adding a mouse set/resset interaction pair with override set/reset.
static void addMouseEventBlock(AShape shape, boolean isPreBlock, java.lang.Integer eventId)
          If an event isn't caught by an AShape it is typically sent to whatever is under the shape.
static void addMouseFireEvent(AShape pressShape, PropertyKey trigger, java.lang.Object commandValue, boolean onlyIfTopMost, boolean consume, java.lang.Integer mouseButton)
          Convenience method for adding an interaction that fires an action when a mouse trigger occurs.
static void addMouseOverride(AShape moShape, AShape target, PropertyKey trigger, PropertyKey property, java.lang.Object o, boolean onlyIfTopMost, boolean autoReset, boolean consume)
          Convenience method for adding a mouse interaction pair with override set/reset.
static void addMousePressedOverride(AShape hitShape, AShape target, PropertyKey property, java.lang.Object o, boolean onlyIfTopMost, boolean consume)
          Add an interaction that sets an override if the shape is pressed and removes if if the mouse is released.
static void addMouseRemoveOverride(AShape pressShape, AShape target, PropertyKey trigger, boolean exclusive, PropertyKey property, java.lang.Object o, boolean onlyIfTopMost, boolean consume)
          Convenience method for adding a mouse 'pressed other place' interaction that removes an override.
static void addStaticOverride(AShape target, PropertyKey property, java.lang.Object o)
          Set an override that is always in effect.
static RootAShape createDefault(int dimension)
          Creates the default shape.
static RootAShape createDefault(int dimension, java.lang.String namePrefix)
          Creates the default shape.
static RootAShape createDefaultNoFitShape(java.lang.String interactionEventName)
          Creates a shape the is for showing that not all activities could be shown within the bounds.
static void enableMouseOverCursor(RootAShape root)
          Convenience method for enabling enter & exit interactions that sets and resets the cursor in the JComponent for the broker.
static void enableMouseOverState(AShape moShape)
          Sets the mouse over state in with ActivityViewInteractionBroker.CMD_SET_STATE the mouse passes over shape.
static java.awt.Insets getRepaintPadding(RootAShape[] shapes, java.awt.Insets startInsets)
          Checks all shapes and returns a new padding that will satisfy all shapes.
static RootAShape loadShape(java.io.InputStream in, boolean isProbablyZipped)
          Loads a shape from a file
static RootAShape loadShape(java.lang.String filename, boolean isProbablyZipped)
          Loads a shape from a file
static void saveShape(RootAShape root, java.lang.String filename, boolean zipIt)
          Save a shape to the specified filename.
static AShape[] setResizeBoxes(AShape shape, int orientation, int width)
          Adds invisible resize boxes at the edge of the shape.
static void setStateOverride(AShape target, PropertyKey state, PropertyKey property, java.lang.Object o)
          Set an override that is in effect when a state true.
static java.util.Map toPropertyKeyMap(java.util.Map map)
          If first key is a String all String keys are converted to PropertyKeys with PropertyKey.getKey(String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONTAINER_SHAPE_NAME

public static final java.lang.String DEFAULT_CONTAINER_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_BACKGROUND_SHAPE_NAME

public static final java.lang.String DEFAULT_BACKGROUND_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_TITLE_TEXT_SHAPE_NAME

public static final java.lang.String DEFAULT_TITLE_TEXT_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_MAIN_TEXT_SHAPE_NAME

public static final java.lang.String DEFAULT_MAIN_TEXT_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_OUTLINE_SHAPE_NAME

public static final java.lang.String DEFAULT_OUTLINE_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_SHADOW_SHAPE_SHAPE_NAME

public static final java.lang.String DEFAULT_SHADOW_SHAPE_SHAPE_NAME
See Also:
Constant Field Values

DEFAULT_SHADOW_SHAPE_NAME

public static final java.lang.String DEFAULT_SHADOW_SHAPE_NAME
See Also:
Constant Field Values
Constructor Detail

AShapeUtil

public AShapeUtil()
Method Detail

toPropertyKeyMap

public static final java.util.Map toPropertyKeyMap(java.util.Map map)
If first key is a String all String keys are converted to PropertyKeys with PropertyKey.getKey(String).

If no key is a String the sent in map will be returned, otherwise a new IdentityHashMap will be created and returned.

Parameters:
map - The map. May be null in which case null is returned. Only the fist key will be checked!
Returns:
map or a new map. May be null.

saveShape

public static void saveShape(RootAShape root,
                             java.lang.String filename,
                             boolean zipIt)
                      throws java.io.IOException
Save a shape to the specified filename.

Parameters:
root - The root of the shape to save.
filename - The filename
Throws:
java.io.IOException

loadShape

public static RootAShape loadShape(java.lang.String filename,
                                   boolean isProbablyZipped)
                            throws java.io.IOException
Loads a shape from a file

Parameters:
filename - The filename.
isProbablyZipped - If the file is expected to be zipped. Some streams doesn't support peak ahead, then this value is tried.
Returns:
The shape. Never null.
Throws:
java.io.IOException

loadShape

public static RootAShape loadShape(java.io.InputStream in,
                                   boolean isProbablyZipped)
                            throws java.io.IOException
Loads a shape from a file

Parameters:
in - An input stream to read from. Will be wrapped in a BufferedInputStream if not already buffered
isProbablyZipped - If the file is expected to be zipped. Some streams doesn't support peak ahead, then this value is tried.
Returns:
The shape.
Throws:
java.io.IOException

getRepaintPadding

public static java.awt.Insets getRepaintPadding(RootAShape[] shapes,
                                                java.awt.Insets startInsets)
Checks all shapes and returns a new padding that will satisfy all shapes.

Parameters:
shapes - The shapes to check. Not null.
startInsets - The isnets to start with. Will never be smaller than when sent in, might be bigger. Not null.
Returns:
startInsets as convenience for chaining.

addMouseCommand

public static void addMouseCommand(AShape shape,
                                   PropertyKey trigger,
                                   boolean exclusive,
                                   CommandSet cmd,
                                   CommandSet resetCmd,
                                   boolean onlyIfTopMost,
                                   boolean consume)
Convenience method for adding a mouse set/resset interaction pair with override set/reset.

Parameters:
shape - The shape that spans the areas the is checked for mouse enter
trigger - The trigger that should activate the command/s. One of:
exclusive - If this interaction must be the first to act. Usually means the event shouldn't have been consumed before if the command should be run.
cmd - The command to run when the shape is in list. If null nothing happens for the entered event.
resetCmd - The command to run when the "oppisite" action happens, normally meaning that is isn't any longer in the list that corresponds to the trigger. Enter/exit will not work correctly for this since it's a bit more complicated. See addEnterExitCommands(com.miginfocom.ashape.shapes.AShape, com.miginfocom.util.command.CommandSet, com.miginfocom.util.command.CommandSet, boolean) for this. If null nothing happens for the entered event.
onlyIfTopMost - If true the cursor is considered over only if the shape is the top most one. If the mouse are moved over another shape that is above this one the out cmd is run.
consume - If the mouse event should be consumed so that underlaying shapes won't get notified.

addEnterExitCommands

public static java.util.List addEnterExitCommands(AShape shape,
                                                  CommandSet inCmd,
                                                  CommandSet outCmd,
                                                  boolean onlyIfTopMost)
A convenience method for setting commands that should be run when the mouse enters and/or exits a shape.

Parameters:
shape - The shape that spans the areas the is checked for mouse enter
inCmd - The command run when the mouse enteres the sub shape
outCmd - The command run when the mouse exits the sub shape
onlyIfTopMost - If true the mouse is considered "over" the shape only if it's the sub shape (which has a hit area) that is topmost. Only interesing within shape tree.
Returns:
The Interactions added to the root of shape.

addMouseEventBlock

public static void addMouseEventBlock(AShape shape,
                                      boolean isPreBlock,
                                      java.lang.Integer eventId)
If an event isn't caught by an AShape it is typically sent to whatever is under the shape. It might be another AShape or a JComponent for instance.

Calling this method (typically last, after all other interactions been added) provides for a catch mechanism for mouse events within the hit area of the shape.

Parameters:
shape - The shape that spans the area that will block mouse events.
isPreBlock - If true then events will be blocked BEFORE they are handled by the more specific handlers. See MouseKeyInteractor.MOUSE_EVENT_PRE
If false the bloch will be after they are handled, consuming them before the get to the underlying object, such as anothe shape or the containing JComponent.
eventId - The event id to block (consume). E.g. MouseEvent.MOUSE_MOVED.
If null ALL mouse events will be blocked.

enableMouseOverState

public static void enableMouseOverState(AShape moShape)
Sets the mouse over state in with ActivityViewInteractionBroker.CMD_SET_STATE the mouse passes over shape.

Parameters:
moShape - The shape that spans the areas the is checked for mouse enter

enableMouseOverCursor

public static void enableMouseOverCursor(RootAShape root)
Convenience method for enabling enter & exit interactions that sets and resets the cursor in the JComponent for the broker.

Parameters:
root - The shape that spans the areas the is checked for mouse enter shape that is above this one the cursor will not be reset. It is only reset when the mouse exits the shapes bounds.
See Also:
RootAShape.addInteraction(com.miginfocom.ashape.interaction.Interaction), DefaultInteractionBroker.CMD_SET_CURSOR_FROM_ASHAPE

addMouseOverride

public static void addMouseOverride(AShape moShape,
                                    AShape target,
                                    PropertyKey trigger,
                                    PropertyKey property,
                                    java.lang.Object o,
                                    boolean onlyIfTopMost,
                                    boolean autoReset,
                                    boolean consume)
Convenience method for adding a mouse interaction pair with override set/reset.

Note that this is not optimal for enter/exit interactions. See addEnterExitOverride(com.miginfocom.ashape.shapes.AShape, com.miginfocom.ashape.shapes.AShape, PropertyKey, Object, boolean, boolean) for that.

Parameters:
moShape - The shape that spans the areas the is checked for mouse enter
target - The target shape for the override
trigger - The trigger that should activate the command/s. One of:
property - The property name to override. E.g AShape.A_PAINT.
o - The object to set
onlyIfTopMost - If true the cursor wil be changed only if the shape is the top most one. If the mouse are moved over another shape that is above this one the interaction will not be reset.
autoReset - If an interaction, opposite to the set one, should counteract the effect.
consume - If the mouse event should be consumed so that underlaying shapes won't get notified.

addMousePressedOverride

public static void addMousePressedOverride(AShape hitShape,
                                           AShape target,
                                           PropertyKey property,
                                           java.lang.Object o,
                                           boolean onlyIfTopMost,
                                           boolean consume)
Add an interaction that sets an override if the shape is pressed and removes if if the mouse is released.

Parameters:
hitShape - The shape to hit
target - The target to set the override for
property - The property to change on the target
o - The value for the property to set as override.
onlyIfTopMost - Only if hitShape was the topmost shape pressed.
consume - If the event should be consumed.

addEnterExitOverride

public static void addEnterExitOverride(AShape moShape,
                                        AShape target,
                                        PropertyKey property,
                                        java.lang.Object o,
                                        boolean onlyIfTopMost,
                                        boolean removeForExit)
Convenience method for adding a mouse enter, and possibly exit, interaction pair with override set/reset.

Better than addMouseOverride(com.miginfocom.ashape.shapes.AShape, com.miginfocom.ashape.shapes.AShape, PropertyKey, PropertyKey, Object, boolean, boolean, boolean) for enter/exit commands

Parameters:
moShape - The shape that spans the areas that is checked for mouse enter/exit.
target - The target shape for the override. I.e. the shape to set the property on.
property - The property name to override. E.g AShape.A_PAINT.
o - The object to set. Might be for instance a new Color.
onlyIfTopMost - If true the cursor wil be changed only if the shape is the top most one. If the mouse are moved over another shape that is above this one the interaction will not be reset.
removeForExit - Of the override should be removed when the mouse exits the sub shape.

addMouseRemoveOverride

public static void addMouseRemoveOverride(AShape pressShape,
                                          AShape target,
                                          PropertyKey trigger,
                                          boolean exclusive,
                                          PropertyKey property,
                                          java.lang.Object o,
                                          boolean onlyIfTopMost,
                                          boolean consume)
Convenience method for adding a mouse 'pressed other place' interaction that removes an override.

Parameters:
pressShape - The shape that spans the areas the is checked for mouse enter
target - The target shape for the override.
trigger - The trigger that should activate the command/s. One of:
exclusive - If this interaction must be the first to act. Usually means the event shouldn't have been consumed before if the command should be run.
property - THe property name to override. E.g AShape.A_PAINT.
o - The object to set
onlyIfTopMost - If true the cursor wil be changed only if the shape is the top most one. If the mouse are moved over another shape that is above this one the interaction will not be reset.
consume - If the mouse event should be consumed so that underlaying shapes won't get notified.

setStateOverride

public static void setStateOverride(AShape target,
                                    PropertyKey state,
                                    PropertyKey property,
                                    java.lang.Object o)
Set an override that is in effect when a state true.

Parameters:
target - The target shape for the override.
state - The state to set the override for. E.g. GenericStates.SELECTED
property - The property name to override. E.g AShape.A_PAINT.
o - The object to set

addStaticOverride

public static void addStaticOverride(AShape target,
                                     PropertyKey property,
                                     java.lang.Object o)
Set an override that is always in effect.

Parameters:
target - The target shape for the override.
property - The property name to override. E.g AShape.A_PAINT.
o - The object to set. May be a OverrideFilter to make the override object choosable at evaluation time.
See Also:
OverrideFilter, AbstractInteractor.TRIGGER_ONCE

addMouseFireEvent

public static void addMouseFireEvent(AShape pressShape,
                                     PropertyKey trigger,
                                     java.lang.Object commandValue,
                                     boolean onlyIfTopMost,
                                     boolean consume,
                                     java.lang.Integer mouseButton)
Convenience method for adding an interaction that fires an action when a mouse trigger occurs.

Adds the interaction to the root shape.

Parameters:
pressShape - The shape the the mouse should be over when the mouse button is pressed, released or clicked.
trigger - The trigger that should fire the event. One of:
commandValue - The value in the InteractionEvent's command.
onlyIfTopMost - If true the event will be fired only if the shape is the top most one. If the mouse are over another shape that is above this one the interaction will not be reset.
consume - Consumes the mouse event so that it will not continue to be evaluated. See InputEvent.consume()
mouseButton - If a specific button must be in the event. E.g. MouseEvent.BUTTON1. If null all values are accepted. Should be null for all trigger types not involving a mouse button.
See Also:
RootAShape.addInteraction(com.miginfocom.ashape.interaction.Interaction)

setResizeBoxes

public static AShape[] setResizeBoxes(AShape shape,
                                      int orientation,
                                      int width)
Adds invisible resize boxes at the edge of the shape. If old resize boxes exists those are removed first.

Parameters:
shape - The shape to attach the resize container to. Must have a valid root.
orientation - SwingConstants.HORIZONTAL or SwingConstants.VERTICAL. If -1 the old resize boxes are removed but no new are added.
Returns:
The two shapes used as resize containers. Can be decorated with sub shapes such as FillAShape. Will be null if orientation is -1.

createDefaultNoFitShape

public static RootAShape createDefaultNoFitShape(java.lang.String interactionEventName)
Creates a shape the is for showing that not all activities could be shown within the bounds. It can be pressed and reacts to moue overs.

Parameters:
interactionEventName - The event name fired when the shape is pressed.
Returns:
The shape. Never null.

createDefault

public static RootAShape createDefault(int dimension)
Creates the default shape.

The sub shapes are named with static names. E.g. DEFAULT_BACKGROUND_SHAPE_NAME. They all starts with DEFAULT_.

This is how to set a new "global shape": DefaultAShapeProvider.setShapeGlobally(VERSHAPE, null);

Parameters:
dimension - SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. -1 will create no resize box box areas.

createDefault

public static RootAShape createDefault(int dimension,
                                       java.lang.String namePrefix)
Creates the default shape.

The sub shapes are named with static names. E.g. DEFAULT_BACKGROUND_SHAPE_NAME. They all starts with DEFAULT_.

This is how to set a new "global shape": DefaultAShapeProvider.setShapeGlobally(VERSHAPE, null);

Parameters:
dimension - SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. -1 will create no resize box box areas.
namePrefix - String that will be added before all ashape names created. Null is ok ("").


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.