1 11 12 package org.eclipse.jface.window; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.custom.CLabel; 16 import org.eclipse.swt.graphics.Color; 17 import org.eclipse.swt.graphics.Font; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Event; 23 24 30 public class DefaultToolTip extends ToolTip { 31 private String text; 32 33 private Color backgroundColor; 34 35 private Font font; 36 37 private Image backgroundImage; 38 39 private Color foregroundColor; 40 41 private Image image; 42 43 private int style = SWT.SHADOW_NONE; 44 45 50 public DefaultToolTip(Control control) { 51 super(control); 52 } 53 54 64 public DefaultToolTip(Control control, int style, boolean manualActivation) { 65 super(control, style, manualActivation); 66 } 67 68 88 protected Composite createToolTipContentArea(Event event, Composite parent) { 89 Image image = getImage(event); 90 Image bgImage = getBackgroundImage(event); 91 String text = getText(event); 92 Color fgColor = getForegroundColor(event); 93 Color bgColor = getBackgroundColor(event); 94 Font font = getFont(event); 95 96 CLabel label = new CLabel(parent, getStyle(event)); 97 if (text != null) { 98 label.setText(text); 99 } 100 101 if (image != null) { 102 label.setImage(image); 103 } 104 105 if (fgColor != null) { 106 label.setForeground(fgColor); 107 } 108 109 if (bgColor != null) { 110 label.setBackground(bgColor); 111 } 112 113 if (bgImage != null) { 114 label.setBackgroundImage(image); 115 } 116 117 if (font != null) { 118 label.setFont(font); 119 } 120 121 return label; 122 } 123 124 131 protected int getStyle(Event event) { 132 return style; 133 } 134 135 144 protected Image getImage(Event event) { 145 return image; 146 } 147 148 157 protected Color getForegroundColor(Event event) { 158 return (foregroundColor == null) ? event.widget.getDisplay() 159 .getSystemColor(SWT.COLOR_INFO_FOREGROUND) : foregroundColor; 160 } 161 162 171 protected Color getBackgroundColor(Event event) { 172 return (backgroundColor == null) ? event.widget.getDisplay() 173 .getSystemColor(SWT.COLOR_INFO_BACKGROUND) : backgroundColor; 174 } 175 176 185 protected Image getBackgroundImage(Event event) { 186 return backgroundImage; 187 } 188 189 197 protected Font getFont(Event event) { 198 return font; 199 } 200 201 208 protected String getText(Event event) { 209 return text; 210 } 211 212 220 public void setBackgroundColor(Color backgroundColor) { 221 this.backgroundColor = backgroundColor; 222 } 223 224 232 public void setBackgroundImage(Image backgroundImage) { 233 this.backgroundImage = backgroundImage; 234 } 235 236 243 public void setFont(Font font) { 244 this.font = font; 245 } 246 247 255 public void setForegroundColor(Color foregroundColor) { 256 this.foregroundColor = foregroundColor; 257 } 258 259 267 public void setImage(Image image) { 268 this.image = image; 269 } 270 271 277 public void setStyle(int style) { 278 this.style = style; 279 } 280 281 287 public void setText(String text) { 288 this.text = text; 289 } 290 291 } 292 | Popular Tags |