MATES 3.0-rc2

org.mates.util
Class Screenshot

java.lang.Object
  extended byorg.mates.util.Screenshot

public class Screenshot
extends java.lang.Object

A class for taking and saving screenshots of arbitrary objects.

Author:
Evan Sultanik

Constructor Summary
Screenshot()
           
 
Method Summary
static java.lang.reflect.Method getPaintMethod(java.lang.Class c)
          Determines if a given class implements the paint(java.awt.Graphics) method.
static java.io.File getScreenshotSaveFile(java.awt.Component parent)
          Prompts the user for a file to which to save a screenshot.
static boolean saveScreenshot(java.lang.Object screenshot_provider, int width, int height, java.io.File file)
          Saves a screenshot of a given object that implements the paint(java.awt.Graphics) method.
static boolean saveScreenshot(java.lang.Object screenshot_provider, int width, int height, java.io.File file, java.awt.Component parent)
          Saves a screenshot of a given object that implements the paint(java.awt.Graphics) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Screenshot

public Screenshot()
Method Detail

getScreenshotSaveFile

public static java.io.File getScreenshotSaveFile(java.awt.Component parent)
Prompts the user for a file to which to save a screenshot.

Parameters:
parent - the parent component of the dialog; can be null.
Returns:
the file to which to save the screenshot. null is returned if the user cancelled the save.

getPaintMethod

public static java.lang.reflect.Method getPaintMethod(java.lang.Class c)
Determines if a given class implements the paint(java.awt.Graphics) method.

Returns:
the paint method of a class. If the class does not implement paint, null is returned.

saveScreenshot

public static boolean saveScreenshot(java.lang.Object screenshot_provider,
                                     int width,
                                     int height,
                                     java.io.File file)
                              throws java.lang.IllegalArgumentException,
                                     java.lang.ClassNotFoundException,
                                     java.io.IOException
Saves a screenshot of a given object that implements the paint(java.awt.Graphics) method.

Parameters:
screenshot_provider - an object that implements the paint(java.awt.Graphics) method. This method will be called to draw the screenshot.
width - the width of the screenshot
height - the height of the screenshot
file - the file to which to save the screenshot. The filetype is determined by the file's extension. Currently, only PNG and EPS are supported. EPS requires that the EpsGraphics2D package is currently in Java's classpath. This package can be freely downloaded from http://www.jibble.org/epsgraphics/.
Returns:
true on success. false will be returned if file is not of a supported image type.
Throws:
java.lang.IllegalArgumentException - if screenshot_provider does not have the paint(java.awt.Graphics) method implemented.
java.lang.ClassNotFoundException - when writing to an EPS file and org.jibble.epsgraphics.EpsGraphics2D cannot be found.
java.io.IOException - on error writing to file.

saveScreenshot

public static boolean saveScreenshot(java.lang.Object screenshot_provider,
                                     int width,
                                     int height,
                                     java.io.File file,
                                     java.awt.Component parent)
                              throws java.lang.IllegalArgumentException
Saves a screenshot of a given object that implements the paint(java.awt.Graphics) method.

Parameters:
screenshot_provider - an object that implements the paint(java.awt.Graphics) method. This method will be called to draw the screenshot.
width - the width of the screenshot
height - the height of the screenshot
file - the file to which to save the screenshot. The filetype is determined by the file's extension. Currently, only PNG and EPS are supported. EPS requires that the EpsGraphics2D package is currently in Java's classpath. This package can be freely downloaded from http://www.jibble.org/epsgraphics/.
parent - the parent component, to which to draw dialogs; can be null.
Returns:
true on success. false will be returned if file is not of a supported image type.
Throws:
java.lang.IllegalArgumentException - if screenshot_provider does not have the paint(java.awt.Graphics) method implemented.

MATES 3.0-rc2

Submit a bug or request a feature
http://mates.sourceforge.net/

Copyright 2004 Evan Sultanik