guided tours implementation
[debian/openrocket] / src / net / sf / openrocket / gui / help / tours / SlideShowComponent.java
1 package net.sf.openrocket.gui.help.tours;
2
3 import java.awt.Dimension;
4
5 import javax.swing.JEditorPane;
6 import javax.swing.JScrollPane;
7 import javax.swing.JSplitPane;
8 import javax.swing.event.HyperlinkListener;
9 import javax.swing.text.html.HTMLDocument;
10 import javax.swing.text.html.StyleSheet;
11
12 import net.sf.openrocket.gui.components.ImageDisplayComponent;
13
14 /**
15  * Component that displays a single slide, with the image on top and
16  * text below it.  The portions are resizeable.
17  * 
18  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
19  */
20 public class SlideShowComponent extends JSplitPane {
21         
22         private final ImageDisplayComponent imageDisplay;
23         private final JEditorPane textPane;
24         
25         
26         public SlideShowComponent() {
27                 super(VERTICAL_SPLIT);
28                 
29                 imageDisplay = new ImageDisplayComponent();
30                 imageDisplay.setPreferredSize(new Dimension(600, 350));
31                 this.setLeftComponent(imageDisplay);
32                 
33                 textPane = new JEditorPane("text/html", "");
34                 textPane.setEditable(false);
35                 textPane.setPreferredSize(new Dimension(600, 100));
36                 
37                 JScrollPane scrollPanel = new JScrollPane(textPane);
38                 this.setRightComponent(scrollPanel);
39                 
40                 this.setResizeWeight(0.7);
41         }
42         
43         
44
45         public void setSlide(Slide slide) {
46                 this.imageDisplay.setImage(slide.getImage());
47                 this.textPane.setText(slide.getText());
48         }
49         
50         
51         /**
52          * Replace the current HTML style sheet with a new style sheet.
53          */
54         public void setStyleSheet(StyleSheet newStyleSheet) {
55                 HTMLDocument doc = (HTMLDocument) textPane.getDocument();
56                 StyleSheet base = doc.getStyleSheet();
57                 StyleSheet[] linked = base.getStyleSheets();
58                 if (linked != null) {
59                         for (StyleSheet ss : linked) {
60                                 base.removeStyleSheet(ss);
61                         }
62                 }
63                 
64                 base.addStyleSheet(newStyleSheet);
65         }
66         
67         
68         public void addHyperlinkListener(HyperlinkListener listener) {
69                 textPane.addHyperlinkListener(listener);
70         }
71         
72 }