1 11 12 13 package org.eclipse.ui.texteditor; 14 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.custom.ScrolledComposite; 18 import org.eclipse.swt.events.DisposeEvent; 19 import org.eclipse.swt.events.DisposeListener; 20 import org.eclipse.swt.graphics.Color; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.layout.GridLayout; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Display; 26 import org.eclipse.swt.widgets.Label; 27 28 import org.eclipse.jface.resource.JFaceResources; 29 import org.eclipse.jface.util.IPropertyChangeListener; 30 import org.eclipse.jface.util.PropertyChangeEvent; 31 32 33 40 public class InfoForm { 41 42 43 private ScrolledComposite fScrolledComposite; 44 45 private Color fBackgroundColor; 46 47 private Color fForegroundColor; 48 49 private Color fSeparatorColor; 50 51 private Label fHeader; 52 53 private Label fBanner; 54 55 private Label fText; 56 57 private IPropertyChangeListener fPropertyChangeListener; 58 59 63 public InfoForm(Composite parent) { 64 65 Display display= parent.getDisplay(); 66 fBackgroundColor= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); 67 fForegroundColor= display.getSystemColor(SWT.COLOR_LIST_FOREGROUND); 68 fSeparatorColor= new Color(display, 152, 170, 203); 69 70 fPropertyChangeListener= new IPropertyChangeListener() { 71 public void propertyChange(PropertyChangeEvent event) { 72 handlePropertyChange(event); 73 } 74 }; 75 JFaceResources.getFontRegistry().addListener(fPropertyChangeListener); 76 77 fScrolledComposite= new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); 78 fScrolledComposite.setAlwaysShowScrollBars(false); 79 fScrolledComposite.setExpandHorizontal(true); 80 fScrolledComposite.setExpandVertical(true); 81 fScrolledComposite.addDisposeListener(new DisposeListener() { 82 public void widgetDisposed(DisposeEvent e) { 83 JFaceResources.getFontRegistry().removeListener(fPropertyChangeListener); 84 fScrolledComposite= null; 85 fSeparatorColor.dispose(); 86 fSeparatorColor= null; 87 fHeader= null; 88 fBanner= null; 89 fText= null; 90 } 91 }); 92 93 Composite composite= createComposite(fScrolledComposite); 94 composite.setLayout(new GridLayout()); 95 96 fHeader= createHeader(composite, null); 97 createLabel(composite, null); 98 createLabel(composite, null); 99 100 fBanner= createBanner(composite, null); 101 102 Composite separator= createCompositeSeparator(composite); 103 GridData data= new GridData(GridData.FILL_HORIZONTAL); 104 data.heightHint= 2; 105 separator.setLayoutData(data); 106 107 fText= createLabel(composite, null); 108 createLabel(composite, null); 109 110 fScrolledComposite.setContent(composite); 111 fScrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 112 113 createActionControls(composite); 114 } 115 116 120 protected void createActionControls(Composite parent) { 121 } 122 123 127 public Control getControl() { 128 return fScrolledComposite; 129 } 130 131 135 public void setHeaderText(String header) { 136 fHeader.setText(header); 137 } 138 139 143 public void setBannerText(String banner) { 144 fBanner.setText(banner); 145 } 146 147 151 public void setInfo(String info) { 152 fText.setText(info); 153 } 154 155 158 protected void handlePropertyChange(PropertyChangeEvent event) { 159 160 if (fHeader != null) 161 fHeader.setFont(JFaceResources.getHeaderFont()); 162 163 if (fBanner != null) 164 fBanner.setFont(JFaceResources.getBannerFont()); 165 166 Control control= fScrolledComposite.getContent(); 167 fScrolledComposite.setMinSize(control.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 168 fScrolledComposite.setContent(control); 169 170 fScrolledComposite.layout(true); 171 fScrolledComposite.redraw(); 172 } 173 174 177 private Composite createComposite(Composite parent) { 178 Composite composite = new Composite(parent, SWT.NONE); 179 composite.setBackground(fBackgroundColor); 180 return composite; 181 } 182 183 186 private Composite createCompositeSeparator(Composite parent) { 187 Composite composite = new Composite(parent, SWT.NONE); 188 composite.setBackground(fSeparatorColor); 189 return composite; 190 } 191 192 195 private Label createLabel(Composite parent, String text) { 196 Label label = new Label(parent, SWT.NONE); 197 GridData data= new GridData(GridData.FILL_HORIZONTAL); 198 label.setLayoutData(data); 199 200 if (text != null) 201 label.setText(text); 202 label.setBackground(fBackgroundColor); 203 label.setForeground(fForegroundColor); 204 return label; 205 } 206 207 210 private Label createHeader(Composite parent, String text) { 211 Label label = new Label(parent, SWT.NONE); 212 GridData data= new GridData(GridData.FILL_HORIZONTAL); 213 label.setLayoutData(data); 214 215 if (text != null) 216 label.setText(text); 217 label.setBackground(fBackgroundColor); 218 label.setForeground(fForegroundColor); 219 label.setFont(JFaceResources.getHeaderFont()); 220 return label; 221 } 222 223 226 private Label createBanner(Composite parent, String text) { 227 Label label = new Label(parent, SWT.NONE); 228 if (text != null) 229 label.setText(text); 230 label.setBackground(fBackgroundColor); 231 label.setForeground(fForegroundColor); 232 label.setFont(JFaceResources.getBannerFont()); 233 return label; 234 } 235 } 236 | Popular Tags |