2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.jbgui.*;
\r
25 import jalview.schemes.*;
\r
27 import org.jibble.epsgraphics.*;
\r
30 import java.awt.event.*;
\r
31 import java.awt.image.*;
\r
32 import java.awt.print.*;
\r
36 import javax.imageio.*;
\r
38 import javax.swing.*;
\r
45 * @version $Revision$
\r
47 public class AlignmentPanel extends GAlignmentPanel
\r
48 implements AdjustmentListener, Printable
\r
50 public AlignViewport av;
\r
51 OverviewPanel overviewPanel;
\r
54 IdwidthAdjuster idwidthAdjuster;
\r
56 /** DOCUMENT ME!! */
\r
57 public AlignFrame alignFrame;
\r
58 ScalePanel scalePanel;
\r
59 AnnotationPanel annotationPanel;
\r
60 AnnotationLabels alabels;
\r
62 // this value is set false when selection area being dragged
\r
63 boolean fastPaint = true;
\r
68 * Creates a new AlignmentPanel object.
\r
70 * @param af DOCUMENT ME!
\r
71 * @param av DOCUMENT ME!
\r
73 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
77 seqPanel = new SeqPanel(av, this);
\r
78 idPanel = new IdPanel(av, this);
\r
80 scalePanel = new ScalePanel(av, this);
\r
82 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
83 idwidthAdjuster = new IdwidthAdjuster(this);
\r
84 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
86 annotationPanel = new AnnotationPanel(this);
\r
87 alabels = new AnnotationLabels(this);
\r
89 annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize());
\r
90 annotationScroller.setPreferredSize(annotationPanel.getPreferredSize());
\r
91 annotationScroller.setViewportView(annotationPanel);
\r
92 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
96 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
97 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
99 setScrollValues(0, 0);
\r
101 hscroll.addAdjustmentListener(this);
\r
102 vscroll.addAdjustmentListener(this);
\r
104 setFocusable(true);
\r
105 addKeyListener(new KeyAdapter()
\r
107 public void keyPressed(KeyEvent evt)
\r
109 switch (evt.getKeyCode())
\r
111 case 27: // escape key
\r
112 av.setSelectionGroup(null);
\r
117 case KeyEvent.VK_DOWN:
\r
118 alignFrame.moveSelectedSequences(false);
\r
122 case KeyEvent.VK_UP:
\r
123 alignFrame.moveSelectedSequences(true);
\r
127 case KeyEvent.VK_BACK_SPACE:
\r
128 case KeyEvent.VK_DELETE:
\r
129 alignFrame.cut_actionPerformed(null);
\r
141 public void fontChanged()
\r
143 // set idCanvas bufferedImage to null
\r
144 // to prevent drawing old image
\r
145 FontMetrics fm = getFontMetrics(av.getFont());
\r
147 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
148 av.charHeight + fm.getDescent()));
\r
149 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
150 av.charHeight + fm.getDescent()));
\r
152 idPanel.idCanvas.gg = null;
\r
153 seqPanel.seqCanvas.img = null;
\r
154 annotationPanel.adjustPanelHeight();
\r
156 Dimension d = calculateIdWidth();
\r
157 d.setSize(d.width + 4, d.height);
\r
158 idPanel.idCanvas.setPreferredSize(d);
\r
159 hscrollFillerPanel.setPreferredSize(d);
\r
161 if (av.getWrapAlignment())
\r
163 int max = av.alignment.getWidth() /
\r
164 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
165 vscroll.setMaximum(max);
\r
166 vscroll.setUnitIncrement(1);
\r
167 vscroll.setVisibleAmount(1);
\r
171 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
174 if(overviewPanel!=null)
\r
175 overviewPanel.setBoxPosition();
\r
183 * @return DOCUMENT ME!
\r
185 public Dimension calculateIdWidth()
\r
187 Container c = new Container();
\r
189 FontMetrics fm = c.getFontMetrics(av.font);
\r
190 AlignmentI al = av.getAlignment();
\r
196 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
198 SequenceI s = al.getSequenceAt(i);
\r
200 if (av.getShowFullId())
\r
202 id = s.getDisplayId();
\r
209 if (fm.stringWidth(id) > idWidth)
\r
211 idWidth = fm.stringWidth(id);
\r
217 // Also check annotation label widths
\r
220 if (al.getAlignmentAnnotation() != null)
\r
222 fm = c.getFontMetrics(alabels.getFont());
\r
224 while (i < al.getAlignmentAnnotation().length)
\r
226 String label = al.getAlignmentAnnotation()[i].label;
\r
228 if (fm.stringWidth(label) > idWidth)
\r
230 idWidth = fm.stringWidth(label);
\r
237 return new Dimension(idWidth, 12);
\r
243 * @param results DOCUMENT ME!
\r
245 public void highlightSearchResults(int[] results)
\r
247 seqPanel.seqCanvas.highlightSearchResults(results);
\r
249 // do we need to scroll the panel?
\r
250 if (results != null)
\r
252 SequenceI seq = av.alignment.getSequenceAt(results[0]);
\r
253 int start = seq.findIndex(results[1]) - 1;
\r
254 int end = seq.findIndex(results[2]) - 1;
\r
256 if ((av.getStartRes() > start) || (av.getEndRes() < end) ||
\r
257 ((av.getStartSeq() > results[0]) ||
\r
258 (av.getEndSeq() < results[0])))
\r
260 setScrollValues(start, results[0]);
\r
268 * @return DOCUMENT ME!
\r
270 public OverviewPanel getOverviewPanel()
\r
272 return overviewPanel;
\r
278 * @param op DOCUMENT ME!
\r
280 public void setOverviewPanel(OverviewPanel op)
\r
282 overviewPanel = op;
\r
288 * @param b DOCUMENT ME!
\r
290 public void setAnnotationVisible(boolean b)
\r
292 if (!av.wrapAlignment)
\r
294 annotationSpaceFillerHolder.setVisible(b);
\r
295 annotationScroller.setVisible(b);
\r
302 * @param wrap DOCUMENT ME!
\r
304 public void setWrapAlignment(boolean wrap)
\r
307 scalePanelHolder.setVisible(!wrap);
\r
308 hscroll.setVisible(!wrap);
\r
309 idwidthAdjuster.setVisible(!wrap);
\r
313 annotationScroller.setVisible(false);
\r
314 annotationSpaceFillerHolder.setVisible(false);
\r
316 else if(av.showAnnotation)
\r
318 annotationScroller.setVisible(true);
\r
319 annotationSpaceFillerHolder.setVisible(true);
\r
322 idSpaceFillerPanel1.setVisible(!wrap);
\r
328 // return value is true if the scroll is valid
\r
329 public boolean scrollUp(boolean up)
\r
333 if (vscroll.getValue() < 1)
\r
339 vscroll.setValue(vscroll.getValue() - 1);
\r
343 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
349 vscroll.setValue(vscroll.getValue() + 1);
\r
360 * @param right DOCUMENT ME!
\r
362 * @return DOCUMENT ME!
\r
364 public boolean scrollRight(boolean right)
\r
368 if (hscroll.getValue() < 1)
\r
374 hscroll.setValue(hscroll.getValue() - 1);
\r
378 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
384 hscroll.setValue(hscroll.getValue() + 1);
\r
395 * @param x DOCUMENT ME!
\r
396 * @param y DOCUMENT ME!
\r
398 public void setScrollValues(int x, int y)
\r
400 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) -
\r
403 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
404 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
406 if (hextent > av.alignment.getWidth())
\r
408 hextent = av.alignment.getWidth();
\r
411 if (vextent > av.alignment.getHeight())
\r
413 vextent = av.alignment.getHeight();
\r
416 if ((hextent + x) > av.getAlignment().getWidth())
\r
418 x = av.getAlignment().getWidth() - hextent;
\r
421 if ((vextent + y) > av.getAlignment().getHeight())
\r
423 y = av.getAlignment().getHeight() - vextent;
\r
436 hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth());
\r
437 vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight());
\r
444 * @param evt DOCUMENT ME!
\r
446 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
449 int oldX = av.getStartRes();
\r
450 int oldY = av.getStartSeq();
\r
452 if (evt.getSource() == hscroll)
\r
454 int x = hscroll.getValue();
\r
457 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
460 if (evt.getSource() == vscroll)
\r
462 int offy = vscroll.getValue();
\r
464 if (av.getWrapAlignment())
\r
466 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
467 av.setStartRes(vscroll.getValue() * rowSize);
\r
468 av.setEndRes((vscroll.getValue() + 1) * rowSize);
\r
472 av.setStartSeq(offy);
\r
473 av.setEndSeq(offy +
\r
474 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
478 if (overviewPanel != null)
\r
480 overviewPanel.setBoxPosition();
\r
483 int xShift = av.getStartRes() - oldX;
\r
484 int yShift = av.getStartSeq() - oldY;
\r
486 if ( (xShift != 0 && yShift != 0) ||
\r
487 (Math.abs(xShift) > av.getEndRes() - av.getStartRes()
\r
488 || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq())
\r
489 || av.getWrapAlignment()
\r
492 // Either no shift at all, or shift greater than visible amount
\r
497 idPanel.idCanvas.fastPaint(yShift);
\r
498 seqPanel.seqCanvas.fastPaint(xShift, yShift);
\r
500 scalePanel.repaint();
\r
502 if (av.getShowAnnotation())
\r
504 annotationPanel.fastPaint(xShift);
\r
512 * @param g DOCUMENT ME!
\r
514 public void paintComponent(Graphics g)
\r
518 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
519 idPanelHolder.setPreferredSize(d);
\r
520 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
523 if (av.getWrapAlignment())
\r
525 int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
526 vscroll.setMaximum(max);
\r
527 vscroll.setUnitIncrement(1);
\r
528 vscroll.setVisibleAmount(1);
\r
532 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
539 * @param pg DOCUMENT ME!
\r
540 * @param pf DOCUMENT ME!
\r
541 * @param pi DOCUMENT ME!
\r
543 * @return DOCUMENT ME!
\r
545 * @throws PrinterException DOCUMENT ME!
\r
547 public int print(Graphics pg, PageFormat pf, int pi)
\r
548 throws PrinterException
\r
550 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
\r
552 int pwidth = (int) pf.getImageableWidth();
\r
553 int pheight = (int) pf.getImageableHeight();
\r
555 if (av.getWrapAlignment())
\r
557 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
561 return printUnwrapped(pg, pwidth, pheight, pi);
\r
568 * @param pg DOCUMENT ME!
\r
569 * @param pwidth DOCUMENT ME!
\r
570 * @param pheight DOCUMENT ME!
\r
571 * @param pi DOCUMENT ME!
\r
573 * @return DOCUMENT ME!
\r
575 * @throws PrinterException DOCUMENT ME!
\r
577 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
578 throws PrinterException
\r
580 int idWidth = calculateIdWidth().width + 4;
\r
581 FontMetrics fm = getFontMetrics(av.getFont());
\r
582 int scaleHeight = av.charHeight + fm.getDescent();
\r
584 pg.setColor(Color.white);
\r
585 pg.fillRect(0, 0, pwidth, pheight);
\r
586 pg.setFont(av.getFont());
\r
588 ////////////////////////////////////
\r
589 /// How many sequences and residues can we fit on a printable page?
\r
590 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
592 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) -
\r
595 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
597 /////////////////////////////
\r
598 /// Only print these sequences and residues on this page
\r
601 /////////////////////////////
\r
602 /// Only print these sequences and residues on this page
\r
605 /////////////////////////////
\r
606 /// Only print these sequences and residues on this page
\r
609 /////////////////////////////
\r
610 /// Only print these sequences and residues on this page
\r
612 startRes = (pi % pagesWide) * totalRes;
\r
613 endRes = (startRes + totalRes) - 1;
\r
615 if (endRes > (av.getAlignment().getWidth() - 1))
\r
617 endRes = av.getAlignment().getWidth() - 1;
\r
620 startSeq = (pi / pagesWide) * totalSeq;
\r
621 endSeq = startSeq + totalSeq;
\r
623 if (endSeq > av.getAlignment().getHeight())
\r
625 endSeq = av.getAlignment().getHeight();
\r
628 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
630 if (av.showAnnotation)
\r
632 pagesHigh += annotationPanel.adjustPanelHeight()+3;
\r
635 pagesHigh /= pheight;
\r
637 if (pi >= (pagesWide * pagesHigh))
\r
639 return Printable.NO_SUCH_PAGE;
\r
643 pg.translate(idWidth, 0);
\r
644 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
645 pg.translate(-idWidth, scaleHeight);
\r
649 Color currentColor = null;
\r
650 Color currentTextColor = null;
\r
652 for (int i = startSeq; i < endSeq; i++)
\r
654 if ((av.getSelectionGroup() != null) &&
\r
655 av.getSelectionGroup().sequences.contains(
\r
656 av.getAlignment().getSequenceAt(i)))
\r
658 currentColor = Color.gray;
\r
659 currentTextColor = Color.black;
\r
663 currentColor = av.getAlignment().getSequenceAt(i).getColor();
\r
664 currentTextColor = Color.black;
\r
667 pg.setColor(currentColor);
\r
668 pg.fillRect(0, (i-startSeq) * av.charHeight, idWidth,
\r
669 av.getCharHeight());
\r
671 pg.setColor(currentTextColor);
\r
673 String string = av.getAlignment().getSequenceAt(i).getName();
\r
675 if (av.getShowFullId())
\r
677 string = av.getAlignment().getSequenceAt(i).getDisplayId();
\r
680 pg.drawString(string, 0,
\r
681 (((i-startSeq) * av.charHeight) + av.getCharHeight()) -
\r
682 (av.getCharHeight() / 5));
\r
685 // draw main sequence panel
\r
686 pg.translate(idWidth, 0);
\r
687 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq,
\r
688 startRes, startSeq, 0);
\r
690 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
692 pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3);
\r
693 alabels.drawComponent((Graphics2D) pg);
\r
694 pg.translate(idWidth, 0);
\r
695 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes +
\r
699 return Printable.PAGE_EXISTS;
\r
705 * @param pg DOCUMENT ME!
\r
706 * @param pwidth DOCUMENT ME!
\r
707 * @param pheight DOCUMENT ME!
\r
708 * @param pi DOCUMENT ME!
\r
710 * @return DOCUMENT ME!
\r
712 * @throws PrinterException DOCUMENT ME!
\r
714 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
715 int pi) throws PrinterException
\r
718 int annotationHeight = 0;
\r
719 if (av.showAnnotation)
\r
720 annotationHeight = annotationPanel.adjustPanelHeight();
\r
722 int hgap = av.charHeight;
\r
723 if (av.scaleAboveWrapped)
\r
724 hgap += av.charHeight;
\r
726 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
728 + annotationHeight;
\r
731 int idWidth = calculateIdWidth().width + 4;
\r
733 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
736 int totalHeight = cHeight * (av.alignment.getWidth() / resWidth +1);
\r
738 pg.setColor(Color.white);
\r
739 pg.fillRect(0, 0, pwidth, pheight);
\r
740 pg.setFont(av.getFont());
\r
745 pg.setColor(Color.black);
\r
747 pg.translate(0, -pi * pheight);
\r
749 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
755 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
757 SequenceI s = av.alignment.getSequenceAt(i);
\r
758 String string = s.getName();
\r
760 if (av.getShowFullId())
\r
762 string = s.getDisplayId();
\r
765 pg.drawString(string, 0,
\r
766 ((i * av.charHeight) + ypos + av.charHeight) -
\r
767 (av.charHeight / 5));
\r
772 while (ypos < totalHeight);
\r
774 pg.translate(idWidth, 0);
\r
776 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
778 if ((pi * pheight) < totalHeight)
\r
780 return Printable.PAGE_EXISTS;
\r
785 return Printable.NO_SUCH_PAGE;
\r
792 public void makeEPS(File epsFile)
\r
794 boolean accurateText = true;
\r
796 String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING",
\r
797 "Prompt each time");
\r
799 // If we need to prompt, and if the GUI is visible then
\r
800 // Prompt for EPS rendering style
\r
801 if (renderStyle.equalsIgnoreCase("Prompt each time")
\r
803 (System.getProperty("java.awt.headless") != null
\r
804 && System.getProperty("java.awt.headless").equals("true")))
\r
806 EPSOptions eps = new EPSOptions();
\r
807 renderStyle = eps.getValue();
\r
809 if(eps.cancelled || renderStyle==null)
\r
812 renderStyle = eps.getValue();
\r
815 if (renderStyle.equalsIgnoreCase("text"))
\r
817 accurateText = false;
\r
821 if(epsFile == null)
\r
823 jalview.io.JalviewFileChooser chooser = new jalview.io.
\r
824 JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
825 "LAST_DIRECTORY"), new String[]
\r
828 {"Encapsulated Postscript"},
\r
829 "Encapsulated Postscript");
\r
830 chooser.setFileView(new jalview.io.JalviewFileView());
\r
831 chooser.setDialogTitle("Create EPS file from alignment");
\r
832 chooser.setToolTipText("Save");
\r
834 int value = chooser.showSaveDialog(this);
\r
836 if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
\r
841 epsFile = chooser.getSelectedFile();
\r
843 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
844 chooser.getSelectedFile().getParent());
\r
848 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
849 int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
\r
852 if (av.getWrapAlignment())
\r
854 height = getWrappedHeight();
\r
855 width = seqPanel.getWidth() + idPanel.getWidth();
\r
857 else if (av.getShowAnnotation())
\r
859 height += annotationPanel.adjustPanelHeight()+3;
\r
865 FileOutputStream out = new FileOutputStream(epsFile);
\r
866 EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width,
\r
869 pg.setAccurateTextMode(accurateText);
\r
871 if (av.getWrapAlignment())
\r
873 printWrappedAlignment(pg, width, height, 0);
\r
877 printUnwrapped(pg, width, height, 0);
\r
883 catch (OutOfMemoryError err)
\r
885 System.out.println("########################\n"
\r
886 + "OUT OF MEMORY " + epsFile + "\n"
\r
887 + "########################");
\r
889 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
890 "Out of memory creating EPS file!!"
\r
892 "\nSee help files for increasing Java Virtual Machine memory."
\r
894 JOptionPane.WARNING_MESSAGE);
\r
895 System.out.println("Create EPS: " + err);
\r
898 catch (Exception ex)
\r
900 ex.printStackTrace();
\r
905 public void makePNGImageMap(File imgMapFile, String imageName)
\r
907 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
908 //////////////////////////////////////////////
\r
909 int idWidth = calculateIdWidth().width + 4;
\r
910 FontMetrics fm = getFontMetrics(av.getFont());
\r
911 int scaleHeight = av.charHeight + fm.getDescent();
\r
914 //////////////////////////////////
\r
915 if(imgMapFile!=null)
\r
919 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
920 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
921 out.println("<img src=\"" + imageName +
\r
922 "\" border=\"0\" usemap=\"#Map\" >"
\r
923 +"<map name=\"Map\">");
\r
925 for (int s = 0; s < av.alignment.getHeight(); s++)
\r
927 SequenceI seq = av.alignment.getSequenceAt(s);
\r
928 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
929 for (int i = 0; i < groups.length; i++)
\r
931 int sy = s * av.charHeight + scaleHeight;
\r
932 for (int res = groups[i].getStartRes();
\r
933 res < groups[i].getEndRes() + 1; res++)
\r
935 int alIndex = seq.findPosition(res);
\r
936 Object obj = ResidueProperties.aa2Triplet.get(
\r
937 seq.getCharAt(res) + "");
\r
941 String triplet = obj.toString();
\r
944 "<area shape=\"rect\" coords=\""
\r
945 + (idWidth + res * av.charWidth) + ","
\r
947 + (idWidth + (res + 1) * av.charWidth) + ","
\r
948 + (av.charHeight + sy) + "\""
\r
949 + " onMouseOver=\"toolTip('"
\r
950 + alIndex + " " + triplet +
\r
951 "<br><em>" + groups[i].getName() +
\r
952 "</em>')\"; onMouseOut=\"toolTip()\"; "
\r
958 out.println("</map></body></html>");
\r
962 catch (Exception ex)
\r
964 ex.printStackTrace();
\r
966 }///////////END OF IMAGE MAP
\r
970 int getWrappedHeight()
\r
973 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
974 seqPanel.seqCanvas.getWidth());
\r
976 int hgap = av.charHeight;
\r
977 if (av.scaleAboveWrapped)
\r
978 hgap += av.charHeight;
\r
980 int annotationHeight = 0;
\r
981 if (av.showAnnotation)
\r
983 annotationHeight = annotationPanel.adjustPanelHeight();
\r
986 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
988 + annotationHeight;
\r
991 int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight;
\r
999 public void makePNG(File pngFile)
\r
1003 jalview.io.JalviewFileChooser chooser = new jalview.io.
\r
1004 JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
1005 "LAST_DIRECTORY"), new String[]
\r
1008 {"Portable network graphics"},
\r
1009 "Portable network graphics");
\r
1010 chooser.setFileView(new jalview.io.JalviewFileView());
\r
1011 chooser.setDialogTitle("Create EPS file from alignment");
\r
1012 chooser.setToolTipText("Save");
\r
1014 int value = chooser.showSaveDialog(this);
\r
1016 if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)
\r
1021 pngFile = chooser.getSelectedFile();
\r
1023 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
1024 chooser.getSelectedFile().getParent());
\r
1029 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
1030 int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
\r
1032 if (av.getWrapAlignment())
\r
1034 height = getWrappedHeight();
\r
1035 width = seqPanel.getWidth() + idPanel.getWidth();
\r
1037 else if (av.getShowAnnotation())
\r
1039 height += annotationPanel.adjustPanelHeight()+3;
\r
1045 FileOutputStream out = new FileOutputStream(pngFile);
\r
1047 BufferedImage bi = new BufferedImage(width, height,
\r
1048 BufferedImage.TYPE_INT_RGB);
\r
1049 Graphics2D png = (Graphics2D) bi.getGraphics();
\r
1051 png.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
1052 RenderingHints.VALUE_ANTIALIAS_ON);
\r
1054 if (av.getWrapAlignment())
\r
1056 printWrappedAlignment(png, width, height, 0);
\r
1060 printUnwrapped(png, width, height, 0);
\r
1063 ImageIO.write(bi, "png", out);
\r
1066 catch (OutOfMemoryError err)
\r
1068 System.out.println("########################\n"
\r
1069 + "OUT OF MEMORY " + pngFile + "\n"
\r
1070 + "########################");
\r
1072 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1073 "Out of memory creating PNG!!"
\r
1075 "\nSee help files for increasing Java Virtual Machine memory."
\r
1076 , "Out of memory",
\r
1077 JOptionPane.WARNING_MESSAGE);
\r
1078 System.out.println("Create PNG: " + err);
\r
1082 catch (Exception ex)
\r
1084 ex.printStackTrace();
\r
1093 * @author $author$
\r
1094 * @version $Revision$
\r
1096 class Preview extends JFrame
\r
1099 * Creates a new Preview object.
\r
1101 * @param image DOCUMENT ME!
\r
1103 public Preview(Image image)
\r
1105 setResizable(true);
\r
1106 setSize(image.getWidth(this), image.getHeight(this));
\r
1108 getContentPane().setLayout(new BorderLayout());
\r
1109 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
\r
1119 * @author $author$
\r
1120 * @version $Revision$
\r
1122 class PreviewPanel extends JPanel
\r
1127 * Creates a new PreviewPanel object.
\r
1129 * @param image DOCUMENT ME!
\r
1131 public PreviewPanel(Image image)
\r
1133 this.image = image;
\r
1139 * @param g DOCUMENT ME!
\r
1141 public void paintComponent(Graphics g)
\r
1143 if (image != null)
\r
1145 g.drawImage(image, 0, 0, this);
\r
1149 System.out.println("DEBUG:image is null");
\r