/************************************************************************** * $Id: Plankton.java,v 1.1.1.1 2000/03/29 22:58:14 kkeys Exp $ * * File: Plankton.java Name: Plankton * This applet/application is designed to graphically represent * caches. It should allow users to load a network, save the network, and * create nodes and links to a network that is already there. * * Allow user to load a network * Allow user to save a network if in standalone * Allow user to create, remove, and change the location of nodes and * links that have already be created * * As a applet it will need a data_address parameter. * * Written: Bradley Huffaker * For: Cooperative Association for Internet Data Analysis *************************************************************************** *************************************************************************** By accessing this software, PLANKTON, you are duly informed of and agree to be bound by the conditions described below in this notice: This software product, PLANKTON, is developed by Bradley Huffaker, and Jaeyeon Jung copyrighted(C) 1998 by the University of California, San Diego (UCSD), with all rights reserved. UCSD administers the NLANR Cache grants, NCR-9796082 and NCR-9616602, under which most of this code was developed. There is no charge for PLANKTON software. You can redistribute it and/or modify it under the terms of the GNU General Public License, v. 2 dated June 1991 which is incorporated by reference herein. PLANKTON is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not infringe on any third party's intellectual property rights. You should have received a copy of the GNU GPL along with the PLANKTON program. Copies can also be obtained from http://www.gnu.org/copyleft/gpl.html or by writing to University of California, San Diego SDSC/CAIDA/NLANR 9500 Gilman Dr., MS-0505 La Jolla, CA 92093 - 0505 USA Or contact INFO@NLANR.NET **************************************************************************/ package bhuffake.plankton; import java.applet.*; import java.awt.*; import java.lang.*; import java.net.*; import java.net.URL; import java.util.Date; public class Plankton extends Applet { String address = null; //protected int width = 500; //protected int height = 300; protected int width = 800; protected int height = 650; public static boolean isApplet = true; PlanktonFrame frame; Button control; //jjung Map stuff; Image image; /********************************************* * Gives some usefule info about this applet * *********************************************/ public String getAppletInfo() { return "Plankton - Developed by: Bradley Huffaker"; } /*************************************************** * This will set up the system if run as a applet. * ***************************************************/ public void init() { //jjung //String image_path = "../Images/world1.gif"; String image_path = "../Images/worldbw.gif"; if (isApplet) { setBackground(Color.white); address = getParameter("data_address"); if (address != null) address = this.getCodeBase().toString() + address; width = Integer.parseInt(getParameter("frame_width")); height = Integer.parseInt(getParameter("frame_height")); String image_address = getParameter("image_address");; if (image_address != null) { int http_found = image_address.indexOf("http://"); if (http_found < 0) image_address = getCodeBase().toString() +"/" + image_address; try { image = this.getImage(new URL(image_address)); System.out.println("image"+ image_address + "is fetched\n"); } catch (MalformedURLException e0) { System.err.println(e0.toString()); } } control = new Button("Start up Plankton"); add(control); } else { image = getToolkit().getImage(image_path); System.out.println("image"+ image_path + "is fetched\n"); frame = new PlanktonFrame(isApplet,address,image,width,height); stop(); } } public boolean action (Event event, Object arg) { if (event.id == Event.ACTION_EVENT && event.target == control) { frame = new PlanktonFrame(isApplet,address,image,width,height); } return super.action(event,arg); } public static void main(String arg[]) { isApplet = false; Plankton plankton = new Plankton(); plankton.init(); } } // This is the frame itself class PlanktonFrame extends Frame implements IOInterface, FileInterface { // Handle most of the mode changeing events // Extends Menu Bar protected PullDownMenu menu; // Handle the drawing and node/link events // Extends Canvus protected Display display; // Handle the auto formatting of the nodes protected Format format; // Handle the File IO protected IOHandler ioHandler; // Remeber if it is a applet or not protected boolean isApplet; // The address of the data file if this is an applet. protected String address; // This is the path to the directory where the data file is. protected String dir; // The scroll bars varaibles protected Scrollbar hbar; protected Scrollbar vbar; final protected int SCROLLBAR_SIZE = 100; // The pop up frame that shows help info protected HelpFrame help; // The pop up frame that does the name search protected NameSearch nameSearch; // The pop up frame that shows step by step protected StepByStep stepBystep; // The pop up frame that does animation between files protected Animator animator; // The pop up frame that does a URL query for fvl file names protected URLDialog urlDialog; protected FileDialog fileDialog; //jjung Image image; public PlanktonFrame(boolean isApplet_input, String address_input, Image image_input, int width, int height) { super("Plankton: a network mapping tool"); isApplet = isApplet_input; address = address_input; image = image_input; //isApplet = true; //address = "http://www.caida.org/Tools/Plankton/Working/Data"; dir = "Data"; resize(width,height); menu = new PullDownMenu(isApplet); display = new Display(image, 90,-180,-90,180); display.setMode(Display.MOVE); format = new Format(display); help = new HelpFrame(HelpFrame.ABOUT); nameSearch = new NameSearch(display); stepBystep = new StepByStep(display); /* hbar = new Scrollbar(Scrollbar.HORIZONTAL, SCROLLBAR_SIZE/2, 0, 0, SCROLLBAR_SIZE); vbar = new Scrollbar(Scrollbar.VERTICAL, SCROLLBAR_SIZE/2, 0, 0, SCROLLBAR_SIZE); vbar = new java.awt.Scrollbar(Scrollbar.VERTICAL); */ //------ Object placement-------------------------- setMenuBar(menu); setLayout(new BorderLayout()); add("Center",display); show(); if (isApplet) StartLoading(); else display.setRes(Display.HIGH); } synchronized public void printMessage(String msg) { display.printMessage(msg); } /******************************************************** * FinishedLoading & FinishedSaving * Purpose to provide a common interface for reading and * saving files. *********************************************************/ boolean ioHandled = false; public void StartLoading() { ioHandled = false; printMessage("Loading ... Please wait."); if (isApplet) { if (ioHandler != null) ioHandler.stop(); ioHandler = new IOHandler(this); Dimension dim = size(); ioHandler.setStart(dim.width/2,dim.height/2); if (urlDialog == null) urlDialog = new URLDialog(this,address); urlDialog.Show(); String file_address = urlDialog.getAddress(); if (!ioHandled) { if (file_address != null) { ioHandled = true; ioHandler.Load(file_address); } else printMessage("aborted"); } } else if (dir != null) { if (ioHandler != null) ioHandler.stop(); ioHandler = new IOHandler(this); Dimension dim = size(); ioHandler.setStart(dim.width/2,dim.height/2); if (fileDialog == null) fileDialog = new FileDialog(this ,"Load a Data File", FileDialog.LOAD); fileDialog.setDirectory(dir); fileDialog.setFilenameFilter(new NameFilter()); fileDialog.show(); String file = fileDialog.getFile(); dir = fileDialog.getDirectory(); if (file != null) ioHandler.Load(file,dir); else printMessage(""); } else printMessage("The directory you gave was null"); } // Used by URLDialog public void setFile(String file) { printMessage("Loading ... Please wait."); if (file != null && !ioHandled) { if (isApplet) ioHandler.Load(file); else ioHandler.Load(file,dir); } ioHandled = true; } // Used by both FilesSelect public boolean isApplet() { return isApplet; } public void setFiles(String[] strings) { } synchronized public void FinishedLoading(DList list, boolean setGEO, Date[] dates) { printMessage("Loading ... Complete."); display.setViewBoth(false); display.setMode(Display.MOVE); display.setListNoPaint(list); display.setNumFiles(1); display.setFileIndexNoPaint(0); format = new Format(display); if (setGEO) format.setMode(Format.GEO); else format.setMode(Format.ROOT); if (setGEO) { display.setShowMap(true); display.setViewGeo(true); display.setResNoPaint(Display.LOW); if(!display.isSetMap()) display.setMap(); else display.zoom(-180,90,180,-90); } else { display.setMap(false); display.setResNoPaint(Display.HIGH); display.setShowMap(false); display.setViewGeo(false); } format.start(); if (dates != null) { display.setDate(dates[0]); display.paintDate(); } } synchronized public void FinishedSaving() { } public boolean handleEvent(Event event) { switch (event.id) { case Event.ACTION_EVENT: if (event.arg instanceof String) { format.stop(); String label = (String)event.arg; // File Menu if (label.equals(PullDownMenu.LOAD)) { StartLoading(); } else if (label.equals(PullDownMenu.LOAD_MAP)){ if(!display.isSetMap()) printMessage("Sorry, data contain no geographical information"); else if(!display.isViewGeo()) printMessage("It doesn't need Map"); else { display.setShowMap(true); double[] latlon = display.getLatLon(); display.zoom(latlon[1],latlon[0] ,latlon[3],latlon[2]); display.repaintNodes(); printMessage("Finished"); } } else if (label.equals(PullDownMenu.CLEAR_MAP)){ display.setShowMap(false); display.repaintNodes(); } else if (label.equals(PullDownMenu.CLEAR)) display.Clear(); else if (label.equals(PullDownMenu.CENTER)) { display.recenter(); display.repaintNodes(); } else if (label.equals(PullDownMenu.REDRAW)) { display.repaintNodes(); } else if (label.equals(PullDownMenu.ANIMATE)) { String where = ""; if (isApplet) where = address; else where = dir; if (animator == null) animator = new Animator(this ,display,isApplet,where); animator.show(); } else if (label.equals(PullDownMenu.EXIT)) { hide(); dispose(); if (!isApplet) System.exit(0); } // Build Menu else if (label.equals(PullDownMenu.ADD_NODE)) display.setMode(Display.ADD_NODE); else if (label.equals(PullDownMenu.ADD_LINK)) display.setMode(Display.ADD_LINK); else if (label.equals(PullDownMenu.REMOVE)) display.setMode(Display.REMOVE); // Interaction Menu else if (label.equals(PullDownMenu.SELECT)) display.setMode(Display.SELECT); else if (label.equals(PullDownMenu.ROOT_SELECT)) display.setMode(Display.ROOT_SELECT); else if (label.equals(PullDownMenu.SELECT_NAME)) nameSearch.show(); else if (label.equals(PullDownMenu.SELECT_TREE)) display.setMode(Display.SELECT_TREE); else if (label.equals(PullDownMenu.DESELECT)) display.deselectAll(); else if (label.equals(PullDownMenu.MOVE)) display.setMode(Display.MOVE); else if (label.equals(PullDownMenu.FORMAT)) { if(!display.isViewGeo()) { format = new Format(display); format.setMode(Format.ROOT); format.start(); } } else if (label.equals(PullDownMenu.STEP_BY_STEP)) { if (display.getNumFiles() > 1) printMessage("This option doesn't work with an Animation mode"); else { display.setMode(display.STEP_BY_STEP); stepBystep.show(); } } // View Menu else if (label.equals(PullDownMenu.VIEW_BOTH)){ display.setViewBoth(true); if(display.isViewGeo()) { display.zoom(-180,90,180,-90); display.setResNoPaint(Display.HIGH); format = new Format(display); format.setMode(Format.ROOT); format.start(); } else if(display.isSetMap()) { display.recenter(); display.setShowMap(true); display.zoom(-180,90,180,-90); format = new Format(display); format.setMode(Format.GEO); format.start(); } else { printMessage("Sorry, data contain no geographical information"); } } else if (label.equals(PullDownMenu.VIEW_ROOT)){ display.setViewBoth(false); display.setShowMap(false); display.setViewGeo(false); display.setResNoPaint(Display.HIGH); format = new Format(display); format.setMode(Format.ROOT); format.start(); } else if (label.equals(PullDownMenu.VIEW_GEO)){ display.setViewBoth(false); if (display.isSetMap()) { display.setShowMap(true); display.setViewGeo(true); display.zoom(-180,90,180,-90); format = new Format(display); format.setMode(Format.GEO); format.start(); } else printMessage("Sorry, data contain no geographical information"); } else if (label.equals(PullDownMenu.VIEW_WORLD)){ display.setViewBoth(false); if (display.isSetMap()) { if (display.isViewGeo()) { display.zoom(-180,90,180,-90); display.repaintNodes(); printMessage("Finished"); } else { display.setShowMap(true); display.setViewGeo(true); display.zoom(-180,90,180,-90); format = new Format(display); format.setMode(Format.GEO); format.start(); } } else printMessage("Sorry, data contain no geographical information"); } else if (label.equals(PullDownMenu.VIEW_USA)){ display.setViewBoth(false); if (display.isSetMap()) { if (display.isViewGeo()) { display.zoom( -131.37, 53.13, -63.79, 22.5); display.repaintNodes(); printMessage("Finished"); } else { display.setShowMap(true); display.setViewGeo(true); display.zoom( -131.37, 53.13, -63.79, 22.5); format = new Format(display); format.setMode(Format.GEO); format.start(); } } else printMessage("Sorry, data contain no geographical information"); } else if (label.equals(PullDownMenu.VIEW_EUROPE)){ display.setViewBoth(false); if (display.isSetMap()) { if (display.isViewGeo()) { display.zoom( -20, 70, 50, 33.13); display.repaintNodes(); printMessage("Finished"); } else { display.setShowMap(true); display.setViewGeo(true); display.zoom( -20, 70, 50, 33.13); format = new Format(display); format.setMode(Format.GEO); format.start(); } } else printMessage("Sorry, data contain no geographical information"); } else if (label.equals(PullDownMenu.VIEW_ASIA)){ display.setViewBoth(false); if (display.isSetMap()) { if (display.isViewGeo()) { display.zoom( 37.89, 67.5, 191, 0.75); display.repaintNodes(); printMessage("Finished"); } else { display.setShowMap(true); display.setViewGeo(true); display.zoom( 37.89, 67.5, 191, 0.75); format = new Format(display); format.setMode(Format.GEO); format.start(); } } else printMessage("Sorry, data contain no geographical information"); } else if (label.equals(PullDownMenu.ALL_NAMES)) display.showAllNames(); else if (label.equals(PullDownMenu.ROOT_NAMES)) display.showRootNames(); else if (label.equals(PullDownMenu.NO_NAMES)) display.hideNames(); // Resolution Menu else if (label.equals(PullDownMenu.LOW)) display.setRes(Display.LOW); else if (label.equals(PullDownMenu.HIGH)) display.setRes(Display.HIGH); // Tool Menu // Zoom Menu else if (label.indexOf(PullDownMenu.ZOOM) >= 0) { // Prase out the part that is a number char[] array = label.toCharArray(); int start = 0; while (start < array.length && (array[start] < '0' || array[start] > '9')) start++; int end = start; while (end < array.length && ((array[end] >= '0' && array[end] <= '9') || array[end] == '.')) end++; if (start < end) { double zoom= (new Double( new String(array,start,end-start)) ).doubleValue(); //if(display.isViewGeo()) display.setMode(display.ZOOM); display.scale(zoom); } } // Rotate Menu else if (label.indexOf("degree") >= 0) { // Prase out the part that is a number char[] array = label.toCharArray(); int start = 0; int minus = 1; while (start < array.length && (array[start] < '0' || array[start] > '9' )) start++; if(start >0) if(array[start-1] =='-') minus = -1; int end = start; while (end < array.length && ((array[end] >= '0' && array[end] <= '9') || array[end] == '.')) end++; if (start < end) { double rotate_degree= (new Double( new String(array,start,end-start)) ).doubleValue(); rotate_degree = minus * rotate_degree; display.rotate(rotate_degree); } } // Node size Menu else if (label.indexOf(PullDownMenu.NODE) >= 0) { // Prase out the part that is a number char[] array = label.toCharArray(); int start = 0; int minus = 1; while (start < array.length && (array[start] < '0' || array[start] > '9' )) start++; if(start >0) if(array[start-1] =='-') minus = -1; int end = start; while (end < array.length && ((array[end] >= '0' && array[end] <= '9') || array[end] == '.')) end++; if (start < end) { double node_size= (new Double( new String(array,start,end-start)) ).doubleValue(); node_size = minus * node_size; display.nodeSize((int)node_size); } } // Line size Menu else if (label.indexOf(PullDownMenu.LINE) >= 0) { // Prase out the part that is a number char[] array = label.toCharArray(); int start = 0; int minus = 1; while (start < array.length && (array[start] < '0' || array[start] > '9' )) start++; if(start >0) if(array[start-1] =='-') minus = -1; int end = start; while (end < array.length && ((array[end] >= '0' && array[end] <= '9') || array[end] == '.')) end++; if (start < end) { double line_size= (new Double( new String(array,start,end-start)) ).doubleValue(); line_size = minus * line_size; display.lineSize((int)line_size); } } // Color Menu else if (label.equals(PullDownMenu.COLOR_HTTP)) display.colorByMask(display.COLOR_HTTP); else if (label.equals(PullDownMenu.COLOR_DEFAULT)) display.colorByDefault(); else if (label.equals(PullDownMenu.COLOR_DOMAIN)) display.colorByMask(display.COLOR_DOMAIN); // Help Menu else if (label.equals(PullDownMenu.COMMANDS)) { help.setType(HelpFrame.COMMANDS); help.toFront(); help.show(); } else if (label.equals(PullDownMenu.ABOUT)) { help.setType(HelpFrame.ABOUT); help.toFront(); help.show(); } else if (label.equals(PullDownMenu.OVERVIEW)) { help.setType(HelpFrame.OVERVIEW); help.toFront(); help.show(); } } break; /* default: if (event.target == hbar) display.Shift_X( ((Integer)event.arg).intValue()/SCROLLBAR_SIZE); else if (event.target == vbar) display.Shift_Y( ((Integer)event.arg).intValue()/SCROLLBAR_SIZE); */ } return super.handleEvent(event); } }