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
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
31 public class FileLoader
\r
36 AlignViewport viewport;
\r
38 public void LoadFile(AlignViewport viewport, String file, String protocol, String format)
\r
40 this.viewport = viewport;
\r
41 LoadFile(file, protocol, format);
\r
44 public void LoadFile(String file, String protocol, String format)
\r
47 this.protocol = protocol;
\r
48 this.format = format;
\r
50 LoadingThread loader = new LoadingThread();
\r
54 public AlignFrame LoadFileWaitTillLoaded(String file, String protocol,
\r
58 this.protocol = protocol;
\r
59 this.format = format;
\r
61 LoadingThread loader = new LoadingThread();
\r
63 while (loader.isAlive())
\r
69 catch (Exception ex)
\r
78 public void updateRecentlyOpened()
\r
80 Vector recent = new Vector();
\r
82 String type = protocol.equals(FormatAdapter.FILE)
\r
83 ? "RECENT_FILE" : "RECENT_URL";
\r
85 String historyItems = jalview.bin.Cache.getProperty(type);
\r
89 if (historyItems != null)
\r
91 st = new StringTokenizer(historyItems, "\t");
\r
93 while (st.hasMoreTokens())
\r
95 recent.addElement(st.nextElement().toString().trim());
\r
99 if (recent.contains(file))
\r
101 recent.remove(file);
\r
104 StringBuffer newHistory = new StringBuffer(file);
\r
105 for (int i = 0; i < recent.size() && i < 10; i++)
\r
107 newHistory.append("\t");
\r
108 newHistory.append(recent.elementAt(i));
\r
111 jalview.bin.Cache.setProperty(type, newHistory.toString());
\r
113 if(type.equals(FormatAdapter.FILE))
\r
114 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format);
\r
118 class LoadingThread
\r
128 Desktop.instance.startLoading(file);
\r
130 SequenceI[] sequences = null;
\r
132 if (format.equalsIgnoreCase("Jalview"))
\r
134 af = new Jalview2XML().LoadJalviewAlign(file);
\r
138 String errorMessage = AppletFormatAdapter.SUPPORTED_FORMATS;
\r
140 if (FormatAdapter.formats.contains(format))
\r
144 sequences = new FormatAdapter().readFile(file, protocol, format);
\r
146 catch (java.io.IOException ex)
\r
148 errorMessage = ex.getMessage();
\r
152 if ( (sequences != null) && (sequences.length > 0))
\r
156 for(int i=0; i<sequences.length; i++)
\r
157 viewport.getAlignment().addSequence(sequences[i]);
\r
159 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
163 af = new AlignFrame(new Alignment(sequences));
\r
164 af.currentFileFormat = format;
\r
165 af.statusBar.setText("Successfully loaded file " + file);
\r
167 Desktop.addInternalFrame(af, file, AlignFrame.NEW_WINDOW_WIDTH,
\r
168 AlignFrame.NEW_WINDOW_HEIGHT);
\r
172 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
\r
174 catch (java.beans.PropertyVetoException ex)
\r
181 Desktop.instance.stopLoading();
\r
183 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
184 "Couldn't load file " + file +
\r
187 "Error loading file",
\r
188 JOptionPane.WARNING_MESSAGE);
\r
194 updateRecentlyOpened();
\r
197 Desktop.instance.stopLoading();
\r