/* *Zine Zine Zine Zine Zine Zine Zine * a demo program. * Implements popups for comic book style messages * on top of an image. * uses a crummy form of markup language * designed only to be easy to parse with java * (read quick n dirty) *Zine (more...) * an app by Johan van der Hoeven. * johan@rosebud.com * http://www.rosebud.com/rb/rbhome.html * johan_van_der_Hoeven@terc.edu * * can be viewed at: * http://http://www.fanzine.se/java/jo/zine.html (zine stuff) * http://teaparty.terc.edu/java/z/glob.html (network science education research) * * There have been made very slight changes to this program by me (Markus * Baumeister ). Just bug-fixes * AFAIK to make it work smoothly with 'mapzine'. Do only use this * version in conjunction with mapzine and don't blame Johan for * any bugs herin (at least not without checking his version first). */ import browser.Applet; import awt.*; import java.io.StreamTokenizer; import java.io.InputStream; import java.io.FileInputStream; import net.www.html.URL; import java.util.Vector; import java.util.Enumeration; class Point { public int x=0,y=0; public Point(int ax,int ay){x=ax;y=ay;}; public Point() { }; } class Rect { public int lX=0; public int tY=0; public int rX=0; public int bY=0; public Rect(int leftX, int topY, int rightX, int bottomY) {lX=leftX; tY=topY; rX=rightX; bY=bottomY;} public Rect(){}; public boolean isPointInRect(int x, int y) { if(xlX&&y>tY&& yboundR.rX) { //do a horizontal left shift int tmp= Math.min(textR.width(),xa); textR.offset(-tmp,0); } else if(textR.lXboundR.bY) { //do a vertical down shift int tmp= Math.min(textR.height(),yb); textR.offset(0,-tmp); } }; public void Draw(Graphics g) { g.setFont(font); g.setForeground(Color.lightGray); g.paint3DRect(textR.lX, textR.tY, textR.width(), textR.height(),true,true); g.setForeground(Color.black); int y=textR.tY; for (Enumeration e = xfrm.strvec.elements(); e.hasMoreElements();) { y+=lineHi; g.drawString((String) e.nextElement() , textR.lX+charWid, y); }; }; } class Zine extends Applet { protected String dana = null; protected String imgna = null; protected String shot=null; protected Image daimg; /* Rect clipR; */ Vector framevect; boolean showhot=false; zineFrame cur_znfrm=null; zinePopUp pop=null; Font font; public void init() { font = getFont("TimesRoman", Font.PLAIN, 12); framevect= new Vector(); resize(200, 200); dana = getAttribute("dataurl"); getFrames(); imgna = getAttribute("imgurl"); daimg= getImage(imgna); if(daimg!=null) resize(daimg.width,daimg.height); else resize(10, 10); shot = getAttribute("showhot"); if(shot!=null) if(shot.equals("yes")) showhot=true; } public void paint(Graphics g) { g.drawImage(daimg, 0, 0); /* System.out.println("Zine Paint"); System.out.println(zfrm); System.out.println(zfrm.p); System.out.println(zfrm.r); System.out.println(zfrm.strvec); System.out.println(framevect); */ if(showhot) for ( Enumeration ee = framevect.elements(); ee.hasMoreElements();) { zineFrame fr= (zineFrame)ee.nextElement(); g.paint3DRect(fr.r.lX, fr.r.tY, fr.r.width(), fr.r.height(),false,true); }; if(pop!=null) pop.Draw(g); g.paint3DRect(0, 0, width, height,false,true); } /* end paint */ public void update(Graphics g) { // Clip to the affected area //make sure not outside applet: //(needed else it can paint outside applet --java bug ?) /* int x= Math.max(0,clipR.lX); int y= Math.max(0,clipR.tY); int w= Math.min(width,clipR.width()); int h= Math.min(height,clipR.height()); g.clipRect(x, y, w, h); */ paint(g); } public void keyDown(int k) { System.out.println("key"); if(k=='s'||k=='S') { showhot=!showhot; /* clipR.lX=0; clipR.rX=width; clipR.tY=0; clipR.bY=height; */ repaint(); } } public void mouseEnter() { getFocus();} public void mouseExit() { if(pop!=null) { cur_znfrm=null; /* clipR=pop.clipR; */ pop=null; repaint(); }; } public void mouseMove(int x, int y) { boolean change=false; if(cur_znfrm==null) { for ( Enumeration ee = framevect.elements(); ee.hasMoreElements();) { zineFrame fr= (zineFrame)ee.nextElement(); if(fr.r.isPointInRect(x,y)) { change=true; cur_znfrm=fr; pop = new zinePopUp(font); Rect r=new Rect(0,0,width,height); pop.doLayout(r,cur_znfrm); /* clipR=pop.clipR; */ }; }; } else { if(!cur_znfrm.r.isPointInRect(x,y)) { cur_znfrm=null; /* clipR=pop.clipR; */ pop=null; change=true; }; }; if(change) { repaint(); }; } protected void getFrames() { zineFrame zfrm=null; //System.out.println("zine get frames"); InputStream is=null; is = new URL(documentURL, dana).openStreamInteractively(); StreamTokenizer st = new StreamTokenizer(is); st.eolIsSignificant = false; st.commentChar('#'); /* parse file --NOT very clean can be improved alot */ int i=0; while (st.ttype != StreamTokenizer.TT_EOF) { st.nextToken(); /* got a new frame: */ if(st.ttype == '{') { zfrm= new zineFrame(); i=0; continue; }; if(st.ttype == '}') {framevect.addElement(zfrm); continue; } if(st.ttype==st.TT_NUMBER) { int n = (int) st.nval; switch (i) { case 0: zfrm.p.x=n; break; case 1: zfrm.p.y=n; break; case 2: zfrm.r.lX=n; break; case 3: zfrm.r.tY=n; break; case 4: zfrm.r.rX=n; break; case 5: zfrm.r.bY=n; break; }; i++; continue; }; if(st.ttype=='"') { String tmp= st.sval; zfrm.strvec.addElement(tmp); continue; }; }; /* while */ }; /* end getFrames() */ } /* end zine class */