yops
Class YOPS

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 yops.YOPS
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class YOPS
extends JFrame

YOPS stands for "Ye Olde Photo Shoppe," an application skeleton that can be used as a starting point for a variety of projects involving image manipulation and graphics.

The YOPS User Interface:

Creating Tools for YOPS:

One of the main purposes of YOPS is to support image processing, but YOPS doesn't have built-in functions for this. Instead, your program will supply various image processing tools for YOPS to use. These tools will appear as a set of buttons on the left edge of the YOPS window. When the user selects a tool, YOPS will inspect that tool to discover what methods it provides. Then YOPS will make the methods of your tool available to the user for modifying the contents of the graphics panels. When defining a tool, you can include any number of methods that operate on the color components of each pixel, on each pixel as a whole, on the background image as a whole, or on the entire graphics panel. The methods will appear, alphabetized by name, in the YOPS methods menu for user selection.

Note that a YOPS 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 YOPS as described above, but YOPS 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 YOPS. In addition, a tool can call methods on a GraphicsPanel to load in a background image and to display additional images, shapes, lines, etc. Depending upon its parameter types, a method of a tools may operate on color components of pixels (int parameters), pixel colors as a whole (Color parameters), entire images (Image parameters), or entire panels (GraphicsPanel parameters). In addition, your tool can provide methods for setting numeric and boolean values (presented in a control panel with sliders and check boxes) and for handling the user's mouse events. We explain each of these below. All of this is discussed in more detail below.

Operating on the color components of each pixel:
Each pixel of an image consists of three color components: red, green, and blue. Each component has an integer value in the range 0 to 255, where 0 means no intensity and 255 means full intensity. So, if all three values are 0, the color is black. If all three are 255, the color is white. Similarly, if the red component is 128 and the others are 0, then the color is a medium intensity red.

Some methods of a tool may need to operate on every color component of every pixel in an image, or you may want to combine the corresponding components of pixels in different images to produce a new image. For example, you may want to average the corresponding components of every pixel of two images in order to produce a composite image. To operate on the color components of each pixel, your tool class can include a method that has one or more int parameters and an int return type. When the user executes this method, YOPS will apply it to every color component of every pixel. If there is only one parameter, YOPS will take the parameter values from the first image (the background image on panel 0). If there are two parameters, the first two images will be used, etc. The return value will be used to set the color component in the corresponding pixel of the resulting image.

Operating on each pixel as a whole:
The three color components of each pixel (red, green, and blue) can be represented as a single object of type Color.

Some methods of a tool may need to operate on every pixel in an image, or may need to combine the corresponding pixels in different images to produce a color for that pixel in a new image. For example, you may want to create a grayscale image by setting the color of each pixel to a new color that has the same value in all three color components, a value you might determine by averaging the three color component values of the original color in that pixel. To operate on each pixel as a whole, a tool class can provide a method that has one or more Color parameters and a Color return type. When the user executes this method, YOPS will apply it to every pixel. If there is only one parameter, YOPS will take the parameter values from the first image (the background image on panel 0). If there are two parameters, the first two images will be used, etc. The return value will be used to set the color of the corresponding pixel of the resulting image.

Within your method, you can call the methods getRed(), getGreen(), and getBlue() on a particular color object to get the values of each component of that color. For the return value, you can create new Color objects by calling a constructor and providing the desired red, green, and blue values.

Operating on each image as a whole:
Some of your tool's methods may need to operate on entire images, or may need to combine different images to produce a new image. For example, you may want to swap pixels in an image in order to flip the image upside down. To operate on images as a whole, your tool class can include a method that has one or more Image parameters and a void return type. If there is only one parameter, YOPS will provide the first image (the background image on panel 0). If there are two parameters, the first two images will be provided, etc. Within your method, you will call methods of the Image class to access and modify the images provided as parameters.

Operating on the graphics panels as a whole:
Some methods of your tool may need to operate on entire graphics panels to add, move or remove various graphics components (circles, squares, lines, etc.). Those methods To operate on graphics panels as a whole, your tool can include a method that has one or more GraphicsPanel parameters and a void return type. If there is only one parameter, YOPS will provide the first image (the background image on panel 0). If there are two parameters, the first two images will be used, etc. Within your method, you will call methods of the GraphicsPanel class to operate on the panels provided as parameters.

Setting variables:
You may want the YOPS user to set numeric or boolean values stored in variables. For example, you may want the user to specify how "red" an image should be, or whether or not a certain technique should be applied in some future operation. For this purpose, your processsor can have one or more methods whose method name begins with the word "set" and that has an int, double, or boolean parameter and a void return type.

For each numeric set method (int or double), YOPS will show a labeled slider. Your method will be called whenever the user adjusts the slider. Parameter values will reported to your method as a percent (0 to 100), which you can adjust as needed when your set method is called. For example, if you want values in the range 0 to 255, you can multiply the supplied slider value by 2.55 to get the desired result.

For each boolean set method (int or double), YOPS will show a labeled checkbox. Your method will be called whenever the user checks or unchecks the box.

Handling mouse events:
If you want your tool to react to the user's mouse events, you can include one or more of the following methods in your tool, depending on the kind of mouse event you are interested in. In each case, the parameters are the GraphicsPanel in which the mouse event occurred, along with the x and y pixel coordinates of mouse cursor location.
  • mousePressed(GraphicsPanel panel, int x, int y) - This method will be called on the tool when the user presses the left mouse button within the panel.
  • mouseReleased(GraphicsPanel panel, int x, int y) - This method will be called on the tool when the user releases the left mouse button. Note that if the user was holding down the mouse button and moved off the panel, then the reported (x,y) coordinate may be outside the boundary of the panel.
  • mouseMoved(GraphicsPanel panel, int x, int y) - this method will be called on the tool when the user moves the mouse to the (x,y) location within the panel
  • mouseDragged(GraphicsPanel panel, int x, int y) - this method will be called on the tool when the user moves the mouse to the (x,y) location within the panel while holding down the left mouse button.
  • Author:
    Kenneth J. Goldman
    Created Jul 6, 2005
    See Also:
    Serialized Form

    Nested Class Summary
     
    Nested classes/interfaces inherited from class javax.swing.JFrame
    JFrame.AccessibleJFrame
     
    Nested classes/interfaces inherited from class java.awt.Frame
    Frame.AccessibleAWTFrame
     
    Nested classes/interfaces inherited from class java.awt.Window
    Window.AccessibleAWTWindow
     
    Nested classes/interfaces inherited from class java.awt.Container
    Container.AccessibleAWTContainer
     
    Nested classes/interfaces inherited from class java.awt.Component
    Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
     
    Field Summary
     
    Fields inherited from class javax.swing.JFrame
    accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
     
    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
    YOPS()
              Creates a YOPS with one panel of a default width and height.
    YOPS(int width, int height)
              Creates a YOPS with one panel of the given width and height
    YOPS(int width, int height, int numPanels)
              Creates a YOPS with the given number of panels, each with the same given width and height.
    YOPS(Object tool)
              Creates a YOPS with one panel of a default width and height, and with the given tool.
    YOPS(Object tool, int numPanels)
              Creates a YOPS with the given tool and given number of panels, each of a default width and height.
    YOPS(Object tool, int width, int height)
              Creates a YOPS with the given tool and one panel of the given width and height.
    YOPS(Object tool, int width, int height, int numPanels)
              Creates a YOPS with the given tool and the given number of panels, each of the given width and height.
    YOPS(Object tool, int width, int height, int numPanels, String firstImage)
              Creates a YOPS with the given tool and the given number of panels, each of the given width and height, and with the provided image file loaded as the background image of the leftmost panel.
    YOPS(Object tool, int width, int height, int numPanels, String firstImage, String secondImage)
              Creates a YOPS with the given tool and the given number of panels, each of the given width and height, and with the provided image files loaded as the background images of the two leftmost panels.
     
    Method Summary
     void addListener(Object listener)
              Makes the given object listen for mouse events in all GraphicsPanels, according to methods as described for YOPS tools.
     void addTool(Object tool)
              Adds the given tool to a user-selectable list.
    static 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.
     Object getTool()
              Gets the current tool.
     void removeListener(Object listener)
              Removes the given listener so that it no longer is notified about mouse events.
    static void setApplet(Applet applet)
              When YOPS is used within an Applet, this static method should be called before the first call to the YOPS constructor.
     void setTool(Object tool)
              Sets the current tool of this YOPS to the provided object.
     
    Methods inherited from class javax.swing.JFrame
    addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
     
    Methods inherited from class java.awt.Frame
    addNotify, finalize, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, 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, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
     
    Methods inherited from class java.awt.Component
    action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
     
    Methods inherited from class java.lang.Object
    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
     
    Methods inherited from interface java.awt.MenuContainer
    getFont, postEvent
     

    Constructor Detail

    YOPS

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


    YOPS

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

    Parameters:
    width - in pixels
    height - in pixels

    YOPS

    public YOPS(int width,
                int height,
                int numPanels)
    Creates a YOPS 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

    YOPS

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

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

    YOPS

    public YOPS(Object tool,
                int numPanels)
    Creates a YOPS with the given tool and given number of panels, each of a default width and height. (See the YOPS 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

    YOPS

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

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

    YOPS

    public YOPS(Object tool,
                int width,
                int height,
                int numPanels)
    Creates a YOPS with the given tool and the given number of panels, each of the given width and height. (See the YOPS 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

    YOPS

    public YOPS(Object tool,
                int width,
                int height,
                int numPanels,
                String firstImage)
    Creates a YOPS with the given tool and the given number of panels, each of the given width and height, and with the provided image file loaded as the background image of the leftmost panel. (See the YOPS 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
    firstImage - the name of the image file to load as the background of the leftmost panel

    YOPS

    public YOPS(Object tool,
                int width,
                int height,
                int numPanels,
                String firstImage,
                String secondImage)
    Creates a YOPS with the given tool and the given number of panels, each of the given width and height, and with the provided image files loaded as the background images of the two leftmost panels. (See the YOPS 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
    firstImage - the name of the image file to load as the background of the leftmost panel * @param firstImage the name of the image file to load as the background of the second panel, if any
    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 YOPS
    Returns:
    the GraphicsPanel for the given index

    setTool

    public void setTool(Object tool)
    Sets the current tool of this YOPS 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

    addListener

    public void addListener(Object listener)
    Makes the given object listen for mouse events in all GraphicsPanels, according to methods as described for YOPS tools. If the given listener is null, this method does nothing.

    Parameters:
    listener - the listener to be added

    removeListener

    public void removeListener(Object listener)
    Removes the given listener so that it no longer is notified about mouse events. If the given listener is null or the given listener is not currently listening, this method does nothing.

    Parameters:
    listener - the listener to be added

    getTool

    public Object getTool()
    Gets the current tool.

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

    addTool

    public void addTool(Object 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 YOPS methods menu will list that tool's methods, as described in the YOPS 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 YOPS overview.

    Parameters:
    tool - the tool to be added

    getApplet

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

    setApplet

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

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