VisClient/org/hfbk/vis/visnode/VisMenu.java

Go to the documentation of this file.
00001 /*
00002  * Created on 19.04.2008
00003  *
00004  */
00005 package org.hfbk.vis.visnode;
00006 
00007 
00008 import java.awt.event.MouseEvent;
00009 import java.util.List;
00010 
00011 import org.dronus.gl.GLFont;
00012 import org.dronus.gl.GLTextPanel;
00013 import org.dronus.gl.GLUtil;
00014 import org.lwjgl.opengl.GL11;
00015 import org.lwjgl.util.vector.Vector3f;
00016 
00028 public class VisMenu extends VisNodeMousable implements VisUI {
00029 
00030         
00031         List<String> items;
00032         GLTextPanel itemText;
00033         VisMenuListener listener;
00034         
00035         public static interface VisMenuListener {
00036                 void menuAction(String item);
00037         }
00038         
00039         
00043         VisMenu(List<String> items, VisMenuListener listener) {
00044                 super(null, new Vector3f());
00045                 this.items=items;       
00046                 String text="";
00047                 for (String item: items)
00048                         text+="\n"+item;
00049                 itemText=new GLTextPanel(text,0,0);
00050                 w=15; h=(items.size())*2; radius=Math.max(w,h);
00051                 position.y=1+h/2;
00052                 position.x=w/3;
00053                 this.listener=listener;
00054                 
00055         }
00056 
00060         void handleEvent(VisMouseEvent evt) {
00061                 
00062                 if (evt.getID()!=MouseEvent.MOUSE_RELEASED) return;
00063                 int i=items.size()-(int)(evt.hit.y+h/2)/2-1;
00064                 
00065                 //tell the client, the result should attach to our parent.
00066                 if (i>=0 && i<items.size()){
00067                         listener.menuAction(items.get(i));
00068                 }
00069                 parent.remove(this); //hide menu again.
00070         }
00071 
00072         void renderSelf() {
00073                 GL11.glColor3f(.4f,.4f,.4f);
00074                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00075                 GL11.glPolygonOffset(1,1);              
00076                 GLUtil.renderQuad(-w/2, -h/2, w/2, h/2);
00077                 GL11.glPolygonOffset(0,0);              
00078                 
00079                 GL11.glTranslatef(-w/2,-h/2,0);
00080                 GL11.glColor3f(1,1,1);          
00081                 GL11.glEnable(GL11.GL_TEXTURE_2D);
00082         GLFont.getDefault().render();
00083         GL11.glTranslatef(0,items.size()*2,0);
00084         GL11.glScalef(1,2,1);
00085                 itemText.render();
00086         }
00087 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1