/*
* This file is part of Mobile GPS Logger.
*
* Mobile GPS Logger is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Mobile GPS Logger is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License v3 for more details.
*
* You should have received a copy of the GNU General Public License v3
* along with Mobile GPS Logger. If not, see <http://www.gnu.org/licenses/>.
*/
package cx.ath.skyflyer.chart;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
*
* @author Ahti Legonkov
*/
public class Legend {
public Legend(Rectangle chartRect) {
this.chartRect = chartRect;
}
public void draw(Graphics g) {
int top = chartRect.top;
Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
g.setFont(font);
final int lineHeight = font.getHeight() + 2;
for (int i = 0; i < names.size(); ++i) {
String name = (String)names.elementAt(i);
Color color = (Color)colors.elementAt(i);
g.setColor(Color.BLACK.intValue());
g.drawString(name, chartRect.right-10, top, Graphics.RIGHT | Graphics.TOP);
g.setColor(color.intValue());
g.drawLine(chartRect.right, top+lineHeight/2, chartRect.right-8, top+lineHeight/2);
top += lineHeight;
}
}
public void clear() {
names.removeAllElements();
colors.removeAllElements();
}
public void addItem(String name, Color color) {
names.addElement(name);
colors.addElement(color);
}
private final Rectangle chartRect;
private final Vector names = new Vector();
private final Vector colors = new Vector();
}
|