001    package echopoint.google.chart.model;
002    
003    import java.io.Serializable;
004    
005    /**
006     * A simple model object that may be used to represent the parameters that
007     * control bar chart size.  Use of this model object is entirely optional,
008     * since the {@link echopoint.google.chart.BarChart#setSize(String)} method may
009     * be used directly using the string value as required by Google API.
010     *
011     * @author Rakesh 2008-08-20
012     * @version $Id: BarChartSize.java 63 2008-08-29 07:46:39Z sptrakesh $
013     */
014    public class BarChartSize implements Serializable
015    {
016      private static final long serialVersionUID = 1l;
017    
018      /** The width in pixels of a bar in the chart. */
019      private final int width;
020    
021      /** The optional space in pixels between bars in a group. */
022      private int groupSpace = -1;
023    
024      /** The optional space in pixels between groups. */
025      private int space = -1;
026    
027      /**
028       * Create a new instance using the specified width.
029       *
030       * @param width The width of a bar in the chart.
031       */
032      public BarChartSize( final int width )
033      {
034        this.width = width;
035      }
036    
037      /**
038       * Create a new instance using the specified width and intra-group spacing.
039       *
040       * @param width The width of a bar in the chart.
041       * @param groupSpace The intra-group spacing for the chart.
042       */
043      public BarChartSize( final int width, final int groupSpace )
044      {
045        this( width );
046        this.groupSpace = groupSpace;
047      }
048    
049      /**
050       * Create a new instance using the specified parameters.
051       *
052       * @param width The width of a bar in the chart.
053       * @param groupSpace The intra-group spacing for the chart.
054       * @param space The space between groups in the chart.
055       */
056      public BarChartSize( final int width, final int groupSpace, final int space )
057      {
058        this( width, groupSpace );
059        this.space = space;
060      }
061    
062      /**
063       * Return a string representation of the data encapsulated in this object.
064       * The string value corresponds to the encoding used to represent this
065       * value in the Google API.
066       *
067       * @return The string representation of this object.
068       */
069      @Override
070      public String toString()
071      {
072        final StringBuilder builder = new StringBuilder( 16 );
073        builder.append( width );
074    
075        if ( groupSpace != -1 )
076        {
077          builder.append( "," ).append( groupSpace );
078        }
079    
080        if ( space != -1 )
081        {
082          builder.append( "," ).append( space );
083        }
084    
085        return builder.toString();
086      }
087    
088      /**
089       * Accessor for property 'width'.
090       *
091       * @return Value for property 'width'.
092       */
093      public int getWidth()
094      {
095        return width;
096      }
097    
098      /**
099       * Accessor for property 'groupSpace'.
100       *
101       * @return Value for property 'groupSpace'.
102       */
103      public int getGroupSpace()
104      {
105        return groupSpace;
106      }
107    
108      /**
109       * Accessor for property 'space'.
110       *
111       * @return Value for property 'space'.
112       */
113      public int getSpace()
114      {
115        return space;
116      }
117    }