You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by jh...@apache.org on 2006/08/29 05:27:11 UTC

svn commit: r437930 - in /jakarta/poi/trunk/src/java/org/apache/poi/hssf: eventmodel/EventRecordFactory.java model/Sheet.java record/RecordFactory.java usermodel/HSSFSheet.java util/PaneInformation.java

Author: jheight
Date: Mon Aug 28 20:27:11 2006
New Revision: 437930

URL: http://svn.apache.org/viewvc?rev=437930&view=rev
Log:
bug 23631: support for getting the current pane information in excel

Added:
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/PaneInformation.java
Modified:
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java?rev=437930&r1=437929&r2=437930&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java Mon Aug 28 20:27:11 2006
@@ -70,6 +70,7 @@
 import org.apache.poi.hssf.record.MulRKRecord;
 import org.apache.poi.hssf.record.NameRecord;
 import org.apache.poi.hssf.record.NumberRecord;
+import org.apache.poi.hssf.record.PaneRecord;
 import org.apache.poi.hssf.record.PaletteRecord;
 import org.apache.poi.hssf.record.PasswordRecord;
 import org.apache.poi.hssf.record.PasswordRev4Record;
@@ -156,7 +157,7 @@
                 LeftMarginRecord.class, RightMarginRecord.class,
                 TopMarginRecord.class, BottomMarginRecord.class,
                 PaletteRecord.class, StringRecord.class, SharedFormulaRecord.class, 
-                WriteProtectRecord.class, FilePassRecord.class
+                WriteProtectRecord.class, FilePassRecord.class, PaneRecord.class
             };
        
     }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java?rev=437930&r1=437929&r2=437930&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java Mon Aug 28 20:27:11 2006
@@ -24,6 +24,8 @@
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.util.PaneInformation;
+
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
@@ -2383,7 +2385,7 @@
     }
 
     /**
-     * Creates a split (freezepane).
+     * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
      * @param colSplit      Horizonatal position of split.
      * @param rowSplit      Vertical position of split.
      * @param topRow        Top row visible in bottom pane
@@ -2391,6 +2393,10 @@
      */
     public void createFreezePane(int colSplit, int rowSplit, int topRow, int leftmostColumn )
     {
+    	int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
+    	if (paneLoc != -1)
+    		records.remove(paneLoc);
+    	
         int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
         PaneRecord pane = new PaneRecord();
         pane.setX((short)colSplit);
@@ -2422,7 +2428,7 @@
     }
 
     /**
-     * Creates a split pane.
+     * Creates a split pane. Any existing freezepane or split pane is overwritten.
      * @param xSplitPos      Horizonatal position of split (in 1/20th of a point).
      * @param ySplitPos      Vertical position of split (in 1/20th of a point).
      * @param topRow        Top row visible in bottom pane
@@ -2436,6 +2442,10 @@
      */
     public void createSplitPane(int xSplitPos, int ySplitPos, int topRow, int leftmostColumn, int activePane )
     {
+    	int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
+    	if (paneLoc != -1)
+    		records.remove(paneLoc);
+    	
         int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
         PaneRecord r = new PaneRecord();
         r.setX((short)xSplitPos);
@@ -2451,6 +2461,19 @@
         SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid);
         sel.setPane(PANE_LOWER_RIGHT);
 
+    }
+    
+    /**
+     * Returns the information regarding the currently configured pane (split or freeze).
+     * @return null if no pane configured, or the pane information.
+     */
+    public PaneInformation getPaneInformation() {
+      PaneRecord rec = (PaneRecord)findFirstRecordBySid(PaneRecord.sid);
+      if (rec == null)
+        return null;
+        
+      return new PaneInformation(rec.getX(), rec.getY(), rec.getTopRow(),
+    		                     rec.getLeftColumn(), (byte)rec.getActivePane(), windowTwo.getFreezePanes());      
     }
 
     public SelectionRecord getSelection()

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=437930&r1=437929&r2=437930&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java Mon Aug 28 20:27:11 2006
@@ -72,7 +72,7 @@
                 ObjRecord.class, TextObjectRecord.class,
                 PaletteRecord.class, StringRecord.class, RecalcIdRecord.class, SharedFormulaRecord.class,
                 HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class, 
-                WriteProtectRecord.class, FilePassRecord.class
+                WriteProtectRecord.class, FilePassRecord.class, PaneRecord.class
             };
     }
     private static Map           recordsMap  = recordsToMap(records);

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=437930&r1=437929&r2=437930&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Mon Aug 28 20:27:11 2006
@@ -26,6 +26,7 @@
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.*;
 import org.apache.poi.hssf.util.Region;
