From 9344c308a62c48e2ddedd12247edab74e581c2e7 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 15 Sep 2005 09:09:17 +0000 Subject: [PATCH] Applet has main method, excutable --- src/jalview/appletgui/AlignFrame.java | 53 ++++++++++++++++++--------------- src/jalview/appletgui/IdPanel.java | 13 ++++---- src/jalview/bin/JalviewLite.java | 37 +++++++++++++++++++---- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 14a341d..289e761 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -48,40 +48,43 @@ public class AlignFrame add(alignPanel); alignPanel.validate(); - String treeFile = applet.getParameter("treeFile"); - if (treeFile != null) + if(applet!=null) { - try + String treeFile = applet.getParameter("treeFile"); + if (treeFile != null) { - treeFile = treeFile; - jalview.io.NewickFile fin = new jalview.io.NewickFile(applet. - getCodeBase() + treeFile, "URL"); - fin.parse(); + try + { + treeFile = treeFile; + jalview.io.NewickFile fin = new jalview.io.NewickFile(applet. + getCodeBase() + treeFile, "URL"); + fin.parse(); - if (fin.getTree() != null) + if (fin.getTree() != null) + { + TreePanel tp = null; + tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), + fin, "FromFile", applet.getCodeBase() + treeFile); + jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500); + addTreeMenuItem(tp, treeFile); + } + } + catch (Exception ex) { - TreePanel tp = null; - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - fin, "FromFile", applet.getCodeBase() + treeFile); - jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500); - addTreeMenuItem(tp, treeFile); + ex.printStackTrace(); } } - catch (Exception ex) + + String param = applet.getParameter("sortBy"); + if (param != null) { - ex.printStackTrace(); + if (param.equalsIgnoreCase("Id")) + sortIDMenuItem_actionPerformed(null); + else if (param.equalsIgnoreCase("Pairwise Identity")) + sortPairwiseMenuItem_actionPerformed(null); } } - String param = applet.getParameter("sortBy"); - if(param!=null) - { - if (param.equalsIgnoreCase("Id")) - sortIDMenuItem_actionPerformed(null); - else if (param.equalsIgnoreCase("Pairwise Identity")) - sortPairwiseMenuItem_actionPerformed(null); - } - this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) @@ -127,6 +130,8 @@ public class AlignFrame { PaintRefresher.components.remove(viewport.alignment); dispose(); + if(PaintRefresher.components.size()==0 && applet==null) + System.exit(0); } Stack historyList = new Stack(); diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index f3db9be..b6e6a2b 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -50,14 +50,17 @@ public class IdPanel idCanvas.addMouseMotionListener(this); String label, url; - for(int i=1; i<10; i++) + if(parent.alignFrame.applet!=null) { - label = parent.alignFrame.applet.getParameter("linkLabel_"+i); - url = parent.alignFrame.applet.getParameter("linkURL_"+i); + for (int i = 1; i < 10; i++) + { + label = parent.alignFrame.applet.getParameter("linkLabel_" + i); + url = parent.alignFrame.applet.getParameter("linkURL_" + i); - if(label!=null && url!=null) - links.addElement(label+"|"+url); + if (label != null && url != null) + links.addElement(label + "|" + url); + } } if (links.size() < 1) { diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index b99d642..c9ec391 100755 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -98,6 +98,26 @@ public class JalviewLite extends Applet } } + public static void main(String [] args) + { + if(args.length!=1) + { + System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n"); + System.exit(1); + } + + String format = jalview.io.IdentifyFile.Identify(args[0],"File"); + SequenceI[] sequences = FormatAdapter.readFile(args[0], "File", format); + + if ( (sequences != null) && (sequences.length > 0)) + { + AlignFrame af = new AlignFrame(new Alignment(sequences), null); + addFrame(af, args[0], AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + af.statusBar.setText("Successfully loaded file " + args[0]); + } + } + /** * Displays the given URL in a new browser window * @@ -111,14 +131,21 @@ public class JalviewLite extends Applet public static void showURL(String url, String target) { - try + if(applet==null) { - applet.getAppletContext().showDocument(new java.net.URL(url), - target); + System.out.println("Not running as applet - no browser available."); } - catch (Exception ex) + else { - ex.printStackTrace(); + try + { + applet.getAppletContext().showDocument(new java.net.URL(url), + target); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } } -- 1.7.10.2