nip
Class NIP

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by nip.NIP
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class NIP
extends javax.swing.JFrame

NIP is an application skeleton that can be used as a starting point for a variety of projects involving image manipulation and graphics.

The NIP User Interface:

Creating Tools for NIP:

One of the main purposes of NIP is to support image processing, but NIP doesn't have built-in functions for this. Instead, your program will supply various image processing tools for NIP to use. These tools will appear as a set of buttons on the left edge of the NIP window. When the user selects a tool, NIP will call the tool's Tool.getEventNames() method to add a list of commands to the Methods menu in the NIP window. When the user clicks one of these commands, the Tool.actionNameCalled(String) method in the Tool is triggered, with the name of the command clicked as the parameter. The tool can then respond appropriately. Tools can also react to mouse events which occur on the NIP GraphicsPanels by overriding the mouse events in the Tool class, which do nothing on their own. More information can be found in the Tool class.

Note that a NIP window is created with one or more GraphicsPanel objects, each with a certain width and height in pixels. The panels are displayed left to right, and they are numbered from 0. That is, the leftmost is panel 0, the next one is panel 1, and so on. Users can load images into NIP as described above, but NIP also has constructors that let you specify images to be loaded into the panels upon initialization, so that you don't have to load them in manually each time you run NIP. In addition, a tool can call methods on a GraphicsPanel to load in a background image and to display additional images, shapes, lines, etc. There are methods for accessing the GraphicsPanels (and their associated Images) that have been marked as Source(s) or Targets by the user; also there is a method to access a specific GraphicsPanel (see below).

NIP is a modification of YOPS, an application created by Professor Ken Goldman to play the same purpose as NIP, and provided much of the same functionality. This main class has been changed a fair amount to remove the reflection found in YOPS as well as to generally simplify the way it works. Some of the other classes were slightly modified, while many are unchanged.

Author:
Jonathon Lundy June 2009 Adapted from the work of Professor Ken Goldman, July 2005
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NIP()
          Creates a NIP with one panel of a default width and height.
NIP(int width, int height)
          Creates a NIP with one panel of the given width and height
NIP(int width, int height, int numPanels)
          Creates a NIP with the given number of panels, each with the same given width and height.
NIP(int width, int height, int numPanels, java.lang.String... imageFileNames)
          Creates a NIP with the given number of panels, each with the same given width and height.
NIP(Tool tool)
          Creates a NIP with one panel of a default width and height, and with the given tool.
NIP(Tool tool, int numPanels)
          Creates a NIP with the given tool and given number of panels, each of a default width and height.
NIP(Tool tool, int width, int height)
          Creates a NIP with the given tool and one panel of the given width and height.
NIP(Tool tool, int width, int height, int numPanels)
          Creates a NIP with the given tool and the given number of panels, each of the given width and height.
NIP(Tool tool, int width, int height, int numPanels, java.lang.String... imageFileNames)
          Creates a NIP with the given tool and the given number of panels, each of the given width and height, and with one or more provided image files loaded as the background images of the panels, left to right.
 
Method Summary
 void addTool(Tool tool)
          Adds the given tool to a user-selectable list.
static java.applet.Applet getApplet()
           
 GraphicsPanel getGraphicsPanel(int panelNumber)
          Returns the GraphicsPanel for the given index, where 0 is the leftmost panel, 1 is the next panel, and so on.
 int getNumPanels()
          Gets the number of GraphicsPanels in this NIP object.
 Image getPrimarySourceImage()
          Returns the Image associated with the GraphicsPanel currently selected as Source 1 by the user.
 GraphicsPanel getPrimarySourcePanel()
          Returns the GraphicsPanel currently selected as Source 1 by the user.
 Image getSecondarySourceImage()
          Returns the Image associated with the GraphicsPanel currently selected as Source 2 by the user.
 GraphicsPanel getSecondarySourcePanel()
          Returns the GraphicsPanel currently selected as Source 2 by the user.
 java.lang.String getStatusText()
          Returns the status text currently displayed at the bottom of the NIP window.
 Image getTargetImage()
          Returns the Image associated with the GraphicsPanel currently selected as the target by the user.
 GraphicsPanel getTargetPanel()
          Returns the GraphicsPanel currently selected as the target by the user.
 Tool getTool()
          Gets the current tool.
static void setApplet(java.applet.Applet applet)
          When NIP is used within an Applet, this static method should be called before the first call to the NIP constructor.
 void setStatusText(java.lang.String str)
          Updates the status text at the bottom of the NIP window to the provided text.
 void setTool(Tool tool)
          Sets the current tool of this NIP to the provided object.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

NIP

public NIP()
Creates a NIP with one panel of a default width and height.


NIP

public NIP(int width,
           int height)
Creates a NIP with one panel of the given width and height

Parameters:
width - in pixels
height - in pixels

NIP

public NIP(int width,
           int height,
           int numPanels)
Creates a NIP with the given number of panels, each with the same given width and height.

Parameters:
width - in pixels
height - in pixels
numPanels - the number of panels to be created

