com.swfm.mica.sys
Class MiUtility

java.lang.Object
  extended bycom.swfm.mica.sys.MiUtility
All Implemented Interfaces:
MiiCommandNames, MiiNames, MiiPropertyTypes, MiiTypes

public class MiUtility
extends java.lang.Object
implements MiiCommandNames, MiiTypes, MiiNames, MiiPropertyTypes

This file contains various, potentially useful, methods.

Version:
%I% %G%
Author:
Michael L. Davis

Field Summary
         
Constructor Summary
MiUtility()
           
 
Method Summary
static MiText assignShortCutFromLabel(MiPart widget, MiiCommandHandler method, java.lang.String text)
          Parses the given text and assigns any short cut it specifies to the given widget.
static MiPart createGraphics(java.lang.String name)
           
static MiPart createGraphics(java.lang.String name, boolean ignoreCase)
           
static MiiLayout createLayout(java.lang.String name, boolean ignoreCase, boolean manipulatable)
          Gets a layout object of the given type name.
static MiPart createShape(java.lang.String name)
           
static MiPart createShape(java.lang.String name, boolean ignoreCase)
           
static boolean equals(java.lang.String one, java.lang.String other, boolean ignoreCase)
           
static void gatherRootNodes(MiPart container, MiParts roots)
          Gets the list of root nodes for all of the nodes in the given container.
static void getActualShapesToApplyAttributeChangeTo(MiPart target, MiParts expandedListOfParts)
           
static MiParts getActualShapesToApplyAttributeChangeTo(MiParts parts)
           
static MiParts getAllDescendentsWithName(MiPart parent, java.lang.String name, boolean ignoreCase)
          Gets the descendents of the given MiPart who have the given name.
static MiParts getAllParts(MiPart container, MiParts parts)
           
static void getBoundsOfTree(MiPart root, java.lang.String connectionType, MiBounds bounds)
           
static MiParts getChildren(MiPart parent)
          Gets the children of the given MiPart.
static MiPart getCommonContainer(MiPart child1, MiPart child2)
          Gets the MiPart that is a container of both of the given MiParts.
static MiPart getDeepPart(MiPart container, java.lang.String name)
          Gets the part in the given container or in one of the parts of this container that has the given name.
static java.awt.Frame getFrame(java.awt.Component applet)
          Gets the Frame that contains the component.
static boolean getIntersectionOfTwoLines(MiPoint p1, MiPoint p2, MiPoint q1, MiPoint q2, MiPoint intersection)
          Gets the intersection of two lines or returns false if there is no intersection.
static boolean getIntersectionOfTwoLineSegments(MiPoint p1, MiPoint p2, MiPoint q1, MiPoint q2, MiPoint intersection)
          Gets the intersection of two lines or returns false if there is no intersection.
static MiPoint getLocationOfLineLocation(MiPart target, int location, MiBounds boundsToPosition, MiPoint pt, MiMargins margins)
           
static MiPoint getLocationWithRespectToPart(MiPart target, int location, MiBounds boundsToPosition, MiPoint pt, MiMargins margins)
           
static MiPart getManipulatableContainerOfPart(MiEditor editor, MiPart part)
           
static int getMaxDepth(MiPart part)
          Gets the maximum depth of the given node in it's graph of connections (i.e.
