import jalview.api.analysis.SimilarityParamsI;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
+import jalview.bin.Jalview;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.jar.JarOutputStream;
import javax.swing.JInternalFrame;
-import javax.swing.SwingUtilities;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
private Map<RnaModel, String> rnaSessions = new HashMap<>();
/**
+ * contains last error message (if any) encountered by XML loader.
+ */
+ String errorMessage = null;
+
+ /**
+ * flag to control whether the Jalview2XML_V1 parser should be deferred to if
+ * exceptions are raised during project XML parsing
+ */
+ public boolean attemptversion1parse = false;
+
+ /*
+ * JalviewJS only -- to allow read file bytes to be saved in the
+ * created AlignFrame, allowing File | Reload of a project file to work
+ *
+ * BH 2019 JAL-3436
+ */
+ private File jarFile;
+
+ /**
* A helper method for safely using the value of an optional attribute that
* may be null if not present in the XML. Answers the boolean value, or false
* if null.
* @param _jmap
* @return
*/
- public SeqFref newMappingRef(final String sref,
+ protected SeqFref newMappingRef(final String sref,
final jalview.datamodel.Mapping _jmap)
{
SeqFref fref = new SeqFref(sref, "Mapping")
return fref;
}
- public SeqFref newAlcodMapRef(final String sref,
+ protected SeqFref newAlcodMapRef(final String sref,
final AlignedCodonFrame _cf,
final jalview.datamodel.Mapping _jmap)
{
return fref;
}
- public void resolveFrefedSequences()
+ protected void resolveFrefedSequences()
{
Iterator<SeqFref> nextFref = frefedSequence.iterator();
int toresolve = frefedSequence.size();
* @param out
* jar entry name
*/
- public JalviewModel saveState(AlignmentPanel ap, String fileName,
+ protected JalviewModel saveState(AlignmentPanel ap, String fileName,
JarOutputStream jout, List<String> viewIds)
{
return saveState(ap, fileName, false, jout, viewIds);
* @param out
* jar entry name
*/
- public JalviewModel saveState(AlignmentPanel ap, String fileName,
+ protected JalviewModel saveState(AlignmentPanel ap, String fileName,
boolean storeDS, JarOutputStream jout, List<String> viewIds)
{
if (viewIds == null)
}
/**
- * contains last error message (if any) encountered by XML loader.
- */
- String errorMessage = null;
-
- /**
- * flag to control whether the Jalview2XML_V1 parser should be deferred to if
- * exceptions are raised during project XML parsing
- */
- public boolean attemptversion1parse = false;
-
- /**
- * JalviewJS only -- to preserve bytes in AlignFrame
- *
- * BH 2019 JAL-3436
- */
- private File file;
-
- /**
* Load a jalview project archive from a jar file
*
* @param file
{
try
{
+
// BH 2019 -- can't wait
- SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
System.err.println("Error loading alignment: " + x.getMessage());
}
}
+ this.jarFile = null;
return af;
}
@SuppressWarnings("unused")
- private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException {
-
- // BH 2018 allow for bytes already attached to File object
- try {
- String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString());
+ private jarInputStreamProvider createjarInputStreamProvider(
+ final Object ofile) throws MalformedURLException
+ {
+ try
+ {
+ String file = (ofile instanceof File
+ ? ((File) ofile).getCanonicalPath()
+ : ofile.toString());
byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile)
: null;
if (bytes != null)
{
- this.file = (File) ofile;
- }
- URL url = null;
- errorMessage = null;
- uniqueSetSuffix = null;
- seqRefIds = null;
- viewportsAdded.clear();
- frefedSequence = null;
-
- if (file.startsWith("http://")) {
- url = new URL(file);
- }
- final URL _url = url;
- return new jarInputStreamProvider() {
-
- @Override
- public JarInputStream getJarInputStream() throws IOException {
- if (bytes != null) {
-// System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length);
- return new JarInputStream(new ByteArrayInputStream(bytes));
- }
- if (_url != null) {
-// System.out.println("Jalview2XML: opening url jarInputStream for " + _url);
- return new JarInputStream(_url.openStream());
- } else {
-// System.out.println("Jalview2XML: opening file jarInputStream for " + file);
- return new JarInputStream(new FileInputStream(file));
- }
- }
-
- @Override
- public String getFilename() {
- return file;
- }
- };
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
+ this.jarFile = (File) ofile;
+ }
+ errorMessage = null;
+ uniqueSetSuffix = null;
+ seqRefIds = null;
+ viewportsAdded.clear();
+ frefedSequence = null;
+
+ URL url = file.startsWith("http://") ? new URL(file) : null;
+ return new jarInputStreamProvider()
+ {
+ @Override
+ public JarInputStream getJarInputStream() throws IOException
+ {
+ InputStream is = bytes != null ? new ByteArrayInputStream(bytes)
+ : (url != null ? url.openStream()
+ : new FileInputStream(file));
+ return new JarInputStream(is);
+ }
+
+ @Override
+ public String getFilename()
+ {
+ return file;
+ }
+ };
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
/**
* Recover jalview session from a jalview project archive. Caller may
* data source provider
* @return alignment frame created from view stored in DOM
*/
- AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
+ private AlignFrame loadFromObject(JalviewModel jalviewModel, String file,
boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
{
-// Platform.timeCheck("Jalview2XML.loadFromObject0", Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject0", Platform.TIME_MARK);
- SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet().get(0);
+ SequenceSet vamsasSet = jalviewModel.getVamsasModel().getSequenceSet()
+ .get(0);
List<Sequence> vamsasSeqs = vamsasSet.getSequence();
-
// JalviewModelSequence jms = object.getJalviewModelSequence();
// Viewport view = (jms.getViewportCount() > 0) ? jms.getViewport(0)
: view.getId() + uniqueSetSuffix);
}
-// Platform.timeCheck("Jalview2XML.loadFromObject1", Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject1", Platform.TIME_MARK);
// ////////////////////////////////
// LOAD SEQUENCES
}
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-seq",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-seq",
+ // Platform.TIME_MARK);
// /
// Create the alignment object from the sequence set
// ///////////////////////////////
recoverDatasetFor(vamsasSet, al, isdsal, uniqueSeqSetId);
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-align",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-align",
+ // Platform.TIME_MARK);
if (referenceseqForView != null)
{
al.setSeqrep(referenceseqForView);
al.setProperty(ssp.getKey(), ssp.getValue());
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-setseqprop",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-setseqprop",
+ // Platform.TIME_MARK);
// ///////////////////////////////
Hashtable pdbloaded = new Hashtable(); // TODO nothing writes to this??
// now, for 2.10 projects, this is also done if the xml doc includes
// dataset sequences not actually present in any particular view.
//
-// Platform.timeCheck("J2XML features0", Platform.TIME_RESET);
+ // Platform.timeCheck("J2XML features0", Platform.TIME_RESET);
for (int i = 0; i < vamsasSeqs.size(); i++)
{
JSeq jseq = jseqs.get(i);
}
// adds feature to datasequence's feature set (since Jalview 2.10)
-// Platform.timeCheck(null, Platform.TIME_SET);
+ // Platform.timeCheck(null, Platform.TIME_SET);
al.getSequenceAt(i).addSequenceFeature(sf);
-// Platform.timeCheck(null, Platform.TIME_MARK);
+ // Platform.timeCheck(null, Platform.TIME_MARK);
}
}
if (vamsasSeqs.get(i).getDBRef().size() > 0)
{
entry.setProperty(prop.getName(), prop.getValue());
}
- Desktop.getStructureSelectionManager()
- .registerPDBEntry(entry);
+ Desktop.getStructureSelectionManager().registerPDBEntry(entry);
// adds PDBEntry to datasequence's set (since Jalview 2.10)
if (al.getSequenceAt(i).getDatasetSequence() != null)
{
}
-// Platform.timeCheck("features done", Platform.TIME_GET);
-// Platform.timeCheck("Jalview2XML.loadFromObject-endmultiview",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("features done", Platform.TIME_GET);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-endmultiview",
+ // Platform.TIME_MARK);
} // end !multipleview
// ///////////////////////////////
else
{
// defer to later
- frefedSequence.add(
- newAlcodMapRef(map.getDnasq(), cf, mapping));
+ frefedSequence
+ .add(newAlcodMapRef(map.getDnasq(), cf, mapping));
}
}
}
al.addCodonFrame(cf);
}
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-seqmap",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-seqmap",
+ // Platform.TIME_MARK);
}
// ////////////////////////////////
}
// Construct new annotation from model.
List<AnnotationElement> ae = annotation.getAnnotationElement();
-// System.err.println(
-// "Jalview2XML processing " + ae.size() + " annotations");
+ // System.err.println(
+ // "Jalview2XML processing " + ae.size() + " annotations");
jalview.datamodel.Annotation[] anot = null;
java.awt.Color firstColour = null;
jaa.setCalcId(annotation.getCalcId());
if (annotation.getProperty().size() > 0)
{
- for (Annotation.Property prop : annotation
- .getProperty())
+ for (Annotation.Property prop : annotation.getProperty())
{
jaa.setProperty(prop.getName(), prop.getValue());
}
al.addAnnotation(jaa);
}
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-annot",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-annot",
+ // Platform.TIME_MARK);
}
// ///////////////////////
// LOAD GROUPS
sg.setShowNonconserved(safeBoolean(jGroup.isShowUnconserved()));
sg.thresholdTextColour = safeInt(jGroup.getTextColThreshold());
// attributes with a default in the schema are never null
- sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
- sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
- sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
+ sg.setShowConsensusHistogram(jGroup.isShowConsensusHistogram());
+ sg.setshowSequenceLogo(jGroup.isShowSequenceLogo());
+ sg.setNormaliseSequenceLogo(jGroup.isNormaliseSequenceLogo());
sg.setIgnoreGapsConsensus(jGroup.isIgnoreGapsinConsensus());
if (jGroup.getConsThreshold() != null
&& jGroup.getConsThreshold().intValue() != 0)
if (addAnnotSchemeGroup)
{
// reconstruct the annotation colourscheme
- sg.setColourScheme(constructAnnotationColour(
- jGroup.getAnnotationColours(), null, al, jalviewModel, false));
+ sg.setColourScheme(
+ constructAnnotationColour(jGroup.getAnnotationColours(),
+ null, al, jalviewModel, false));
}
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-groups",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-groups",
+ // Platform.TIME_MARK);
}
if (view == null)
{
}
}
-// Platform.timeCheck("Jalview2XML.loadFromObject-viewport",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-viewport",
+ // Platform.TIME_MARK);
}
/**
* indicate that annotation colours are applied across all groups (pre
final AlignFrame af0 = af;
final AlignViewport av0 = av;
final AlignmentPanel ap0 = ap;
-// Platform.timeCheck("Jalview2XML.loadFromObject-beforetree",
-// Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadFromObject-beforetree",
+ // Platform.TIME_MARK);
if (loadTreesAndStructures)
{
if (!jalviewModel.getTree().isEmpty())
{
- SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
{
-// Platform.timeCheck(null, Platform.TIME_MARK);
+ // Platform.timeCheck(null, Platform.TIME_MARK);
loadTrees(jalviewModel, view, af0, av0, ap0);
-// Platform.timeCheck("Jalview2XML.loadTrees", Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadTrees", Platform.TIME_MARK);
}
});
}
if (!jalviewModel.getPcaViewer().isEmpty())
{
- SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
{
-// Platform.timeCheck(null, Platform.TIME_MARK);
+ // Platform.timeCheck(null, Platform.TIME_MARK);
loadPCAViewers(jalviewModel, ap0);
-// Platform.timeCheck("Jalview2XML.loadPCA", Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadPCA", Platform.TIME_MARK);
}
});
}
- SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
{
-// Platform.timeCheck(null, Platform.TIME_MARK);
+ // Platform.timeCheck(null, Platform.TIME_MARK);
loadPDBStructures(jprovider, jseqs, af0, ap0);
-// Platform.timeCheck("Jalview2XML.loadPDB", Platform.TIME_MARK);
+ // Platform.timeCheck("Jalview2XML.loadPDB", Platform.TIME_MARK);
}
});
- SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
loadRnaViewers(jprovider, jseqs, ap0);
}
});
+
}
// and finally return.
// but do not set holdRepaint true just yet, because this could be the
svattrib.getWidth(), svattrib.getHeight());
// try
// {
- javax.swing.SwingUtilities.invokeLater(new Runnable()
+ Jalview.execRunnable(new Runnable()
{
@Override
public void run()
}
}
}
- });
+ });
+ // javax.swing.SwingUtilities.invokeLater(r);
// } catch (InvocationTargetException ex)
// {
// warn("Unexpected error when opening Jmol view.", ex);
;
af.alignPanel.setHoldRepaint(true);
af.setFileName(fileName, FileFormat.Jalview);
- af.setFileObject(file); // BH 2019 JAL-3436
+ af.setFileObject(jarFile); // BH 2019 JAL-3436
final AlignViewport viewport = af.getViewport();
for (int i = 0; i < JSEQ.size(); i++)
return false;
}
- public void addToSkipList(AlignFrame af)
+ protected void addToSkipList(AlignFrame af)
{
if (skipList == null)
{
skipList.put(af.getViewport().getSequenceSetId(), af);
}
- public void clearSkipList()
+ protected void clearSkipList()
{
if (skipList != null)
{
af.getAlignPanels().clear();
af.closeMenuItem_actionPerformed(true);
af.alignPanel.setHoldRepaint(false);
+ this.jarFile = null;
return af.alignPanel;
}