package jalview.bin; import java.applet.*; import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; import jalview.io.*; import jalview.appletgui.AlignFrame; public class JalviewLite extends Applet { static int lastFrameX = 200; static int lastFrameY = 200; static Applet applet; boolean fileFound = true; String file = "No file"; Button launcher = new Button("Start Jalview"); public void init() { applet = this; this.setBackground(Color.white); file = getParameter("file"); if (file != null) { add(launcher); file = applet.getCodeBase() + file; launcher.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { String format = jalview.io.IdentifyFile.Identify( file, "URL"); LoadFile(file, "URL", format); } }); } else { file = "NO FILE"; fileFound = false; } } public static void showURL(String url) { try{ applet.getAppletContext().showDocument(new java.net.URL(url), "HELP_WINDOW"); }catch(Exception ex){} } public void LoadFile(String file, String protocol, String format) { LoadingThread loader = new LoadingThread(file, protocol, format, this); loader.start(); } public static void addFrame(final Frame frame, String title, int width, int height) { frame.setLocation(lastFrameX,lastFrameY); lastFrameX+=40; lastFrameY+=40; frame.setSize(width,height); frame.setTitle(title); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); } }); frame.setVisible(true); } public void paint(Graphics g) { if(!fileFound) { g.setColor(new Color(200,200,200)); g.setColor(Color.cyan); g.fillRect(0,0,getSize().width, getSize().height); g.setColor(Color.red); g.drawString("Jalview can't open file", 5, 15); g.drawString("\""+ file+"\"", 5, 30); } } class LoadingThread extends Thread { String file, protocol, format; JalviewLite jlapplet; public LoadingThread(String file, String protocol, String format, JalviewLite applet) { this.file = file; this.protocol = protocol; this.format = format; this.jlapplet = applet; } public void run() { SequenceI [] sequences = null; sequences = FormatAdapter.readFile(file, protocol, format); if (sequences != null && sequences.length>0) { AlignFrame af = new AlignFrame(new Alignment(sequences), jlapplet ); addFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); af.statusBar.setText("Successfully loaded file " + file); } else { fileFound = false; remove(launcher); repaint(); } } } }