Class AutoWidthTabularSpreadSheetWriter

  • All Implemented Interfaces:
    AdditionalInformationHandler, Destroyable, GlobalInfoSupporter, EncodingSupporter, LoggingLevelHandler, LoggingSupporter, LocaleSupporter, OptionHandlingLocaleSupporter, OptionHandler, SizeOfHandler, Stoppable, StoppableWithFeedback, NoHeaderSpreadSheetWriter, SpreadSheetWriter, Serializable

    public class AutoWidthTabularSpreadSheetWriter
    extends AbstractFormattedSpreadSheetWriter
    implements NoHeaderSpreadSheetWriter
    Outputs the spreadsheet in a simple tabular format with column widths to fit the content in each row.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
        min-user-mode: Expert
     
    -missing <java.lang.String> (property: missingValue)
        The placeholder for missing values.
        default:
     
    -locale <java.util.Locale> (property: locale)
        The locale to use for formatting the numbers.
        default: Default
     
    -number-format <java.lang.String> (property: numberFormat)
        The format for the numbers (see java.text.DecimalFormat), use empty string
        for default 'double' output.
        default:
     
    -encoding <adams.core.base.BaseCharset> (property: encoding)
        The type of encoding to use when writing using a writer, use empty string
        for default.
        default: Default
     
    -num-spaces <int> (property: numSpaces)
        The number of spaces to use between columns.
        default: 1
        minimum: 1
     
    -new-line <java.lang.String> (property: newLine)
        The newline character(s) to use for the columns; use '\r' for carriage return
        and '\n' for line feed; Linux/Unix use '\n', Windows uses '\r\n' and old
        Macs use '\r'.
        default: \\n
     
    -date-format <adams.data.DateFormatString> (property: dateFormat)
        The format for dates.
        default: yyyy-MM-dd
        more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
     
    -datetime-format <adams.data.DateFormatString> (property: dateTimeFormat)
        The format for date/times.
        default: yyyy-MM-dd HH:mm:ss
        more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
     
    -datetimemsec-format <adams.data.DateFormatString> (property: dateTimeMsecFormat)
        The format for date/time msecs.
        default: yyyy-MM-dd HH:mm:ss.SSS
        more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
     
    -time-format <adams.data.DateFormatString> (property: timeFormat)
        The format for times.
        default: HH:mm:ss
        more: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
     
    -no-header <boolean> (property: noHeader)
        If enabled, no header is output.
        default: false
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_NumSpaces

        protected int m_NumSpaces
        the number of spaces between columns.
      • m_NewLine

        protected String m_NewLine
        the new line.
      • m_DateFormat

        protected DateFormatString m_DateFormat
        the format string for the dates.
      • m_DateTimeFormat

        protected DateFormatString m_DateTimeFormat
        the format string for the date/times.
      • m_DateTimeMsecFormat

        protected DateFormatString m_DateTimeMsecFormat
        the format string for the date/times msec.
      • m_TimeFormat

        protected DateFormatString m_TimeFormat
        the format string for the times.
      • m_NoHeader

        protected boolean m_NoHeader
        whether to skip outputting the header.
    • Constructor Detail

      • AutoWidthTabularSpreadSheetWriter

        public AutoWidthTabularSpreadSheetWriter()
    • Method Detail

      • setNumSpaces

        public void setNumSpaces​(int value)
        Sets the number of spaces between columns.
        Parameters:
        value - the spaces
      • getNumSpaces

        public int getNumSpaces()
        Returns the number of spaces between columns.
        Returns:
        the spaces
      • numSpacesTipText

        public String numSpacesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNewLine

        public void setNewLine​(String value)
        Sets the string to use as newline.
        Parameters:
        value - the character(s)
      • getNewLine

        public String getNewLine()
        Returns the string used as newline.
        Returns:
        the character(s)
      • newLineTipText

        public String newLineTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setDateFormat

        public void setDateFormat​(DateFormatString value)
        Sets the format for date columns.
        Parameters:
        value - the format
      • getDateFormat

        public DateFormatString getDateFormat()
        Returns the format for date columns.
        Returns:
        the format
      • dateFormatTipText

        public String dateFormatTipText()
        Returns the tip date for this property.
        Returns:
        tip date for this property suitable for displaying in the gui
      • setDateTimeFormat

        public void setDateTimeFormat​(DateFormatString value)
        Sets the format for date/time columns.
        Parameters:
        value - the format
      • getDateTimeFormat

        public DateFormatString getDateTimeFormat()
        Returns the format for date/time columns.
        Returns:
        the format
      • dateTimeFormatTipText

        public String dateTimeFormatTipText()
        Returns the tip date/time for this property.
        Returns:
        tip date for this property suitable for displaying in the gui
      • setDateTimeMsecFormat

        public void setDateTimeMsecFormat​(DateFormatString value)
        Sets the format for date/time msec columns.
        Parameters:
        value - the format
      • getDateTimeMsecFormat

        public DateFormatString getDateTimeMsecFormat()
        Returns the format for date/time msec columns.
        Returns:
        the format
      • dateTimeMsecFormatTipText

        public String dateTimeMsecFormatTipText()
        Returns the tip date/time for this property.
        Returns:
        tip date for this property suitable for displaying in the gui
      • setTimeFormat

        public void setTimeFormat​(DateFormatString value)
        Sets the format for time columns.
        Parameters:
        value - the format
      • getTimeFormat

        public DateFormatString getTimeFormat()
        Returns the format for time columns.
        Returns:
        the format
      • timeFormatTipText

        public String timeFormatTipText()
        Returns the tip time for this property.
        Returns:
        tip time for this property suitable for displaying in the gui
      • setNoHeader

        public void setNoHeader​(boolean value)
        Sets whether to use a header or not.
        Specified by:
        setNoHeader in interface NoHeaderSpreadSheetWriter
        Parameters:
        value - true if to skip header
      • noHeaderTipText

        public String noHeaderTipText()
        Returns the tip text for this property.
        Specified by:
        noHeaderTipText in interface NoHeaderSpreadSheetWriter
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • determineColWidths

        protected int[] determineColWidths​(SpreadSheet content)
        Determines the column widths.
        Parameters:
        content - the spreadsheet to use for calculation
        Returns:
        the widths
      • pad

        protected String pad​(String s,
                             int width,
                             boolean leftPad)
        Pads a string either on the left or the right hand side with blanks.
        Parameters:
        s - the string to pad
        width - the maximum width to pad to
        leftPad - whether to pad on the left or right
        Returns:
        the padded string
      • doWrite

        protected boolean doWrite​(SpreadSheet content,
                                  Writer writer)
        Performs the actual writing. The caller must ensure that the writer gets closed.
        Overrides:
        doWrite in class AbstractSpreadSheetWriter
        Parameters:
        content - the spreadsheet to write
        writer - the writer to write the spreadsheet to
        Returns:
        true if successfully written