import jalview.gui.AlignViewport;
import jalview.gui.Desktop;
import jalview.gui.Jalview2XML;
+import jalview.gui.JvOptionPane;
+import jalview.gui.JvSwingUtils;
import jalview.json.binding.biojson.v1.ColourSchemeMapper;
import jalview.schemes.ColourSchemeI;
import jalview.structure.StructureSelectionManager;
import java.util.StringTokenizer;
import java.util.Vector;
-import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
public class FileLoader implements Runnable
FileFormatI format;
- AlignmentFileI source = null; // alternative specification of where data comes
+ AlignmentFileReaderI source = null; // alternative specification of where data
+ // comes
// from
DataSourceType protocol, FileFormatI format)
{
this.viewport = viewport;
- LoadFile(file, protocol, format);
- }
-
- public void LoadFile(String file, DataSourceType protocol,
- FileFormatI format)
- {
this.file = file;
this.protocol = protocol;
this.format = format;
-
+
final Thread loader = new Thread(this);
-
+
SwingUtilities.invokeLater(new Runnable()
{
@Override
}
/**
- * Load a (file, protocol) source of unknown type
- *
- * @param file
- * @param protocol
- */
- public void LoadFile(String file, DataSourceType protocol)
- {
- LoadFile(file, protocol, null);
- }
-
- /**
* Load alignment from (file, protocol) and wait till loaded
*
* @param file
}
/**
- * Load alignment from FileParse source of type format and wait till loaded
- *
- * @param source
- * @param format
- * @return alignFrame constructed from file contents
- */
- public AlignFrame LoadFileWaitTillLoaded(AlignmentFileI source,
- FileFormatI format)
- {
- this.source = source;
-
- file = source.getInFile();
- protocol = source.getDataSourceType();
- this.format = format;
- return _LoadFileWaitTillLoaded();
- }
-
- /**
* start thread and wait until finished, then return the alignFrame that's
* (hopefully) been read.
*
if (protocol == DataSourceType.FILE)
{
- Cache.setProperty("DEFAULT_FILE_FORMAT", format.toString());
+ Cache.setProperty("DEFAULT_FILE_FORMAT", format.getName());
}
}
@Override
public void run()
{
- String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard"
+ final String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard"
: file;
Runtime rt = Runtime.getRuntime();
try
+ "\" has null or unidentifiable data content!");
if (!Jalview.isHeadlessMode())
{
- javax.swing.JOptionPane.showInternalMessageDialog(
+ JvOptionPane.showInternalMessageDialog(
Desktop.desktop,
MessageManager.getString("label.couldnt_read_data")
+ " in " + file + "\n"
- + AppletFormatAdapter.SUPPORTED_FORMATS,
+ + AppletFormatAdapter.getSupportedFormats(),
MessageManager.getString("label.couldnt_read_data"),
- JOptionPane.WARNING_MESSAGE);
+ JvOptionPane.WARNING_MESSAGE);
}
return;
}
if (Desktop.desktop != null && Desktop.desktop.isShowMemoryUsage())
{
System.gc();
- memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory()); // free
- // memory
- // before
- // load
+ // free memory before loading file
+ memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory());
}
loadtime = -System.currentTimeMillis();
AlignmentI al = null;
- if (format == FileFormat.Jalview)
+ if (FileFormat.Jalview.equals(format))
{
if (source != null)
{
}
else
{
- String error = AppletFormatAdapter.SUPPORTED_FORMATS;
- try
+ String error = AppletFormatAdapter.getSupportedFormats();
+ try
+ {
+ if (source != null)
{
- if (source != null)
- {
- // read from the provided source
+ // read from the provided source
al = new FormatAdapter().readFromFile(source, format);
- }
- else
- {
-
- // open a new source and read from it
- FormatAdapter fa = new FormatAdapter();
- al = fa.readFile(file, protocol, format);
- source = fa.getAlignFile(); // keep reference for later if
- // necessary.
- }
- } catch (java.io.IOException ex)
+ }
+ else
{
- error = ex.getMessage();
+
+ // open a new source and read from it
+ FormatAdapter fa = new FormatAdapter();
+ al = fa.readFile(file, protocol, format);
+ source = fa.getAlignFile(); // keep reference for later if
+ // necessary.
}
+ } catch (java.io.IOException ex)
+ {
+ error = ex.getMessage();
+ }
- if ((al != null) && (al.getHeight() > 0) && al.hasValidSequence())
+ if (!format.hasSequenceData())
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ String msg = MessageManager.formatMessage("label.successfully_loaded_file_type", format.getName(), title);
+ msg = JvSwingUtils.wrapTooltip(true, msg);
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
+ "", JvOptionPane.INFORMATION_MESSAGE);
+ }
+ });
+ }
+ else if ((al != null) && (al.getHeight() > 0)
+ && al.hasValidSequence())
{
// construct and register dataset sequences
for (SequenceI sq : al.getSequences())
{
for (PDBEntry pdbe : sq.getAllPDBEntries())
{
- // register PDB entries with desktop's structure selection
- // manager
StructureSelectionManager.getStructureSelectionManager(
Desktop.instance).registerPDBEntry(pdbe);
}
}
else
{
- // otherwise construct the alignFrame
-
- if (source instanceof ComplexAlignFile)
- {
- ColumnSelection colSel = ((ComplexAlignFile) source)
- .getColumnSelection();
- SequenceI[] hiddenSeqs = ((ComplexAlignFile) source)
- .getHiddenSequences();
- String colourSchemeName = ((ComplexAlignFile) source)
- .getGlobalColourScheme();
- FeaturesDisplayedI fd = ((ComplexAlignFile) source)
- .getDisplayedFeatures();
- alignFrame = new AlignFrame(al, hiddenSeqs, colSel,
- AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
- alignFrame.getViewport().setFeaturesDisplayed(fd);
- alignFrame.getViewport().setShowSequenceFeatures(
- ((ComplexAlignFile) source).isShowSeqFeatures());
- ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
- colourSchemeName, al);
- if (cs != null)
- {
- alignFrame.changeColour(cs);
- }
- }
- else
- {
- alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
- AlignFrame.DEFAULT_HEIGHT);
- if (source instanceof FeaturesSourceI)
- {
- alignFrame.getViewport().setShowSequenceFeatures(true);
- }
- }
- // add metadata and update ui
- if (!(protocol == DataSourceType.PASTE))
- {
- alignFrame.setFileName(file, format);
- }
- if (proxyColourScheme != null)
- {
- alignFrame.getViewport()
- .applyFeaturesStyle(proxyColourScheme);
- }
- alignFrame.statusBar.setText(MessageManager.formatMessage(
- "label.successfully_loaded_file",
- new String[] { title }));
-
- if (raiseGUI)
- {
- // add the window to the GUI
- // note - this actually should happen regardless of raiseGUI
- // status in Jalview 3
- // TODO: define 'virtual desktop' for benefit of headless scripts
- // that perform queries to find the 'current working alignment'
- Desktop.addInternalFrame(alignFrame, title,
- AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
- }
-
- try
- {
- alignFrame.setMaximum(jalview.bin.Cache.getDefault(
- "SHOW_FULLSCREEN", false));
- } catch (java.beans.PropertyVetoException ex)
- {
- }
+ addAlignFrame(al, title);
}
}
else
+ "\n" + error;
// TODO: refactor FileLoader to be independent of Desktop / Applet GUI
// bits ?
- if (raiseGUI && Desktop.desktop != null)
+ if (format.hasSequenceData() && raiseGUI
+ && Desktop.desktop != null)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
errorMessage, MessageManager
.getString("label.error_loading_file"),
- JOptionPane.WARNING_MESSAGE);
+ JvOptionPane.WARNING_MESSAGE);
}
});
}
@Override
public void run()
{
- javax.swing.JOptionPane.showInternalMessageDialog(
+ JvOptionPane.showInternalMessageDialog(
Desktop.desktop, MessageManager.formatMessage(
"label.problems_opening_file",
new String[] { file }), MessageManager
.getString("label.file_open_error"),
- javax.swing.JOptionPane.WARNING_MESSAGE);
+ JvOptionPane.WARNING_MESSAGE);
}
});
}
@Override
public void run()
{
- javax.swing.JOptionPane.showInternalMessageDialog(
+ JvOptionPane.showInternalMessageDialog(
Desktop.desktop, MessageManager.formatMessage(
"warn.out_of_memory_loading_file", new String[]
{ file }), MessageManager
.getString("label.out_of_memory"),
- javax.swing.JOptionPane.WARNING_MESSAGE);
+ JvOptionPane.WARNING_MESSAGE);
}
});
}
}
- /*
- * (non-Javadoc)
+ /**
+ * Helper method that adds the alignment as a new frame on the Desktop
*
- * @see java.lang.Object#finalize()
+ * @param al
+ * @param title
*/
- @Override
- protected void finalize() throws Throwable
+ protected void addAlignFrame(AlignmentI al, String title)
{
- source = null;
- alignFrame = null;
- viewport = null;
- super.finalize();
+ // otherwise construct the alignFrame
+
+ if (source instanceof ComplexAlignFile)
+ {
+ ColumnSelection colSel = ((ComplexAlignFile) source)
+ .getColumnSelection();
+ SequenceI[] hiddenSeqs = ((ComplexAlignFile) source)
+ .getHiddenSequences();
+ String colourSchemeName = ((ComplexAlignFile) source)
+ .getGlobalColourScheme();
+ FeaturesDisplayedI fd = ((ComplexAlignFile) source)
+ .getDisplayedFeatures();
+ alignFrame = new AlignFrame(al, hiddenSeqs, colSel,
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ alignFrame.getViewport().setFeaturesDisplayed(fd);
+ alignFrame.getViewport().setShowSequenceFeatures(
+ ((ComplexAlignFile) source).isShowSeqFeatures());
+ ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
+ colourSchemeName, al);
+ if (cs != null)
+ {
+ alignFrame.changeColour(cs);
+ }
+ }
+ else
+ {
+ alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ if (source instanceof FeaturesSourceI)
+ {
+ alignFrame.getViewport().setShowSequenceFeatures(true);
+ }
+ }
+ // add metadata and update ui
+ if (!(protocol == DataSourceType.PASTE))
+ {
+ alignFrame.setFileName(file, format);
+ }
+ FeatureSettingsModelI proxyColourScheme = source
+ .getFeatureColourScheme();
+ if (proxyColourScheme != null)
+ {
+ alignFrame.getViewport()
+ .applyFeaturesStyle(proxyColourScheme);
+ }
+ alignFrame.statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_loaded_file",
+ new String[] { title }));
+
+ if (raiseGUI)
+ {
+ // add the window to the GUI
+ // note - this actually should happen regardless of raiseGUI
+ // status in Jalview 3
+ // TODO: define 'virtual desktop' for benefit of headless scripts
+ // that perform queries to find the 'current working alignment'
+ Desktop.addInternalFrame(alignFrame, title,
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ try
+ {
+ alignFrame.setMaximum(jalview.bin.Cache.getDefault(
+ "SHOW_FULLSCREEN", false));
+ } catch (java.beans.PropertyVetoException ex)
+ {
+ }
}
}