import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
*/
public abstract class PackageListPage extends PageTemplate {
- private Text mDescriptionText;
+ private StyledText mDescriptionText;
protected Tree tree;
private Label lblSelectPackage;
protected Label lblRequiredSize;
tree.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent arg0) {
- mDescriptionText.setText("Position your mouse pointer over an item to view its description.");
+ setComponentDescriptionText("Position your mouse pointer over an item to view its description.");
mDescriptionText.setForeground(new Color(null, 96, 96, 96));
}
});
String description = viewController.getDescription(packageName);
if (!description.isEmpty()) {
- mDescriptionText.setText(description);
+ setComponentDescriptionText(description);
} else {
- mDescriptionText.setText("\"" + packageName + "\" category.");
+ setComponentDescriptionText("\"" + packageName + "\" category.");
}
} else {
- mDescriptionText.setText("Position your mouse pointer over an item to view its description.");
+ setComponentDescriptionText("Position your mouse pointer over an item to view its description.");
mDescriptionText.setForeground(new Color(null, 96, 96, 96));
}
}
}
private void setDescriptionText(Composite composite) {
- mDescriptionText = new Text(
+ mDescriptionText = new StyledText(
composite,
SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.CANCEL | SWT.MULTI);
mDescriptionText.setForeground(new Color(null, 96, 96, 96));
- mDescriptionText.setText("Position your mouse pointer over an item to view its description.");
+ setComponentDescriptionText("Position your mouse pointer over an item to view its description.");
mDescriptionText.setEditable(false);
mDescriptionText.setEnabled(false);
mDescriptionText.setBounds(0, 287, 447, 45);
}
}
+
+ private void setComponentDescriptionText(String text) {
+ StringBuffer newText = new StringBuffer();
+ ArrayList<StyleRange> styles = new ArrayList<StyleRange>();
+ StyleRange currentStyle = null;
+ int styleCount = 0;
+
+ for (int i = 0; i < text.length(); i++) {
+ char c = text.charAt(i);
+ if (c == '<' && text.indexOf('>', i) != -1) {
+ int startIdx = i;
+ int endIdx = text.indexOf('>', startIdx);
+
+ String tag = text.substring(startIdx, endIdx + 1);
+ if (tag.equals("<b>")) {
+ if (currentStyle == null) {
+ currentStyle = new StyleRange();
+ currentStyle.start = newText.length();
+ }
+ currentStyle.fontStyle |= SWT.BOLD;
+
+ styleCount++;
+ i += (tag.length() - 1);
+ } else if (tag.equals("</b>") && currentStyle != null) {
+ styleCount--;
+
+ if (styleCount == 0) {
+ currentStyle.length = newText.length()
+ - currentStyle.start;
+ styles.add(currentStyle);
+ currentStyle = null;
+ }
+
+ i += (tag.length() - 1);
+ } else if (tag.matches("<font color=\"#[0-9a-fA-F]+\">")) {
+ int hexStartIdx = tag.indexOf('#');
+ int r = -1, g = -1, b = -1;
+ try {
+ r = Integer
+ .parseInt(tag.substring(hexStartIdx + 1,
+ hexStartIdx + 3), 16);
+ g = Integer
+ .parseInt(tag.substring(hexStartIdx + 3,
+ hexStartIdx + 5), 16);
+ b = Integer
+ .parseInt(tag.substring(hexStartIdx + 5,
+ hexStartIdx + 7), 16);
+ } catch (IndexOutOfBoundsException e) {
+ r = -1;
+ g = -1;
+ b = -1;
+ } catch (NumberFormatException e) {
+ r = -1;
+ g = -1;
+ b = -1;
+ }
+
+ if (currentStyle == null) {
+ currentStyle = new StyleRange();
+ currentStyle.start = newText.length();
+ }
+ if (r != -1 && g != -1 && b != -1) {
+ currentStyle.foreground = new Color(null, r, g, b);
+ }
+
+ styleCount++;
+ i += (tag.length() - 1);
+ } else if (tag.equals("</font>") && currentStyle != null) {
+ styleCount--;
+
+ if (styleCount == 0) {
+ currentStyle.length = newText.length()
+ - currentStyle.start;
+ styles.add(currentStyle);
+ currentStyle = null;
+ }
+
+ i += (tag.length() - 1);
+ } else {
+ newText.append(c);
+ }
+ } else {
+ newText.append(c);
+ }
+ }
+ mDescriptionText.setText(newText.toString());
+ mDescriptionText.setStyleRanges(styles.toArray(new StyleRange[0]));
+ }
protected void setNextBtnEnabledAboutCheckedPackageCount() {
if (getCheckedPackageNumber() > 0) {