1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Add decorations

This commit is contained in:
Marc Khouzam 2012-02-27 11:08:22 -05:00
parent 820844d7c2
commit b00e6396b8
4 changed files with 63 additions and 10 deletions

View file

@ -19,7 +19,9 @@ class Messages extends NLS {
public static String ProblemCountVisualizer_Name; public static String ProblemCountVisualizer_Name;
public static String ProblemCountVisualizer_DisplayName; public static String ProblemCountVisualizer_DisplayName;
public static String ProblemCountVisualizer_Description; public static String ProblemCountVisualizer_Description;
public static String ProblemCountVisualizer_Errors;
public static String ProblemCountVisualizer_Warnings;
public static String ProblemCountVisualizer_Infos;
static { static {
// initialize resource bundle // initialize resource bundle

View file

@ -10,5 +10,8 @@
############################################################################### ###############################################################################
ProblemCountVisualizer_Name=ProblemCounter ProblemCountVisualizer_Name=ProblemCounter
ProblemCountVisualizer_DisplayName=Problem Count Visualizer ProblemCountVisualizer_DisplayName=Problem Count
ProblemCountVisualizer_Description=Visualizer displaying the count of errors/warnings/info ProblemCountVisualizer_Description=Visualizer displaying the count of errors/warnings/info
ProblemCountVisualizer_Errors=Errors:
ProblemCountVisualizer_Warnings=Warnings:
ProblemCountVisualizer_Infos=Infos:

View file

@ -14,6 +14,7 @@ import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvas;
import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvasVisualizer; import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvasVisualizer;
import org.eclipse.cdt.visualizer.ui.canvas.GraphicObject; import org.eclipse.cdt.visualizer.ui.canvas.GraphicObject;
import org.eclipse.cdt.visualizer.ui.util.Colors; import org.eclipse.cdt.visualizer.ui.util.Colors;
import org.eclipse.cdt.visualizer.ui.util.GUIUtils;
import org.eclipse.cdt.visualizer.ui.util.SelectionManager; import org.eclipse.cdt.visualizer.ui.util.SelectionManager;
import org.eclipse.cdt.visualizer.ui.util.SelectionUtils; import org.eclipse.cdt.visualizer.ui.util.SelectionUtils;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
@ -52,11 +53,13 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
*/ */
private class BarGraphicObject extends GraphicObject { private class BarGraphicObject extends GraphicObject {
private boolean m_outline; private boolean m_outline;
private String m_label;
public BarGraphicObject(Color color, int x, int y, int w, int h, boolean outline) { public BarGraphicObject(int severity, int x, int y, int w, int h, boolean outline) {
super(x, y, w, h); super(x, y, w, h);
m_outline = outline; m_outline = outline;
Color color = getColor(severity);
if (m_outline) { if (m_outline) {
setForeground(color); setForeground(color);
} else { } else {
@ -64,6 +67,10 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
} }
} }
public void setLabel(String label) {
m_label = label;
}
@Override @Override
public void paintContent(GC gc) { public void paintContent(GC gc) {
if (m_outline) { if (m_outline) {
@ -72,6 +79,42 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
gc.fillRectangle(m_bounds); gc.fillRectangle(m_bounds);
} }
} }
@Override
public boolean hasDecorations() {
// Only the outline bar has a label decoration.
// We muse the the outline bar and not the inside one because
// the inside bar may be too small
return m_outline;
}
/** Invoked to allow element to paint decorations on top of anything drawn on it */
@Override
public void paintDecorations(GC gc) {
if (m_bounds.height > 20) {
gc.setForeground(Colors.BLACK);
int text_indent = 6;
int tx = m_bounds.x + m_bounds.width - text_indent;
int ty = m_bounds.y + m_bounds.height - text_indent;
GUIUtils.drawTextAligned(gc, m_label, tx, ty, false, false);
}
}
private Color getColor(int severity) {
switch (severity) {
case IMarker.SEVERITY_ERROR:
if (m_outline) return ERROR_OUTLINE_COLOR;
return ERROR_INSIDE_COLOR;
case IMarker.SEVERITY_WARNING:
if (m_outline) return WARNING_OUTLINE_COLOR;
return WARNING_INSIDE_COLOR;
case IMarker.SEVERITY_INFO:
if (m_outline) return INFO_OUTLINE_COLOR;
return INFO_INSIDE_COLOR;
}
return Colors.ORANGE;
}
} }
private class ResizableGraphicCanvas extends GraphicCanvas { private class ResizableGraphicCanvas extends GraphicCanvas {
@ -178,13 +221,16 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
if (outline) { if (outline) {
// The bar outlines take the entire width of the view // The bar outlines take the entire width of the view
bars[0] = new BarGraphicObject(ERROR_OUTLINE_COLOR, x, y, maxWidth, height, outline); bars[0] = new BarGraphicObject(IMarker.SEVERITY_ERROR, x, y, maxWidth, height, outline);
bars[0].setLabel(Messages.ProblemCountVisualizer_Errors + m_markerCount[IMarker.SEVERITY_ERROR]);
y = y + height + spacing; y = y + height + spacing;
bars[1] = new BarGraphicObject(WARNING_OUTLINE_COLOR, x, y, maxWidth, height, outline); bars[1] = new BarGraphicObject(IMarker.SEVERITY_WARNING, x, y, maxWidth, height, outline);
bars[1].setLabel(Messages.ProblemCountVisualizer_Warnings + m_markerCount[IMarker.SEVERITY_WARNING]);
y = y + height + spacing; y = y + height + spacing;
bars[2] = new BarGraphicObject(INFO_OUTLINE_COLOR, x, y, maxWidth, height, outline); bars[2] = new BarGraphicObject(IMarker.SEVERITY_INFO, x, y, maxWidth, height, outline);
bars[2].setLabel(Messages.ProblemCountVisualizer_Infos + m_markerCount[IMarker.SEVERITY_INFO]);
} else { } else {
// The inside of the bars use a proportional width with the maximum width and // The inside of the bars use a proportional width with the maximum width and
@ -196,15 +242,15 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
if (maxCount == 0) maxCount = 1; // Set to anything but 0. It will be multiplied by 0 and not matter. if (maxCount == 0) maxCount = 1; // Set to anything but 0. It will be multiplied by 0 and not matter.
int width = maxWidth * m_markerCount[IMarker.SEVERITY_ERROR] / maxCount; int width = maxWidth * m_markerCount[IMarker.SEVERITY_ERROR] / maxCount;
bars[0] = new BarGraphicObject(ERROR_INSIDE_COLOR, x, y, width, height, outline); bars[0] = new BarGraphicObject(IMarker.SEVERITY_ERROR, x, y, width, height, outline);
y = y + height + spacing; y = y + height + spacing;
width = maxWidth * m_markerCount[IMarker.SEVERITY_WARNING] / maxCount; width = maxWidth * m_markerCount[IMarker.SEVERITY_WARNING] / maxCount;
bars[1] = new BarGraphicObject(WARNING_INSIDE_COLOR, x, y, width, height, outline); bars[1] = new BarGraphicObject(IMarker.SEVERITY_WARNING, x, y, width, height, outline);
y = y + height + spacing; y = y + height + spacing;
width = maxWidth * m_markerCount[IMarker.SEVERITY_INFO] / maxCount; width = maxWidth * m_markerCount[IMarker.SEVERITY_INFO] / maxCount;
bars[2] = new BarGraphicObject(INFO_INSIDE_COLOR, x, y, width, height, outline); bars[2] = new BarGraphicObject(IMarker.SEVERITY_INFO, x, y, width, height, outline);
} }
return bars; return bars;

View file

@ -34,6 +34,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/ */
@Override
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
super.start(context); super.start(context);
plugin = this; plugin = this;
@ -43,6 +44,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/ */
@Override
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {
plugin = null; plugin = null;
super.stop(context); super.stop(context);