poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slaub...@apache.org
Subject cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel TestWorkbook.java
Date Thu, 24 Jul 2003 19:22:34 GMT
slaubach    2003/07/24 12:22:34

  Modified:    src/java/org/apache/poi/hssf/model Tag: REL_2_BRANCH
                        Sheet.java
               src/java/org/apache/poi/hssf/usermodel Tag: REL_2_BRANCH
                        HSSFWorkbook.java
               src/testcases/org/apache/poi/hssf/usermodel Tag:
                        REL_2_BRANCH TestWorkbook.java
  Log:
  Fixed the problem in bug# 16756 by making sure the same HSSFDataFormat object is returned
for a given book.  Also included the new margin code that Mr. Oliver wanted (just because
in was in the particular directory).
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.31.2.4  +76 -71    jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java
  
  Index: Sheet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java,v
  retrieving revision 1.31.2.3
  retrieving revision 1.31.2.4
  diff -u -r1.31.2.3 -r1.31.2.4
  --- Sheet.java	24 Jul 2003 18:42:45 -0000	1.31.2.3
  +++ Sheet.java	24 Jul 2003 19:22:33 -0000	1.31.2.4
  @@ -109,6 +109,7 @@
       protected FooterRecord              footer           = null;
       protected PrintGridlinesRecord      printGridlines   = null;
       protected MergeCellsRecord          merged           = null;
  +    protected Margin                    margins[]        = null;
       protected ArrayList                 mergedRecords    = new ArrayList();
       protected ArrayList                 mergedLocs       = new ArrayList();
       protected int                       numMergedRegions = 0;
  @@ -257,10 +258,26 @@
               {
                   retval.footer = (FooterRecord) rec;
               }
  -            else if ( rec.getSid() == PrintSetupRecord.sid )
  +            else if ( rec.getSid() == PrintSetupRecord.sid && bofEofNestingLevel
== 1)
               {
                   retval.printSetup = (PrintSetupRecord) rec;
               }
  +            else if ( rec.getSid() == LeftMarginRecord.sid)
  +            {
  +                retval.getMargins()[LeftMargin] = (LeftMarginRecord) rec;
  +            }
  +            else if ( rec.getSid() == RightMarginRecord.sid)
  +            {
  +                retval.getMargins()[RightMargin] = (RightMarginRecord) rec;
  +            }
  +            else if ( rec.getSid() == TopMarginRecord.sid)
  +            {
  +                retval.getMargins()[TopMargin] = (TopMarginRecord) rec;
  +            }
  +            else if ( rec.getSid() == BottomMarginRecord.sid)
  +            {
  +                retval.getMargins()[BottomMargin] = (BottomMarginRecord) rec;
  +            }
               else if ( rec.getSid() == SelectionRecord.sid )
               {
                   retval.selection = (SelectionRecord) rec;
  @@ -2330,82 +2347,59 @@
         * @param margin which margin to get
         * @return the size of the margin
         */
  -     public double getMargin(short margin) {
  -         Margin m;
  -         switch ( margin )
  -         {
  -             case LeftMargin:
  -                 m = (Margin) findFirstRecordBySid( LeftMarginRecord.sid );
  -                 if ( m == null )
  -                     return .75;
  -                 break;
  -             case RightMargin:
  -                 m = (Margin) findFirstRecordBySid( RightMarginRecord.sid );
  -                 if ( m == null )
  -                     return .75;
  -                 break;
  -             case TopMargin:
  -                 m = (Margin) findFirstRecordBySid( TopMarginRecord.sid );
  -                 if ( m == null )
  -                     return 1.0;
  -                 break;
  -             case BottomMargin:
  -                 m = (Margin) findFirstRecordBySid( BottomMarginRecord.sid );
  -                 if ( m == null )
  -                     return 1.0;
  -                 break;
  -             default :
  -                 throw new RuntimeException( "Unknown margin constant:  " + margin );
  -         }
  -         return m.getMargin();
  -     }
  +    public double getMargin(short margin) {
  +	if (getMargins()[margin] != null)
  +	    return margins[margin].getMargin();
  +	else {
  +	    switch ( margin )
  +		{
  +		case LeftMargin:
  +		    return .75;
  +		case RightMargin:
  +		    return .75;
  +		case TopMargin:
  +		    return 1.0;
  +		case BottomMargin:
  +		    return 1.0;
  +		default :
  +		    throw new RuntimeException( "Unknown margin constant:  " + margin );
  +		}
  +	}
  +    }
   
        /**
         * Sets the size of the margin in inches.
         * @param margin which margin to get
         * @param size the size of the margin
         */
  -     public void setMargin(short margin, double size) {
  -         Margin m;
  -         switch ( margin )
  -         {
  -             case LeftMargin:
  -                 m = (Margin) findFirstRecordBySid( LeftMarginRecord.sid );
  -                 if ( m == null )
  -                 {
  -                     m = new LeftMarginRecord();
  -                     records.add( getDimsLoc() + 1, m );
  -                 }
  -                 break;
  -             case RightMargin:
  -                 m = (Margin) findFirstRecordBySid( RightMarginRecord.sid );
  -                 if ( m == null )
  -                 {
  -                     m = new RightMarginRecord();
  -                     records.add( getDimsLoc() + 1, m );
  -                 }
  -                 break;
  -             case TopMargin:
  -                 m = (Margin) findFirstRecordBySid( TopMarginRecord.sid );
  -                 if ( m == null )
  -                 {
  -                     m = new TopMarginRecord();
  -                     records.add( getDimsLoc() + 1, m );
  -                 }
  -                 break;
  -             case BottomMargin:
  -                 m = (Margin) findFirstRecordBySid( BottomMarginRecord.sid );
  -                 if ( m == null )
  -                 {
  -                     m = new BottomMarginRecord();
  -                     records.add( getDimsLoc() + 1, m );
  -                 }
  -                 break;
  -             default :
  -                 throw new RuntimeException( "Unknown margin constant:  " + margin );
  -         }
  -         m.setMargin( size );
  -     }
  +    public void setMargin(short margin, double size) {
  +	Margin m = getMargins()[margin];
  +	if (m  == null) {
  +	    switch ( margin )
  +		{
  +		case LeftMargin:
  +		    m = new LeftMarginRecord();
  +		    records.add( getDimsLoc() + 1, m );
  +		    break;
  +		case RightMargin:
  +		    m = new RightMarginRecord();
  +		    records.add( getDimsLoc() + 1, m );
  +		    break;
  +		case TopMargin:
  +		    m = new TopMarginRecord();
  +		    records.add( getDimsLoc() + 1, m );
  +		    break;
  +		case BottomMargin:
  +		    m = new BottomMarginRecord();
  +		    records.add( getDimsLoc() + 1, m );
  +		    break;
  +		default :
  +		    throw new RuntimeException( "Unknown margin constant:  " + margin );
  +		}
  +	    margins[margin] = m;
  +	}
  +	m.setMargin( size );
  +    }
   
       public int getEofLoc()
       {
  @@ -2527,6 +2521,17 @@
       public void setSelection( SelectionRecord selection )
       {
           this.selection = selection;
  +    }
  +
  +    /**
  +     * Returns the array of margins.  If not created, will create.
  +     *
  +     * @return the array of marings.
  +     */
  +    protected Margin[] getMargins() {
  +        if (margins == null)
  +            margins = new Margin[4];
  +	return margins;
       }
   
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.24.2.1  +12 -2     jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
  
  Index: HSSFWorkbook.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
  retrieving revision 1.24
  retrieving revision 1.24.2.1
  diff -u -r1.24 -r1.24.2.1
  --- HSSFWorkbook.java	30 Apr 2003 04:39:00 -0000	1.24
  +++ HSSFWorkbook.java	24 Jul 2003 19:22:34 -0000	1.24.2.1
  @@ -147,6 +147,14 @@
        * memory.
        */
       private POIFSFileSystem poifs;
  +
  +    /**
  +     * Used to keep track of the data formatter so that all
  +     * createDataFormatter calls return the same one for a given
  +     * book.  This ensures that updates from one places is visible
  +     * someplace else.
  +     */
  +    private HSSFDataFormat formatter;
       
       private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
   
  @@ -945,13 +953,15 @@
       }
   
       /**
  -     * Creates an instance of HSSFDataFormat.
  +     * Returns the instance of HSSFDataFormat for this workbook.
        * @return the HSSFDataFormat object
        * @see org.apache.poi.hssf.record.FormatRecord
        * @see org.apache.poi.hssf.record.Record
        */
       public HSSFDataFormat createDataFormat() {
  -        return new HSSFDataFormat(workbook);
  +	if (formatter == null)
  +	    formatter = new HSSFDataFormat(workbook);
  +	return formatter;
       }
   	
       /** remove the named range by his name
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.1  +2 -0      jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
  
  Index: TestWorkbook.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- TestWorkbook.java	30 Apr 2003 04:38:58 -0000	1.10
  +++ TestWorkbook.java	24 Jul 2003 19:22:34 -0000	1.10.2.1
  @@ -304,6 +304,8 @@
           assertEquals(1.25,cell.getNumericCellValue(), 1e-10);
   
   	assertEquals(format.getFormat(df), "0.0");
  +
  +	assertEquals(format, workbook.createDataFormat());
   	
           stream.close();
       }
  
  
  

Mime
View raw message