+ av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) -\r
+ 1);\r
+\r
+ hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;\r
+ vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;\r
+\r
+ if (hextent > av.alignment.getWidth())\r
+ {\r
+ hextent = av.alignment.getWidth();\r
+ }\r
+\r
+ if (vextent > av.alignment.getHeight())\r
+ {\r
+ vextent = av.alignment.getHeight();\r
+ }\r
+\r
+ if ((hextent + x) > av.getAlignment().getWidth())\r
+ {\r
+ x = av.getAlignment().getWidth() - hextent;\r
+ }\r
+\r
+ if ((vextent + y) > av.getAlignment().getHeight())\r
+ {\r
+ y = av.getAlignment().getHeight() - vextent;\r
+ }\r
+\r
+ if (y < 0)\r
+ {\r
+ y = 0;\r
+ }\r
+\r
+ if (x < 0)\r
+ {\r
+ x = 0;\r
+ }\r
+\r
+ hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth());\r
+ vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight());\r
+ }\r
+\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void adjustmentValueChanged(AdjustmentEvent evt)\r
+ {\r
+\r
+ int oldX = av.getStartRes();\r
+ int oldY = av.getStartSeq();\r
+\r
+ if (evt.getSource() == hscroll)\r
+ {\r
+ int x = hscroll.getValue();\r
+ av.setStartRes(x);\r
+ av.setEndRes((x +\r
+ (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);\r
+ }\r
+\r
+ if (evt.getSource() == vscroll)\r
+ {\r
+ int offy = vscroll.getValue();\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());\r
+ av.setStartRes(vscroll.getValue() * rowSize);\r
+ av.setEndRes((vscroll.getValue() + 1) * rowSize);\r
+ }\r
+ else\r
+ {\r
+ av.setStartSeq(offy);\r
+ av.setEndSeq(offy +\r
+ (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));\r
+ }\r
+ }\r
+\r
+ if (overviewPanel != null)\r
+ {\r
+ overviewPanel.setBoxPosition();\r
+ }\r
+\r
+ int xShift = av.getStartRes() - oldX;\r
+ int yShift = av.getStartSeq() - oldY;\r
+\r
+ if ( (xShift == 0 && yShift == 0) ||\r
+ (Math.abs(xShift) > av.getEndRes() - av.getStartRes()\r
+ || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq())\r
+ || av.getWrapAlignment()\r
+ || !fastPaint)\r
+ {\r
+ // Either no shift at all, or shift greater than visible amount\r
+ repaint();\r
+ }\r
+ else\r
+ {\r
+ idPanel.idCanvas.fastPaint(yShift);\r
+ seqPanel.seqCanvas.fastPaint(xShift, yShift);\r
+\r
+ scalePanel.repaint();\r
+\r
+ if (av.getShowAnnotation())\r
+ {\r
+ annotationPanel.fastPaint(xShift);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param g DOCUMENT ME!\r
+ */\r
+ public void paintComponent(Graphics g)\r
+ {\r
+ invalidate();\r
+\r
+ Dimension d = idPanel.idCanvas.getPreferredSize();\r
+ idPanelHolder.setPreferredSize(d);\r
+ hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));\r
+ validate();\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());\r
+ vscroll.setMaximum(max);\r
+ vscroll.setUnitIncrement(1);\r
+ vscroll.setVisibleAmount(1);\r
+ }\r
+ else\r
+ {\r
+ setScrollValues(av.getStartRes(), av.getStartSeq());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param pg DOCUMENT ME!\r
+ * @param pf DOCUMENT ME!\r
+ * @param pi DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ *\r
+ * @throws PrinterException DOCUMENT ME!\r
+ */\r
+ public int print(Graphics pg, PageFormat pf, int pi)\r
+ throws PrinterException\r
+ {\r
+ pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());\r
+\r
+ int pwidth = (int) pf.getImageableWidth();\r
+ int pheight = (int) pf.getImageableHeight();\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ return printWrappedAlignment(pg, pwidth, pheight, pi);\r
+ }\r
+ else\r
+ {\r
+ return printUnwrapped(pg, pwidth, pheight, pi);\r
+ }\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 printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)\r
+ throws PrinterException\r
+ {\r
+ int idWidth = calculateIdWidth().width + 4;\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+ int scaleHeight = av.charHeight + fm.getDescent();\r
+\r
+ pg.setColor(Color.white);\r
+ pg.fillRect(0, 0, pwidth, pheight);\r
+ pg.setFont(av.getFont());\r
+\r
+ ////////////////////////////////////\r
+ /// How many sequences and residues can we fit on a printable page?\r
+ int totalRes = (pwidth - idWidth) / av.getCharWidth();\r
+\r
+ int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) -\r
+ 1;\r
+\r
+ int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;\r
+\r
+ /////////////////////////////\r
+ /// Only print these sequences and residues on this page\r
+ int startRes;\r
+\r
+ /////////////////////////////\r
+ /// Only print these sequences and residues on this page\r
+ int endRes;\r
+\r
+ /////////////////////////////\r
+ /// Only print these sequences and residues on this page\r
+ int startSeq;\r
+\r
+ /////////////////////////////\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