|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.visuals.ImageView
public class ImageView
The ImageView displays an image in the component area.
The image can be specified with either a URL, the image name and path, or
a java.awt.image object.
Creating an ImageView Component
A valid instance is created by instantiating an object of ImageView from one of the three constructors.
// Default Constructor ImageView imageView1 = new ImageView(); // Sets source path ImageView imageView2 = new ImageView("d:/source.gif"); ImageView imageView3 = new ImageView("http://www.example.com/source.gif"); // Sets image to specified java.net.URL object ImageView imageView4 = new ImageView( new java.net.URL("http://www.example.com/source.gif") ); // Sets image to specified source relative to a certain class ImageView imageView4 = new ImageView( com.sas.viuals.ImageView.class, "res/DefaultIDEImage32.gif" ); // Sets image to specified java.awt.image object ImageView imageView4 = new ImageView( (java.awt.image)imgSource );
Usage
Source
There are several different ways of setting the source of the image to be displayed.
ResizeToFit
The image will resize the component if possible to fit the current source image. This only works when the Display Mode is set to NO_SCALE. When the Display Mode is set to something else, ResizeToFit will automatically be set to false.
Display Mode
The Display mode sets how the image will be displayed within the component area. There are five display modes.
ImageFilter
The ImageFilter will create and display a filtered image based on the current source image. If no imageFilter is set or the imageFilter is set to null, the original source image will be displayed.
MediaTracker
This allows an application that uses the imageView to wait until all of the image is loaded. IF THE PREFERRED SIZE OF AN IMAGEVIEW IS CHECKED BEFORE THE IMAGE IS LOADED IT WILL BE INCORRECT.
ImageView imageView1.setSource("d:/source.gif"); java.awt.MediaTracker mediaTrack = imageView1.getMediaTracker(); try { mediaTrack.waitForAll(); // Waits for all images associated with this tracker to be loaded. } catch ( InterruptedException e ) { }
ImageLoadWait
The ImageLoadWait uses the MediaTracker to wait for the images to load. This is set to true by default.
IconInterface
,
Serialized FormField Summary | |
---|---|
protected java.lang.String |
absoluteSource
The absolute path and name of the source |
static int |
AUTO_SCALE
DisplayMode value AUTO_SCALE: Image is scaled to fit within the component but keeps its aspect ratio. |
protected java.awt.Insets |
currentInsets
The insets set on the ImageView less the amount of the border insets at the time the insets were set. |
protected boolean |
defaultImageLoaded
Flag indicating the defaultImage is loaded. |
protected java.awt.Image |
disabledImage
The disabled image filtered using a GrayFilter. |
protected java.awt.Image |
dispImage
The image actually painted. |
protected int |
displayMode
The displayMode of the image |
protected java.awt.Image |
filteredImage
The original image filtered using the imageFilter. |
protected java.awt.Image |
image
The original image created to display. |
protected boolean |
imageWait
Flag indicating that the MediaTracker will be used to load the images. |
static int |
LAST_DISPLAY_MODE
The last DisplayMode value used |
protected java.awt.Image |
missingImage
The missing file image. |
static int |
NO_SCALE
DisplayMode value NO_SCALE: Image is displayed at original size. |
protected int |
oldHeight
The previous height the image was painted at. |
protected int |
oldWidth
The previous width the image was painted at. |
static java.lang.String |
RB_KEY
|
protected java.lang.String |
relativeSource
The path and name of the source relative to the relativeSourceClass location. |
protected java.lang.Class |
relativeSourceClass
The class to use as the root location for the relative path and name of the source. |
protected java.lang.String |
relativeSourceClassName
The name of the class to use as the root location for the relative path and name of the source. |
protected com.sas.net.ResourceLocatorInterface |
resourceLocator
The ResourceLocator used to locate the image to be displayed, returns a valid URL is possible. |
static int |
SCALE
DisplayMode value SCALE: Image is scaled to the size of the component and then displayed. |
static int |
SCALE_HEIGHT
DisplayMode value SCALE_HEIGHT: Image is scaled to the height of the component with the original aspect ratio. |
static int |
SCALE_WIDTH
DisplayMode value SCALE_WIDTH: Image is scaled to the width of the component with the original aspect ratio. |
protected java.lang.String |
source
The source of the image displayed. |
protected boolean |
sourceAppletRelative
Flag indicating to use find the source relative to the applet the ImageView is used in |
protected java.net.URL |
sourceURL
The URL of the source. |
static int |
TILE
DisplayMode value TILE: Image is tiled of the area of the component |
Constructor Summary | |
---|---|
ImageView()
Default constructor |
|
ImageView(java.lang.Class relativeClass,
java.lang.String relativeSrc)
Constructor that creates an ImageView with a relative class and a source relative to that class. |
|
ImageView(java.awt.Image img)
Constructor that displays an existing image. |
|
ImageView(com.sas.net.ResourceLocatorInterface resourceLocator)
Constuctor that creates an ImageView using the given ResourceLocatorInterface to locate the image to display. |
|
ImageView(java.lang.String src)
Constructor that takes a String holding the source path or URL string for the image |
|
ImageView(java.net.URL srcURL)
Constuctor that creates an ImageView with URL source. |
Method Summary | |
---|---|
void |
addNotify()
Makes this Component displayable by connecting it to a native screen resource. |
void |
attachModel(com.sas.ModelInterface model)
Attaches a model to the ImageView. |
java.lang.Object |
clone()
Create a clone of this ImageView. |
java.awt.Dimension |
computePreferredSize()
Compute the preferred size of the image. |
protected java.awt.Image |
createDisabledImage(java.awt.Image img)
Create an image based on the image given that greys out the colors. |
protected void |
createDisplayImage(int width,
int height)
Create the image to be displayed. |
java.awt.Image |
createFilteredImage(java.awt.Image img,
java.awt.image.ImageFilter imgFilter)
Create an image based on the image given that is filtered using the given ImageFilter. |
protected java.awt.Image |
createTiledImage(java.awt.Image img,
int width,
int height)
Create an image based on the image given that is tiled over the entire area of the ImageView. |
void |
detachModel(com.sas.ModelInterface model)
Detach the current model. |
static int |
getDefaultHeight()
Returns the default height to display the ImageView with. |
static int |
getDefaultWidth()
Returns the default width to display the ImageView with. |
int |
getDisplayMode()
Returns the display mode of the imageView. |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to
augment the automatically introspected information about this ImageView. |
int |
getIconHeight()
Gets the height of the image. |
int |
getIconWidth()
Gets the width of the image. |
java.awt.Image |
getImage()
Returns the original image object for the current display. |
java.awt.image.ImageFilter |
getImageFilter()
Returns the image filter to apply to the image. |
java.awt.Insets |
getInsets()
Returns the insets of the ImageView. |
java.awt.MediaTracker |
getMediaTracker()
Returns the MediaTracker so external sources can track the loading of the images. |
java.awt.Dimension |
getMinimumSize()
Returns the minimum size of the ImageView. |
java.awt.Image |
getMissingFileImage()
Returns the image used if the image is missing. |
java.lang.Class |
getRelativeSourceClass()
Gets the class that is used with the relative source path. |
java.util.Vector |
getRequiredInterfaces()
Returns the required interfaces Vector for this component. |
com.sas.net.ResourceLocatorInterface |
getResourceLocator()
Gets the instance of ResourceLocatorInterface that is used to locate the URL of the image. |
java.lang.String |
getSource()
Gets the source (file location) for obtaining the image |
java.lang.String |
getSourceAbsolute()
Gets the absolute source name for the image to display. |
java.lang.String |
getSourceRelative()
Gets the source, relative to the relativeSourceClass, of the image to display. |
java.net.URL |
getSourceURL()
Gets the URL object for the image file to be displayed. |
static boolean |
imageExists(com.sas.net.ResourceLocatorInterface rli)
Returns true if an image get be retrieved from the given ResourceLocatorInterface, false otherwise. |
boolean |
isImageLoadWait()
Returns if the ImageView will wait for the image to load. |
boolean |
isResizeToFit()
Returns the value of the resizeToFit property If set to true, then the ImageView object will resize itself to the size of the image it displays. |
boolean |
isSourceAppletRelative()
Returns whether or not the image source is relative to the applet For true to be returned, the ResourceLocatorInterface must be of type AppletResourceLocator, else false is returned. |
protected void |
loadDisplayImage()
Load the images that have been created. |
void |
paint(java.awt.Component comp,
java.awt.Graphics g,
int x,
int y,
int width,
int height)
Paints the image in the ImageView objects with specified displayMode |
void |
paint(java.awt.Graphics g)
Paint the ImageView |
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
Paints the ImageView. |
void |
print(java.awt.Graphics g,
int pageNumber,
int pageWidth,
int pageHeight)
Prints the requested page. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Handle PropertyChangeEvents from the model. |
void |
refresh()
Sets the source for the image from the attached model. |
void |
refresh(com.sas.ModelInterface model)
Refresh the image displayed based on the model changing. |
void |
resizeToFit()
Reset the size of the ImageView to the preferredSize. |
void |
setBounds(int x,
int y,
int width,
int height)
Call super.setBounds() and then repaint the entire component. |
static void |
setDefaultHeight(int newHeight)
Sets the default height to display the ImageView with. |
void |
setDefaultValues()
This method sets the initial values to the default values. |
static void |
setDefaultWidth(int newWidth)
Sets the default width to display the ImageView with. |
void |
setDisplayMode(int mode)
Sets the display mode of the image. |
void |
setImage(java.awt.Image img)
Sets the image object to be displayed in the ImageView. |
void |
setImageFilter(java.awt.image.ImageFilter imgFilter)
Sets the image filter that will be applied to the original image source to produce the image that is displayed. |
void |
setImageLoadWait(boolean loadWait)
Sets the ImageView to wait for the image to load |
void |
setInsets(java.awt.Insets newInsets)
Sets the Insets for the ImageView. |
void |
setRelativeSourceClass(java.lang.Class newValue)
Sets the class that is used with the relative source path. |
void |
setResizeToFit(boolean resizeToFit)
Sets the value of the resizeToFit property |
void |
setResourceLocator(com.sas.net.ResourceLocatorInterface newValue)
Sets the instance of ResourceLocatorInterface for obtaining the image. |
void |
setSource(java.lang.String newValue)
Sets the source (location) for obtaining the image. |
void |
setSourceAbsolute(java.lang.String newValue)
Sets the absolute source name for the image to display. |
void |
setSourceAppletRelative(boolean newValue)
Sets the source to be relative to the applet location. |
void |
setSourceRelative(java.lang.String newValue)
Sets the relative source. |
void |
setSourceURL(java.net.URL newValue)
Sets the URL object for the image file to be displayed. |
protected boolean |
validateDisplayMode(int mode)
Validate the displayMode value. |
Methods inherited from interface com.sas.visuals.IconInterface |
---|
getPreferredSize |
Field Detail |
---|
public static final java.lang.String RB_KEY
public static final int NO_SCALE
public static final int SCALE
public static final int SCALE_HEIGHT
public static final int SCALE_WIDTH
public static final int TILE
public static final int AUTO_SCALE
public static final int LAST_DISPLAY_MODE
protected transient java.awt.Image image
protected transient java.awt.Image dispImage
protected transient java.awt.Image filteredImage
protected transient java.awt.Image disabledImage
protected transient java.awt.Image missingImage
protected transient int oldWidth
protected transient int oldHeight
protected java.awt.Insets currentInsets
protected java.lang.String source
protected boolean imageWait
protected int displayMode
protected boolean defaultImageLoaded
protected java.lang.String absoluteSource
protected java.lang.String relativeSourceClassName
protected transient java.lang.Class relativeSourceClass
protected java.lang.String relativeSource
protected java.net.URL sourceURL
protected boolean sourceAppletRelative
protected com.sas.net.ResourceLocatorInterface resourceLocator
Constructor Detail |
---|
public ImageView()
public ImageView(java.net.URL srcURL)
srcURL
- the URL of the image sourcesetSourceURL(java.net.URL)
public ImageView(java.lang.Class relativeClass, java.lang.String relativeSrc)
relativeClass
- the class relative to the image sourcerelativeSrc
- the source relative to the class givensetSourceRelative(java.lang.String)
,
setRelativeSourceClass(java.lang.Class)
public ImageView(java.lang.String src)
src
- full valid path string to an imagesetSource(java.lang.String)
public ImageView(java.awt.Image img)
img
- a java.awt.Image to displaysetImage(java.awt.Image)
public ImageView(com.sas.net.ResourceLocatorInterface resourceLocator)
resourceLocator
- an instance of ResourceLocatorInterface to locate the imagesetResourceLocator(ResourceLocatorInterface)
,
ResourceLocatorInterface
Method Detail |
---|
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
com.sas.beans.Introspector
to
augment the automatically introspected information about this ImageView.
public static int getDefaultHeight()
public static int getDefaultWidth()
public static void setDefaultHeight(int newHeight)
newHeight
- the default height of an ImageView objectpublic static void setDefaultWidth(int newWidth)
newWidth
- the default width of an ImageView objectpublic void attachModel(com.sas.ModelInterface model)
attachModel
in interface com.sas.ViewInterface
attachModel
in class ComponentVisualComponent
model
- Model to attach toViewInterface.attachModel(com.sas.ModelInterface)
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in interface com.sas.PublicClonable
clone
in class ComponentVisualComponent
java.lang.CloneNotSupportedException
- if clone creation failspublic void detachModel(com.sas.ModelInterface model)
detachModel
in interface com.sas.ViewInterface
detachModel
in class ComponentVisualComponent
model
- Model to detachViewInterface.detachModel(com.sas.ModelInterface)
public void addNotify()
addNotify
in class java.awt.Component
public static final boolean imageExists(com.sas.net.ResourceLocatorInterface rli)
rli
- an instance of a ResourceLocatorInterface that should have an image set as the resourceResourceLocatorInterface
public java.awt.Image getMissingFileImage()
public java.util.Vector getRequiredInterfaces()
getRequiredInterfaces
in interface com.sas.ViewInterface
getRequiredInterfaces
in class ComponentVisualComponent
ViewInterface.getRequiredInterfaces()
public java.awt.Image createFilteredImage(java.awt.Image img, java.awt.image.ImageFilter imgFilter)
img
- the image to create a filtered image of.imgFilter
- the filter to use on the img object.
protected java.awt.Image createTiledImage(java.awt.Image img, int width, int height)
img
- the image to create a tiled image of.width
- the width in pixels that the image should be tiled withinheight
- the height in pixels that the image should be tiled within
protected java.awt.Image createDisabledImage(java.awt.Image img)
img
- the image to create a disabled image of.
protected void createDisplayImage(int width, int height)
width
- the width of the area to display the image in.height
- the height of the area to display the image in.protected void loadDisplayImage()
public int getDisplayMode()
setDisplayMode(int)
public java.awt.Image getImage()
setImage(java.awt.Image)
public java.awt.image.ImageFilter getImageFilter()
setImageFilter(java.awt.image.ImageFilter)
public boolean isImageLoadWait()
setImageLoadWait(boolean)
public java.awt.Insets getInsets()
getInsets
in interface com.sas.visuals.PainterInterface
setInsets(java.awt.Insets)
public java.awt.MediaTracker getMediaTracker()
public java.awt.Dimension getMinimumSize()
getMinimumSize
in interface VisualInterface
getMinimumSize
in class Component
computePreferredSize()
public java.awt.Dimension computePreferredSize()
computePreferredSize
in interface VisualInterface
computePreferredSize
in class ComponentVisualComponent
getMinimumSize()
public java.lang.String getSource()
setSource(java.lang.String)
public boolean isResizeToFit()
isResizeToFit
in interface ResizeToFitInterface
setResizeToFit(boolean)
,
resizeToFit
public void paint(java.awt.Graphics g)
paint
in class ComponentVisualComponent
g
- the specified Graphics contextVisualInterfaceSupport.paint(com.sas.ComponentInterface, com.sas.awt.VisualInterface, java.awt.Component, java.awt.Graphics)
public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
x
, y
)
in the coordinate space of the graphics context g
.
paintIcon
in interface javax.swing.Icon
c
- the component to be used as the observerg
- the graphics contextx
- the X coordinate of the icon's top-left cornery
- the Y coordinate of the icon's top-left cornerpublic int getIconWidth()
getIconWidth
in interface javax.swing.Icon
public int getIconHeight()
getIconHeight
in interface javax.swing.Icon
public void paint(java.awt.Component comp, java.awt.Graphics g, int x, int y, int width, int height)
paint
in interface com.sas.visuals.PainterInterface
comp
- the Component to paint the IconInterface with.g
- Graphics contextx
- the x coordinatey
- the y coordinatewidth
- the width to be painted.height
- the height to be painted.IconInterface
public void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
propertyChange
in class ComponentVisualComponent
event
- The event from the model indicating what property changed.PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)
public void refresh(com.sas.ModelInterface model)
refresh
in interface com.sas.ViewInterface
refresh
in class ComponentVisualComponent
model
- the model that has changed and needs to be refreshedViewInterface.refresh(com.sas.ModelInterface)
public void refresh()
public void resizeToFit()
setResizeToFit(boolean)
,
isResizeToFit()
public void setBounds(int x, int y, int width, int height)
setBounds
in interface VisualInterface
setBounds
in class ComponentVisualComponent
ComponentVisualComponent.setBounds(int, int, int, int)
public void setDefaultValues()
setDefaultValues
in interface VisualInterface
setDefaultValues
in interface com.sas.ComponentInterface
setDefaultValues
in class Component
ComponentInterface.setDefaultValues()
public void setDisplayMode(int mode)
mode
- any of the displayMode ids defined in this class.getDisplayMode()
protected boolean validateDisplayMode(int mode)
mode
- the displayMode to validate.
public void setInsets(java.awt.Insets newInsets)
newInsets
- the new Insets.getInsets()
public void setResizeToFit(boolean resizeToFit)
setResizeToFit
in interface ResizeToFitInterface
resizeToFit
- boolean valueisResizeToFit()
public void setImage(java.awt.Image img)
img
- the image object to be displayedgetImage(java.lang.Object)
public void setImageFilter(java.awt.image.ImageFilter imgFilter)
imgFilter
- the image filter applied to the original image.getImageFilter()
public void setImageLoadWait(boolean loadWait)
loadWait
- true to set the ImageView to wait for the image to load before displayingisImageLoadWait()
public void setResourceLocator(com.sas.net.ResourceLocatorInterface newValue)
setResourceLocator
in interface ResourceConsumerInterface
newValue
- the instance of ResourceLocatorInterface for obtaining the imagegetResourceLocator()
,
ResourceLocatorInterface
,
BaseResourceLocator
,
AppletResourceLocator
,
FileResourceLocator
,
ClassResourceLocator
,
ContextResourceLocator
,
URL
public com.sas.net.ResourceLocatorInterface getResourceLocator()
getResourceLocator
in interface ResourceConsumerInterface
setSourceAbsolute(java.lang.String)
,
ResourceLocatorInterface
,
AppletResourceLocator.getAbsolutePath()
public void setSource(java.lang.String newValue)
newValue
- the location for obtaining the imagegetSource()
,
ResourceLocatorInterface
,
URL
,
ClassLoader.getSystemResource(java.lang.String)
,
Class.getResource(java.lang.String)
public java.lang.String getSourceAbsolute()
setSourceAbsolute(java.lang.String)
,
ResourceLocatorInterface
,
AppletResourceLocator.getAbsolutePath()
public void setSourceAbsolute(java.lang.String newValue)
newValue
- the string path and name of the image to display.getSourceAbsolute()
,
ResourceLocatorInterface
,
FileResourceLocator
,
Toolkit.getImage(java.lang.String)
public java.net.URL getSourceURL()
setSourceURL(java.net.URL)
,
ResourceLocatorInterface
,
ResourceLocatorInterface.getResource()
,
Toolkit.getImage(java.lang.String)
public void setSourceURL(java.net.URL newValue)
newValue
- the URL of the image to displaygetSourceURL()
,
ResourceLocatorInterface
,
BaseResourceLocator
,
Toolkit.getImage(java.lang.String)
public boolean isSourceAppletRelative()
AppletResourceLocator
public void setSourceAppletRelative(boolean newValue)
newValue
- true if the source is located relative to the applet containing the ImageViewGlobalInfoTable.getApplet()
,
ResourceLocatorInterface
,
AppletResourceLocator
,
FileResourceLocator
,
Class.getResource(java.lang.String)
public java.lang.String getSourceRelative()
setSourceRelative(java.lang.String)
,
ResourceLocatorInterface
public void setSourceRelative(java.lang.String newValue)
src
- the relative path and name of the image source.getSourceRelative()
,
ResourceLocatorInterface
,
AppletResourceLocator
,
ClassResourceLocator
,
ClassLoader.getSystemResource(java.lang.String)
,
Class.getResource(java.lang.String)
public java.lang.Class getRelativeSourceClass()
setSourceRelative(java.lang.String)
,
getRelativeSourceClass()
,
ResourceLocatorInterface
,
AppletResourceLocator
,
ClassResourceLocator
public void setRelativeSourceClass(java.lang.Class newValue)
relativeClass
- the class used to get the URL of the relative source.ResourceLocatorInterface
,
ClassResourceLocator
,
setSourceRelative(java.lang.String)
,
getRelativeSourceClass()
public void print(java.awt.Graphics g, int pageNumber, int pageWidth, int pageHeight) throws com.sas.awt.print.PrintException
ComponentVisualComponent
This implementation temporarily resizes the component via
setSize(pageWidth, pageHeight)
and calls the standard print method, print(g)
.
Therefore, subclasses should make sure that their paint method, which
is called by the default implementation of standard print, is
synchronized, as print is here, to guard against an independent call to
paint, due to a window refresh for example, inadvertently using this
size change.
Subclasses with multiple pages will have to override
pageExists()
since it returns false
for
page numbers other than one which will cause the implementation of this
method to throw an IndexOutOfBoundsException. Such subclasses will
also need to override this method in order to change pages.
print
in interface com.sas.awt.print.PrintableInterface
print
in class ComponentVisualComponent
g
- The graphics context to use for printing.pageNumber
- The one-based index of the page to be printed.pageWidth
- The width of the page (in pixels) being printed to.pageHeight
- The height of the page (in pixels) being printed to.
com.sas.awt.print.PrintException
- Thrown if a failure occurred while printing.PrintableInterface.print(java.awt.Graphics, int, int, int)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |