Class JComponentWriter

    • 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.
    • Constructor Detail

      • JComponentWriter

        public JComponentWriter()
    • Method Detail

      • 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 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
      • 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 instantiate
        options - 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
      • main

        public static void main​(String[] args)
                         throws Exception
        For testing only.
        Parameters:
        args - ignored
        Throws:
        Exception - if something goes wrong