X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FHTMLOutput.java;h=fd51823c9277734de36dd88550ef599f111df726;hb=505e70d1af8a25642843387160b1ef199c5cbb04;hp=8eef36f345af5cd863bb9f50c06e64bf9fee3967;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index 8eef36f..fd51823 100755 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -11,59 +11,226 @@ import java.util.*; public class HTMLOutput { - SequenceRenderer sr = new SequenceRenderer(); + AlignViewport av; + SequenceRenderer sr; + Color color; - public HTMLOutput(AlignmentI alignment, ColourSchemeI cs) + public HTMLOutput(AlignViewport av) { - Color color; - JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY); + this.av = av; + sr = new SequenceRenderer(av); + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY") + , new String[]{"html"}, "HTML files"); + + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Save as HTML"); chooser.setToolTipText("Save"); int value = chooser.showSaveDialog(null); - if(value == JFileChooser.APPROVE_OPTION) + if(value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.LAST_DIRECTORY = choice; + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); try{ PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(choice)); out.println(""); out.println(""); out.println(""); - out.println(""); - out.close(); } - catch(Exception ex){} + + out.println(""); } + ////////////// + out.println("
\n"); - out.println("\n"); - ////////////// - for (int i = 0; i < alignment.getHeight(); i++) + if(av.getWrapAlignment()) + drawWrappedAlignment(out); + else + drawUnwrappedAlignment(out); + + out.println("\n\n"); + out.close(); + jalview.util.BrowserLauncher.openURL( "file:///"+choice ); + } + catch(Exception ex){ex.printStackTrace();} + } + } + + void drawUnwrappedAlignment(PrintWriter out) + { + + out.println("
\n"); + out.println("\n"); + + + ////////////// + SequenceGroup [] groups; + SequenceI seq; + ColourSchemeI cs = null; + AlignmentI alignment = av.getAlignment(); + String r,g,b; + + // draws the top row, the measure rule + out.println(""); + int i=0; + for(i=10; i"+i+"
|
"); + + out.println(""); + out.println(""); + + for (i = 0; i < alignment.getHeight(); i++) + { + seq = alignment.getSequenceAt(i); + groups = alignment.findAllGroups( seq ); + if(av.getShowFullId()) + out.println(""); + else + out.println(""); + + + + for (int res = 0; res < seq.getLength(); res++) + { + cs = av.getGlobalColourScheme(); + + if(groups!=null) + { + for (int k = 0; k < groups.length; k++) + if (groups[k].getStartRes() <= res && groups[k].getEndRes() >= res) + { + cs = groups[k].cs; + break; + } + } + + + color = sr.getResidueBoxColour(cs, seq, res); + + if(color.getRGB()<-1) { - SequenceI seq = alignment.getSequenceAt(i); - out.println(""); - for (int res = 0; res < seq.getLength(); res++) - { - color = sr.getResidueBoxColour(cs, seq, res); - Integer.toHexString(color.getRed()); - - out.println(""); - } - - out.println(""); + r = Integer.toHexString(color.getRed()); + if(r.length()<2) + r = "0"+r; + g = Integer.toHexString(color.getGreen()); + if(g.length()<2) + g = "0"+g; + b = Integer.toHexString(color.getBlue()); + if(b.length()<2) + b = "0"+b; + out.println(""); } - ////////////// - out.println("
"+i+"
|
"+seq.getDisplayId()+"  
"+seq.getName()+"  
"+seq.getName()+"  
"+seq.getCharAt(res)+"
"+seq.getCharAt(res)+"
"); - out.println("
\n\n"); + else + out.println("
"+seq.getCharAt(res)+"
"); + out.println(""); + + } + + void drawWrappedAlignment(PrintWriter out) + { + //////////////////////////////////// + /// How many sequences and residues can we fit on a printable page? + AlignmentI al = av.getAlignment(); + SequenceGroup [] groups; + SequenceI seq; + ColourSchemeI cs = null; + String r,g,b; + + out.println("
\n"); + out.println("\n"); + + for(int startRes=0; startResal.getWidth()) + endRes = al.getWidth(); + + out.println(""); + out.println(""); + for (int i = startRes+10; i < endRes; i += 10) + out.println(""); + + // out.println(""); + out.println(""); + + + + for (int s = 0; s < al.getHeight(); s++) + { + out.println(""); + seq = al.getSequenceAt(s); + groups = al.findAllGroups( seq ); + if(av.getShowFullId()) + out.println(""); + else + out.println(""); + + for (int res = startRes; res < endRes; res++) + { + cs = av.getGlobalColourScheme(); + if(groups!=null) + { + for (int k = 0; k < groups.length; k++) + if (groups[k].getStartRes() <= res && groups[k].getEndRes() >= res) + { + cs = groups[k].cs; + break; + } + } + + color = sr.getResidueBoxColour(cs, seq, res); + + if(color.getRGB()<-1) + { + r = Integer.toHexString(color.getRed()); + if(r.length()<2) + r = "0"+r; + g = Integer.toHexString(color.getGreen()); + if(g.length()<2) + g = "0"+g; + b = Integer.toHexString(color.getBlue()); + if(b.length()<2) + b = "0"+b; + out.println(""); + } + else + out.println(""); + + } + + out.println(""); + + } + if(endRes"); + + + + } + + out.println("
 " + i + "
|
" + i + + // "
|
"+seq.getDisplayId()+"  "+seq.getName()+"  "+seq.getCharAt(res)+""+seq.getCharAt(res)+"
"); + out.println("
"); + + + }