Package adams.gui.print
Class JComponentWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.gui.print.JComponentWriter
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,Serializable
- Direct Known Subclasses:
NullWriter
,ScalableComponentWriter
public abstract class JComponentWriter extends AbstractOptionHandler
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()
Based on weka.gui.visualize.JComponentWriter- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected JComponent
m_Component
the component to print in the output format.protected int
m_CustomHeight
the custom height.protected int
m_CustomWidth
the custom width.protected boolean
m_Enabled
whether the writer is enabled.protected PlaceholderFile
m_OutputFile
the file to write the output stream to.protected boolean
m_UseCustomDimensions
whether to use custom dimensions.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description JComponentWriter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
customHeightTipText()
Returns the tip text for this property.String
customWidthTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.String
enabledTipText()
Returns the tip text for this property.String
fileTipText()
Returns the tip text for this property.static JComponentWriter
forCommandLine(String cmdline)
Instantiates the writer from the given commandline (i.e., classname and optional options).static JComponentWriter
forName(String classname, String[] options)
Instantiates the writer with the given options.protected abstract void
generateOutput()
generates the actual output.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.boolean
getEnabled()
Returns whether the writer is enabled.abstract String[]
getExtensions()
returns the extensions (incl.PlaceholderFile
getFile()
returns the file being used for storing the output.static JComponentWriterFileFilter[]
getFileFilters()
Returns an array with all the available extension file filters.boolean
getUseCustomDimensions()
whether custom dimensions are to used for the size of the image.static JComponentWriter
getWriterForExtension(String ext)
Returns the appropriate writer for the given extension.static JComponentWriter
getWriterForFile(File file)
Returns the appropriate writer for the given file.static JComponentWriter
getWriterForFile(String filename)
Returns the appropriate writer for the given filename.static String[]
getWriters()
Returns a list with classnames of writers.static void
main(String[] args)
For testing only.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
setEnabled(boolean value)
Sets whether the writer is enabled.void
setFile(PlaceholderFile value)
sets the file to store the output in.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.String
useCustomDimensionsTipText()
Returns the tip text for this property.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_Component
protected transient JComponent m_Component
the component to print in the output format.
-
m_Enabled
protected boolean m_Enabled
whether the writer is enabled.
-
m_OutputFile
protected PlaceholderFile m_OutputFile
the file to write the output stream to.
-
m_UseCustomDimensions
protected boolean m_UseCustomDimensions
whether to use custom dimensions.
-
m_CustomWidth
protected int m_CustomWidth
the custom width.
-
m_CustomHeight
protected int m_CustomHeight
the custom height.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
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
-
setEnabled
public void setEnabled(boolean value)
Sets whether the writer is enabled.- Parameters:
value
- true if to enable writer
-
getEnabled
public boolean getEnabled()
Returns whether the writer is enabled.- Returns:
- true if writer is enabled
-
enabledTipText
public String enabledTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setFile
public void setFile(PlaceholderFile value)
sets the file to store the output in.- Parameters:
value
- the file to store the output in
-
getFile
public PlaceholderFile getFile()
returns the file being used for storing the output.- Returns:
- the file to store the output in
-
fileTipText
public String fileTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
getExtensions
public abstract String[] getExtensions()
returns the extensions (incl. ".") of the output format, to use in the FileChooser. Must be overridden in the derived class.- Returns:
- the file extensions
-
setUseCustomDimensions
public void setUseCustomDimensions(boolean value)
sets whether to use custom dimensions for the image.- Parameters:
value
- whether custom dimensions are used
-
getUseCustomDimensions
public boolean getUseCustomDimensions()
whether custom dimensions are to used for the size of the image.- Returns:
- true if custom dimensions are used
-
useCustomDimensionsTipText
public String useCustomDimensionsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
customWidthTipText
public String customWidthTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
customHeightTipText
public String customHeightTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
generateOutput
protected abstract void generateOutput() throws Exception
generates the actual output.- Throws:
Exception
- if something goes wrong
-
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 isnull
-
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 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
-
getWriters
public static String[] getWriters()
Returns a list with classnames of writers.- Returns:
- the writer classnames
-
getFileFilters
public static JComponentWriterFileFilter[] getFileFilters()
Returns an array with all the available extension file filters. Only adds writers that produce actual output.- Returns:
- the filters
-
getWriterForFile
public static JComponentWriter getWriterForFile(File file)
Returns the appropriate writer for the given file. Defaults to first writer it finds, if extension cannot be matched.- Parameters:
file
- the file to get writer for- Returns:
- the writer
-
getWriterForFile
public static JComponentWriter getWriterForFile(String filename)
Returns the appropriate writer for the given filename. Defaults to first writer it finds, if extension cannot be matched.- Parameters:
filename
- the filename to get writer for- Returns:
- the writer
-
getWriterForExtension
public static JComponentWriter getWriterForExtension(String ext)
Returns the appropriate writer for the given extension. Defaults to first writer it finds, if extension cannot be matched.- Parameters:
ext
- the file extension (with or without ".")- Returns:
- the writer
-
forName
public static JComponentWriter forName(String classname, String[] options)
Instantiates the writer with the given options.- Parameters:
classname
- the classname of the writer to instantiateoptions
- the options for the writer- Returns:
- the instantiated writer or null if an error occurred
-
forCommandLine
public static JComponentWriter forCommandLine(String cmdline)
Instantiates the writer from the given commandline (i.e., classname and optional options).- Parameters:
cmdline
- the classname (and optional options) of the writer to instantiate- Returns:
- the instantiated writer or null if an error occurred
-
-