1 2 package org.catacomb.druid.gui.base; 3 4 import org.catacomb.druid.swing.DHTMLPane; 5 import org.catacomb.druid.swing.DScrollPane; 6 import org.catacomb.interlish.content.StringValue; 7 import org.catacomb.interlish.structure.*; 8 9 10 import java.awt.Color; 11 import java.awt.Dimension; 12 import java.awt.Rectangle; 13 14 15 public class DruScrollingHTMLPanel extends DruPanel 16 implements TextSettable, PageDisplay, ValueWatcher { 17 static final long serialVersionUID = 1001; 18 19 DHTMLPane dHTMLPane; 20 21 PageSupplier pageSupplier; 22 23 boolean preformat = false; 24 25 StringValue stringValue; 26 27 28 public DruScrollingHTMLPanel() { 29 super(); 30 setSingle(); 31 DScrollPane dsp = new DScrollPane(); 32 dsp.setVerticalScrollBarAlways(); 33 addDComponent(dsp); 34 35 dHTMLPane = new DHTMLPane(); 36 dHTMLPane.setDefaultStyleSheet(); 37 38 dsp.setViewportView(dHTMLPane); 39 } 40 41 42 public void setPreformat(boolean b) { 43 preformat = b; 44 } 45 46 47 public void setStylesheetPath(String s) { 48 dHTMLPane.setStylesheetPath(s); 49 } 50 51 public void setText(String sin) { 52 String s = sin; 53 if (preformat) { 54 s = "<pre>\n" + s + "\n</pre>\n"; 55 } 56 57 setContent(s); 58 } 59 60 61 public void setBg(Color c) { 62 dHTMLPane.setBg(c); 63 super.setBg(c); 64 } 65 66 67 public void setContent(String s) { 68 dHTMLPane.showHTML(s); 69 } 70 71 72 public void setPageSupplier(PageSupplier ps) { 73 pageSupplier = ps; 74 showPage(ps.getPage("/")); 75 } 76 77 78 public void showPage(Page p) { 79 dHTMLPane.showHTML(p.getHTMLText()); 80 } 81 82 public void setStringValue(StringValue sv) { 83 if (stringValue != null) { 84 stringValue.removeValueWatcher(this); 85 } 86 stringValue = sv; 87 if (stringValue == null) { 88 dHTMLPane.showHTML(""); 89 } else { 90 exportStringValueContent(); 91 92 stringValue.addValueWatcher(this); 93 } 94 } 95 96 97 public void valueChangedBy(Value pv, Object src) { 98 exportStringValueContent(); 99 } 100 101 102 private void exportStringValueContent() { 103 String s = ""; 104 if (stringValue != null) { 105 s = stringValue.getString(); 106 } 107 setText(s); 108 } 109 110 111 public Dimension getPreferredScrollableViewportSize() { 112 return getPreferredSize(); 113 } 114 public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { 115 return 10; 116 } 117 118 public boolean getScrollableTracksViewportHeight() { 119 return false; 120 } 121 122 public boolean getScrollableTracksViewportWidth() { 123 return true; 124 } 125 public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { 126 return 10; 127 } 128 129 }