|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object vmm.core.View
public class View
A View represents one of possibly several views of an Exhibit
.
A View displays its Exhbit in a Display
. These three classes
are the central classes in VMM. Drawing takes place when the View's render(Graphics2D, int, int)
method is called. Note that this
might potentially be called to draw the Exhibit to other destinations besides a Display, such as
to the graphics device associated with a printer.
This top-level View class might be used directly for simple two-dimensional Exhibits, but it is also likely to be used as a base class for customized Views for particular Exhibits or types of Exhibits. In particular, a specialized View class will be used for 3D views.
The View class contains several methods that can be used for drawing, such as
drawCurve(Point2D[])
, setColor(Color)
, and drawPixel(double, double)
.
Note that to work correctly with the XML save/restore facility defined in SaveAndRestore
,
a subclass of View must have a parameterless constructor, and it must be an independent class or
a public nested class.
Field Summary | |
---|---|
protected ActionRadioGroup |
backgroundCommands
Used for setting the background color of this View, this contains three commands for black background, white background, and custom background. |
protected Animation |
buildAnimation
|
protected boolean |
buildingImageForFilmstrip
This variable was introduced to handle a specific special case: when an image is created asynchronously over a period of time, as in ray-traced views of implicit surfaces. |
protected java.awt.Graphics2D |
currentGraphics
When an exhibit is being drawn, this variable is set to the graphics context where the exhibit is being drawn. |
protected java.util.ArrayList<Decoration> |
decorations
Decorations that have been added to this view. |
protected boolean |
directOffscreenDrawing
This is set to a true by beginDrawToOffscreenImage() when a direct off-screen drawing operation is
initiated. |
protected java.awt.image.BufferedImage |
fullOSI
An offscreen image that is used for drawing. |
protected boolean |
needsRedraw
Used to determine when the off-screen image needs to be redrawn. |
protected int |
offscreenImageType
The type parameter used for creating athe offscreen image -- this is reset in View3DLit when black and white image is selected. |
protected java.util.ArrayList<Parameter> |
parameters
Parameters that have been added to this View. |
protected AbstractActionVMM |
showAxesAction
The action for setting the showAxisProperty, which is one one of the commands returned by getViewCommands() . |
Constructor Summary | |
---|---|
View()
|
Method Summary | |
---|---|
void |
addDecoration(Decoration d)
Add a decoration that will appear in this View only. |
void |
addExtraXML(org.w3c.dom.Document containingDocument,
org.w3c.dom.Element viewElement)
This method is called when an XML representation of this view is being constructed by the SaveAndRestore class to give the View a chance to add any extra infomation that
is not saved by default. |
protected void |
addParameter(Parameter param)
Associate a parameter with this view. |
boolean |
beginDrawToOffscreenImage()
This method, along with endDrawToOffscreenImage() , allow you to draw directly to this view's off-screen
image, if there is one. |
void |
clearDecorations()
Remove all decorations from this View. |
protected void |
clearOSI()
Fills the offscreen image with the background color of this View. |
protected Axes2D |
createAxes()
Create an "Axes" decoration that can be added to this view. |
protected void |
createOSI(int width,
int height)
This method is called whenever an off-screen image needs to be created. |
protected void |
doDraw(java.awt.Graphics2D g)
This method is called by the render method when the Exhibit in this View
needs to be redrawn. |
void |
drawCurve(java.awt.geom.Point2D[] points)
Draws a curve through all the points in an array by calling drawCurve(points,points.length) |
void |
drawCurve(java.awt.geom.Point2D[] points,
int pointCount)
Draws a curve in the current drawing context. |
void |
drawCurve(java.awt.geom.Point2D[] points,
int pointIndexStart,
int pointIndexEnd)
Draws a curve in the current drawing context. |
void |
drawDot(java.awt.geom.Point2D pt,
double diameter)
Draws a dot of specified diameter centered at a specified point. |
void |
drawLine(double x1,
double y1,
double x2,
double y2)
Draws a line in the current drawing context. |
void |
drawLine(java.awt.geom.Point2D pt1,
java.awt.geom.Point2D pt2)
Draws a line in the current drawing context. |
void |
drawLineDirect(int x1,
int y1,
int x2,
int y2)
Draws a line in the current color between points that are specified using pixel coordinates. |
void |
drawPixel(double x,
double y)
Draws a point by turning on a single pixel. |
void |
drawPixel(java.awt.geom.Point2D pt)
Draws a point by turning on a single pixel. |
void |
drawPixelDirect(java.awt.Color color,
int x,
int y)
Sets the pixel with pixel coordinates (x,y) to be a specified color. |
void |
drawPixels(java.awt.geom.Point2D[] points,
int pointIndexStart,
int pointIndexEnd)
Draws a list of pixels in the current drawing context, where the pixels are specified in object coordinates. |
void |
drawString(java.lang.String s,
double x,
double y)
This can be called during drawing to draw a string at a specified point, given in window (real x,y) coordinates. |
void |
drawString(java.lang.String s,
java.awt.geom.Point2D xyCoords)
This can be called during drawing to draw a string at a specified point, given in window (real x,y) coordinates. |
void |
endDrawToOffscreenImage()
This method, along with beginDrawToOffscreenImage() , allow you to draw directly to this view's off-screen
image, if there is one. |
void |
fillRectDirect(int x,
int y,
int width,
int height)
Draws a filled-in rectangle in the current color, where the rectangle is specified in pixel coordinates. |
void |
finish()
This method is called by the Display that contains this View, just before the
view is removed from the display. |
protected void |
finishOSIDraw()
This is called when drawing to the off-screen image is finished, to give it a chance for clean-up. |
void |
forceRedraw()
Force the Exhibit to be completely redrawn. |
ActionList |
getActions()
Generates a list of "Action commands" that can be applied to this View. |
ActionList |
getActionsForViewAndExhibit()
Returns a list containing Action commands for this View and for the Exhibit that is contined in this View. |
ActionList |
getAdditionalAnimations()
This method returns a list of ActionItem that will be added to
the Animation menu of the 3dxm applicaiton. |
ActionList |
getAdditionalAnimationsForViewAndExhibit()
Returns the combined contents of the lists obtained from getAdditionalAnimations()
and Exhibit.getAdditionalAnimationsForView(View) . |
boolean |
getAntialiased()
Returns the value of the antialiased property. |
boolean |
getApplyGraphics2DTransform()
Returns the value of the applyGraphics2DTransform property. |
java.awt.Color |
getBackground()
Gets the background color used when rendering this view. |
java.awt.Color |
getColor()
Returns the drawing color of the current graphics context. |
Decoration[] |
getDecorations()
Returns a list of decorations that have been added to this View |
MouseTask |
getDefaultMouseTask()
Returns a MouseTask that can be installed in the Display attached to this View. |
Display |
getDisplay()
Returns the Display where this View is installed. |
Exhibit |
getExhibit()
Get the Exhibit that is shown in this View. |
boolean |
getFastDrawing()
Tells whether the Exhibit should be drawn as quickly as possible. |
java.awt.Color |
getForeground()
Get the foreground color used for rendering this view. |
java.awt.image.BufferedImage |
getImage(boolean alwaysCopy)
Get a buffered image that contains the picture shown on this View's display. |
java.lang.String |
getName()
Returns a name for this View. |
Parameter |
getParameterByName(java.lang.String name)
Returns a paramter that has been added to this View and that has the specified name. |
Parameter[] |
getParameters()
Returns an array containing all the parameters associated with this View. |
boolean |
getPreserveAspect()
Returns the value of the preserveAspect property. |
double[] |
getRequestedWindow()
Get the window that was originally requested in setWindow . |
ActionList |
getSettingsCommands()
Generates a list of "Settings commands" that can be applied to this View. |
ActionList |
getSettingsCommandsForViewAndExhibit()
Returns a list containing Settings commands for this View and for the Exhibit that is contained in this View. |
boolean |
getShowAxes()
Returns the value of the showAxes property. |
java.lang.String |
getStatusText()
This method is called by the display to determine what message to show in the status bar when this view is active. |
java.lang.String |
getTitle()
Returns a human-readable title for this View that could, for example, be used in a menu that is presented to the user. |
Transform |
getTransform()
Returns the transform that is used when drawing this View. |
Parameter[] |
getViewAndExhibitParameters()
Returns an array of Parameters containing those that have been added to the Exhibit (if any) that is displayed in this view, followed by those that have been added to this view. |
ActionList |
getViewCommands()
Returns a list of "view commands" that can be applied to this View. |
double[] |
getWindow()
Returns a four-element array containing the limits of the window for this View in the xy-plane, assuming that an Exhibit has been installed in the View. |
protected boolean |
needsNewOSI(int width,
int height)
This is called by render to check whether a new offscreen image needs to be
created, given the specified width and height of the drawing area. |
void |
parameterChanged(Parameter param,
java.lang.Object oldValue,
java.lang.Object newValue)
This method will be called automatically when a parameter that has been added to this View is changed. |
protected java.awt.Graphics2D |
prepareOSIForDrawing()
Prepare the offscreen image for drawing and return a graphics context for drawing to it. |
protected void |
putOSI(java.awt.Graphics2D g,
int width,
int height)
This is called by render to copy the offscreen image to the screen. |
void |
readExtraXML(org.w3c.dom.Element viewInfo)
This method is called when this View is being reconstructed from an XML representation by the SaveAndRestore class. |
void |
removeDecoration(Decoration d)
Remove a specified decoration from this View, if present. |
protected void |
removeParameter(Parameter param)
Removes a parameter from this View. |
void |
render(java.awt.Graphics2D g,
int width,
int height)
This method is called to draw this View's Exhibit. |
void |
setAntialiased(boolean antialiased)
If the antialiased property is true, then antialiasing is enabled in the Graphics2D objects that are used to draw this View's exhibit. |
void |
setApplyGraphics2DTransform(boolean applyGraphics2DTransform)
If the applyGraphics2DTransform property is set to true, then a transformation will be applied to the Graphics2D objects that are used to draw this View's Exhibit. |
void |
setBackground(java.awt.Color c)
Set the background color that will be used for rendering this view. |
void |
setColor(java.awt.Color c)
This method will set the color in the current graphics context. |
void |
setDisplay(Display display)
Sets the Display where this View is installed. |
void |
setExhibit(Exhibit exhibit)
Set the Exhibit that is shown in this View. |
void |
setFastDrawing(boolean fast)
Sets the fastDrawing property, which tells whether the Exhibit should be drawn as quickly as possible. |
void |
setFastDrawing(boolean fast,
boolean redrawSynchronizedViews)
Sets the fastDrawing property, which tells whether the Exhibt in this View should be drawn as quickly as possible. |
void |
setForeground(java.awt.Color c)
Set the foreground color to be used for rendering this view. |
void |
setName(java.lang.String name)
Sets the name for this view. |
void |
setPreserveAspect(boolean preserveAspect)
If the preservAspect property is set to true, then the 2D window requested for the View is adjusted so that the shape of the rectanglar window in the xy-plane has the same aspect ratio as the rectangle of pixels to which the view is being drawn. |
void |
setShowAxes(boolean show)
If set to true, an Axes decoration is added to the View. |
void |
setStrokeSizeMultiplier(int pixels)
Sets the width of the stroke used for drawing lines and curves in the current graphics context to have a width equal to a specified number of pixels. |
void |
setTransform(Transform transform)
Sets the transform for this view to a specified transform, with no error checking. |
void |
setWindow(double[] window)
Sets the window in the xy-plane for this View. |
void |
setWindow(double xmin,
double xmax,
double ymin,
double ymax)
Sets the rectangular "window" in the xy-plane for this View. |
void |
stateChanged(javax.swing.event.ChangeEvent evt)
A View listens for state change events that are generated when the Exhibit or Decoration that it is displaying is changed, or by the transform (that converts real coords to pixel coords). |
void |
takeExhibit(View view,
boolean shareTransform)
Sets the exhibit of this View equal to the same Exhibit that is displayed by another specified View. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Animation buildAnimation
protected boolean needsRedraw
forceRedraw()
is called, and it is checked and reset to false in
render(Graphics2D, int, int)
.
protected java.awt.image.BufferedImage fullOSI
protected java.awt.Graphics2D currentGraphics
render(Graphics2D, int, int)
protected java.util.ArrayList<Parameter> parameters
protected java.util.ArrayList<Decoration> decorations
protected volatile boolean buildingImageForFilmstrip
Display
from grabbing an incomplete image and
saving it to the Filmstrip
of the morph that is being created. The value
of this variable is set to true while the image is only partially complete, and
is reset to false when the image is complete.
protected AbstractActionVMM showAxesAction
getViewCommands()
. (This is created along with the View object and is non-null.)
protected ActionRadioGroup backgroundCommands
getViewCommands()
. (This is created along with
the View object and is non-null.)
protected boolean directOffscreenDrawing
beginDrawToOffscreenImage()
when a direct off-screen drawing operation is
initiated. It is reset to false when endDrawToOffscreenImage()
is called (or when a normal drawing
operation begins in render(Graphics2D, int, int)
). A subclass could test its value to tell whether
direct offscreen drawing is in progress.
protected int offscreenImageType
Constructor Detail |
---|
public View()
Method Detail |
---|
public java.lang.String getName()
setName
method. The name
is intended to be something that can be used internally to distinguish one
view from other views of the same Exhibit. For a human-readable name,
the getTitle
method should be used instead of getName
.
(In practice, names are rarely used for views.)
getTitle()
public void setName(java.lang.String name)
getName()
public java.lang.String getTitle()
getName
as a key in the method I18n.tr(String)
. This allows
for easy internationalization. Note that if the I18n.tr
method does not
find a translation for the name, then the title will be the same as the name.
(In practice, titles are rarely used for views.)
getName()
,
I18n.tr(String)
public Display getDisplay()
Display.install(View, Exhibit)
public void setDisplay(Display display)
install
method in the Display class, which is used to install a
View into a Display. It is not meant to be called directly (since that would bypass a lot of
the set-up performed automatically by the install
method).
Display.install(View, Exhibit)
public Exhibit getExhibit()
public void setExhibit(Exhibit exhibit)
repaint
method is called.
This setExhibit method will be called automatically when an Exhibit is installed in a Display;
although it might be called directly, that would be much less usual since it would
by-pass all the set-up that is done automatically by the Display's install
method.
If the exhibit is non-null, then the foreground and background colors of the view are set to the default foreground and background colors of the exhibit. If the exhibit is null, then the view's foreground and background are set to black and white.
Note when overriding this method: You should almost certainly start by saying "if (exhibit == getExhibit()) return". That is, in general, this method should do nothing when the exhibit that is being installed is already installed.
exhibit
- The exhibit to be installed in this View. The value can be null.
In that case, no Exhibit will be associated with the View after the method executes.
If exhibit is already installed in this View, then no changes are made.Display.install(View, Exhibit)
public void finish()
Display
that contains this View, just before the
view is removed from the display. It gives the view a chance to clean up. The method
in this top-level view class does nothing. It is not likely that this method will be called
directly.
public void takeExhibit(View view, boolean shareTransform)
setExhibit(Exhibit)
, except that instead of taking the
colors and transform from the default properties of the Exhibit, they are copied from the
specified View.
view
- The view whose Exhibit is to be copied. After the method is called, both views will
be drawing the same exhibit. If null, then the exhibit of this view will also be set to null.shareTransform
- If true, the two views will share the same Transform, so that changes made to the transform in
one will also result in a change in the other.public java.lang.String getStatusText()
public boolean getShowAxes()
setShowAxes(boolean)
public void setShowAxes(boolean show)
createAxes()
.
protected Axes2D createAxes()
public MouseTask getDefaultMouseTask()
BasicMouseTask2D
, which allows
dragging and zooming of the 2D window.MouseTask
public boolean getApplyGraphics2DTransform()
setApplyGraphics2DTransform(boolean)
public void setApplyGraphics2DTransform(boolean applyGraphics2DTransform)
Transform.getUntransformedGraphics()
.)
Note: When this property is true, a stroke size is also set in the graphics context used
to draw the exhibit. If the preserveAspect
property is also true, which is the default, then the
stroke size is one pixel width. However, if preserveAspect is set to false, the stroke size
is set to the smaller of the pixel width and pixel height.
public boolean getPreserveAspect()
setPreserveAspect(boolean)
public void setPreserveAspect(boolean preserveAspect)
setWindow(double, double, double, double)
,
setApplyGraphics2DTransform(boolean)
,
Transform.setUpDrawInfo(Graphics2D, int, int, int, int, boolean, boolean)
public boolean getAntialiased()
setAntialiased(boolean)
public void setAntialiased(boolean antialiased)
antialiased
- public void setWindow(double xmin, double xmax, double ymin, double ymax)
xmin
- The lower limit of x-values in the xy-plane.xmax
- The upper limit of x-values in the xy-plane.ymin
- The lower limit of y-values in the xy-plane.ymax
- The upper limit of y-values in the xy-plane.Exhibit.getDefaultWindow()
,
setPreserveAspect(boolean)
public void setWindow(double[] window)
window
- If non-null, must be an array containing at least four doubles. If
the value is null, this method does nothing. A non-null value with fewer than four
elements will cause an array index out of bounds exception.setWindow(double, double, double, double)
public double[] getWindow()
setWindow
, if the preserveAspect property is true;
the actual value adjustment is made only when the Exhibit is drawn.
setWindow(double, double, double, double)
,
getRequestedWindow()
,
setPreserveAspect(boolean)
public Transform getTransform()
Exhibit.getDefaultTransform(View)
method when that exhibit is installed
in this View. Note that the transform is not necessarily completely valid unless a drawing
operation is in progress during a call to render(Graphics2D, int, int)
.
This is not guaranteed to be valid in all respects unless a drawing operation is in progress. However, the window in the xy-plane and the 3D projection, if any, are valid.
public void setTransform(Transform transform)
SaveAndRestore
class.
public double[] getRequestedWindow()
setWindow
. This might differ from the values returned
by getWindow
if the preserveAspect property is true.
setWindow(double, double, double, double)
,
getWindow()
public java.awt.Color getBackground()
setBackground(Color)
public void setBackground(java.awt.Color c)
Exhibit.getDefaultBackground()
; if a null exhibit is installed, the background color
is set to white. So, this method is only for adjusting the background color while an exhibit is displayed.
Changing the background color will cause a redraw.
In addition to setting the background color, this method will set the foreground color to either black or white, depending on whehter the background color is light or dark. It is possible to change the foreground color to something else after setting the background.
public java.awt.Color getForeground()
setForeground(Color)
public void setForeground(java.awt.Color c)
setBackground(Color)
. As a result, this
method will rarely be used.
public void setFastDrawing(boolean fast, boolean redrawSynchronizedViews)
getFastDrawing()
when the
usual rendering method takes a long time. (Note that the "fastDrawing" property is shared by any "synchronized"
views, and the actual variable that represents this property is stored in the Transform object that is shared
by the synchronized views.)
When the value of fastDrawing is changed by this method, the view will be redrawn. Any synchronized views will also be redrawn, unless the redrawSynchronizedViews parameter is false. (This method was introduced to be used during resizing of a DisplayXM in the 3DXM application, where only one view should be redrawn.)
setFastDrawing(boolean)
public void setFastDrawing(boolean fast)
getFastDrawing()
when the
usual rendering method takes a long time.
When the value of fastDrawing is changed by this method, this view and any synchronized views will be redrawn.
public boolean getFastDrawing()
fastDrawing
property is set, for example
in BasicMouseTask2D
and BasicMouseTask3D
during mouse manipulation of the exhibit.
public void addExtraXML(org.w3c.dom.Document containingDocument, org.w3c.dom.Element viewElement)
SaveAndRestore
class to give the View a chance to add any extra infomation that
is not saved by default. Any Parameters associated with the View are
saved automatically, as are the transform and the applyGraphics2DTransform,
antialiased, and preserveAspect properties. Decorations associated with the View are
not saved automatically UNLESS they are marked with the VMMSave
annotation. Property variables will also be saved automatically IF they are marked
with VMMSave
annotations.
The method in this top-level View class does nothing.
When a subclass overrides this method, it should start by calling super.addExtraXML(containingDocument,viewElement) to make sure that information from the superclass is saved.
containingDocument
- The overall XML document that contains the view Element that is being created.
This parameter is necessary because it is needed to create any nested subelements that are to be added
to the view element.viewElement
- The XML element that is being constructed. This element already exists; the
purpose of this method to add any extra information that would be needed to reconstruct this view
object from the XML represenation.readExtraXML(Element)
public void readExtraXML(org.w3c.dom.Element viewInfo) throws java.io.IOException
SaveAndRestore
class. The View object has already been created, and default information
(parameters, colors, and transform) have been retrieved.
This method is responsible
for retrieving any data that was written by addExtraXML(Document, Element)
,
except that properties written with SaveAndRestore.addProperty(Object, String, Document, Element)
are retrieved automatically, and decorations written with SaveAndRestore.addDecorationElement(Document, Element, Decoration)
are retrieved automatically.
The method in this top-level View class does nothing.
In general, when a subclass overrides this method, it should be sure to call super.readExtraXML(viewInfo).
viewInfo
- The <view> element from the XML file that contains the information about this
view. Some methods from the SaveAndRestore
class might be useful for getting the data.
java.io.IOException
- If an error is found, an exception of type IOException should be thrown.
This will abort the whole processing of the XML file.public Parameter[] getParameters()
addParameter
method. Note that in the array returned
by this method, parameters are listed in the REVERSE of the order in which
they were added to the View.
public Parameter[] getViewAndExhibitParameters()
UserExhibit
, then the View parameters
from the user exhibit are also added, between the Exhibit and the Exhibtit parameters.
Exhibit.getParameters()
,
UserExhibit.Support.getFunctionParameters()
public Parameter getParameterByName(java.lang.String name)
protected void addParameter(Parameter param)
param
- The parameter to be added. If the parameter is null, it is ignored.
If the parameter has already been added to the View, it is not added for a second time.protected void removeParameter(Parameter param)
param
- The parameter to be removed. If the value is null or if the parameter is
not associated with this View, then nothing is done.public void parameterChanged(Parameter param, java.lang.Object oldValue, java.lang.Object newValue)
forceRedraw
.
parameterChanged
in interface Parameterizable
param
- The Parmeter whose value has been set.oldValue
- The previous value of the parameter.newValue
- The new, current value of the parameter. This is not
necessarily guaranteed to be different from the old value (although it
is for parameters definedin the VMM core).forceRedraw()
public void addDecoration(Decoration d)
forceRedraw
.
addDecoration
in interface Decorateable
d
- The decoration to be added. If this is null or if it has already been added to the View,
then nothing is done. The View is added
as a ChangeListener to the decoration. This will cause the View to be automatically
redrawn when the Decoration is changed.public void removeDecoration(Decoration d)
removeDecoration
in interface Decorateable
d
- The decoration to be removed (if present).public void clearDecorations()
public Decoration[] getDecorations()
public ActionList getViewCommands()
ActionItem
interface and will generally
belong to one of the classes AbstractActionVMM
,
ToggleAction
, ActionRadioGroup
, or
ActionList
. Null items represent separators.
The idea is that the list items will be added to a menu or otherwise presented to the user
so that the user can invoke the commands (with ActionList items representing submenus).
Null values can occur in the list; they are meant to become separaters in the menu.
In this top-level View class, the list contains a "Show/Hide Axes" Action, a null value, and an ActionRadioGroup with three items that can be used to set the background color.
In general, when overriding this method, a subclass should call super.getViewCommands() to obtain a list of commands from the superclass. It can then add additional commands or remove or disable commands that are in the list from the superclass.
public ActionList getSettingsCommands()
ActionItem
interface and will generally
belong to one of the classes AbstractActionVMM
,
ToggleAction
, ActionRadioGroup
, or
ActionList
. Null items represent separators.
The idea is that the list items will be added to a menu or otherwise presented to the user
so that the user can invoke the commands (with ActionList items representing submenus).
Null values can occur in the list; they are meant to become separaters in the menu.
Subclasses that override this method should generally call super.getSettingsCommands() and add their commands to the list retured by that method. This top-level View class does not define any Settings commands; the return value is an empty non-null ArrayList.
public ActionList getSettingsCommandsForViewAndExhibit()
getSettingsCommands()
and
Exhibit.getSettingsCommandsForView(View)
. In addtion, if the exhibit is a UserExhibit
, and
if the exhbit allows the user data to be changed, then a "ChangeUserData" command is also included,
between the other Exhibit commands and the View commands. If there is currently no Exhibit in the View,
only the view commands are returned.
There is presumably no need to override this method.
Note that of the three types of commands defined by Views and Exhibits ("Settings", "Action", and "View" commands), "View" commands are constructed entirely by Views, while "Action" commands and "Settings" commands are constructed by both.
public ActionList getActions()
ActionItem
interface and will generally
belong to one of the classes AbstractActionVMM
,
ToggleAction
, ActionRadioGroup
, or
ActionList
. Null items represent separators.
The idea is that the list items will be added to a menu or otherwise presented to the user
so that the user can invoke the commands (with ActionList items representing submenus).
Null values can occur in the list; they are meant to become separaters in the menu.
Subclasses that override this method should generally call super.getActionss() and add their commands to the list retured by that method. This top-level View class does not define any Action commands; the return value is an empty non-null ArrayList.
public ActionList getActionsForViewAndExhibit()
getActions()
and
Exhibit.getActionsForView(View)
.
If there is currently no Exhibit in the View,
only the view commands are returned.
There is presumably no need to override this method.
Note that of the three types of commands defined by Views and Exhibits ("Settings", "Action", and "View" commands), "View" commands are constructed entirely by Views, while "Action" commands and "Settings" commands are constructed by both.
public ActionList getAdditionalAnimations()
ActionItem
that will be added to
the Animation menu of the 3dxm applicaiton. The values in the list should
ordinarily be commands (i.e. AbstractActionVMM
)
that run animations (although there is no way to enforce
this restriction). These animations commands are in addition to the standard "Morph"
and "Cyclic Morph" commands. Note that these commands are added to those returned
by getAdditionalAnimations()
.
In this top-level View class, the return value is a an empty list (but not null). In general, when overriding this method, subclasses should call "super.getAdditionalAnimations()" to obtain a list of actions from the superclass. It can then add additional actions or remove or disable actions that are in the list from the superclass.
public ActionList getAdditionalAnimationsForViewAndExhibit()
getAdditionalAnimations()
and Exhibit.getAdditionalAnimationsForView(View)
. There should not be any
need to override this method.
protected void doDraw(java.awt.Graphics2D g)
render
method when the Exhibit in this View
needs to be redrawn. The default as defined here is simply to call the
exhibit's render
method. Subclasses can override this method if some
other action is needed.
Drawing is likely to need information about the transform (including the rectangular area in the
xy-plane that is being drawn and the rectangle of pixels in the graphics
context where it is drawn) and the decorations that have been added to the view. This
information is available from getTransform()
and getDecorations()
.
g
- The graphics context where the exhibit is to be drawn. The drawing
area has already been cleared to the background color.public void forceRedraw()
repaint
on the Display where this View is rendered will NOT
cause the off-screen image to be redrawn and so will not necessarily cause what is
displayed on the screen to change. The system is designed so that this method
or its equivalent will be called automatically in most cases, such as
when Parameters of the View or Exhibit are changed or when a Decoration is added or removed or changed.
It is also called when other properties defined in this top-level View
classe are changed. Subclasses of View might need to call this method when changes are made
that affect the appearance of the Exhibit.
public void stateChanged(javax.swing.event.ChangeEvent evt)
stateChanged
in interface javax.swing.event.ChangeListener
forceRedraw()
public void render(java.awt.Graphics2D g, int width, int height)
paintComponent
method of the Display class. The process of
rendering a View is rather complicated because of the need to manage off-screen images and
various properties of the View. Subclasses of
View should probably not override this method. They should change the doDraw
method, which is called by this method, instead.
While the exhibit is being rendered, this method sets the value of the protected
variable currentGraphics
to the graphics context in which the exhibit is being
drawn. This variable is used implicitely for drawing in the rendering methods that are provided
by the View class and its 3D subclass. This graphics context is set only for the duration of the call
to the doDraw(Graphics2D)
method in this class, and hence during rendering
of an exhibit (in its Exhibit.doDraw(Graphics2D, View, Transform)
method.
It is also set during direct drawing to the off-screen image initiated by
beginDrawToOffscreenImage()
. At other
times currentGraphics is null, and calling the rendering methods that use this graphics context at those
times will result in an error.
Note that this render method always completely paints the rectangle in which it draws.
(In the rare case that creation of an offscreen image fails because of low memory, an error message is placed in the drawing area.)
g
- The graphics context where the Exhibit is to be drawn. It is assumed
that the upper left corner of the drawing area has coordinates (0,0). The off-screen
image is simply drawn in g, except that when no exhibit exists, it is filled with
the background color.width
- The width, in pixels, of the drawing area where the exhibit is to be drawn.height
- The height, in pixels, of the drawing area where the exhibit is to be drawn.protected boolean needsNewOSI(int width, int height)
render
to check whether a new offscreen image needs to be
created, given the specified width and height of the drawing area.
protected void putOSI(java.awt.Graphics2D g, int width, int height)
render
to copy the offscreen image to the screen.
The width and height of the drawing area are given as parameters, although they
is not used in the version of this method in class View.
protected void createOSI(int width, int height)
fullOSI
to the newly created image. (Subclasses should
respect this.) The default is to create a
new BufferedImage whose type is specified by the protected variable
offscreenImageType
. This is most likely what is desired.
However, sub-classes can override this method if a different type of image
is needed.
protected void clearOSI()
protected java.awt.Graphics2D prepareOSIForDrawing()
render(Graphics2D, int, int)
before it begins drawing
to the offscreen image. It is also called by beginDrawToOffscreenImage()
.
The offscreen image exists before this is called. In the
top-level View class, this applies the transform and (if approprieate) antialiasing to
the OSI drawing context and sets the foregraund and background colors.
Note: It is important that the protected variable fullOSI
point to a
BufferedImage that contains the image that is shown on the screen. Subclasses that
override this method should respect this. This is true in View3D, for example,
even when the actual drawing is being done elsewhere during RED_GREEN_STEREO rendering.
protected void finishOSIDraw()
public void setColor(java.awt.Color c)
beginDrawToOffscreenImage()
. If called
at other times, there is no effect.
c
- the color to be used for subsequent drawing; if c is null, then the default foreground
color of the View is restored.public java.awt.Color getColor()
beginDrawToOffscreenImage()
. If called
at other times, the return value is null.
public void setStrokeSizeMultiplier(int pixels)
beginDrawToOffscreenImage()
. If called
at other times, the call has no effect. Note that this just sets the stroke width
to be a multiple of the default stroke size, as defined by the Transform. Calling this
method with a parameter value of 1 will restore the default stoke width.
Transform.getDefaultStrokeSize()
public void drawPixel(double x, double y)
drawPixelDirect
to set the color of the single pixel.
x
- The x-coordinate of the point, in window (real xy) coodinates.y
- The y-coordinate of the point, in window (real xy) coodinates.drawPixelDirect(Color, int, int)
public void drawPixel(java.awt.geom.Point2D pt)
drawPixel(pt.getX(),pt.getY())
.
pt
- The non-null point, in window (real xy) coodinates.public void drawDot(java.awt.geom.Point2D pt, double diameter)
public void drawPixels(java.awt.geom.Point2D[] points, int pointIndexStart, int pointIndexEnd)
public void drawString(java.lang.String s, double x, double y)
drawString
method of a drawing context to which a transform has been applied.
The point (x,y) is properly transformed from xy-coordinates to pixel coordinates, whether a
transform has been applied ot the drawing context or not. After conversion, if necessary, the
graphics context returned by Transform.getUntransformedGraphics()
is used to draw the string.
drawString(String, Point2D)
public void drawString(java.lang.String s, java.awt.geom.Point2D xyCoords)
drawString
method of a drawing context to which a transform has been applied.
xyCoords
- The non-null point containting the coordinates of the basepoint of the string in real xy-coordinates.
This point is not modified.drawString(String, double, double)
public void drawLine(double x1, double y1, double x2, double y2)
public void drawLine(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
pt1
- The first endpoint of the line, with coordinates given in the window (real xy) coordinates system.pt2
- The second endpoint of the point, with coordinates given in the window (real xy) coordinates system.public void drawCurve(java.awt.geom.Point2D[] points, int pointIndexStart, int pointIndexEnd)
points
- The curve is drawn through some or all of the points in this array. If the array is null, nothing is done.
The curve is acutually just made up of lines from one point to the next. An element in the array can be null.
In that case, one or two segments are missing from the curve -- the segments on either side of the missing point.
Consecutive points are also not joined by a segment if the jump from one point to the next is too large.pointIndexStart
- The number of points in the array that should be used for the curve. A curve is drawn
though points[pointIndexStart], point[pointIndexStart+1], ..., points[pointIndexEnd]. The value of pointIndexStart
is clamped to lie in the range 0 to points.length-1.pointIndexEnd
- The number of points in the array that should be used for the curve. A curve is drawn
though points[pointIndexStart], point[pointIndexStart+1], ..., points[pointIndexEnd]. The value of pointIndexEnd
is clamped to lie in the range 0 to points.length-1. If pointIndexEnd is less than or equal to pointIndexStart,
nothing is drawn.public void drawCurve(java.awt.geom.Point2D[] points)
drawCurve(points,points.length)
points
- The array of points on the curve. If this is null, nothing is done.public void drawCurve(java.awt.geom.Point2D[] points, int pointCount)
points
- The curve is drawn through some of all of the points in this array. If the array is null, nothing is done.
The curve is acutually just made up of lines from one point to the next. An element in the array can be null.
In that case, one or two segments are missing from the curve -- the segments on either side of the missing point.
Consecutive points are also not joined by a segment if the jump from one point to the next is too large.pointCount
- The number of points in the array that should be used for the curve. A curve is drawn
though points[0], point[1], ..., points[pointCount-1]. If pointCount is greater than points.length, then
its value is changed to points.length.public void drawPixelDirect(java.awt.Color color, int x, int y)
color
- the color for the pixel; if null, the current drawing color is used.x
- the horizontal pixel coordinate.y
- the vertical pixel coordinate.public void drawLineDirect(int x1, int y1, int x2, int y2)
public void fillRectDirect(int x, int y, int width, int height)
public boolean beginDrawToOffscreenImage()
endDrawToOffscreenImage()
, allow you to draw directly to this view's off-screen
image, if there is one. This operation is allowed only if (1) An offscreen image exists, (2) the View has
already been drawn to the screen at least once since its current exhibit was installed, and (3) no drawing
operation is in progress (including a regular draw by the render
method or a draw operation
initiated by a previous call to this method that was not matched by a call to endDrawToOffscreenImage
).
If all these conditions hold, this method initiates a drawing operation and returns true. If any of them
fail, it returns false and no drawing operation is initiated. To terminate the drawing operation, you must
call endDrawToOffscreenImage
. A drawing operation should not remain open for any length of time.
It should complete before the method in which beginDrawToOffscreenImage
is called.
During a drawing operation initiated by this method, drawing done using the draw methods in this
class, such as drawCurve(Point2D[])
, will draw to the off-screen image. This also applies to
drawing operations in the View3D subclass and presumably in other subclasses. The point of this is
to allow you to draw extra stuff incrementally on the off-screen canvas, without redrawing the whole
thing from scratch each time.
After calling endDrawToOffscreenImage
, you will probably want to call the repaint() method of
this View's display to cause the changes to appear on the screen. Do NOT call forceRedraw()
,
since that will generate a call to render
, which will erase the changes you just made!
public void endDrawToOffscreenImage()
beginDrawToOffscreenImage()
, allow you to draw directly to this view's off-screen
image, if there is one. See that method for more information. No error occurs if this is called
when no draw-to-image operation is in progress.
public java.awt.image.BufferedImage getImage(boolean alwaysCopy)
Note that if you need to draw to the offscreen image, you should use the facility provided
by beginDrawToOffscreenImage()
. You should not generally simply draw to the image returned by
this method (even though that will work in some cases). This method was introduced mainly to
make it possible to save the screen image to a file or to a "filmstrip" animation.
alwaysCopy
- If this is false, it is possible that the image that is returned is the
actual image that the View uses to store its content; this image will be modified whenever
the view is redrawn. (alwaysCopy = true is used to get the frame for a filmstrip;
alwaysCopy = false is used to get an image to save to a file)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |