|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Window java.awt.Frame javax.swing.JFrame yops.YOPS
public class YOPS
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:
addTool(Object)
method.
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.
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.
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.
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.
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.
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.
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.
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 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.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Constructor Detail |
---|
public YOPS()
public YOPS(int width, int height)
width
- in pixelsheight
- in pixelspublic YOPS(int width, int height, int numPanels)
width
- in pixelsheight
- in pixelsnumPanels
- the number of panels to be createdpublic YOPS(Object tool)
tool
- the tool whose methods should be made available to the userpublic YOPS(Object tool, int numPanels)
tool
- the tool whose methods should be made available to the usernumPanels
- the number of panels to be createdpublic YOPS(Object tool, int width, int height)
tool
- the tool whose methods should be made available to the userwidth
- in pixelsheight
- in pixelspublic YOPS(Object tool, int width, int height, int numPanels)
tool
- the tool whose methods should be made available to the userwidth
- in pixelsheight
- in pixelsnumPanels
- the number of panels to be createdpublic YOPS(Object tool, int width, int height, int numPanels, String firstImage)
tool
- the tool whose methods should be made available to the userwidth
- in pixelsheight
- in pixelsnumPanels
- the number of panels to be createdfirstImage
- the name of the image file to load as the background of the leftmost panelpublic YOPS(Object tool, int width, int height, int numPanels, String firstImage, String secondImage)
tool
- the tool whose methods should be made available to the userwidth
- in pixelsheight
- in pixelsnumPanels
- the number of panels to be createdfirstImage
- 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 anyMethod Detail |
---|
public GraphicsPanel getGraphicsPanel(int panelNumber)
panelNumber
- the index of the desired GraphicsPanel within this YOPS
public void setTool(Object tool)
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.
tool
- the tool to be usedpublic void addListener(Object listener)
listener
- the listener to be addedpublic void removeListener(Object listener)
listener
- the listener to be addedpublic Object getTool()
public void addTool(Object tool)
tool
- the tool to be addedpublic static Applet getApplet()
public static void setApplet(Applet applet)
applet
- The Applet that YOPS should use to load remote image and sound files.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |