00001
00002
00003
00004
00005 package org.hfbk.vis.visnode;
00006
00007
00008 import java.awt.event.MouseEvent;
00009
00010 import org.dronus.gl.GLUtil;
00011 import org.dronus.gl.Texture;
00012 import org.dronus.graph.Node;
00013 import org.hfbk.vis.ImageFetcher;
00014 import org.lwjgl.opengl.GL11;
00015 import org.lwjgl.util.vector.Vector3f;
00016
00023 public class VisImage extends VisNodeDraggable {
00024
00025 final float SCALE=15f;
00026
00027 Texture tex=null;
00028 ImageFetcher fetcher;
00029
00030 String large;
00031
00032 public VisImage(Node n, Vector3f position) {
00033 super(n, position);
00034
00035 String imageURL=n.getSubNodeText("thumbnail");
00036 if (imageURL==null) imageURL=n.text;
00037 fetcher=new ImageFetcher(imageURL,true);
00038
00039 large=n.text;
00040 if (large==null)
00041 large=imageURL;
00042 }
00043
00047 public void add(VisNode node) {}
00048
00049 public VisImage(String imageUrl, String contextUrl, Vector3f position, boolean asThumbnail) {
00050 super(new Node(imageUrl), position);
00051 url=contextUrl;
00052 fetcher=new ImageFetcher(imageUrl,asThumbnail);
00053 large=imageUrl;
00054 }
00055
00056
00057 void renderSelf() {
00058 if (tex!=null){
00059 tex.render();
00060
00061 Vector3f pos=new Vector3f(GLUtil.getPosition());
00062
00063 float alpha=Math.max(Math.min(-pos.z/20,1),0);
00064 GL11.glColor4f(1,1,1,alpha);
00065
00066 GLUtil.renderQuad(-w/2,-h/2,w/2,h/2, tex.imagewidth, tex.imageheight);
00067 }else if (fetcher.pixels!=null){
00068 tex=new Texture(fetcher.pixels, fetcher.width, fetcher.height, fetcher.pixelformat);
00069 fetcher.free();
00070 fetcher=null;
00071
00072 w=tex.width; h=tex.height;
00073 float scale=Math.max(w,h);
00074 scale=SCALE/scale;
00075 w*=scale; h*=scale;
00076 radius=(float)Math.sqrt(w*w+h*h)/2;
00077 }
00078 }
00079
00080 void handleEvent(VisMouseEvent evt) {
00081 super.handleEvent(evt);
00082 if (evt.getID()==MouseEvent.MOUSE_CLICKED){
00083
00084 if (evt.getButton()==1)
00085 if (getRoot() instanceof VisHUD)
00086 getRoot().remove(this);
00087 else
00088
00089 getRoot().client.hud.add(new VisImage(large, url, new Vector3f(0,0,-20),false));
00090 else if(evt.getButton()==3 && url!=null)
00091 getRoot().fetch("spider", url, this);
00092
00093 }
00094 }
00095
00096 public void close() {
00097 if (fetcher!=null) fetcher.free();
00098 super.close();
00099 }
00100 }