00001
00002
00003
00004
00005 package org.hfbk.vis.visnode;
00006
00007 import java.awt.event.MouseEvent;
00008 import java.util.ArrayList;
00009 import java.util.Arrays;
00010 import java.util.List;
00011
00012 import org.dronus.gl.GLTextPanel;
00013 import org.dronus.gl.GLUtil;
00014 import org.dronus.graph.Node;
00015 import org.hfbk.vis.Prefs;
00016 import org.hfbk.vis.VisNodeLayouter;
00017 import org.hfbk.vis.visnode.VisMenu.VisMenuListener;
00018 import org.lwjgl.opengl.GL11;
00019 import org.lwjgl.util.vector.Vector3f;
00020
00028 public class VisKeyword extends VisNodeDraggable implements VisMenuListener {
00029
00030
00031
00032 private GLTextPanel textPanel;
00033
00034 public String keyword;
00035
00036 VisMenu menu = null;
00037
00038 List<String> menuitems=new ArrayList<String>(
00039 Arrays.asList("commonImages", "mixImages", "wikipedia", "googleNews", "google" ));
00040
00041 int dl;
00042
00051 public VisKeyword(Node n, Vector3f pos) {
00052 super(n, pos);
00053 String text=n.text;
00054 this.keyword = text;
00055 if (text.matches("http://.*"))
00056 url = text;
00057
00058 int l=text.length();
00059 if (l>20)
00060 text=text.replace("http://","").substring(0,10)+"..."+text.substring(l-10,l);
00061
00062 textPanel = new GLTextPanel(text, 0, 0);
00063 w = textPanel.w;
00064 h = 1.8f;
00065 radius=w/2;
00066
00067 }
00068
00072 void transform() {
00073 super.transform();
00074 if (children.size() < (menu==null ? 1 : 2) )
00075 GLUtil.billboardCylinder();
00076 }
00077
00085 public void renderSelf() {
00086 if (children.size() > 0) {
00087
00088 if (menu != null) remove(menu);
00089 VisNodeLayouter.layOut(this, 50, 0, 50);
00090 if (menu != null) add(menu);
00091 }
00092
00093 if (dl==0){
00094 dl=GL11.glGenLists(1);
00095 GL11.glNewList(dl,GL11.GL_COMPILE);
00096
00097
00098 GL11.glColor3f(.2f, .2f, .2f);
00099 GL11.glDisable(GL11.GL_TEXTURE_2D);
00100 GL11.glPolygonOffset(1, 1);
00101 GLUtil.renderQuad(-w / 2, -h / 2, w / 2, h / 2);
00102 GL11.glPolygonOffset(0, 0);
00103
00104
00105 GL11.glTranslatef(-w / 2, -h / 2, 0);
00106 GL11.glScalef(1, 2, 1);
00107 GL11.glColor3f(1, 1, 1);
00108 textPanel.render();
00109 GL11.glEndList();
00110 }
00111
00112 GL11.glCallList(dl);
00113 }
00114
00118 void handleEvent(VisMouseEvent evt) {
00119 super.handleEvent(evt);
00120 if (evt.getID() != MouseEvent.MOUSE_CLICKED)
00121 return;
00122
00123 if (url == keyword)
00124 getRoot().fetch("spider", url, this);
00125 else if (!children.contains(menu)) {
00126
00127 if (url != null && !url.contains(Prefs.current.baseURL))
00128 menuitems.add("spider");
00129
00130 add(menu = new VisMenu(menuitems, this));
00131
00132 getRoot().client.setViewpoint(traverse(getRoot(), new Vector3f(0,0,0)),1);
00133
00134 }
00135 }
00136
00140 public void menuAction(String item) {
00141 getRoot().fetch(item, (item.equals("spider") ? url : keyword), this);
00142 menu=null;
00143 }
00144 }