support links to slides in HSLF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1401642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04b9f9dff9
commit
a88447b0e4
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user