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;
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(AlignmentFileReaderI 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.
*
@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
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;
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()
{
}
- /*
- * (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)
+ {
+ }
}
}