Package hec.gfx2d

Class PlotSpecification

java.lang.Object
hec.gfx2d.PlotSpecification
Direct Known Subclasses:
PlotSpec

public class PlotSpecification extends Object
  • Field Details

    • reXmlDuration

      protected static final Pattern reXmlDuration
    • reHecDuration

      protected static final Pattern reHecDuration
    • reXmlTime

      protected static final Pattern reXmlTime
    • reXmlTimeZone

      protected static final Pattern reXmlTimeZone
    • reValidCurve

      protected static final Pattern reValidCurve
    • logger

      protected static final Logger logger
    • tzUtc

      protected static final TimeZone tzUtc
    • validUtcIds

      protected static final List<String> validUtcIds
    • xmlTypeAttributes

      protected static final Map<String,String[]> xmlTypeAttributes
    • xmlElementTypes

      protected static final Map<String,String> xmlElementTypes
    • colorNames

      protected static final Map<String,String> colorNames
    • lineStyleNames

      protected static final Map<float[],String> lineStyleNames
    • lineStylePatterns

      protected static final Map<String,float[]> lineStylePatterns
    • lineStepStyleNames

      protected static final Map<Integer,String> lineStepStyleNames
    • lineStepStyleNumbers

      protected static final Map<String,Integer> lineStepStyleNumbers
    • fillPatternNames

      protected static final Map<Integer,String> fillPatternNames
    • fillPatternNumbers

      protected static final Map<String,Integer> fillPatternNumbers
    • alignmentNames

      protected static final Map<Integer,String> alignmentNames
    • alignmentNumbers

      protected static final Map<String,Integer> alignmentNumbers
    • fillPositionNames

      protected static final Map<Integer,String> fillPositionNames
    • fillPositionNumbers

      protected static final Map<String,Integer> fillPositionNumbers
    • labelPositionNames

      protected static final Map<Integer,String> labelPositionNames
    • labelPositionNumbers

      protected static final Map<String,Integer> labelPositionNumbers
    • fontStyleNames

      protected static final Map<Integer,String> fontStyleNames
    • fontStyleNumbers

      protected static final Map<String,Integer> fontStyleNumbers
    • legendLocationNames

      protected static final Map<Integer,String> legendLocationNames
    • legendLocationNumbers

      protected static final Map<String,Integer> legendLocationNumbers
    • axisTypeNames

      protected static final Map<Integer,String> axisTypeNames
    • axisTypeNumbers

      protected static final Map<String,Integer> axisTypeNumbers
    • symbolTypeNames

      protected static final Map<Integer,String> symbolTypeNames
    • symbolTypeNumbers

      protected static final Map<String,Integer> symbolTypeNumbers
    • lineColors

      protected static final Color[] lineColors
    • defaultLabelProp

      protected static final G2dLabelDrawProp defaultLabelProp
    • defaultPanelProp

      protected static final G2dPanelProp defaultPanelProp
    • defaultLegendProp

      protected static final LegendPanelProp defaultLegendProp
    • defaultViewportProp

      protected static final ViewportDrawProp defaultViewportProp
    • defaultAxisProp

      protected static final AxisProp defaultAxisProp
    • defaultAxisTicsProp

      protected static final AxisTicsDrawProp defaultAxisTicsProp
    • defaultAxisMarkerProp

      protected static final G2dMarkerProperties defaultAxisMarkerProp
    • defaultLineProp

      protected static final G2dLineProperties 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 properties
      prop2 - The second set of properties
      Returns:
      true if the properties are equivalent, otherwise false
      Throws:
      IOException
    • getXmlDuration

      public static String getXmlDuration(int start, int end)
      Constructs an XML duration string from 2 HecTime minutes values
      Parameters:
      start - the start of the duration
      end - the end of the duration
      Returns:
      An XML duration string representing the time span and direction
    • getXmlDuration

      public static String getXmlDuration(String hecDuration)
      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

      public static String getHecDuration(String xmlDuration)
      Constructs an HEC-style duration (ex: 1HOUR) from an XML duration string
      Parameters:
      xmlDuration - The XML duration string
      Returns:
    • getHecDuration

      public static String getHecDuration(int minutes)
    • getMinutes

      public static int getMinutes(String durationStr)
      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

      public static HecTime addDuration(HecTime baseTime, String durationStr)
      Adds a specified duration to a base time and returns the resulting time
      Parameters:
      baseTime - The base time
      durationStr - 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

      public static String getValue(String valueStr)
      Normalizes numeric text
      Parameters:
      valueStr - The numeric text to normalize
      Returns:
      The normalized text
    • validateCurveId

      public static 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.
      Parameters:
      curveId - the curve identifier to validate
      Returns:
      the curve identifier if valid
    • getCurveData

      public Map<String,String> getCurveData()
      Returns a copy of the current curve data mapping
      Returns:
      the curve data mapping.
    • getCurveData

      public String getCurveData(String curveId)
      Returns a copy of the current data mapping for a specified curve
      Returns:
      the curve data mapping.
    • setData

      public void setData(String curveId, String curveDataStr)
      Sets the current data mapping for a specified curve identifier
      Parameters:
      curveId - The curve identifier
      curveDataStr - The data to be mapped to the curve identifier
    • setData

      public void setData(String curveId, DataContainer dc) throws Exception
      Sets the current data mapping for a specified curve identifier
      Parameters:
      curveId - The curve identifier
      dc - 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

      public String getIndent()
      Retrieves the indentation string for non-compact output
      Returns:
      the indentation string for non-compact output
    • setIndent

      public void setIndent(String indent)
      Sets the indentation string for non-compact output
      Parameters:
      indent - the indentation string for non-compact output
    • getTimeZone

      public TimeZone getTimeZone()
      Retrieves the time zone of the time axis of the plot being constructed.
      Returns:
      the timeZone
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
      Sets the time zone of the time axis of the plot being constructed.
      Parameters:
      timeZone - the timeZone to set
    • specTextToXml

      public String specTextToXml(String specText)
      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

      public String specXmlToText(String specXml) throws org.jdom.JDOMException, IOException
      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

      public String getPlotSpecXml(G2dDialog plot) throws IOException
      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

      public String getPlotSpecText(G2dDialog plot) throws IOException
      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

      protected String getPlotSpecText(org.jdom.Document plotDoc)
    • getPlotSpecXml

      protected String getPlotSpecXml(org.jdom.Document plotDoc)
      Retrieves an XML string for the JDom plot document
      Parameters:
      plotDoc - The JDom plot document
      Returns:
      The XML string for the document
    • buildColorElem

      protected org.jdom.Element buildColorElem(Color color, String name)
      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

      protected org.jdom.Element buildLabelElem(G2dLabel label, String name, List<?> options)
      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
      options - Options to override default properties
      Returns:
      The JDOM element
    • buildLabelElem

      protected org.jdom.Element buildLabelElem(G2dLabel label, String name)
      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

      protected org.jdom.Element buildScaleElem(Axis axis, String name, Viewport viewport)
      Constructs a JDom scale element from a Viewport, Axis, and name
      Parameters:
      axis - The axis of the scale
      name - The name of the scale element
      viewport - The viewport
      Returns:
    • buildTicsElem

      protected org.jdom.Element buildTicsElem(AxisTics axisTics)
      Constructs a JDom axis tics element from an AxisTics object
      Parameters:
      axisTics - The AxisTics object
      Returns:
      The JDom element
    • buildCurveElems

      protected List<org.jdom.Element> buildCurveElems(Viewport viewport, Scale scale)
      Constructs JDom curve elements for viewport and a scale
      Parameters:
      viewport - The viewport to generate curve elements for
      scale - The scale to generate curve elements for
      Returns:
      A list of curve elements
    • buildAxisElems

      protected List<org.jdom.Element> buildAxisElems(Viewport viewport, boolean includeX1Axis)
      Constructs JDom axis elements for a viewport
      Parameters:
      viewport - The viewport to construct the axis elements for
      includeX1Axis - Flag specifying whether to include the X1 axis
      Returns:
      A List containing the axis elements
    • buildAxisMarkerElems

      protected List<org.jdom.Element> buildAxisMarkerElems(Viewport viewport)
      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

      protected List<org.jdom.Element> buildViewportElems(G2dDialog plot)
      Constructs JDom viewport elements for a plot
      Parameters:
      plot - The plot to generate the viewport elements for
      Returns:
      The viewport elements
    • buildLegendElem

      protected org.jdom.Element buildLegendElem(G2dDialog plot)
      Constructs a JDom legend element for a plot
      Parameters:
      plot - The plot to generate the legend element for
      Returns:
      The legend element
    • buildPlotDoc

      protected org.jdom.Document buildPlotDoc(G2dDialog plot) throws IOException
      Constructs a JDom document from a plot
      Parameters:
      plot - The plot to generate the document from
      Returns:
      The JDom document
      Throws:
      IOException
    • buildPlot

      public G2dDialog buildPlot(File plotFile) throws Exception
      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

      public G2dDialog buildPlot(String plotText) throws Exception
      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

      protected G2dDialog buildPlot(org.jdom.Document plotDoc) throws Exception
      Constructs a plot from a JDom document
      Parameters:
      plotDoc - The JDom document
      Returns:
      The plot
      Throws:
      Exception
    • customizeTitle

      protected static void customizeTitle(G2dDialog plot, org.jdom.Element titleElem)
      Modifies a plot's title based on a JDom title element
      Parameters:
      plot -
      titleElem -
    • customizeLegend

      protected static void customizeLegend(G2dDialog plot, org.jdom.Element legendElem)
      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 modify
      viewportElems - The JDom viewport elements to use
      curveElementMap - A mapping of data source names to JDom curve elements
    • updateLegend

      protected static void updateLegend(G2dDialog plot)
      Updates the plot legend
      Parameters:
      plot - The plot to updated the legend for
    • updateLegend

      protected static void updateLegend(G2dDialog plot, LegendPanelProp legendProps)
      Updates the plot legend from the specified properties
      Parameters:
      plot - The plot to updated the legend for
      legendProps - The legend properties to use
    • getFontString

      protected static String getFontString(org.jdom.Element fontElem)
      Constructs a font string from a JDom font element
      Parameters:
      fontElem - The font element
      Returns:
      The font string
    • getFontString

      protected static String getFontString(org.jdom.Element fontElem, List<?> options)
      Constructs a font string from a JDom font element
      Parameters:
      fontElem - The font element
      options - A list of defaults, keys can be "size", "style"
      Returns:
      The font string
    • getColorString

      protected static String getColorString(org.jdom.Element colorElem)
      Constructs a color string from a JDom color element
      Parameters:
      colorElem - The JDom color element
      Returns:
      The color string
    • getColorString

      protected static String getColorString(org.jdom.Element colorElem, String defaultValue)
      Constructs a color string from a JDom color element
      Parameters:
      colorElem - The JDom color element
      defaultValue - 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 modify
      viewportElems - 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 Exception
      Adds appropriate curves to a specified viewport layout and axis
      Parameters:
      viewportLayout - The viewport layout to add the curves to
      axisName - The axis on the viewport to add curves to
      curveElems - The list of JDom curve elements to select curves from
      elementMap - A mapping of data container names to curve elements that the method populates
      Throws:
      Exception
    • dataSourceSeparatorPos

      protected 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.
      Parameters:
      dataSourceName - the data source name
      Returns:
      the position of the separating ':' character or -1 if not found
    • isCwmsDbDataSource

      protected static boolean isCwmsDbDataSource(String dataSourceName)
      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

      protected static int parseInt(String intString, int intDefault)
      Description of the Method
      Parameters:
      intString - Description of Parameter
      intDefault - Description of Parameter
      Returns:
      Description of the Returned Value
    • parseTimeIntervalString

      protected static long parseTimeIntervalString(String timeInterval)
      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 set
      dataSourceName - The data source name
      Throws:
      DataSetIllegalArgumentException
    • quote

      protected static String quote(String str)
    • getPlotText

      protected static String getPlotText(DataContainer dc) throws Exception
      Throws:
      Exception
    • all

      protected static boolean all(Map<String,Boolean> map, String... keys)
      Returns whether all specified keys map to true in the specified mapping
      Parameters:
      map - The mapping to check
      keys - 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 array
      a2 - The second array
      Returns:
      Whether the two arrays contain the same values in the same order
    • sameColor

      protected static boolean sameColor(Color c1, Color c2)
      Retrieves whether two colors are the same (2 null colors = same)
      Parameters:
      c1 - The first color
      c2 - The second color
      Returns:
      Whether the two colors are the same
    • makeList

      protected static List<?> makeList(Object... objs)
      Helper routine for constructing lists of objects.
      Parameters:
      objs - The objects to make into a list
      Returns:
      The resulting list of objects
    • getColorInfo

      protected static PlotSpecification.ColorInfo getColorInfo(Color color)
      Retrieves a ColorInfo container for the specified color
      Parameters:
      color - The specified color
      Returns:
      The ColorInfo container
    • getXmlDurationFromMinutes

      protected static String getXmlDurationFromMinutes(int start, int end)
      Constructs an XML duration string from 2 HecTime minutes values
      Parameters:
      start - the start of the duration
      end - the end of the duration
      Returns:
      An XML duration string representing the time span and direction
    • getXmlDurationFromHecDuration

      protected static String getXmlDurationFromHecDuration(String hecDuration)
      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

      protected static String[] getAttributeNames(org.jdom.Element element)
      Returns a sorted array of attribute names for a JDom element
      Parameters:
      element - The JDom element
      Returns:
      The sorted array of attribute names
    • getElementLines

      public static List<String> getElementLines(org.jdom.Element element, String indent, int level)
      Constructs a list of plot specification lines for a specified JDom element
      Parameters:
      element - The element to generate the plot specification lines for
      indent - The indentation string for each level
      level - The indentation level for the current element
      Returns:
      A list of plot specification lines for the element
    • prepareLines

      protected static String prepareLines(String lines)
      Strips comments, nulls non-quoted spaces, preserves quotes
      Parameters:
      lines - The lines to prepare
      Returns:
      The prepared lines
    • prepareWord

      protected static String prepareWord(String word)
      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 words
      parent - The parent (element or document) to attach the new element to, if appropriate
      startingPath - The initial element hierarchy
      Returns:
      The new element, or null if the element was attached to the parent
    • getTimeZone

      protected static TimeZone getTimeZone(String timeZone)
    • parsePlotSpecText

      protected static org.jdom.Document parsePlotSpecText(String text)
      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