edu.mit.csail.sdg.alloy4
Class OurUtil

java.lang.Object
  extended by edu.mit.csail.sdg.alloy4.OurUtil

public final class OurUtil
extends java.lang.Object

Graphical convenience methods.

Thread Safety: Can be called only by the AWT event thread.


Method Summary
static javax.swing.JButton button(java.lang.String label, java.lang.String tip, java.lang.String iconFileName, java.awt.event.ActionListener func)
          Make a graphical button
static void enableAll(javax.swing.JMenu menu)
          Convenience method that recursively enables every JMenu and JMenuItem inside "menu".
static int getScreenHeight()
          Returns the screen height (in pixels).
static int getScreenWidth()
          Returns the screen width (in pixels).
static java.awt.Font getVizFont()
          Returns the recommended font to use in the visualizer, based on the OS.
static javax.swing.JLabel label(java.lang.String label, java.lang.Object... attributes)
          Make a JLabel, then call Util.make() to apply a set of attributes to it.
static javax.swing.Icon loadIcon(java.lang.String pathname)
          Load the given image file from an accompanying JAR file, and return it as an Icon object.
static
<X extends javax.swing.JComponent>
X
make(X obj, java.lang.Object... attributes)
          Assign the given attributes to the given JComponent, then return the JComponent again.
static javax.swing.JPanel makeH(java.lang.Object... components)
          Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be center-aligned).
static javax.swing.JPanel makeHB(java.lang.Object... components)
          Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be bottom-aligned).
static javax.swing.JPanel makeHT(java.lang.Object... components)
          Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be top-aligned).
static javax.swing.JPanel makeVL(java.lang.Object... components)
          Make a JPanel using vertical BoxLayout, and add the components to it (each component will be left-aligned).
static javax.swing.JPanel makeVR(java.lang.Object... components)
          Make a JPanel using vertical BoxLayout, and add the components to it (each component will be right-aligned).
static javax.swing.JMenu menu(javax.swing.JMenuBar parent, java.lang.String label, java.lang.Runnable func)
          Construct a new JMenu and add it to an existing JMenuBar.
static javax.swing.JMenuItem menuItem(javax.swing.JMenu parent, java.lang.String label, java.lang.Object... attrs)
          Construct a new JMenuItem then add it to an existing JMenu.
static void minimize(javax.swing.JFrame frame)
          This method minimizes the window.
static javax.swing.JScrollPane scrollpane(java.awt.Component component, java.lang.Object... attributes)
          Make a JScrollPane containing the given component (which can be null), then apply a set of attributes to it.
static void show(javax.swing.JFrame frame)
          Make the frame visible, non-iconized, and focused.
static javax.swing.JSplitPane splitpane(int orientation, java.awt.Component first, java.awt.Component second, int initialDividerLocation)
          Constructs a new SplitPane containing the two components given as arguments
static javax.swing.JTextArea textarea(java.lang.String text, int rows, int columns, boolean editable, boolean wrap, java.lang.Object... attributes)
          Make a JTextArea with the given text and number of rows and columns, then call Util.make() to apply a set of attributes to it.
static javax.swing.JTextField textfield(java.lang.String text, int columns, java.lang.Object... attributes)
          Make a JTextField with the given text and number of columns, then call Util.make() to apply a set of attributes to it.
static void zoom(javax.swing.JFrame frame)
          This method alternatingly maximizes or restores the window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

make

public static <X extends javax.swing.JComponent> X make(X obj,
                                                        java.lang.Object... attributes)
Assign the given attributes to the given JComponent, then return the JComponent again.

If Font x is given in the list, we call obj.setFont(x)

If String x is given in the list, we call obj.setToolTipText(x)

If Border x is given in the list, we call obj.setBorder(x)

If Dimension x is given in the list, we call obj.setPreferredSize(x)

If Color x is given in the list, and it's the first color, we call obj.setForeground(x)

If Color x is given in the list, and it's not the first color, we call obj.setBackground(x) then obj.setOpaque(true)

(If no Font is given, then after all these changes have been applied, we will call obj.setFont() will a default font)


label

public static javax.swing.JLabel label(java.lang.String label,
                                       java.lang.Object... attributes)
Make a JLabel, then call Util.make() to apply a set of attributes to it.

Parameters:
attributes - - see OurUtil.make(component, attributes...)

textfield

public static javax.swing.JTextField textfield(java.lang.String text,
                                               int columns,
                                               java.lang.Object... attributes)
Make a JTextField with the given text and number of columns, then call Util.make() to apply a set of attributes to it.

Parameters:
attributes - - see OurUtil.make(component, attributes...)

textarea

public static javax.swing.JTextArea textarea(java.lang.String text,
                                             int rows,
                                             int columns,
                                             boolean editable,
                                             boolean wrap,
                                             java.lang.Object... attributes)
Make a JTextArea with the given text and number of rows and columns, then call Util.make() to apply a set of attributes to it.

Parameters:
attributes - - see OurUtil.make(component, attributes...)

scrollpane

public static javax.swing.JScrollPane scrollpane(java.awt.Component component,
                                                 java.lang.Object... attributes)
Make a JScrollPane containing the given component (which can be null), then apply a set of attributes to it.

Parameters:
attributes - - see OurUtil.make(component, attributes...)

getVizFont

public static java.awt.Font getVizFont()
Returns the recommended font to use in the visualizer, based on the OS.


getScreenWidth

public static int getScreenWidth()
Returns the screen width (in pixels).


getScreenHeight

public static int getScreenHeight()
Returns the screen height (in pixels).


button

public static javax.swing.JButton button(java.lang.String label,
                                         java.lang.String tip,
                                         java.lang.String iconFileName,
                                         java.awt.event.ActionListener func)
