examples/javascript/deployJava.js : http://java.com/js/deployJava.js
examples/javascript/jquery*.js : BSD license
examples/javascript/jshashtable-2.1.js : Apache License
+examples/javascript/facebox-1.3.js : MTI License - http://www.opensource.org/licenses/mit-license.php
--- /dev/null
+/*
+ * Facebox (for jQuery)
+ * version: 1.2 (05/05/2008)
+ * @requires jQuery v1.2 or later
+ *
+ * Examples at http://famspam.com/facebox/
+ *
+ * Licensed under the MIT:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
+ *
+ * Usage:
+ *
+ * jQuery(document).ready(function() {
+ * jQuery('a[rel*=facebox]').facebox()
+ * })
+ *
+ * <a href="#terms" rel="facebox">Terms</a>
+ * Loads the #terms div in the box
+ *
+ * <a href="terms.html" rel="facebox">Terms</a>
+ * Loads the terms.html page in the box
+ *
+ * <a href="terms.png" rel="facebox">Terms</a>
+ * Loads the terms.png image in the box
+ *
+ *
+ * You can also use it programmatically:
+ *
+ * jQuery.facebox('some html')
+ * jQuery.facebox('some html', 'my-groovy-style')
+ *
+ * The above will open a facebox with "some html" as the content.
+ *
+ * jQuery.facebox(function($) {
+ * $.get('blah.html', function(data) { $.facebox(data) })
+ * })
+ *
+ * The above will show a loading screen before the passed function is called,
+ * allowing for a better ajaxy experience.
+ *
+ * The facebox function can also display an ajax page, an image, or the contents of a div:
+ *
+ * jQuery.facebox({ ajax: 'remote.html' })
+ * jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')
+ * jQuery.facebox({ image: 'stairs.jpg' })
+ * jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')
+ * jQuery.facebox({ div: '#box' })
+ * jQuery.facebox({ div: '#box' }, 'my-groovy-style')
+ *
+ * Want to close the facebox? Trigger the 'close.facebox' document event:
+ *
+ * jQuery(document).trigger('close.facebox')
+ *
+ * Facebox also has a bunch of other hooks:
+ *
+ * loading.facebox
+ * beforeReveal.facebox
+ * reveal.facebox (aliased as 'afterReveal.facebox')
+ * init.facebox
+ * afterClose.facebox
+ *
+ * Simply bind a function to any of these hooks:
+ *
+ * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
+ *
+ */
+(function($) {
+ $.facebox = function(data, klass) {
+ $.facebox.loading()
+
+ if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
+ else if (data.image) fillFaceboxFromImage(data.image, klass)
+ else if (data.div) fillFaceboxFromHref(data.div, klass)
+ else if ($.isFunction(data)) data.call($)
+ else $.facebox.reveal(data, klass)
+ }
+
+ /*
+ * Public, $.facebox methods
+ */
+
+ $.extend($.facebox, {
+ settings: {
+ opacity : 0.2,
+ overlay : true,
+ loadingImage : 'https://raw.githubusercontent.com/jalview/biojson/gh-pages/images/loading.gif',
+ closeImage : 'https://raw.githubusercontent.com/jalview/biojson/gh-pages/images/cancel.png',
+ imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],
+ faceboxHtml : '\
+ <div id="facebox" style="display:none;"> \
+ <div class="popup"> \
+ <div class="content"> \
+ </div> \
+ <a href="#" class="close"><img src="https://raw.githubusercontent.com/jalview/biojson/gh-pages/images/cancel.png" title="close" class="close_image" /></a> \
+ </div> \
+ </div>'
+ },
+
+ loading: function() {
+ init()
+ if ($('#facebox .loading').length == 1) return true
+ showOverlay()
+
+ $('#facebox .content').empty()
+ $('#facebox .body').children().hide().end().
+ append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')
+
+ $('#facebox').css({
+ top: getPageScroll()[1] + (getPageHeight() / 10),
+ left: $(window).width() / 2 - 205
+ }).show()
+
+ $(document).bind('keydown.facebox', function(e) {
+ if (e.keyCode == 27) $.facebox.close()
+ return true
+ })
+ $(document).trigger('loading.facebox')
+ },
+
+ reveal: function(data, klass) {
+ $(document).trigger('beforeReveal.facebox')
+ if (klass) $('#facebox .content').addClass(klass)
+ $('#facebox .content').append('<pre><code>'+JSON.stringify(JSON.parse(data),null,4)+'</pre></code>')
+ $('#facebox .loading').remove()
+ $('#facebox .body').children().fadeIn('normal')
+ $('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').width() / 2))
+ $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
+ },
+
+ close: function() {
+ $(document).trigger('close.facebox')
+ return false
+ }
+ })
+
+ /*
+ * Public, $.fn methods
+ */
+
+ $.fn.facebox = function(settings) {
+ if ($(this).length == 0) return
+
+ init(settings)
+
+ function clickHandler() {
+ $.facebox.loading(true)
+
+ // support for rel="facebox.inline_popup" syntax, to add a class
+ // also supports deprecated "facebox[.inline_popup]" syntax
+ var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
+ if (klass) klass = klass[1]
+
+ fillFaceboxFromHref(this.href, klass)
+ return false
+ }
+
+ return this.bind('click.facebox', clickHandler)
+ }
+
+ /*
+ * Private methods
+ */
+
+ // called one time to setup facebox on this page
+ function init(settings) {
+ if ($.facebox.settings.inited) return true
+ else $.facebox.settings.inited = true
+
+ $(document).trigger('init.facebox')
+ makeCompatible()
+
+ var imageTypes = $.facebox.settings.imageTypes.join('|')
+ $.facebox.settings.imageTypesRegexp = new RegExp('\.(' + imageTypes + ')$', 'i')
+
+ if (settings) $.extend($.facebox.settings, settings)
+ $('body').append($.facebox.settings.faceboxHtml)
+
+ var preload = [ new Image(), new Image() ]
+ preload[0].src = $.facebox.settings.closeImage
+ preload[1].src = $.facebox.settings.loadingImage
+
+ $('#facebox').find('.b:first, .bl').each(function() {
+ preload.push(new Image())
+ preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
+ })
+
+ $('#facebox .close').click($.facebox.close)
+ $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
+ }
+
+ // getPageScroll() by quirksmode.com
+ function getPageScroll() {
+ var xScroll, yScroll;
+ if (self.pageYOffset) {
+ yScroll = self.pageYOffset;
+ xScroll = self.pageXOffset;
+ } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
+ yScroll = document.documentElement.scrollTop;
+ xScroll = document.documentElement.scrollLeft;
+ } else if (document.body) {// all other Explorers
+ yScroll = document.body.scrollTop;
+ xScroll = document.body.scrollLeft;
+ }
+ return new Array(xScroll,yScroll)
+ }
+
+ // Adapted from getPageSize() by quirksmode.com
+ function getPageHeight() {
+ var windowHeight
+ if (self.innerHeight) { // all except Explorer
+ windowHeight = self.innerHeight;
+ } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
+ windowHeight = document.documentElement.clientHeight;
+ } else if (document.body) { // other Explorers
+ windowHeight = document.body.clientHeight;
+ }
+ return windowHeight
+ }
+
+ // Backwards compatibility
+ function makeCompatible() {
+ var $s = $.facebox.settings
+
+ $s.loadingImage = $s.loading_image || $s.loadingImage
+ $s.closeImage = $s.close_image || $s.closeImage
+ $s.imageTypes = $s.image_types || $s.imageTypes
+ $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
+ }
+
+ // Figures out what you want to display and displays it
+ // formats are:
+ // div: #id
+ // image: blah.extension
+ // ajax: anything else
+ function fillFaceboxFromHref(href, klass) {
+ // div
+ if (href.match(/#/)) {
+ var url = window.location.href.split('#')[0]
+ var target = href.replace(url,'')
+ if (target == '#') return
+ $.facebox.reveal($(target).html(), klass)
+
+ // image
+ } else if (href.match($.facebox.settings.imageTypesRegexp)) {
+ fillFaceboxFromImage(href, klass)
+ // ajax
+ } else {
+ fillFaceboxFromAjax(href, klass)
+ }
+ }
+
+ function fillFaceboxFromImage(href, klass) {
+ var image = new Image()
+ image.onload = function() {
+ $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
+ }
+ image.src = href
+ }
+
+ function fillFaceboxFromAjax(href, klass) {
+ $.get(href, function(data) { $.facebox.reveal(data, klass) })
+ }
+
+ function skipOverlay() {
+ return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
+ }
+
+ function showOverlay() {
+ if (skipOverlay()) return
+
+ if ($('#facebox_overlay').length == 0)
+ $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')
+
+ $('#facebox_overlay').hide().addClass("facebox_overlayBG")
+ .css('opacity', $.facebox.settings.opacity)
+ .click(function() { $(document).trigger('close.facebox') })
+ .fadeIn(200)
+ return false
+ }
+
+ function hideOverlay() {
+ if (skipOverlay()) return
+
+ $('#facebox_overlay').fadeOut(200, function(){
+ $("#facebox_overlay").removeClass("facebox_overlayBG")
+ $("#facebox_overlay").addClass("facebox_hide")
+ $("#facebox_overlay").remove()
+ })
+
+ return false
+ }
+
+ /*
+ * Bindings
+ */
+
+ $(document).bind('close.facebox', function() {
+ $(document).unbind('keydown.facebox')
+ $('#facebox').fadeOut(function() {
+ $('#facebox .content').removeClass().addClass('content')
+ $('#facebox .loading').remove()
+ $(document).trigger('afterClose.facebox')
+ })
+ hideOverlay()
+ })
+
+})(jQuery);
</p>
<p>Selecting this option causes the colour scheme to be applied to
only those residues that occur in that column more than a certain
- percentage of the time. For instance selecting the threshold to be
- 100 will only colour those columns with 100 % identity. This
- threshold option can be applied to the Zappo, Taylor, Hydrophobicity
- and User colour schemes.</p>
+ percentage of the time. For instance, selecting the threshold to be
+ 100 will only colour those columns with 100% identity.</p>
+ <p>To be coloured, a residue must match the consensus (most commonly occurring) residue for the column (or joint equal consensus).</p>
+ <p>The percentage calculation may include or exclude gaps in the column, depending on the option selected for the <a href="../calculations/consensus.html">consensus calculation</a>.</p>
+ <p>With a threshold of 0, colouring is unchanged (including non-consensus residues).</p>
</body>
</html>
a colour the feature).</p>
<p>
- If your sequence annotation is already available in GFF Format (see
- <a href="http://gmod.org/wiki/GFF2">gmod.org/wiki/GFF2</a>), then
- you can leave it as is, after first adding a line containing only
+ If your sequence annotation is already available in <a href="http://gmod.org/wiki/GFF2">GFF2</a> (http://gmod.org/wiki/GFF2) or
+ <a href="https://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md">GFF3</a>
+ (http://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md) format,
+ then you can leave it as is, after first adding a line containing only
'GFF' after any Jalview feature colour definitions (<em>this
- mixed format capability was added in Jalview 2.6</em>). Alternately,
+ mixed format capability was added in Jalview 2.6</em>). Alternately,
you can use Jalview's own sequence feature annotation format, which
additionally allows HTML and URLs to be directly attached to each
piece of annotation.
the match. For example, a simple query like "ACDED" would
match all occurences of that string, but "ACD+ED" matches
both 'ACDDED' and 'ACDDDDDDDDED'. More usefully, the query
- "[ILGVMA]{;5,}" would find stretches of small, hydrophobic
+ "[GVATC]{;5,}" would find stretches of small, hydrophobic
amino acids of at least five residues in length.</p>
<p>
The table below describes some of the regular expression syntax:<br>
label.translation_failed = Translation Failed
label.error_when_translating_sequences_submit_bug_report = Desafortunadamente, algo fue mal a la hora de traducir tus secuencias.\nPor favor, revisa la consola Jalview java \ny presenta un informe de error que incluya el seguimiento.
label.implementation_error = Error de implementación:
-label.automatically_associate_structure_files_with_sequences_same_name = Quieres asociar automáticamente los {0} ficheros structure con las secuencias del alineamiento que tengan el mismo nombre?
-label.automatically_associate_structure_files_by_name = Asociar los ficheros structure por nombre automáticamente
+label.automatically_associate_structure_files_with_sequences_same_name = Quieres asociar automáticamente los {0} ficheros estructura con las secuencias del alineamiento que tengan el mismo nombre?
+label.automatically_associate_structure_files_by_name = Asociar los ficheros estructura por nombre automáticamente
label.ignore_unmatched_dropped_files_info = Quieres <em>ignorar</em> los {0} ficheros cuyos nombres no coincidan con ningún IDs de las secuencias ?
label.ignore_unmatched_dropped_files = Ignorar los ficheros sin coincidencias?
label.enter_view_name = Introduzca un nombre para la vista
import jalview.schemes.ResidueProperties;
import jalview.structure.StructureImportSettings;
import jalview.structure.StructureMapping;
+import jalview.util.Comparison;
import java.awt.Color;
import java.util.List;
pdbpos++;
}
- if (as.astr1.charAt(i) == as.astr2.charAt(i))
+ boolean sameResidue = Comparison.isSameResidue(as.astr1.charAt(i),
+ as.astr2.charAt(i), false);
+ if (sameResidue)
{
if (pdbpos >= residues.size())
{
{
if ((i + (j * len)) < astr1.length())
{
- if (astr1.charAt(i + (j * len)) == astr2.charAt(i + (j * len))
+ boolean sameChar = Comparison.isSameResidue(
+ astr1.charAt(i + (j * len)), astr2.charAt(i + (j * len)),
+ false);
+ if (sameChar
&& !jalview.util.Comparison.isGap(astr1.charAt(i
+ (j * len))))
{
this.ap = ap;
jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(),
new PDBEntry[] { pdbentry }, new SequenceI[][] { seq },
- new String[][] { chains }, protocol);
+ protocol);
jmb.setColourBySequence(true);
if (pdbentry.getId() == null || pdbentry.getId().length() < 1)
{
jmb.loadInline(string);
}
- void setChainMenuItems(Vector<String> chains)
+ void setChainMenuItems(List<String> chains)
{
chainMenu.removeAll();
repaint();
return;
}
- setChainMenuItems(jmb.chainNames);
+ setChainMenuItems(jmb.getChainNames());
jmb.colourBySequence(ap);
setTitle(jmb.getViewerTitle());
public AppletJmolBinding(AppletJmol appletJmol,
StructureSelectionManager sSm, PDBEntry[] pdbentry,
- SequenceI[][] seq, String[][] chains, String protocol)
+ SequenceI[][] seq, String protocol)
{
- super(sSm, pdbentry, seq, chains, protocol);
+ super(sSm, pdbentry, seq, protocol);
appletJmolBinding = appletJmol;
}
appletJmolBinding.updateTitleAndMenus();
}
+ @Override
public void updateColours(Object source)
{
AlignmentPanel ap = (AlignmentPanel) source;
colourBySequence(ap);
}
+ @Override
public void showUrl(String url)
{
try
// do nothing.
}
+ @Override
public void selectionChanged(BS arg0)
{
// TODO Auto-generated method stub
private AlignmentPanel ap;
protected ExtJmol(jalview.appletgui.AlignFrame alframe,
- PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains,
+ PDBEntry[] pdbentry, SequenceI[][] seq,
String protocol)
{
super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq,
- chains, protocol);
+ protocol);
}
public ExtJmol(Viewer viewer, AlignmentPanel alignPanel,
notifyFileLoaded(null, null, null, null, 0);
}
+ @Override
public void updateColours(Object source)
{
}
+ @Override
public void showUrl(String arg0)
{
showUrl(arg0, "jmol");
// ignore
}
+ @Override
public void selectionChanged(BS arg0)
{
System.out.println(arg0);
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.security.AllPermission;
import java.security.CodeSource;
{
File imageFile = new File(file);
imageName = imageFile.getName();
- new HtmlSvgOutput(new File(file), af.alignPanel);
+ HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
+ htmlSVG.exportHTML(file);
+
System.out.println("Creating HTML image: " + file);
continue;
}
else if (format.equalsIgnoreCase("biojsmsa"))
{
- BioJsHTMLOutput.updateBioJS();
+ if (file == null)
+ {
+ System.err.println("The output html file must not be null");
+ return;
+ }
try
{
- Thread.sleep(1500);
- } catch (InterruptedException e)
+ BioJsHTMLOutput
+ .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ } catch (URISyntaxException e)
{
e.printStackTrace();
}
- BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel, af);
- bjs.exportJalviewAlignmentAsBioJsHtmlFile(file);
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
+ bjs.exportHTML(file);
System.out.println("Creating BioJS MSA Viwer HTML file: "
+ file);
continue;
{
}
- /**
- * Constructor given file path and PDB id.
- *
- * @param filePath
- */
- // public PDBEntry(String filePath, String pdbId)
- // {
- // this.file = filePath;
- // this.id = pdbId;
- // }
public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
String filePath)
}
SequenceFeature sf = (SequenceFeature) o;
- if (begin != sf.begin || end != sf.end || score != sf.score)
+ boolean sameScore = Float.isNaN(score) ? Float.isNaN(sf.score)
+ : score == sf.score;
+ if (begin != sf.begin || end != sf.end || !sameScore)
{
return false;
}
Vector<String> atomsPicked = new Vector<String>();
- public Vector<String> chainNames;
+ private List<String> chainNames;
Hashtable<String, String> chainFile;
public Viewer viewer;
public JalviewJmolBinding(StructureSelectionManager ssm,
- PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
+ PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
String protocol)
{
- super(ssm, pdbentry, sequenceIs, chains, protocol);
+ super(ssm, pdbentry, sequenceIs, protocol);
/*
* viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
* "jalviewJmol", ap.av.applet .getDocumentBase(),
fileLoadingError = null;
String[] oldmodels = modelFileNames;
modelFileNames = null;
- chainNames = new Vector<String>();
+ chainNames = new ArrayList<String>();
chainFile = new Hashtable<String, String>();
boolean notifyLoaded = false;
String[] modelfilenames = getPdbFile();
for (int pe = 0; pe < getPdbCount(); pe++)
{
boolean matches = false;
+ addSequence(pe, getSequence()[pe]);
if (fileName == null)
{
if (false)
String chid = new String(pdb.getId() + ":"
+ pdb.getChains().elementAt(i).id);
chainFile.put(chid, fileName);
- chainNames.addElement(chid);
+ chainNames.add(chid);
}
notifyLoaded = true;
}
setLoadingFromArchive(false);
}
+ @Override
+ public List<String> getChainNames()
+ {
+ return chainNames;
+ }
+
public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
{
notifyAtomPicked(iatom, strMeasure, null);
import java.awt.Color;
import java.net.BindException;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
private static final String ALPHACARBON = "CA";
+ private List<String> chainNames = new ArrayList<String>();
+
+ private Hashtable<String, String> chainFile = new Hashtable<String, String>();
/*
* Object through which we talk to Chimera
*/
* @param protocol
*/
public JalviewChimeraBinding(StructureSelectionManager ssm,
- PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
- String protocol)
+ PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol)
{
- super(ssm, pdbentry, sequenceIs, chains, protocol);
+ super(ssm, pdbentry, sequenceIs, protocol);
viewer = new ChimeraManager(
new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
}
boolean first = true;
for (String chain : toshow)
{
+ int modelNumber = getModelNoForChain(chain);
+ String showChainCmd = modelNumber == -1 ? "" : modelNumber + ":."
+ + chain.split(":")[1];
if (!first)
{
cmd.append(",");
}
- cmd.append(":.").append(chain);
+ cmd.append(showChainCmd);
first = false;
}
* window, but it looks more helpful not to (easier to relate chains to the
* whole)
*/
- final String command = "~display #*; ~ribbon #*; ribbon "
+ final String command = "~display #*; ~ribbon #*; ribbon :"
+ cmd.toString();
sendChimeraCommand(command, false);
}
{
return new String[0];
}
- // if (modelFileNames == null)
- // {
- // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
- // _modelFileNameMap = new int[chimodels.size()];
- // int j = 0;
- // for (ChimeraModel chimodel : chimodels)
- // {
- // String mdlName = chimodel.getModelName();
- // }
- // modelFileNames = new String[j];
- // // System.arraycopy(mset, 0, modelFileNames, 0, j);
- // }
return chimeraMaps.keySet().toArray(
modelFileNames = new String[chimeraMaps.size()]);
*
* @return
*/
- public List<String> getChainNames()
- {
- List<String> names = new ArrayList<String>();
- String[][] allNames = getChains();
- if (allNames != null)
- {
- for (String[] chainsForPdb : allNames)
- {
- if (chainsForPdb != null)
- {
- for (String chain : chainsForPdb)
- {
- if (chain != null && !names.contains(chain))
- {
- names.add(chain);
- }
- }
- }
- }
- }
- return names;
- }
/**
* Send a 'focus' command to Chimera to recentre the visible display
sm.highlightStructure(this, seq, positions);
}
}
+
+
+ @Override
+ public List<String> getChainNames()
+ {
+ return chainNames;
+ }
+
+ public Hashtable<String, String> getChainFile()
+ {
+ return chainFile;
+ }
+
+ public List<ChimeraModel> getChimeraModelByChain(String chain)
+ {
+ return chimeraMaps.get(chainFile.get(chain));
+ }
+
+ public int getModelNoForChain(String chain)
+ {
+ List<ChimeraModel> foundModels = getChimeraModelByChain(chain);
+ if (foundModels != null && !foundModels.isEmpty())
+ {
+ return foundModels.get(0).getModelNumber();
+ }
+ return -1;
+ }
}
@Override
protected void htmlMenuItem_actionPerformed(ActionEvent e)
{
- new HtmlSvgOutput(null, alignPanel);
+ HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
+ htmlSVG.exportHTML(null);
}
@Override
public void bioJSMenuItem_actionPerformed(ActionEvent e)
{
- BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
- bjs.exportJalviewAlignmentAsBioJsHtmlFile(null);
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
+ bjs.exportHTML(null);
}
public void createImageMap(File file, String image)
if (av.getWrapAlignment())
{
- return printWrappedAlignment(pg, pwidth, pheight, pi);
+ return printWrappedAlignment(pwidth, pheight, pi, pg);
}
else
{
- return printUnwrapped(pg, pwidth, pheight, pi);
+ return printUnwrapped(pwidth, pheight, pi, pg);
}
}
* @throws PrinterException
* DOCUMENT ME!
*/
- public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
+ public int printUnwrapped(int pwidth, int pheight, int pi,
+ Graphics... pg)
throws PrinterException
{
+ boolean isMultiGraphics = pg.length > 1;
+ int G0 = 0; // Graphic index of idPanel graphics in multi-graphics mode or
+ // entire graphics for non mulit-graphics mode
+ int G1 = 0; // Graphic index of alignmentPanel graphics for multi-graphics
+ // mode
+ if (isMultiGraphics)
+ {
+ G0 = 0;
+ G1 = 1;
+ }
+
int idWidth = getVisibleIdWidth(false);
FontMetrics fm = getFontMetrics(av.getFont());
int scaleHeight = av.getCharHeight() + fm.getDescent();
- pg.setColor(Color.white);
- pg.fillRect(0, 0, pwidth, pheight);
- pg.setFont(av.getFont());
+ pg[G0].setColor(Color.white);
+ pg[G0].fillRect(0, 0, pwidth, pheight);
+ pg[G0].setFont(av.getFont());
// //////////////////////////////////
// / How many sequences and residues can we fit on a printable page?
}
// draw Scale
- pg.translate(idWidth, 0);
- getScalePanel().drawScale(pg, startRes, endRes, pwidth - idWidth,
- scaleHeight);
- pg.translate(-idWidth, scaleHeight);
+ if (isMultiGraphics)
+ {
+ pg[G1].translate(0, 0);
+ getScalePanel().drawScale(pg[G1], startRes, endRes,
+ pwidth - idWidth, scaleHeight);
+ pg[G1].translate(-idWidth, scaleHeight);
+ }
+ else
+ {
+ pg[G0].translate(idWidth, 0);
+ getScalePanel().drawScale(pg[G0], startRes, endRes, pwidth - idWidth,
+ scaleHeight);
+ pg[G0].translate(-idWidth, scaleHeight);
+ }
// //////////////
// Draw the ids
Color currentColor = null;
Color currentTextColor = null;
- pg.setFont(getIdPanel().getIdCanvas().getIdfont());
+ if (isMultiGraphics)
+ {
+ pg[G0].translate(0, scaleHeight);
+ }
+ pg[G0].setFont(getIdPanel().getIdCanvas().getIdfont());
SequenceI seq;
for (int i = startSeq; i < endSeq; i++)
currentTextColor = Color.black;
}
- pg.setColor(currentColor);
- pg.fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth,
+ pg[G0].setColor(currentColor);
+ pg[G0].fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth,
av.getCharHeight());
- pg.setColor(currentTextColor);
+ pg[G0].setColor(currentTextColor);
int xPos = 0;
if (av.isRightAlignIds())
{
- fm = pg.getFontMetrics();
+ fm = pg[G0].getFontMetrics();
xPos = idWidth
- fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
- 4;
}
- pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
+ pg[G0].drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
(((i - startSeq) * av.getCharHeight()) + av.getCharHeight())
- (av.getCharHeight() / 5));
}
- pg.setFont(av.getFont());
+ pg[G0].setFont(av.getFont());
+
// draw main sequence panel
- pg.translate(idWidth, 0);
- getSeqPanel().seqCanvas.drawPanel(pg, startRes, endRes, startSeq,
- endSeq, 0);
+ pg[G0].translate(idWidth, 0);
+ if (isMultiGraphics)
+ {
+ pg[G1].translate(idWidth, 0);
+ getSeqPanel().seqCanvas.drawPanel(pg[G1], startRes, endRes,
+ startSeq, endSeq, 0);
+ }
+ else
+ {
+ getSeqPanel().seqCanvas.drawPanel(pg[G0], startRes, endRes, startSeq,
+ endSeq, 0);
+ }
if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight()))
{
- // draw annotation - need to offset for current scroll position
+ // draw annotation label - need to offset for current scroll position
int offset = -getAlabels().getScrollOffset();
- pg.translate(0, offset);
- pg.translate(-idWidth - 3, (endSeq - startSeq) * av.getCharHeight()
- + 3);
- getAlabels().drawComponent(pg, idWidth);
- pg.translate(idWidth + 3, 0);
- getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av,
- pg, -1, startRes, endRes + 1);
- pg.translate(0, -offset);
+ pg[G0].translate(0, offset);
+ pg[G0].translate(-idWidth - 3,
+ (endSeq - startSeq) * av.getCharHeight() + 3);
+ getAlabels().drawComponent(pg[G0], idWidth);
+ pg[G0].translate(idWidth + 3, 0);
+ pg[G0].translate(0, -offset);
+ if (isMultiGraphics)
+ {
+ // draw annotation - need to offset for current scroll position
+ pg[G1].translate(0, offset);
+ pg[G1].translate(-idWidth - 3,
+ (endSeq - startSeq) * av.getCharHeight() + 3);
+ pg[G1].translate(idWidth + 3, 0);
+ getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(),
+ av, pg[G1], -1, startRes, endRes + 1);
+ pg[G1].translate(0, -offset);
+ }
+ else
+ {
+ getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(),
+ av, pg[G0], -1, startRes, endRes + 1);
+ pg[G0].translate(0, -offset);
+ }
}
return Printable.PAGE_EXISTS;
* @throws PrinterException
* DOCUMENT ME!
*/
- public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
- int pi) throws PrinterException
+ public int printWrappedAlignment(int pwidth, int pheight, int pi,
+ Graphics pg) throws PrinterException
{
int annotationHeight = 0;
AnnotationLabels labels = null;
{
if (im.getGraphics() != null)
{
- printWrappedAlignment(im.getGraphics(), aDimension.getWidth(),
- aDimension.getHeight() + boarderBottomOffset, 0);
+ printWrappedAlignment(aDimension.getWidth(),
+ aDimension.getHeight() + boarderBottomOffset, 0,
+ im.getGraphics());
im.writeImage();
}
}
{
if (im.getGraphics() != null)
{
- printUnwrapped(im.getGraphics(), aDimension.getWidth(),
- aDimension.getHeight(), 0);
+ printUnwrapped(aDimension.getWidth(), aDimension.getHeight(),
+ 0, im.getGraphics());
im.writeImage();
}
}
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
-import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
// / TODO: check if protocol is needed to be set, and if chains are
// autodiscovered.
jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
- pdbentrys, seqs, null, null);
+ pdbentrys, seqs, null);
jmb.setLoadingFromArchive(true);
addAlignmentPanel(ap);
{
progressBar = ap.alignFrame;
jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(),
- pdbentrys, seqs, null, null);
+ pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
if (pdbentrys.length > 1)
jmb.setFinishedInit(true);
}
- void setChainMenuItems(Vector<String> chains)
- {
- chainMenu.removeAll();
- if (chains == null)
- {
- return;
- }
- JMenuItem menuItem = new JMenuItem(
- MessageManager.getString("label.all"));
- menuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- allChainsSelected = true;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
- }
- }
- centerViewer();
- allChainsSelected = false;
- }
- });
-
- chainMenu.add(menuItem);
-
- for (String chain : chains)
- {
- menuItem = new JCheckBoxMenuItem(chain, true);
- menuItem.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent evt)
- {
- if (!allChainsSelected)
- {
- centerViewer();
- }
- }
- });
- chainMenu.add(menuItem);
- }
- }
boolean allChainsSelected = false;
- void centerViewer()
+ @Override
+ void showSelectedChains()
{
Vector<String> toshow = new Vector<String>();
for (int i = 0; i < chainMenu.getItemCount(); i++)
repaint();
return;
}
- setChainMenuItems(jmb.chainNames);
+ setChainMenuItems(jmb.getChainNames());
this.setTitle(jmb.getViewerTitle());
if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
private FeatureRenderer fr = null;
public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
- PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
- String protocol)
+ PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String protocol)
{
- super(sSm, pdbentry, sequenceIs, chains, protocol);
+ super(sSm, pdbentry, sequenceIs, protocol);
appJmolWindow = appJmol;
}
// appJmolWindow.repaint();
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
+ @Override
public void run()
{
appJmolWindow.updateTitleAndMenus();
});
}
+ @Override
public void updateColours(Object source)
{
AlignmentPanel ap = (AlignmentPanel) source;
// msWalltime);
}
+ @Override
public void showUrl(String url)
{
showUrl(url, "jmol");
import jalview.io.AppletFormatAdapter;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
+import jalview.io.StructureFile;
import jalview.schemes.BuriedColourScheme;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.HelixColourScheme;
import jalview.ws.dbsources.Pdb;
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import javax.swing.JColorChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
-import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
{
createProgressBar();
// FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
- String[][] chains = extractChains(seqs);
jmb = new JalviewChimeraBindingModel(this,
- ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
- null);
+ ap.getStructureSelectionManager(), pdbentrys, seqs, null);
addAlignmentPanel(ap);
useAlignmentPanelForColourbyseq(ap);
if (pdbentrys.length > 1)
}
- /**
- * Retrieve chains for sequences by inspecting their PDB refs. The hope is
- * that the first will be to the sequence's own chain. Really need a more
- * managed way of doing this.
- *
- * @param seqs
- * @return
- */
- protected String[][] extractChains(SequenceI[][] seqs)
- {
- String[][] chains = new String[seqs.length][];
- for (int i = 0; i < seqs.length; i++)
- {
- chains[i] = new String[seqs[i].length];
- int seqno = 0;
- for (SequenceI seq : seqs[i])
- {
- String chain = null;
- if (seq.getDatasetSequence() != null)
- {
- Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
- .getAllPDBEntries();
- if (pdbrefs != null && pdbrefs.size() > 0)
- {
- // FIXME: SequenceI.PDBEntry[0] chain mapping used for
- // ChimeraViewFrame. Is this even used ???
- chain = pdbrefs.get(0).getChainCode();
- }
- }
- chains[i][seqno++] = chain;
- }
- }
- return chains;
- }
/**
* Create a new viewer from saved session state data including Chimera session
jmb.startChimeraListener();
}
- /**
- * If the list is not empty, add menu items for 'All' and each individual
- * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
- *
- * @param chainNames
- */
- void setChainMenuItems(List<String> chainNames)
- {
- chainMenu.removeAll();
- if (chainNames == null || chainNames.isEmpty())
- {
- return;
- }
- JMenuItem menuItem = new JMenuItem(
- MessageManager.getString("label.all"));
- menuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent evt)
- {
- allChainsSelected = true;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
- }
- }
- showSelectedChains();
- allChainsSelected = false;
- }
- });
-
- chainMenu.add(menuItem);
-
- for (String chainName : chainNames)
- {
- menuItem = new JCheckBoxMenuItem(chainName, true);
- menuItem.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent evt)
- {
- if (!allChainsSelected)
- {
- showSelectedChains();
- }
- }
- });
-
- chainMenu.add(menuItem);
- }
- }
/**
* Show only the selected chain(s) in the viewer
*/
+ @Override
void showSelectedChains()
{
List<String> toshow = new ArrayList<String>();
List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
List<Integer> filePDBpos = new ArrayList<Integer>();
PDBEntry thePdbEntry = null;
+ StructureFile pdb = null;
try
{
String[] curfiles = jmb.getPdbFile(); // files currently in viewer
stopProgressBar("", startTime);
}
// Explicitly map to the filename used by Chimera ;
- jmb.getSsm().setMapping(jmb.getSequence()[pos],
+ pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
jmb.getChains()[pos], pe.getFile(), protocol);
+ stashFoundChains(pdb, pe.getFile());
} catch (OutOfMemoryError oomerror)
{
new OOMWarning(
}
}
}
+ jmb.refreshGUI();
jmb.setFinishedInit(true);
jmb.setLoadingFromArchive(false);
* @return
* @throws Exception
*/
+
+ private void stashFoundChains(StructureFile pdb, String file)
+ {
+ for (int i = 0; i < pdb.getChains().size(); i++)
+ {
+ String chid = new String(pdb.getId() + ":"
+ + pdb.getChains().elementAt(i).id);
+ jmb.getChainNames().add(chid);
+ jmb.getChainFile().put(chid, file);
+ }
+ }
private String fetchPdbFile(PDBEntry processingEntry) throws Exception
{
// FIXME: this is duplicated code with Jmol frame ?
// only need to check links if there is one with a
// SEQUENCE_ID which is not the default EMBL_EBI link
ListIterator<String> li = links.listIterator();
- Boolean check = false;
- while (li.hasNext() && !check)
+ boolean check = false;
+ List<JLabel> urls = new ArrayList<JLabel>();
+ while (li.hasNext())
{
String link = li.next();
- check = (link.contains(SEQUENCE_ID) && !link
- .equals(EMBLEBI_STRING));
+ if (link.contains(SEQUENCE_ID) && !link.equals(EMBLEBI_STRING))
+ {
+ check = true;
+ int barPos = link.indexOf("|");
+ String urlMsg = barPos == -1 ? link : link.substring(0,
+ barPos) + ": " + link.substring(barPos + 1);
+ urls.add(new JLabel(urlMsg));
+ }
}
if (!check)
{
MessageManager
.getString("label.SEQUENCE_ID_for_DB_ACCESSION2"));
msgPanel.add(msg);
+ for (JLabel url : urls)
+ {
+ msgPanel.add(url);
+ }
msgPanel.add(msg2);
final JCheckBox jcb = new JCheckBox(
@Override
public void actionPerformed(ActionEvent e)
{
- // update Cache settings if checkbox is selected
- if (jcb.isSelected())
- {
- Cache.setProperty("CHECKURLLINKS", "false");
- }
- else
- {
- Cache.setProperty("CHECKURLLINKS", "true");
- }
+ // update Cache settings for "don't show this again"
+ boolean showWarningAgain = !jcb.isSelected();
+ Cache.setProperty("CHECKURLLINKS",
+ Boolean.valueOf(showWarningAgain).toString());
}
});
msgPanel.add(jcb);
private FeatureRenderer fr = null;
+
public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame,
StructureSelectionManager ssm, PDBEntry[] pdbentry,
- SequenceI[][] sequenceIs, String[][] chains, String protocol)
+ SequenceI[][] sequenceIs, String protocol)
{
- super(ssm, pdbentry, sequenceIs, chains, protocol);
+ super(ssm, pdbentry, sequenceIs, protocol);
cvf = chimeraViewFrame;
}
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
+ @Override
public void run()
{
cvf.updateTitleAndMenus();
});
}
+ @Override
public void updateColours(Object source)
{
AlignmentPanel ap = (AlignmentPanel) source;
* Send an asynchronous command to Chimera, in a new thread, optionally with
* an 'in progress' message in a progress bar somewhere
*/
+ @Override
protected void sendAsynchronousCommand(final String command,
final String progressMsg)
{
thread.start();
}
+
+
}
import jalview.util.MessageManager;
import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
protected Thread worker = null;
+ protected boolean allChainsSelected = false;
+
/**
*
* @param ap2
this.ap = alp;
}
+ @Override
public AlignmentPanel[] getAllAlignmentPanels()
{
AlignmentPanel[] t, list = new AlignmentPanel[0];
// queue.
new Thread(new Runnable()
{
+ @Override
public void run()
{
while (worker != null && worker.isAlive() && _started)
}
return finished;
}
+
+ void setChainMenuItems(List<String> chainNames)
+ {
+ chainMenu.removeAll();
+ if (chainNames == null || chainNames.isEmpty())
+ {
+ return;
+ }
+ JMenuItem menuItem = new JMenuItem(
+ MessageManager.getString("label.all"));
+ menuItem.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent evt)
+ {
+ allChainsSelected = true;
+ for (int i = 0; i < chainMenu.getItemCount(); i++)
+ {
+ if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+ {
+ ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
+ }
+ }
+ showSelectedChains();
+ allChainsSelected = false;
+ }
+ });
+
+ chainMenu.add(menuItem);
+
+ for (String chain : chainNames)
+ {
+ menuItem = new JCheckBoxMenuItem(chain, true);
+ menuItem.addItemListener(new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if (!allChainsSelected)
+ {
+ showSelectedChains();
+ }
+ }
+ });
+
+ chainMenu.add(menuItem);
+ }
+ }
+
+ abstract void showSelectedChains();
+
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
-import jalview.api.AlignmentViewPanel;
-import jalview.datamodel.AlignmentExportData;
import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.IProgressIndicator;
+import jalview.gui.AlignmentPanel;
import jalview.gui.OOMWarning;
import jalview.json.binding.biojs.BioJSReleasePojo;
import jalview.json.binding.biojs.BioJSRepositoryPojo;
import java.util.Objects;
import java.util.TreeMap;
-public class BioJsHTMLOutput
+public class BioJsHTMLOutput extends HTMLOutput
{
- private AlignmentViewPanel ap;
-
- private long pSessionId;
-
- private IProgressIndicator pIndicator;
-
- private boolean headless;
private static File currentBJSTemplateFile;
"biojs_template_git_repo",
"https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
- public BioJsHTMLOutput(AlignmentViewPanel ap,
- IProgressIndicator pIndicator)
+ public BioJsHTMLOutput(AlignmentPanel ap)
{
- if (ap != null)
- {
- this.ap = ap;
- this.pSessionId = System.currentTimeMillis();
- this.pIndicator = pIndicator;
- this.headless = (System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true"));
- }
+ super(ap);
}
- public void exportJalviewAlignmentAsBioJsHtmlFile(String outputFile)
+ @Override
+ public void exportHTML(String outputFile)
{
- // String outputFile = null;
+ exportStarted();
try
{
+
if (outputFile == null)
{
outputFile = getOutputFile();
}
- AlignExportSettingI exportSettings = new AlignExportSettingI()
- {
- @Override
- public boolean isExportHiddenSequences()
- {
- return true;
- }
+ generatedFile = new File(outputFile);
- @Override
- public boolean isExportHiddenColumns()
- {
- return true;
- }
-
- @Override
- public boolean isExportAnnotations()
- {
- return true;
- }
-
- @Override
- public boolean isExportFeatures()
- {
- return true;
- }
-
- @Override
- public boolean isExportGroups()
- {
- return true;
- }
-
- @Override
- public boolean isCancelled()
- {
- return false;
- }
-
- };
- AlignmentExportData exportData = jalview.gui.AlignFrame
- .getAlignmentForExport(JSONFile.FILE_DESC,
- ap.getAlignViewport(), exportSettings);
- String bioJSON = new FormatAdapter(ap, exportData.getSettings())
- .formatSequences(JSONFile.FILE_DESC, exportData
- .getAlignment(), exportData.getOmitHidden(),
- exportData.getStartEndPostions(), ap
- .getAlignViewport().getColumnSelection());
-
- String bioJSTemplateString = getBioJsTemplateAsString();
+ String bioJSON = getBioJSONData();
+ String bioJSTemplateString = HTMLOutput.readFileAsString(getCurrentBJSTemplateFile());
String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
.replaceAll("#sequenceData#", bioJSON).toString();
PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
- outputFile));
+ generatedFile));
out.print(generatedBioJsWithJalviewAlignmentAsJson);
out.flush();
out.close();
- jalview.util.BrowserLauncher.openURL("file:///" + outputFile);
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.export_complete", "BioJS"), pSessionId);
- }
+ exportCompleted();
+ setProgressMessage(MessageManager.formatMessage(
+ "status.export_complete", "BioJS"));
+
} catch (NoFileSelectedException ex)
{
// do noting if no file was selected
new OOMWarning("Creating Image for " + outputFile, err);
} catch (Exception e)
{
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
- }
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
e.printStackTrace();
}
}
- public String getOutputFile() throws NoFileSelectedException
- {
- String selectedFile = null;
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.waiting_for_user_to_select_output_file", "HTML"),
- pSessionId);
- }
-
- JalviewFileChooser jvFileChooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "html" }, new String[] { "HTML files" },
- "HTML files");
- jvFileChooser.setFileView(new JalviewFileView());
- jvFileChooser.setDialogTitle(MessageManager
- .getString("label.save_as_biojs_html"));
- jvFileChooser.setToolTipText(MessageManager.getString("action.save"));
- int fileChooserOpt = jvFileChooser.showSaveDialog(null);
- if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
- {
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
- .getSelectedFile().getParent());
- selectedFile = jvFileChooser.getSelectedFile().getPath();
- }
- else
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", "BioJS"),
- pSessionId);
- throw new NoFileSelectedException("No file was selected.");
- }
- return selectedFile;
- }
-
- public static String getBioJsTemplateAsString() throws IOException
- {
- InputStreamReader isReader = null;
- BufferedReader buffReader = null;
- StringBuilder sb = new StringBuilder();
- Objects.requireNonNull(getCurrentBJSTemplateFile(),
- "BioJsTemplate File not initialized!");
- @SuppressWarnings("deprecation")
- URL url = getCurrentBJSTemplateFile().toURL();
- if (url != null)
- {
- try
- {
- isReader = new InputStreamReader(url.openStream());
- buffReader = new BufferedReader(isReader);
- String line;
- String lineSeparator = System.getProperty("line.separator");
- while ((line = buffReader.readLine()) != null)
- {
- sb.append(line).append(lineSeparator);
- }
-
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (isReader != null)
- {
- isReader.close();
- }
-
- if (buffReader != null)
- {
- buffReader.close();
- }
- }
- }
- return sb.toString();
- }
-
- public static void refreshBioJSVersionsInfo(String dirName)
+ public static void refreshVersionInfo(String dirName)
throws URISyntaxException
{
File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY);
BioJSRepositoryPojo release = new BioJSRepositoryPojo(
gitRepoPkgJson);
syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
- refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
+ refreshVersionInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
}
} catch (URISyntaxException e)
{
BioJsHTMLOutput.bioJsMSAVersions = bioJsMSAVersions;
}
+ @Override
+ public boolean isEmbedData()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isLaunchInBrowserAfterExport()
+ {
+ return true;
+ }
+
+ @Override
+ public File getExportedFile()
+ {
+ return generatedFile;
+ }
+
}
*/
package jalview.io;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignViewport;
+import jalview.api.AlignExportSettingI;
+import jalview.datamodel.AlignmentExportData;
+import jalview.exceptions.NoFileSelectedException;
import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
-import jalview.gui.SequenceRenderer;
+import jalview.gui.IProgressIndicator;
import jalview.util.MessageManager;
-import java.awt.Color;
-import java.awt.Font;
-import java.io.PrintWriter;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Objects;
-public class HTMLOutput
+
+public abstract class HTMLOutput
{
- AlignViewport av;
+ protected AlignmentPanel ap;
- SequenceRenderer sr;
+ protected long pSessionId;
- jalview.renderer.seqfeatures.FeatureRenderer fr;
+ protected IProgressIndicator pIndicator;
- Color color;
+ protected File generatedFile;
- public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
- FeatureRenderer fr1)
+ public HTMLOutput(AlignmentPanel ap)
{
- this.av = ap.av;
- this.sr = sr;
-
- fr = new FeatureRenderer(ap);
- fr.transferSettings(fr1);
-
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "html" }, new String[] { "HTML files" },
- "HTML files");
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_as_html"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(null);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ if (ap != null)
{
- String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
- .getSelectedFile().getParent());
-
- try
- {
- PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
- choice));
- out.println("<HTML>");
- out.println("<style type=\"text/css\">");
- out.println("<!--");
- out.print("td {font-family: \"" + av.getFont().getFamily()
- + "\", \"" + av.getFont().getName() + "\", mono; "
- + "font-size: " + av.getFont().getSize() + "px; ");
-
- if (av.getFont().getStyle() == Font.BOLD)
- {
- out.print("font-weight: BOLD; ");
- }
-
- if (av.getFont().getStyle() == Font.ITALIC)
- {
- out.print("font-style: italic; ");
- }
-
- out.println("text-align: center; }");
-
- out.println("-->");
- out.println("</style>");
- out.println("<BODY>");
-
- if (av.getWrapAlignment())
- {
- drawWrappedAlignment(out);
- }
- else
- {
- drawUnwrappedAlignment(out);
- }
-
- out.println("\n</body>\n</html>");
- out.close();
- jalview.util.BrowserLauncher.openURL("file:///" + choice);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
+ this.ap = ap;
+ this.pIndicator = ap.alignFrame;
}
}
- void drawUnwrappedAlignment(PrintWriter out)
- {
- out.println("<table border=\"1\"><tr><td>\n");
- out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
-
- // ////////////
- SequenceI seq;
- AlignmentI alignment = av.getAlignment();
-
- // draws the top row, the measure rule
- out.println("<tr><td colspan=\"6\"></td>");
- int i = 0;
-
- for (i = 10; i < (alignment.getWidth() - 10); i += 10)
+ public String getBioJSONData()
+ {
+ if (!isEmbedData())
{
- out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
+ return null;
}
-
- out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
- + "<br>|</td>");
- out.println("</tr>");
-
- for (i = 0; i < alignment.getHeight(); i++)
+ AlignExportSettingI exportSettings = new AlignExportSettingI()
{
- seq = alignment.getSequenceAt(i);
-
- String id = seq.getDisplayId(av.getShowJVSuffix());
-
- out.println("<tr><td nowrap>" + id + " </td>");
-
- for (int res = 0; res < seq.getLength(); res++)
+ @Override
+ public boolean isExportHiddenSequences()
{
- if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
- {
- color = sr.getResidueBoxColour(seq, res);
-
- color = fr.findFeatureColour(color, seq, res);
- }
- else
- {
- color = Color.white;
- }
-
- if (color.getRGB() < -1)
- {
- out.println("<td bgcolor=\"#"
- + jalview.util.Format.getHexString(color) + "\">"
- + seq.getCharAt(res) + "</td>");
- }
- else
- {
- out.println("<td>" + seq.getCharAt(res) + "</td>");
- }
+ return true;
}
- out.println("</tr>");
- }
-
- // ////////////
- out.println("</table>");
- out.println("</td></tr></table>");
- }
-
- void drawWrappedAlignment(PrintWriter out)
- {
- // //////////////////////////////////
- // / How many sequences and residues can we fit on a printable page?
- AlignmentI al = av.getAlignment();
- SequenceI seq;
- String r;
- String g;
- String b;
-
- out.println("<table border=\"1\"><tr><td>\n");
- out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
-
- for (int startRes = 0; startRes < al.getWidth(); startRes += av
- .getWrappedWidth())
- {
- int endRes = startRes + av.getWrappedWidth();
-
- if (endRes > al.getWidth())
+ @Override
+ public boolean isExportHiddenColumns()
{
- endRes = al.getWidth();
+ return true;
}
- if (av.getScaleAboveWrapped())
+ @Override
+ public boolean isExportAnnotations()
{
- out.println("<tr>");
-
- if (av.getScaleLeftWrapped())
- {
- out.println("<td colspan=\"7\"> </td>");
- }
- else
- {
- out.println("<td colspan=\"6\"> </td>");
- }
-
- for (int i = startRes + 10; i < endRes; i += 10)
- {
- out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
- }
-
- out.println("</tr>");
+ return true;
}
- int startPos, endPos;
- for (int s = 0; s < al.getHeight(); s++)
+ @Override
+ public boolean isExportFeatures()
{
- out.println("<tr>");
- seq = al.getSequenceAt(s);
-
- startPos = seq.findPosition(startRes);
- endPos = seq.findPosition(endRes) - 1;
+ return true;
+ }
- String id = seq.getDisplayId(av.getShowJVSuffix());
+ @Override
+ public boolean isExportGroups()
+ {
+ return true;
+ }
- out.println("<td nowrap>" + id + " </td>");
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
- if (av.getScaleLeftWrapped())
- {
- if (startPos > seq.getEnd() || endPos == 0)
- {
- out.println("<td nowrap> </td>");
- }
- else
- {
- out.println("<td nowrap>" + startPos + " </td>");
- }
- }
+ };
+ AlignmentExportData exportData = jalview.gui.AlignFrame
+ .getAlignmentForExport(JSONFile.FILE_DESC,
+ ap.getAlignViewport(), exportSettings);
+ String bioJSON = new FormatAdapter(ap, exportData.getSettings())
+ .formatSequences(JSONFile.FILE_DESC, exportData.getAlignment(),
+ exportData.getOmitHidden(), exportData
+ .getStartEndPostions(), ap.getAlignViewport()
+ .getColumnSelection());
+ return bioJSON;
+ }
- for (int res = startRes; res < endRes; res++)
+ /**
+ * Read a template file content as string
+ *
+ * @param file
+ * - the file to be read
+ * @return File content as String
+ * @throws IOException
+ */
+ public static String readFileAsString(File file) throws IOException
+ {
+ InputStreamReader isReader = null;
+ BufferedReader buffReader = null;
+ StringBuilder sb = new StringBuilder();
+ Objects.requireNonNull(file, "File must not be null!");
+ @SuppressWarnings("deprecation")
+ URL url = file.toURL();
+ if (url != null)
+ {
+ try
+ {
+ isReader = new InputStreamReader(url.openStream());
+ buffReader = new BufferedReader(isReader);
+ String line;
+ String lineSeparator = System.getProperty("line.separator");
+ while ((line = buffReader.readLine()) != null)
{
- if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
- {
- color = sr.getResidueBoxColour(seq, res);
-
- color = fr.findFeatureColour(color, seq, res);
- }
- else
- {
- color = Color.white;
- }
-
- if (color.getRGB() < -1)
- {
- out.println("<td bgcolor=\"#"
- + jalview.util.Format.getHexString(color) + "\">"
- + seq.getCharAt(res) + "</td>");
- }
- else
- {
- out.println("<td>" + seq.getCharAt(res) + "</td>");
- }
-
+ sb.append(line).append(lineSeparator);
}
-
- if (av.getScaleRightWrapped()
- && endRes < startRes + av.getWrappedWidth())
+
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } finally
+ {
+ if (isReader != null)
{
- out.println("<td colspan=\""
- + (startRes + av.getWrappedWidth() - endRes) + "\">"
- + " </td>");
+ isReader.close();
}
-
- if (av.getScaleRightWrapped() && startPos < endPos)
+
+ if (buffReader != null)
{
- out.println("<td nowrap> " + endPos + " </td>");
+ buffReader.close();
}
-
- out.println("</tr>");
- }
-
- if (endRes < al.getWidth())
- {
- out.println("<tr><td height=\"5\"></td></tr>");
}
}
-
- out.println("</table>");
- out.println("</table>");
+ return sb.toString();
}
public static String getImageMapHTML()
+ "initToolTips(); //--></script>\n");
}
+
+ public String getOutputFile() throws NoFileSelectedException
+ {
+ String selectedFile = null;
+ if (pIndicator != null && !isHeadless())
+ {
+ pIndicator.setProgressBar(MessageManager.formatMessage(
+ "status.waiting_for_user_to_select_output_file", "HTML"),
+ pSessionId);
+ }
+
+ JalviewFileChooser jvFileChooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
+ new String[] { "html" }, new String[] { "HTML files" },
+ "HTML files");
+ jvFileChooser.setFileView(new JalviewFileView());
+
+ jvFileChooser.setDialogTitle(MessageManager
+ .getString("label.save_as_biojs_html"));
+ jvFileChooser.setToolTipText(MessageManager.getString("action.save"));
+
+ int fileChooserOpt = jvFileChooser.showSaveDialog(null);
+ if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
+ {
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
+ .getSelectedFile().getParent());
+ selectedFile = jvFileChooser.getSelectedFile().getPath();
+ }
+ else
+ {
+ pIndicator.setProgressBar(MessageManager.formatMessage(
+ "status.cancelled_image_export_operation", "BioJS"),
+ pSessionId);
+ throw new NoFileSelectedException("No file was selected.");
+ }
+ return selectedFile;
+ }
+
+ protected void setProgressMessage(String message)
+ {
+ if (pIndicator != null && !isHeadless())
+ {
+ pIndicator.setProgressBar(message, pSessionId);
+ }
+ else
+ {
+ System.out.println(message);
+ }
+ }
+
+ /**
+ * Answers true if HTML export is invoke in headless mode or false otherwise
+ *
+ * @return
+ */
+ protected boolean isHeadless()
+ {
+ return System.getProperty("java.awt.headless") != null
+ && System.getProperty("java.awt.headless").equals("true");
+ }
+
+ /**
+ * This method provides implementation of consistent behaviour which should
+ * occur before a HTML file export. It MUST be called at the start of the
+ * exportHTML() method implementation.
+ */
+ protected void exportStarted()
+ {
+ pSessionId = System.currentTimeMillis();
+ }
+
+ /**
+ * This method provides implementation of consistent behaviour which should
+ * occur after a HTML file export. It MUST be called at the end of the
+ * exportHTML() method implementation.
+ */
+ protected void exportCompleted()
+ {
+ if (isLaunchInBrowserAfterExport() && !isHeadless())
+ {
+ try
+ {
+ jalview.util.BrowserLauncher
+ .openURL("file:///" + getExportedFile());
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * if this answers true then BioJSON data will be embedded to the exported
+ * HTML file otherwise it won't be embedded.
+ *
+ * @return
+ */
+ public abstract boolean isEmbedData();
+
+ /**
+ * if this answers true then the generated HTML file is opened for viewing in
+ * a browser after its generation otherwise it won't be opened in a browser
+ *
+ * @return
+ */
+ public abstract boolean isLaunchInBrowserAfterExport();
+
+ /**
+ * handle to the generated HTML file
+ *
+ * @return
+ */
+ public abstract File getExportedFile();
+
+ /**
+ * This is the main method to handle the HTML generation.
+ *
+ * @param outputFile
+ * the file path of the generated HTML
+ */
+ public abstract void exportHTML(String outputFile);
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
-import jalview.api.FeatureRenderer;
-import jalview.datamodel.AlignmentExportData;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignViewport;
import jalview.gui.AlignmentPanel;
import jalview.gui.HTMLOptions;
-import jalview.gui.IProgressIndicator;
import jalview.gui.OOMWarning;
import jalview.math.AlignmentDimension;
import jalview.util.MessageManager;
-import java.awt.Color;
-import java.awt.FontMetrics;
import java.awt.Graphics;
-import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import org.jfree.graphics2d.svg.SVGGraphics2D;
import org.jfree.graphics2d.svg.SVGHints;
-public class HtmlSvgOutput
+public class HtmlSvgOutput extends HTMLOutput
{
- AlignViewport av;
- FeatureRenderer fr;
+ private File generatedFile;
- AlignmentPanel ap;
-
- private IProgressIndicator pIndicator;
-
- private long pSessionId;
-
- private boolean headless;
-
- public HtmlSvgOutput(File file, AlignmentPanel ap)
+ public HtmlSvgOutput(AlignmentPanel ap)
{
- this.av = ap.av;
- this.ap = ap;
- fr = ap.cloneFeatureRenderer();
- generateHtmlSvgOutput(file);
+ super(ap);
}
- public void generateHtmlSvgOutput(File file)
+ @Override
+ public void exportHTML(String file)
{
- pIndicator = ap.alignFrame;
- pSessionId = System.currentTimeMillis();
+ exportStarted();
try
{
- headless = (System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true"));
if (file == null)
{
- setProgressMessage(MessageManager.formatMessage(
- "status.waiting_for_user_to_select_output_file", "HTML"));
- JalviewFileChooser chooser = getHTMLChooser();
- chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle(ap.alignFrame.getTitle());
- chooser.setToolTipText(MessageManager.getString("action.save"));
- int value = chooser.showSaveDialog(ap.alignFrame);
-
- if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
- {
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
- .getSelectedFile().getParent());
- file = chooser.getSelectedFile();
- ap.alignFrame.repaint();
- }
- else
- {
- setProgressMessage(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", "HTML"));
- return;
- }
+ file = getOutputFile();
}
+ generatedFile = new File(file);
} catch (Exception e)
{
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
e.printStackTrace();
return;
}
- final File fileX = file;
new Thread()
{
@Override
setProgressMessage(MessageManager.formatMessage(
"status.exporting_alignment_as_x_file", "HTML"));
AlignmentDimension aDimension = ap.getAlignmentDimension();
- SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(),
+ SVGGraphics2D idPanelGraphics = new SVGGraphics2D(
+ aDimension.getWidth(),
aDimension.getHeight());
- SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(),
+ SVGGraphics2D alignPanelGraphics = new SVGGraphics2D(
+ aDimension.getWidth(),
aDimension.getHeight());
String renderStyle = jalview.bin.Cache.getDefault(
// If we need to prompt, and if the GUI is visible then
// Prompt for rendering style
if (renderStyle.equalsIgnoreCase("Prompt each time")
- && !(System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true")))
+ && !isHeadless())
{
HTMLOptions svgOption = new HTMLOptions();
renderStyle = svgOption.getValue();
if (renderStyle.equalsIgnoreCase("Lineart"))
{
- g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
+ idPanelGraphics.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
- g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
+ alignPanelGraphics.setRenderingHint(
+ SVGHints.KEY_DRAW_STRING_TYPE,
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
}
- if (av.getWrapAlignment())
+ if (ap.av.getWrapAlignment())
{
printWrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
- g1, g2);
+ alignPanelGraphics);
}
else
{
printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
- g1, g2);
+ idPanelGraphics, alignPanelGraphics);
}
- String titleSvgData = g1.getSVGDocument();
- String alignSvgData = g2.getSVGDocument();
- String jsonData = null;
- boolean isEmbbedBioJSON = Boolean.valueOf(jalview.bin.Cache
- .getDefault("EXPORT_EMBBED_BIOJSON", "true"));
- if (isEmbbedBioJSON)
- {
- AlignExportSettingI exportSettings = new AlignExportSettingI()
- {
- @Override
- public boolean isExportHiddenSequences()
- {
- return true;
- }
-
- @Override
- public boolean isExportHiddenColumns()
- {
- return true;
- }
-
- @Override
- public boolean isExportAnnotations()
- {
- return true;
- }
-
- @Override
- public boolean isExportFeatures()
- {
- return true;
- }
-
- @Override
- public boolean isExportGroups()
- {
- return true;
- }
-
- @Override
- public boolean isCancelled()
- {
- return false;
- }
-
- };
- AlignmentExportData exportData = jalview.gui.AlignFrame
- .getAlignmentForExport(JSONFile.FILE_DESC, av,
- exportSettings);
- jsonData = new FormatAdapter(ap, exportData.getSettings())
- .formatSequences(JSONFile.FILE_DESC,
- exportData.getAlignment(),
- exportData.getOmitHidden(),
- exportData.getStartEndPostions(),
- av.getColumnSelection());
- }
- String htmlData = getHtml(titleSvgData, alignSvgData, jsonData,
- av.getWrapAlignment());
- FileOutputStream out = new FileOutputStream(fileX);
+ String idPanelSvgData = idPanelGraphics.getSVGDocument();
+ String alignPanelSvgData = alignPanelGraphics.getSVGDocument();
+ String jsonData = getBioJSONData();
+ String htmlData = getHtml(idPanelSvgData, alignPanelSvgData, jsonData,
+ ap.av.getWrapAlignment());
+ FileOutputStream out = new FileOutputStream(generatedFile);
out.write(htmlData.getBytes());
out.flush();
out.close();
- if (!(System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true")))
- {
- jalview.util.BrowserLauncher.openURL("file:///" + fileX);
- }
+ exportCompleted();
} catch (OutOfMemoryError err)
{
System.out.println("########################\n"
- + "OUT OF MEMORY " + fileX + "\n"
+ + "OUT OF MEMORY " + generatedFile + "\n"
+ "########################");
- new OOMWarning("Creating Image for " + fileX, err);
+ new OOMWarning("Creating Image for " + generatedFile, err);
} catch (Exception e)
{
e.printStackTrace();
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
}
setProgressMessage(MessageManager.formatMessage(
"status.export_complete", "HTML"));
}
- private void setProgressMessage(String message)
- {
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(message, pSessionId);
- }
- else
- {
- System.out.println(message);
- }
- }
static JalviewFileChooser getHTMLChooser()
{
public int printUnwrapped(int pwidth, int pheight, int pi, Graphics... pg)
throws PrinterException
{
- int idWidth = ap.getVisibleIdWidth(false);
- FontMetrics fm = ap.getFontMetrics(av.getFont());
- int scaleHeight = av.getCharHeight() + fm.getDescent();
-
- pg[0].setColor(Color.white);
- pg[0].fillRect(0, 0, pwidth, pheight);
- pg[0].setFont(av.getFont());
-
- // //////////////////////////////////
- // / How many sequences and residues can we fit on a printable page?
- int totalRes = (pwidth - idWidth) / av.getCharWidth();
- int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
- int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
-
- // ///////////////////////////
- // / Only print these sequences and residues on this page
- int startRes;
-
- // ///////////////////////////
- // / Only print these sequences and residues on this page
- int endRes;
-
- // ///////////////////////////
- // / Only print these sequences and residues on this page
- int startSeq;
-
- // ///////////////////////////
- // / Only print these sequences and residues on this page
- int endSeq;
- startRes = (pi % pagesWide) * totalRes;
- endRes = (startRes + totalRes) - 1;
-
- if (endRes > (av.getAlignment().getWidth() - 1))
- {
- endRes = av.getAlignment().getWidth() - 1;
- }
- startSeq = (pi / pagesWide) * totalSeq;
- endSeq = startSeq + totalSeq;
- if (endSeq > av.getAlignment().getHeight())
- {
- endSeq = av.getAlignment().getHeight();
- }
- int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
- * pheight;
- if (av.isShowAnnotation())
- {
- pagesHigh += ap.getAnnotationPanel().adjustPanelHeight() + 3;
- }
- pagesHigh /= pheight;
- if (pi >= (pagesWide * pagesHigh))
- {
- return Printable.NO_SUCH_PAGE;
- }
-
- // draw Scale
- pg[1].translate(0, 0);
- ap.getScalePanel().drawScale(pg[1], startRes, endRes, pwidth - idWidth,
- scaleHeight);
- pg[1].translate(-idWidth, scaleHeight);
-
- // //////////////
- // Draw the ids
- Color currentColor = null;
- Color currentTextColor = null;
- pg[0].translate(0, scaleHeight);
- pg[0].setFont(ap.getIdPanel().getIdCanvas().getIdfont());
- SequenceI seq;
- for (int i = startSeq; i < endSeq; i++)
- {
- seq = av.getAlignment().getSequenceAt(i);
- if ((av.getSelectionGroup() != null)
- && av.getSelectionGroup().getSequences(null).contains(seq))
- {
- currentColor = Color.gray;
- currentTextColor = Color.black;
- }
- else
- {
- currentColor = av.getSequenceColour(seq);
- currentTextColor = Color.black;
- }
- pg[0].setColor(currentColor);
- pg[0].fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth,
- av.getCharHeight());
- pg[0].setColor(currentTextColor);
- int xPos = 0;
- if (av.isRightAlignIds())
- {
- fm = pg[0].getFontMetrics();
- xPos = idWidth
- - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
- - 4;
- }
- pg[0].drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
- (((i - startSeq) * av.getCharHeight()) + av.getCharHeight())
- - (av.getCharHeight() / 5));
- }
- pg[0].setFont(av.getFont());
- pg[0].translate(idWidth, 0);
-
- // draw main sequence panel
- pg[1].translate(idWidth, 0);
- ap.getSeqPanel().seqCanvas.drawPanel(pg[1], startRes, endRes, startSeq,
- endSeq, 0);
- if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight()))
- {
- // draw annotation label - need to offset for current scroll position
- int offset = -ap.getAlabels().getScrollOffset();
- pg[0].translate(0, offset);
- pg[0].translate(-idWidth - 3,
- (endSeq - startSeq) * av.getCharHeight() + 3);
- ap.getAlabels().drawComponent(pg[0], idWidth);
- pg[0].translate(idWidth + 3, 0);
- pg[0].translate(0, -offset);
-
- // draw annotation - need to offset for current scroll position
- pg[1].translate(0, offset);
- pg[1].translate(-idWidth - 3,
- (endSeq - startSeq) * av.getCharHeight() + 3);
- pg[1].translate(idWidth + 3, 0);
- ap.getAnnotationPanel().renderer.drawComponent(
- ap.getAnnotationPanel(), av, pg[1], -1, startRes, endRes + 1);
- pg[1].translate(0, -offset);
- }
-
- return Printable.PAGE_EXISTS;
+ return ap.printUnwrapped(pwidth, pheight, pi, pg);
}
public int printWrapped(int pwidth, int pheight, int pi, Graphics... pg)
throws PrinterException
{
- return ap.printWrappedAlignment(pg[1], pwidth, pheight, pi);
+ return ap.printWrappedAlignment(pwidth, pheight, pi, pg[0]);
}
private String getHtml(String titleSvg, String alignmentSvg,
// jquery facebox for displaying raw BioJSON data");
if (jsonData != null)
{
- htmlSvg.append("/* Facebox (for jQuery)\n");
- htmlSvg.append("* version: 1.3\n");
- htmlSvg.append(" * @requires jQuery v1.2 or later\n");
- htmlSvg.append(" * @homepage https://github.com/defunkt/facebox\n");
- htmlSvg.append(" * Licensed under the MIT:\n");
- htmlSvg.append(" * http://www.opensource.org/licenses/mit-license.php\n");
- htmlSvg.append(" * Copyright Forever Chris Wanstrath, Kyle Neath\n");
- htmlSvg.append(" * Usage:\n");
- htmlSvg.append(" * jQuery(document).ready(function() {\n");
- htmlSvg.append(" * jQuery('a[rel*=facebox]').facebox()\n");
- htmlSvg.append(" * })\n");
- htmlSvg.append(" * <a href=\"#terms\" rel=\"facebox\">Terms</a>\n");
- htmlSvg.append(" * Loads the #terms div in the box\n");
- htmlSvg.append(" * <a href=\"terms.html\" rel=\"facebox\">Terms</a>\n");
- htmlSvg.append(" * Loads the terms.html page in the box\n");
- htmlSvg.append(" * <a href=\"terms.png\" rel=\"facebox\">Terms</a>\n");
- htmlSvg.append(" * Loads the terms.png image in the box\n");
- htmlSvg.append(" * You can also use it programmatically:\n");
- htmlSvg.append(" * jQuery.facebox('some html')\n");
- htmlSvg.append(" * jQuery.facebox('some html', 'my-groovy-style')\n");
- htmlSvg.append(" * The above will open a facebox with \"some html\" as the content.\n");
- htmlSvg.append(" * jQuery.facebox(function($) {\n");
- htmlSvg.append(" * $.get('blah.html', function(data) { $.facebox(data) })\n");
- htmlSvg.append(" * })\n");
- htmlSvg.append(" * The above will show a loading screen before the passed function is called,\n");
- htmlSvg.append(" * allowing for a better ajaxy experience.\n");
- htmlSvg.append(" * The facebox function can also display an ajax page, an image, or the contents of a div:\n");
- htmlSvg.append(" * jQuery.facebox({ ajax: 'remote.html' })\n");
- htmlSvg.append(" * jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')\n");
- htmlSvg.append(" * jQuery.facebox({ image: 'stairs.jpg' })\n");
- htmlSvg.append(" * jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')\n");
- htmlSvg.append(" * jQuery.facebox({ div: '#box' })\n");
- htmlSvg.append(" * jQuery.facebox({ div: '#box' }, 'my-groovy-style')\n");
- htmlSvg.append(" * Want to close the facebox? Trigger the 'close.facebox' document event:\n");
- htmlSvg.append(" * jQuery(document).trigger('close.facebox')\n");
- htmlSvg.append(" * Facebox also has a bunch of other hooks:\n");
- htmlSvg.append(" * loading.facebox\n");
- htmlSvg.append(" * beforeReveal.facebox\n");
- htmlSvg.append(" * reveal.facebox (aliased as 'afterReveal.facebox')\n");
- htmlSvg.append(" * init.facebox\n");
- htmlSvg.append(" * afterClose.facebox\n");
- htmlSvg.append(" * Simply bind a function to any of these hooks:\n");
- htmlSvg.append(" * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })\n");
- htmlSvg.append(" *\n");
- htmlSvg.append(" */\n");
- htmlSvg.append("(function($) {\n");
- htmlSvg.append(" $.facebox = function(data, klass) {\n");
- htmlSvg.append(" $.facebox.loading()\n");
- htmlSvg.append(" if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)\n");
- htmlSvg.append(" else if (data.image) fillFaceboxFromImage(data.image, klass)\n");
- htmlSvg.append(" else if (data.div) fillFaceboxFromHref(data.div, klass)\n");
- htmlSvg.append(" else if ($.isFunction(data)) data.call($)\n");
- htmlSvg.append(" else $.facebox.reveal(data, klass)\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" $.extend($.facebox, {\n");
- htmlSvg.append(" settings: {\n");
- htmlSvg.append(" opacity : 0.2,\n");
- htmlSvg.append(" overlay : true,\n");
- htmlSvg.append(" loadingImage : 'https://raw.githubusercontent.com/jalview/biojson/gh-pages/images/loading.gif',\n");
- htmlSvg.append(" closeImage : 'https://raw.githubusercontent.com/jalview/biojson/gh-pages/images/cancel.png',\n");
- htmlSvg.append(" imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],\n");
- htmlSvg.append(" faceboxHtml : '<div id=\"facebox\" style=\"display:none; width: 95%; height: 85%; overflow: auto;\"> ");
- htmlSvg.append(" <div class=\"popup\"> ");
- htmlSvg.append(" <div class=\"content\"> ");
- htmlSvg.append(" </div> ");
- htmlSvg.append(" <a href=\"#\" class=\"close\"></a> ");
- htmlSvg.append(" </div> ");
- htmlSvg.append(" </div>'\n");
- htmlSvg.append(" }, \n");
- htmlSvg.append(" loading: function() {\n");
- htmlSvg.append(" init()\n");
- htmlSvg.append(" if ($('#facebox .loading').length == 1) return true\n");
- htmlSvg.append(" showOverlay() \n");
- htmlSvg.append(" $('#facebox .content').empty().\n");
- htmlSvg.append(" append('<div class=\"loading\"><img src=\"'+$.facebox.settings.loadingImage+'\"/></div>')\n");
- htmlSvg.append(" $('#facebox').show().css({\n");
- htmlSvg.append(" top: getPageScroll()[1] + (getPageHeight() / 10),\n");
- htmlSvg.append(" left: $(window).width() / 2 - ($('#facebox .popup').outerWidth() / 2)\n");
- htmlSvg.append(" }) \n");
- htmlSvg.append(" $(document).bind('keydown.facebox', function(e) {\n");
- htmlSvg.append(" if (e.keyCode == 27) $.facebox.close()\n");
- htmlSvg.append(" return true\n");
- htmlSvg.append(" })\n");
- htmlSvg.append(" $(document).trigger('loading.facebox')\n");
- htmlSvg.append(" },\n");
- htmlSvg.append(" reveal: function(data, klass) {\n");
- htmlSvg.append(" $(document).trigger('beforeReveal.facebox')\n");
- htmlSvg.append(" if (klass) $('#facebox .content').addClass(klass)\n");
- htmlSvg.append(" $('#facebox .content').empty().append('<pre><code>'+JSON.stringify(JSON.parse(data),null,4)+'</pre></code>')\n");
- htmlSvg.append(" $('#facebox .popup').children().fadeIn('normal')\n");
- htmlSvg.append(" $('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').outerWidth() / 2))\n");
- htmlSvg.append(" $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')\n");
- htmlSvg.append(" }, \n");
- htmlSvg.append(" close: function() {\n");
- htmlSvg.append(" $(document).trigger('close.facebox')\n");
- htmlSvg.append(" return false\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" })\n");
- htmlSvg.append(" $.fn.facebox = function(settings) {\n");
- htmlSvg.append(" if ($(this).length == 0) return \n");
- htmlSvg.append(" init(settings) \n");
- htmlSvg.append(" function clickHandler() {\n");
- htmlSvg.append(" $.facebox.loading(true) \n");
- htmlSvg.append(" // support for rel=\"facebox.inline_popup\" syntax, to add a class\n");
- htmlSvg.append(" // also supports deprecated \"facebox[.inline_popup]\" syntax\n");
- htmlSvg.append(" var klass = this.rel.match(/facebox\\[?\\.(\\w+)\\]?/)\n");
- htmlSvg.append(" if (klass) klass = klass[1]\n");
- htmlSvg.append(" fillFaceboxFromHref(this.href, klass)\n");
- htmlSvg.append(" return false\n");
- htmlSvg.append(" } \n");
- htmlSvg.append(" return this.bind('click.facebox', clickHandler)\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" // called one time to setup facebox on this page\n");
- htmlSvg.append(" function init(settings) {\n");
- htmlSvg.append(" if ($.facebox.settings.inited) return true\n");
- htmlSvg.append(" else $.facebox.settings.inited = true\n");
- htmlSvg.append(" $(document).trigger('init.facebox')\n");
- htmlSvg.append(" makeCompatible()\n");
- htmlSvg.append(" var imageTypes = $.facebox.settings.imageTypes.join('|')\n");
- htmlSvg.append(" $.facebox.settings.imageTypesRegexp = new RegExp('\\\\.(' + imageTypes + ')(\\\\?.*)?$', 'i')\n");
-
- htmlSvg.append(" if (settings) $.extend($.facebox.settings, settings)\n");
- htmlSvg.append(" $('body').append($.facebox.settings.faceboxHtml)\n");
-
- htmlSvg.append(" var preload = [ new Image(), new Image() ]\n");
- htmlSvg.append(" preload[0].src = $.facebox.settings.closeImage\n");
- htmlSvg.append(" preload[1].src = $.facebox.settings.loadingImage\n");
-
- htmlSvg.append(" $('#facebox').find('.b:first, .bl').each(function() {\n");
- htmlSvg.append(" preload.push(new Image())\n");
- htmlSvg.append(" preload.slice(-1).src = $(this).css('background-image').replace(/url\\((.+)\\)/, '$1')\n");
- htmlSvg.append(" })\n");
-
- htmlSvg.append(" $('#facebox .close')\n");
- htmlSvg.append(" .click($.facebox.close)\n");
- htmlSvg.append(" .append('<img src=\"'\n");
- htmlSvg.append(" + $.facebox.settings.closeImage\n");
- htmlSvg.append(" + '\" class=\"close_image\" title=\"close\">')\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" // getPageScroll() by quirksmode.com\n");
- htmlSvg.append(" function getPageScroll() {\n");
- htmlSvg.append(" var xScroll, yScroll;\n");
- htmlSvg.append(" if (self.pageYOffset) {\n");
- htmlSvg.append(" yScroll = self.pageYOffset;\n");
- htmlSvg.append(" xScroll = self.pageXOffset;\n");
- htmlSvg.append(" } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict\n");
- htmlSvg.append(" yScroll = document.documentElement.scrollTop;\n");
- htmlSvg.append(" xScroll = document.documentElement.scrollLeft;\n");
- htmlSvg.append(" } else if (document.body) {// all other Explorers\n");
- htmlSvg.append(" yScroll = document.body.scrollTop;\n");
- htmlSvg.append(" xScroll = document.body.scrollLeft;\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" return new Array(xScroll,yScroll)\n");
- htmlSvg.append(" }\n");
-
- // Adapted from getPageSize() by quirksmode.com");
- htmlSvg.append(" function getPageHeight() {\n");
- htmlSvg.append(" var windowHeight\n");
- htmlSvg.append(" if (self.innerHeight) { // all except Explorer\n");
- htmlSvg.append(" windowHeight = self.innerHeight;\n");
- htmlSvg.append(" } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode\n");
- htmlSvg.append(" windowHeight = document.documentElement.clientHeight;\n");
- htmlSvg.append(" } else if (document.body) { // other Explorers\n");
- htmlSvg.append(" windowHeight = document.body.clientHeight;\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" return windowHeight\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" // Backwards compatibility\n");
- htmlSvg.append(" function makeCompatible() {\n");
- htmlSvg.append(" var $s = $.facebox.settings \n");
- htmlSvg.append(" $s.loadingImage = $s.loading_image || $s.loadingImage\n");
- htmlSvg.append(" $s.closeImage = $s.close_image || $s.closeImage\n");
- htmlSvg.append(" $s.imageTypes = $s.image_types || $s.imageTypes\n");
- htmlSvg.append(" $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" // Figures out what you want to display and displays it\n");
- htmlSvg.append(" // formats are:\n");
- htmlSvg.append(" // div: #id\n");
- htmlSvg.append(" // image: blah.extension\n");
- htmlSvg.append(" // ajax: anything else\n");
- htmlSvg.append(" function fillFaceboxFromHref(href, klass) {\n");
- htmlSvg.append(" // div\n");
- htmlSvg.append(" if (href.match(/#/)) {\n");
- htmlSvg.append(" var url = window.location.href.split('#')[0]\n");
- htmlSvg.append(" var target = href.replace(url,'')\n");
- htmlSvg.append(" if (target == '#') return\n");
- htmlSvg.append(" $.facebox.reveal($(target).html(), klass)\n");
-
- htmlSvg.append(" // image\n");
- htmlSvg.append(" } else if (href.match($.facebox.settings.imageTypesRegexp)) {\n");
- htmlSvg.append(" fillFaceboxFromImage(href, klass)\n");
- htmlSvg.append(" // ajax\n");
- htmlSvg.append(" } else {\n");
- htmlSvg.append(" fillFaceboxFromAjax(href, klass)\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" function fillFaceboxFromImage(href, klass) {\n");
- htmlSvg.append(" var image = new Image()\n");
- htmlSvg.append(" image.onload = function() {\n");
- htmlSvg.append(" $.facebox.reveal('<div class=\"image\"><img src=\"' + image.src + '\" /></div>', klass)\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" image.src = href\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" function fillFaceboxFromAjax(href, klass) {\n");
- htmlSvg.append(" $.facebox.jqxhr = $.get(href, function(data) { $.facebox.reveal(data, klass) })\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" function skipOverlay() {\n");
- htmlSvg.append(" return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" function showOverlay() {\n");
- htmlSvg.append(" if (skipOverlay()) return\n");
-
- htmlSvg.append(" if ($('#facebox_overlay').length == 0)\n");
- htmlSvg.append(" $(\"body\").append('<div id=\"facebox_overlay\" class=\"facebox_hide\"></div>')\n");
-
- htmlSvg.append(" $('#facebox_overlay').hide().addClass(\"facebox_overlayBG\")\n");
- htmlSvg.append(" .css('opacity', $.facebox.settings.opacity)\n");
- htmlSvg.append(" .click(function() { $(document).trigger('close.facebox') })\n");
- htmlSvg.append(" .fadeIn(200)\n");
- htmlSvg.append(" return false\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" function hideOverlay() {\n");
- htmlSvg.append(" if (skipOverlay()) return \n");
- htmlSvg.append(" $('#facebox_overlay').fadeOut(200, function(){\n");
- htmlSvg.append(" $(\"#facebox_overlay\").removeClass(\"facebox_overlayBG\")\n");
- htmlSvg.append(" $(\"#facebox_overlay\").addClass(\"facebox_hide\")\n");
- htmlSvg.append(" $(\"#facebox_overlay\").remove()\n");
- htmlSvg.append(" }) \n");
- htmlSvg.append(" return false\n");
- htmlSvg.append(" }\n");
-
- htmlSvg.append(" $(document).bind('close.facebox', function() {\n");
- htmlSvg.append(" if ($.facebox.jqxhr) {\n");
- htmlSvg.append(" $.facebox.jqxhr.abort()\n");
- htmlSvg.append(" $.facebox.jqxhr = null\n");
- htmlSvg.append(" }\n");
- htmlSvg.append(" $(document).unbind('keydown.facebox')\n");
- htmlSvg.append(" $('#facebox').fadeOut(function() {\n");
- htmlSvg.append(" $('#facebox .content').removeClass().addClass('content')\n");
- htmlSvg.append(" $('#facebox .loading').remove()\n");
- htmlSvg.append(" $(document).trigger('afterClose.facebox')\n");
- htmlSvg.append(" })\n");
- htmlSvg.append(" hideOverlay()\n");
- htmlSvg.append(" })\n");
-
- htmlSvg.append("})(jQuery);\n");
-
+ File faceBoxJsFile = new File("examples/javascript/facebox-1.3.js");
+ try
+ {
+ htmlSvg.append(HTMLOutput.readFileAsString(faceBoxJsFile));
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ }
}
htmlSvg.append("</script>\n");
htmlSvg.append("</html>");
return htmlSvg.toString();
}
+
+ @Override
+ public boolean isEmbedData()
+ {
+ return Boolean.valueOf(jalview.bin.Cache.getDefault(
+ "EXPORT_EMBBED_BIOJSON", "true"));
+ }
+
+ @Override
+ public boolean isLaunchInBrowserAfterExport()
+ {
+ return true;
+ }
+
+ @Override
+ public File getExportedFile()
+ {
+ return generatedFile;
+ }
}
}
});
urlTB.setFont(JvSwingUtils.getLabelFont());
- urlTB.setText("http://www.");
+ urlTB.setText("http://");
urlTB.setBounds(new Rectangle(78, 40, 309, 23));
urlTB.addKeyListener(new KeyAdapter()
{
hydrophobic.put("D", ZERO);
hydrophobic.put("N", ZERO);
hydrophobic.put("S", ZERO);
- hydrophobic.put("T", ZERO);
+ hydrophobic.put("T", ONE);
hydrophobic.put("P", ZERO);
}
registerPDBFile(pdb.getId().trim(), pdbFile);
}
// if PDBId is unavailable then skip SIFTS mapping execution path
- isMapUsingSIFTs = pdb.isPPDBIdAvailable();
+ isMapUsingSIFTs = isMapUsingSIFTs && pdb.isPPDBIdAvailable();
} catch (Exception ex)
{
* @param protocol
*/
public AAStructureBindingModel(StructureSelectionManager ssm,
- PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
+ PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
String protocol)
{
this.ssm = ssm;
this.sequence = sequenceIs;
this.nucleotide = Comparison.isNucleotide(sequenceIs);
- this.chains = chains;
this.pdbEntry = pdbentry;
this.protocol = protocol;
- if (chains == null)
- {
- this.chains = new String[pdbentry.length][];
- }
}
public StructureSelectionManager getSsm()
{
this.finishedInit = fi;
}
+
+ /**
+ * Returns a list of chains mapped in this viewer.
+ *
+ * @return
+ */
+ public abstract List<String> getChainNames();
+
}
.size()]);
return isNucleotide(oneDArray);
}
+
+ /**
+ * Compares two residues either case sensitively or case insensitively
+ * depending on the caseSensitive flag
+ *
+ * @param c1
+ * first char
+ * @param c2
+ * second char to compare with
+ * @param caseSensitive
+ * if true comparison will be case sensitive otherwise its not
+ * @return
+ */
+ public static boolean isSameResidue(char c1, char c2,
+ boolean caseSensitive)
+ {
+ if (caseSensitive)
+ {
+ return (c1 == c2);
+ }
+ else
+ {
+ return Character.toUpperCase(c1) == Character.toUpperCase(c2);
+ }
+ }
}
*/
public class Platform
{
+ private static Boolean isAMac = null;
+
+ private static Boolean isHeadless = null;
+
/**
* sorry folks - Macs really are different
*
*/
public static boolean isAMac()
{
- return java.lang.System.getProperty("os.name").indexOf("Mac") > -1;
+ if (isAMac == null)
+ {
+ isAMac = System.getProperty("os.name").indexOf("Mac") > -1;
+ }
+ return isAMac.booleanValue();
}
public static boolean isHeadless()
{
- String hdls = java.lang.System.getProperty("java.awt.headless");
-
- return hdls != null && hdls.equals("true");
+ if (isHeadless == null)
+ {
+ isHeadless = "true".equals(System.getProperty("java.awt.headless"));
+ }
+ return isHeadless;
}
/**
*/
public static boolean isControlDown(MouseEvent e)
{
- if (isAMac())
+ boolean aMac = isAMac();
+ return isControlDown(e, aMac);
+ }
+
+ /**
+ * Overloaded version of method (to allow unit testing)
+ *
+ * @param e
+ * @param aMac
+ * @return
+ */
+ protected static boolean isControlDown(MouseEvent e, boolean aMac)
+ {
+ if (aMac)
{
+ /*
+ * answer false for right mouse button
+ */
+ if (e.isPopupTrigger())
+ {
+ return false;
+ }
return (Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() & e
.getModifiers()) != 0;
// could we use e.isMetaDown() here?
import jalview.io.StructureFile;
import jalview.schemes.ResidueProperties;
import jalview.structure.StructureMapping;
+import jalview.util.Comparison;
import jalview.util.DBRefUtils;
import jalview.util.Format;
import jalview.xml.binding.sifts.Entry;
if (os != null)
{
MappingOutputPojo mop = new MappingOutputPojo();
- mop.setSeqStart(pdbStart);
- mop.setSeqEnd(pdbEnd);
+ mop.setSeqStart(seqStart);
+ mop.setSeqEnd(seqEnd);
mop.setSeqName(seq.getName());
mop.setSeqResidue(matchedSeq);
- mop.setStrStart(seqStart);
- mop.setStrEnd(seqEnd);
+ mop.setStrStart(pdbStart);
+ mop.setStrEnd(pdbEnd);
mop.setStrName(structId);
mop.setStrResidue(targetStrucSeqs.toString());
{
if ((i + (j * len)) < seqRes.length())
{
- if (seqRes.charAt(i + (j * len)) == strRes
- .charAt(i + (j * len))
+ boolean sameChar = Comparison.isSameResidue(
+ seqRes.charAt(i + (j * len)),
+ strRes.charAt(i + (j * len)), false);
+ if (sameChar
&& !jalview.util.Comparison.isGap(seqRes.charAt(i
+ (j * len))))
{
public class CommandLineOperations
{
+ private static final int TEST_TIMEOUT = 4500; // Note longer timeout needed on
+ // full test run than on
+ // individual tests
+
+ private static final int SETUP_TIMEOUT = 9000;
+
+ private static final int MINFILESIZE_SMALL = 2096;
+
+ private static final int MINFILESIZE_BIG = 4096;
private ArrayList<String> successfulCMDs = new ArrayList<String>();
this.process = process;
}
+ @Override
public void run()
{
try
String cmds = "nodisplay -open examples/uniref50.fa -sortbytree -props FILE -colour zappo "
+ "-jabaws http://www.compbio.dundee.ac.uk/jabaws -nosortbytree -dasserver nickname=www.test.com "
+ "-features examples/testdata/plantfdx.features -annotations examples/testdata/plantfdx.annotations -tree examples/testdata/uniref50_test_tree";
- Worker worker = jalviewDesktopRunner(true, cmds, 9000);
+ Worker worker = jalviewDesktopRunner(true, cmds, SETUP_TIMEOUT);
String ln = null;
while ((ln = worker.getOutputReader().readLine()) != null)
{
public void setUpForCommandLineInputOperations() throws IOException
{
String cmds = "-open examples/uniref50.fa -noquestionnaire -nousagestats";
- Worker worker = jalviewDesktopRunner(false, cmds, 9000);
+ Worker worker = jalviewDesktopRunner(false, cmds, SETUP_TIMEOUT);
String ln = null;
int count = 0;
while ((ln = worker.getErrorReader().readLine()) != null)
worker.process.destroy();
Assert.fail("Jalview did not exit after "
+ type
- + " generation (try running test again to verify - timeout at 9000ms). ["
+ + " generation (try running test again to verify - timeout at "
+ + SETUP_TIMEOUT + "ms). ["
+ harg + "]");
}
new File(fileName).delete();
{
return new Object[][] {
{ "nodisplay -open examples/uniref50.fa", " -eps",
- "test_uniref50_out.eps", true, 4096, 4000 },
+ "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "nodisplay -open examples/uniref50.fa", " -eps",
- "test_uniref50_out.eps", false, 4096, 4000 },
+ "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "nogui -open examples/uniref50.fa", " -eps",
- "test_uniref50_out.eps", true, 4096, 4000 },
+ "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "nogui -open examples/uniref50.fa", " -eps",
- "test_uniref50_out.eps", false, 4096, 4000 },
+ "test_uniref50_out.eps", false, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -eps",
- "test_uniref50_out.eps", true, 4096, 4000 },
+ "test_uniref50_out.eps", true, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -svg",
- "test_uniref50_out.svg", false, 4096, 3000 },
+ "test_uniref50_out.svg", false, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -png",
- "test_uniref50_out.png", true, 4096, 3000 },
+ "test_uniref50_out.png", true, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -html",
- "test_uniref50_out.html", true, 4096, 3000 },
+ "test_uniref50_out.html", true, MINFILESIZE_BIG, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -fasta",
- "test_uniref50_out.mfa", true, 2096, 3000 },
+ "test_uniref50_out.mfa", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -clustal",
- "test_uniref50_out.aln", true, 2096, 3000 },
+ "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -msf",
- "test_uniref50_out.msf", true, 2096, 3000 },
+ "test_uniref50_out.msf", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -pileup",
- "test_uniref50_out.aln", true, 2096, 3000 },
+ "test_uniref50_out.aln", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -pir",
- "test_uniref50_out.pir", true, 2096, 3000 },
+ "test_uniref50_out.pir", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -pfam",
- "test_uniref50_out.pfam", true, 2096, 3000 },
+ "test_uniref50_out.pfam", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -blc",
- "test_uniref50_out.blc", true, 2096, 3000 },
+ "test_uniref50_out.blc", true, MINFILESIZE_SMALL, TEST_TIMEOUT },
{ "headless -open examples/uniref50.fa", " -jalview",
- "test_uniref50_out.jvp", true, 2096, 3000 }, };
+ "test_uniref50_out.jvp", true, MINFILESIZE_SMALL, TEST_TIMEOUT }, };
}
}
assertEquals(sf1.hashCode(), sf2.hashCode());
// changing type breaks equals:
+ String restores = sf2.getType();
sf2.setType("Type");
assertFalse(sf1.equals(sf2));
+ sf2.setType(restores);
// changing description breaks equals:
- sf2.setType("type");
+ restores = sf2.getDescription();
sf2.setDescription("Desc");
assertFalse(sf1.equals(sf2));
+ sf2.setDescription(restores);
+
+ // changing score breaks equals:
+ float restoref = sf2.getScore();
+ sf2.setScore(12.4f);
+ assertFalse(sf1.equals(sf2));
+ sf2.setScore(restoref);
+
+ // NaN doesn't match a number
+ restoref = sf2.getScore();
+ sf2.setScore(Float.NaN);
+ assertFalse(sf1.equals(sf2));
+
+ // NaN matches NaN
+ sf1.setScore(Float.NaN);
+ assertTrue(sf1.equals(sf2));
+ sf1.setScore(restoref);
+ sf2.setScore(restoref);
// changing start position breaks equals:
- sf2.setDescription("desc");
+ int restorei = sf2.getBegin();
sf2.setBegin(21);
assertFalse(sf1.equals(sf2));
+ sf2.setBegin(restorei);
// changing end position breaks equals:
- sf2.setBegin(22);
+ restorei = sf2.getEnd();
sf2.setEnd(32);
assertFalse(sf1.equals(sf2));
+ sf2.setEnd(restorei);
// changing feature group breaks equals:
- sf2.setEnd(33);
+ restores = sf2.getFeatureGroup();
sf2.setFeatureGroup("Group");
assertFalse(sf1.equals(sf2));
+ sf2.setFeatureGroup(restores);
// changing ID breaks equals:
- sf2.setFeatureGroup("group");
+ restores = (String) sf2.getValue("ID");
sf2.setValue("ID", "id2");
assertFalse(sf1.equals(sf2));
+ sf2.setValue("ID", restores);
// changing Name breaks equals:
- sf2.setValue("ID", "id");
+ restores = (String) sf2.getValue("Name");
sf2.setValue("Name", "Name");
assertFalse(sf1.equals(sf2));
+ sf2.setValue("Name", restores);
// changing Parent breaks equals:
- sf2.setValue("Name", "name");
+ restores = (String) sf1.getValue("Parent");
sf1.setValue("Parent", "Parent");
assertFalse(sf1.equals(sf2));
+ sf1.setValue("Parent", restores);
// changing strand breaks equals:
- sf1.setValue("Parent", "parent");
+ restorei = sf2.getStrand();
sf2.setStrand("-");
assertFalse(sf1.equals(sf2));
+ sf2.setStrand(restorei == 1 ? "+" : "-");
// changing phase breaks equals:
- sf2.setStrand("+");
+ restores = sf1.getPhase();
sf1.setPhase("2");
assertFalse(sf1.equals(sf2));
+ sf1.setPhase(restores);
// restore equality as sanity check:
- sf1.setPhase("1");
assertTrue(sf1.equals(sf2));
assertTrue(sf2.equals(sf1));
assertEquals(sf1.hashCode(), sf2.hashCode());
*/
public class TestHtsContigDb
{
- @Test
+ @Test(groups = "Functional")
public final void testHTSReferenceSequence() throws Exception
{
HtsContigDb remmadb = new HtsContigDb("REEMADB", new File(
public class AlignFrameTest
{
- @Test
+ @Test(groups = "Functional")
public void testHideFeatureColumns()
{
SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
public class AppVarnaTest
{
- @Test
+ @Test(groups = "Functional")
public void testReplaceOddGaps()
{
String struct = "{(<]}>)";
{
e.printStackTrace();
}
- bjsTemplate = BioJsHTMLOutput.getBioJsTemplateAsString();
+ bjsTemplate = HTMLOutput.readFileAsString(BioJsHTMLOutput
+ .getCurrentBJSTemplateFile());
// System.out.println(bjsTemplate);
} catch (IOException e)
{
{
try
{
- BioJsHTMLOutput.refreshBioJSVersionsInfo(null);
+ BioJsHTMLOutput.refreshVersionInfo(null);
} catch (URISyntaxException e)
{
AssertJUnit.fail("Expception occured while testing!");
try
{
BioJsHTMLOutput
- .refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
versions = BioJsHTMLOutput.getBioJsMSAVersions();
} catch (URISyntaxException e)
{
public class PfamFormatInputTest
{
- @Test
+ @Test(groups = "Functional")
public void testPfamFormatNoLimits() throws IOException
{
- AlignmentI al = new jalview.io.AppletFormatAdapter().readFile("ASEQ"
+ AlignmentI al = new AppletFormatAdapter().readFile("ASEQ"
+ '\t' + "...--FFAFAFF--", AppletFormatAdapter.PASTE, "PFAM");
Assert.assertEquals(1, al.getHeight(), "Wrong number of sequences");
Assert.assertTrue(al.hasValidSequence(),
"Didn't extract limits from PFAM ID");
}
- @Test
+ @Test(groups = "Functional")
public void testPfamFormatValidLimits() throws IOException
{
- AlignmentI al = new jalview.io.AppletFormatAdapter().readFile(
+ AlignmentI al = new AppletFormatAdapter().readFile(
"ASEQ/15-25" + '\t' + "...--FFAFAFF--",
AppletFormatAdapter.PASTE, "PFAM");
Assert.assertEquals(1, al.getHeight(), "Wrong number of sequences");
checkProperty("polar", "YWHRKTSNDEQ-*X");
checkProperty("positive", "HKR-*");
checkProperty("proline", "P-*");
- checkProperty("hydrophobic", "MILVFYWHKCGAC-*X");
+ checkProperty("hydrophobic", "MILVFYWHKTGAC-*X");
}
/**
pdbFiles[0] = new PDBEntry("1YCS", "A", Type.PDB, "INLINE1YCS");
pdbFiles[1] = new PDBEntry("3A6S", "B", Type.PDB, "INLINE3A6S");
pdbFiles[2] = new PDBEntry("1OOT", "A", Type.PDB, "INLINE1OOT");
- String[][] chains = new String[3][];
SequenceI[][] seqs = new SequenceI[3][];
seqs[0] = new SequenceI[] { seq1a, seq1b };
seqs[1] = new SequenceI[] { seq2 };
ssm.setMapping(new SequenceI[] { seq3 }, null, PDB_3,
AppletFormatAdapter.PASTE);
- testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, chains, null)
+ testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, null)
{
@Override
public String[] getPdbFile()
public void highlightAtoms(List<AtomSpec> atoms)
{
}
+
+ @Override
+ public List<String> getChainNames()
+ {
+ return null;
+ }
};
}
assertTrue(Comparison.isNucleotideSequence("a A-g.GcCtTuU", true));
assertFalse(Comparison.isNucleotideSequence("a A-g.GcCtTuU", false));
}
+
+ @Test(groups = { "Functional" })
+ public void testIsSameResidue()
+ {
+ assertTrue(Comparison.isSameResidue('a', 'a', false));
+ assertTrue(Comparison.isSameResidue('a', 'a', true));
+ assertTrue(Comparison.isSameResidue('A', 'a', false));
+ assertTrue(Comparison.isSameResidue('a', 'A', false));
+
+ assertFalse(Comparison.isSameResidue('a', 'A', true));
+ assertFalse(Comparison.isSameResidue('A', 'a', true));
+ }
}
--- /dev/null
+package jalview.util;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.awt.Button;
+import java.awt.Event;
+import java.awt.event.MouseEvent;
+
+import org.testng.annotations.Test;
+
+public class PlatformTest
+{
+ Button b = new Button();
+
+ /**
+ * isControlDown for Mac should answer true for Meta-down, but not for right
+ * mouse (popup trigger)
+ */
+ @Test(groups = "Functional")
+ public void testIsControlDown_mac()
+ {
+ int clickCount = 1;
+ boolean isPopupTrigger = false;
+ int buttonNo = MouseEvent.BUTTON1;
+ boolean mac = true;
+
+ int mods = 0;
+ // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
+ assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ mods = Event.CTRL_MASK;
+ assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ mods = Event.META_MASK;
+ assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ isPopupTrigger = true;
+ assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ isPopupTrigger = false;
+ buttonNo = MouseEvent.BUTTON2;
+ mods = 0;
+ assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+ }
+
+ /**
+ * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
+ * event
+ */
+ @Test(groups = "Functional")
+ public void testIsControlDown_notMac()
+ {
+ int clickCount = 1;
+ boolean isPopupTrigger = false;
+ int buttonNo = MouseEvent.BUTTON1;
+ boolean mac = false;
+
+ int mods = 0;
+ // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
+ assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ mods = Event.CTRL_MASK;
+ assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+
+ mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
+ clickCount = 2;
+ buttonNo = 2;
+ isPopupTrigger = true;
+ assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
+ 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
+ }
+}
{
orig_alig.deleteAnnotation(aa);
}
- testAnnotationFileIO("Testing IUPred Annotation IO", orig_alig);
+ checkAnnotationFileIO("Testing IUPred Annotation IO", orig_alig);
}
- public static void testAnnotationFileIO(String testname, AlignmentI al)
+ static void checkAnnotationFileIO(String testname, AlignmentI al)
{
try
{
testSeq, testPDBId, "A");
String expectedMappingOutput = "\nSequence ⟷ Structure mapping details\n"
+ "Method: SIFTS\n\n"
- + "P00221 : 1 - 97 Maps to \n"
- + "1A70|A : 51 - 147\n\n"
+ + "P00221 : 51 - 147 Maps to \n"
+ + "1A70|A : 1 - 97\n\n"
+ "P00221 AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n"
+ " |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
+ "1A70|A AAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLD\n\n"