X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=86c1cf4cc139ed5790de492c951682bd5842fe6c;hb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;hp=34e5886a039d54a50ae42e784af631145d9e0774;hpb=ed8d18abc302ac802ad1d0611f3fe2fef570ab5e;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 34e5886..86c1cf4 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -1,35 +1,33 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.io; -import jalview.gui.AlignFrame; -import jalview.gui.Jalview2XML; -import javax.swing.JOptionPane; +import java.util.*; + +import javax.swing.*; -import jalview.gui.*; import jalview.datamodel.*; -import java.util.Vector; -import java.util.StringTokenizer; -import javax.swing.SwingUtilities; +import jalview.gui.*; -public class FileLoader implements Runnable +public class FileLoader + implements Runnable { String file; String protocol; @@ -37,14 +35,13 @@ public class FileLoader implements Runnable AlignViewport viewport; AlignFrame alignFrame; - public void LoadFile(AlignViewport viewport, String file, String protocol, String format) + public void LoadFile(AlignViewport viewport, String file, String protocol, + String format) { this.viewport = viewport; LoadFile(file, protocol, format); } - - public void LoadFile(String file, String protocol, String format) { this.file = file; @@ -62,9 +59,8 @@ public class FileLoader implements Runnable }); } - public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, - String format) + String format) { this.file = file; this.protocol = protocol; @@ -86,8 +82,6 @@ public class FileLoader implements Runnable return alignFrame; } - - public void updateRecentlyOpened() { Vector recent = new Vector(); @@ -123,122 +117,130 @@ public class FileLoader implements Runnable jalview.bin.Cache.setProperty(type, newHistory.toString()); - if(type.equals(FormatAdapter.FILE)) + if (type.equals(FormatAdapter.FILE)) + { jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); + } } - public void run() + public void run() + { + try { - try{ - if (Desktop.instance != null) - Desktop.instance.startLoading(file); + if (Desktop.instance != null) + { + Desktop.instance.startLoading(file); + } - Alignment al = null; + Alignment al = null; - if (format.equalsIgnoreCase("Jalview")) + if (format.equalsIgnoreCase("Jalview")) + { + alignFrame = new Jalview2XML().LoadJalviewAlign(file); + } + else + { + String error = AppletFormatAdapter.SUPPORTED_FORMATS; + + if (FormatAdapter.isValidFormat(format)) { - alignFrame = new Jalview2XML().LoadJalviewAlign(file); + try + { + al = new FormatAdapter().readFile(file, protocol, format); + } + catch (java.io.IOException ex) + { + error = ex.getMessage(); + } } - else - { - String error = AppletFormatAdapter.SUPPORTED_FORMATS; - if (FormatAdapter.isValidFormat(format)) + if ( (al != null) && (al.getHeight() > 0)) + { + if (viewport != null) { - try + for (int i = 0; i < al.getHeight(); i++) { - al = new FormatAdapter().readFile(file, protocol, format); + viewport.getAlignment().addSequence(al.getSequenceAt(i)); } - catch (java.io.IOException ex) - { - error = ex.getMessage(); - } - } + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); - if ( (al != null) && (al.getHeight() > 0)) + } + else { - if (viewport != null) - { - for (int i = 0; i < al.getHeight(); i++) - { - viewport.getAlignment().addSequence(al.getSequenceAt(i)); - } - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); + alignFrame = new AlignFrame(al, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + + alignFrame.statusBar.setText("Successfully loaded file " + file); + alignFrame.setFileName(file, format); + + Desktop.addInternalFrame(alignFrame, file, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + try + { + alignFrame.setMaximum(jalview.bin.Cache.getDefault( + "SHOW_FULLSCREEN", false)); } - else + catch (java.beans.PropertyVetoException ex) { - alignFrame = new AlignFrame(al, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); - - alignFrame.statusBar.setText("Successfully loaded file " + file); - alignFrame.setFileName(file, format); - - - Desktop.addInternalFrame(alignFrame, file, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); - - try - { - alignFrame.setMaximum(jalview.bin.Cache.getDefault( - "SHOW_FULLSCREEN", false)); - } - catch (java.beans.PropertyVetoException ex) - { - } } } - else + } + else + { + if (Desktop.instance != null) { - if (Desktop.instance != null) - Desktop.instance.stopLoading(); + Desktop.instance.stopLoading(); + } - final String errorMessage = "Couldn't load file " + file + "\n" + - error; + final String errorMessage = "Couldn't load file " + file + "\n" + + error; - javax.swing.SwingUtilities.invokeLater(new Runnable() + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() { - public void run() - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - errorMessage, - "Error loading file", - JOptionPane.WARNING_MESSAGE); - } - }); - } + JOptionPane.showInternalMessageDialog(Desktop.desktop, + errorMessage, + "Error loading file", + JOptionPane.WARNING_MESSAGE); + } + }); } + } - updateRecentlyOpened(); + updateRecentlyOpened(); - } - catch (OutOfMemoryError er) - { + } + catch (OutOfMemoryError er) + { - er.printStackTrace(); - alignFrame = null; + er.printStackTrace(); + alignFrame = null; - javax.swing.SwingUtilities.invokeLater(new Runnable() + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() { - public void run() - { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory loading file "+file+"!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - javax.swing.JOptionPane.WARNING_MESSAGE); - } - }); - } - - System.gc(); - if (Desktop.instance != null) - Desktop.instance.stopLoading(); + javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Out of memory loading file " + file + "!!" + + + "\nSee help files for increasing Java Virtual Machine memory." + , "Out of memory", + javax.swing.JOptionPane.WARNING_MESSAGE); + } + }); + } + System.gc(); + if (Desktop.instance != null) + { + Desktop.instance.stopLoading(); } + } + }