home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-09-25 | 11.4 KB | 432 lines |
- import java.net.*;
- import java.lang.*;
- import java.util.*;
- import java.awt.*;
- import java.applet.*;
- // menu1 = file
- // pop1 = 1:10
- public class mac extends Applet
- {
- Image wallpaper;
- String frame_target;
- //for Icons (size=32x32)
- int iconWH=32;
- int iconCount=0;
- Vector iconText =new Vector();
- Vector icons =new Vector();
- Vector iconX =new Vector();
- Vector iconY =new Vector();
- Vector iconLink =new Vector();
- //for MainMenu
- String applebtn="Start";
- int applebtnEX=0;
- FontMetrics f;
- Image applelogo,buffer=null;
- Vector mpops=new Vector();
- Vector mlinks=new Vector();
- Vector macts=new Vector();
- Vector mitems=new Vector();
- boolean applepop=false;
- boolean mclick=false;
-
- int pop=-1;
- int mix=0,miy=0;
- int popselect=-1;
- int mitemCount=0;
- Dimension d=size();
- int fwidth=100;
- int xmenu=0;
- int mouseX=0,mouseY=0;
- int fheight=0;
- String message;
- boolean message_show=false;
- //code for Icons
- public void addIcon(String txt,Image img,String href,String x,String y)
- { iconText.addElement(txt);
- icons.addElement(img);
- iconLink.addElement(href);
- iconX.addElement(x);
- iconY.addElement(y);
- iconCount++;
- }
- //code for MainMenu
- public void addMItem(String caption)
- {
- mitems.addElement(caption);
- mpops.addElement(new Vector());
- mlinks.addElement(new Vector());
- macts.addElement("none");
- mitemCount++;
- };
- //code for messageBox
- public void message_box(String caption)
- {
- message=caption;
- message_show=true;
- repaint();
- };
- public boolean mouseUp(Event e,int x,int y)
- { int tempY=0,i=0,maxlength=0,j=0,tx=0,ix=0,iy=0,iex=0;
- mouseX=x;
- mouseY=y;
- if(mouseY<=fheight)mclick=true;
- message_show=false;
- if(pop>-1)
- {
- if(!((Vector)mpops.elementAt(pop)).isEmpty())
- {
- Vector temp=(Vector)mpops.elementAt(pop);
- Vector temp2=(Vector)mlinks.elementAt(pop);
-
- for(j=0;j<temp.size();j++)
- if(maxlength<f.stringWidth((String)temp.elementAt(j)))
- maxlength=f.stringWidth((String)temp.elementAt(j));
- maxlength=maxlength+32;
- for(j=0;j<temp.size();j++)
- if((mouseY>(j+1)*fheight)
- &&(mouseY<fheight*(j+2))
- &&(mouseX>=mix)
- &&(mouseX<=maxlength+mix))
- {
- popselect=j;
- do_link((String)temp2.elementAt(j));
- }
- else
- {popselect=-1;pop=-1;}
- };
- };
- i=0;
- // logo button
- if((mouseY<fheight)&&(mouseX<=16)&&(applepop)){i=1;pop=0;mix=0;mclick=false;}
- // x button
- if((mouseY<fheight)&&(mouseX>d.width-16))
- {xmenu++;
- switch(xmenu)
- {
- case 1:
- message_box("RDESKTOP II (C) Raymond Anthony Samalo June 1998 ");
- break;
- case 2:
- message_box("This is a FREE ware, Desktop like Site navigation tool.");
- break;
- case 3:
- message_box("Any support moral, financial :), critics are welcome.");
- break;
- case 4:
- message_box("Contact me at eng60728@leonis.nus.edu.sg");
- break;
- case 5:
- message_box("Visit http://members.tripod.com/~yarsa");
- xmenu=0;
- break;
- default:
- message_box("Click on the logo, menu or icon, to navigate ");
- break;
- };
- mclick=false;
- }
-
-
- if(iconCount>0)
- for(i=iconCount-1;i>=0;i--)
- {
- if(icons.elementAt(i)!=null)
- {
- ix= Integer.parseInt((String) iconX.elementAt(i))-iconWH/2;
- iex=iconWH;
- iy= Integer.parseInt((String) iconY.elementAt(i))+iconWH;
- if((ix<=mouseX)&&(iy-iconWH<=mouseY)
- &&(ix+iex>=mouseX)&&(iy+fheight-8>=mouseY))
- {do_icon(i);break;}
- }else break;
- }
- return true;
- }
- public boolean mouseMove(Event e,int x,int y)
- {
- int tempY=0;
- mouseX=x;
- mouseY=y;
- repaint();
- return true;
- }
- public void update(Graphics g){paint(g);}
- public boolean imageUpdate(Image img,int flags,int x,int y, int w,int h)
- {
- if((flags&SOMEBITS)!=0){repaint(x,y,w,h);
- } else if((flags&ABORT)!=0)
- {repaint();}
- return(flags&(ALLBITS|ABORT))==0;
- }
-
- public void paint(Graphics g)
- {
- Graphics screengc=null;
- screengc=g;
- g=buffer.getGraphics();
- int i=0;
- int j=0;
- String str;
- int y=0;
- int maxy=0;
- int mxlength=0;
-
- int ix=0,iy=0,iex=0;
- int x=0;
- d=size();
- g.setColor(getColor("bgcolor",Color.lightGray));
- g.fill3DRect(0,0,d.width,d.height,true);
-
- f=g.getFontMetrics();
- fheight= f.getHeight()+3;
- if(wallpaper!=null) g.drawImage(wallpaper,0,0,d.width,d.height-8,this);
- g.setColor(getColor("mnu0color",Color.white));
- g.fill3DRect(0,0,d.width,fheight,true);
- g.setColor(getColor("mnu1color",Color.black));
- g.drawRect(0,0,d.width,fheight);
- // draw icon
- if(iconCount>0)
- for(i=iconCount-1;i>=0;i--)
- {
- if(icons.elementAt(i)!=null)
- {
- g.setColor(Color.lightGray);
- iex= g.getFontMetrics().stringWidth((String) iconText.elementAt(i));
- ix= Integer.parseInt((String) iconX.elementAt(i))-
- iex/2;
- iy= Integer.parseInt((String) iconY.elementAt(i))+iconWH;
- if((ix<=mouseX)&&(iy-iconWH<=mouseY)
- &&(ix+iex>=mouseX)&&(iy+fheight-8>=mouseY))
- g.draw3DRect(ix-4,iy-iconWH-4,iex+8,fheight+iconWH,true);
- g.setColor(Color.black);
- g.fillRect(
- ix,
- iy+2,
- g.getFontMetrics().stringWidth((String) iconText.elementAt(i)),
- fheight-8
- );
- g.setColor(Color.white);
- g.drawString(
- (String) iconText.elementAt(i),
- ix,
- iy+fheight-8
- );
- g.drawImage(
- (Image)icons.elementAt(i),
- ix+iconWH/2,
- iy-iconWH,
- iconWH,iconWH,this
- );
- };
-
- };
- // draw message
- if(message_show)
- { int message_width=g.getFontMetrics().stringWidth(message)+64;
- int message_x=(d.width-message_width)/2;
- int message_y=d.height/2-fheight*2;
- g.setColor(getColor("msg0color",Color.gray));
- g.fill3DRect(message_x,message_y,message_width,fheight*4,true);
- g.setColor(getColor("msg1color",Color.white));
- g.drawString(message,message_x+32,message_y+fheight*2);
- if(applelogo!=null)
- g.drawImage(applelogo,message_x+2,message_y+fheight,28,28,this);
- };
- // draw apple button
- applebtnEX=16;
- i=0;
- if(applelogo!=null)
- {
- g.drawImage(applelogo,0,0,16,fheight,this);
- if((mouseY<fheight)&&(mouseX>=0)&&(mouseX<=16))
- g.draw3DRect(0,0,16,fheight,true);
- i=1;
- };
-
- // draw main menu
- for(;i<mitemCount;i++)
- { x+=applebtnEX;
- x+=16;
- if(i==mitemCount-1) x=d.width-16;
- str=(String)mitems.elementAt(i);
- applebtnEX=g.getFontMetrics().stringWidth(str);
- if((mouseY<fheight)&&(mouseX>=x)&&(mouseX<=x+applebtnEX))
- {
- if(mclick){
- pop=i;mix=x;
- if(!(macts.elementAt(i).equals("none")))
- do_link((String)macts.elementAt(i));
- };
- g.setColor(getColor("mnu1color",Color.black));
- g.fillRect(x,1,applebtnEX,fheight-2);
- g.setColor(getColor("mnu0color",Color.white));
- g.drawString(str,x,fheight-3);
- }
- else
- {
- g.setColor(getColor("mnu0color",Color.white));
- g.fillRect(x,1,applebtnEX,fheight-2);
- g.setColor(getColor("mnu1color",Color.black));
- g.drawString(str,x,fheight-3);
- };
- };
- mclick=false;
-
- // draw pop menu
- x=mix;
- if(pop>-1)
- if(!((Vector)mpops.elementAt(pop)).isEmpty())
- { Vector temp=(Vector)mpops.elementAt(pop);
- for(j=0;j<temp.size();j++)
- if(mxlength<g.getFontMetrics().stringWidth((String)temp.elementAt(j)))
- mxlength=g.getFontMetrics().stringWidth((String)temp.elementAt(j));
- mxlength=mxlength+32;
- g.setColor(getColor("mnu0color",Color.white));
- g.fillRect(x,fheight,mxlength,temp.size()*fheight);
- g.setColor(getColor("mnu1color",Color.black));
- g.drawRect(x,fheight,mxlength,temp.size()*fheight);
- for(j=0;j<temp.size();j++)
- {
- g.setColor(getColor("mnu1color",Color.black));
- if((mouseY>fheight*(j+1))&&(mouseY<fheight*(j+2))
- &&(mouseX>x)&&(mouseX<mxlength+x))
- {
- g.fill3DRect(x,(j+1)*fheight,mxlength,fheight,true);
- g.setColor(getColor("mnu0color",Color.white));
- }
-
- g.drawString((String)temp.elementAt(j),x+16,(j+2)*fheight);
- };
- };
- screengc.drawImage(buffer,0,0,null);
- };
- // icon handler
- public void do_icon(int i)
- {
- do_link((String)iconLink.elementAt(i));
- }
- // link executor
- public void do_link(String link)
- {
- if (!(link.equals("none")))
- {
- if(link.startsWith("say:"))
- message_box(link.substring(4));
- else
- {
- try{
- if (frame_target==null){
- getAppletContext().showDocument(new URL(link));
- }
- else
- {
- getAppletContext().showDocument(new URL(link),frame_target);
- }
- }
- catch(MalformedURLException er)
- { message_box("Malformed URL error at "+link);}
- }
- }
- }
- // INIT()
- public void init()
- {int i=0,k=0;
- int j=0;
- String str;
- d=size();
- buffer=createImage(d.width,d.height);
- // frame handler
- frame_target=getParameter("target");
- //end_frame
- if(getParameter("img")!=null) wallpaper=getImage(getDocumentBase(),getParameter("img"));
- k=0;
- if(getParameter("logo")!=null)
- {
- addMItem("@");// logo pop up
- applelogo=getImage(getDocumentBase(),getParameter("logo"));
- if((str=getParameter("poplogo"))!=null)
- {
- applepop=true;
- Vector temp=(Vector)(mpops.elementAt(0));
- Vector temp2=(Vector)(mlinks.elementAt(0));
- for(j=1;getParameter(str+j)!=null;j++)
- {
- temp.addElement(getParameter(str+j));
- temp2.addElement(getParameter(str+"link"+j)==null?"none":getParameter(str+"link"+j));
- };
- k=1;
- };
- };
-
- for(i=1;getParameter("menu"+i)!=null;i++)
- {
- addMItem(getParameter("menu"+i));
- if((str=getParameter("pop"+i))!=null)
- {
- Vector temp=(Vector)(mpops.elementAt(k+i-1));
- Vector temp2=(Vector)(mlinks.elementAt(k+i-1));
- for(j=1;getParameter(str+j)!=null;j++)
- {
- temp.addElement(getParameter(str+j));
- temp2.addElement(getParameter(str+"link"+j)==null?"none":getParameter(str+"link"+j));
- };
- }else if((str=getParameter("link"+i))!=null)
- {
- macts.setElementAt(str,k+i-1);
- };
- };
- addMItem("?");
-
- for(i=1;getParameter("icon"+i)!=null;i++)
- addIcon(
- (getParameter("itext"+i)!=null)?getParameter("itext"+i):"",
- getImage(getDocumentBase(),getParameter("icon"+i)),
- (
- getParameter("ilink"+i)!=null)?getParameter("ilink"+i):"none",
- getParameter("ix"+i),
- getParameter("iy"+i)
- );
-
- message_box(
- (
- getParameter("msg")!=null)?getParameter("msg")
- :
- "Welcome To (C)RDesktop II"
- );
-
- };
-
-
- // get color
- Color getColor(String sx, Color standard)
- {
- String s=getParameter(sx);
- if(s==null){return standard;}
- else
- {
- if(s.charAt(0)=='#')return(new Color(
- Integer.parseInt(s.substring(1),16)
- ));
- else
- {
- if(s.equals("black"))return(Color.black);
- if(s.equals("white"))return(Color.white);
- if(s.equals("lightGray"))return(Color.lightGray);
- if(s.equals("gray"))return(Color.gray);
- if(s.equals("darkGray"))return(Color.darkGray);
- if(s.equals("red"))return(Color.red);
- if(s.equals("pink"))return(Color.pink);
- if(s.equals("magenta"))return(Color.magenta);
- if(s.equals("yellow"))return(Color.yellow);
- if(s.equals("green"))return(Color.green);
- if(s.equals("cyan"))return(Color.cyan);
- if(s.equals("blue"))return(Color.blue);
- };
- };
- return(standard);
- };
- // end get color
- };
- // end mac applet
-
-