2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.bin;
\r
21 import jalview.appletgui.AlignFrame;
\r
23 import jalview.datamodel.*;
\r
25 import jalview.io.*;
\r
27 import java.applet.*;
\r
30 import java.awt.event.*;
\r
34 * Jalview Applet. Runs in Java 1.18 runtime
\r
37 * @version $Revision$
\r
39 public class JalviewLite extends Applet
\r
41 static int lastFrameX = 200;
\r
42 static int lastFrameY = 200;
\r
43 boolean fileFound = true;
\r
44 String file = "No file";
\r
45 Button launcher = new Button("Start Jalview");
\r
47 AlignFrame currentAlignFrame;
\r
51 * init method for Jalview Applet
\r
60 String param = getParameter("RGB");
\r
66 r = Integer.parseInt(param.substring(0, 2), 16);
\r
67 g = Integer.parseInt(param.substring(2, 4), 16);
\r
68 b = Integer.parseInt(param.substring(4, 6), 16);
\r
70 catch (Exception ex)
\r
78 param = getParameter("label");
\r
80 launcher.setLabel(param);
\r
82 this.setBackground(new Color(r, g, b));
\r
85 param = getParameter("features");
\r
88 if(param.indexOf("://")==-1)
\r
89 param = getCodeBase() + param;
\r
91 final String featuresFile = param;
\r
93 file = getParameter("file");
\r
94 final JalviewLite applet = this;
\r
98 if(file.indexOf("://")==-1)
\r
99 file = getCodeBase() + file;
\r
101 launcher.addActionListener(new java.awt.event.ActionListener()
\r
103 public void actionPerformed(ActionEvent e)
\r
105 String format = jalview.io.IdentifyFile.Identify(file,
\r
107 LoadingThread loader = new LoadingThread(file,
\r
124 public static void main(String [] args)
\r
128 System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
\r
132 String format = jalview.io.IdentifyFile.Identify(args[0],"File");
\r
133 SequenceI[] sequences = new AppletFormatAdapter().readFile(args[0], "File", format);
\r
135 if ( (sequences != null) && (sequences.length > 0))
\r
137 AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0]);
\r
138 af.statusBar.setText("Successfully loaded file " + args[0]);
\r
144 * Initialises and displays a new java.awt.Frame
\r
146 * @param frame java.awt.Frame to be displayed
\r
147 * @param title title of new frame
\r
148 * @param width width if new frame
\r
149 * @param height height of new frame
\r
151 public static void addFrame(final Frame frame, String title, int width,
\r
154 frame.setLocation(lastFrameX, lastFrameY);
\r
157 frame.setSize(width, height);
\r
158 frame.setTitle(title);
\r
159 frame.addWindowListener(new WindowAdapter()
\r
161 public void windowClosing(WindowEvent e)
\r
166 frame.setVisible(true);
\r
169 public String getAlignment(String format)
\r
171 return getAlignment(format, "true");
\r
174 public String getAlignment(String format, String suffix)
\r
178 boolean seqlimits = suffix.equalsIgnoreCase("true");
\r
180 String reply = new AppletFormatAdapter().formatSequences(format,
\r
181 currentAlignFrame.viewport.getAlignment().getSequences(), seqlimits);
\r
184 catch (Exception ex)
\r
185 {ex.printStackTrace();
\r
186 return "Error retrieving alignment in " + format + " format. ";
\r
192 * This paints the background surrounding the "Launch Jalview button"
\r
194 * <br>If file given in parameter not found, displays error message
\r
196 * @param g graphics context
\r
198 public void paint(Graphics g)
\r
202 g.setColor(new Color(200, 200, 200));
\r
203 g.setColor(Color.cyan);
\r
204 g.fillRect(0, 0, getSize().width, getSize().height);
\r
205 g.setColor(Color.red);
\r
206 g.drawString("Jalview can't open file", 5, 15);
\r
207 g.drawString("\"" + file + "\"", 5, 30);
\r
211 class LoadingThread extends Thread
\r
216 String featuresFile;
\r
217 JalviewLite applet;
\r
219 public LoadingThread(String file,
\r
223 JalviewLite applet)
\r
226 this.protocol = protocol;
\r
227 this.format = format;
\r
228 featuresFile = features;
\r
229 this.applet = applet;
\r
234 SequenceI[] sequences = null;
\r
235 sequences = new AppletFormatAdapter().readFile(file, protocol, format);
\r
237 if ((sequences != null) && (sequences.length > 0))
\r
239 currentAlignFrame = new AlignFrame(new Alignment(sequences),
\r
241 currentAlignFrame.statusBar.setText("Successfully loaded file " + file);
\r
243 if(featuresFile!=null)
\r
244 currentAlignFrame.parseFeaturesFile(featuresFile);
\r
246 String pdbfile = applet.getParameter("PDBFILE");
\r
249 if(pdbfile.indexOf("://")==-1)
\r
250 pdbfile = getCodeBase() + pdbfile;
\r
252 String sequence = applet.getParameter("PDBSEQ");
\r
256 new MCview.AppletPDBViewer(pdbfile, "URL",
\r
257 (Sequence)currentAlignFrame.getAlignViewport().getAlignment().findName(sequence),
\r
258 currentAlignFrame.getSeqcanvas());
\r