]> source.dussan.org Git - poi.git/commitdiff
Add accessors to horizontal and vertical alignment in HSSFTextbox
authorYegor Kozlov <yegor@apache.org>
Fri, 14 Mar 2008 18:05:55 +0000 (18:05 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 14 Mar 2008 18:05:55 +0000 (18:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@637189 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/TextboxShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java [new file with mode: 0755]

index 8c1a63ceb9fd1f2fe62237a6cdccf99d400a46b3..e6f5251d88075c4fa2438a806a09e52bceb14acf 100644 (file)
@@ -36,7 +36,8 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
-           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
+           <action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
+           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
            <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
index 9213e0184ec2c0494af74e353b1636c911466eb4..36aee6a5d689af1f2f1b835289065b2abba87de4 100644 (file)
@@ -33,7 +33,8 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
-           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
+           <action dev="POI-DEVELOPERS" type="add">Add accessors to horizontal and vertical alignment in HSSFTextbox</action>
+           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</action>
            <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
index 4b1027809150b3ddf92fcfd60b20a7eb84cdcd82..e55fcacbc378e4a15c12ff5b3e444dd4a06d6b21 100644 (file)
@@ -133,8 +133,8 @@ public class TextboxShape
         HSSFTextbox shape = hssfShape;
 
         TextObjectRecord obj = new TextObjectRecord();
-        obj.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
-        obj.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
+        obj.setHorizontalTextAlignment( hssfShape.getHorizontalAlignment() );
+        obj.setVerticalTextAlignment( hssfShape.getVerticalAlignment());
         obj.setTextLocked( true );
         obj.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
         int frLength = ( shape.getString().numFormattingRuns() + 1 ) * 8;
index 51c4c25b5bf6c09575941762ff73bbbd9ba94a1e..f994f364630dafa294581285f68587ea980f808e 100644 (file)
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+
 /**
  * A textbox is a shape that may hold a rich text string.
  *
@@ -27,7 +30,25 @@ public class HSSFTextbox
 {
     public final static short       OBJECT_TYPE_TEXT               = 6;
 
+    /**
+     * How to align text horizontally
+     */
+    public final static short  HORIZONTAL_ALIGNMENT_LEFT = 1;
+    public final static short  HORIZONTAL_ALIGNMENT_CENTERED = 2;
+    public final static short  HORIZONTAL_ALIGNMENT_RIGHT = 3;
+    public final static short  HORIZONTAL_ALIGNMENT_JUSTIFIED = 4;
+
+    /**
+     * How to align text vertically
+     */
+    public final static short  VERTICAL_ALIGNMENT_TOP    = 1;
+    public final static short  VERTICAL_ALIGNMENT_CENTER = 2;
+    public final static short  VERTICAL_ALIGNMENT_BOTTOM = 3;
+    public final static short  VERTICAL_ALIGNMENT_JUSTIFY = 4;
+
+
     int marginLeft, marginRight, marginTop, marginBottom;
+    short halign, valign;
 
     HSSFRichTextString string = new HSSFRichTextString("");
 
@@ -40,6 +61,9 @@ public class HSSFTextbox
     {
         super( parent, anchor );
         setShapeType(OBJECT_TYPE_TEXT);
+
+        halign = HORIZONTAL_ALIGNMENT_LEFT;
+        valign = VERTICAL_ALIGNMENT_TOP;
     }
 
     /**
@@ -121,4 +145,36 @@ public class HSSFTextbox
     {
         this.marginBottom = marginBottom;
     }
+
+    /**
+     * Gets the horizontal alignment.
+     */
+    public short getHorizontalAlignment()
+    {
+        return halign;
+    }
+
+    /**
+     * Sets the horizontal alignment.
+     */
+    public void setHorizontalAlignment( short align )
+    {
+        this.halign = align;
+    }
+
+    /**
+     * Gets the vertical alignment.
+     */
+    public short getVerticalAlignment()
+    {
+        return valign;
+    }
+
+    /**
+     * Sets the vertical alignment.
+     */
+    public void setVerticalAlignment( short align )
+    {
+        this.valign = align;
+    }
 }
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFTextbox.java
new file mode 100755 (executable)
index 0000000..f7ce61f
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+* Licensed to the Apache Software Foundation (ASF) under one or more\r
+* contributor license agreements.  See the NOTICE file distributed with\r
+* this work for additional information regarding copyright ownership.\r
+* The ASF licenses this file to You under the Apache License, Version 2.0\r
+* (the "License"); you may not use this file except in compliance with\r
+* the License.  You may obtain a copy of the License at\r
+*\r
+*     http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+package org.apache.poi.hssf.usermodel;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+import junit.framework.TestCase;\r
+\r
+/**\r
+ * Test <code>HSSFTextbox</code>.\r
+ *\r
+ * @author Yegor Kozlov (yegor at apache.org)\r
+ */\r
+public final class TestHSSFTextbox extends TestCase{\r
+\r
+    /**\r
+     * Test that accessors to horizontal and vertical alignment work properly\r
+     */\r
+    public void testAlignment() {\r
+        HSSFWorkbook wb = new HSSFWorkbook();\r
+        HSSFSheet sh1 = wb.createSheet();\r
+        HSSFPatriarch patriarch = sh1.createDrawingPatriarch();\r
+\r
+        HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 6, 4));\r
+        HSSFRichTextString str = new HSSFRichTextString("Hello, World");\r
+        textbox.setString(str);\r
+        textbox.setHorizontalAlignment(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED);\r
+        textbox.setVerticalAlignment(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER);\r
+\r
+        assertEquals(HSSFTextbox.HORIZONTAL_ALIGNMENT_CENTERED, textbox.getHorizontalAlignment());\r
+        assertEquals(HSSFTextbox.VERTICAL_ALIGNMENT_CENTER, textbox.getVerticalAlignment());\r
+    }\r
+\r
+ }\r