verinec.gui
Class GuiUtil

java.lang.Object
  extended by verinec.gui.GuiUtil

public class GuiUtil
extends Object

Contains utility methods for GUI operations.

Author:
david.buchmann at unifr.ch

Nested Class Summary
static class GuiUtil.ColorChooseAction
          Action class for the color chooser button.
(package private) static class GuiUtil.InvertFilter
          Invert filter for RGB images.
static class GuiUtil.SpringUtilities
          A helper class that provides utility methods for creating form- or grid-style layouts with SpringLayout.
 
Field Summary
static String DECONNECT_ICON
          Icon location for deconnect symbol.
static String DELETE_ICON
          Icon location for delete symbol.
static String IMPORT_ICON
          Icon location for import symbol.
static String IPOK_ICON
          Icon location for ip ok symbol.
static String MOVEDOWN_ICON
          Icon location for move interface down symbol.
static String MOVELEFT_ICON
          Icon location for move interface left symbol.
static String MOVERIGHT_ICON
          Icon location for move interface right symbol.
static String MOVEUP_ICON
          Icon location for move interface up symbol.
static String OK_ICON
          Icon location for ok symbol.
static String PROPERTIES_ICON
          Icon location for properties symbol.
static String SEND_ICON
          Icon location for send symbol.
 
Constructor Summary
private GuiUtil()
          Never instantiate GuiUtil, it contains only static methods.
 
Method Summary
static Element Color2Xml(Color c, Element e)
          Convert a color object to an XML element.
private static NwHub connectBinding(VerinecStudio studio, NwBinding src, NwBinding bind)
          Connect two bindings, creating a hub in between.
private static void connectHub(VerinecStudio studio, NwComponent c, NwHub hub)
          Connect a binding or interface with an existing hub.
private static NwHub connectInterface(VerinecStudio studio, NwInterface src, NwInterface bi)
          Connect two interfaces, creating a hub in between.
static NwHub connectNetwork(VerinecStudio studio, NwComponent start, NwComponent dest)
          Connect two interfaces / bindings together.
static void deepEnable(Container c, boolean enable)
          Recursively change setEnabled for a container and all its components.
static void drawStringCentered(Graphics2D g2, String text, int x, int y)
          String will be horizontally centered around x.
static ImageProducer getInversePicture(Image image)
          Calculates the inverse picture of a image.
static Rectangle2D getStringCenteredLocation(Graphics2D g2, String text, int x, int y)
          Get the location of a string as it would be used by drawStringCentered.
static String isCompatible(NwComponent c1, NwComponent c2)
          Test if two components might be connected.
static ImageIcon loadIcon(Object context, String name)
          Loads an image either using getResource() or from the file system.
static void removeAllMouseListeners(Component c)
          Removes all mouse listeners from a component.
static void removeAllMouseMotionListeners(Component c)
          Removes all mouse motion listeners from a component.
static Color Xml2Color(Element e)
          Convert an XML element to a java.awt.Color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK_ICON

public static final String OK_ICON
Icon location for ok symbol.

See Also:
Constant Field Values

DELETE_ICON

public static final String DELETE_ICON
Icon location for delete symbol.

See Also:
Constant Field Values

PROPERTIES_ICON

public static final String PROPERTIES_ICON
Icon location for properties symbol.

See Also:
Constant Field Values

DECONNECT_ICON

public static final String DECONNECT_ICON
Icon location for deconnect symbol.

See Also:
Constant Field Values

SEND_ICON

public static final String SEND_ICON
Icon location for send symbol.

See Also:
Constant Field Values

IPOK_ICON

public static final String IPOK_ICON
Icon location for ip ok symbol.

See Also:
Constant Field Values

IMPORT_ICON

public static final String IMPORT_ICON
Icon location for import symbol.

See Also:
Constant Field Values

MOVERIGHT_ICON

public static final String MOVERIGHT_ICON
Icon location for move interface right symbol.

See Also:
Constant Field Values

MOVEDOWN_ICON

public static final String MOVEDOWN_ICON
Icon location for move interface down symbol.

See Also:
Constant Field Values

MOVELEFT_ICON

public static final String MOVELEFT_ICON
Icon location for move interface left symbol.

See Also:
Constant Field Values

MOVEUP_ICON

public static final String MOVEUP_ICON
Icon location for move interface up symbol.

See Also:
Constant Field Values
Constructor Detail

GuiUtil

private GuiUtil()
Never instantiate GuiUtil, it contains only static methods.

Method Detail

