amol        2005/08/24 09:26:20

  Modified:    src/testcases/org/apache/poi/hssf/usermodel
                        TestHSSFWorkbook.java
               src/java/org/apache/poi/hssf/model Workbook.java
               src/java/org/apache/poi/hssf/usermodel HSSFWorkbook.java
  Log:
  Fix for Bug#28328
  
  Revision  Changes    Path
  1.5       +20 -0     
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
  
  Index: TestHSSFWorkbook.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestHSSFWorkbook.java     21 Apr 2005 07:43:22 -0000      1.4
  +++ TestHSSFWorkbook.java     24 Aug 2005 16:26:20 -0000      1.5
  @@ -64,4 +64,24 @@
           c.createSheet("Sheet4");
   
       }
  +    
  +    public void testWindowOneDefaults() {
  +        HSSFWorkbook b = new HSSFWorkbook( );
  +        try {
  +            assertEquals(b.getSelectedTab(), 0);
  +            assertEquals(b.getDisplayedTab(), 0);
  +        } catch (NullPointerException npe) {
  +            fail("WindowOneRecord in Workbook is probably not initialized");
  +        }
  +    }
  +    
  +    public void testSheetSelection() {
  +        HSSFWorkbook b = new HSSFWorkbook();
  +        b.createSheet("Sheet One");
  +        HSSFSheet s = b.createSheet("Sheet Two");
  +        b.setSelectedTab((short) 1);
  +        b.setDisplayedTab((short) 1);
  +        assertEquals(b.getSelectedTab(), 1);
  +        assertEquals(b.getDisplayedTab(), 1);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.46      +25 -11    
jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java
  
  Index: Workbook.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- Workbook.java     18 Aug 2005 07:06:33 -0000      1.45
  +++ Workbook.java     24 Aug 2005 16:26:20 -0000      1.46
  @@ -100,6 +100,7 @@
       private boolean            uses1904datewindowing  = false;  // whether 
1904 date windowing is being used
       private DrawingManager2    drawingManager;
       private List               escherBSERecords = new ArrayList();  // 
EscherBSERecord
  +    private WindowOneRecord windowOne;
   
       private static POILogger   log = POILogFactory.getLogger(Workbook.class);
   
  @@ -215,6 +216,10 @@
                       if (log.check( POILogger.DEBUG ))
                           log.log(DEBUG, "found palette record at " + k);
                       retval.records.setPalettepos( k );
  +                case WindowOneRecord.sid:
  +                    if (log.check( POILogger.DEBUG ))
  +                        log.log(DEBUG, "found WindowOneRecord at " + k);
  +                    retval.windowOne = (WindowOneRecord) rec;
                   default :
               }
               records.add(rec);
  @@ -226,6 +231,10 @@
           //        }
   
           retval.records.setRecords(records);
  +        
  +        if (retval.windowOne == null) {
  +            retval.windowOne = (WindowOneRecord) retval.createWindowOne();
  +        }
           if (log.check( POILogger.DEBUG ))
               log.log(DEBUG, "exit create workbook from existing file 
function");
           return retval;
  @@ -259,7 +268,8 @@
           records.add( retval.createPassword() );
           records.add( retval.createProtectionRev4() );
           records.add( retval.createPasswordRev4() );
  -        records.add( retval.createWindowOne() );
  +        retval.windowOne = (WindowOneRecord) retval.createWindowOne();
  +        records.add( retval.windowOne );
           records.add( retval.createBackup() );
           retval.records.setBackuppos( records.size() - 1 );
           records.add( retval.createHideObj() );
  @@ -625,21 +635,21 @@
   
       /**
        * Adds a string to the SST table and returns its index (if its a 
duplicate
  -     * just returns its index and update the counts) ASSUMES compressed 
unicode

  -     * (meaning 8bit)

  +     * just returns its index and update the counts) ASSUMES compressed 
unicode
  +     * (meaning 8bit)
        *
        * @param string the string to be added to the SSTRecord
  -     *

  +     *
        * @return index of the string within the SSTRecord
        */
   
  -    public int addSSTString(UnicodeString string) {

  +    public int addSSTString(UnicodeString string) {
           if (log.check( POILogger.DEBUG ))
  -          log.log(DEBUG, "insert to sst string='", string);

  +          log.log(DEBUG, "insert to sst string='", string);
           if (sst == null) {
               insertSST();
           }
  -      return sst.addString(string);

  +      return sst.addString(string);
       }
   
       /**
  @@ -647,11 +657,11 @@
        * @return String containing the SST String
        */
   
  -    public UnicodeString getSSTString(int str) {

  +    public UnicodeString getSSTString(int str) {
           if (sst == null) {
               insertSST();
           }
  -        UnicodeString retval = sst.getString(str);

  +        UnicodeString retval = sst.getString(str);
   
           if (log.check( POILogger.DEBUG ))
               log.log(DEBUG, "Returning SST for index=", new Integer(str),
  @@ -1617,7 +1627,7 @@
        */
       protected PaletteRecord createPalette()
       {
  -        return new PaletteRecord();

  +        return new PaletteRecord();
       }
       
       /**
  @@ -2164,7 +2174,11 @@
           }
   
       }
  -
  +    
  +    public WindowOneRecord getWindowOne() {
  +        return windowOne;
  +    }
  +    
       public int addBSERecord(EscherBSERecord e)
       {
           createDrawingGroup();
  
  
  
  1.42      +51 -9     
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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- HSSFWorkbook.java 18 Aug 2005 07:06:41 -0000      1.41
  +++ HSSFWorkbook.java 24 Aug 2005 16:26:20 -0000      1.42
  @@ -251,6 +251,48 @@
       public void setSheetOrder(String sheetname, int pos ) {
           workbook.setSheetOrder(sheetname, pos);
       }
  +    
  +    /**
  +     * sets the tab whose data is actually seen when the sheet is opened.
  +     * This may be different from the "selected sheet" since excel seems to
  +     * allow you to show the data of one sheet when another is seen 
"selected"
  +     * in the tabs (at the bottom).
  +     * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
  +     * @param index
  +     */
  +    public void setSelectedTab(short index) {
  +        workbook.getWindowOne().setSelectedTab(index);
  +    }
  +    
  +    /**
  +     * gets the tab whose data is actually seen when the sheet is opened.
  +     * This may be different from the "selected sheet" since excel seems to
  +     * allow you to show the data of one sheet when another is seen 
"selected"
  +     * in the tabs (at the bottom).
  +     * @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
  +     * @return
  +     */
  +    public short getSelectedTab() {
  +        return workbook.getWindowOne().getSelectedTab();
  +    }
  +    
  +    /**
  +     * sets the first tab that is displayed in the list of tabs
  +     * in excel.
  +     * @param index
  +     */
  +    public void setDisplayedTab(short index) {
  +        workbook.getWindowOne().setDisplayedTab(index);
  +    }
  +    
  +    /**
  +     * sets the first tab that is displayed in the list of tabs
  +     * in excel.
  +     * @return
  +     */
  +    public short getDisplayedTab() {
  +        return workbook.getWindowOne().getDisplayedTab();
  +    }
   
       public final static byte ENCODING_COMPRESSED_UNICODE = 0;
       public final static byte ENCODING_UTF_16             = 1;
  @@ -826,20 +868,20 @@
           return retval;
       }
   
  -    /** @deprecated Do not call this method from your applications. Use the 
methods

  -     *  available in the HSSFRow to add string HSSFCells

  -     */

  +    /** @deprecated Do not call this method from your applications. Use the 
methods
  +     *  available in the HSSFRow to add string HSSFCells
  +     */
       public int addSSTString(String string)
       {
  -        return workbook.addSSTString(new UnicodeString(string));

  +        return workbook.addSSTString(new UnicodeString(string));
       }
   
  -    /** @deprecated Do not call this method from your applications. Use the 
methods

  -     *  available in the HSSFRow to get string HSSFCells

  -     */

  +    /** @deprecated Do not call this method from your applications. Use the 
methods
  +     *  available in the HSSFRow to get string HSSFCells
  +     */
       public String getSSTString(int index)
       {
  -        return workbook.getSSTString(index).getString();

  +        return workbook.getSSTString(index).getString();
       }
   
       Workbook getWorkbook()
  @@ -1089,7 +1131,7 @@
              (byte)0x00, (byte)0x08, (byte)0x17, (byte)0x00, (byte)0x00,
              (byte)0x08, (byte)0xF7, (byte)0x00, (byte)0x00, (byte)0x10,
           };
  -        UnknownRecord r = new UnknownRecord((short)0x00EB, data);

  +        UnknownRecord r = new UnknownRecord((short)0x00EB, data);
           workbook.getRecords().add(loc, r);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to