Package weka.gui.visualize

# Class JComponentWriter

java.lang.Object
weka.gui.visualize.JComponentWriter

Direct Known Subclasses:
  `BMPWriter`, `JPEGWriter`, `PNGWriter`, `PostscriptWriter`

public abstract class JComponentWriter extends Object
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: 7059 $
Author:
  FracPete (fracpete at waikato dot ac dot nz)
See Also:
  - `setScalingEnabled(boolean)`

## Constructor Summary

Constructors
Constructor
Description
`JComponentWriter()`
initializes the object
`JComponentWriter(JComponent c)`
initializes the object with the given Component
`JComponentWriter(JComponent c, File f)`
initializes the object with the given Component and filename

## Method Summary

Modifier and Type
Method
Description
`JComponent`
`getComponent()`
returns the component that is stored in the output format
`int`
`getCustomHeight()`
gets the custom height currently used
`int`
`getCustomWidth()`
gets the custom width currently used
`abstract String`
`getDescription()`
returns the name of the writer, to display in the FileChooser.
`abstract String`
`getExtension()`
returns the extension (incl.
`File`
`getFile()`
returns the file being used for storing the output
`boolean`
`getScalingEnabled()`
whether scaling is enabled or ignored
`boolean`
`getUseCustomDimensions()`
whether custom dimensions are to used for the size of the image
`double`
`getXScale()`
returns the scale factor for the x-axis
`double`
`getYScale()`
returns the scale factor for the y-axis
`void`
`setComponent(JComponent c)`
sets the component to print to an output format
`void`
`setCustomHeight(int value)`
sets the custom height to use
`void`
`setCustomWidth(int value)`
sets the custom width to use
`void`
`setFile(File f)`
sets the file to store the output in
`void`
`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 scaling
`void`
`setUseCustomDimensions(boolean value)`
sets whether to use custom dimensions for the image
`void`
`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 file
`static void`
`toOutput(JComponentWriter writer, JComponent comp, File file, int width, int height)`
outputs the given component with the given writer in the specified file.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JComponentWriter

public JComponentWriter()
initializes the object

### JComponentWriter

public JComponentWriter(JComponent c)
initializes the object with the given Component

Parameters:
  `c` - the component to print in the output format

### JComponentWriter

public JComponentWriter(JComponent c, File f)
initializes the object with the given Component and filename

Parameters:
  `c` - the component to print in the output format
  `f` - the file to store the output in

## Method Details

### setComponent

public void setComponent(JComponent c)
sets the component to print to an output format

Parameters:
  `c` - the component to print

### getComponent

public JComponent getComponent()
returns the component that is stored in the output format

Returns:
  the component to print

### setFile

public void setFile(File f)
sets the file to store the output in

Parameters:
  `f` - the file to store the output in

### getFile

public File getFile()
returns the file being used for storing the output

Returns:
  the file to store the output in

### getDescription

public abstract String 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

public abstract String 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-axis
  `y` - 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

public void toOutput() throws Exception
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 is `null`

### toOutput

public static void toOutput(JComponentWriter writer, JComponent comp, File file) throws Exception
outputs the given component with the given writer in the specified file

Parameters:
  `writer` - the writer to use
  `comp` - the component to output
  `file` - the file to store the output in
Throws:
  `Exception` - if component of file are `null`

### 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 use
  `comp` - the component to output
  `file` - the file to store the output in
  `width` - custom width, -1 uses the component's one
  `height` - custom height, -1 uses the component's one
Throws:
  `Exception` - if component or file are `null`