1 11 package org.eclipse.ui.forms.widgets; 12 import java.io.InputStream ; 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.Color; 15 import org.eclipse.swt.widgets.*; 16 39 public class ScrolledFormText extends SharedScrolledComposite { 40 private FormText content; 41 private String text; 42 51 public ScrolledFormText(Composite parent, boolean createFormText) { 52 this(parent, SWT.V_SCROLL | SWT.H_SCROLL, createFormText); 53 } 54 65 public ScrolledFormText(Composite parent, int style, boolean createFormText) { 66 super(parent, style); 67 if (createFormText) 68 setFormText(new FormText(this, SWT.NULL)); 69 } 70 79 public void setFormText(FormText formText) { 80 this.content = formText; 81 super.setContent(content); 82 content.setMenu(getMenu()); 83 if (text != null) 84 loadText(text); 85 } 86 92 public void setForeground(Color fg) { 93 super.setForeground(fg); 94 if (content != null) 95 content.setForeground(fg); 96 } 97 103 public void setBackground(Color bg) { 104 super.setBackground(bg); 105 if (content != null) 106 content.setBackground(bg); 107 } 108 115 public final void setContent(Control c) { 116 } 117 124 public void setText(String text) { 125 this.text = text; 126 loadText(text); 127 reflow(true); 128 } 129 140 public void setContents(InputStream is) { 141 loadContents(is); 142 } 143 148 public FormText getFormText() { 149 return content; 150 } 151 private void loadText(String text) { 152 if (content != null) { 153 String markup = text; 154 if (!markup.startsWith("<form>")) markup = "<form>" + text + "</form>"; content.setText(markup, true, false); 157 } 158 } 159 private void loadContents(InputStream is) { 160 if (content != null) { 161 content.setContents(is, false); 162 } 163 } 164 } 165 | Popular Tags |