]> git.gag.com Git - debian/openrocket/blob - src/net/sf/openrocket/gui/help/tours/SlideShowComponent.java
introduction tour
[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 int WIDTH = 600;
23         private final int HEIGHT_IMAGE = 400;
24         private final int HEIGHT_TEXT = 100;
25         
26         private final ImageDisplayComponent imageDisplay;
27         private final JEditorPane textPane;
28         
29         
30         public SlideShowComponent() {
31                 super(VERTICAL_SPLIT);
32                 
33                 imageDisplay = new ImageDisplayComponent();
34                 imageDisplay.setPreferredSize(new Dimension(WIDTH, HEIGHT_IMAGE));
35                 this.setLeftComponent(imageDisplay);
36                 
37                 textPane = new JEditorPane("text/html", "");
38                 textPane.setEditable(false);
39                 textPane.setPreferredSize(new Dimension(WIDTH, HEIGHT_TEXT));
40                 
41                 JScrollPane scrollPanel = new JScrollPane(textPane);
42                 this.setRightComponent(scrollPanel);
43                 
44                 this.setResizeWeight(((double) HEIGHT_IMAGE) / (HEIGHT_IMAGE + HEIGHT_TEXT));
45         }
46         
47         
48         
49         public void setSlide(Slide slide) {
50                 this.imageDisplay.setImage(slide.getImage());
51                 this.textPane.setText(slide.getText());
52         }
53         
54         
55         /**
56          * Replace the current HTML style sheet with a new style sheet.
57          */
58         public void setStyleSheet(StyleSheet newStyleSheet) {
59                 HTMLDocument doc = (HTMLDocument) textPane.getDocument();
60                 StyleSheet base = doc.getStyleSheet();
61                 StyleSheet[] linked = base.getStyleSheets();
62                 if (linked != null) {
63                         for (StyleSheet ss : linked) {
64                                 base.removeStyleSheet(ss);
65                         }
66                 }
67                 
68                 base.addStyleSheet(newStyleSheet);
69         }
70         
71         
72         public void addHyperlinkListener(HyperlinkListener listener) {
73                 textPane.addHyperlinkListener(listener);
74         }
75         
76 }