+ ypos += cHeight;\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
+ }\r
+ else\r
+ {\r
+ return Printable.NO_SUCH_PAGE;\r
+ }\r
+ }\r
+\r
+ int getVisibleIdWidth()\r
+ {\r
+ return\r
+ idPanel.getWidth() > 0 ? idPanel.getWidth() :\r
+ calculateIdWidth().width + 4;\r
+ }\r
+\r
+ void makeAlignmentImage(int type, File file)\r
+ {\r
+ int maxwidth = av.alignment.getWidth();\r
+ if (av.hasHiddenColumns)\r
+ {\r
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);\r
+ }\r
+\r
+ int height = ( (av.alignment.getHeight() + 1) * av.charHeight)\r
+ + scalePanel.getHeight();\r
+ int width = getVisibleIdWidth() + (maxwidth * av.charWidth);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ height = getWrappedHeight();\r
+ if (System.getProperty("java.awt.headless") != null\r
+ && System.getProperty("java.awt.headless").equals("true"))\r
+ {\r
+ width = alignFrame.getWidth()\r
+ - vscroll.getPreferredSize().width\r
+ - alignFrame.getInsets().left\r
+ - alignFrame.getInsets().right;\r
+ }\r
+ else\r
+ {\r
+ width = seqPanel.getWidth() + getVisibleIdWidth();\r
+ }\r
+\r
+ }\r
+ else if (av.getShowAnnotation())\r
+ {\r
+ height += annotationPanel.adjustPanelHeight() + 3;\r
+ }\r
+\r
+ try\r
+ {\r
+\r
+ jalview.util.ImageMaker im;\r
+ if (type == jalview.util.ImageMaker.PNG)\r
+ {\r
+ im = new jalview.util.ImageMaker(this,\r
+ jalview.util.ImageMaker.PNG,\r
+ "Create PNG image from alignment",\r
+ width, height, file, null);\r
+ }\r
+ else\r
+ {\r
+ im = new jalview.util.ImageMaker(this,\r
+ jalview.util.ImageMaker.EPS,\r
+ "Create EPS file from alignment",\r
+ width, height, file,\r
+ alignFrame.getTitle());\r
+ }\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ if (im.getGraphics() != null)\r
+ {\r
+ printWrappedAlignment(im.getGraphics(), width, height, 0);\r
+ im.writeImage();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (im.getGraphics() != null)\r
+ {\r
+ printUnwrapped(im.getGraphics(), width, height, 0);\r
+ im.writeImage();\r
+ }\r
+ }\r
+ }\r
+ catch (OutOfMemoryError err)\r
+ {\r
+ System.out.println("########################\n"\r
+ + "OUT OF MEMORY " + file + "\n"\r
+ + "########################");\r
+\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Out of Memory Creating Image!!"\r
+ +\r
+ "\nSee help files for increasing Java Virtual Machine memory."\r
+ , "Out of memory",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ System.out.println("Create IMAGE: " + err);\r
+ System.gc();\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void makeEPS(File epsFile)\r
+ {\r
+ makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void makePNG(File pngFile)\r
+ {\r
+ makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);\r
+ }\r
+\r
+ public void makePNGImageMap(File imgMapFile, String imageName)\r
+ {\r
+ ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS\r
+ //////////////////////////////////////////////\r
+ int idWidth = getVisibleIdWidth();\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
+ int s, sSize = av.alignment.getHeight(),\r
+ res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;\r
+ StringBuffer text = new StringBuffer();\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 (s = 0; s < sSize; s++)\r
+ {\r
+ sy = s * av.charHeight + scaleHeight;\r
+\r
+ SequenceI seq = av.alignment.getSequenceAt(s);\r
+ SequenceFeature[] features = seq.getDatasetSequence().\r
+ getSequenceFeatures();\r
+ SequenceGroup[] groups = av.alignment.findAllGroups(seq);\r
+ for (res = 0; res < alwidth; res++)\r
+ {\r
+ text = new StringBuffer();\r
+ Object obj = null;\r
+ if (av.alignment.isNucleotide())\r
+ {\r
+ obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res) +\r
+ "");\r
+ }\r
+ else\r
+ {\r
+ obj = ResidueProperties.aa2Triplet.get(\r
+ seq.getCharAt(res) + "");\r
+ }\r
+\r
+ if (obj == null)\r
+ {\r
+ continue;\r
+ }\r
+\r
+ String triplet = obj.toString();\r
+ int alIndex = seq.findPosition(res);\r
+ gSize = groups.length;\r
+ for (g = 0; g < gSize; g++)\r
+ {\r
+ if (text.length() < 1)\r
+ {\r
+ text.append("<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
+ }\r
+\r
+ if (groups[g].getStartRes() < res && groups[g].getEndRes() > res)\r
+ {\r
+ text.append("<br><em>" + groups[g].getName() + "</em>");\r
+ }\r
+ }\r
+\r
+ if (features != null)\r
+ {\r
+ if (text.length() < 1)\r
+ {\r
+ text.append("<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
+ }\r
+ fSize = features.length;\r
+ for (f = 0; f < fSize; f++)\r
+ {\r
+\r
+ if ( (features[f].getBegin() <= seq.findPosition(res)) &&\r
+ (features[f].getEnd() >= seq.findPosition(res)))\r
+ {\r
+ if (features[f].getType().equals("disulfide bond"))\r
+ {\r
+ if (features[f].getBegin() == seq.findPosition(res)\r
+ || features[f].getEnd() == seq.findPosition(res))\r
+ {\r
+ text.append("<br>disulfide bond " + features[f].getBegin() +\r
+ ":" +\r
+ features[f].getEnd());\r
+ }\r
+ }\r
+ else\r
+ {\r
+ text.append("<br>");\r
+ text.append(features[f].getType());\r
+ if (features[f].getDescription() != null &&\r
+ !features[f].\r
+ getType().equals(features[f].getDescription()))\r
+ {\r
+ text.append(" " + features[f].getDescription());\r
+ }\r
+\r
+ if (features[f].getValue("status") != null)\r
+ {\r
+ text.append(" (" + features[f].getValue("status") + ")");\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+ }\r
+ if (text.length() > 1)\r
+ {\r
+ text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");\r
+ out.println(text.toString());\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
+ int getWrappedHeight()\r
+ {\r
+ int seqPanelWidth = seqPanel.seqCanvas.getWidth();\r
+\r
+ if (System.getProperty("java.awt.headless") != null\r
+ && System.getProperty("java.awt.headless").equals("true"))\r
+ {\r
+ seqPanelWidth = alignFrame.getWidth()\r
+ - getVisibleIdWidth()\r
+ - vscroll.getPreferredSize().width\r
+ - alignFrame.getInsets().left\r
+ - alignFrame.getInsets().right;\r
+ }\r
+\r
+ int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(\r
+ seqPanelWidth\r
+ );\r
+\r
+ int hgap = av.charHeight;\r
+ if (av.scaleAboveWrapped)\r
+ {\r
+ hgap += av.charHeight;\r
+ }\r
+\r
+ int annotationHeight = 0;\r
+ if (av.showAnnotation)\r
+ {\r
+ annotationHeight = annotationPanel.adjustPanelHeight();\r
+ }\r
+\r
+ int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+ + hgap\r
+ + annotationHeight;\r
+\r
+ int maxwidth = av.alignment.getWidth();\r
+ if (av.hasHiddenColumns)\r
+ {\r
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;\r
+ }\r
+\r
+ int height = ( (maxwidth / chunkWidth) + 1) * cHeight;\r
+\r
+ return height;\r
+ }\r
+}\r