// 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;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JToggleButton;
import javax.swing.KeyStroke;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.ProgressMonitor;
import javax.swing.Timer;
import java.awt.Cursor;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import medusa.dataio.DataLoader;
import medusa.display.EditableGraphPanel;
import medusa.graph.Graph;
import medusa.graph.Node;
import medusa.graphedit.EditGraphDialog;


/**
 * The main holding and controlling frame for the graph displaying
 * panels. For documentation on how to use Medusa, see the online
 * manual {@link http://www.bork.embl.de/medusa}
 * @author Sean Hooper
 * @version 1.0
 */
public final class MedusaFrameBackup extends JFrame
        implements
        ItemListener,
        ComponentListener,
        ChangeListener{
    
    // this class should not directly require StringletPanel...
    // use reflection
    EditableGraphPanel stringletPanel;
    
    // test here
    //Object stringletPanel;
    MedusaSettings stringSettings;
    
    
    static final Color darkBackground = new Color(0.33f,0.0f,0.0f);
    static final Color foreground = new Color(1.0f,1.0f,1.0f);
    /**
     * The main color of components
     */
    public static final Color STRINGCOLOR=new Color(161, 173, 236);
    Color background = STRINGCOLOR;
    Border graphBorder = BorderFactory.createRaisedBevelBorder();
    
    //scrollable panel
    JScrollPane jScrollPane;
    // a holder frame for dialogs etc
    Frame f=new Frame();
    
    // version number
    public static final String version="1.042";
    
    public MedusaFrameBackup(){
        super("Medusa "+version);
        //init();
    }
    
    /**
     * Initializes the main panel
     */
    private final void init(){
        //setLnF();
        stringSettings = new MedusaSettings();
        //stringSettings.init();
        
        stringletPanel = new EditableGraphPanel(stringSettings);
        //Frame f = new Frame();
        stringletPanel.setBasicEdgeColor(java.awt.Color.black);
        stringletPanel.setTimeFrameXY(600,600);
        stringletPanel.setBorder(graphBorder);
        stringletPanel.setShowBorder(false);
        stringletPanel.setArrows(false);
        stringletPanel.setCool(true);
        jScrollPane=new JScrollPane(stringletPanel);
        egd = new EditGraphDialog(this, true);
        buildGUI();
        
    }
    
    
    
    protected void buildGUI(){
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addComponentListener(this);
        Container content = getContentPane();
        content.setLayout(new BorderLayout());
        
        // add the menus
        menuBar.setBackground(background);
        
        populateFileMenu();
        menuBar.add(fileMenu);
        populateSelectMenu();
        menuBar.add(selectMenu);
        populateOptionMenu();
        menuBar.add(optionMenu);
        populateManipulateMenu();
        menuBar.add(manipulateMenu);
        populateInteractionMenu();
        menuBar.add(interactionMenu);
        populateDisplayMenu();
        menuBar.add(displayMenu);
        populateHelpMenu();
        menuBar.add(helpMenu);
        setJMenuBar(menuBar);
        
        
        // add the controls
        controlPanel=new JPanel();
        populateControlPanel();
        
        // set borders
        controlPanel.setBorder(graphBorder);
        //scalerPanel.setBorder(graphBorder);
        
        // add components
        content.add("Center",jScrollPane); // added scrollpane instead of stringletPanel
        content.add("South",controlPanel);
        populateLegendPanel();
        populateScalerPanel();
        content.add("East",scalerPanel);
        // add keyboard bindings
        //addKeyBindings();
        
        
    }
    
    /**
     * Loads a data file without threading. Useful for loading
     * graphs before start-up
     * @param data
     * @throws java.io.IOException
     * @throws medusa.DataFormatException
     */
    public void loadData(String data, boolean medusa) throws IOException, DataFormatException{
        System.out.println("Loading "+data+". Please wait");
        dl = new DataLoader();
        Graph g=null;
        if(medusa)
            g=dl.load(data);
        else
                g=dl.loadSimplest(data);
        stringletPanel.setGraph(g);
        
    }
    
    private final void loadInteractionSettings(String interactionSettings)throws IOException{
        stringSettings.load(interactionSettings);
        updateLegend();
        stringletPanel.updateStringSettings(stringSettings);
    }
    
    void initData(){
        try {
            boolean weng=loadSettings();
            defaultNet();
            if (stringletPanel==null)
                System.out.println("stringletPanel is null");
            if (weng){
                //stringletPanel.loadingMessage();
                //stringletPanel.loadGraph(lastDir);
                
                waitForLoad(lastDir, DataLoader.LOAD_MEDUSA);
            }
            //else
            //	 defaultNet();
            //updateInfo();
            
        }
        
        catch (IOException ie) {
            defaultNet();
        } catch (DataFormatException de){
            JOptionPane.showMessageDialog
                    (this, de.getMessage(),
                    "Data Error", JOptionPane.ERROR_MESSAGE);
            defaultNet();
        }
        
    }
    
    public void defaultNet(){}
    
    /*public void addKeyBindings(){
        System.out.println("key bindings added?");
        InputMap im = stringletPanel.getInputMap();
        ActionMap am = stringletPanel.getActionMap();
        KeyStroke key = KeyStroke.getKeyStroke("r");
        im.put(key,"toggleRelax");
        am.put("toggleRelax",toggleRelax);
        }*/
    
    public static void main(String [] args){
        //Make sure we have nice window decorations.
        MedusaFrameBackup.setLnF();
        //JFrame.setDefaultLookAndFeelDecorated(true);
        MedusaFrameBackup stringletFrame = new MedusaFrameBackup();
        stringletFrame.init();
        
        try {
            // do we have args?
            stringletFrame.checkArgs(args);
        } catch (DataFormatException ex) {
            System.out.println("Data format error! Check your data.");
            ex.printStackTrace();
            System.exit(0);
        } catch (IOException ex) {
            System.out.println("File error! Check the integrity of your file.");
            ex.printStackTrace();
            System.exit(0);
        }
        
        //stringletFrame.init();
        stringletFrame.pack();
        centerWindow(stringletFrame);
        stringletFrame.setVisible(true);
        //stringletFrame.initData();
        
    }
    
    public void checkArgs(String[] args)throws IOException, DataFormatException{
        // use the format
        // f 
        // i 
        System.out.println("Checking arguments");
        int ln = args.length;
        //System.out.println(args.length);
        // should be 0, 2 or 4
        if (ln==0){
            System.out.println("No arguments. Proceeding normally");
            initData();
            return;
        }
        if (ln==2){
            
            checkArgPair(args);
            return;
        }
        if (ln==4){
            
            checkArgPair(new String[]{args[0],args[1]});
            checkArgPair(new String[]{args[2],args[3]});
            return;
        }
    }
    
    private void checkArgPair(String[] args)throws IOException, DataFormatException{
        
        if (args[0].compareTo("f")==0){
            loadData(args[1],true);
        }
        if (args[0].compareTo("i")==0){
            loadInteractionSettings(args[1]);
        }
        if (args[0].compareTo("t")==0){
            loadData(args[1],false);
        }
        
    }
    
    
    public static void setLnF(){
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        Color silly = new Color(255,255,255);
        javax.swing.plaf.ColorUIResource weng = new
                javax.swing.plaf.ColorUIResource(silly);
        /*UIManager.put("InternalFrame.activeTitleBackground", weng);
        UIManager.put("MenuItem.background", STRINGCOLOR);
        UIManager.put("MenuItem.foreground", weng);
        UIManager.put("MenuItem.selectionBackground", STRINGCOLOR.darker());
        UIManager.put("MenuItem.selectionForeground", weng);
         
        UIManager.put("CheckBoxMenuItem.background", STRINGCOLOR);
        UIManager.put("CheckBoxMenuItem.foreground", weng);
        UIManager.put("CheckBoxMenuItem.selectionBackground", STRINGCOLOR.darker());
        UIManager.put("CheckBoxMenuItem.selectionForeground", weng);
         
        UIManager.put("Menu.background", STRINGCOLOR);
        UIManager.put("Menu.foreground", weng);
        UIManager.put("Menu.selectionBackground", STRINGCOLOR.darker());
        UIManager.put("Menu.selectionForeground", weng);*/
        //UIManager.put("Menu.background", background);
        //UIManager.put("Menu.foreground", weng);
    }
    
    
    public static void centerWindow(java.awt.Window win){
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = win.getSize();
        win.setLocation((screenSize.width - (frameSize.width)) / 2,
                (screenSize.height - (frameSize.height)) / 2);
    }
    
    // FR button
    JButton frButton = new JButton("Spring");
    JButton stringButton = new JButton("Data");
    // controlPanel
    JPanel controlPanel;
    JToggleButton relax=new JToggleButton("Relax",false);
    JToggleButton temperatureButton=new JToggleButton("Cooling",true);
    JLabel fileLabel=new JLabel("File: none");
    JLabel infoLabel=new JLabel("nodes: 0
edges: 0
"); JLabel emptyLabel=new JLabel(" "); JButton recalcButton = new JButton("Recalculate"); private void populateControlPanel(){ controlPanel.add(fileLabel); controlPanel.add(infoLabel); controlPanel.add(emptyLabel); controlPanel.add(relax); relax.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent ex) { if (relax.isSelected()){ stringletPanel.start(); } else stringletPanel.stop(); } }); controlPanel.add(temperatureButton); temperatureButton.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setCool(temperatureButton.isSelected() ); } } ); controlPanel.add(stringButton); stringButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringConnection(); } } ); controlPanel.add(frButton); frButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stopRelax(); // disabled for now stringletPanel.energy(); //stringletPanel.repaint(); } } ); controlPanel.add(recalcButton); recalcButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { recalcEvent(); //stringletPanel.autoFixOrientation(); // disabled for now //stringletPanel.repaint(); } } ); } private Action toggleRelax = new AbstractAction(){ public void actionPerformed(ActionEvent e){ //System.out.println("action fired"); boolean relaxOn = relax.isSelected(); if (!relaxOn) stringletPanel.start(); else stringletPanel.stop(); relax.setSelected(!relaxOn); } }; // update the info label private void updateInfo(){ String[] result=stringletPanel.getGraphData(); String display="nodes: "+ result[0]+"
edges: "+result[1]+"
"; infoLabel.setText(display); } private void updateFileInfo(){ fileLabel.setText(lastFile); //fileLabel.setToolTip(lastDir); } // Set up the legend and scaler panel JPanel scalerPanel = new JPanel(); //Box scalerPanel = new Box(X_AXIS); JLabel scalerLabel = new JLabel(" Scale"); JSlider scalerSlider = new JSlider(JSlider.VERTICAL,100,300,100); private void populateScalerPanel(){ scalerPanel.setLayout(new BoxLayout(scalerPanel,BoxLayout.Y_AXIS)); //scalerPanel.setLayout(new java.awt.GridLayout(0, 1, 5, 5)); scalerPanel.setOpaque(true); scalerPanel.setBackground(background); scalerSlider.setMajorTickSpacing(50); scalerSlider.setMinorTickSpacing(10); scalerSlider.setPaintTicks(true); scalerSlider.setPaintLabels(true); scalerSlider.setBackground(background); scalerSlider.setForeground(foreground); scalerPanel.setBackground(background); scalerPanel.setForeground(foreground); legendPanel.setAlignmentX(LEFT_ALIGNMENT); scalerSlider.setAlignmentX(LEFT_ALIGNMENT); scalerLabel.setAlignmentX(LEFT_ALIGNMENT); scalerLabel.setForeground(foreground); scalerPanel.add(legendPanel); scalerPanel.add(scalerLabel); scalerPanel.add(scalerSlider); scalerSlider.addChangeListener(this); } //private void updateLegend(){ // Set up the Options menu JMenu optionMenu = new JMenu("Options"); JMenu selectMenu = new JMenu("Select"); JMenu colorMenu = new JMenu("Color"); JMenu imageMenu = new JMenu("Image"); JMenu fontMenu = new JMenu("Font"); JMenuItem selectAllMenuItem = new JMenuItem("All"); JMenuItem selectNoneMenuItem = new JMenuItem("None"); JMenuItem searchMenuItem = new JMenuItem("Search"); JMenuItem selectNodeFromFileMenuItem = new JMenuItem("From file"); JMenuItem invertFixMenuItem = new JMenuItem("Invert"); JMenuItem selectGrowMenuItem = new JMenuItem("Grow selection"); //JMenuItem changeSizeMenuItem = new JMenuItem("Change panel Size"); JMenuItem changeColorMenuItem = new JMenuItem("Change node color"); JMenuItem switchColorMenuItem = new JMenuItem("Switch channels"); JMenuItem copyColorMenuItem = new JMenuItem("Copy channels"); JMenuItem xGradientColorMenuItem = new JMenuItem("X gradient"); JMenuItem changeNodeSizeMenuItem = new JMenuItem("Change node size"); JMenuItem selectNodeLabelByRegExpMenuItem = new JMenuItem("By label"); JMenuItem selectNodeAnnotationByRegExpMenuItem = new JMenuItem("By annotation"); JMenuItem addNodeMenuItem = new JMenuItem("Add nodes"); JMenuItem setLabelColorMenuItem = new JMenuItem("Label"); JMenuItem setBasicEdgeColorMenuItem = new JMenuItem("Base color"); JMenuItem loadImageMenuItem = new JMenuItem("Load"); JMenuItem setBackgroundColorMenuItem = new JMenuItem("Background"); JMenuItem changeFontSizeMenuItem = new JMenuItem("Font size"); JMenuItem clearImageMenuItem = new JMenuItem("Clear"); JMenuItem setEdgeLenMenuItem = new JMenuItem("Edge Length"); private void populateOptionMenu(){ optionMenu.setMnemonic(KeyEvent.VK_O); colorMenu.setMnemonic(KeyEvent.VK_C); fontMenu.setMnemonic(KeyEvent.VK_F); // searchMenuItem.addActionListener(new java.awt.event.ActionListener() { // public void actionPerformed(java.awt.event.ActionEvent e) { // // searchNodeEvent();} // } ); changeColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { changeColorEvent();} } ); switchColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { switchColorEvent();} } ); copyColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { copyColorEvent();} } ); xGradientColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringletPanel.addGradientX(2);} } ); changeNodeSizeMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { changeNodeSizeEvent();} } ); /*addNodeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EditNodeDialog dialog = new EditNodeDialog(); dialog.showDialog(); if(dialog.getStatus() == EditNodeDialog.NET_CHANGED) { stringletPanel.repaint(); } } });*/ setBasicEdgeColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setBasicEdgeColorEvent();} } ); setLabelColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setLabelColorEvent();} } ); setBackgroundColorMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setBackgroundColorEvent();} } ); loadImageMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { loadImageEvent();} } ); clearImageMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { clearImageEvent();} } ); changeFontSizeMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { changeFontSizeEvent();} } ); setEdgeLenMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setEdgeLenEvent();} } ); colorMenu.add(changeColorMenuItem); colorMenu.add(switchColorMenuItem); colorMenu.add(copyColorMenuItem); // colorMenu.add(xGradientColorMenuItem); optionMenu.setBackground(background); optionMenu.setForeground(foreground); //optionMenu.add(searchMenuItem); //optionMenu.add(changeSizeMenuItem); optionMenu.add(changeNodeSizeMenuItem); optionMenu.add(setEdgeLenMenuItem); colorMenu.addSeparator(); colorMenu.add(setBasicEdgeColorMenuItem); fontMenu.add(setLabelColorMenuItem); colorMenu.add(setBackgroundColorMenuItem); optionMenu.addSeparator(); //optionMenu.add(selectMenu); optionMenu.add(colorMenu); fontMenu.add(changeFontSizeMenuItem); optionMenu.add(fontMenu); optionMenu.addSeparator(); imageMenu.add(loadImageMenuItem); imageMenu.add(clearImageMenuItem); optionMenu.add(imageMenu); } private void populateSelectMenu(){ selectMenu.setBackground(background); selectMenu.setForeground(foreground); selectMenu.setMnemonic(KeyEvent.VK_S); selectNodeLabelByRegExpMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { searchNodeEvent(true);} } ); selectNodeAnnotationByRegExpMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { searchNodeEvent(false);} } ); selectNodeFromFileMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { selectNodeFromFileEvent();} } ); selectAllMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringletPanel.setFix(true);} } ); selectNoneMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringletPanel.setFix(false);} } ); invertFixMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringletPanel.invertFix();} } ); selectGrowMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stringletPanel.growSelection();} } ); selectAllMenuItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_A, ActionEvent.ALT_MASK)); selectNoneMenuItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_Q, ActionEvent.ALT_MASK)); selectMenu.add(selectAllMenuItem); selectMenu.add(selectNoneMenuItem); selectMenu.add(selectNodeLabelByRegExpMenuItem); selectMenu.add(selectNodeAnnotationByRegExpMenuItem); selectMenu.add(selectNodeFromFileMenuItem); selectMenu.add(invertFixMenuItem); selectMenu.add(selectGrowMenuItem); } // manipulate data menu JMenu manipulateMenu = new JMenu("Manipulate"); JMenu rotateMenu = new JMenu("Rotate"); JMenu flipMenu = new JMenu("Flip"); JMenuItem rotateRightMenuItem = new JMenuItem("90d clockwise"); JMenuItem rotateLeftMenuItem = new JMenuItem("90d anti-clockwise"); JMenuItem flipXItem = new JMenuItem("Vertical"); JMenuItem flipYItem = new JMenuItem("Horizontal"); JMenuItem deleteNodeMenuItem = new JMenuItem("Delete nodes"); JMenuItem changeNodeShapeMenuItem = new JMenuItem("Change node shape"); JMenuItem cropMenuItem = new JMenuItem("Crop graph"); JMenuItem randomGraphMenuItem = new JMenuItem("Random graph"); JMenuItem clearGraphMenuItem = new JMenuItem("Clear graph"); JMenuItem editGraphMenuItem = new JMenuItem("Edit graph"); private void populateManipulateMenu(){ manipulateMenu.setMnemonic(KeyEvent.VK_M); changeNodeShapeMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setShapeEvent();} } ); deleteNodeMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { stopRelax(); stringletPanel.removeFixedNodes(); //stringletPanel.updateNodes(); updateInfo(); stringletPanel.repaint(); } }); cropMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { String confidence = (String)JOptionPane.showInputDialog ("Choose minimum confidence level:" + "", "1.0"); if (confidence!=null){ stringletPanel.crop(Double.parseDouble(confidence)); updateInfo(); stringletPanel.repaint(); } } }); randomGraphMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { getRandomGraphEvent();} } ); clearGraphMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { clearGraphEvent();} } ); rotateRightMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { rotateEvent(Math.PI/2);} } ); rotateLeftMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { rotateEvent(-Math.PI/2);} } ); flipXItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { flipX();} } ); flipYItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { flipY();} } ); editGraphMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { editGraph();} } ); manipulateMenu.add(clearGraphMenuItem); manipulateMenu.add(changeNodeShapeMenuItem); manipulateMenu.add(deleteNodeMenuItem); manipulateMenu.add(cropMenuItem); manipulateMenu.add(randomGraphMenuItem); manipulateMenu.setForeground(foreground); manipulateMenu.setBackground(background); rotateMenu.add(rotateRightMenuItem); rotateMenu.add(rotateLeftMenuItem); flipMenu.add(flipXItem); flipMenu.add(flipYItem); manipulateMenu.add(rotateMenu); manipulateMenu.add(flipMenu); manipulateMenu.addSeparator(); manipulateMenu.add(editGraphMenuItem); } // Set up the File menu JMenu fileMenu=new JMenu("File"); JMenuBar menuBar=new JMenuBar(); JMenuItem openMenuItem = new JMenuItem("Open"); JMenu addSubractMenu = new JMenu("Add/Subtract"); JMenuItem addMenuItem = new JMenuItem("Add graph"); JMenuItem subtractMenuItem = new JMenuItem("Subtract graph"); JMenuItem copyMenuItem = new JMenuItem("Copy settings"); JMenu importMenu = new JMenu("Import"); JMenuItem importTabbedMenuItem = new JMenuItem("Simple tabbed"); JMenuItem saveMenuItem = new JMenuItem("Save"); JMenuItem saveHTMLParametersMenuItem = new JMenuItem("HTML Parameters"); JMenu exportMenu=new JMenu("Export"); JMenu exportImageMenu = new JMenu("Image"); JMenu exportPostscriptMenu = new JMenu("PostScript"); JMenuItem exportJPGMenuItem = new JMenuItem("JPG"); JMenuItem exportPNGMenuItem = new JMenuItem("PNG"); JMenuItem quitMenuItem = new JMenuItem("Quit"); JMenuItem exportPSMenuItem = new JMenuItem("PS"); JMenuItem exportEPSMenuItem = new JMenuItem("EPS"); JMenuItem exportPajekMenuItem = new JMenuItem("Pajek"); protected void populateFileMenu(){ fileMenu.setMnemonic(KeyEvent.VK_F); quitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { quitApplication();} } ); openMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { loadEvent(DataLoader.LOAD_MEDUSA);} } ); addMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { addGraphEvent();} } ); subtractMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { subtractGraphEvent();} } ); copyMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { copyGraphEvent();} } ); saveMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { saveEvent();} } ); saveHTMLParametersMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { saveHTMLParametersEvent();} } ); exportJPGMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { exportImageEvent(false);} } ); exportPNGMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { exportImageEvent(true);} } ); exportPSMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { exportPSEvent();} }); exportEPSMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { exportEPSEvent();} } ); exportPajekMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { exportPajekEvent();} } ); importTabbedMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { loadEvent(DataLoader.LOAD_TABBED);} }); fileMenu.setBackground(background); fileMenu.setForeground(foreground); fileMenu.add(openMenuItem); fileMenu.add(addSubractMenu); // build addSubtract addSubractMenu.add(addMenuItem); addSubractMenu.add(subtractMenuItem); addSubractMenu.add(copyMenuItem); fileMenu.add(importMenu); fileMenu.add(saveMenuItem); // the export submenu exportImageMenu.add(exportJPGMenuItem); exportImageMenu.add(exportPNGMenuItem); exportPostscriptMenu.add(exportPSMenuItem); exportPostscriptMenu.add(exportEPSMenuItem); exportMenu.add(exportImageMenu); exportMenu.add(exportPostscriptMenu); exportMenu.add(exportPajekMenuItem); exportMenu.add(saveHTMLParametersMenuItem); importMenu.add(importTabbedMenuItem); fileMenu.add(exportMenu); fileMenu.addSeparator(); fileMenu.add(quitMenuItem); } // set up the interactions menu JMenu interactionMenu = new JMenu("Interaction"); JMenuItem loadInteractionMenuItem = new JMenuItem("Load"); JMenu stringDefaultMenu = new JMenu("STRING default"); JMenuItem stringProteinInteractionMenuItem = new JMenuItem("Protein"); JMenuItem stringCOGInteractionMenuItem = new JMenuItem("COGS"); JMenuItem hideShowMenuItem = new JMenuItem("Hide"); protected void populateInteractionMenu(){ interactionMenu.setMnemonic(KeyEvent.VK_I); loadInteractionMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { interactionEvent();} }); stringProteinInteractionMenuItem.addActionListener (new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { proteinInteractionEvent();} }); stringCOGInteractionMenuItem.addActionListener (new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { cogInteractionEvent();} }); hideShowMenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { hideShowInteractionsEvent();} }); interactionMenu.add(loadInteractionMenuItem); stringDefaultMenu.add(stringProteinInteractionMenuItem); stringDefaultMenu.add(stringCOGInteractionMenuItem); interactionMenu.add(stringDefaultMenu); interactionMenu.addSeparator(); interactionMenu.add(hideShowMenuItem); interactionMenu.setBackground(background); interactionMenu.setForeground(foreground); } // set up the display menu JMenu displayMenu = new JMenu("Display"); JCheckBoxMenuItem confidenceCBMItem=new JCheckBoxMenuItem("Confidence",true); JCheckBoxMenuItem prettyCBMItem=new JCheckBoxMenuItem("Interactions",false); JCheckBoxMenuItem namesCBMItem = new JCheckBoxMenuItem("Labels", true); JCheckBoxMenuItem showNamesCBMItem = new JCheckBoxMenuItem("Show names", true); JCheckBoxMenuItem directedCBMItem=new JCheckBoxMenuItem("Directed",false); JCheckBoxMenuItem hideWhenMoveCBMItem=new JCheckBoxMenuItem("Hide when move",false); JCheckBoxMenuItem alphaCBMItem=new JCheckBoxMenuItem("Alpha conf",true); JMenu nodeColorDisplayMenu = new JMenu("Node color set"); JRadioButton channel1MenuItem = new JRadioButton("1",true); JRadioButton channel2MenuItem = new JRadioButton("2"); JRadioButton channel3MenuItem = new JRadioButton("3"); ButtonGroup nodeColorSetGroup = new ButtonGroup(); protected void populateDisplayMenu(){ displayMenu.setMnemonic(KeyEvent.VK_D); prettyCBMItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_I, ActionEvent.ALT_MASK)); prettyCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setPretty(prettyCBMItem.isSelected()); stringletPanel.repaint();} } ); namesCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setLabel(namesCBMItem.isSelected()); stringletPanel.repaint();} } ); showNamesCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setShowName(showNamesCBMItem.isSelected()); stringletPanel.repaint();} } ); confidenceCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setConfidence(confidenceCBMItem.isSelected()); stringletPanel.repaint();} } ); directedCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setArrows(directedCBMItem.isSelected()); stringletPanel.repaint();} } ); hideWhenMoveCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setHideWhenMove(hideWhenMoveCBMItem.isSelected()); stringletPanel.repaint();} } ); alphaCBMItem.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { stringletPanel.setAlpha(alphaCBMItem.isSelected()); stringletPanel.repaint();} } ); channel1MenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setNodeColorSet(1);} }); channel2MenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setNodeColorSet(2);} }); channel3MenuItem.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setNodeColorSet(3);} }); displayMenu.setBackground(background); displayMenu.setForeground(foreground); displayMenu.add(prettyCBMItem); displayMenu.add(namesCBMItem); displayMenu.add(showNamesCBMItem); displayMenu.add(directedCBMItem); displayMenu.add(confidenceCBMItem); displayMenu.add(alphaCBMItem); displayMenu.addSeparator(); displayMenu.add(hideWhenMoveCBMItem); displayMenu.addSeparator(); nodeColorDisplayMenu.add(channel1MenuItem); nodeColorDisplayMenu.add(channel2MenuItem); nodeColorDisplayMenu.add(channel3MenuItem); nodeColorSetGroup.add(channel1MenuItem); nodeColorSetGroup.add(channel2MenuItem); nodeColorSetGroup.add(channel3MenuItem); displayMenu.add(nodeColorDisplayMenu); } /* Set up the help menu */ JMenu helpMenu = new JMenu("Help"); JMenuItem aboutMenuItem = new JMenuItem("About Medusa"); protected void populateHelpMenu(){ aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { aboutEvent();} }); helpMenu.add(aboutMenuItem); helpMenu.setBackground(background); helpMenu.setForeground(foreground); } /* legend panel will hold the interaction names and colors */ //JLabel legendTitle = new JLabel(" Interactions"); JPanel legendPanel=new JPanel(); JToggleButton[] toggleButton; protected void populateLegendPanel(){ //legendPanel.setLayout(new java.awt.GridLayout(0, 1, 5, 5)); legendPanel.setLayout(new BoxLayout(legendPanel, BoxLayout.Y_AXIS)); legendPanel.setOpaque(true); legendPanel.setBackground(background); initLegendTitle(); legendPanel.add(legendTitlePanel); initLegendScroller(); legendPanel.add(legendScroller); } public void updateLegend(){ //System.out.println("settings updated"); //scalerPanel.removeAll(); legendPanel.removeAll(); initLegendScroller(); legendPanel.add(legendTitlePanel); legendPanel.add(legendScroller); legendPanel.validate(); //legendScroller.validate(); //scalerPanel.add(legendTitlePanel); //scalerPanel.add(legendScroller); //scalerPanel.add(legendPanel); //scalerPanel.add(scalerLabel); //scalerPanel.add(scalerSlider); scalerPanel.validate(); scalerPanel.repaint(); //populateScalerPanel(); //legendPanel.removeAll(); //initLegend(); //legendPanel.validate(); } JLabel legendTitleLabel; JPanel legendTitlePanel; JLabel logoLabel; private void initLegendTitle(){ legendTitlePanel=new JPanel(); legendTitlePanel.setLayout(new BoxLayout (legendTitlePanel,BoxLayout.Y_AXIS)); legendTitlePanel.setOpaque(true); legendTitlePanel.setBackground(background); logoLabel=new JLabel(); legendTitleLabel = new JLabel("Interactions"); legendTitleLabel.setBackground(background); legendTitleLabel.setForeground(foreground); java.net.URL imageURL = this.getClass().getResource ("/medusa/images/medusa_logo_small.png"); logoLabel.setIcon(new javax.swing.ImageIcon(imageURL)); legendTitlePanel.add(logoLabel); legendTitlePanel.add(legendTitleLabel); } JScrollPane legendScroller; private void initLegendScroller(){ Dimension legendSize=new Dimension(150,100); //legendScrollPane.setPreferredSize(legendSize); // ShowEdgeMultiPanel sp = new ShowEdgeMultiPanel // (this,stringSettings); // sp.setBackground(background); // legendScroller = new JScrollPane(sp); legendScroller.setPreferredSize(legendSize); legendScroller.revalidate(); } // a yes/no dialogue private int yes_no(String message){ int s = JOptionPane.showConfirmDialog (this, message, "Confirm", JOptionPane.YES_NO_OPTION); return s; } private void clearGraphEvent(){ stopAllRelax(); if (yes_no("Your data will be lost. Are you sure?")==0){ stringletPanel.clearGraph(); stringletPanel.repaint(); updateInfo(); } } private void recalcEvent(){ stopAllRelax(); if (yes_no("This will return edge length \nand orientation to default values\n Are you sure you want to do this?")==0){ stringletPanel.autoFixOrientation(); stringletPanel.calculateEdgeLength(); stringletPanel.repaint(); } } private void rotateEvent(double degrees){ stopAllRelax(); stringletPanel.rotate(degrees); stringletPanel.repaint(); } private void flipEvent(boolean x, boolean y){ stopAllRelax(); stringletPanel.mirror(x,y); stringletPanel.repaint(); } private void flipX(){ flipEvent(true,false); } private void flipY(){ flipEvent(false,true); } EditGraphDialog egd; private void editGraph(){ stopAllRelax(); egd=new EditGraphDialog(this,true); egd.setGraph(stringletPanel.getGraph()); egd.setVisible(true); Graph g=egd.getGraph(); if (g!=null){ stringletPanel.setGraph(g); stringletPanel.repaint(); } } // allow for user defined data connections // from pull-down menu // TODO // scan the plugin directory for suitable // TODO // default data connection // MedusaDataConnection mc = new medusa.stringconnection.Main(); // private void stringConnection(){ // String nodes=getFixedNodesAsString(); // //System.out.println("debug 600> "+nodes); // //AboutDialog.showDialog(this,null); // Graph graph = mc.getGraph(nodes, this); // stringletPanel.addGraph(graph); // stringletPanel.copyNodeSettings(graph); // // //System.out.println(graph.report()); // //graph.printNodeAnnotation(); // stringletPanel.repaint(); // updateInfo(); // } // for public version private void stringConnection(){ JOptionPane.showConfirmDialog(this,"STRING requires a license and is not\navailable to open source", "Disabled",JOptionPane.PLAIN_MESSAGE,JOptionPane.INFORMATION_MESSAGE); } // version number for medusa! remember to update it! private void aboutEvent(){ AboutDialog.showDialog(this,null, version); } private void setShapeEvent(){ Object[] shapes = {"circle","rectangle","triangle","diamond"}; int s =JOptionPane.showOptionDialog (this, "Choose a node shape", "Shape", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, shapes, "circle"); // If a string was returned, say so. stringletPanel.setShape(s); //System.out.println("Green eggs and... " + s + "!"); return; } public void loadImageEvent(){ stringletPanel.stop(); relax.setSelected(false); FileDialog fdLoad = new FileDialog (this, "Load image",FileDialog.LOAD); fdLoad.setVisible(true); String loadFile=fdLoad.getFile(); String dir=fdLoad.getDirectory(); if (loadFile!=null){ try{ stringletPanel.setImage(dir+loadFile); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "The image could not be found or opened", "Load Error", JOptionPane.ERROR_MESSAGE); } } stringletPanel.repaint(); } private void stopAllRelax(){ stringletPanel.stop(); relax.setSelected(false); controlPanel.repaint(); } public void clearImageEvent(){ stopAllRelax(); stringletPanel.clearImage(); stringletPanel.repaint(); } public void quitApplication(){ stopAllRelax(); System.out.println("Closing application"); try{ saveSettings(); System.out.println("Current settings saved"); } catch (IOException ie){ System.out.println("...settings not saved due to file problems"); } remove(stringletPanel); System.exit(0); } private void loadEvent(int loadType){ stopAllRelax(); scaleOut(); FileDialog fdLoad = new FileDialog (this, "Load graph",FileDialog.LOAD); if (lastDir!=null) fdLoad.setDirectory(lastDir); fdLoad.setFilenameFilter(new DataFileFilter()); fdLoad.setVisible(true); String loadFile=fdLoad.getFile(); String dir=fdLoad.getDirectory(); if (loadFile!=null){ try{ //stringletPanel.loadGraph(dir+loadFile); waitForLoad(dir+loadFile, loadType); lastDir=dir; lastFile=loadFile; //System.out.println(lastFile); } catch (IOException ie){ ie.printStackTrace(); JOptionPane.showMessageDialog (this, "The file could not be found or opened", "Load Error", JOptionPane.ERROR_MESSAGE); } catch (DataFormatException dfe){ JOptionPane.showMessageDialog (this, dfe.getMessage(), "Data Error", JOptionPane.ERROR_MESSAGE); //System.exit(0); } } } private void getRandomGraphEvent(){ int s = yes_no("This will generate a random graph. Are you sure?"); //System.out.println(s); if (s==0){ stopAllRelax(); stringletPanel.randomGraph(30,60); updateInfo(); stringletPanel.repaint(); } } private void addGraphEvent(){ stopAllRelax(); scaleOut(); FileDialog fdLoad = new FileDialog (this, "Add graph",FileDialog.LOAD); if (lastDir!=null) fdLoad.setFile(lastDir+lastFile);fdLoad.setFilenameFilter(new DataFileFilter()); fdLoad.setVisible(true); String loadFile=fdLoad.getFile(); String dir=fdLoad.getDirectory(); if (loadFile!=null){ try{ stringletPanel.appendGraph(dir+loadFile); lastDir=dir+loadFile; lastFile=loadFile; updateInfo(); stringletPanel.repaint(); } catch (IOException ie){ //ie.printStackTrace(); JOptionPane.showMessageDialog (this, "The file could not be found or opened", "Load Error", JOptionPane.ERROR_MESSAGE); } catch (DataFormatException dfe){ JOptionPane.showMessageDialog (this, dfe.getMessage(), "Data Error", JOptionPane.ERROR_MESSAGE); //System.exit(0); } } } private void subtractGraphEvent(){ stopAllRelax(); scaleOut(); FileDialog fdLoad = new FileDialog (this, "Add graph",FileDialog.LOAD); if (lastDir!=null) fdLoad.setFile(lastDir+lastFile);fdLoad.setFilenameFilter(new DataFileFilter()); fdLoad.setVisible(true); String loadFile=fdLoad.getFile(); String dir=fdLoad.getDirectory(); if (loadFile!=null){ try{ stringletPanel.subtractGraph(dir+loadFile); lastDir=dir+loadFile; lastFile=loadFile; updateInfo(); stringletPanel.repaint(); } catch (IOException ie){ //ie.printStackTrace(); JOptionPane.showMessageDialog (this, "The file could not be found or opened", "Load Error", JOptionPane.ERROR_MESSAGE); } catch (DataFormatException dfe){ JOptionPane.showMessageDialog (this, dfe.getMessage(), "Data Error", JOptionPane.ERROR_MESSAGE); //System.exit(0); } } } private void copyGraphEvent(){ stopAllRelax(); scaleOut(); FileDialog fdLoad = new FileDialog (this, "Add graph",FileDialog.LOAD); if (lastDir!=null) fdLoad.setFile(lastDir+lastFile);fdLoad.setFilenameFilter(new DataFileFilter()); fdLoad.setVisible(true); String loadFile=fdLoad.getFile(); String dir=fdLoad.getDirectory(); if (loadFile!=null){ try{ stringletPanel.copyGraphSettings(dir+loadFile); lastDir=dir+loadFile; lastFile=loadFile; updateInfo(); stringletPanel.repaint(); } catch (IOException ie){ //ie.printStackTrace(); JOptionPane.showMessageDialog (this, "The file could not be found or opened", "Load Error", JOptionPane.ERROR_MESSAGE); } catch (DataFormatException dfe){ JOptionPane.showMessageDialog (this, dfe.getMessage(), "Data Error", JOptionPane.ERROR_MESSAGE); //System.exit(0); } } } private void saveEvent(){ FileDialog fdSave = new FileDialog(this, "Save as",FileDialog.SAVE); //fdSave.setDirectory(fdDirectory); fdSave.setFilenameFilter(new DataFileFilter()); fdSave.setVisible(true); String saveFile=fdSave.getFile(); String dir=fdSave.getDirectory(); if (saveFile!=null){ lastDir=dir; lastFile=saveFile; try{ stringletPanel.saveGraph(dir+saveFile); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "Error saving file.", "Save error", JOptionPane.ERROR_MESSAGE); } } } private void saveHTMLParametersEvent(){ FileDialog fdSave = new FileDialog(this, "Save applet parameters to",FileDialog.SAVE); fdSave.setVisible(true); String saveFile=fdSave.getFile(); dl = new DataLoader(); //System.out.println(stringletPanel.getGraph().report()); if (saveFile!=null){ try { dl.saveHTMLParameters(stringletPanel.getGraph(),saveFile); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "Error saving file.", "Save error", JOptionPane.ERROR_MESSAGE); } } } private void exportEPSEvent(){ FileDialog fdSave = new FileDialog(this, "Save as EPS",FileDialog.SAVE); //fdSave.setDirectory(fdDirectory); //fdSave.setFilenameFilter(new CustomFileFilter("\\.ps")); fdSave.setVisible(true); String saveFile=fdSave.getFile(); String dir=fdSave.getDirectory(); if (saveFile!=null){ //lastDir=dir+saveFile; try{ stringletPanel.writeEPS(dir+saveFile); //System.out.println("weng MedusaFrame exportPSEvent"); JOptionPane.showMessageDialog (this, "Panel exported to "+saveFile, "EPS saved", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "Error saving file.", "Save error", JOptionPane.ERROR_MESSAGE); } } } private void exportPSEvent(){ FileDialog fdSave = new FileDialog(this, "Save as PS",FileDialog.SAVE); //fdSave.setDirectory(fdDirectory); //fdSave.setFilenameFilter(new CustomFileFilter("\\.ps")); fdSave.setVisible(true); String saveFile=fdSave.getFile(); String dir=fdSave.getDirectory(); if (saveFile!=null){ //lastDir=dir+saveFile; try{ stringletPanel.writePS(dir+saveFile); JOptionPane.showMessageDialog (this, "Panel exported to "+saveFile, "PS saved", JOptionPane.INFORMATION_MESSAGE); //System.out.println("weng MedusaFrame exportPSEvent"); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "Error saving file.", "Save error", JOptionPane.ERROR_MESSAGE); } } } private void exportPajekEvent(){ FileDialog fdSave = new FileDialog(this, "Save as pajek",FileDialog.SAVE); fdSave.setVisible(true); String saveFile=fdSave.getFile(); String dir=fdSave.getDirectory(); if (saveFile!=null){ //lastDir=dir+saveFile; try{ stringletPanel.writePajek(dir+saveFile); JOptionPane.showMessageDialog (this, "Exported to pajek format "+saveFile, "Pajek", JOptionPane.INFORMATION_MESSAGE); //System.out.println("weng MedusaFrame exportPSEvent"); } catch (IOException ie){ JOptionPane.showMessageDialog (this, "Error saving file.", "Save error", JOptionPane.ERROR_MESSAGE); } } } private void interactionEvent(){ FileDialog fdInter = new FileDialog (this, "Load interaction file",FileDialog.LOAD); fdInter.setVisible(true); String loadFile=fdInter.getFile(); String dir=fdInter.getDirectory(); if (loadFile!=null){ try{ lastInter=dir+loadFile; stringSettings.load(dir+loadFile); updateLegend(); stringletPanel.updateStringSettings(stringSettings); legendPanel.repaint(); //stringSettings.report(); } catch (IOException ie){ //ie.printStackTrace(); JOptionPane.showMessageDialog (this, "Interaction settings could not be loaded.\n"+ "Check if the file is valid.", "Load error", JOptionPane.ERROR_MESSAGE); } } } private void exportImageEvent(boolean png){ String name = "network."+( (png)?"png":"jpg"); FileDialog fdSave = new FileDialog(this, "Save as" +( (png)?"png":"jpg"),FileDialog.SAVE); fdSave.setFile(name); //fdSave.setFilenameFilter(new CustomFileFilter("\\.ps")); fdSave.setVisible(true); String saveFile=fdSave.getFile(); String dir=fdSave.getDirectory(); int type=(png)? 1:0; stringletPanel.saveImage(dir+saveFile,type); JOptionPane.showMessageDialog (this, "Panel exported to "+saveFile, "Image saved", JOptionPane.INFORMATION_MESSAGE); } private void switchColorEvent(){ int[] colors = ColorJDialog.showDialog(f, null, "switch with"); stringletPanel.manipulateColor(colors[0], colors[1], true); stringletPanel.repaint(); } private void copyColorEvent(){ int[] colors = ColorJDialog.showDialog(f, null, "copy to"); stringletPanel.manipulateColor(colors[0], colors[1], false); stringletPanel.repaint(); } private void changeColorEvent(){ Color newColor = JColorChooser.showDialog(getRootPane(), "Choose node color", Color.red); if (newColor!=null){ stringletPanel.changeNodeColor(newColor); stringletPanel.repaint(); } } private void setLabelColorEvent(){ Color newColor = JColorChooser.showDialog(getRootPane(), "Choose label color", Color.black); if (newColor!=null){ stringletPanel.setFontColor(newColor); stringletPanel.repaint(); } } private void setBackgroundColorEvent(){ Color newColor = JColorChooser.showDialog(getRootPane(), "Choose label color", Color.white); if (newColor!=null){ stringletPanel.setBackgroundColor(newColor); stringletPanel.repaint(); } } private void setBasicEdgeColorEvent(){ Color newColor = JColorChooser.showDialog(getRootPane(), "Choose label color", Color.gray); if (newColor!=null){ stringletPanel.setBasicEdgeColor(newColor); stringletPanel.repaint(); } } private void changeNodeSizeEvent(){ String s = (String)JOptionPane.showInputDialog ("Enter node size in pixels:\n" + "Default value is 10", ""); int newSize=-1; // default if something goes wrong if ((s != null) && (s.length() > 0)){ try{ newSize=Integer.parseInt(s); stringletPanel.setNodeSize(newSize); } catch (NumberFormatException ne){ JOptionPane.showMessageDialog (this, "Incorrect input", "An integer is required for this action", JOptionPane.ERROR_MESSAGE); } } stringletPanel.repaint(); } private void changeFontSizeEvent(){ String s = (String)JOptionPane.showInputDialog ("Enter font size:\n" + "Default value is 10", ""); if ((s != null) && (s.length() > 0)){ try{ int newSize=Integer.parseInt(s); stringletPanel.changeFont(newSize); } catch (NumberFormatException ne){ JOptionPane.showMessageDialog (this, "Incorrect input", "An integer is required for this action", JOptionPane.ERROR_MESSAGE); } } stringletPanel.repaint(); } private void searchNodeEvent(boolean label){ String s = (String)JOptionPane.showInputDialog ("Mark node matching regular expression:\n" + "e.g. \"mito.*\"", ""); //stringletPanel.findLabel if (s != null) if (stringletPanel.selectNodeByRegExp(s,label)==0){ JOptionPane.showMessageDialog (this, "No match found", "No nodes matching your pattern were found", JOptionPane.ERROR_MESSAGE); } stringletPanel.repaint(); } private void selectNodeFromFileEvent(){ FileDialog fdSelect = new FileDialog (this, "Load node list",FileDialog.LOAD); if (lastDir!=null) fdSelect.setDirectory(lastDir); fdSelect.setVisible(true); String loadFile=fdSelect.getFile(); String dir=fdSelect.getDirectory(); //lastDir=dir; try { int c=stringletPanel.selectNodeFromFile(dir+loadFile); stringletPanel.repaint(); } catch (IOException sNFFe){ JOptionPane.showMessageDialog (this, sNFFe.getMessage(), "Load Error", JOptionPane.ERROR_MESSAGE); } } /* // Handle the menu events specific to this class ---------------------------------- public void handleClassEvent(ActionEvent e) { Object source = e.getSource(); }*/ // a stopper method, if we need to turn off relax public void stopRelax(){ stringletPanel.stop(); if (relax.isSelected()) relax.setSelected(false); } // add listeners, that set parameters for the StringletPanel object public void itemStateChanged(ItemEvent e){ //handleClassStateChange(e); } public void handleClassStateChange(ItemEvent e){ Object src = e.getSource(); handleToggle(src); } public void handleToggle(Object src){ System.out.println("debug line 1522 event handled"); ShowEdgePanel se = (ShowEdgePanel) src; System.out.println(se.getNumber()); /* for (int i=0; i 0)){ try{ int newSize=Integer.parseInt(s); stringletPanel.setEdgeLen(newSize); } catch (NumberFormatException ne){ JOptionPane.showMessageDialog (this, "Incorrect input", "An integer is required for this action", JOptionPane.ERROR_MESSAGE); } } } // testing here ProgressMonitor loader; Timer timer; DataLoader dl; public void waitForLoad(String fileName, int loadType) throws IOException, DataFormatException{ dl = new DataLoader(600,600,fileName); dl.setLoadType(loadType); timer=new javax.swing.Timer(500,runLoad); dl.start(); timer.start(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } private ActionListener runLoad=new ActionListener(){ public void actionPerformed(ActionEvent evt){ infoLabel.setText(dl.getStatus()+" "+dl.getProgress()); //loader.setProgress(0); //System.out.println(dl.getProgress()); if (dl.isDone()){ timer.stop(); dl.stop(); //loader.close(); //loader.setProgress(0); infoLabel.setText("Cleaning graph"); setCursor(null); stringletPanel.setGraph(dl.getGraph()); updateInfo(); updateFileInfo(); stringletPanel.repaint(); } } }; private boolean hideInteractions=false; private void hideShowInteractionsEvent(){ Container content = getContentPane(); if (!hideInteractions){ content.remove(scalerPanel); hideShowMenuItem.setText("Show"); hideInteractions=true; } else{ content.add("East",scalerPanel); hideShowMenuItem.setText("Hide"); hideInteractions=false; } validate(); } private void setNodeColorSet(int i){ stringletPanel.setNodeColorSet(i); } }

Ads help maintain this website.