+ /////////////////////////////\r
+ /// Only print these sequences and residues on this page\r
+ int endSeq;\r
+ startRes = (pi % pagesWide) * totalRes;\r
+ endRes = (startRes + totalRes) - 1;\r
+\r
+ if (endRes > (av.getAlignment().getWidth() - 1))\r
+ {\r
+ endRes = av.getAlignment().getWidth() - 1;\r
+ }\r
+\r
+ startSeq = (pi / pagesWide) * totalSeq;\r
+ endSeq = startSeq + totalSeq;\r
+\r
+ if (endSeq > av.getAlignment().getHeight())\r
+ {\r
+ endSeq = av.getAlignment().getHeight();\r
+ }\r
+\r
+ int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;\r
+\r
+ if (av.showAnnotation)\r
+ {\r
+ pagesHigh += annotationPanel.getHeight();\r
+ }\r
+\r
+ pagesHigh /= pheight;\r
+\r
+ if (pi >= (pagesWide * pagesHigh))\r
+ {\r
+ return Printable.NO_SUCH_PAGE;\r
+ }\r
+\r
+ //draw Scale\r
+ pg.translate(idWidth, 0);\r
+ scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);\r
+ pg.translate(-idWidth, scaleHeight);\r
+\r
+ ////////////////\r
+ // Draw the ids\r
+ Color currentColor = null;\r
+ Color currentTextColor = null;\r
+\r
+ for (int i = startSeq; i < endSeq; i++)\r
+ {\r
+ if ((av.getSelectionGroup() != null) &&\r
+ av.getSelectionGroup().sequences.contains(\r
+ av.getAlignment().getSequenceAt(i)))\r
+ {\r
+ currentColor = Color.gray;\r
+ currentTextColor = Color.black;\r
+ }\r
+ else\r
+ {\r
+ currentColor = av.getAlignment().getSequenceAt(i).getColor();\r
+ currentTextColor = Color.black;\r
+ }\r
+\r
+ pg.setColor(currentColor);\r
+ pg.fillRect(0, (i-startSeq) * av.charHeight, idWidth,\r
+ av.getCharHeight());\r
+\r
+ pg.setColor(currentTextColor);\r
+\r
+ String string = av.getAlignment().getSequenceAt(i).getName();\r
+\r
+ if (av.getShowFullId())\r
+ {\r
+ string = av.getAlignment().getSequenceAt(i).getDisplayId();\r
+ }\r
+\r
+ pg.drawString(string, 0,\r
+ (((i-startSeq) * av.charHeight) + av.getCharHeight()) -\r
+ (av.getCharHeight() / 5));\r
+ }\r
+\r
+ // draw main sequence panel\r
+ pg.translate(idWidth, 0);\r
+ seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq,\r
+ startRes, startSeq, 0);\r
+\r
+ if (av.showAnnotation && (endSeq == av.alignment.getHeight()))\r
+ {\r
+ pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight);\r
+ alabels.drawComponent((Graphics2D) pg);\r
+ pg.translate(idWidth, 0);\r
+ annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes +\r
+ 1);\r
+ }\r
+\r
+ return Printable.PAGE_EXISTS;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param pg DOCUMENT ME!\r
+ * @param pwidth DOCUMENT ME!\r
+ * @param pheight DOCUMENT ME!\r
+ * @param pi DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ *\r
+ * @throws PrinterException DOCUMENT ME!\r
+ */\r
+ public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,\r
+ int pi) throws PrinterException\r
+ {\r
+ int idWidth = calculateIdWidth().width + 4;\r
+\r
+ int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -\r
+ idWidth);\r
+ int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * ((av.alignment.getWidth() / resWidth) +\r
+ 1) * av.charHeight;\r
+\r
+ pg.setColor(Color.white);\r
+ pg.fillRect(0, 0, pwidth, pheight);\r
+ pg.setFont(av.getFont());\r
+\r
+ ////////////////\r
+ // Draw the ids\r
+ pg.setColor(Color.black);\r
+\r
+ pg.translate(0, -pi * pheight);\r
+\r
+ pg.setClip(0, pi * pheight, pwidth, pheight);\r
+\r
+ int ypos = 2 * av.charHeight;\r
+\r
+ do\r
+ {\r
+ for (int i = 0; i < av.alignment.getHeight(); i++)\r
+ {\r
+ SequenceI s = av.alignment.getSequenceAt(i);\r
+ String string = s.getName();\r
+\r
+ if (av.getShowFullId())\r
+ {\r
+ string = s.getDisplayId();\r
+ }\r
+\r
+ pg.drawString(string, 0,\r
+ ((i * av.charHeight) + ypos + av.charHeight) -\r
+ (av.charHeight / 5));\r
+ }\r
+\r
+ ypos += ((av.alignment.getHeight() + 2) * av.charHeight);\r
+ }\r
+ while (ypos < totalHeight);\r
+\r
+ pg.translate(idWidth, 0);\r
+\r
+ seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);\r
+\r
+ if ((pi * pheight) < totalHeight)\r
+ {\r
+ return Printable.PAGE_EXISTS;\r
+ }\r
+ else\r
+ {\r
+ return Printable.NO_SUCH_PAGE;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void makeEPS(File epsFile)\r
+ {\r
+ if(epsFile == null)\r
+ {\r
+ jalview.io.JalviewFileChooser chooser = new jalview.io.\r
+ JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[]\r
+ {"eps"},\r
+ new String[]\r
+ {"Encapsulated Postscript"},\r
+ "Encapsulated Postscript");\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Create EPS file from alignment");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+\r
+ if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ return;\r
+ }\r
+\r
+ epsFile = chooser.getSelectedFile();\r
+\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+ chooser.getSelectedFile().getParent());\r
+ }\r
+\r
+ int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;\r
+ int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) *\r
+ av.chunkHeight;\r
+ width = seqPanel.getWidth() + idPanel.getWidth();\r
+\r
+ }\r
+\r
+\r
+ if (av.getShowAnnotation())\r
+ {\r
+ height += annotationPanel.getPreferredSize().height;\r
+ }\r
+\r
+ try\r
+ {\r
+ FileOutputStream out = new FileOutputStream(epsFile);\r
+ EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width,\r
+ height);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ printWrappedAlignment(pg, width, height, 0);\r
+ }\r
+ else\r
+ {\r
+ printUnwrapped(pg, width, height, 0);\r
+ }\r
+\r
+ pg.flush();\r
+ pg.close();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+\r
+ public void makePNGImageMap(File imgMapFile, String imageName)\r
+ {\r
+ ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS\r
+ //////////////////////////////////////////////\r
+ int idWidth = calculateIdWidth().width + 4;\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+ int scaleHeight = av.charHeight + fm.getDescent();\r
+\r
+ // Gen image map\r
+ //////////////////////////////////\r
+ if(imgMapFile!=null)\r
+ {\r
+ try\r
+ {\r
+ PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));\r
+ out.println(jalview.io.HTMLOutput.getImageMapHTML());\r
+ out.println("<img src=\"" + imageName +\r
+ "\" border=\"0\" usemap=\"#Map\" >"\r
+ +"<map name=\"Map\">");\r
+\r
+ for (int s = 0; s < av.alignment.getHeight(); s++)\r
+ {\r
+ SequenceI seq = av.alignment.getSequenceAt(s);\r
+ SequenceGroup[] groups = av.alignment.findAllGroups(seq);\r
+ for (int i = 0; i < groups.length; i++)\r
+ {\r
+ int sy = s * av.charHeight + scaleHeight;\r
+ for (int res = groups[i].getStartRes();\r
+ res < groups[i].getEndRes() + 1; res++)\r
+ {\r
+ int alIndex = seq.findPosition(res);\r
+ Object obj = ResidueProperties.aa2Triplet.get(\r
+ seq.getCharAt(res) + "");\r
+ if (obj == null)\r
+ continue;\r
+\r
+ String triplet = obj.toString();\r
+\r
+ out.println(\r
+ "<area shape=\"rect\" coords=\""\r
+ + (idWidth + res * av.charWidth) + ","\r
+ + sy + ","\r
+ + (idWidth + (res + 1) * av.charWidth) + ","\r
+ + (av.charHeight + sy) + "\""\r
+ + " onMouseOver=\"toolTip('"\r
+ + alIndex + " " + triplet +\r
+ "<br><em>" + groups[i].getName() +\r
+ "</em>')\"; onMouseOut=\"toolTip()\"; "\r
+ + " href=\"#\">");\r
+ }\r
+ }\r
+ }\r
+\r
+ out.println("</map></body></html>");\r
+ out.close();\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }///////////END OF IMAGE MAP\r
+\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void makePNG(File pngFile)\r
+ {\r
+ if(pngFile==null)\r
+ {\r
+ jalview.io.JalviewFileChooser chooser = new jalview.io.\r
+ JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[]\r
+ {"png"},\r
+ new String[]\r
+ {"Portable network graphics"},\r
+ "Portable network graphics");\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Create EPS file from alignment");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+\r
+ if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ return;\r
+ }\r
+\r
+ pngFile = chooser.getSelectedFile();\r
+\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+ chooser.getSelectedFile().getParent());\r
+ }\r
+\r
+\r
+\r
+ int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;\r
+ int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) *\r
+ av.chunkHeight;\r
+ width = seqPanel.getWidth() + idPanel.getWidth();\r
+\r
+ }\r
+\r
+\r
+ if (av.getShowAnnotation())\r
+ {\r
+ height += annotationPanel.getPreferredSize().height;\r
+ }\r
+\r
+ try\r
+ {\r
+\r
+ FileOutputStream out = new FileOutputStream(pngFile);\r
+\r
+ BufferedImage bi = new BufferedImage(width, height,\r
+ BufferedImage.TYPE_INT_RGB);\r
+ Graphics2D png = (Graphics2D) bi.getGraphics();\r
+\r
+ png.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+ RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ printWrappedAlignment(png, width, height, 0);\r
+ }\r
+ else\r
+ {\r
+ printUnwrapped(png, width, height, 0);\r
+ }\r
+\r
+ ImageIO.write(bi, "png", out);\r
+ out.close();\r
+ }\r
+ catch(OutOfMemoryError err)\r
+ {\r
+ System.out.println("########################\n"\r
+ +"OUT OF MEMORY "+pngFile+"\n"\r
+ +"########################");\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+class Preview extends JFrame\r
+{\r
+ /**\r
+ * Creates a new Preview object.\r
+ *\r
+ * @param image DOCUMENT ME!\r
+ */\r
+ public Preview(Image image)\r
+ {\r
+ setResizable(true);\r
+ setSize(image.getWidth(this), image.getHeight(this));\r
+ setVisible(true);\r
+ getContentPane().setLayout(new BorderLayout());\r
+ getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);\r
+ validate();\r
+ repaint();\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+class PreviewPanel extends JPanel\r
+{\r
+ Image image;\r
+\r
+ /**\r
+ * Creates a new PreviewPanel object.\r
+ *\r
+ * @param image DOCUMENT ME!\r
+ */\r
+ public PreviewPanel(Image image)\r
+ {\r
+ this.image = image;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param g DOCUMENT ME!\r
+ */\r
+ public void paintComponent(Graphics g)\r
+ {\r
+ if (image != null)\r
+ {\r
+ g.drawImage(image, 0, 0, this);\r
+ }\r
+ else\r
+ {\r
+ System.out.println("DEBUG:image is null");\r
+ }\r
+ }\r