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
33 import javax.swing.*;
\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
100 adjustAnnotationHeight();
\r
108 public void fontChanged()
\r
110 // set idCanvas bufferedImage to null
\r
111 // to prevent drawing old image
\r
112 FontMetrics fm = getFontMetrics(av.getFont());
\r
114 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
115 av.charHeight + fm.getDescent()));
\r
116 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
117 av.charHeight + fm.getDescent()));
\r
119 idPanel.idCanvas.gg = null;
\r
120 seqPanel.seqCanvas.img = null;
\r
121 annotationPanel.adjustPanelHeight();
\r
123 Dimension d = calculateIdWidth();
\r
124 d.setSize(d.width + 4, d.height);
\r
125 idPanel.idCanvas.setPreferredSize(d);
\r
126 hscrollFillerPanel.setPreferredSize(d);
\r
128 if (overviewPanel != null)
\r
129 overviewPanel.setBoxPosition();
\r
137 * @return DOCUMENT ME!
\r
139 public Dimension calculateIdWidth()
\r
141 Container c = new Container();
\r
143 FontMetrics fm = c.getFontMetrics(
\r
144 new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));
\r
146 AlignmentI al = av.getAlignment();
\r
152 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
154 SequenceI s = al.getSequenceAt(i);
\r
156 id = s.getDisplayId(av.getShowJVSuffix());
\r
158 if (fm.stringWidth(id) > idWidth)
\r
160 idWidth = fm.stringWidth(id);
\r
166 // Also check annotation label widths
\r
169 if (al.getAlignmentAnnotation() != null)
\r
171 fm = c.getFontMetrics(alabels.getFont());
\r
173 while (i < al.getAlignmentAnnotation().length)
\r
175 String label = al.getAlignmentAnnotation()[i].label;
\r
177 if (fm.stringWidth(label) > idWidth)
\r
179 idWidth = fm.stringWidth(label);
\r
186 return new Dimension(idWidth, 12);
\r
192 * @param results DOCUMENT ME!
\r
194 public void highlightSearchResults(SearchResults results)
\r
196 seqPanel.seqCanvas.highlightSearchResults(results);
\r
198 // do we need to scroll the panel?
\r
199 if (results != null)
\r
201 SequenceI seq = results.getResultSequence(0);
\r
202 int seqIndex = av.alignment.findIndex(seq);
\r
203 int start = seq.findIndex(results.getResultStart(0)) - 1;
\r
204 int end = seq.findIndex(results.getResultEnd(0)) - 1;
\r
206 if(!av.wrapAlignment)
\r
208 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
\r
209 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
\r
211 setScrollValues(start, seqIndex);
\r
216 scrollToWrappedVisible(start);
\r
221 void scrollToWrappedVisible(int res)
\r
223 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
224 if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) )
\r
226 vscroll.setValue(res / cwidth);
\r
227 av.startRes = vscroll.getValue() * cwidth;
\r
234 * @return DOCUMENT ME!
\r
236 public OverviewPanel getOverviewPanel()
\r
238 return overviewPanel;
\r
244 * @param op DOCUMENT ME!
\r
246 public void setOverviewPanel(OverviewPanel op)
\r
248 overviewPanel = op;
\r
254 * @param b DOCUMENT ME!
\r
256 public void setAnnotationVisible(boolean b)
\r
258 if (!av.wrapAlignment)
\r
260 annotationSpaceFillerHolder.setVisible(b);
\r
261 annotationScroller.setVisible(b);
\r
266 public void adjustAnnotationHeight()
\r
268 if (alignFrame.getHeight() == 0)
\r
270 System.out.println("NEEDS FIXING");
\r
273 int height = annotationPanel.adjustPanelHeight();
\r
275 if (height > alignFrame.getHeight() / 2)
\r
277 height = alignFrame.getHeight() / 2;
\r
280 annotationScroller.setPreferredSize(
\r
281 new Dimension(annotationScroller.getWidth(),
\r
284 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
285 annotationSpaceFillerHolder.getWidth(),
\r
288 annotationPanel.repaint();
\r
295 * @param wrap DOCUMENT ME!
\r
297 public void setWrapAlignment(boolean wrap)
\r
300 scalePanelHolder.setVisible(!wrap);
\r
301 hscroll.setVisible(!wrap);
\r
302 idwidthAdjuster.setVisible(!wrap);
\r
306 annotationScroller.setVisible(false);
\r
307 annotationSpaceFillerHolder.setVisible(false);
\r
309 else if (av.showAnnotation)
\r
311 annotationScroller.setVisible(true);
\r
312 annotationSpaceFillerHolder.setVisible(true);
\r
315 idSpaceFillerPanel1.setVisible(!wrap);
\r
320 // return value is true if the scroll is valid
\r
321 public boolean scrollUp(boolean up)
\r
325 if (vscroll.getValue() < 1)
\r
331 vscroll.setValue(vscroll.getValue() - 1);
\r
335 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
341 vscroll.setValue(vscroll.getValue() + 1);
\r
352 * @param right DOCUMENT ME!
\r
354 * @return DOCUMENT ME!
\r
356 public boolean scrollRight(boolean right)
\r
360 if (hscroll.getValue() < 1)
\r
366 hscroll.setValue(hscroll.getValue() - 1);
\r
370 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
376 hscroll.setValue(hscroll.getValue() + 1);
\r
387 * @param x DOCUMENT ME!
\r
388 * @param y DOCUMENT ME!
\r
390 public void setScrollValues(int x, int y)
\r
393 int width = av.alignment.getWidth();
\r
394 int height = av.alignment.getHeight();
\r
396 if(av.hasHiddenColumns)
\r
397 width = av.getColumnSelection().findColumnPosition(width);
\r
399 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
\r
401 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
402 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
404 if (hextent > width)
\r
409 if (vextent > height)
\r
414 if ( (hextent + x) > width)
\r
416 x = width - hextent;
\r
419 if ( (vextent + y) > height)
\r
421 y = height - vextent;
\r
434 hscroll.setValues(x, hextent, 0, width);
\r
435 vscroll.setValues(y, vextent, 0, height);
\r
441 * @param evt DOCUMENT ME!
\r
443 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
446 int oldX = av.getStartRes();
\r
447 int oldY = av.getStartSeq();
\r
449 if (evt.getSource() == hscroll)
\r
451 int x = hscroll.getValue();
\r
454 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
457 if (evt.getSource() == vscroll)
\r
459 int offy = vscroll.getValue();
\r
461 if (av.getWrapAlignment())
\r
465 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
466 seqCanvas.getWidth());
\r
467 av.setStartRes(offy * rowSize);
\r
468 av.setEndRes( (offy + 1) * rowSize);
\r
472 //This is only called if file loaded is a jar file that
\r
473 //was wrapped when saved and user has wrap alignment true
\r
474 //as preference setting
\r
475 SwingUtilities.invokeLater(new Runnable()
\r
479 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
486 av.setStartSeq(offy);
\r
487 av.setEndSeq(offy +
\r
488 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
492 if (overviewPanel != null)
\r
494 overviewPanel.setBoxPosition();
\r
497 int scrollX = av.startRes - oldX;
\r
498 int scrollY = av.startSeq - oldY;
\r
500 if (av.getWrapAlignment() || !fastPaint)
\r
506 // Make sure we're not trying to draw a panel
\r
507 // larger than the visible window
\r
508 if(scrollX>av.endRes-av.startRes)
\r
509 scrollX = av.endRes-av.startRes;
\r
510 else if(scrollX<av.startRes-av.endRes)
\r
511 scrollX = av.startRes - av.endRes;
\r
513 if(scrollX!=0 || scrollY!=0)
\r
515 idPanel.idCanvas.fastPaint(scrollY);
\r
516 seqPanel.seqCanvas.fastPaint(scrollX,
\r
518 scalePanel.repaint();
\r
520 if (av.getShowAnnotation())
\r
522 annotationPanel.fastPaint(scrollX);
\r
531 * @param g DOCUMENT ME!
\r
533 public void paintComponent(Graphics g)
\r
537 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
538 idPanelHolder.setPreferredSize(d);
\r
539 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
542 if (av.getWrapAlignment())
\r
544 int maxwidth = av.alignment.getWidth();
\r
546 if (av.hasHiddenColumns)
\r
547 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
549 int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
552 int max = maxwidth /
\r
553 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
\r
556 vscroll.setMaximum(max);
\r
557 vscroll.setUnitIncrement(1);
\r
558 vscroll.setVisibleAmount(1);
\r
563 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
566 if( this.getVisibleRect().getBounds() == g.getClipBounds()
\r
567 && overviewPanel != null)
\r
568 overviewPanel.updateOverviewImage();
\r
574 * @param pg DOCUMENT ME!
\r
575 * @param pf DOCUMENT ME!
\r
576 * @param pi DOCUMENT ME!
\r
578 * @return DOCUMENT ME!
\r
580 * @throws PrinterException DOCUMENT ME!
\r
582 public int print(Graphics pg, PageFormat pf, int pi)
\r
583 throws PrinterException
\r
585 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
\r
587 int pwidth = (int) pf.getImageableWidth();
\r
588 int pheight = (int) pf.getImageableHeight();
\r
590 if (av.getWrapAlignment())
\r
592 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
596 return printUnwrapped(pg, pwidth, pheight, pi);
\r
603 * @param pg DOCUMENT ME!
\r
604 * @param pwidth DOCUMENT ME!
\r
605 * @param pheight DOCUMENT ME!
\r
606 * @param pi DOCUMENT ME!
\r
608 * @return DOCUMENT ME!
\r
610 * @throws PrinterException DOCUMENT ME!
\r
612 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
613 throws PrinterException
\r
615 int idWidth = getVisibleIdWidth();
\r
616 FontMetrics fm = getFontMetrics(av.getFont());
\r
617 int scaleHeight = av.charHeight + fm.getDescent();
\r
619 pg.setColor(Color.white);
\r
620 pg.fillRect(0, 0, pwidth, pheight);
\r
621 pg.setFont(av.getFont());
\r
623 ////////////////////////////////////
\r
624 /// How many sequences and residues can we fit on a printable page?
\r
625 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
627 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
\r
630 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
632 /////////////////////////////
\r
633 /// Only print these sequences and residues on this page
\r
636 /////////////////////////////
\r
637 /// Only print these sequences and residues on this page
\r
640 /////////////////////////////
\r
641 /// Only print these sequences and residues on this page
\r
644 /////////////////////////////
\r
645 /// Only print these sequences and residues on this page
\r
647 startRes = (pi % pagesWide) * totalRes;
\r
648 endRes = (startRes + totalRes) - 1;
\r
650 if (endRes > (av.getAlignment().getWidth() - 1))
\r
652 endRes = av.getAlignment().getWidth() - 1;
\r
655 startSeq = (pi / pagesWide) * totalSeq;
\r
656 endSeq = startSeq + totalSeq;
\r
658 if (endSeq > av.getAlignment().getHeight())
\r
660 endSeq = av.getAlignment().getHeight();
\r
663 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
665 if (av.showAnnotation)
\r
667 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
\r
670 pagesHigh /= pheight;
\r
672 if (pi >= (pagesWide * pagesHigh))
\r
674 return Printable.NO_SUCH_PAGE;
\r
678 pg.translate(idWidth, 0);
\r
679 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
680 pg.translate( -idWidth, scaleHeight);
\r
684 Color currentColor = null;
\r
685 Color currentTextColor = null;
\r
687 pg.setFont(new Font(av.getFont().getName(),
\r
689 av.getFont().getSize()));
\r
690 for (int i = startSeq; i < endSeq; i++)
\r
692 if ( (av.getSelectionGroup() != null) &&
\r
693 av.getSelectionGroup().getSequences(false).contains(
\r
694 av.getAlignment().getSequenceAt(i)))
\r
696 currentColor = Color.gray;
\r
697 currentTextColor = Color.black;
\r
701 currentColor = av.getAlignment().getSequenceAt(i).getColor();
\r
702 currentTextColor = Color.black;
\r
705 pg.setColor(currentColor);
\r
706 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
\r
707 av.getCharHeight());
\r
709 pg.setColor(currentTextColor);
\r
711 String string = av.getAlignment().getSequenceAt(i).getDisplayId
\r
712 ( av.getShowJVSuffix());
\r
714 pg.drawString(string, 0,
\r
715 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
\r
716 (av.getCharHeight() / 5));
\r
719 pg.setFont(av.getFont());
\r
721 // draw main sequence panel
\r
722 pg.translate(idWidth, 0);
\r
723 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
\r
725 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
727 pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
\r
728 alabels.drawComponent( (Graphics2D) pg, idWidth);
\r
729 pg.translate(idWidth+3, 0);
\r
730 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
\r
734 return Printable.PAGE_EXISTS;
\r
740 * @param pg DOCUMENT ME!
\r
741 * @param pwidth DOCUMENT ME!
\r
742 * @param pheight DOCUMENT ME!
\r
743 * @param pi DOCUMENT ME!
\r
745 * @return DOCUMENT ME!
\r
747 * @throws PrinterException DOCUMENT ME!
\r
749 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
751 throws PrinterException
\r
754 int annotationHeight = 0;
\r
755 AnnotationLabels labels = null;
\r
756 if (av.showAnnotation)
\r
758 annotationHeight = annotationPanel.adjustPanelHeight();
\r
759 labels = new AnnotationLabels(av);
\r
762 int hgap = av.charHeight;
\r
763 if (av.scaleAboveWrapped)
\r
764 hgap += av.charHeight;
\r
766 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
768 + annotationHeight;
\r
770 int idWidth = getVisibleIdWidth();
\r
772 int maxwidth = av.alignment.getWidth();
\r
773 if (av.hasHiddenColumns)
\r
774 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
777 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
780 int totalHeight = cHeight * (maxwidth / resWidth + 1);
\r
782 pg.setColor(Color.white);
\r
783 pg.fillRect(0, 0, pwidth, pheight);
\r
784 pg.setFont(av.getFont());
\r
788 pg.setColor(Color.black);
\r
790 pg.translate(0, -pi * pheight);
\r
792 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
795 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
796 av.getFont().getSize());
\r
797 pg.setFont(italic);
\r
801 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
803 SequenceI s = av.alignment.getSequenceAt(i);
\r
804 String string = s.getDisplayId( av.getShowJVSuffix());
\r
806 pg.drawString(string, 0,
\r
807 ( (i * av.charHeight) + ypos + av.charHeight) -
\r
808 (av.charHeight / 5));
\r
810 if (labels != null)
\r
814 (av.getAlignment().getHeight() * av.charHeight));
\r
816 pg.setFont(av.getFont());
\r
817 labels.drawComponent(pg, idWidth);
\r
818 pg.setFont(italic);
\r
821 (av.getAlignment().getHeight() * av.charHeight));
\r
826 while (ypos < totalHeight);
\r
828 pg.translate(idWidth, 0);
\r
830 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
832 if ( (pi * pheight) < totalHeight)
\r
834 return Printable.PAGE_EXISTS;
\r
839 return Printable.NO_SUCH_PAGE;
\r
843 int getVisibleIdWidth()
\r
846 idPanel.getWidth() > 0 ? idPanel.getWidth() :
\r
847 calculateIdWidth().width + 4;
\r
850 void makeAlignmentImage(int type, File file)
\r
852 int maxwidth = av.alignment.getWidth();
\r
853 if (av.hasHiddenColumns)
\r
854 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
\r
856 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
857 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
\r
859 if (av.getWrapAlignment())
\r
861 height = getWrappedHeight();
\r
862 if (System.getProperty("java.awt.headless") != null
\r
863 && System.getProperty("java.awt.headless").equals("true"))
\r
865 width = alignFrame.getWidth() - 22;
\r
868 width = seqPanel.getWidth() + getVisibleIdWidth();
\r
871 else if (av.getShowAnnotation())
\r
873 height += annotationPanel.adjustPanelHeight() + 3;
\r
879 jalview.util.ImageMaker im;
\r
880 if(type==jalview.util.ImageMaker.PNG)
\r
881 im = new jalview.util.ImageMaker(this,
\r
882 jalview.util.ImageMaker.PNG,
\r
883 "Create PNG image from alignment",
\r
884 width, height, file, null);
\r
886 im = new jalview.util.ImageMaker(this,
\r
887 jalview.util.ImageMaker.EPS,
\r
888 "Create EPS file from alignment",
\r
889 width, height, file, alignFrame.getTitle() );
\r
891 if (av.getWrapAlignment())
\r
893 if(im.getGraphics()!=null)
\r
895 printWrappedAlignment(im.getGraphics(), width, height, 0);
\r
901 if(im.getGraphics()!=null)
\r
903 printUnwrapped(im.getGraphics(), width, height, 0);
\r
908 catch (OutOfMemoryError err)
\r
910 System.out.println("########################\n"
\r
911 + "OUT OF MEMORY " + file + "\n"
\r
912 + "########################");
\r
914 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
915 "Out of Memory Creating Image!!"
\r
917 "\nSee help files for increasing Java Virtual Machine memory."
\r
919 JOptionPane.WARNING_MESSAGE);
\r
920 System.out.println("Create IMAGE: " + err);
\r
924 catch (Exception ex)
\r
926 ex.printStackTrace();
\r
932 public void makeEPS(File epsFile)
\r
934 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
\r
940 public void makePNG(File pngFile)
\r
942 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
\r
945 public void makePNGImageMap(File imgMapFile, String imageName)
\r
947 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
948 //////////////////////////////////////////////
\r
949 int idWidth = getVisibleIdWidth();
\r
950 FontMetrics fm = getFontMetrics(av.getFont());
\r
951 int scaleHeight = av.charHeight + fm.getDescent();
\r
954 //////////////////////////////////
\r
955 if (imgMapFile != null)
\r
959 int s, sSize = av.alignment.getHeight(),
\r
960 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
\r
961 StringBuffer text = new StringBuffer();
\r
962 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
963 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
964 out.println("<img src=\"" + imageName +
\r
965 "\" border=\"0\" usemap=\"#Map\" >"
\r
966 + "<map name=\"Map\">");
\r
968 for (s = 0; s < sSize; s++)
\r
970 sy = s * av.charHeight + scaleHeight;
\r
972 SequenceI seq = av.alignment.getSequenceAt(s);
\r
973 SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures();
\r
974 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
975 for(res =0; res<alwidth; res++)
\r
977 text = new StringBuffer();
\r
979 if(av.alignment.isNucleotide())
\r
980 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)+"" );
\r
982 obj = ResidueProperties.aa2Triplet.get(
\r
983 seq.getCharAt(res) + "");
\r
988 String triplet = obj.toString();
\r
989 int alIndex = seq.findPosition(res);
\r
990 gSize = groups.length;
\r
991 for (g = 0; g < gSize; g++)
\r
993 if(text.length()<1)
\r
995 text.append("<area shape=\"rect\" coords=\""
\r
996 + (idWidth + res * av.charWidth) + ","
\r
998 + (idWidth + (res + 1) * av.charWidth) + ","
\r
999 + (av.charHeight + sy) + "\""
\r
1000 + " onMouseOver=\"toolTip('"
\r
1001 + alIndex + " " + triplet );
\r
1004 if(groups[g].getStartRes()<res && groups[g].getEndRes()>res)
\r
1005 text.append("<br><em>" + groups[g].getName() + "</em>");
\r
1008 if (features != null)
\r
1010 if(text.length()<1)
\r
1012 text.append("<area shape=\"rect\" coords=\""
\r
1013 + (idWidth + res * av.charWidth) + ","
\r
1015 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1016 + (av.charHeight + sy) + "\""
\r
1017 + " onMouseOver=\"toolTip('"
\r
1018 + alIndex + " " + triplet );
\r
1020 fSize = features.length;
\r
1021 for (f = 0; f < fSize; f++)
\r
1024 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
\r
1025 (features[f].getEnd() >= seq.findPosition(res)))
\r
1027 if (features[f].getType().equals("disulfide bond"))
\r
1029 if (features[f].getBegin() == seq.findPosition(res)
\r
1030 || features[f].getEnd() == seq.findPosition(res))
\r
1032 text.append("<br>disulfide bond " + features[f].getBegin() + ":" +
\r
1033 features[f].getEnd());
\r
1038 text.append("<br>");
\r
1039 text.append(features[f].getType());
\r
1040 if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription()))
\r
1041 text.append(" " + features[f].getDescription());
\r
1043 if (features[f].getValue("status") != null )
\r
1045 text.append(" (" + features[f].getValue("status") + ")");
\r
1052 if(text.length()>1)
\r
1054 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
\r
1055 out.println(text.toString());
\r
1059 out.println("</map></body></html>");
\r
1063 catch (Exception ex)
\r
1065 ex.printStackTrace();
\r
1067 } ///////////END OF IMAGE MAP
\r
1071 int getWrappedHeight()
\r
1073 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
\r
1075 //If headless, seqPanel will have 0 width
\r
1076 if (System.getProperty("java.awt.headless") != null
\r
1077 && System.getProperty("java.awt.headless").equals("true"))
\r
1079 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth();
\r
1082 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
1086 int hgap = av.charHeight;
\r
1087 if (av.scaleAboveWrapped)
\r
1088 hgap += av.charHeight;
\r
1090 int annotationHeight = 0;
\r
1091 if (av.showAnnotation)
\r
1093 annotationHeight = annotationPanel.adjustPanelHeight();
\r
1096 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
1098 + annotationHeight;
\r
1100 int maxwidth = av.alignment.getWidth();
\r
1101 if (av.hasHiddenColumns)
\r
1102 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
1105 int height = ( (maxwidth / chunkWidth) + 1) * cHeight;
\r
1113 * @author $author$
\r
1114 * @version $Revision$
\r
1120 * Creates a new Preview object.
\r
1122 * @param image DOCUMENT ME!
\r
1124 public Preview(Image image)
\r
1126 setResizable(true);
\r
1127 setSize(image.getWidth(this), image.getHeight(this));
\r
1129 getContentPane().setLayout(new BorderLayout());
\r
1130 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
\r
1139 * @author $author$
\r
1140 * @version $Revision$
\r
1142 class PreviewPanel
\r
1148 * Creates a new PreviewPanel object.
\r
1150 * @param image DOCUMENT ME!
\r
1152 public PreviewPanel(Image image)
\r
1154 this.image = image;
\r
1160 * @param g DOCUMENT ME!
\r
1162 public void paintComponent(Graphics g)
\r
1164 if (image != null)
\r
1166 g.drawImage(image, 0, 0, this);
\r
1170 System.out.println("DEBUG:image is null");
\r