Class pmr.simplegraph.SimpleGraph
All Packages Class Hierarchy This Package Previous Next Index
Class pmr.simplegraph.SimpleGraph
java.lang.Object
|
+----pmr.simplegraph.SimpleGraph
- public class SimpleGraph
- extends Object
a set of routines for various simple graphics operations that either
are provided by java at present, or encapsulate some complex and commonly
used operations. Most are static.
- Author:
- (C) P. Murray-Rust, 1996
-
SimpleGraph()
-
-
addAfterMenuItem(MenuBar, String, Menu)
- adds the Menu 'menu' after the Menu with label 'after' on
MenuBar menuBar.
-
addBeforeMenuItem(Menu, String, MenuItem)
- adds the MenuItem 'mi' before the MenuItem with label 'before'.
-
addBeforeMenuItem(Menu, String, String)
- adds the String 'label' before the MenuItem with label 'before'.
-
addWithConstraints(Container, Component, int, int, int, int, int, int, double, double, int, int, int, int)
- grid bag contraints (lifted from Java in a Nutshell, p111) with thanx
-
continueBox(Frame)
- asks user to continue (and blocks till then)
-
drawArrow(Graphics, int, int, int, int)
- needs work - only draws a line at present
-
drawLine(Graphics, int, int, int, int, int)
- crude routine for drawing thick lines till Java do it better
-
drawString(Graphics, String, int, int)
- draws a string at a given position and returns the new coordinates of the
'cursor.
-
error(Frame, String)
- public static void setErrorOutput(Dialog d) {
errorDialog = d;
if (d == null) {
System.err.println("MESSAGES BEING RE-ROUTED TO STDERR");
}
}
-
error(String)
-
-
getFont(Graphics, String, int, int)
- does the same, but allows just certain fields to be filled in and the
others default to the current font (if none, chooses default); e.g.
-
getFont(String, int, int)
- caches fonts; this is because "new Font" is SO SLOW!!!
-
getMenu(MenuBar, String)
- get a Menu by name from a MenuBar; if not present, returns
null; thus getMenu(menubar, "Edit") returns the Edit menu if one
exists
-
getMenuIndex(MenuBar, String)
- get the index of a Menu by name from a MenuBar; if not present, returns
-1; thus getMenu(menubar, "Edit") returns the index of the Edit menu
if one exists
-
getMenuItem(Menu, String)
- get a MenuItem by name from a Menu; if not present, returns
null; thus getMenuItem(menu, "Quit") returns the Quit menu item if one
exists
-
getMenuItemIndex(Menu, String)
- get the index of a MenuItem by name from a Menu; if not present, returns
-1; thus getMenuItem(menu, "Quit") returns the index of the Quit menu
item if one exists.
-
getMenuLabels(MenuItem)
- interpret menu item as a hierachy of labels (i.e.
-
getPixelHeight(Graphics, String)
- gets height of String in pixels (neglects descenders)
-
getPixelLength(Graphics, String)
- gets length of String in pixels
-
getTargetType(String, String)
- parses target (e.g.
-
getXLength(Component, String)
- gets length of String in pixels
-
message(String)
-
-
outputToSelectedFile(String, Frame, String)
- select a file with the browser and output a string to it.
-
selectFile(Frame, String)
- select a file using the browser
-
setMessageOutput(TextArea)
- message output
Under development
SimpleGraph
public SimpleGraph()
drawLine
public static void drawLine(Graphics g,
int x0,
int y0,
int x1,
int y1,
int thickness)
- crude routine for drawing thick lines till Java do it better
getFont
public static Font getFont(String name,
int style,
int size)
- caches fonts; this is because "new Font" is SO SLOW!!!
getFont
public static Font getFont(Graphics g,
String name,
int style,
int size)
- does the same, but allows just certain fields to be filled in and the
others default to the current font (if none, chooses default); e.g.
name = "", style = 0, size = 0 will force the current font
getXLength
public static int getXLength(Component comp,
String text)
- gets length of String in pixels
getPixelLength
public static int getPixelLength(Graphics g,
String text)
- gets length of String in pixels
getPixelHeight
public static int getPixelHeight(Graphics g,
String text)
- gets height of String in pixels (neglects descenders)
drawArrow
public static void drawArrow(Graphics g,
int x1,
int y1,
int x2,
int y2)
- needs work - only draws a line at present
setMessageOutput
public static void setMessageOutput(TextArea t)
- message output
Under development
message
public static void message(String s)
error
public static void error(Frame frame,
String s)
- public static void setErrorOutput(Dialog d) {
errorDialog = d;
if (d == null) {
System.err.println("MESSAGES BEING RE-ROUTED TO STDERR");
}
}
continueBox
public static void continueBox(Frame frame)
- asks user to continue (and blocks till then)
error
public static void error(String s)
getTargetType
public static String getTargetType(String prefix,
String string)
- parses target (e.g. from Event) such as
java.awt.List[232,5,136x75,selected=MOL_adrenalin] or just
MyList[...]
to give the type (e.g. List); (returns "" if not of this type). Prefix
is the classpath (e.g. java.awt. - note trailing dot)
addWithConstraints
public static void addWithConstraints(Container container,
Component component,
int xPos,
int yPos,
int width,
int height,
int fill,
int anchor,
double xWeight,
double yWeight,
int top,
int left,
int bottom,
int right)
- grid bag contraints (lifted from Java in a Nutshell, p111) with thanx
drawString
public static Int2 drawString(Graphics g,
String s,
int x,
int y)
- draws a string at a given position and returns the new coordinates of the
'cursor. The y distance is calcuated on the basis that the value increases
by the size of the font. Thus to produce a 'newline', the new y value should
be taken; to stay on the old line, keep y unchanged.
outputToSelectedFile
public static void outputToSelectedFile(String s,
Frame f,
String currentDirectory) throws IOException
- select a file with the browser and output a string to it.
- Throws: IOException
- an output exception occurred
selectFile
public static File selectFile(Frame f,
String currentDirectory)
- select a file using the browser
- Parameters:
- currentDirectory - null or "" if not known
getMenuIndex
public static int getMenuIndex(MenuBar menuBar,
String label)
- get the index of a Menu by name from a MenuBar; if not present, returns
-1; thus getMenu(menubar, "Edit") returns the index of the Edit menu
if one exists
getMenu
public static Menu getMenu(MenuBar menuBar,
String label)
- get a Menu by name from a MenuBar; if not present, returns
null; thus getMenu(menubar, "Edit") returns the Edit menu if one
exists
getMenuItemIndex
public static int getMenuItemIndex(Menu menu,
String label)
- get the index of a MenuItem by name from a Menu; if not present, returns
-1; thus getMenuItem(menu, "Quit") returns the index of the Quit menu
item if one exists.
getMenuItem
public static MenuItem getMenuItem(Menu menu,
String label)
- get a MenuItem by name from a Menu; if not present, returns
null; thus getMenuItem(menu, "Quit") returns the Quit menu item if one
exists
getMenuLabels
public static String[] getMenuLabels(MenuItem mi)
- interpret menu item as a hierachy of labels (i.e. get the parent
MenuItem's label (and so on upwards). "File | Quit" is returned
as the Strings "File" and "Quit" in that order. This can be useful for
processing menu events by Event.target, as the hierarchy defines the menu.
addAfterMenuItem
public static void addAfterMenuItem(MenuBar menuBar,
String after,
Menu menu)
- adds the Menu 'menu' after the Menu with label 'after' on
MenuBar menuBar.
If 'after' doesn't exist, adds it at the beginning.
addBeforeMenuItem
public static void addBeforeMenuItem(Menu menu,
String before,
String label)
- adds the String 'label' before the MenuItem with label 'before'.
If this doesn't exist, adds it at the end
addBeforeMenuItem
public static void addBeforeMenuItem(Menu menu,
String before,
MenuItem mi)
- adds the MenuItem 'mi' before the MenuItem with label 'before'.
If this doesn't exist, adds it at the end
All Packages Class Hierarchy This Package Previous Next Index