View Javadoc

1   package org.catacomb.druid.gui.base;
2   
3   import org.catacomb.druid.gui.edit.DruButton;
4   import org.catacomb.druid.swing.DBorderLayout;
5   import org.catacomb.druid.swing.DHTMLPane;
6   import org.catacomb.druid.swing.DScrollPane;
7   import org.catacomb.interlish.structure.Page;
8   import org.catacomb.interlish.structure.PageDisplay;
9   import org.catacomb.interlish.structure.PageSupplier;
10  import org.catacomb.interlish.util.JUtil;
11  import org.catacomb.xdoc.HTMLPage;
12  import org.catacomb.xdoc.XdocBase;
13  
14  
15  import java.awt.Color;
16  import java.awt.Dimension;
17  import java.awt.Rectangle;
18  
19  
20  public class DruBrowserPanel extends DruPanel implements PageDisplay {
21      static final long serialVersionUID = 1001;
22  
23      DScrollPane dsp;
24  
25      String htmlTemplate;
26  
27      DHTMLPane htmlPane;
28      DruFlowPanel dlfp;
29  
30      DruButton bprevious;
31      DruButton bnext;
32  
33  
34  
35      public DruBrowserPanel() {
36          init();
37  
38          HTMLPage hpage = new HTMLPage();
39          hpage.loadDefault();
40  
41          showPage(hpage);
42      }
43  
44  
45      public DruBrowserPanel(String s) {
46          init();
47  
48          HTMLPage hpage = new HTMLPage();
49          if (s != null && s.length() > 3) {
50              hpage.wrapText(s);
51          } else {
52              hpage.loadDefault();
53          }
54  
55          showPage(hpage);
56      }
57  
58  
59      public DruBrowserPanel(HTMLPage hpage) {
60          init();
61          showPage(hpage);
62      }
63  
64  
65      public void init() {
66          setBorderLayout(0, 0);
67  
68          DruActionRelay relay = new DruActionRelay(this);
69  
70          dsp = new DScrollPane();
71          dsp.setVerticalScrollBarAlways();
72  
73  
74          addDComponent(dsp,  DBorderLayout.CENTER);
75  
76  
77          dlfp = new DruFlowPanel();
78  
79          bprevious = new DruButton("back");
80          bprevious.setActionRelay(relay);
81  
82          bnext = new DruButton("next");
83          bnext.setActionRelay(relay);
84  
85          dlfp.addPanel(bprevious);
86          dlfp.addPanel(bnext);
87  
88          addPanel(dlfp, DBorderLayout.NORTH);
89  
90  
91          htmlPane = new DHTMLPane();
92          htmlPane.setEditable(false);
93          htmlPane.setDefaultStyleSheet();
94  
95          dsp.setViewportView(htmlPane);
96      }
97  
98  
99  
100     // EXTEND need separate handler class to receive requests and deliver pages; Should register
101     // as sucn with htnlPane.
102     public void setPageSupplier(PageSupplier ps) {
103 
104         DruLinkHandler linkHandler = new DruLinkHandler(ps, this);
105 
106         htmlPane.setHyperlinkHandler(linkHandler);
107     }
108 
109 
110 
111     public void showBottom() {
112         dsp.scrollToBottom();
113     }
114 
115 
116     public void showPage(Page page) {
117         htmlPane.showPage(page);
118     }
119 
120 
121 
122     public String getHTMLTemplate() {
123         if (htmlTemplate == null) {
124             htmlTemplate = JUtil.getRelativeResource(new XdocBase(), "InfoHTMLTemplate.txt");
125         }
126         return htmlTemplate;
127     }
128 
129 
130 
131     public void setBg(Color c) {
132         dlfp.setBg(c);
133         htmlPane.setBackground(c);
134         super.setBg(c);
135     }
136 
137 
138 
139     public void labelAction(String s,  boolean b) {
140 
141     }
142 
143 
144 
145 
146 
147 
148     public Dimension getPreferredScrollableViewportSize() {
149         return getPreferredSize();
150     }
151 
152 
153     public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
154         return 10;
155     }
156 
157     public boolean getScrollableTracksViewportHeight() {
158         return false;
159     }
160 
161     public boolean getScrollableTracksViewportWidth() {
162         return true;
163     }
164 
165     public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
166         return 10;
167     }
168 
169 
170 
171 }