Package adams.data.io.output
Class FixedTabularSpreadSheetWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractSpreadSheetWriter
-
- adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
-
- adams.data.io.output.AbstractFormattedSpreadSheetWriter
-
- adams.data.io.output.FixedTabularSpreadSheetWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler
,Destroyable
,GlobalInfoSupporter
,EncodingSupporter
,LoggingLevelHandler
,LoggingSupporter
,LocaleSupporter
,OptionHandlingLocaleSupporter
,OptionHandler
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,NoHeaderSpreadSheetWriter
,SpreadSheetWriter
,Serializable
public class FixedTabularSpreadSheetWriter extends AbstractFormattedSpreadSheetWriter implements NoHeaderSpreadSheetWriter
Outputs the spreadsheet in a simple tabular format with fixed column width, as used by dot matrix printers in days gone by.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-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
-column-width <adams.core.base.BaseInteger> [-column-width ...] (property: columnWidth) The width in characters to use for the columns; if only one is specified then this is used for all columns. default: 10
-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: http://docs.oracle.com/javase/6/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: http://docs.oracle.com/javase/6/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: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
-time-format <adams.data.DateFormatString> (property: timeFormat) The format for times. default: HH:mm:ss more: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
-only-float <boolean> (property: onlyFloat) If enabled, all numbers are treated as float rather than distinguishing between long and double. default: false
-no-header <boolean> (property: noHeader) If enabled, no header is output. default: false
-no-border <boolean> (property: noBorder) If enabled, no border is output. default: false
- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class adams.data.io.output.AbstractSpreadSheetWriter
AbstractSpreadSheetWriter.OutputType
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
m_ActualColumnWidth
the actual column widths.protected BaseInteger[]
m_ColumnWidth
the column width.protected DateFormatString
m_DateFormat
the format string for the dates.protected DateFormatString
m_DateTimeFormat
the format string for the date/times.protected DateFormatString
m_DateTimeMsecFormat
the format string for the date/times msec.protected String
m_NewLine
the new line.protected boolean
m_NoBorder
whether to skip outputting the border.protected boolean
m_NoHeader
whether to skip outputting the header.protected boolean
m_OnlyFloat
whether to treat all numbers as float.protected DateFormatString
m_TimeFormat
the format string for the times.-
Fields inherited from class adams.data.io.output.AbstractFormattedSpreadSheetWriter
m_Formatter, m_Locale, m_NumberFormat
-
Fields inherited from class adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
m_MissingValue
-
Fields inherited from class adams.data.io.output.AbstractSpreadSheetWriter
m_Encoding, m_Stopped
-
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 FixedTabularSpreadSheetWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addSeparatorLine(SpreadSheet content, Writer writer)
Adds a separator line to the output.String
columnWidthTipText()
Returns the tip text for this property.String
dateFormatTipText()
Returns the tip date for this property.String
dateTimeFormatTipText()
Returns the tip date/time for this property.String
dateTimeMsecFormatTipText()
Returns the tip date/time for this property.void
defineOptions()
Adds options to the internal list of options.protected boolean
doWrite(SpreadSheet content, Writer writer)
Performs the actual writing.BaseInteger[]
getColumnWidth()
Returns the column width.SpreadSheetReader
getCorrespondingReader()
Returns, if available, the corresponding reader.DateFormatString
getDateFormat()
Returns the format for date columns.DateFormatString
getDateTimeFormat()
Returns the format for date/time columns.DateFormatString
getDateTimeMsecFormat()
Returns the format for date/time msec columns.String
getFormatDescription()
Returns a string describing the format (used in the file chooser).String[]
getFormatExtensions()
Returns the extension(s) of the format.String
getNewLine()
Returns the string used as newline.boolean
getNoBorder()
Returns whether to use a border or not.boolean
getNoHeader()
Returns whether to use a header or not.boolean
getOnlyFloat()
Returns whether to treat all numbers as float rather than distinguishing between long and double.protected AbstractSpreadSheetWriter.OutputType
getOutputType()
Returns how the data is written.DateFormatString
getTimeFormat()
Returns the format for time columns.String
globalInfo()
Returns a string describing the object.String
newLineTipText()
Returns the tip text for this property.String
noBorderTipText()
Returns the tip text for this property.String
noHeaderTipText()
Returns the tip text for this property.String
onlyFloatTipText()
Returns the tip text for this property.protected String
pad(int col, String s, boolean leftPad)
Pads a string either on the left or the right hand side with blanks.void
setColumnWidth(BaseInteger[] value)
Sets the column width.void
setDateFormat(DateFormatString value)
Sets the format for date columns.void
setDateTimeFormat(DateFormatString value)
Sets the format for date/time columns.void
setDateTimeMsecFormat(DateFormatString value)
Sets the format for date/time msec columns.void
setNewLine(String value)
Sets the string to use as newline.void
setNoBorder(boolean value)
Sets whether to use a border or not.void
setNoHeader(boolean value)
Sets whether to use a header or not.void
setOnlyFloat(boolean value)
Sets whether to treat all numbers as float rather than distinguishing between long and double.void
setTimeFormat(DateFormatString value)
Sets the format for time columns.String
timeFormatTipText()
Returns the tip time for this property.-
Methods inherited from class adams.data.io.output.AbstractFormattedSpreadSheetWriter
format, getDefaultNumberFormat, getDefaultUseSimpleNumberFormat, getLocale, getNumberFormat, localeTipText, numberFormatTipText, setLocale, setNumberFormat
-
Methods inherited from class adams.data.io.output.AbstractSpreadSheetWriterWithMissingValueSupport
getDefaultMissingValue, getMissingValue, missingValueTipText, setMissingValue
-
Methods inherited from class adams.data.io.output.AbstractSpreadSheetWriter
canCompress, doWrite, doWrite, encodingTipText, getAdditionalInformation, getDefaultFormatExtension, getEncoding, getWriters, initialize, isStopped, preWriteFile, reset, setEncoding, stopExecution, supportsCompressedOutput, write, write, write, write
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, 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.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
Methods inherited from interface adams.data.io.output.SpreadSheetWriter
reset, write, write, write, write
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_ColumnWidth
protected BaseInteger[] m_ColumnWidth
the column width.
-
m_ActualColumnWidth
protected int[] m_ActualColumnWidth
the actual column widths.
-
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_OnlyFloat
protected boolean m_OnlyFloat
whether to treat all numbers as float.
-
m_NoHeader
protected boolean m_NoHeader
whether to skip outputting the header.
-
m_NoBorder
protected boolean m_NoBorder
whether to skip outputting the border.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceSpreadSheetWriter
- Specified by:
getFormatDescription
in classAbstractSpreadSheetWriter
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensions
in interfaceSpreadSheetWriter
- Specified by:
getFormatExtensions
in classAbstractSpreadSheetWriter
- Returns:
- the extension (without the dot!)
-
getCorrespondingReader
public SpreadSheetReader getCorrespondingReader()
Returns, if available, the corresponding reader.- Specified by:
getCorrespondingReader
in interfaceSpreadSheetWriter
- Returns:
- the reader, null if none available
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractFormattedSpreadSheetWriter
-
setColumnWidth
public void setColumnWidth(BaseInteger[] value)
Sets the column width.- Parameters:
value
- the width in characters
-
getColumnWidth
public BaseInteger[] getColumnWidth()
Returns the column width.- Returns:
- the width in characters
-
columnWidthTipText
public String columnWidthTipText()
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
-
setOnlyFloat
public void setOnlyFloat(boolean value)
Sets whether to treat all numbers as float rather than distinguishing between long and double.- Parameters:
value
- true if to treat all numbers as float
-
getOnlyFloat
public boolean getOnlyFloat()
Returns whether to treat all numbers as float rather than distinguishing between long and double.- Returns:
- true if all numbers are treated as float
-
onlyFloatTipText
public String onlyFloatTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setNoHeader
public void setNoHeader(boolean value)
Sets whether to use a header or not.- Specified by:
setNoHeader
in interfaceNoHeaderSpreadSheetWriter
- Parameters:
value
- true if to skip header
-
getNoHeader
public boolean getNoHeader()
Returns whether to use a header or not.- Specified by:
getNoHeader
in interfaceNoHeaderSpreadSheetWriter
- Returns:
- true if no header
-
noHeaderTipText
public String noHeaderTipText()
Returns the tip text for this property.- Specified by:
noHeaderTipText
in interfaceNoHeaderSpreadSheetWriter
- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setNoBorder
public void setNoBorder(boolean value)
Sets whether to use a border or not.- Parameters:
value
- true if to skip border
-
getNoBorder
public boolean getNoBorder()
Returns whether to use a border or not.- Returns:
- true if no border
-
noBorderTipText
public String noBorderTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getOutputType
protected AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Specified by:
getOutputType
in classAbstractSpreadSheetWriter
- Returns:
- the type
-
addSeparatorLine
protected void addSeparatorLine(SpreadSheet content, Writer writer) throws Exception
Adds a separator line to the output.- Parameters:
writer
- the writer to add the line to- Throws:
Exception
- if writing to writer fails
-
pad
protected String pad(int col, String s, boolean leftPad)
Pads a string either on the left or the right hand side with blanks. Shortens it if necessary.- Parameters:
col
- the column to pads
- the string to padleftPad
- 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 classAbstractSpreadSheetWriter
- Parameters:
content
- the spreadsheet to writewriter
- the writer to write the spreadsheet to- Returns:
- true if successfully written
-
-