Class ImageExporter

  • All Implemented Interfaces:
    IExporter, ITableExporter

    public class ImageExporter
    extends Object
    implements ITableExporter
    This class is used to export a NatTable to different types of image. Currently, 4 types of image are supported: BMP, JPEG, JPG, PNG. GIF is not supported due to its limitation on image depth described in the bug 38232.

    Warning: Using this class is risky as it could cause severe damage to NatTables that show huge data sets (for example: a table with more than 20k rows).

    Since:
    1.5
    • Constructor Detail

      • ImageExporter

        public ImageExporter()
        Default constructor to create a new image exporter.
      • ImageExporter

        public ImageExporter​(IOutputStreamProvider outputStreamProvider)
        Create a new ImageExporter that uses the given IOutputStreamProvider for retrieving the OutputStream.
        Parameters:
        outputStreamProvider - The IOutputStreamProvider used to retrieve the OutputStream to write the export to.
    • Method Detail

      • getResult

        public Object getResult()
        Specified by:
        getResult in interface IExporter
        Returns:
        The result that is produced by this ITableExporter. Usually the file that is created or written by this exporter.
      • exportTable

        public void exportTable​(org.eclipse.swt.widgets.Shell shell,
                                org.eclipse.swt.widgets.ProgressBar progressBar,
                                OutputStream outputStream,
                                ILayer layer,
                                IConfigRegistry configRegistry)
                         throws IOException
        Export the given layer of the nattable to image. This method must be called after the execution of the getOutputStream(Shell) method.
        Specified by:
        exportTable in interface ITableExporter
        Parameters:
        shell - The parent shell
        layer - The layer to be exported
        configRegistry - The configure registry of the nattable
        progressBar - The ProgressBar that can be used to report the export progress to the user.
        outputStream - The OutputStream to write the export to. Typically previously retrieved by calling IExporter.getOutputStream(Shell).
        Throws:
        IOException - If an error occurs while exporting.
      • getImageFormatIndex

        protected int getImageFormatIndex​(String selectedFilterExt)
        Get the image format index by the filter extension.
        Parameters:
        selectedFilterExt - The selected filter extension
        Returns:
        The image index or -1 if not found
      • getOutputStream

        public OutputStream getOutputStream​(org.eclipse.swt.widgets.Shell shell)
        Description copied from interface: IExporter
        Get the OutputStream to which the export should be written to.
        Specified by:
        getOutputStream in interface IExporter
        Parameters:
        shell - The Shell to which the ILayer to export is connected to. Necessary to support user interactions via dialogs on configuring the output location.
        Returns:
        The OutputStream to write the export to.