]> source.dussan.org Git - poi.git/commitdiff
support links to slides in HSLF
authorYegor Kozlov <yegor@apache.org>
Wed, 24 Oct 2012 12:11:31 +0000 (12:11 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 24 Oct 2012 12:11:31 +0000 (12:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1401642 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java

index 010bf6d6b8e6100b2b3828350a13833522ad8013..0aa8db32de87536cf158338a8dae44d65bbe56ed 100644 (file)
@@ -33,22 +33,39 @@ public final class CreateHyperlink {
     public static void main(String[] args) throws Exception {
         SlideShow ppt = new SlideShow();
 
-        Slide slide = ppt.createSlide();
+        Slide slideA = ppt.createSlide();
+        Slide slideB = ppt.createSlide();
+        Slide slideC = ppt.createSlide();
 
-        TextBox shape = new TextBox();
-        shape.setText("Apache POI");
-        Rectangle anchor = new Rectangle(100, 100, 200, 50);
-        shape.setAnchor(anchor);
+        // link to a URL
+        TextBox textBox1 = new TextBox();
+        textBox1.setText("Apache POI");
+        textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
 
-        String text = shape.getText();
+        String text = textBox1.getText();
         Hyperlink link = new Hyperlink();
         link.setAddress("http://www.apache.org");
-        link.setTitle(shape.getText());
+        link.setTitle(textBox1.getText());
         int linkId = ppt.addHyperlink(link);
 
-        shape.setHyperlink(linkId, 0, text.length());
+        // apply link to the text
+        textBox1.setHyperlink(linkId, 0, text.length());
 
-        slide.addShape(shape);
+        slideA.addShape(textBox1);
+
+        // link to another slide
+        TextBox textBox2 = new TextBox();
+        textBox2.setText("Go to slide #3");
+        textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
+
+        Hyperlink link2 = new Hyperlink();
+        link2.setAddress(slideC);
+        ppt.addHyperlink(link2);
+
+        // apply link to the whole shape
+        textBox2.setHyperlink(link2);
+
+        slideA.addShape(textBox2);
 
         FileOutputStream out = new FileOutputStream("hyperlink.ppt");
         ppt.write(out);
index 5c33d807ee37ae8ebf29585618e79af975cb2e0e..fbdd2e7aee156ee79e788522758fb282d9210c82 100644 (file)
@@ -37,6 +37,7 @@ public final class Hyperlink {
     public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide;
     public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide;
     public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide;
+    public static final byte LINK_SLIDENUMBER = InteractiveInfoAtom.LINK_SlideNumber;
     public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url;
     public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL;
 
@@ -76,6 +77,8 @@ public final class Hyperlink {
                 title = "LAST";
                 address = "1,-1,LAST";
                 break;
+            case LINK_SLIDENUMBER:
+                break;
             default:
                 title = "";
                 address = "";
@@ -92,6 +95,13 @@ public final class Hyperlink {
         return address;
     }
 
+    public void setAddress(Slide slide) {
+        String href = slide._getSheetNumber() + ","+slide.getSlideNumber()+",Slide " + slide.getSlideNumber();
+        setAddress(href);;
+        setTitle("Slide " + slide.getSlideNumber());
+        setType(Hyperlink.LINK_SLIDENUMBER);
+    }
+
     public void setAddress(String str) {
         address = str;
     }
index 8e3b9d2701f9dbb4ddf84474b800fe141bb23f33..1a4ae896b37c1ceb73ce3192ec248dce82de7b0d 100644 (file)
@@ -401,7 +401,12 @@ public abstract class SimpleShape extends Shape {
                 infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
                 infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
                 break;
-          }
+            case Hyperlink.LINK_SLIDENUMBER:
+                infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+                infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
+                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_SlideNumber);
+                break;
+        }
 
         infoAtom.setHyperlinkID(link.getId());
 
index 3ea5b0159ded8ddb63a7eea205429119e9579484..92245598f6d453fb966e4aa508bab5ed0592001f 100644 (file)
@@ -67,6 +67,13 @@ public class ExHyperlink extends RecordContainer {
                        linkDetailsB.setText(url);
                }
        }
+    public void setLinkURL(String url, int options) {
+        if(linkDetailsB != null) {
+            linkDetailsB.setText(url);
+            linkDetailsB.setOptions(options);
+        }
+    }
+
     public void setLinkTitle(String title) {
         if(linkDetailsA != null) {
             linkDetailsA.setText(title);
index 8061cc817659fd750ba8cd051790a7a4f0875bc5..4561f8e4d3a12ff839f38ba33d33da00f48ae84a 100644 (file)
@@ -1062,7 +1062,11 @@ public final class SlideShow {
                ExHyperlink ctrl = new ExHyperlink();
                ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
                obj.setNumber(objectId);
-               ctrl.setLinkURL(link.getAddress());
+        if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
+            ctrl.setLinkURL(link.getAddress(), 0x30);
+        } else {
+            ctrl.setLinkURL(link.getAddress());
+        }
                ctrl.setLinkTitle(link.getTitle());
                lst.addChildAfter(ctrl, objAtom);
                link.setId(objectId);