import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
import jalview.datamodel.GraphLine;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Point;
import java.awt.Font;
import java.awt.Rectangle;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
*/
public class Jalview2XML
{
+
+ // BH 2018 we add the .jvp binary extension to J2S so that
+ // it will declare that binary when we do the file save from the browser
+
+ static
+ {
+ Platform.addJ2SBinaryType(".jvp?");
+ }
+
private static final String VIEWER_PREFIX = "viewer_";
private static final String RNA_PREFIX = "rna_";
public boolean isResolvable()
{
return super.isResolvable() && mp.getTo() != null;
- };
+ }
@Override
boolean resolve()
} catch (Exception foo)
{
}
- ;
jout.close();
} catch (Exception ex)
{
try
{
// create backupfiles object and get new temp filename destination
- BackupFiles backupfiles = new BackupFiles(jarFile);
- FileOutputStream fos = new FileOutputStream(
- backupfiles.getTempFilePath());
+ boolean doBackup = BackupFiles.getEnabled();
+ BackupFiles backupfiles = doBackup ? new BackupFiles(jarFile) : null;
+ FileOutputStream fos = new FileOutputStream(doBackup ?
+ backupfiles.getTempFilePath() : jarFile);
JarOutputStream jout = new JarOutputStream(fos);
List<AlignFrame> frames = new ArrayList<>();
} catch (Exception foo)
{
}
- ;
jout.close();
boolean success = true;
- backupfiles.setWriteSuccess(success);
- success = backupfiles.rollBackupsAndRenameTempFile();
+ if (doBackup)
+ {
+ backupfiles.setWriteSuccess(success);
+ success = backupfiles.rollBackupsAndRenameTempFile();
+ }
return success;
} catch (Exception ex)
* only view *should* be coped with sensibly.
*/
// This must have been loaded, is it still visible?
- JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
String matchedFile = null;
for (int f = frames.length - 1; f > -1; f--)
{
{
// FIND ANY ASSOCIATED TREES
// NOT IMPLEMENTED FOR HEADLESS STATE AT PRESENT
- if (Desktop.desktop != null)
+ if (Desktop.getDesktopPane() != null)
{
- JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
for (int t = 0; t < frames.length; t++)
{
/*
* save PCA viewers
*/
- if (!storeDS && Desktop.desktop != null)
+ if (!storeDS && Desktop.getDesktopPane() != null)
{
- for (JInternalFrame frame : Desktop.desktop.getAllFrames())
+ for (JInternalFrame frame : Desktop.getDesktopPane().getAllFrames())
{
if (frame instanceof PCAPanel)
{
// using save and then load
try
{
+ fileName = fileName.replace('\\', '/');
System.out.println("Writing jar entry " + fileName);
JarEntry entry = new JarEntry(fileName);
jout.putNextEntry(entry);
final SequenceI jds, List<String> viewIds, AlignmentPanel ap,
boolean storeDataset)
{
- if (Desktop.desktop == null)
+ if (Desktop.getDesktopPane() == null)
{
return;
}
- JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
for (int f = frames.length - 1; f > -1; f--)
{
if (frames[f] instanceof AppVarna)
{
if (jout != null)
{
+ jarEntryName = jarEntryName.replace('\\','/');
System.out.println("Writing jar entry " + jarEntryName);
jout.putNextEntry(new JarEntry(jarEntryName));
DataOutputStream dout = new DataOutputStream(jout);
vamsasSeq.setName(jds.getName());
vamsasSeq.setSequence(jds.getSequenceAsString());
vamsasSeq.setDescription(jds.getDescription());
- jalview.datamodel.DBRefEntry[] dbrefs = null;
+ List<DBRefEntry> dbrefs = null;
if (jds.getDatasetSequence() != null)
{
vamsasSeq.setDsseqid(seqHash(jds.getDatasetSequence()));
}
if (dbrefs != null)
{
- for (int d = 0; d < dbrefs.length; d++)
+ for (int d = 0, nd = dbrefs.size(); d < nd; d++)
{
DBRef dbref = new DBRef();
- dbref.setSource(dbrefs[d].getSource());
- dbref.setVersion(dbrefs[d].getVersion());
- dbref.setAccessionId(dbrefs[d].getAccessionId());
- if (dbrefs[d].hasMap())
+ DBRefEntry ref = dbrefs.get(d);
+ dbref.setSource(ref.getSource());
+ dbref.setVersion(ref.getVersion());
+ dbref.setAccessionId(ref.getAccessionId());
+ if (ref.hasMap())
{
- Mapping mp = createVamsasMapping(dbrefs[d].getMap(), parentseq,
+ Mapping mp = createVamsasMapping(ref.getMap(), parentseq,
jds, recurse);
dbref.setMapping(mp);
}
* @param file
* - HTTP URL or filename
*/
- public AlignFrame loadJalviewAlign(final String file)
+ public AlignFrame loadJalviewAlign(final Object file)
{
jalview.gui.AlignFrame af = null;
public void run()
{
setLoadingFinishedForNewStructureViewers();
- };
+ }
});
} catch (Exception x)
{
return af;
}
- private jarInputStreamProvider createjarInputStreamProvider(
- final String file) throws MalformedURLException
- {
- 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 (_url != null)
- {
- return new JarInputStream(_url.openStream());
- }
- else
- {
- return new JarInputStream(new FileInputStream(file));
- }
- }
-
- @Override
- public String getFilename()
- {
- return file;
- }
- };
- }
+ @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());
+ byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile)
+ : null;
+ 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;
+ }
+ }
/**
* Recover jalview session from a jalview project archive. Caller may
if (jarentry != null && jarentry.getName().endsWith(".xml"))
{
- InputStreamReader in = new InputStreamReader(jin, UTF_8);
- // JalviewModel object = new JalviewModel();
-
JAXBContext jc = JAXBContext
.newInstance("jalview.xml.binding.jalview");
XMLStreamReader streamReader = XMLInputFactory.newInstance()
.unmarshal(streamReader, JalviewModel.class);
JalviewModel object = jbe.getValue();
- /*
- Unmarshaller unmar = new Unmarshaller(object);
- unmar.setValidation(false);
- object = (JalviewModel) unmar.unmarshal(in);
- */
if (true) // !skipViewport(object))
{
_af = loadFromObject(object, file, true, jprovider);
{
// used to attempt to parse as V1 castor-generated xml
}
- if (Desktop.instance != null)
+ if (Desktop.getInstance() != null)
{
- Desktop.instance.stopLoading();
+ Desktop.getInstance().stopLoading();
}
if (af != null)
{
*/
for (AlignFrame fr : gatherToThisFrame.values())
{
- Desktop.instance.gatherViews(fr);
+ Desktop.getInstance().gatherViews(fr);
}
restoreSplitFrames();
if (ds.getCodonFrames() != null)
{
StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance)
+ .getStructureSelectionManager(Desktop.getInstance())
.registerMappings(ds.getCodonFrames());
}
}
reportErrors();
}
- if (Desktop.instance != null)
+ if (Desktop.getInstance() != null)
{
- Desktop.instance.stopLoading();
+ Desktop.getInstance().stopLoading();
}
return af;
*/
for (SplitFrame sf : gatherTo)
{
- Desktop.instance.gatherViews(sf);
+ Desktop.getInstance().gatherViews(sf);
}
splitFrameCandidates.clear();
@Override
public void run()
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
finalErrorMessage,
"Error " + (saving ? "saving" : "loading")
+ " Jalview file",
entry.setProperty(prop.getName(), prop.getValue());
}
StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance)
+ .getStructureSelectionManager(Desktop.getInstance())
.registerPDBEntry(entry);
// adds PDBEntry to datasequence's set (since Jalview 2.10)
if (al.getSequenceAt(i).getDatasetSequence() != null)
}
else
{
- cs = ColourSchemeProperty.getColourScheme(al,
+ cs = ColourSchemeProperty.getColourScheme(null, al,
jGroup.getColour());
}
}
// TODO: verify 'associate with all views' works still
tp.getTreeCanvas().setViewport(av); // af.viewport;
tp.getTreeCanvas().setAssociatedPanel(ap); // af.alignPanel;
- // FIXME: should we use safeBoolean here ?
- tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
-
}
+ tp.getTreeCanvas().setApplyToAllViews(tree.isLinkToAllViews());
if (tp == null)
{
warn("There was a problem recovering stored Newick tree: \n"
int height = safeInt(structureState.getHeight());
// Probably don't need to do this anymore...
- // Desktop.desktop.getComponentAt(x, y);
+ // Desktop.getDesktop().getComponentAt(x, y);
// TODO: NOW: check that this recovers the PDB file correctly.
String pdbFile = loadPDBFile(jprovider, pdbid.getId(),
pdbid.getFile());
{
try
{
- frames = Desktop.desktop.getAllFrames();
+ frames = Desktop.getDesktopPane().getAllFrames();
} catch (ArrayIndexOutOfBoundsException e)
{
// occasional No such child exceptions are thrown here...
{
AlignFrame af = null;
af = new AlignFrame(al, safeInt(view.getWidth()),
- safeInt(view.getHeight()), uniqueSeqSetId, viewId);
+ safeInt(view.getHeight()), uniqueSeqSetId, viewId)
+// {
+//
+// @Override
+// protected void processKeyEvent(java.awt.event.KeyEvent e) {
+// System.out.println("Jalview2XML AF " + e);
+// super.processKeyEvent(e);
+//
+// }
+//
+// }
+ ;
af.setFileName(file, FileFormat.Jalview);
}
else
{
- cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
+ cs = ColourSchemeProperty.getColourScheme(af.getViewport(), al,
+ view.getBgColour());
}
}
+ /*
+ * turn off 'alignment colour applies to all groups'
+ * while restoring global colour scheme
+ */
+ viewport.setColourAppliesToAllGroups(false);
viewport.setGlobalColourScheme(cs);
viewport.getResidueShading().setThreshold(pidThreshold,
view.isIgnoreGapsinConsensus());
viewport.getResidueShading()
.setConsensus(viewport.getSequenceConsensusHash());
- viewport.setColourAppliesToAllGroups(false);
-
if (safeBoolean(view.isConservationSelected()) && cs != null)
{
viewport.getResidueShading()
.setConservationInc(safeInt(view.getConsThreshold()));
}
-
af.changeColour(cs);
-
viewport.setColourAppliesToAllGroups(true);
viewport
float min = safeFloat(safeFloat(setting.getMin()));
float max = setting.getMax() == null ? 1f
: setting.getMax().floatValue();
- FeatureColourI gc = new FeatureColour(minColour, maxColour,
+ FeatureColourI gc = new FeatureColour(maxColour, minColour,
+ maxColour,
noValueColour, min, max);
if (setting.getAttributeName().size() > 0)
{
else
{
cs = new AnnotationColourGradient(matchedAnnotation,
- ColourSchemeProperty.getColourScheme(al,
+ ColourSchemeProperty.getColourScheme(af.getViewport(), al,
viewAnnColour.getColourScheme()),
safeInt(viewAnnColour.getAboveThreshold()));
}
noValueColour = maxcol;
}
- colour = new FeatureColour(mincol, maxcol, noValueColour,
+ colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour,
safeFloat(colourModel.getMin()),
safeFloat(colourModel.getMax()));
final List<String> attributeName = colourModel.getAttributeName();