Save This Page
Home » jexcelapi_2_6_8 » jxl.biff » [javadoc | source]
    1   /*********************************************************************
    2   *
    3   *      Copyright (C) 2002 Andrew Khan
    4   *
    5   * This library is free software; you can redistribute it and/or
    6   * modify it under the terms of the GNU Lesser General Public
    7   * License as published by the Free Software Foundation; either
    8   * version 2.1 of the License, or (at your option) any later version.
    9   *
   10   * This library is distributed in the hope that it will be useful,
   11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13   * Lesser General Public License for more details.
   14   *
   15   * You should have received a copy of the GNU Lesser General Public
   16   * License along with this library; if not, write to the Free Software
   17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   18   ***************************************************************************/
   19   
   20   package jxl.biff;
   21   
   22   import jxl.format.Format;
   23   
   24   /**
   25    * The excel string for the various built in formats.  Used to present
   26    * the cell format information back to the user
   27    *
   28    * The difference between this class and the various format object contained
   29    * in the jxl.write package is that this object contains the Excel strings,
   30    * not their java equivalents
   31    */
   32   final class BuiltInFormat implements Format, DisplayFormat
   33   {
   34     /**
   35      * The excel format string
   36      */
   37     private String formatString;
   38   
   39     /**
   40      * The index
   41      */
   42     private int formatIndex;
   43   
   44     /**
   45      * Constructor
   46      *
   47      * @param s the format string
   48      * @param i the format index
   49      */
   50     private BuiltInFormat(String s, int i)
   51     {
   52       formatIndex = i;
   53       formatString = s;
   54     }
   55   
   56     /**
   57      * Accesses the excel format string which is applied to the cell
   58      * Note that this is the string that excel uses, and not the java
   59      * equivalent
   60      *
   61      * @return the cell format string
   62      */
   63     public String getFormatString()
   64     {
   65       return formatString;
   66     }
   67   
   68     /**
   69      * Accessor for the index style of this format
   70      *
   71      * @return the index for this format
   72      */
   73     public int getFormatIndex()
   74     {
   75       return formatIndex;
   76     }
   77     /**
   78      * Accessor to see whether this format has been initialized
   79      *
   80      * @return TRUE if initialized, FALSE otherwise
   81      */
   82     public boolean isInitialized()
   83     {
   84       return true;
   85     }
   86     /**
   87      * Initializes this format with the specified index number
   88      *
   89      * @param pos the position of this format record in the workbook
   90      */
   91     public void initialize(int pos)
   92     {
   93     }
   94   
   95     /**
   96      * Accessor to determine whether or not this format is built in
   97      *
   98      * @return TRUE if this format is a built in format, FALSE otherwise
   99      */
  100     public boolean isBuiltIn()
  101     {
  102       return true;
  103     }
  104   
  105     /**
  106      * Equals method
  107      *
  108      * @return TRUE if the two built in formats are equal, FALSE otherwise
  109      */
  110     public boolean equals(Object o)
  111     {
  112       if (o == this)
  113       {
  114         return true;
  115       }
  116   
  117       if (!(o instanceof BuiltInFormat))
  118       {
  119         return false;
  120       }
  121   
  122       BuiltInFormat bif = (BuiltInFormat) o;
  123       return (formatIndex == bif.formatIndex);
  124     }
  125   
  126     /**
  127      * The list of built in formats
  128      */
  129     public static BuiltInFormat[] builtIns = new BuiltInFormat[0x32];
  130   
  131     // Populate the built ins
  132     static
  133     {
  134       builtIns[0x0] = new BuiltInFormat("", 0);
  135       builtIns[0x1] = new BuiltInFormat("0", 1);
  136       builtIns[0x2] = new BuiltInFormat("0.00", 2);
  137       builtIns[0x3] = new BuiltInFormat("#,##0", 3);
  138       builtIns[0x4] = new BuiltInFormat("#,##0.00", 4);
  139       builtIns[0x5] = new BuiltInFormat("($#,##0_);($#,##0)", 5);
  140       builtIns[0x6] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 6);
  141       builtIns[0x7] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 7);
  142       builtIns[0x8] = new BuiltInFormat("($#,##0.00_);[Red]($#,##0.00)", 8);
  143       builtIns[0x9] = new BuiltInFormat("0%", 9);
  144       builtIns[0xa] = new BuiltInFormat("0.00%", 10);
  145       builtIns[0xb] = new BuiltInFormat("0.00E+00", 11);
  146       builtIns[0xc] = new BuiltInFormat("# ?/?", 12);
  147       builtIns[0xd] = new BuiltInFormat("# ??/??", 13);
  148       builtIns[0xe] = new BuiltInFormat("dd/mm/yyyy", 14);
  149       builtIns[0xf] = new BuiltInFormat("d-mmm-yy", 15);
  150       builtIns[0x10] = new BuiltInFormat("d-mmm", 16);
  151       builtIns[0x11] = new BuiltInFormat("mmm-yy", 17);
  152       builtIns[0x12] = new BuiltInFormat("h:mm AM/PM", 18);
  153       builtIns[0x13] = new BuiltInFormat("h:mm:ss AM/PM", 19);
  154       builtIns[0x14] = new BuiltInFormat("h:mm", 20);
  155       builtIns[0x15] = new BuiltInFormat("h:mm:ss", 21);
  156       builtIns[0x16] = new BuiltInFormat("m/d/yy h:mm", 22);
  157       builtIns[0x25] = new BuiltInFormat("(#,##0_);(#,##0)", 0x25);
  158       builtIns[0x26] = new BuiltInFormat("(#,##0_);[Red](#,##0)", 0x26);
  159       builtIns[0x27] = new BuiltInFormat("(#,##0.00_);(#,##0.00)", 0x27);
  160       builtIns[0x28] = new BuiltInFormat("(#,##0.00_);[Red](#,##0.00)", 0x28);
  161       builtIns[0x29] = new BuiltInFormat
  162         ("_(*#,##0_);_(*(#,##0);_(*\"-\"_);(@_)", 0x29);
  163       builtIns[0x2a] = new BuiltInFormat
  164         ("_($*#,##0_);_($*(#,##0);_($*\"-\"_);(@_)", 0x2a);
  165       builtIns[0x2b] = new BuiltInFormat
  166         ("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);(@_)", 0x2b);
  167       builtIns[0x2c] = new BuiltInFormat
  168         ("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);(@_)", 0x2c);
  169       builtIns[0x2d] = new BuiltInFormat("mm:ss", 0x2d);
  170       builtIns[0x2e] = new BuiltInFormat("[h]mm:ss", 0x2e);
  171       builtIns[0x2f] = new BuiltInFormat("mm:ss.0", 0x2f);
  172       builtIns[0x30] = new BuiltInFormat("##0.0E+0", 0x30);
  173       builtIns[0x31] = new BuiltInFormat("@", 0x31);
  174     }
  175   }
  176   

Save This Page
Home » jexcelapi_2_6_8 » jxl.biff » [javadoc | source]