]> source.dussan.org Git - poi.git/commitdiff
initial support for creating hyperlinks in HSLF, units test are still to do
authorYegor Kozlov <yegor@apache.org>
Tue, 30 Sep 2008 15:11:26 +0000 (15:11 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 30 Sep 2008 15:11:26 +0000 (15:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@700493 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java [new file with mode: 0755]
src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java

diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
new file mode 100755 (executable)
index 0000000..9254c37
--- /dev/null
@@ -0,0 +1,59 @@
+/* ====================================================================\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.hslf.examples;\r
+\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.usermodel.RichTextRun;\r
+import org.apache.poi.hslf.model.*;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.awt.*;\r
+\r
+/**\r
+ * Demonstrates how to create hyperlinks in PowerPoint presentations\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class CreateHyperlink {\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        SlideShow ppt = new SlideShow();\r
+\r
+        Slide slide = ppt.createSlide();\r
+\r
+        TextBox shape = new TextBox();\r
+        shape.setText("Apache POI");\r
+        Rectangle anchor = new Rectangle(100, 100, 200, 50);\r
+        shape.setAnchor(anchor);\r
+\r
+        String text = shape.getText();\r
+        Hyperlink link = new Hyperlink();\r
+        link.setAddress("http://www.apache.org");\r
+        link.setTitle(shape.getText());\r
+        int linkId = ppt.addHyperlink(link);\r
+\r
+        shape.setHyperlink(linkId, 0, text.length());\r
+\r
+        slide.addShape(shape);\r
+\r
+        FileOutputStream out = new FileOutputStream("hyperlink.ppt");\r
+        ppt.write(out);\r
+        out.close();\r
+\r
+   }\r
+}\r
index 751753b22e538e426dd25d9c42fc43459dd2c480..a4d823be55029b03f1e378307304684d1f62ba18 100755 (executable)
@@ -547,4 +547,31 @@ public abstract class TextShape extends SimpleShape {
         return (OEPlaceholderAtom)getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
     }
 
+    /**
+     *
+     * Assigns a hyperlink to this text shape
+     *
+     * @param linkId    id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
+     * @param      beginIndex   the beginning index, inclusive.
+     * @param      endIndex     the ending index, exclusive.
+     * @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
+     */
+    public void setHyperlink(int linkId, int beginIndex, int endIndex){
+        //TODO validate beginIndex and endIndex and throw IllegalArgumentException
+
+        InteractiveInfo info = new InteractiveInfo();
+        InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
+        infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+        infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
+        infoAtom.setHyperlinkID(linkId);
+
+        _txtbox.appendChildRecord(info);
+
+        TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom();
+        txiatom.setStartIndex(beginIndex);
+        txiatom.setEndIndex(endIndex);
+        _txtbox.appendChildRecord(txiatom);
+
+    }
+
 }
index b3db6bafaa8c38a775742ea714a08743e2998187..e6a827977343284bcae5f00a9240f73412146f86 100644 (file)
@@ -40,7 +40,7 @@ public class TxInteractiveInfoAtom extends RecordAtom {
     /**\r
      * Constructs a brand new link related atom record.\r
      */\r
-    protected TxInteractiveInfoAtom() {\r
+    public TxInteractiveInfoAtom() {\r
         _header = new byte[8];\r
         _data = new byte[8];\r
 \r