Package weka.gui.visualize
Class JComponentWriter
java.lang.Object
weka.gui.visualize.JComponentWriter
- Direct Known Subclasses:
BMPWriter
,JPEGWriter
,PNGWriter
,PostscriptWriter
This class takes any JComponent and outputs it to a file. Scaling is by
default enabled. Derived classes only need to override the following
methods:
getDescription()
getExtension()
generateOutput()
- Version:
- $Revision: 8034 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
-
Constructor Summary
ConstructorDescriptioninitializes the objectinitializes the object with the given ComponentJComponentWriter
(JComponent c, File f) initializes the object with the given Component and filename -
Method Summary
Modifier and TypeMethodDescriptionreturns the component that is stored in the output formatint
gets the custom height currently usedint
gets the custom width currently usedabstract String
returns the name of the writer, to display in the FileChooser.abstract String
returns the extension (incl.getFile()
returns the file being used for storing the outputboolean
whether scaling is enabled or ignoredboolean
whether custom dimensions are to used for the size of the imagedouble
returns the scale factor for the x-axisdouble
returns the scale factor for the y-axisvoid
sets the component to print to an output formatvoid
setCustomHeight
(int value) sets the custom height to usevoid
setCustomWidth
(int value) sets the custom width to usevoid
sets the file to store the output invoid
setScale
(double x, double y) sets the scale factor - is ignored since we always create a screenshot!void
setScalingEnabled
(boolean enabled) sets whether to enable scalingvoid
setUseCustomDimensions
(boolean value) sets whether to use custom dimensions for the imagevoid
toOutput()
saves the current component to the currently set file.static void
toOutput
(JComponentWriter writer, JComponent comp, File file) outputs the given component with the given writer in the specified filestatic void
toOutput
(JComponentWriter writer, JComponent comp, File file, int width, int height) outputs the given component with the given writer in the specified file.
-
Constructor Details
-
JComponentWriter
public JComponentWriter()initializes the object -
JComponentWriter
initializes the object with the given Component- Parameters:
c
- the component to print in the output format
-
JComponentWriter
initializes the object with the given Component and filename- Parameters:
c
- the component to print in the output formatf
- the file to store the output in
-
-
Method Details
-
setComponent
sets the component to print to an output format- Parameters:
c
- the component to print
-
getComponent
returns the component that is stored in the output format- Returns:
- the component to print
-
setFile
sets the file to store the output in- Parameters:
f
- the file to store the output in
-
getFile
returns the file being used for storing the output- Returns:
- the file to store the output in
-
getDescription
returns the name of the writer, to display in the FileChooser. must be overridden in the derived class.- Returns:
- the name of the writer
-
getExtension
returns the extension (incl. ".") of the output format, to use in the FileChooser. must be overridden in the derived class.- Returns:
- the file extension
-
getScalingEnabled
public boolean getScalingEnabled()whether scaling is enabled or ignored- Returns:
- true if scaling is enabled
-
setScalingEnabled
public void setScalingEnabled(boolean enabled) sets whether to enable scaling- Parameters:
enabled
- whether scaling is enabled
-
setScale
public void setScale(double x, double y) sets the scale factor - is ignored since we always create a screenshot!- Parameters:
x
- the scale factor for the x-axisy
- the scale factor for the y-axis
-
getXScale
public double getXScale()returns the scale factor for the x-axis- Returns:
- the scale scale factor for the x-axis
-
getYScale
public double getYScale()returns the scale factor for the y-axis- Returns:
- the scale scale factor for the y-axis
-
getUseCustomDimensions
public boolean getUseCustomDimensions()whether custom dimensions are to used for the size of the image- Returns:
- true if custom dimensions are used
-
setUseCustomDimensions
public void setUseCustomDimensions(boolean value) sets whether to use custom dimensions for the image- Parameters:
value
- whether custom dimensions are used
-
setCustomWidth
public void setCustomWidth(int value) sets the custom width to use- Parameters:
value
- the width to use- See Also:
-
m_UseCustomDimensions
-
getCustomWidth
public int getCustomWidth()gets the custom width currently used- Returns:
- the custom width currently used
- See Also:
-
m_UseCustomDimensions
-
setCustomHeight
public void setCustomHeight(int value) sets the custom height to use- Parameters:
value
- the height to use- See Also:
-
m_UseCustomDimensions
-
getCustomHeight
public int getCustomHeight()gets the custom height currently used- Returns:
- the custom height currently used
- See Also:
-
m_UseCustomDimensions
-
toOutput
saves the current component to the currently set file.Note: this method calls
generateOutput()
which needs to be overriden in subclasses!- Throws:
Exception
- if either the file or the component isnull
-
toOutput
outputs the given component with the given writer in the specified file- Parameters:
writer
- the writer to usecomp
- the component to outputfile
- the file to store the output in- Throws:
Exception
- if component of file arenull
-
toOutput
public static void toOutput(JComponentWriter writer, JComponent comp, File file, int width, int height) throws Exception outputs the given component with the given writer in the specified file. If width and height are different from -1 then these sizes are used, otherwise the current ones of the component- Parameters:
writer
- the writer to usecomp
- the component to outputfile
- the file to store the output inwidth
- custom width, -1 uses the component's oneheight
- custom height, -1 uses the component's one- Throws:
Exception
- if component or file arenull
-