// Medusa is a graph viewer which allows interactive editing of networks
// (edges and nodes) and also connects to databases.
//
// Copyright (C) 2006 Sean Hooper
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA

package medusa.applet;

//import TimeNet.Stringlet;
import java.awt.BorderLayout;
import java.awt.Graphics;
import javax.swing.JApplet;
import java.awt.event.ItemListener;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JCheckBox;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import medusa.*;
import medusa.dataio.DataLoader;
import medusa.display.BasicGraphPanel;
import medusa.georgios.Layouts.Layouts;
import medusa.graph.Graph;



/**
 * MedusaLite is an applet version of medusa.
 * The parameters required are very strict, since the applet will probably be used
 * as a complement to a webserver and the data will be generated by scripts.
 *
 *
 * 
 * 
 * 
 * 
 *  Network
 * 
 * 
 * 

Lightweight network viewer

*
* * * * * * *
* *
* @author Sean Hooper * @version 1.0 */ public class MedusaLite extends JApplet implements ItemListener, ActionListener{ final Color babyBlue=new Color(230,226,230); public BasicGraphPanel panel; private MedusaSettings stringSettings; //InfoPanel infoPanel; private JScrollPane jScrollPane; //Image image; public JPanel controlPanel = new JPanel(); private int xParam; private int yParam; JCheckBox relax=new JCheckBox("Relax",false); JCheckBox pretty=new JCheckBox("Edge colours",true); JCheckBox names = new JCheckBox("Labels", true); JMenuBar jMenuBar1 = new javax.swing.JMenuBar(); JMenuItem randomButton = new JMenuItem("Random"); JMenu layout_menu = new JMenu("Layout"); JMenu clustering_menu = new JMenu("Clustering"); JMenuItem circularButton = new JMenuItem("Circular"); JMenuItem gridButton = new JMenuItem("Grid"); JMenuItem hierarchicalButton = new JMenuItem("Hierarchical"); JMenuItem geometryButton = new JMenuItem("Distance Geometry"); JMenuItem kmeansButton = new JMenuItem("k-means"); JMenuItem affinityButton = new JMenuItem("Affinity Propagation"); JMenuItem mclButton = new JMenuItem("Markov Clustering"); JMenuItem predefinedButton = new JMenuItem("Predefined Clustering"); JMenuItem frButton = new JMenuItem("Fruchterman"); JMenuItem imageButton = new JMenuItem("Export"); public void initPanel(){ System.out.println("Initializing MedusaAppletPanel"); String settingsParam=getParameter("settings"); setLocalStringSettings(new MedusaSettings(settingsParam)); String linkStart=getParameter("linkStart"); String linkEnd=getParameter("linkEnd"); System.out.println(linkStart); //MedusaAppletPanel panel=new MedusaAppletPanel(getLocalStringSettings(), this, linkStart, linkEnd); setPanel(new MedusaAppletPanel(getLocalStringSettings(), this, linkStart, linkEnd)); getPanel().stop(); } public void init(){ // first, lets find out how large the panel should be. int myX=getParameter("X")==null ? 900:Integer.parseInt(getParameter("X")); int myY=getParameter("Y")==null ? 900:Integer.parseInt(getParameter("Y")); // check the size System.out.println("size: "+myX+" "+myY); // create panels and such initPanel(); // get the dataloader and set the size DataLoader dl = new DataLoader(myX,myY); // get the graph String edges = getParameter("edges"); String nodes = getParameter("nodes"); Graph g = dl.readParameters(edges,nodes); // check if g is null. that should not be the case. if (g==null) throw new RuntimeException("Graph is null!"); // convert node positions to pixel position dl.convertToRealDistances(g); // add the graph to the panel panel.setGraph(g); // set things such as arrows, interactions etc setPrefs(); // lay out the graph if necessary String layoutParam=getParameter("layout"); if (layoutParam!=null){ if (layoutParam.compareTo("true")==0){ getPanel().energy(); } } // add the panels to the applet frame Container content = getContentPane(); content.setLayout(new BorderLayout()); setJScrollPane(new JScrollPane(getPanel())); content.add("Center", getJScrollPane()); controlPanel=new JPanel(); populateControlPanel(); content.add("South",controlPanel); //pack(); } public void setPrefs(){ //netPanel.setImage(image); getPanel().setPretty(true); getPanel().setArrows(false); getPanel().setLabel(true); getPanel().setConfidence(true); getPanel().setCool(true); getPanel().repaint(); } public void populateControlPanel(){ controlPanel.setLayout(new GridLayout(1,5)); controlPanel.setBackground(babyBlue); relax.setBackground(babyBlue); pretty.setBackground(babyBlue); names.setBackground(babyBlue); layout_menu.setBackground(babyBlue); clustering_menu.setBackground(babyBlue); controlPanel.add(relax); relax.addItemListener(this); controlPanel.add(pretty); pretty.addItemListener(this); controlPanel.add(names); names.addItemListener(this); layout_menu.add(frButton); frButton.setBackground(babyBlue);frButton.addActionListener(this); layout_menu.add(randomButton); randomButton.setBackground(babyBlue);randomButton.addActionListener(this); layout_menu.add(circularButton); circularButton.setBackground(babyBlue);circularButton.addActionListener(this); layout_menu.add(gridButton); gridButton.setBackground(babyBlue);gridButton.addActionListener(this); layout_menu.add(hierarchicalButton);hierarchicalButton.setBackground(babyBlue); hierarchicalButton.addActionListener(this); layout_menu.add(geometryButton); geometryButton.setBackground(babyBlue);geometryButton.addActionListener(this); clustering_menu.add(predefinedButton);predefinedButton.setBackground(babyBlue); predefinedButton.addActionListener(this); clustering_menu.add(kmeansButton); kmeansButton.setBackground(babyBlue);kmeansButton.addActionListener(this); clustering_menu.add(affinityButton); affinityButton.setBackground(babyBlue);affinityButton.addActionListener(this); clustering_menu.add(mclButton);mclButton.setBackground(babyBlue); mclButton.addActionListener(this); jMenuBar1.add(layout_menu); jMenuBar1.add(clustering_menu); controlPanel.add(jMenuBar1); getPanel().repaint(); } public void destroy() { //netPanel.stop(); remove(panel); } public void start() { // panel.start(); } public void startRelax() { getPanel().start(); //panel.energy(); } public void stopRelax() { getPanel().stop(); //panel.energy(); } public void stop() { panel.stop(); } public String getAppletInfo(){ return "Title: MedusaLite \nAuthor: Sean Hooper and Georgios Pavlopoulos"; } /* * Handle the button */ public void actionPerformed(ActionEvent e) { Object es=e.getSource(); if (es==frButton){ relax.setSelected(false); getPanel().energy(); } if (es == randomButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Random_Coordinates(g, getPanel()); getPanel().repaint(); } if (es == gridButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Grid_Coordinates(g, getPanel()); getPanel().repaint(); } if (es == circularButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Circular_Coordinates(g, getPanel()); getPanel().repaint(); } if (es == hierarchicalButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_GO_like_Coordinates(g, getPanel()); getPanel().repaint(); } if (es == geometryButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Distance_Geomretry_Coordinates(g, getPanel()); getPanel().repaint(); } if (es == kmeansButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Kmeans_Clustering(g, getPanel()); getPanel().repaint(); } if (es == affinityButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Affinity_Propagation_Clustering(g, getPanel()); getPanel().repaint(); } if (es == mclButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_MCL_Propagation_Clustering(g, getPanel()); getPanel().repaint(); } if (es == predefinedButton){ getPanel().stop(); Graph g = getPanel().getGraph(); Layouts.Apply_Predefined_Clustering(g, getPanel()); getPanel().repaint(); } } /* * Handle item state changes */ public void itemStateChanged(ItemEvent e){ Object src = e.getSource(); if (src==relax){ if (relax.isSelected()){ startRelax(); //panel.energy(); } else stopRelax(); } if (src == pretty){ getPanel().setPretty(pretty.isSelected()); getPanel().repaint(); } if (src == names){ getPanel().setLabel(names.isSelected()); getPanel().repaint(); } } /** * * Paints the container. This forwards the paint to any lightweight * components that are children of this container. If this method is * reimplemented, super.paint(g) should be called so that lightweight * components are properly rendered. If a child component is entirely * clipped by the current clipping setting in g, paint() will not be * forwarded to that child. * * @param g the specified Graphics window * @see Component#update(Graphics) */ public void paint(Graphics g) { super.paint(g); } public void setLocalStringSettings(MedusaSettings stringSettings) { this.stringSettings = stringSettings; } public void setPanel(BasicGraphPanel panel) { this.panel = panel; } public BasicGraphPanel getPanel() { return panel; } public int getXParam() { return xParam; } public void setXParam(int xParam) { this.xParam = xParam; } public int getYParam() { return yParam; } public void setYParam(int yParam) { this.yParam = yParam; } public MedusaSettings getLocalStringSettings() { return stringSettings; } public JScrollPane getJScrollPane() { return jScrollPane; } public void setJScrollPane(JScrollPane jScrollPane) { this.jScrollPane = jScrollPane; } /** * Add controllers for javascript! * Some examples follow. Remember to repaint! * */ public void setHideWhenMoveJS(boolean hwm){ getPanel().setHideWhenMove(hwm); } public void setArrowsJS(boolean arrows){ getPanel().setArrows(arrows); getPanel().repaint(); } public void setPrettyJS(boolean tof){ getPanel().setPretty(tof); getPanel().repaint(); } public void setConfidenceJS(boolean tof){ getPanel().setConfidence(tof); getPanel().repaint(); } }

Ads help maintain this website.