1 package com.generalrobotix.ui.view.graph;
3 import java.awt.Dimension;
4 import java.util.ArrayList;
5 import java.util.ListIterator;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.PaintEvent;
9 import org.eclipse.swt.events.PaintListener;
10 import org.eclipse.swt.graphics.Color;
11 import org.eclipse.swt.graphics.Font;
12 import org.eclipse.swt.graphics.FontMetrics;
13 import org.eclipse.swt.widgets.Canvas;
14 import org.eclipse.swt.widgets.Composite;
22 public class LegendPanel extends Canvas implements PaintListener{
28 private static final int GAP_X = 10;
29 private static final int GAP_Y = 5;
55 super(parent, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
57 backColor_ = backColor;
58 labelColor_ = labelColor;
59 size_ =
new Dimension(0, 0);
61 legendList_ =
new ArrayList<LegendInfo>();
63 addPaintListener(
this);
74 legendList_.add(legend);
86 int ind = legendList_.indexOf(legend);
87 legendList_.remove(ind);
131 int width = getSize().x;
133 e.gc.setBackground(backColor_);
134 e.gc.fillRectangle(0, 0, width, height);
137 FontMetrics metrics = e.gc.getFontMetrics();
138 int yofs = (
int)(metrics.getHeight() / 3.5);
139 int ygap = metrics.getHeight() +
GAP_Y;
140 ListIterator<LegendInfo> li = legendList_.listIterator();
142 while (li.hasNext()) {
144 e.gc.setForeground(legend.
color);
146 e.gc.drawLine(MARGIN_X, ypos, MARGIN_X + LEN_LINE, ypos);
148 e.gc.setForeground(labelColor_);
151 MARGIN_X + LEN_LINE + GAP_X,
177 ListIterator<LegendInfo> li = legendList_.listIterator();
180 while (li.hasNext()) {
192 size_.width = MARGIN_X + LEN_LINE + GAP_X + max +
MARGIN_X;
193 size_.height = ysize;
void paintControl(PaintEvent e)
static final int LEN_LINE
Dimension getMinimalSize()
void addLegend(LegendInfo legend)
png_infop png_uint_32 * width
void setBackColor(Color color)
png_infop png_uint_32 png_uint_32 * height
LegendPanel(Composite parent, Font font, Color backColor, Color labelColor)
void removeLegend(LegendInfo legend)
ArrayList< LegendInfo > legendList_
void setLabelColor(Color color)
static final int MARGIN_Y
static final int MARGIN_X
static int max(int a, int b)