loadIcon

public static ImageIcon loadIcon(Object context,
                                 String name)
                          throws VerinecException
Loads an image either using getResource() or from the file system. This allows you to place the icon files into the jar. By convention, the files should be placed in the pictures directory, resulting in the path /pictures/sample.jpg . See java.lang.class.getResource for more information about specifying the location. If the resource is not found as a resource, this method looks if the string could denote a path in the file system and loads the icon from file system if it finds it.

Parameters:
context - The calling class, usually 'this'.
name - The image path to load.
Returns:
The Icon corresponding to name.
Throws:
VerinecException - If the icon can not be found or is no valid image.
NullPointerException - If either parameter is null.

getInversePicture

public static ImageProducer getInversePicture(Image image)
Calculates the inverse picture of a image. Use with Component.newImage(ImageProduces).

Parameters:
image - the image to be inversed.
Returns:
the inverse picture of the passed image instance

connectNetwork

public static NwHub connectNetwork(VerinecStudio studio,
                                   NwComponent start,
                                   NwComponent dest)
                            throws IllegalArgumentException
Connect two interfaces / bindings together. The parameters must be compatible as defined in isCompatible(NwComponent, NwComponent)

Parameters:
studio - Main application used to create hubs and wires.
start - Start component
dest - Destination component
Returns:
If a hub has to be created, the newly created hub is returned, otherwise null
Throws:
IllegalArgumentException - If the parameters are not compatible.

connectHub

private static void connectHub(VerinecStudio studio,
                               NwComponent c,
                               NwHub hub)
Connect a binding or interface with an existing hub.

Parameters:
studio - Main app to create wire
c - The binding or interface
hub - The hub to connect to

connectBinding

private static NwHub connectBinding(VerinecStudio studio,
                                    NwBinding src,
                                    NwBinding bind)
Connect two bindings, creating a hub in between.

Parameters:
studio - Main app to create wires and hub
src - The first binding
bind - The second binding
Returns:
The newly created hub.

connectInterface

private static NwHub connectInterface(VerinecStudio studio,
                                      NwInterface src,
                                      NwInterface bi)
Connect two interfaces, creating a hub in between.

Parameters:
studio - Main app to create wires and hub
src - The first interface
bi - The second interface
Returns:
The newly created hub.

isCompatible

public static String isCompatible(NwComponent c1,
                                  NwComponent c2)
Test if two components might be connected. The parameters may be of the following types, and must be of matching network type: s

Parameters:
c1 - First component to test.
c2 - Target component to test.
Returns:
Error message or null if compatible.

removeAllMouseListeners

public static void removeAllMouseListeners(Component c)
Removes all mouse listeners from a component. (There seems to be no such method in awt.Component)

Parameters:
c - The component to remove mouse listeners from.

removeAllMouseMotionListeners

public static void removeAllMouseMotionListeners(Component c)
Removes all mouse motion listeners from a component. (There seems to be no such method in awt.Component)

Parameters:
c - The component to remove mouse listeners from.

deepEnable

public static void deepEnable(Container c,
                              boolean enable)
Recursively change setEnabled for a container and all its components.

Parameters:
c - A container to set enabled on.
enable - Whether everything is to enable or not.

drawStringCentered

public static void drawStringCentered(Graphics2D g2,
                                      String text,
                                      int x,
                                      int y)
String will be horizontally centered around x. vertically it will be below the y.

Parameters:
g2 - The graphics context
text - Text to draw
x - Coordinate to center horizontally
y - Vertical top line

getStringCenteredLocation

public static Rectangle2D getStringCenteredLocation(Graphics2D g2,
                                                    String text,
                                                    int x,
                                                    int y)
Get the location of a string as it would be used by drawStringCentered. String will be horizontally centered around x, vertically it will be below the y.

Parameters:
g2 - The graphics context
text - Text to draw
x - Coordinate to center horizontally
y - Vertical top line
Returns:
A rectangle which is exactly where the string will be drawn.

Xml2Color

public static Color Xml2Color(Element e)
Convert an XML element to a java.awt.Color.

Parameters:
e - The element with attributes r, g and b, denoting integer values from 0-255.
Returns:
A color object with the three color components.

Color2Xml

public static Element Color2Xml(Color c,
                                Element e)
Convert a color object to an XML element.

Parameters:
c - The color to use.
e - An XML element to set the attributes r, g and b to the integer values from 0-255 of color c.
Returns:
The parameter e.

Copyright © 2005 Verinec, DIUF