2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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 java.beans.*;
\r
25 import java.awt.event.*;
\r
26 import java.awt.print.*;
\r
27 import javax.swing.*;
\r
29 import jalview.datamodel.*;
\r
30 import jalview.jbgui.*;
\r
31 import jalview.schemes.*;
\r
37 * @version $Revision$
\r
39 public class AlignmentPanel
\r
40 extends GAlignmentPanel implements AdjustmentListener, Printable
\r
42 public AlignViewport av;
\r
43 OverviewPanel overviewPanel;
\r
46 IdwidthAdjuster idwidthAdjuster;
\r
48 /** DOCUMENT ME!! */
\r
49 public AlignFrame alignFrame;
\r
50 ScalePanel scalePanel;
\r
51 AnnotationPanel annotationPanel;
\r
52 AnnotationLabels alabels;
\r
54 // this value is set false when selection area being dragged
\r
55 boolean fastPaint = true;
\r
60 * Creates a new AlignmentPanel object.
\r
62 * @param af DOCUMENT ME!
\r
63 * @param av DOCUMENT ME!
\r
65 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
69 seqPanel = new SeqPanel(av, this);
\r
70 idPanel = new IdPanel(av, this);
\r
72 scalePanel = new ScalePanel(av, this);
\r
74 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
75 idwidthAdjuster = new IdwidthAdjuster(this);
\r
76 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
78 annotationPanel = new AnnotationPanel(this);
\r
79 alabels = new AnnotationLabels(this);
\r
81 annotationScroller.setViewportView(annotationPanel);
\r
82 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
84 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
85 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
87 setScrollValues(0, 0);
\r
89 setAnnotationVisible(av.getShowAnnotation());
\r
91 hscroll.addAdjustmentListener(this);
\r
92 vscroll.addAdjustmentListener(this);
\r
94 final AlignmentPanel ap = this;
\r
95 av.addPropertyChangeListener(new PropertyChangeListener()
\r
97 public void propertyChange(PropertyChangeEvent evt)
\r
99 if (evt.getPropertyName().equals("alignment"))
\r
101 PaintRefresher.Refresh(ap,
\r
102 av.getSequenceSetId(),
\r
105 alignmentChanged();
\r
114 public void alignmentChanged()
\r
116 av.alignmentChanged(this);
\r
118 if (overviewPanel != null)
\r
120 overviewPanel.updateOverviewImage();
\r
123 alignFrame.updateEditMenuBar();
\r
131 public void fontChanged()
\r
133 // set idCanvas bufferedImage to null
\r
134 // to prevent drawing old image
\r
135 FontMetrics fm = getFontMetrics(av.getFont());
\r
137 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
138 av.charHeight + fm.getDescent()));
\r
139 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
140 av.charHeight + fm.getDescent()));
\r
142 idPanel.idCanvas.gg = null;
\r
143 seqPanel.seqCanvas.img = null;
\r
144 annotationPanel.adjustPanelHeight();
\r
146 Dimension d = calculateIdWidth();
\r
147 d.setSize(d.width + 4, d.height);
\r
148 idPanel.idCanvas.setPreferredSize(d);
\r
149 hscrollFillerPanel.setPreferredSize(d);
\r
151 if (overviewPanel != null)
\r
153 overviewPanel.setBoxPosition();
\r
162 * @return DOCUMENT ME!
\r
164 public Dimension calculateIdWidth()
\r
166 Container c = new Container();
\r
168 FontMetrics fm = c.getFontMetrics(
\r
169 new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));
\r
171 AlignmentI al = av.getAlignment();
\r
177 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
179 SequenceI s = al.getSequenceAt(i);
\r
181 id = s.getDisplayId(av.getShowJVSuffix());
\r
183 if (fm.stringWidth(id) > idWidth)
\r
185 idWidth = fm.stringWidth(id);
\r
191 // Also check annotation label widths
\r
194 if (al.getAlignmentAnnotation() != null)
\r
196 fm = c.getFontMetrics(alabels.getFont());
\r
198 while (i < al.getAlignmentAnnotation().length)
\r
200 String label = al.getAlignmentAnnotation()[i].label;
\r
202 if (fm.stringWidth(label) > idWidth)
\r
204 idWidth = fm.stringWidth(label);
\r
211 return new Dimension(idWidth, 12);
\r
217 * @param results DOCUMENT ME!
\r
219 public void highlightSearchResults(SearchResults results)
\r
221 seqPanel.seqCanvas.highlightSearchResults(results);
\r
223 // do we need to scroll the panel?
\r
224 if (results != null)
\r
226 SequenceI seq = results.getResultSequence(0);
\r
227 int seqIndex = av.alignment.findIndex(seq);
\r
228 int start = seq.findIndex(results.getResultStart(0)) - 1;
\r
229 int end = seq.findIndex(results.getResultEnd(0)) - 1;
\r
231 if (!av.wrapAlignment)
\r
233 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
\r
234 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
\r
236 setScrollValues(start, seqIndex);
\r
241 scrollToWrappedVisible(start);
\r
246 void scrollToWrappedVisible(int res)
\r
248 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
\r
250 if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
\r
252 vscroll.setValue(res / cwidth);
\r
253 av.startRes = vscroll.getValue() * cwidth;
\r
260 * @return DOCUMENT ME!
\r
262 public OverviewPanel getOverviewPanel()
\r
264 return overviewPanel;
\r
270 * @param op DOCUMENT ME!
\r
272 public void setOverviewPanel(OverviewPanel op)
\r
274 overviewPanel = op;
\r
280 * @param b DOCUMENT ME!
\r
282 public void setAnnotationVisible(boolean b)
\r
284 if (!av.wrapAlignment)
\r
286 annotationSpaceFillerHolder.setVisible(b);
\r
287 annotationScroller.setVisible(b);
\r
292 public void adjustAnnotationHeight()
\r
294 if (alignFrame.getHeight() == 0)
\r
296 System.out.println("NEEDS FIXING");
\r
299 int height = annotationPanel.adjustPanelHeight() +
\r
300 hscroll.getPreferredSize().height;
\r
302 if (height > alignFrame.getHeight() / 2)
\r
304 height = alignFrame.getHeight() / 2;
\r
307 hscroll.addNotify();
\r
309 annotationScroller.setPreferredSize(
\r
310 new Dimension(annotationScroller.getWidth(),
\r
311 height + hscroll.getHeight()));
\r
314 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
315 annotationSpaceFillerHolder.getWidth(),
\r
324 * @param wrap DOCUMENT ME!
\r
326 public void setWrapAlignment(boolean wrap)
\r
329 scalePanelHolder.setVisible(!wrap);
\r
330 hscroll.setVisible(!wrap);
\r
331 idwidthAdjuster.setVisible(!wrap);
\r
335 annotationScroller.setVisible(false);
\r
336 annotationSpaceFillerHolder.setVisible(false);
\r
338 else if (av.showAnnotation)
\r
340 annotationScroller.setVisible(true);
\r
341 annotationSpaceFillerHolder.setVisible(true);
\r
344 idSpaceFillerPanel1.setVisible(!wrap);
\r
349 // return value is true if the scroll is valid
\r
350 public boolean scrollUp(boolean up)
\r
354 if (vscroll.getValue() < 1)
\r
360 vscroll.setValue(vscroll.getValue() - 1);
\r
364 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
370 vscroll.setValue(vscroll.getValue() + 1);
\r
381 * @param right DOCUMENT ME!
\r
383 * @return DOCUMENT ME!
\r
385 public boolean scrollRight(boolean right)
\r
389 if (hscroll.getValue() < 1)
\r
395 hscroll.setValue(hscroll.getValue() - 1);
\r
399 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
405 hscroll.setValue(hscroll.getValue() + 1);
\r
416 * @param x DOCUMENT ME!
\r
417 * @param y DOCUMENT ME!
\r
419 public void setScrollValues(int x, int y)
\r
422 int width = av.alignment.getWidth();
\r
423 int height = av.alignment.getHeight();
\r
425 if (av.hasHiddenColumns)
\r
427 width = av.getColumnSelection().findColumnPosition(width);
\r
430 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
\r
432 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
433 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
435 if (hextent > width)
\r
440 if (vextent > height)
\r
445 if ( (hextent + x) > width)
\r
447 x = width - hextent;
\r
450 if ( (vextent + y) > height)
\r
452 y = height - vextent;
\r
465 hscroll.setValues(x, hextent, 0, width);
\r
466 vscroll.setValues(y, vextent, 0, height);
\r
472 * @param evt DOCUMENT ME!
\r
474 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
477 int oldX = av.getStartRes();
\r
478 int oldY = av.getStartSeq();
\r
480 if (evt.getSource() == hscroll)
\r
482 int x = hscroll.getValue();
\r
485 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
488 if (evt.getSource() == vscroll)
\r
490 int offy = vscroll.getValue();
\r
492 if (av.getWrapAlignment())
\r
496 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
497 seqCanvas.getWidth());
\r
498 av.setStartRes(offy * rowSize);
\r
499 av.setEndRes( (offy + 1) * rowSize);
\r
503 //This is only called if file loaded is a jar file that
\r
504 //was wrapped when saved and user has wrap alignment true
\r
505 //as preference setting
\r
506 SwingUtilities.invokeLater(new Runnable()
\r
510 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
517 av.setStartSeq(offy);
\r
518 av.setEndSeq(offy +
\r
519 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
523 if (overviewPanel != null)
\r
525 overviewPanel.setBoxPosition();
\r
528 int scrollX = av.startRes - oldX;
\r
529 int scrollY = av.startSeq - oldY;
\r
531 if (av.getWrapAlignment() || !fastPaint)
\r
537 // Make sure we're not trying to draw a panel
\r
538 // larger than the visible window
\r
539 if (scrollX > av.endRes - av.startRes)
\r
541 scrollX = av.endRes - av.startRes;
\r
543 else if (scrollX < av.startRes - av.endRes)
\r
545 scrollX = av.startRes - av.endRes;
\r
548 if (scrollX != 0 || scrollY != 0)
\r
550 idPanel.idCanvas.fastPaint(scrollY);
\r
551 seqPanel.seqCanvas.fastPaint(scrollX,
\r
553 scalePanel.repaint();
\r
555 if (av.getShowAnnotation())
\r
557 annotationPanel.fastPaint(scrollX);
\r
563 public void paintAlignment(boolean updateOverview)
\r
569 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
\r
570 .sequenceColoursChanged(this);
\r
572 if (overviewPanel != null)
\r
574 overviewPanel.updateOverviewImage();
\r
582 * @param g DOCUMENT ME!
\r
584 public void paintComponent(Graphics g)
\r
588 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
589 idPanelHolder.setPreferredSize(d);
\r
590 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
593 if (av.getWrapAlignment())
\r
595 int maxwidth = av.alignment.getWidth();
\r
597 if (av.hasHiddenColumns)
\r
599 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
602 int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
603 seqCanvas.getWidth());
\r
604 if (canvasWidth > 0)
\r
606 int max = maxwidth /
\r
607 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
\r
610 vscroll.setMaximum(max);
\r
611 vscroll.setUnitIncrement(1);
\r
612 vscroll.setVisibleAmount(1);
\r
617 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
624 * @param pg DOCUMENT ME!
\r
625 * @param pf DOCUMENT ME!
\r
626 * @param pi DOCUMENT ME!
\r
628 * @return DOCUMENT ME!
\r
630 * @throws PrinterException DOCUMENT ME!
\r
632 public int print(Graphics pg, PageFormat pf, int pi)
\r
633 throws PrinterException
\r
635 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
\r
637 int pwidth = (int) pf.getImageableWidth();
\r
638 int pheight = (int) pf.getImageableHeight();
\r
640 if (av.getWrapAlignment())
\r
642 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
646 return printUnwrapped(pg, pwidth, pheight, pi);
\r
653 * @param pg DOCUMENT ME!
\r
654 * @param pwidth DOCUMENT ME!
\r
655 * @param pheight DOCUMENT ME!
\r
656 * @param pi DOCUMENT ME!
\r
658 * @return DOCUMENT ME!
\r
660 * @throws PrinterException DOCUMENT ME!
\r
662 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
663 throws PrinterException
\r
665 int idWidth = getVisibleIdWidth();
\r
666 FontMetrics fm = getFontMetrics(av.getFont());
\r
667 int scaleHeight = av.charHeight + fm.getDescent();
\r
669 pg.setColor(Color.white);
\r
670 pg.fillRect(0, 0, pwidth, pheight);
\r
671 pg.setFont(av.getFont());
\r
673 ////////////////////////////////////
\r
674 /// How many sequences and residues can we fit on a printable page?
\r
675 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
677 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
\r
680 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
682 /////////////////////////////
\r
683 /// Only print these sequences and residues on this page
\r
686 /////////////////////////////
\r
687 /// Only print these sequences and residues on this page
\r
690 /////////////////////////////
\r
691 /// Only print these sequences and residues on this page
\r
694 /////////////////////////////
\r
695 /// Only print these sequences and residues on this page
\r
697 startRes = (pi % pagesWide) * totalRes;
\r
698 endRes = (startRes + totalRes) - 1;
\r
700 if (endRes > (av.getAlignment().getWidth() - 1))
\r
702 endRes = av.getAlignment().getWidth() - 1;
\r
705 startSeq = (pi / pagesWide) * totalSeq;
\r
706 endSeq = startSeq + totalSeq;
\r
708 if (endSeq > av.getAlignment().getHeight())
\r
710 endSeq = av.getAlignment().getHeight();
\r
713 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
715 if (av.showAnnotation)
\r
717 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
\r
720 pagesHigh /= pheight;
\r
722 if (pi >= (pagesWide * pagesHigh))
\r
724 return Printable.NO_SUCH_PAGE;
\r
728 pg.translate(idWidth, 0);
\r
729 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
730 pg.translate( -idWidth, scaleHeight);
\r
734 Color currentColor = null;
\r
735 Color currentTextColor = null;
\r
737 pg.setFont(idPanel.idCanvas.idfont);
\r
740 for (int i = startSeq; i < endSeq; i++)
\r
742 seq = av.getAlignment().getSequenceAt(i);
\r
743 if ( (av.getSelectionGroup() != null) &&
\r
744 av.getSelectionGroup().getSequences(null).contains(seq))
\r
746 currentColor = Color.gray;
\r
747 currentTextColor = Color.black;
\r
751 currentColor = av.getSequenceColour(seq);
\r
752 currentTextColor = Color.black;
\r
755 pg.setColor(currentColor);
\r
756 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
\r
757 av.getCharHeight());
\r
759 pg.setColor(currentTextColor);
\r
762 if (av.rightAlignIds)
\r
764 fm = pg.getFontMetrics();
\r
765 xPos = idWidth - fm.stringWidth(
\r
766 seq.getDisplayId(av.getShowJVSuffix())
\r
770 pg.drawString(seq.getDisplayId(av.getShowJVSuffix()),
\r
772 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
\r
773 (av.getCharHeight() / 5));
\r
776 pg.setFont(av.getFont());
\r
778 // draw main sequence panel
\r
779 pg.translate(idWidth, 0);
\r
780 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
\r
782 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
784 pg.translate( -idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
\r
785 alabels.drawComponent( (Graphics2D) pg, idWidth);
\r
786 pg.translate(idWidth + 3, 0);
\r
787 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
\r
791 return Printable.PAGE_EXISTS;
\r
797 * @param pg DOCUMENT ME!
\r
798 * @param pwidth DOCUMENT ME!
\r
799 * @param pheight DOCUMENT ME!
\r
800 * @param pi DOCUMENT ME!
\r
802 * @return DOCUMENT ME!
\r
804 * @throws PrinterException DOCUMENT ME!
\r
806 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
808 throws PrinterException
\r
811 int annotationHeight = 0;
\r
812 AnnotationLabels labels = null;
\r
813 if (av.showAnnotation)
\r
815 annotationHeight = annotationPanel.adjustPanelHeight();
\r
816 labels = new AnnotationLabels(av);
\r
819 int hgap = av.charHeight;
\r
820 if (av.scaleAboveWrapped)
\r
822 hgap += av.charHeight;
\r
825 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
827 + annotationHeight;
\r
829 int idWidth = getVisibleIdWidth();
\r
831 int maxwidth = av.alignment.getWidth();
\r
832 if (av.hasHiddenColumns)
\r
834 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
837 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
840 int totalHeight = cHeight * (maxwidth / resWidth + 1);
\r
842 pg.setColor(Color.white);
\r
843 pg.fillRect(0, 0, pwidth, pheight);
\r
844 pg.setFont(av.getFont());
\r
848 pg.setColor(Color.black);
\r
850 pg.translate(0, -pi * pheight);
\r
852 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
858 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
860 pg.setFont(idPanel.idCanvas.idfont);
\r
861 SequenceI s = av.alignment.getSequenceAt(i);
\r
862 String string = s.getDisplayId(av.getShowJVSuffix());
\r
864 if (av.rightAlignIds)
\r
866 FontMetrics fm = pg.getFontMetrics();
\r
867 xPos = idWidth - fm.stringWidth(string) - 4;
\r
869 pg.drawString(string, xPos,
\r
870 ( (i * av.charHeight) + ypos + av.charHeight) -
\r
871 (av.charHeight / 5));
\r
873 if (labels != null)
\r
877 (av.getAlignment().getHeight() * av.charHeight));
\r
879 pg.setFont(av.getFont());
\r
880 labels.drawComponent(pg, idWidth);
\r
883 (av.getAlignment().getHeight() * av.charHeight));
\r
888 while (ypos < totalHeight);
\r
890 pg.translate(idWidth, 0);
\r
892 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
894 if ( (pi * pheight) < totalHeight)
\r
896 return Printable.PAGE_EXISTS;
\r
901 return Printable.NO_SUCH_PAGE;
\r
905 int getVisibleIdWidth()
\r
908 idPanel.getWidth() > 0 ? idPanel.getWidth() :
\r
909 calculateIdWidth().width + 4;
\r
912 void makeAlignmentImage(int type, File file)
\r
914 int maxwidth = av.alignment.getWidth();
\r
915 if (av.hasHiddenColumns)
\r
917 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
\r
920 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
921 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
\r
923 if (av.getWrapAlignment())
\r
925 height = getWrappedHeight();
\r
926 if (System.getProperty("java.awt.headless") != null
\r
927 && System.getProperty("java.awt.headless").equals("true"))
\r
929 width = alignFrame.getWidth()
\r
930 - vscroll.getPreferredSize().width
\r
931 - alignFrame.getInsets().left
\r
932 - alignFrame.getInsets().right;
\r
936 width = seqPanel.getWidth() + getVisibleIdWidth();
\r
940 else if (av.getShowAnnotation())
\r
942 height += annotationPanel.adjustPanelHeight() + 3;
\r
948 jalview.util.ImageMaker im;
\r
949 if (type == jalview.util.ImageMaker.PNG)
\r
951 im = new jalview.util.ImageMaker(this,
\r
952 jalview.util.ImageMaker.PNG,
\r
953 "Create PNG image from alignment",
\r
954 width, height, file, null);
\r
958 im = new jalview.util.ImageMaker(this,
\r
959 jalview.util.ImageMaker.EPS,
\r
960 "Create EPS file from alignment",
\r
961 width, height, file,
\r
962 alignFrame.getTitle());
\r
965 if (av.getWrapAlignment())
\r
967 if (im.getGraphics() != null)
\r
969 printWrappedAlignment(im.getGraphics(), width, height, 0);
\r
975 if (im.getGraphics() != null)
\r
977 printUnwrapped(im.getGraphics(), width, height, 0);
\r
982 catch (OutOfMemoryError err)
\r
984 System.out.println("########################\n"
\r
985 + "OUT OF MEMORY " + file + "\n"
\r
986 + "########################");
\r
988 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
989 "Out of Memory Creating Image!!"
\r
991 "\nSee help files for increasing Java Virtual Machine memory."
\r
993 JOptionPane.WARNING_MESSAGE);
\r
994 System.out.println("Create IMAGE: " + err);
\r
998 catch (Exception ex)
\r
1000 ex.printStackTrace();
\r
1007 public void makeEPS(File epsFile)
\r
1009 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
\r
1015 public void makePNG(File pngFile)
\r
1017 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
\r
1020 public void makePNGImageMap(File imgMapFile, String imageName)
\r
1022 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
1023 //////////////////////////////////////////////
\r
1024 int idWidth = getVisibleIdWidth();
\r
1025 FontMetrics fm = getFontMetrics(av.getFont());
\r
1026 int scaleHeight = av.charHeight + fm.getDescent();
\r
1029 //////////////////////////////////
\r
1030 if (imgMapFile != null)
\r
1034 int s, sSize = av.alignment.getHeight(),
\r
1035 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
\r
1036 StringBuffer text = new StringBuffer();
\r
1037 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
1038 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
1039 out.println("<img src=\"" + imageName +
\r
1040 "\" border=\"0\" usemap=\"#Map\" >"
\r
1041 + "<map name=\"Map\">");
\r
1043 for (s = 0; s < sSize; s++)
\r
1045 sy = s * av.charHeight + scaleHeight;
\r
1047 SequenceI seq = av.alignment.getSequenceAt(s);
\r
1048 SequenceFeature[] features = seq.getDatasetSequence().
\r
1049 getSequenceFeatures();
\r
1050 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
1051 for (res = 0; res < alwidth; res++)
\r
1053 text = new StringBuffer();
\r
1054 Object obj = null;
\r
1055 if (av.alignment.isNucleotide())
\r
1057 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res) +
\r
1062 obj = ResidueProperties.aa2Triplet.get(
\r
1063 seq.getCharAt(res) + "");
\r
1071 String triplet = obj.toString();
\r
1072 int alIndex = seq.findPosition(res);
\r
1073 gSize = groups.length;
\r
1074 for (g = 0; g < gSize; g++)
\r
1076 if (text.length() < 1)
\r
1078 text.append("<area shape=\"rect\" coords=\""
\r
1079 + (idWidth + res * av.charWidth) + ","
\r
1081 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1082 + (av.charHeight + sy) + "\""
\r
1083 + " onMouseOver=\"toolTip('"
\r
1084 + alIndex + " " + triplet);
\r
1087 if (groups[g].getStartRes() < res && groups[g].getEndRes() > res)
\r
1089 text.append("<br><em>" + groups[g].getName() + "</em>");
\r
1093 if (features != null)
\r
1095 if (text.length() < 1)
\r
1097 text.append("<area shape=\"rect\" coords=\""
\r
1098 + (idWidth + res * av.charWidth) + ","
\r
1100 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1101 + (av.charHeight + sy) + "\""
\r
1102 + " onMouseOver=\"toolTip('"
\r
1103 + alIndex + " " + triplet);
\r
1105 fSize = features.length;
\r
1106 for (f = 0; f < fSize; f++)
\r
1109 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
\r
1110 (features[f].getEnd() >= seq.findPosition(res)))
\r
1112 if (features[f].getType().equals("disulfide bond"))
\r
1114 if (features[f].getBegin() == seq.findPosition(res)
\r
1115 || features[f].getEnd() == seq.findPosition(res))
\r
1117 text.append("<br>disulfide bond " + features[f].getBegin() +
\r
1119 features[f].getEnd());
\r
1124 text.append("<br>");
\r
1125 text.append(features[f].getType());
\r
1126 if (features[f].getDescription() != null &&
\r
1128 getType().equals(features[f].getDescription()))
\r
1130 text.append(" " + features[f].getDescription());
\r
1133 if (features[f].getValue("status") != null)
\r
1135 text.append(" (" + features[f].getValue("status") + ")");
\r
1142 if (text.length() > 1)
\r
1144 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
\r
1145 out.println(text.toString());
\r
1149 out.println("</map></body></html>");
\r
1153 catch (Exception ex)
\r
1155 ex.printStackTrace();
\r
1157 } ///////////END OF IMAGE MAP
\r
1161 int getWrappedHeight()
\r
1163 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
\r
1165 if (System.getProperty("java.awt.headless") != null
\r
1166 && System.getProperty("java.awt.headless").equals("true"))
\r
1168 seqPanelWidth = alignFrame.getWidth()
\r
1169 - getVisibleIdWidth()
\r
1170 - vscroll.getPreferredSize().width
\r
1171 - alignFrame.getInsets().left
\r
1172 - alignFrame.getInsets().right;
\r
1175 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
1179 int hgap = av.charHeight;
\r
1180 if (av.scaleAboveWrapped)
\r
1182 hgap += av.charHeight;
\r
1185 int annotationHeight = 0;
\r
1186 if (av.showAnnotation)
\r
1188 annotationHeight = annotationPanel.adjustPanelHeight();
\r
1191 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
1193 + annotationHeight;
\r
1195 int maxwidth = av.alignment.getWidth();
\r
1196 if (av.hasHiddenColumns)
\r
1198 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
1201 int height = ( (maxwidth / chunkWidth) + 1) * cHeight;
\r