NIP

public NIP(int width,
           int height,
           int numPanels,
           java.lang.String... imageFileNames)
Creates a NIP with the given number of panels, each with the same given width and height.

Parameters:
width - in pixels
height - in pixels
numPanels - the number of panels to be created
imageFileNames - - one or more Strings naming the images to be loaded into panels, left to right

NIP

public NIP(Tool tool)
Creates a NIP with one panel of a default width and height, and with the given tool. (See the NIP overview for details about tools.)

Parameters:
tool - the tool whose methods should be made available to the user

NIP

public NIP(Tool tool,
           int numPanels)
Creates a NIP with the given tool and given number of panels, each of a default width and height. (See the NIP overview for details about tools.)

Parameters:
tool - the tool whose methods should be made available to the user
numPanels - the number of panels to be created

NIP

public NIP(Tool tool,
           int width,
           int height)
Creates a NIP with the given tool and one panel of the given width and height. (See the NIP overview for details about tools.)

Parameters:
tool - the tool whose methods should be made available to the user
width - in pixels
height - in pixels

NIP

public NIP(Tool tool,
           int width,
           int height,
           int numPanels)
Creates a NIP with the given tool and the given number of panels, each of the given width and height. (See the NIP overview for details about tools.)

Parameters:
tool - the tool whose methods should be made available to the user
width - in pixels
height - in pixels
numPanels - the number of panels to be created

NIP

public NIP(Tool tool,
           int width,
           int height,
           int numPanels,
           java.lang.String... imageFileNames)
Creates a NIP with the given tool and the given number of panels, each of the given width and height, and with one or more provided image files loaded as the background images of the panels, left to right. If the number of image file names exceeds the number of panels, then the extra file names are ignored. (See the NIP overview for details about tools.)

Parameters:
tool - the tool whose methods should be made available to the user
width - in pixels
height - in pixels
numPanels - the number of panels to be created
imageFileNames - - one or more Strings naming the images to be loaded into panels, left to right
Method Detail

getGraphicsPanel

public GraphicsPanel getGraphicsPanel(int panelNumber)
Returns the GraphicsPanel for the given index, where 0 is the leftmost panel, 1 is the next panel, and so on.

Parameters:
panelNumber - the index of the desired GraphicsPanel within this NIP
Returns:
the GraphicsPanel for the given index

getNumPanels

public int getNumPanels()
Gets the number of GraphicsPanels in this NIP object.

Returns:
Number of panels.

getPrimarySourcePanel

public GraphicsPanel getPrimarySourcePanel()
Returns the GraphicsPanel currently selected as Source 1 by the user.

Returns:
The primary source GraphicsPanel object.

getSecondarySourcePanel

public GraphicsPanel getSecondarySourcePanel()
Returns the GraphicsPanel currently selected as Source 2 by the user.

Returns:
The secondary source GraphicsPanel object.

getTargetPanel

public GraphicsPanel getTargetPanel()
Returns the GraphicsPanel currently selected as the target by the user.

Returns:
The target GraphicsPanel object.

getPrimarySourceImage

public Image getPrimarySourceImage()
Returns the Image associated with the GraphicsPanel currently selected as Source 1 by the user.

Returns:
The primary source Image object.

getSecondarySourceImage

public Image getSecondarySourceImage()
Returns the Image associated with the GraphicsPanel currently selected as Source 2 by the user.

Returns:
The secondary source Image object.

getTargetImage

public Image getTargetImage()
Returns the Image associated with the GraphicsPanel currently selected as the target by the user.

Returns:
The target Image object.

setTool

public void setTool(Tool tool)
Sets the current tool of this NIP to the provided object. If there is already a tool, then it is replaced with the new one. If the parameter is null, then no tool methods will be used. Note that the method setTool automatically calls addListener for the given tool, and calls removeListener for the old tool.

Parameters:
tool - the tool to be used

getTool

public Tool getTool()
Gets the current tool.

Returns:
the current tool, or null if there isn't one

addTool

public void addTool(Tool tool)
Adds the given tool to a user-selectable list. The toString method of the given tool is displayed to the user for selection purposes. When the tool is selected by the user, the NIP methods menu will list that tool's methods, as described in the NIP overview at the beginning of this file. In addition, the currently selected tool is automatically added as a listener for mouse events, also described in the NIP overview.

Parameters:
tool - the tool to be added

getApplet

public static java.applet.Applet getApplet()
Returns:
Returns the applet.

setApplet

public static void setApplet(java.applet.Applet applet)
When NIP is used within an Applet, this static method should be called before the first call to the NIP constructor. This will enable NIP to use the applet to load images and sounds from the server.

Parameters:
applet - The Applet that NIP should use to load remote image and sound files.

setStatusText

public void setStatusText(java.lang.String str)
Updates the status text at the bottom of the NIP window to the provided text.

Parameters:
str - Text to be displayed.

getStatusText

public java.lang.String getStatusText()
Returns the status text currently displayed at the bottom of the NIP window.

Returns:
Status text string.