2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
22 import jalview.gui.AlignFrame;
\r
23 import jalview.gui.Jalview2XML;
\r
24 import javax.swing.JOptionPane;
\r
26 import jalview.gui.*;
\r
27 import jalview.datamodel.*;
\r
28 import java.util.Vector;
\r
29 import java.util.StringTokenizer;
\r
30 import javax.swing.SwingUtilities;
\r
32 public class FileLoader implements Runnable
\r
37 AlignViewport viewport;
\r
38 AlignFrame alignFrame;
\r
40 public void LoadFile(AlignViewport viewport, String file, String protocol, String format)
\r
42 this.viewport = viewport;
\r
43 LoadFile(file, protocol, format);
\r
48 public void LoadFile(String file, String protocol, String format)
\r
51 this.protocol = protocol;
\r
52 this.format = format;
\r
54 final Thread loader = new Thread(this);
\r
56 SwingUtilities.invokeLater(new Runnable()
\r
66 public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,
\r
70 this.protocol = protocol;
\r
71 this.format = format;
\r
73 Thread loader = new Thread(this);
\r
76 while (loader.isAlive())
\r
82 catch (Exception ex)
\r
91 public void updateRecentlyOpened()
\r
93 Vector recent = new Vector();
\r
95 String type = protocol.equals(FormatAdapter.FILE)
\r
96 ? "RECENT_FILE" : "RECENT_URL";
\r
98 String historyItems = jalview.bin.Cache.getProperty(type);
\r
100 StringTokenizer st;
\r
102 if (historyItems != null)
\r
104 st = new StringTokenizer(historyItems, "\t");
\r
106 while (st.hasMoreTokens())
\r
108 recent.addElement(st.nextElement().toString().trim());
\r
112 if (recent.contains(file))
\r
114 recent.remove(file);
\r
117 StringBuffer newHistory = new StringBuffer(file);
\r
118 for (int i = 0; i < recent.size() && i < 10; i++)
\r
120 newHistory.append("\t");
\r
121 newHistory.append(recent.elementAt(i));
\r
124 jalview.bin.Cache.setProperty(type, newHistory.toString());
\r
126 if(type.equals(FormatAdapter.FILE))
\r
127 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
\r
133 if (Desktop.instance != null)
\r
134 Desktop.instance.startLoading(file);
\r
136 Alignment al = null;
\r
138 if (format.equalsIgnoreCase("Jalview"))
\r
140 alignFrame = new Jalview2XML().LoadJalviewAlign(file);
\r
144 String error = AppletFormatAdapter.SUPPORTED_FORMATS;
\r
146 if (FormatAdapter.isValidFormat(format))
\r
150 al = new FormatAdapter().readFile(file, protocol, format);
\r
152 catch (java.io.IOException ex)
\r
154 error = ex.getMessage();
\r
158 if ( (al != null) && (al.getHeight() > 0))
\r
160 if (viewport != null)
\r
162 for (int i = 0; i < al.getHeight(); i++)
\r
164 viewport.getAlignment().addSequence(al.getSequenceAt(i));
\r
166 viewport.firePropertyChange("alignment", null,
\r
167 viewport.getAlignment().getSequences());
\r
172 alignFrame = new AlignFrame(al,
\r
173 AlignFrame.DEFAULT_WIDTH,
\r
174 AlignFrame.DEFAULT_HEIGHT);
\r
176 alignFrame.statusBar.setText("Successfully loaded file " + file);
\r
177 alignFrame.setFileName(file, format);
\r
180 Desktop.addInternalFrame(alignFrame, file,
\r
181 AlignFrame.DEFAULT_WIDTH,
\r
182 AlignFrame.DEFAULT_HEIGHT);
\r
186 alignFrame.setMaximum(jalview.bin.Cache.getDefault(
\r
187 "SHOW_FULLSCREEN", false));
\r
189 catch (java.beans.PropertyVetoException ex)
\r
196 if (Desktop.instance != null)
\r
197 Desktop.instance.stopLoading();
\r
199 final String errorMessage = "Couldn't load file " + file + "\n" +
\r
202 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
206 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
208 "Error loading file",
\r
209 JOptionPane.WARNING_MESSAGE);
\r
215 updateRecentlyOpened();
\r
218 catch (OutOfMemoryError er)
\r
221 er.printStackTrace();
\r
224 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
228 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
229 "Out of memory loading file "+file+"!!"
\r
231 "\nSee help files for increasing Java Virtual Machine memory."
\r
233 javax.swing.JOptionPane.WARNING_MESSAGE);
\r
239 if (Desktop.instance != null)
\r
240 Desktop.instance.stopLoading();
\r