2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
24 import javax.swing.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.gui.*;
\r
29 public class FileLoader
\r
35 AlignViewport viewport;
\r
36 AlignFrame alignFrame;
\r
38 public void LoadFile(AlignViewport viewport, String file, String protocol,
\r
41 this.viewport = viewport;
\r
42 LoadFile(file, protocol, format);
\r
45 public void LoadFile(String file, String protocol, String format)
\r
48 this.protocol = protocol;
\r
49 this.format = format;
\r
51 final Thread loader = new Thread(this);
\r
53 SwingUtilities.invokeLater(new Runnable()
\r
62 public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,
\r
66 this.protocol = protocol;
\r
67 this.format = format;
\r
69 Thread loader = new Thread(this);
\r
72 while (loader.isAlive())
\r
78 catch (Exception ex)
\r
85 public void updateRecentlyOpened()
\r
87 Vector recent = new Vector();
\r
89 String type = protocol.equals(FormatAdapter.FILE)
\r
90 ? "RECENT_FILE" : "RECENT_URL";
\r
92 String historyItems = jalview.bin.Cache.getProperty(type);
\r
96 if (historyItems != null)
\r
98 st = new StringTokenizer(historyItems, "\t");
\r
100 while (st.hasMoreTokens())
\r
102 recent.addElement(st.nextElement().toString().trim());
\r
106 if (recent.contains(file))
\r
108 recent.remove(file);
\r
111 StringBuffer newHistory = new StringBuffer(file);
\r
112 for (int i = 0; i < recent.size() && i < 10; i++)
\r
114 newHistory.append("\t");
\r
115 newHistory.append(recent.elementAt(i));
\r
118 jalview.bin.Cache.setProperty(type, newHistory.toString());
\r
120 if (protocol.equals(FormatAdapter.FILE))
\r
122 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
\r
128 String title = protocol.equals(AppletFormatAdapter.PASTE)
\r
129 ? "Copied From Clipboard" : file;
\r
133 if (Desktop.instance != null)
\r
135 Desktop.instance.startLoading(file);
\r
138 Alignment al = null;
\r
140 if (format.equalsIgnoreCase("Jalview"))
\r
142 alignFrame = new Jalview2XML().LoadJalviewAlign(file);
\r
146 String error = AppletFormatAdapter.SUPPORTED_FORMATS;
\r
148 if (FormatAdapter.isValidFormat(format))
\r
152 al = new FormatAdapter().readFile(file, protocol, format);
\r
154 catch (java.io.IOException ex)
\r
156 error = ex.getMessage();
\r
160 if ( (al != null) && (al.getHeight() > 0))
\r
162 if (viewport != null)
\r
164 for (int i = 0; i < al.getHeight(); i++)
\r
166 viewport.getAlignment().addSequence(al.getSequenceAt(i));
\r
168 viewport.firePropertyChange("alignment", null,
\r
169 viewport.getAlignment().getSequences());
\r
174 alignFrame = new AlignFrame(al,
\r
175 AlignFrame.DEFAULT_WIDTH,
\r
176 AlignFrame.DEFAULT_HEIGHT);
\r
178 alignFrame.statusBar.setText("Successfully loaded file " + title);
\r
180 if (!protocol.equals(AppletFormatAdapter.PASTE))
\r
181 alignFrame.setFileName(file, format);
\r
183 Desktop.addInternalFrame(alignFrame, title,
\r
184 AlignFrame.DEFAULT_WIDTH,
\r
185 AlignFrame.DEFAULT_HEIGHT);
\r
189 alignFrame.setMaximum(jalview.bin.Cache.getDefault(
\r
190 "SHOW_FULLSCREEN", false));
\r
192 catch (java.beans.PropertyVetoException ex)
\r
199 if (Desktop.instance != null)
\r
201 Desktop.instance.stopLoading();
\r
204 final String errorMessage = "Couldn't load file " + title + "\n" +
\r
207 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
211 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
213 "Error loading file",
\r
214 JOptionPane.WARNING_MESSAGE);
\r
220 updateRecentlyOpened();
\r
223 catch (OutOfMemoryError er)
\r
226 er.printStackTrace();
\r
229 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
233 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
234 "Out of memory loading file " + file + "!!"
\r
236 "\nSee help files for increasing Java Virtual Machine memory."
\r
238 javax.swing.JOptionPane.WARNING_MESSAGE);
\r
244 if (Desktop.instance != null)
\r
246 Desktop.instance.stopLoading();
\r