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

Constructor Index

 o SimpleGraph()

Method Index

 o addAfterMenuItem(MenuBar, String, Menu)
adds the Menu 'menu' after the Menu with label 'after' on MenuBar menuBar.
 o addBeforeMenuItem(Menu, String, MenuItem)
adds the MenuItem 'mi' before the MenuItem with label 'before'.
 o addBeforeMenuItem(Menu, String, String)
adds the String 'label' before the MenuItem with label 'before'.
 o 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
 o continueBox(Frame)
asks user to continue (and blocks till then)
 o drawArrow(Graphics, int, int, int, int)
needs work - only draws a line at present
 o drawLine(Graphics, int, int, int, int, int)
crude routine for drawing thick lines till Java do it better
 o drawString(Graphics, String, int, int)
draws a string at a given position and returns the new coordinates of the 'cursor.
 o error(Frame, String)
public static void setErrorOutput(Dialog d) { errorDialog = d; if (d == null) { System.err.println("MESSAGES BEING RE-ROUTED TO STDERR"); } }
 o error(String)
 o 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.
 o getFont(String, int, int)
caches fonts; this is because "new Font" is SO SLOW!!!
 o 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
 o 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
 o 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
 o 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.
 o getMenuLabels(MenuItem)
interpret menu item as a hierachy of labels (i.e.
 o getPixelHeight(Graphics, String)
gets height of String in pixels (neglects descenders)
 o getPixelLength(Graphics, String)
gets length of String in pixels
 o getTargetType(String, String)
parses target (e.g.
 o getXLength(Component, String)
gets length of String in pixels
 o message(String)
 o outputToSelectedFile(String, Frame, String)
select a file with the browser and output a string to it.
 o selectFile(Frame, String)
select a file using the browser
 o setMessageOutput(TextArea)
message output

Under development

Constructors

 o SimpleGraph
  public SimpleGraph()

Methods

 o 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
 o getFont
  public static Font getFont(String name,
                             int style,
                             int size)
caches fonts; this is because "new Font" is SO SLOW!!!
 o 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
 o getXLength
  public static int getXLength(Component comp,
                               String text)
gets length of String in pixels
 o getPixelLength
  public static int getPixelLength(Graphics g,
                                   String text)
gets length of String in pixels
 o getPixelHeight
  public static int getPixelHeight(Graphics g,
                                   String text)
gets height of String in pixels (neglects descenders)
 o drawArrow
  public static void drawArrow(Graphics g,
                               int x1,
                               int y1,
                               int x2,
                               int y2)
needs work - only draws a line at present
 o setMessageOutput
  public static void setMessageOutput(TextArea t)
message output

Under development

 o message
  public static void message(String s)
 o 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"); } }
 o continueBox
  public static void continueBox(Frame frame)
asks user to continue (and blocks till then)
 o error
  public static void error(String s)
 o 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)

 o 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
 o 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.
 o 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
 o selectFile
  public static File selectFile(Frame f,
                                String currentDirectory)
select a file using the browser
Parameters:
currentDirectory - null or "" if not known
 o 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
 o 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
 o 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.
 o 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
 o 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.
 o 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.
 o 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
 o 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