Package hec.gfx2d
Class PlotSpecification
java.lang.Object
hec.gfx2d.PlotSpecification
- Direct Known Subclasses:
PlotSpec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Simple container class for combining color string and transparency -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final G2dMarkerProperties
protected static final AxisProp
protected static final AxisTicsDrawProp
protected static final G2dLabelDrawProp
protected static final LegendPanelProp
protected static final G2dLineProperties
protected static final G2dPanelProp
protected static final ViewportDrawProp
protected int
protected static final Color[]
protected static final Logger
protected static final Pattern
protected static final Pattern
protected static final Pattern
protected static final Pattern
protected static final Pattern
protected static final TimeZone
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HecTime
addDuration
(HecTime baseTime, String durationStr) Adds a specified duration to a base time and returns the resulting timeprotected static boolean
Returns whether all specified keys map to true in the specified mappingprotected List<org.jdom.Element>
buildAxisElems
(Viewport viewport, boolean includeX1Axis) Constructs JDom axis elements for a viewportprotected List<org.jdom.Element>
buildAxisMarkerElems
(Viewport viewport) Constructs JDom axis marker elements for a viewportprotected org.jdom.Element
buildColorElem
(Color color, String name) Constructs a JDom color element from a Color and an element nameprotected List<org.jdom.Element>
buildCurveElems
(Viewport viewport, Scale scale) Constructs JDom curve elements for viewport and a scaleprotected void
buildCurveLayouts
(ViewportLayout viewportLayout, String axisName, List<?> curveElems, Map<String, org.jdom.Element> elementMap) Adds appropriate curves to a specified viewport layout and axisprotected org.jdom.Element
buildLabelElem
(G2dLabel label, String name) Constructs a JDom label element from G2dLabel and a nameprotected org.jdom.Element
buildLabelElem
(G2dLabel label, String name, List<?> options) Constructs a JDom label element from G2dLabel and a nameprotected org.jdom.Element
buildLegendElem
(G2dDialog plot) Constructs a JDom legend element for a plotConstructs a plot from plot file containing plot specification XML or text.Constructs a plot from plot specification XML or text.protected G2dDialog
buildPlot
(org.jdom.Document plotDoc) Constructs a plot from a JDom documentprotected org.jdom.Document
buildPlotDoc
(G2dDialog plot) Constructs a JDom document from a plotprotected org.jdom.Element
buildScaleElem
(Axis axis, String name, Viewport viewport) Constructs a JDom scale element from a Viewport, Axis, and nameprotected org.jdom.Element
buildTicsElem
(AxisTics axisTics) Constructs a JDom axis tics element from an AxisTics objectprotected List<org.jdom.Element>
buildViewportElems
(G2dDialog plot) Constructs JDom viewport elements for a plotbuildViewportLayouts
(PlotLayout plotLayout, List<org.jdom.Element> viewportElems) Adds viewports to the plot layoutvoid
Removes all curve data mappingprotected static void
customizeLegend
(G2dDialog plot, org.jdom.Element legendElem) Modifies a plot's legend based on a JDom legend elementprotected static void
customizeTitle
(G2dDialog plot, org.jdom.Element titleElem) Modifies a plot's title based on a JDom title elementprotected static void
customizeViewports
(G2dDialog plot, List<org.jdom.Element> viewportElems, Map<String, org.jdom.Element> curveElementMap) Modifies the plot viewports according to the JDom viewport elementsprotected static int
dataSourceSeparatorPos
(String dataSourceName) Returns the position in the data source name of the ':' character that separates the data source location from the data identifier.boolean
Retrieves whether data are currently included in outputboolean
Retrieves whether data references are currently included in outputboolean
Retrieves whether defaults are currently included in outputboolean
Retrieves whether plot specifications are generated using the compact formprotected static String[]
getAttributeNames
(org.jdom.Element element) Returns a sorted array of attribute names for a JDom elementprotected static PlotSpecification.ColorInfo
getColorInfo
(Color color) Retrieves a ColorInfo container for the specified colorprotected static String
getColorString
(org.jdom.Element colorElem) Constructs a color string from a JDom color elementprotected static String
getColorString
(org.jdom.Element colorElem, String defaultValue) Constructs a color string from a JDom color elementReturns a copy of the current curve data mappinggetCurveData
(String curveId) Returns a copy of the current data mapping for a specified curvegetElementLines
(org.jdom.Element element, String indent, int level) Constructs a list of plot specification lines for a specified JDom elementprotected static String
getFontString
(org.jdom.Element fontElem) Constructs a font string from a JDom font elementprotected static String
getFontString
(org.jdom.Element fontElem, List<?> options) Constructs a font string from a JDom font elementstatic String
getHecDuration
(int minutes) static String
getHecDuration
(String xmlDuration) Constructs an HEC-style duration (ex: 1HOUR) from an XML duration stringRetrieves the indentation string for non-compact outputstatic int
getMinutes
(String durationStr) Retrieves the number of minutes represented by a duration stringgetPlotSpecText
(G2dDialog plot) Retrieves the plot specification text for the specified plotprotected String
getPlotSpecText
(org.jdom.Document plotDoc) getPlotSpecXml
(G2dDialog plot) Retrieves the plot specification XML for the specified plotprotected String
getPlotSpecXml
(org.jdom.Document plotDoc) Retrieves an XML string for the JDom plot documentprotected static String
Retrieves the time zone of the time axis of the plot being constructed.protected static TimeZone
getTimeZone
(String timeZone) static String
Normalizes numeric textstatic String
getXmlDuration
(int start, int end) Constructs an XML duration string from 2 HecTime minutes valuesstatic String
getXmlDuration
(String hecDuration) Constructs an XML duration string from an HEC-style duration (ex: 1HOUR)protected static String
getXmlDurationFromHecDuration
(String hecDuration) Constructs an XML duration string from an HEC-style duration (ex: 1HOUR)protected static String
getXmlDurationFromMinutes
(int start, int end) Constructs an XML duration string from 2 HecTime minutes valuesprotected void
init()
protected static boolean
isCwmsDbDataSource
(String dataSourceName) Returns whether the data source name specifies a CWMS database for the data source location.protected static List<?>
Helper routine for constructing lists of objects.protected static int
Description of the Methodprotected static org.jdom.Document
parsePlotSpecText
(String text) Constructs a JDom document from a plot specification textprotected static long
parseTimeIntervalString
(String timeInterval) Interprets time interval strings such as "6HOURS", "1MONTH" as milliseconds.protected static String
prepareLines
(String lines) Strips comments, nulls non-quoted spaces, preserves quotesprotected static String
prepareWord
(String word) Strips quote characters and replaces nulls with spacesprotected void
prune
(org.jdom.Element element) Removes any elements under the current element that have no content or attributesprotected static String
protected static boolean
sameArray
(float[] a1, float[] a2) Retrieves whether two arrays contain the same values in the same orderprotected static boolean
Retrieves whether two colors are the same (2 null colors = same)protected static boolean
sameProperties
(G2dLabelDrawProp prop1, G2dLabelDrawProp prop2) Returns whether 2 properties are equivalentvoid
setData
(String curveId, DataContainer dc) Sets the current data mapping for a specified curve identifiervoid
Sets the current data mapping for a specified curve identifiervoid
setIncludeData
(boolean includeData) Sets whether to include data in outputvoid
setIncludeDataReference
(boolean includeDataReference) Sets whether to include data references in outputvoid
setIncludeDefaults
(boolean includeDefaults) Sets whether to include default values in outputvoid
Sets the indentation string for non-compact outputvoid
setTimeZone
(TimeZone timeZone) Sets the time zone of the time axis of the plot being constructed.protected static void
setTscFromDataSource
(TimeSeriesContainer tsc, String dataSourceName) Sets TimeSeriesContainer data from a data source namevoid
setUseCompactForm
(boolean useCompactForm) Sets whether plot specifications are generated using the compact formspecTextToXml
(String specText) Retrieves the XML equivalent of the supplied plot specification textspecXmlToText
(String specXml) Retrieves the plot specification text equivalent of the XMLprotected static void
updateLegend
(G2dDialog plot) Updates the plot legendprotected static void
updateLegend
(G2dDialog plot, LegendPanelProp legendProps) Updates the plot legend from the specified propertiesstatic String
validateCurveId
(String curveId) Validates a curve identifier to be of the form a,b,yc,d where a,b is the viewport, c is the Y axis (1 or 2) and d is the sequence of curve for that axis.protected static org.jdom.Element
wordsToElement
(Deque<String> words, org.jdom.Parent parent, String startingPath) Constructs a JDom element from a list of plot specification words
-
Field Details
-
reXmlDuration
-
reHecDuration
-
reXmlTime
-
reXmlTimeZone
-
reValidCurve
-
logger
-
tzUtc
-
validUtcIds
-
xmlTypeAttributes
-
xmlElementTypes
-
colorNames
-
lineStyleNames
-
lineStylePatterns
-
lineStepStyleNames
-
lineStepStyleNumbers
-
fillPatternNames
-
fillPatternNumbers
-
alignmentNames
-
alignmentNumbers
-
fillPositionNames
-
fillPositionNumbers
-
labelPositionNames
-
labelPositionNumbers
-
fontStyleNames
-
fontStyleNumbers
-
legendLocationNames
-
legendLocationNumbers
-
axisTypeNames
-
axisTypeNumbers
-
symbolTypeNames
-
symbolTypeNumbers
-
lineColors
-
defaultLabelProp
-
defaultPanelProp
-
defaultLegendProp
-
defaultViewportProp
-
defaultAxisProp
-
defaultAxisTicsProp
-
defaultAxisMarkerProp
-
defaultLineProp
-
lineColorIndex
protected int lineColorIndex
-
-
Constructor Details
-
PlotSpecification
public PlotSpecification()Public constructor
-
-
Method Details
-
sameProperties
protected static boolean sameProperties(G2dLabelDrawProp prop1, G2dLabelDrawProp prop2) throws IOException Returns whether 2 properties are equivalent- Parameters:
prop1
- The first set of propertiesprop2
- The second set of properties- Returns:
- true if the properties are equivalent, otherwise false
- Throws:
IOException
-
getXmlDuration
Constructs an XML duration string from 2 HecTime minutes values- Parameters:
start
- the start of the durationend
- the end of the duration- Returns:
- An XML duration string representing the time span and direction
-
getXmlDuration
Constructs an XML duration string from an HEC-style duration (ex: 1HOUR)- Parameters:
hecDuration
- The HEC-style duration string- Returns:
- The corresponding XML-style duration string
-
getHecDuration
Constructs an HEC-style duration (ex: 1HOUR) from an XML duration string- Parameters:
xmlDuration
- The XML duration string- Returns:
-
getHecDuration
-
getMinutes
Retrieves the number of minutes represented by a duration string- Parameters:
durationStr
- The duration string. This must be a valid HEC-style duration string or an XML duration string convertible to an HEC-style string.- Returns:
- The number of minutes represented by the duration string. If the unit is "MIN", "HOUR", or "DAY", the actual number of minutes is returned, otherwise a minutes signature is returned.
-
addDuration
Adds a specified duration to a base time and returns the resulting time- Parameters:
baseTime
- The base timedurationStr
- The duration to add as as HEC-style or XML duration. The XML duration does not need to be convertible to an HEC-style duration.- Returns:
- The base time plus the duration
-
getValue
Normalizes numeric text- Parameters:
valueStr
- The numeric text to normalize- Returns:
- The normalized text
-
validateCurveId
Validates a curve identifier to be of the form a,b,yc,d where a,b is the viewport, c is the Y axis (1 or 2) and d is the sequence of curve for that axis.- Parameters:
curveId
- the curve identifier to validate- Returns:
- the curve identifier if valid
-
getCurveData
Returns a copy of the current curve data mapping- Returns:
- the curve data mapping.
-
getCurveData
Returns a copy of the current data mapping for a specified curve- Returns:
- the curve data mapping.
-
setData
Sets the current data mapping for a specified curve identifier- Parameters:
curveId
- The curve identifiercurveDataStr
- The data to be mapped to the curve identifier
-
setData
Sets the current data mapping for a specified curve identifier- Parameters:
curveId
- The curve identifierdc
- The data to be mapped to the curve identifier- Throws:
Exception
- if dc cannot be processed (currently only handles TimeSeriesContainers)
-
clearCurveData
public void clearCurveData()Removes all curve data mapping -
doesIncludeDefaults
public boolean doesIncludeDefaults()Retrieves whether defaults are currently included in output- Returns:
- whether defaults are currently included in output
-
setIncludeDefaults
public void setIncludeDefaults(boolean includeDefaults) Sets whether to include default values in output- Parameters:
includeDefaults
- flag specifying whether to include default values in output
-
doesIncludeData
public boolean doesIncludeData()Retrieves whether data are currently included in output- Returns:
- whether data are currently included in output
-
setIncludeData
public void setIncludeData(boolean includeData) Sets whether to include data in output- Parameters:
includeData
- flag specifying whether to include data in output
-
doesIncludeDataReference
public boolean doesIncludeDataReference()Retrieves whether data references are currently included in output- Returns:
- whether data references are currently included in output
-
setIncludeDataReference
public void setIncludeDataReference(boolean includeDataReference) Sets whether to include data references in output- Parameters:
includeDataReference
- flag specifying whether to include data references in output
-
doesUseCompactForm
public boolean doesUseCompactForm()Retrieves whether plot specifications are generated using the compact form- Returns:
- Whether plot specifications are generated using the compact form
-
setUseCompactForm
public void setUseCompactForm(boolean useCompactForm) Sets whether plot specifications are generated using the compact form- Parameters:
useCompactForm
- specifying whether plot specifications are generated using the compact form
-
getIndent
Retrieves the indentation string for non-compact output- Returns:
- the indentation string for non-compact output
-
setIndent
Sets the indentation string for non-compact output- Parameters:
indent
- the indentation string for non-compact output
-
getTimeZone
Retrieves the time zone of the time axis of the plot being constructed.- Returns:
- the timeZone
-
setTimeZone
Sets the time zone of the time axis of the plot being constructed.- Parameters:
timeZone
- the timeZone to set
-
specTextToXml
Retrieves the XML equivalent of the supplied plot specification text- Parameters:
specText
- The plot specification text- Returns:
- The XML equivalent of the specification text
-
specXmlToText
Retrieves the plot specification text equivalent of the XML- Parameters:
specXml
- The plot specification XML- Returns:
- The plot specification text
- Throws:
org.jdom.JDOMException
IOException
-
getPlotSpecXml
Retrieves the plot specification XML for the specified plot- Parameters:
plot
- The plot to retrieve the specification XML for- Returns:
- The plot specification XML
- Throws:
IOException
-
getPlotSpecText
Retrieves the plot specification text for the specified plot- Parameters:
plot
- The plot to retrieve the specification text for- Returns:
- The plot specification text
- Throws:
IOException
-
init
protected void init() -
getPlotSpecText
-
getPlotSpecXml
Retrieves an XML string for the JDom plot document- Parameters:
plotDoc
- The JDom plot document- Returns:
- The XML string for the document
-
buildColorElem
Constructs a JDom color element from a Color and an element name- Parameters:
color
- The color to use (may be null)name
- The name of the element- Returns:
-
buildLabelElem
Constructs a JDom label element from G2dLabel and a name- Parameters:
label
- The G2dLabel to use (may be null for a default label)name
- The JDom element nameoptions
- Options to override default properties- Returns:
- The JDOM element
-
buildLabelElem
Constructs a JDom label element from G2dLabel and a name- Parameters:
label
- The G2dLabel to use (may be null for a default label)name
- The JDom element name- Returns:
- The JDOM element
-
buildScaleElem
Constructs a JDom scale element from a Viewport, Axis, and name- Parameters:
axis
- The axis of the scalename
- The name of the scale elementviewport
- The viewport- Returns:
-
buildTicsElem
Constructs a JDom axis tics element from an AxisTics object- Parameters:
axisTics
- The AxisTics object- Returns:
- The JDom element
-
buildCurveElems
Constructs JDom curve elements for viewport and a scale- Parameters:
viewport
- The viewport to generate curve elements forscale
- The scale to generate curve elements for- Returns:
- A list of curve elements
-
buildAxisElems
Constructs JDom axis elements for a viewport- Parameters:
viewport
- The viewport to construct the axis elements forincludeX1Axis
- Flag specifying whether to include the X1 axis- Returns:
- A List containing the axis elements
-
buildAxisMarkerElems
Constructs JDom axis marker elements for a viewport- Parameters:
viewport
- The viewport to construct the axis marker elements for- Returns:
- The axis marker elements for the viewport
-
buildViewportElems
Constructs JDom viewport elements for a plot- Parameters:
plot
- The plot to generate the viewport elements for- Returns:
- The viewport elements
-
buildLegendElem
Constructs a JDom legend element for a plot- Parameters:
plot
- The plot to generate the legend element for- Returns:
- The legend element
-
buildPlotDoc
Constructs a JDom document from a plot- Parameters:
plot
- The plot to generate the document from- Returns:
- The JDom document
- Throws:
IOException
-
buildPlot
Constructs a plot from plot file containing plot specification XML or text. The XML or text must include curve data- Parameters:
plotFile
- The plot file- Returns:
- The plot
- Throws:
Exception
-
buildPlot
Constructs a plot from plot specification XML or text. The XML or text must include curve data- Parameters:
plotText
- The plot specification XML or text- Returns:
- The plot
- Throws:
Exception
-
buildPlot
Constructs a plot from a JDom document- Parameters:
plotDoc
- The JDom document- Returns:
- The plot
- Throws:
Exception
-
customizeTitle
Modifies a plot's title based on a JDom title element- Parameters:
plot
-titleElem
-
-
customizeLegend
Modifies a plot's legend based on a JDom legend element- Parameters:
plot
-legendElem
-
-
customizeViewports
protected static void customizeViewports(G2dDialog plot, List<org.jdom.Element> viewportElems, Map<String, org.jdom.Element> curveElementMap) Modifies the plot viewports according to the JDom viewport elements- Parameters:
plot
- The plot to modifyviewportElems
- The JDom viewport elements to usecurveElementMap
- A mapping of data source names to JDom curve elements
-
updateLegend
Updates the plot legend- Parameters:
plot
- The plot to updated the legend for
-
updateLegend
Updates the plot legend from the specified properties- Parameters:
plot
- The plot to updated the legend forlegendProps
- The legend properties to use
-
getFontString
Constructs a font string from a JDom font element- Parameters:
fontElem
- The font element- Returns:
- The font string
-
getFontString
Constructs a font string from a JDom font element- Parameters:
fontElem
- The font elementoptions
- A list of defaults, keys can be "size", "style"- Returns:
- The font string
-
getColorString
Constructs a color string from a JDom color element- Parameters:
colorElem
- The JDom color element- Returns:
- The color string
-
getColorString
Constructs a color string from a JDom color element- Parameters:
colorElem
- The JDom color elementdefaultValue
- The default color string if the element is null- Returns:
- The color string
-
buildViewportLayouts
protected Map<String,org.jdom.Element> buildViewportLayouts(PlotLayout plotLayout, List<org.jdom.Element> viewportElems) throws Exception Adds viewports to the plot layout- Parameters:
plotLayout
- The plot layout object to modifyviewportElems
- The JDom viewport elements to add- Returns:
- A mappings of data container names to curve elements
- Throws:
Exception
-
buildCurveLayouts
protected void buildCurveLayouts(ViewportLayout viewportLayout, String axisName, List<?> curveElems, Map<String, org.jdom.Element> elementMap) throws ExceptionAdds appropriate curves to a specified viewport layout and axis- Parameters:
viewportLayout
- The viewport layout to add the curves toaxisName
- The axis on the viewport to add curves tocurveElems
- The list of JDom curve elements to select curves fromelementMap
- A mapping of data container names to curve elements that the method populates- Throws:
Exception
-
dataSourceSeparatorPos
Returns the position in the data source name of the ':' character that separates the data source location from the data identifier.- Parameters:
dataSourceName
- the data source name- Returns:
- the position of the separating ':' character or -1 if not found
-
isCwmsDbDataSource
Returns whether the data source name specifies a CWMS database for the data source location.- Parameters:
dataSourceName
- the data source name- Returns:
- whether the data source name specifies a CWMS database location
-
parseInt
Description of the Method- Parameters:
intString
- Description of ParameterintDefault
- Description of Parameter- Returns:
- Description of the Returned Value
-
parseTimeIntervalString
Interprets time interval strings such as "6HOURS", "1MONTH" as milliseconds. (1 month = 30 days, 1 year = 365 days)- Parameters:
timeInterval
- The time interval string to interpret.- Returns:
- The interpreted time interval in milliseconds.
-
setTscFromDataSource
protected static void setTscFromDataSource(TimeSeriesContainer tsc, String dataSourceName) throws DataSetIllegalArgumentException Sets TimeSeriesContainer data from a data source name- Parameters:
tsc
- The TimeSeriesContainer to setdataSourceName
- The data source name- Throws:
DataSetIllegalArgumentException
-
quote
-
getPlotText
- Throws:
Exception
-
all
Returns whether all specified keys map to true in the specified mapping- Parameters:
map
- The mapping to checkkeys
- The array of keys to check- Returns:
-
sameArray
protected static boolean sameArray(float[] a1, float[] a2) Retrieves whether two arrays contain the same values in the same order- Parameters:
a1
- The first arraya2
- The second array- Returns:
- Whether the two arrays contain the same values in the same order
-
sameColor
Retrieves whether two colors are the same (2 null colors = same)- Parameters:
c1
- The first colorc2
- The second color- Returns:
- Whether the two colors are the same
-
makeList
Helper routine for constructing lists of objects.- Parameters:
objs
- The objects to make into a list- Returns:
- The resulting list of objects
-
getColorInfo
Retrieves a ColorInfo container for the specified color- Parameters:
color
- The specified color- Returns:
- The ColorInfo container
-
getXmlDurationFromMinutes
Constructs an XML duration string from 2 HecTime minutes values- Parameters:
start
- the start of the durationend
- the end of the duration- Returns:
- An XML duration string representing the time span and direction
-
getXmlDurationFromHecDuration
Constructs an XML duration string from an HEC-style duration (ex: 1HOUR)- Parameters:
hecDuration
- The HEC-style duration string- Returns:
- The corresponding XML-style duration string
-
getAttributeNames
Returns a sorted array of attribute names for a JDom element- Parameters:
element
- The JDom element- Returns:
- The sorted array of attribute names
-
getElementLines
Constructs a list of plot specification lines for a specified JDom element- Parameters:
element
- The element to generate the plot specification lines forindent
- The indentation string for each levellevel
- The indentation level for the current element- Returns:
- A list of plot specification lines for the element
-
prepareLines
Strips comments, nulls non-quoted spaces, preserves quotes- Parameters:
lines
- The lines to prepare- Returns:
- The prepared lines
-
prepareWord
Strips quote characters and replaces nulls with spaces- Parameters:
word
- The word to prepare- Returns:
- The prepared word
-
wordsToElement
protected static org.jdom.Element wordsToElement(Deque<String> words, org.jdom.Parent parent, String startingPath) Constructs a JDom element from a list of plot specification words- Parameters:
words
- The list of plot specification wordsparent
- The parent (element or document) to attach the new element to, if appropriatestartingPath
- The initial element hierarchy- Returns:
- The new element, or null if the element was attached to the parent
-
getTimeZone
-
parsePlotSpecText
Constructs a JDom document from a plot specification text- Parameters:
text
- The plot specification text- Returns:
- The JDom document
-
prune
protected void prune(org.jdom.Element element) Removes any elements under the current element that have no content or attributes- Parameters:
element
- The element to prune
-