1 11 package org.eclipse.search.internal.ui.util; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.custom.CLabel; 15 import org.eclipse.swt.events.DisposeEvent; 16 import org.eclipse.swt.events.DisposeListener; 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.RGB; 19 import org.eclipse.swt.widgets.Composite; 20 21 26 public class MessageLine extends CLabel { 27 28 private String fMessageText; 29 private String fErrorText; 30 31 private Color fDefaultColor; 32 private RGB fErrorRGB; 33 private Color fErrorColor; 34 35 private static RGB fgErrorRGB= new RGB(200, 0, 0); 36 37 41 public MessageLine(Composite parent) { 42 this(parent, SWT.LEFT); 43 } 44 45 49 public MessageLine(Composite parent, int style) { 50 super(parent, style); 51 fDefaultColor= getForeground(); 52 fErrorRGB= fgErrorRGB; 53 } 54 55 59 public MessageLine(Composite parent, int style, RGB errorRGB) { 60 super(parent, style); 61 fDefaultColor= getForeground(); 62 fErrorRGB= errorRGB; 63 } 64 65 69 public void clearErrorMessage() { 70 setErrorMessage(null); 71 } 72 73 76 public void clearMessage() { 77 setMessage(null); 78 } 79 80 84 public String getErrorMessage() { 85 return fErrorText; 86 } 87 88 92 public String getMessage() { 93 return fMessageText; 94 } 95 96 100 public static void setDefaultErrorColor(RGB color) { 101 fgErrorRGB= color; 102 } 103 104 108 public void setErrorMessage(String message) { 109 fErrorText= message; 110 111 if (message == null) { 112 setMessage(fMessageText); 113 } else { 114 if (fErrorColor == null) { 115 fErrorColor= new Color(getDisplay(), fErrorRGB); 116 addDisposeListener(new DisposeListener() { 117 public void widgetDisposed(DisposeEvent e) { 118 getErrorColor().dispose(); 119 } 120 }); 121 } 122 setForeground(fErrorColor); 123 setText(message); 124 } 125 } 126 127 131 public void setMessage(String message) { 132 fMessageText= message; 133 if (message == null) 134 message= ""; if (fErrorText == null) { 136 setForeground(fDefaultColor); 137 setText(message); 138 } 139 } 140 141 protected Color getErrorColor() { 142 return fErrorColor; 143 } 144 } 145 | Popular Tags |