Go to the documentation of this file.00001 package edu.tum.cs.ias.knowrob.vis.items;
00002 import java.io.BufferedReader;
00003 import java.io.FileReader;
00004 import java.io.IOException;
00005 import java.util.*;
00006
00007 import edu.tum.cs.ias.knowrob.vis.Canvas;
00008 import edu.tum.cs.ias.knowrob.vis.Drawable;
00009
00010 public class Legend implements Drawable {
00011
00012 int legPosX = 0, legPosY = 0;
00013
00014 public Legend(java.io.File labelFile, int x, int y) throws NumberFormatException, IOException {
00015 legPosX = x;
00016 legPosY = y;
00017 loadLabels(labelFile);
00018 }
00019
00020 public Vector<String> stringLeg = new Vector<String>();
00021 public static int[] colors = new int[] {0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff00ffff, 0xffff8800, 0xffff0088, 0xff88ff00, 0xff00ff88, 0xff8800ff, 0xff0088ff};
00022
00023 public void draw(Canvas c) {
00024 int i = 0;
00025 for(String str : stringLeg){
00026 c.fill(colors[i]);
00027 int x = legPosX;
00028 int y = legPosY + 13*i;
00029 c.rect(x, y-6, 6, 6);
00030 c.fill(0xffffffff);
00031 c.text(str, x + 10, y);
00032 i += 1;
00033 }
00034 }
00035
00036 protected void loadLabels(java.io.File ascFile) throws NumberFormatException, IOException{
00037 BufferedReader r = new BufferedReader(new FileReader(ascFile));
00038 String line;
00039 while((line = r.readLine()) != null) {
00040 this.stringLeg.add(line);
00041 }
00042 }
00043 }