Make a graphical button

Parameters:
label - - the text to show beneath the button
tip - - the tooltip to show when the mouse hovers over the button
iconFileName - - if nonnull, it's the filename of the icon to show (it will be loaded from an accompanying jar file)
func - - if nonnull, it's the function to call when the button is pressed

loadIcon

public static javax.swing.Icon loadIcon(java.lang.String pathname)
Load the given image file from an accompanying JAR file, and return it as an Icon object.


makeH

public static javax.swing.JPanel makeH(java.lang.Object... components)
Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be center-aligned).
If a component is Color, it's the background of this JPanel and every component after it (until we see another Color)
If a component is Dimension, we will set it as the newly constructed JPanel's preferedSize and MaximumSize.
If a component is String, we will insert a JLabel with it as the label.
If a component is Integer, we will insert an "n*1" (or "1*n") rigid area instead.
If a component is null, we will insert a horizontal (or vertical) glue instead.


makeHT

public static javax.swing.JPanel makeHT(java.lang.Object... components)
Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be top-aligned).
If a component is Color, it's the background of this JPanel and every component after it (until we see another Color)
If a component is Dimension, we will set it as the newly constructed JPanel's preferedSize and MaximumSize.
If a component is String, we will insert a JLabel with it as the label.
If a component is Integer, we will insert an "n*1" (or "1*n") rigid area instead.
If a component is null, we will insert a horizontal (or vertical) glue instead.


makeHB

public static javax.swing.JPanel makeHB(java.lang.Object... components)
Make a JPanel using horizontal BoxLayout, and add the components to it (each component will be bottom-aligned).
If a component is Color, it's the background of this JPanel and every component after it (until we see another Color)
If a component is Dimension, we will set it as the newly constructed JPanel's preferedSize and MaximumSize.
If a component is String, we will insert a JLabel with it as the label.
If a component is Integer, we will insert an "n*1" (or "1*n") rigid area instead.
If a component is null, we will insert a horizontal (or vertical) glue instead.


makeVL

public static javax.swing.JPanel makeVL(java.lang.Object... components)
Make a JPanel using vertical BoxLayout, and add the components to it (each component will be left-aligned).
If a component is Color, it's the background of this JPanel and every component after it (until we see another Color)
If a component is Dimension, we will set it as the newly constructed JPanel's preferedSize and MaximumSize.
If a component is String, we will insert a JLabel with it as the label.
If a component is Integer, we will insert an "n*1" (or "1*n") rigid area instead.
If a component is null, we will insert a horizontal (or vertical) glue instead.


makeVR

public static javax.swing.JPanel makeVR(java.lang.Object... components)
Make a JPanel using vertical BoxLayout, and add the components to it (each component will be right-aligned).
If a component is Color, it's the background of this JPanel and every component after it (until we see another Color)
If a component is Dimension, we will set it as the newly constructed JPanel's preferedSize and MaximumSize.
If a component is String, we will insert a JLabel with it as the label.
If a component is Integer, we will insert an "n*1" (or "1*n") rigid area instead.
If a component is null, we will insert a horizontal (or vertical) glue instead.


splitpane

public static javax.swing.JSplitPane splitpane(int orientation,
                                               java.awt.Component first,
                                               java.awt.Component second,
                                               int initialDividerLocation)
Constructs a new SplitPane containing the two components given as arguments

Parameters:
orientation - - the orientation (HORIZONTAL_SPLIT or VERTICAL_SPLIT)
first - - the left component (if horizontal) or top component (if vertical)
second - - the right component (if horizontal) or bottom component (if vertical)
initialDividerLocation - - the initial divider location (in pixels)

enableAll

public static void enableAll(javax.swing.JMenu menu)
Convenience method that recursively enables every JMenu and JMenuItem inside "menu".

Parameters:
menu - - the menu to start the recursive search

menu

public static javax.swing.JMenu menu(javax.swing.JMenuBar parent,
                                     java.lang.String label,
                                     java.lang.Runnable func)
Construct a new JMenu and add it to an existing JMenuBar.

Note: every time the user expands then collapses this JMenu, we automatically enable all JMenu and JMenuItem objects in it.

Parameters:
parent - - the JMenuBar to add this Menu into (or null if we don't want to add it to a JMenuBar yet)
label - - the label to show on screen (if it contains '&' followed by 'a'..'z', we'll remove '&' and use it as mnemonic)
func - - if nonnull we'll call its "run()" method right before expanding this menu

menuItem

public static javax.swing.JMenuItem menuItem(javax.swing.JMenu parent,
                                             java.lang.String label,
                                             java.lang.Object... attrs)
Construct a new JMenuItem then add it to an existing JMenu.

Parameters:
parent - - the JMenu to add this JMenuItem into (or null if you don't want to add it to any JMenu yet)
label - - the text to show on the menu
attrs - - a list of attributes to apply onto the new JMenuItem

If one positive number a is supplied, we call setMnemonic(a)

If two positive numbers a and b are supplied, and a!=VK_ALT, and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)

If two positive numbers a and b are supplied, and a==VK_ALT or a==VK_SHIFT, we call setAccelerator(a | b)

If an ActionListener is supplied, we call addActionListener(x)

If an Boolean x is supplied, we call setEnabled(x)

If an Icon x is supplied, we call setIcon(x)


minimize

public static void minimize(javax.swing.JFrame frame)
This method minimizes the window.


zoom

public static void zoom(javax.swing.JFrame frame)
This method alternatingly maximizes or restores the window.


show

public static void show(javax.swing.JFrame frame)
Make the frame visible, non-iconized, and focused.