public class CGUtil
extends Object
Constructor and Description |
---|
CGUtil() |
Modifier and Type | Method and Description |
---|---|
static Rectangle2D.Double |
adjustForCartesian(double x1,
double y1,
double x2,
double y2)
returns the AWT rectangle given any two opposite corners, correcting for
signs.
|
static Rectangle2D.Double |
adjustForCartesian(Point2D.Double p1,
Point2D.Double p2)
returns the AWT rectangle given its two opposite corners
|
static GNode |
closestObject(ArrayList<GNode> nodes,
Point2D.Double point)
Finds the object in the list that is closest to the point given
|
static int |
fillChoiceList(JComboBox c,
String[] choices,
FontMetrics fm)
Loads choice list from the enumeration given.
|
static Point2D.Double |
getCenter(Rectangle2D.Double r)
Returns the center of the rectangle as a Point2D.Double
|
static Point2D.Double |
getCenterPoint(ArrayList<GNode> nodes)
Finds the center of the bounding rectangle that enclosed all the nodes
|
static ArrayList<ArrayList<GNode>> |
getConnectedComponents(Graph g)
Used in determining connected components.
|
static Color |
getDarkest(Color c1,
Color c2)
Returns the darker of the two colors, using a very crude algorithm.
|
static Point2D.Double |
getStringLowerLeftFromCenter(FontMetrics fm,
String s,
Point2D.Double center)
Find the lower left point for displaying a string whose center point is
known.
|
static void |
grow(Rectangle2D.Double r,
double xinc,
double yinc)
Mimics behavior of jawa.awt.Rectangle.grow which was oddly omitted from
Rectangle2D
|
private static void |
labelConnectedNodes(HashMap<GNode,Integer> componentLabels,
GNode startNode,
int componentNum)
Start by labeling the start node and then recursively find all the others
|
static void |
loadSizedComboBox(JComboBox cb,
String textLabel,
FontMetrics fm)
Loads combo box, setting given string as the default, resizing the field
if necessary.
|
static void |
loadSizedTextField(JTextField tf,
String textLabel,
FontMetrics fm)
Loads given text field with given string, resizing the field if
necessary.
|
static String |
shortClassName(Object obj)
Returns the short (un-qualified) name string of the given object
|
static void |
showMessageDialog(Component parentComponent,
Object message) |
static void |
showPoint(Graphics2D g,
Point2D.Double p)
Displays a point's coordinates in text at its location.
|
static ArrayList<GraphObject> |
sortObjects(ArrayList<GraphObject> list)
Gather together all the selected nodes, edges and graphs into a list.
|
static Dimension |
stringDimensions(String s,
FontMetrics fm)
Calculate height and width on a string using a given font metrics.
|
static Rectangle2D.Double |
unionDisplayRects(ArrayList nodeList)
Determines the union of a set of nodes' display rectangles.
|
static boolean |
verifyIntegrityOfGraph(Graph g)
Performs various "sanity checks" to make sure a graph is formed and/or constructed properly.
|
public static String shortClassName(Object obj)
obj
- Any Java objectpublic static Point2D.Double getStringLowerLeftFromCenter(FontMetrics fm, String s, Point2D.Double center)
fm
- any font metricss
- the string to be displayedcenter
- position of the centerpoint (in pixels)public static ArrayList<GraphObject> sortObjects(ArrayList<GraphObject> list)
public static Rectangle2D.Double adjustForCartesian(double x1, double y1, double x2, double y2)
x1
- are the x,y's for points 1 and 2 representing opposite corners
of a rectangley1
- x2
- y2
- public static Rectangle2D.Double adjustForCartesian(Point2D.Double p1, Point2D.Double p2)
p1
- and p2 are the two points representing opposite corners of a
rectanglep2
- public static Dimension stringDimensions(String s, FontMetrics fm)
s
- String whose dimensions are desired.fm
- Font metrics under which the string is to be rendered.public static int fillChoiceList(JComboBox c, String[] choices, FontMetrics fm)
c
- The (already allocated) Choice to be loadedchoices
- The list of choice strings to be put into the list.fm
- The currently applicable font metrics, used for determining
size of boxpublic static void loadSizedTextField(JTextField tf, String textLabel, FontMetrics fm)
tf
- The (already allocated) TextField to be loadedtextLabel
- The string to load into tffm
- font metrics from the context for which the combo box will be
sizedpublic static void loadSizedComboBox(JComboBox cb, String textLabel, FontMetrics fm)
cb
- The (already allocated) JComboBox to be loadedtextLabel
- The string to load into tffm
- font metrics from the context for which the combo box will be
sizedpublic static Rectangle2D.Double unionDisplayRects(ArrayList nodeList)
nodeList
- Set of Graph objects.public static void showPoint(Graphics2D g, Point2D.Double p)
g
- context in which to drawp
- point being displayed.public static Color getDarkest(Color c1, Color c2)
public static void grow(Rectangle2D.Double r, double xinc, double yinc)
public static Point2D.Double getCenter(Rectangle2D.Double r)
public static ArrayList<ArrayList<GNode>> getConnectedComponents(Graph g)
private static void labelConnectedNodes(HashMap<GNode,Integer> componentLabels, GNode startNode, int componentNum)
startNode
- public static Point2D.Double getCenterPoint(ArrayList<GNode> nodes)
nodes
- public static GNode closestObject(ArrayList<GNode> nodes, Point2D.Double point)
public static boolean verifyIntegrityOfGraph(Graph g)
General.error(java.lang.String)
public static void showMessageDialog(Component parentComponent, Object message)