static int getMaxDepth(MiParts roots)
          Gets the maximum depth of a node in the graph with the given root nodes (i.e.
static MiParts getParents(MiPart child)
          Gets the parents of the given MiPart.
static boolean getPath(MiPart parent, MiPart child, MiParts path)
          Get the list of MiParts (path) in the container-part hierarchy between and including the given parent and given child.
static boolean getPath(MiPart parent, MiPart child, MiParts path, MiParts validNodes)
          Get the list of MiParts (path) in the container-part hierarchy between and including the given parent and given child.
static boolean getPointFromPartNamePointNumberSpec(MiPart part, java.lang.String spec, MiPoint returnedPoint)
           
static MiRenderer getRenderer(MiPart part)
          Get a renderer to use to draw using the coordinates and transforms compatible with the MiPart.
static MiTransforms getTransformsAlongPath(MiPart parent, MiPart child)
          Get the list of MiiTranforms in the container-part hierarchy between and including the given parent and given child.
static boolean getTransformsAlongPath(MiPart parent, MiPart child, FastVector transforms)
          Get the list of MiiTranforms in the container-part hierarchy between and including the given parent and given child.
static boolean isLocallyRequestingEventType(MiPart part, MiEvent event)
          Gets whether the given MiPart's event handlers are interested in the given event.
static MiParts makeCopyOfNetwork(MiParts network)
           
static boolean partAndContainersAreVisible(MiPart part)
           
static boolean pathExists(MiPart src, MiPart dest, MiParts path, boolean depthfirstSearch)
          Gets whether a path (a sequence of connections) exist between the two given MiParts.
static void popMouseAppearance(MiPart part, java.lang.String identifier)
          Restores the mouse appearance to the appearance of the mouse before the corresponding call to #pushMouseAppearance which used this identifier.
static void pushMouseAppearance(MiPart part, int appearance, java.lang.String identifier)
          Sets the mouse appearance.
static void rotate(MiPoint pt, MiPoint centerOfRotation, double radians)
           
static int rotateAndFlipExitDirectionMask(int mask, double radians, boolean flipped)
           
static void translateTree(MiPart parent, java.lang.String connectionType, double tx, double ty)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MiUtility

public MiUtility()
Method Detail

getIntersectionOfTwoLines

public static boolean getIntersectionOfTwoLines(MiPoint p1,
                                                MiPoint p2,
                                                MiPoint q1,
                                                MiPoint q2,
                                                MiPoint intersection)
Gets the intersection of two lines or returns false if there is no intersection. The lines are defined by points (p1, p2) and (q1, q2) and are treated as infinitely long (i.e. the point of intersection may not lie on the line segments defined by the given points).

Parameters:
p1 - the start point of line 1
p2 - the end point of line 1
q1 - the start point of line 2
intersection - the (returned) point of intersection
Returns:
true if there is an intersection

getIntersectionOfTwoLineSegments

public static boolean getIntersectionOfTwoLineSegments(MiPoint p1,
                                                       MiPoint p2,
                                                       MiPoint q1,
                                                       MiPoint q2,
                                                       MiPoint intersection)
Gets the intersection of two lines or returns false if there is no intersection. The lines are defined by points (p1, p2) and (q1, q2) and are treatd as line (i.e. the point of intersection will lie on both line segments).

Parameters:
p1 - the start point of line 1
p2 - the end point of line 1
q1 - the start point of line 2
intersection - the (returned) point of intersection
Returns:
true if there is an intersection

getCommonContainer

public static MiPart getCommonContainer(MiPart child1,
                                        MiPart child2)
Gets the MiPart that is a container of both of the given MiParts.

Parameters:
child1 - the given MiPart
child2 - the given MiPart
Returns:
the common container or null

getParents

public static MiParts getParents(MiPart child)
Gets the parents of the given MiPart. A child is defined as the MiPart at the other side (source) of a connection that is connected to the given MiPart.

Returns:
the list of parent MiParts

getChildren

public static MiParts getChildren(MiPart parent)
Gets the children of the given MiPart. A child is defined as the MiPart at the other side (destination) of a connection that is connected to the given MiPart.

Parameters:
parent - the given MiPart
Returns:
the list of child MiParts

getAllDescendentsWithName

public static MiParts getAllDescendentsWithName(MiPart parent,
                                                java.lang.String name,
                                                boolean ignoreCase)
Gets the descendents of the given MiPart who have the given name.

Parameters:
parent - the given MiPart
name - the name to match
ignoreCase - true if ignore case of name
Returns:
the list of descendent MiParts with name

pathExists

public static boolean pathExists(MiPart src,
                                 MiPart dest,
                                 MiParts path,
                                 boolean depthfirstSearch)
Gets whether a path (a sequence of connections) exist between the two given MiParts. If so, the path is appended to the given path and true is returned. The type of search is specified by the depthfirstSearch parameter.

Parameters:
src - the start of the path
dest - the end of the path
path - the (returned) path
depthfirstSearch - true if depth first, false if breadth first search is to be performed
Returns:
true if a path exists

getMaxDepth

public static int getMaxDepth(MiParts roots)
Gets the maximum depth of a node in the graph with the given root nodes (i.e. get the maximum number of MiParts between any root MiPart and any other connected MiPart). Roots are MiParts that have no connection that they are not the source of. This is useful when laying out trees and one needs to know the number of levels in the tree.

Parameters:
roots - the list of root nodes
Returns:
the maximum number of levels in all of the trees defined by the connections of the root nodes

getMaxDepth

public static int getMaxDepth(MiPart part)
Gets the maximum depth of the given node in it's graph of connections (i.e. get the maximum number of MiParts between any the given MiPart and all of it's root MiParts. Roots are MiParts that have no connection that they are not the source of (i.e. they are the start of a directed graph/tree).

Parameters:
part - the part
Returns:
the maximum number of levels to any root in the graph of connections that the MiPart has

gatherRootNodes

public static void gatherRootNodes(MiPart container,
                                   MiParts roots)
Gets the list of root nodes for all of the nodes in the given container.

Parameters:
container - the container of the parts
roots - the (returned) roots of the graph

isLocallyRequestingEventType

public static boolean isLocallyRequestingEventType(MiPart part,
                                                   MiEvent event)
Gets whether the given MiPart's event handlers are interested in the given event.

Parameters:
event - the event
Returns:
true if one of the event handlers are interested

getRenderer

public static MiRenderer getRenderer(MiPart part)
Get a renderer to use to draw using the coordinates and transforms compatible with the MiPart. This will NOT work correctly with old JDKs which had the AWT clip bug (which means that as soon as the clip bounds is set in this new renderer, a new java.awt.Graphics is created which the current renderer does not have access to, and so draws to the old renderer have no effect until the window is resized).

Parameters:
part - A part
Returns:
A renderer

getTransformsAlongPath

public static boolean getTransformsAlongPath(MiPart parent,
                                             MiPart child,
                                             FastVector transforms)
Get the list of MiiTranforms in the container-part hierarchy between and including the given parent and given child. The order of the transforms is child-most transform (element #0) to parent-most transform.

Parameters:
parent - the given parent
child - the given child
transforms - the (returned) list of transforms
Returns:
true if there is such a path
See Also:
getPath(com.swfm.mica.core.MiPart, com.swfm.mica.core.MiPart, com.swfm.mica.core.MiParts)

getTransformsAlongPath

public static MiTransforms getTransformsAlongPath(MiPart parent,
                                                  MiPart child)
Get the list of MiiTranforms in the container-part hierarchy between and including the given parent and given child. The order of the transforms is child-most transform (element #0) to parent-most transform.

Parameters:
parent - the given parent
child - the given child
Returns:
the transforms condensed into a MiTransforms object
See Also:
getPath(com.swfm.mica.core.MiPart, com.swfm.mica.core.MiPart, com.swfm.mica.core.MiParts)

getPath

public static boolean getPath(MiPart parent,
                              MiPart child,
                              MiParts path)
Get the list of MiParts (path) in the container-part hierarchy between and including the given parent and given child. The order of the path is child (element #0) to parent. If the parent is null then the root window of the child is used as the parent.

Parameters:
parent - the given parent
child - the given child
path - the (returned) list of parts (path)
Returns:
true if there is such a path
See Also:
getTransformsAlongPath(com.swfm.mica.core.MiPart, com.swfm.mica.core.MiPart, com.swfm.mica.util.FastVector)

getPath

public static boolean getPath(MiPart parent,
                              MiPart child,
                              MiParts path,
                              MiParts validNodes)
Get the list of MiParts (path) in the container-part hierarchy between and including the given parent and given child. The order of the path is child to parent. If the parent is null then the root window of the child is used as the parent. This algorithm supports paths that have parts with multiple parents.

Parameters:
parent - the given parent
child - the given child
path - the (returned) list of parts (path)
validNodes - valid parts along the path
Returns:
true if there is such a path
See Also:
getTransformsAlongPath(com.swfm.mica.core.MiPart, com.swfm.mica.core.MiPart, com.swfm.mica.util.FastVector)

getFrame

public static java.awt.Frame getFrame(java.awt.Component applet)
Gets the Frame that contains the component.

Returns:
the Frame or null, if none

getDeepPart

public static MiPart getDeepPart(MiPart container,
                                 java.lang.String name)
Gets the part in the given container or in one of the parts of this container that has the given name.

Parameters:
container - the container of the parts to check
name - the given name
Returns:
the part with the given name or null

getBoundsOfTree

public static void getBoundsOfTree(MiPart root,
                                   java.lang.String connectionType,
                                   MiBounds bounds)

translateTree

public static void translateTree(MiPart parent,
                                 java.lang.String connectionType,
                                 double tx,
                                 double ty)

makeCopyOfNetwork

public static MiParts makeCopyOfNetwork(MiParts network)

assignShortCutFromLabel

public static MiText assignShortCutFromLabel(MiPart widget,
                                             MiiCommandHandler method,
                                             java.lang.String text)
Parses the given text and assigns any short cut it specifies to the given widget. The short cut calls the given method. The given text is of form: labe&l\tCtrl+C where the optional '&' indicates that the character following is to be a short cut (when widget is visible) and the '\t' indicates the following event is to be a short cut. If either '&' or '\t' is proceeded by a backslash then the character is ignored (i.e. "\\&" is replaced by "&").

Parameters:
widget - The widget to assign any short cuts to.
method - The method to call when the short cut is activated by the end-user.
text - The string to parse looking for short cuts.
Returns:
the text left over after removing any specified short cuts

pushMouseAppearance

public static void pushMouseAppearance(MiPart part,
                                       int appearance,
                                       java.lang.String identifier)
Sets the mouse appearance.

Parameters:
part - a part in the root window in which this sets the mouse appearance or null
appearance - the mouse cursor appearance
identifier - identifies the current position in the mouse appearance stack
See Also:
MiEditor.pushMouseAppearance(int, java.lang.String)

popMouseAppearance

public static void popMouseAppearance(MiPart part,
                                      java.lang.String identifier)
Restores the mouse appearance to the appearance of the mouse before the corresponding call to #pushMouseAppearance which used this identifier.

Parameters:
part - a part in the root window in which this restores the mouse appearance or null
identifier - identifies a position in the mouse appearance stack
See Also:
MiEditor.popMouseAppearance(java.lang.String)

getAllParts

public static MiParts getAllParts(MiPart container,
                                  MiParts parts)

getActualShapesToApplyAttributeChangeTo

public static MiParts getActualShapesToApplyAttributeChangeTo(MiParts parts)

getActualShapesToApplyAttributeChangeTo

public static void getActualShapesToApplyAttributeChangeTo(MiPart target,
                                                           MiParts expandedListOfParts)

getManipulatableContainerOfPart

public static MiPart getManipulatableContainerOfPart(MiEditor editor,
                                                     MiPart part)

getPointFromPartNamePointNumberSpec

public static boolean getPointFromPartNamePointNumberSpec(MiPart part,
                                                          java.lang.String spec,
                                                          MiPoint returnedPoint)
Parameters:
spec - of form: "subPartName.subPartPointNumber"
Returns:
true if such a part with such a point is found

getLocationWithRespectToPart

public static MiPoint getLocationWithRespectToPart(MiPart target,
                                                   int location,
                                                   MiBounds boundsToPosition,
                                                   MiPoint pt,
                                                   MiMargins margins)

getLocationOfLineLocation

public static MiPoint getLocationOfLineLocation(MiPart target,
                                                int location,
                                                MiBounds boundsToPosition,
                                                MiPoint pt,
                                                MiMargins margins)

rotateAndFlipExitDirectionMask

public static int rotateAndFlipExitDirectionMask(int mask,
                                                 double radians,
                                                 boolean flipped)

rotate

public static void rotate(MiPoint pt,
                          MiPoint centerOfRotation,
                          double radians)

createGraphics

public static MiPart createGraphics(java.lang.String name)

createGraphics

public static MiPart createGraphics(java.lang.String name,
                                    boolean ignoreCase)

createShape

public static MiPart createShape(java.lang.String name)

createShape

public static MiPart createShape(java.lang.String name,
                                 boolean ignoreCase)

createLayout

public static MiiLayout createLayout(java.lang.String name,
                                     boolean ignoreCase,
                                     boolean manipulatable)
Gets a layout object of the given type name.

Parameters:
name - the name of a layout
ignoreCase -
manipulatable - true if this should be a manipulatable layout template, if the layout is an instance of MiManipulatableLayout.
Returns:
the layout or null

partAndContainersAreVisible

public static boolean partAndContainersAreVisible(MiPart part)

equals

public static boolean equals(java.lang.String one,
                             java.lang.String other,
                             boolean ignoreCase)