+import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
@@ -1076,7 +1077,7 @@
     }
 
     /**
-     * Creates a split (freezepane).
+     * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
      * @param colSplit      Horizonatal position of split.
      * @param rowSplit      Vertical position of split.
      * @param topRow        Top row visible in bottom pane
@@ -1092,7 +1093,7 @@
     }
 
     /**
-     * Creates a split (freezepane).
+     * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
      * @param colSplit      Horizonatal position of split.
      * @param rowSplit      Vertical position of split.
      */
@@ -1102,7 +1103,7 @@
     }
 
     /**
-     * Creates a split pane.
+     * Creates a split pane. Any existing freezepane or split pane is overwritten.
      * @param xSplitPos      Horizonatal position of split (in 1/20th of a point).
      * @param ySplitPos      Vertical position of split (in 1/20th of a point).
      * @param topRow        Top row visible in bottom pane
@@ -1117,6 +1118,14 @@
     public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane )
     {
         getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
+    }
+    
+    /**
+     * Returns the information regarding the currently configured pane (split or freeze).
+     * @return null if no pane configured, or the pane information.
+     */
+    public PaneInformation getPaneInformation() {
+      return getSheet().getPaneInformation();
     }
 
     /**

Added: jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/PaneInformation.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/PaneInformation.java?rev=437930&view=auto
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/PaneInformation.java (added)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/PaneInformation.java Mon Aug 28 20:27:11 2006
@@ -0,0 +1,104 @@
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.util;
+
+/**
+ * Holds information regarding a split plane or freeze plane for a sheet.
+ *
+ */
+public class PaneInformation
+{
+	/** Constant for active pane being the lower right*/
+    public static final byte PANE_LOWER_RIGHT = (byte)0;
+    /** Constant for active pane being the upper right*/
+    public static final byte PANE_UPPER_RIGHT = (byte)1;
+    /** Constant for active pane being the lower left*/
+    public static final byte PANE_LOWER_LEFT = (byte)2;
+    /** Constant for active pane being the upper left*/
+    public static final byte PANE_UPPER_LEFT = (byte)3;
+    
+	private short x;
+	private short y;
+	private short topRow;
+	private short leftColumn;
+	private byte activePane;
+	private boolean frozen = false;
+	
+	public PaneInformation(short x, short y, short top, short left, byte active, boolean frozen) {
+		this.x = x;
+		this.y = y;
+		this.topRow = top;
+		this.leftColumn = left;
+		this.activePane = active;
+		this.frozen = frozen;
+	}
+
+
+	/**
+	 * Returns the vertical position of the split.
+	 * @return 0 if there is no vertical spilt,
+	 *         or for a freeze pane the number of columns in the TOP pane,
+	 *         or for a split plane the position of the split in 1/20th of a point.
+	 */
+	public short getVerticalSplitPosition() {
+	  return x;
+	}
+	
+	/**
+	 * Returns the horizontal position of the split.
+	 * @return 0 if there is no horizontal spilt,
+	 *         or for a freeze pane the number of rows in the LEFT pane,
+	 *         or for a split plane the position of the split in 1/20th of a point.
+	 */
+	public short getHorizontalSplitPosition() {
+	  return y;
+	}
+	
+	/**
+	 * For a horizontal split returns the top row in the BOTTOM pane.
+	 * @return 0 if there is no horizontal split, or the top row of the bottom pane.
+	 */
+	public short getHorizontalSplitTopRow() {
+	  return topRow;
+	}
+	
+	/**
+	 * For a vertical split returns the left column in the RIGHT pane.
+	 * @return 0 if there is no vertical split, or the left column in the RIGHT pane.
+	 */
+	public short getVerticalSplitLeftColumn() {
+	  return leftColumn;
+	}
+	
+	/**
+	 * Returns the active pane
+	 * @see PANE_LOWER_RIGHT
+	 * @see PANE_UPPER_RIGHT
+	 * @see PANE_LOWER_LEFT
+	 * @see PANE_UPPER_LEFT
+	 * @return the active pane.
+	 */
+	public byte getActivePane() {
+	  return activePane;
+	}
+	
+	/** Returns true if this is a Freeze pane, false if it is a split pane.
+	 */
+	public boolean isFreezePane() {
+		return frozen;
+	}
+}



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