2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
28 import java.awt.event.*;
\r
29 import java.awt.print.*;
\r
31 import javax.swing.*;
\r
32 import java.beans.*;
\r
40 * @version $Revision$
\r
42 public class AlignmentPanel extends GAlignmentPanel
\r
43 implements AdjustmentListener, Printable
\r
45 public AlignViewport av;
\r
46 OverviewPanel overviewPanel;
\r
49 IdwidthAdjuster idwidthAdjuster;
\r
51 /** DOCUMENT ME!! */
\r
52 public AlignFrame alignFrame;
\r
53 ScalePanel scalePanel;
\r
54 AnnotationPanel annotationPanel;
\r
55 AnnotationLabels alabels;
\r
57 // this value is set false when selection area being dragged
\r
58 boolean fastPaint = true;
\r
63 * Creates a new AlignmentPanel object.
\r
65 * @param af DOCUMENT ME!
\r
66 * @param av DOCUMENT ME!
\r
68 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
72 seqPanel = new SeqPanel(av, this);
\r
73 idPanel = new IdPanel(av, this);
\r
75 scalePanel = new ScalePanel(av, this);
\r
77 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
78 idwidthAdjuster = new IdwidthAdjuster(this);
\r
79 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
81 annotationPanel = new AnnotationPanel(this);
\r
82 alabels = new AnnotationLabels(this);
\r
84 annotationScroller.setViewportView(annotationPanel);
\r
85 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
89 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
90 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
92 setScrollValues(0, 0);
\r
94 setAnnotationVisible(av.getShowAnnotation());
\r
96 hscroll.addAdjustmentListener(this);
\r
97 vscroll.addAdjustmentListener(this);
\r
99 final AlignmentPanel ap = this;
\r
100 av.addPropertyChangeListener(new PropertyChangeListener()
\r
102 public void propertyChange(PropertyChangeEvent evt)
\r
104 if (evt.getPropertyName().equals("alignment"))
\r
106 PaintRefresher.Refresh(ap,
\r
107 av.getSequenceSetId(),
\r
110 alignmentChanged();
\r
115 adjustAnnotationHeight();
\r
119 public void alignmentChanged()
\r
121 av.alignmentChanged(this);
\r
123 if (overviewPanel != null)
\r
124 overviewPanel.updateOverviewImage();
\r
126 alignFrame.updateEditMenuBar();
\r
136 public void fontChanged()
\r
138 // set idCanvas bufferedImage to null
\r
139 // to prevent drawing old image
\r
140 FontMetrics fm = getFontMetrics(av.getFont());
\r
142 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
143 av.charHeight + fm.getDescent()));
\r
144 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
145 av.charHeight + fm.getDescent()));
\r
147 idPanel.idCanvas.gg = null;
\r
148 seqPanel.seqCanvas.img = null;
\r
149 annotationPanel.adjustPanelHeight();
\r
151 Dimension d = calculateIdWidth();
\r
152 d.setSize(d.width + 4, d.height);
\r
153 idPanel.idCanvas.setPreferredSize(d);
\r
154 hscrollFillerPanel.setPreferredSize(d);
\r
156 if (overviewPanel != null)
\r
157 overviewPanel.setBoxPosition();
\r
165 * @return DOCUMENT ME!
\r
167 public Dimension calculateIdWidth()
\r
169 Container c = new Container();
\r
171 FontMetrics fm = c.getFontMetrics(
\r
172 new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));
\r
174 AlignmentI al = av.getAlignment();
\r
180 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
182 SequenceI s = al.getSequenceAt(i);
\r
184 id = s.getDisplayId(av.getShowJVSuffix());
\r
186 if (fm.stringWidth(id) > idWidth)
\r
188 idWidth = fm.stringWidth(id);
\r
194 // Also check annotation label widths
\r
197 if (al.getAlignmentAnnotation() != null)
\r
199 fm = c.getFontMetrics(alabels.getFont());
\r
201 while (i < al.getAlignmentAnnotation().length)
\r
203 String label = al.getAlignmentAnnotation()[i].label;
\r
205 if (fm.stringWidth(label) > idWidth)
\r
207 idWidth = fm.stringWidth(label);
\r
214 return new Dimension(idWidth, 12);
\r
220 * @param results DOCUMENT ME!
\r
222 public void highlightSearchResults(SearchResults results)
\r
224 seqPanel.seqCanvas.highlightSearchResults(results);
\r
226 // do we need to scroll the panel?
\r
227 if (results != null)
\r
229 SequenceI seq = results.getResultSequence(0);
\r
230 int seqIndex = av.alignment.findIndex(seq);
\r
231 int start = seq.findIndex(results.getResultStart(0)) - 1;
\r
232 int end = seq.findIndex(results.getResultEnd(0)) - 1;
\r
234 if(!av.wrapAlignment)
\r
236 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
\r
237 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
\r
239 setScrollValues(start, seqIndex);
\r
244 scrollToWrappedVisible(start);
\r
249 void scrollToWrappedVisible(int res)
\r
251 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
252 if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) )
\r
254 vscroll.setValue(res / cwidth);
\r
255 av.startRes = vscroll.getValue() * cwidth;
\r
262 * @return DOCUMENT ME!
\r
264 public OverviewPanel getOverviewPanel()
\r
266 return overviewPanel;
\r
272 * @param op DOCUMENT ME!
\r
274 public void setOverviewPanel(OverviewPanel op)
\r
276 overviewPanel = op;
\r
282 * @param b DOCUMENT ME!
\r
284 public void setAnnotationVisible(boolean b)
\r
286 if (!av.wrapAlignment)
\r
288 annotationSpaceFillerHolder.setVisible(b);
\r
289 annotationScroller.setVisible(b);
\r
294 public void adjustAnnotationHeight()
\r
296 if (alignFrame.getHeight() == 0)
\r
298 System.out.println("NEEDS FIXING");
\r
301 int height = annotationPanel.adjustPanelHeight();
\r
303 if (height > alignFrame.getHeight() / 2)
\r
305 height = alignFrame.getHeight() / 2;
\r
308 annotationScroller.setPreferredSize(
\r
309 new Dimension(annotationScroller.getWidth(),
\r
312 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
313 annotationSpaceFillerHolder.getWidth(),
\r
322 * @param wrap DOCUMENT ME!
\r
324 public void setWrapAlignment(boolean wrap)
\r
327 scalePanelHolder.setVisible(!wrap);
\r
328 hscroll.setVisible(!wrap);
\r
329 idwidthAdjuster.setVisible(!wrap);
\r
333 annotationScroller.setVisible(false);
\r
334 annotationSpaceFillerHolder.setVisible(false);
\r
336 else if (av.showAnnotation)
\r
338 annotationScroller.setVisible(true);
\r
339 annotationSpaceFillerHolder.setVisible(true);
\r
342 idSpaceFillerPanel1.setVisible(!wrap);
\r
347 // return value is true if the scroll is valid
\r
348 public boolean scrollUp(boolean up)
\r
352 if (vscroll.getValue() < 1)
\r
358 vscroll.setValue(vscroll.getValue() - 1);
\r
362 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
368 vscroll.setValue(vscroll.getValue() + 1);
\r
379 * @param right DOCUMENT ME!
\r
381 * @return DOCUMENT ME!
\r
383 public boolean scrollRight(boolean right)
\r
387 if (hscroll.getValue() < 1)
\r
393 hscroll.setValue(hscroll.getValue() - 1);
\r
397 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
403 hscroll.setValue(hscroll.getValue() + 1);
\r
414 * @param x DOCUMENT ME!
\r
415 * @param y DOCUMENT ME!
\r
417 public void setScrollValues(int x, int y)
\r
420 int width = av.alignment.getWidth();
\r
421 int height = av.alignment.getHeight();
\r
423 if(av.hasHiddenColumns)
\r
424 width = av.getColumnSelection().findColumnPosition(width);
\r
426 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
\r
428 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
429 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
431 if (hextent > width)
\r
436 if (vextent > height)
\r
441 if ( (hextent + x) > width)
\r
443 x = width - hextent;
\r
446 if ( (vextent + y) > height)
\r
448 y = height - vextent;
\r
461 hscroll.setValues(x, hextent, 0, width);
\r
462 vscroll.setValues(y, vextent, 0, height);
\r
468 * @param evt DOCUMENT ME!
\r
470 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
473 int oldX = av.getStartRes();
\r
474 int oldY = av.getStartSeq();
\r
476 if (evt.getSource() == hscroll)
\r
478 int x = hscroll.getValue();
\r
481 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
484 if (evt.getSource() == vscroll)
\r
486 int offy = vscroll.getValue();
\r
488 if (av.getWrapAlignment())
\r
492 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
493 seqCanvas.getWidth());
\r
494 av.setStartRes(offy * rowSize);
\r
495 av.setEndRes( (offy + 1) * rowSize);
\r
499 //This is only called if file loaded is a jar file that
\r
500 //was wrapped when saved and user has wrap alignment true
\r
501 //as preference setting
\r
502 SwingUtilities.invokeLater(new Runnable()
\r
506 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
513 av.setStartSeq(offy);
\r
514 av.setEndSeq(offy +
\r
515 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
519 if (overviewPanel != null)
\r
521 overviewPanel.setBoxPosition();
\r
524 int scrollX = av.startRes - oldX;
\r
525 int scrollY = av.startSeq - oldY;
\r
527 if (av.getWrapAlignment() || !fastPaint)
\r
533 // Make sure we're not trying to draw a panel
\r
534 // larger than the visible window
\r
535 if(scrollX>av.endRes-av.startRes)
\r
536 scrollX = av.endRes-av.startRes;
\r
537 else if(scrollX<av.startRes-av.endRes)
\r
538 scrollX = av.startRes - av.endRes;
\r
540 if(scrollX!=0 || scrollY!=0)
\r
542 idPanel.idCanvas.fastPaint(scrollY);
\r
543 seqPanel.seqCanvas.fastPaint(scrollX,
\r
545 scalePanel.repaint();
\r
547 if (av.getShowAnnotation())
\r
549 annotationPanel.fastPaint(scrollX);
\r
558 * @param g DOCUMENT ME!
\r
560 public void paintComponent(Graphics g)
\r
564 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
565 idPanelHolder.setPreferredSize(d);
\r
566 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
569 if (av.getWrapAlignment())
\r
571 int maxwidth = av.alignment.getWidth();
\r
573 if (av.hasHiddenColumns)
\r
574 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
576 int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
579 int max = maxwidth /
\r
580 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
\r
583 vscroll.setMaximum(max);
\r
584 vscroll.setUnitIncrement(1);
\r
585 vscroll.setVisibleAmount(1);
\r
590 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
593 if( this.getVisibleRect().getBounds() == g.getClipBounds()
\r
594 && overviewPanel != null)
\r
595 overviewPanel.updateOverviewImage();
\r
601 * @param pg DOCUMENT ME!
\r
602 * @param pf DOCUMENT ME!
\r
603 * @param pi DOCUMENT ME!
\r
605 * @return DOCUMENT ME!
\r
607 * @throws PrinterException DOCUMENT ME!
\r
609 public int print(Graphics pg, PageFormat pf, int pi)
\r
610 throws PrinterException
\r
612 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
\r
614 int pwidth = (int) pf.getImageableWidth();
\r
615 int pheight = (int) pf.getImageableHeight();
\r
617 if (av.getWrapAlignment())
\r
619 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
623 return printUnwrapped(pg, pwidth, pheight, pi);
\r
630 * @param pg DOCUMENT ME!
\r
631 * @param pwidth DOCUMENT ME!
\r
632 * @param pheight DOCUMENT ME!
\r
633 * @param pi DOCUMENT ME!
\r
635 * @return DOCUMENT ME!
\r
637 * @throws PrinterException DOCUMENT ME!
\r
639 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
640 throws PrinterException
\r
642 int idWidth = getVisibleIdWidth();
\r
643 FontMetrics fm = getFontMetrics(av.getFont());
\r
644 int scaleHeight = av.charHeight + fm.getDescent();
\r
646 pg.setColor(Color.white);
\r
647 pg.fillRect(0, 0, pwidth, pheight);
\r
648 pg.setFont(av.getFont());
\r
650 ////////////////////////////////////
\r
651 /// How many sequences and residues can we fit on a printable page?
\r
652 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
654 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
\r
657 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
659 /////////////////////////////
\r
660 /// Only print these sequences and residues on this page
\r
663 /////////////////////////////
\r
664 /// Only print these sequences and residues on this page
\r
667 /////////////////////////////
\r
668 /// Only print these sequences and residues on this page
\r
671 /////////////////////////////
\r
672 /// Only print these sequences and residues on this page
\r
674 startRes = (pi % pagesWide) * totalRes;
\r
675 endRes = (startRes + totalRes) - 1;
\r
677 if (endRes > (av.getAlignment().getWidth() - 1))
\r
679 endRes = av.getAlignment().getWidth() - 1;
\r
682 startSeq = (pi / pagesWide) * totalSeq;
\r
683 endSeq = startSeq + totalSeq;
\r
685 if (endSeq > av.getAlignment().getHeight())
\r
687 endSeq = av.getAlignment().getHeight();
\r
690 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
692 if (av.showAnnotation)
\r
694 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
\r
697 pagesHigh /= pheight;
\r
699 if (pi >= (pagesWide * pagesHigh))
\r
701 return Printable.NO_SUCH_PAGE;
\r
705 pg.translate(idWidth, 0);
\r
706 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
707 pg.translate( -idWidth, scaleHeight);
\r
711 Color currentColor = null;
\r
712 Color currentTextColor = null;
\r
714 pg.setFont(new Font(av.getFont().getName(),
\r
716 av.getFont().getSize()));
\r
718 for (int i = startSeq; i < endSeq; i++)
\r
720 seq = av.getAlignment().getSequenceAt(i);
\r
721 if ( (av.getSelectionGroup() != null) &&
\r
722 av.getSelectionGroup().getSequences(false).contains(seq))
\r
724 currentColor = Color.gray;
\r
725 currentTextColor = Color.black;
\r
729 currentColor = av.getSequenceColour(seq);
\r
730 currentTextColor = Color.black;
\r
733 pg.setColor(currentColor);
\r
734 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
\r
735 av.getCharHeight());
\r
737 pg.setColor(currentTextColor);
\r
740 if (av.rightAlignIds)
\r
742 fm = pg.getFontMetrics();
\r
743 xPos = idWidth - fm.stringWidth(
\r
744 seq.getDisplayId(av.getShowJVSuffix())
\r
748 pg.drawString(seq.getDisplayId( av.getShowJVSuffix()),
\r
750 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
\r
751 (av.getCharHeight() / 5));
\r
754 pg.setFont(av.getFont());
\r
756 // draw main sequence panel
\r
757 pg.translate(idWidth, 0);
\r
758 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
\r
760 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
762 pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
\r
763 alabels.drawComponent( (Graphics2D) pg, idWidth);
\r
764 pg.translate(idWidth+3, 0);
\r
765 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
\r
769 return Printable.PAGE_EXISTS;
\r
775 * @param pg DOCUMENT ME!
\r
776 * @param pwidth DOCUMENT ME!
\r
777 * @param pheight DOCUMENT ME!
\r
778 * @param pi DOCUMENT ME!
\r
780 * @return DOCUMENT ME!
\r
782 * @throws PrinterException DOCUMENT ME!
\r
784 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
786 throws PrinterException
\r
789 int annotationHeight = 0;
\r
790 AnnotationLabels labels = null;
\r
791 if (av.showAnnotation)
\r
793 annotationHeight = annotationPanel.adjustPanelHeight();
\r
794 labels = new AnnotationLabels(av);
\r
797 int hgap = av.charHeight;
\r
798 if (av.scaleAboveWrapped)
\r
799 hgap += av.charHeight;
\r
801 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
803 + annotationHeight;
\r
805 int idWidth = getVisibleIdWidth();
\r
807 int maxwidth = av.alignment.getWidth();
\r
808 if (av.hasHiddenColumns)
\r
809 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
812 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
815 int totalHeight = cHeight * (maxwidth / resWidth + 1);
\r
817 pg.setColor(Color.white);
\r
818 pg.fillRect(0, 0, pwidth, pheight);
\r
819 pg.setFont(av.getFont());
\r
823 pg.setColor(Color.black);
\r
825 pg.translate(0, -pi * pheight);
\r
827 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
830 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
831 av.getFont().getSize());
\r
832 pg.setFont(italic);
\r
836 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
838 SequenceI s = av.alignment.getSequenceAt(i);
\r
839 String string = s.getDisplayId( av.getShowJVSuffix());
\r
841 if (av.rightAlignIds)
\r
843 FontMetrics fm = getFontMetrics(italic);
\r
844 xPos = idWidth - fm.stringWidth( string ) - 4;
\r
846 pg.drawString(string, xPos,
\r
847 ( (i * av.charHeight) + ypos + av.charHeight) -
\r
848 (av.charHeight / 5));
\r
850 if (labels != null)
\r
854 (av.getAlignment().getHeight() * av.charHeight));
\r
856 pg.setFont(av.getFont());
\r
857 labels.drawComponent(pg, idWidth);
\r
858 pg.setFont(italic);
\r
861 (av.getAlignment().getHeight() * av.charHeight));
\r
866 while (ypos < totalHeight);
\r
868 pg.translate(idWidth, 0);
\r
870 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
872 if ( (pi * pheight) < totalHeight)
\r
874 return Printable.PAGE_EXISTS;
\r
879 return Printable.NO_SUCH_PAGE;
\r
883 int getVisibleIdWidth()
\r
886 idPanel.getWidth() > 0 ? idPanel.getWidth() :
\r
887 calculateIdWidth().width + 4;
\r
890 void makeAlignmentImage(int type, File file)
\r
892 int maxwidth = av.alignment.getWidth();
\r
893 if (av.hasHiddenColumns)
\r
894 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
\r
896 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
897 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
\r
899 if (av.getWrapAlignment())
\r
901 height = getWrappedHeight();
\r
902 if (System.getProperty("java.awt.headless") != null
\r
903 && System.getProperty("java.awt.headless").equals("true"))
\r
905 width = alignFrame.getWidth() - 22;
\r
908 width = seqPanel.getWidth() + getVisibleIdWidth();
\r
911 else if (av.getShowAnnotation())
\r
913 height += annotationPanel.adjustPanelHeight() + 3;
\r
919 jalview.util.ImageMaker im;
\r
920 if(type==jalview.util.ImageMaker.PNG)
\r
921 im = new jalview.util.ImageMaker(this,
\r
922 jalview.util.ImageMaker.PNG,
\r
923 "Create PNG image from alignment",
\r
924 width, height, file, null);
\r
926 im = new jalview.util.ImageMaker(this,
\r
927 jalview.util.ImageMaker.EPS,
\r
928 "Create EPS file from alignment",
\r
929 width, height, file, alignFrame.getTitle() );
\r
931 if (av.getWrapAlignment())
\r
933 if(im.getGraphics()!=null)
\r
935 printWrappedAlignment(im.getGraphics(), width, height, 0);
\r
941 if(im.getGraphics()!=null)
\r
943 printUnwrapped(im.getGraphics(), width, height, 0);
\r
948 catch (OutOfMemoryError err)
\r
950 System.out.println("########################\n"
\r
951 + "OUT OF MEMORY " + file + "\n"
\r
952 + "########################");
\r
954 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
955 "Out of Memory Creating Image!!"
\r
957 "\nSee help files for increasing Java Virtual Machine memory."
\r
959 JOptionPane.WARNING_MESSAGE);
\r
960 System.out.println("Create IMAGE: " + err);
\r
964 catch (Exception ex)
\r
966 ex.printStackTrace();
\r
972 public void makeEPS(File epsFile)
\r
974 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
\r
980 public void makePNG(File pngFile)
\r
982 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
\r
985 public void makePNGImageMap(File imgMapFile, String imageName)
\r
987 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
988 //////////////////////////////////////////////
\r
989 int idWidth = getVisibleIdWidth();
\r
990 FontMetrics fm = getFontMetrics(av.getFont());
\r
991 int scaleHeight = av.charHeight + fm.getDescent();
\r
994 //////////////////////////////////
\r
995 if (imgMapFile != null)
\r
999 int s, sSize = av.alignment.getHeight(),
\r
1000 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
\r
1001 StringBuffer text = new StringBuffer();
\r
1002 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
1003 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
1004 out.println("<img src=\"" + imageName +
\r
1005 "\" border=\"0\" usemap=\"#Map\" >"
\r
1006 + "<map name=\"Map\">");
\r
1008 for (s = 0; s < sSize; s++)
\r
1010 sy = s * av.charHeight + scaleHeight;
\r
1012 SequenceI seq = av.alignment.getSequenceAt(s);
\r
1013 SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures();
\r
1014 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
1015 for(res =0; res<alwidth; res++)
\r
1017 text = new StringBuffer();
\r
1018 Object obj = null;
\r
1019 if(av.alignment.isNucleotide())
\r
1020 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)+"" );
\r
1022 obj = ResidueProperties.aa2Triplet.get(
\r
1023 seq.getCharAt(res) + "");
\r
1028 String triplet = obj.toString();
\r
1029 int alIndex = seq.findPosition(res);
\r
1030 gSize = groups.length;
\r
1031 for (g = 0; g < gSize; g++)
\r
1033 if(text.length()<1)
\r
1035 text.append("<area shape=\"rect\" coords=\""
\r
1036 + (idWidth + res * av.charWidth) + ","
\r
1038 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1039 + (av.charHeight + sy) + "\""
\r
1040 + " onMouseOver=\"toolTip('"
\r
1041 + alIndex + " " + triplet );
\r
1044 if(groups[g].getStartRes()<res && groups[g].getEndRes()>res)
\r
1045 text.append("<br><em>" + groups[g].getName() + "</em>");
\r
1048 if (features != null)
\r
1050 if(text.length()<1)
\r
1052 text.append("<area shape=\"rect\" coords=\""
\r
1053 + (idWidth + res * av.charWidth) + ","
\r
1055 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1056 + (av.charHeight + sy) + "\""
\r
1057 + " onMouseOver=\"toolTip('"
\r
1058 + alIndex + " " + triplet );
\r
1060 fSize = features.length;
\r
1061 for (f = 0; f < fSize; f++)
\r
1064 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
\r
1065 (features[f].getEnd() >= seq.findPosition(res)))
\r
1067 if (features[f].getType().equals("disulfide bond"))
\r
1069 if (features[f].getBegin() == seq.findPosition(res)
\r
1070 || features[f].getEnd() == seq.findPosition(res))
\r
1072 text.append("<br>disulfide bond " + features[f].getBegin() + ":" +
\r
1073 features[f].getEnd());
\r
1078 text.append("<br>");
\r
1079 text.append(features[f].getType());
\r
1080 if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription()))
\r
1081 text.append(" " + features[f].getDescription());
\r
1083 if (features[f].getValue("status") != null )
\r
1085 text.append(" (" + features[f].getValue("status") + ")");
\r
1092 if(text.length()>1)
\r
1094 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
\r
1095 out.println(text.toString());
\r
1099 out.println("</map></body></html>");
\r
1103 catch (Exception ex)
\r
1105 ex.printStackTrace();
\r
1107 } ///////////END OF IMAGE MAP
\r
1111 int getWrappedHeight()
\r
1113 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
\r
1115 //If headless, seqPanel will have 0 width
\r
1116 if (System.getProperty("java.awt.headless") != null
\r
1117 && System.getProperty("java.awt.headless").equals("true"))
\r
1119 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth();
\r
1122 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
1126 int hgap = av.charHeight;
\r
1127 if (av.scaleAboveWrapped)
\r
1128 hgap += av.charHeight;
\r
1130 int annotationHeight = 0;
\r
1131 if (av.showAnnotation)
\r
1133 annotationHeight = annotationPanel.adjustPanelHeight();
\r
1136 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
1138 + annotationHeight;
\r
1140 int maxwidth = av.alignment.getWidth();
\r
1141 if (av.hasHiddenColumns)
\r
1142 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
1145 int height = ( (maxwidth / chunkWidth) + 1) * cHeight;
\r
1153 * @author $author$
\r
1154 * @version $Revision$
\r
1160 * Creates a new Preview object.
\r
1162 * @param image DOCUMENT ME!
\r
1164 public Preview(Image image)
\r
1166 setResizable(true);
\r
1167 setSize(image.getWidth(this), image.getHeight(this));
\r
1169 getContentPane().setLayout(new BorderLayout());
\r
1170 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
\r
1179 * @author $author$
\r
1180 * @version $Revision$
\r
1182 class PreviewPanel
\r
1188 * Creates a new PreviewPanel object.
\r
1190 * @param image DOCUMENT ME!
\r
1192 public PreviewPanel(Image image)
\r
1194 this.image = image;
\r
1200 * @param g DOCUMENT ME!
\r
1202 public void paintComponent(Graphics g)
\r
1204 if (image != null)
\r
1206 g.drawImage(image, 0, 0, this);
\r
1210 System.out.println("DEBUG:image is null");
\r