mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Add decorations
This commit is contained in:
parent
820844d7c2
commit
b00e6396b8
4 changed files with 63 additions and 10 deletions
|
@ -19,7 +19,9 @@ class Messages extends NLS {
|
|||
public static String ProblemCountVisualizer_Name;
|
||||
public static String ProblemCountVisualizer_DisplayName;
|
||||
public static String ProblemCountVisualizer_Description;
|
||||
|
||||
public static String ProblemCountVisualizer_Errors;
|
||||
public static String ProblemCountVisualizer_Warnings;
|
||||
public static String ProblemCountVisualizer_Infos;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
|
|
|
@ -10,5 +10,8 @@
|
|||
###############################################################################
|
||||
|
||||
ProblemCountVisualizer_Name=ProblemCounter
|
||||
ProblemCountVisualizer_DisplayName=Problem Count Visualizer
|
||||
ProblemCountVisualizer_DisplayName=Problem Count
|
||||
ProblemCountVisualizer_Description=Visualizer displaying the count of errors/warnings/info
|
||||
ProblemCountVisualizer_Errors=Errors:
|
||||
ProblemCountVisualizer_Warnings=Warnings:
|
||||
ProblemCountVisualizer_Infos=Infos:
|
||||
|
|
|
@ -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.GraphicObject;
|
||||
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.SelectionUtils;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
|
@ -52,11 +53,13 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
*/
|
||||
private class BarGraphicObject extends GraphicObject {
|
||||
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);
|
||||
m_outline = outline;
|
||||
|
||||
Color color = getColor(severity);
|
||||
if (m_outline) {
|
||||
setForeground(color);
|
||||
} else {
|
||||
|
@ -64,6 +67,10 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
}
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
m_label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintContent(GC gc) {
|
||||
if (m_outline) {
|
||||
|
@ -72,6 +79,42 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
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 {
|
||||
|
@ -178,13 +221,16 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
|
|||
|
||||
if (outline) {
|
||||
// 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;
|
||||
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;
|
||||
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 {
|
||||
// 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.
|
||||
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
|
|
|
@ -34,6 +34,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
|
|||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
|
@ -43,6 +44,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
|
|||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
|
|
Loading…
Add table
Reference in a new issue