MiniCanvasRectangle.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.misc;
00002
00003 import java.util.EnumSet;
00004 import org.eclipse.swt.SWT;
00005 import org.eclipse.swt.graphics.Color;
00006 import org.eclipse.swt.graphics.GC;
00007 import org.eclipse.swt.graphics.Image;
00008 import org.eclipse.swt.graphics.Rectangle;
00009 import org.eclipse.swt.widgets.Composite;
00010 import org.eclipse.swt.widgets.Control;
00011 import org.eclipse.swt.widgets.Display;
00012 import org.eclipse.swt.widgets.Label;
00013
00014 import edu.rice.cs.hpc.traceviewer.data.util.Debugger;
00015
00016 public class MiniCanvasRectangle {
00017 final EnumSet<SampleHiddenReason> reasons;
00018 final boolean areAllSamplesHidden;
00019 final Rectangle rect;
00020 Image img;
00021
00022 public MiniCanvasRectangle (SampleHiddenReason hiddenReason, boolean _areAllSamplesHidden, Rectangle _rect) {
00023 this(EnumSet.of(hiddenReason), _areAllSamplesHidden, _rect);
00024 }
00025
00026
00027 public MiniCanvasRectangle (EnumSet<SampleHiddenReason> hiddenReasons, boolean _areAllSamplesHidden, Rectangle _rect) {
00028 reasons = hiddenReasons;
00029 areAllSamplesHidden = _areAllSamplesHidden;
00030 rect = _rect;
00031 createLabel();
00032 }
00033
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 private void createLabel() {
00051
00052
00053
00054 if (rect.width > 0 && rect.height>0) {
00055 img = new Image(Display.getCurrent(), rect.width, rect.height);
00056 GC gc = new GC(img);
00057 gc.setForeground(getColor());
00058
00059
00060 gc.drawRectangle(new Rectangle(0, 0, rect.width, rect.height));
00061 gc.dispose();
00062 }
00063 else {
00064 Debugger.printDebug(1, "Unable to create label with negative area: " + rect);
00065 }
00066 }
00067
00068 private Color getColor() {
00069
00070 int r = 0, g = 0, b = 0;
00071 for (SampleHiddenReason reason : reasons) {
00072 r += reason.color.getRed();
00073 g += reason.color.getGreen();
00074 b += reason.color.getBlue();
00075 }
00076 r /= reasons.size();
00077 g /= reasons.size();
00078 b /= reasons.size();
00079 return new Color(Display.getCurrent(), r, g, b);
00080 }
00081
00084 public Control getControl(Composite parent) {
00085 Label label = new Label(parent, SWT.NONE);
00086 label.setImage(img);
00087 label.setToolTipText(getAsMessage());
00088 label.setLocation(rect.x, rect.y);
00089 label.pack();
00090 return label;
00091 }
00092
00093 private String getAsMessage() {
00094 if ((reasons.size() == 0) ||
00095 ((reasons.size()==1) && (reasons.contains(SampleHiddenReason.NONE)))) {
00096 return "All samples from this region are displayed.";
00097 }
00098 StringBuilder sb = new StringBuilder();
00099 if (areAllSamplesHidden)
00100 sb.append("All");
00101 else
00102 sb.append("Some");
00103 sb.append(" samples from this region ");
00104 if (areAllSamplesHidden)
00105 sb.append("are");
00106 else
00107 sb.append("may be");
00108 sb.append(" hidden");
00109
00110 int i = 0;
00111 for (SampleHiddenReason reason : reasons) {
00112 switch (reason) {
00113 case OUTSIDE_BOUNDS:
00114 sb.append(" because they are outside the currently selected time "
00115 + "and process bounds");
00116 break;
00117 case FILTERED:
00118 sb.append(" because they do not match the current filter");
00119 break;
00120 case VERTICAL_RESOLUTION:
00121 sb.append(" because the current vertical resolution is too small "
00122 + "to show all selected traces");
00123 }
00124 if (reasons.size() > 1){
00125 if (i < reasons.size() - 2)
00126 sb.append(",");
00127 else
00128 sb.append(", and");
00129 }
00130 }
00131
00132 sb.append(".");
00133 return sb.toString();
00134 }
00135
00136 public void dispose() {
00137 if (img != null)
00138 img.dispose();
00139 }
00140 }
00141
00142 enum SampleHiddenReason {
00143 NONE (SWT.COLOR_WHITE),
00144 OUTSIDE_BOUNDS (SWT.COLOR_DARK_GRAY),
00145 FILTERED (SWT.COLOR_DARK_BLUE),
00146 VERTICAL_RESOLUTION (new Color(Display.getCurrent(), 170, 170, 170));
00147 final Color color;
00148 private SampleHiddenReason(Color _color) {
00149 color = _color;
00150 }
00151 private SampleHiddenReason(int _color) {
00152 color = Display.getCurrent().getSystemColor(_color);
00153 }
00154 }