2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.datamodel.*;
23 import jalview.jbgui.*;
25 import jalview.schemes.*;
28 import java.awt.event.*;
29 import java.awt.print.*;
42 public class AlignmentPanel extends GAlignmentPanel
43 implements AdjustmentListener, Printable
45 public AlignViewport av;
46 OverviewPanel overviewPanel;
49 IdwidthAdjuster idwidthAdjuster;
52 public AlignFrame alignFrame;
53 ScalePanel scalePanel;
54 AnnotationPanel annotationPanel;
55 AnnotationLabels alabels;
57 // this value is set false when selection area being dragged
58 boolean fastPaint = true;
63 * Creates a new AlignmentPanel object.
65 * @param af DOCUMENT ME!
66 * @param av DOCUMENT ME!
68 public AlignmentPanel(AlignFrame af, final AlignViewport av)
72 seqPanel = new SeqPanel(av, this);
73 idPanel = new IdPanel(av, this);
75 scalePanel = new ScalePanel(av, this);
77 idPanelHolder.add(idPanel, BorderLayout.CENTER);
78 idwidthAdjuster = new IdwidthAdjuster(this);
79 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
81 annotationPanel = new AnnotationPanel(this);
82 alabels = new AnnotationLabels(this);
85 annotationScroller.setViewportView(annotationPanel);
86 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
90 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
91 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
93 setScrollValues(0, 0);
95 adjustAnnotationHeight();
97 setAnnotationVisible(av.getShowAnnotation());
99 hscroll.addAdjustmentListener(this);
100 vscroll.addAdjustmentListener(this);
102 af.addKeyListener(new KeyAdapter()
104 public void keyPressed(KeyEvent evt)
107 && evt.getKeyCode()>=KeyEvent.VK_0
108 && evt.getKeyCode()<=KeyEvent.VK_9)
110 seqPanel.numberPressed(evt.getKeyChar());
113 switch (evt.getKeyCode())
115 case 27: // escape key
116 alignFrame.deselectAllSequenceMenuItem_actionPerformed(null);
120 case KeyEvent.VK_DOWN:
123 seqPanel.moveCursor(0,1);
126 alignFrame.moveSelectedSequences(false);
132 seqPanel.moveCursor(0,-1);
135 alignFrame.moveSelectedSequences(true);
138 case KeyEvent.VK_LEFT:
141 seqPanel.moveCursor(-1,0);
145 case KeyEvent.VK_RIGHT:
148 seqPanel.moveCursor(1,0);
152 case KeyEvent.VK_SPACE:
155 seqPanel.insertGapAtCursor(evt.isControlDown() || evt.isShiftDown());
159 case KeyEvent.VK_DELETE:
160 case KeyEvent.VK_BACK_SPACE:
163 alignFrame.cut_actionPerformed(null);
166 seqPanel.deleteGapAtCursor(evt.isControlDown() || evt.isShiftDown());
173 seqPanel.setCursorRow();
177 if(av.cursorMode && !evt.isControlDown())
179 seqPanel.setCursorColumn();
185 seqPanel.setCursorPosition();
189 case KeyEvent.VK_ENTER:
190 case KeyEvent.VK_COMMA:
193 seqPanel.setCursorRowAndColumn();
200 seqPanel.setSelectionAreaAtCursor(true);
206 seqPanel.setSelectionAreaAtCursor(false);
211 av.cursorMode = ! av.cursorMode;
212 alignFrame.statusBar.setText("Keyboard editing mode is "+
213 (av.cursorMode ? "on" : "off"));
216 seqPanel.seqCanvas.cursorX = av.startRes;
217 seqPanel.seqCanvas.cursorY = av.startSeq;
219 seqPanel.seqCanvas.repaint();
225 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
226 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
227 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
229 javax.help.HelpBroker hb = hs.createHelpBroker();
230 hb.setCurrentID("home");
231 hb.setDisplayed(true);
235 ex.printStackTrace();
240 boolean toggleSeqs = !evt.isControlDown();
241 boolean toggleCols = !evt.isShiftDown();
243 boolean hide = false;
245 SequenceGroup sg = av.getSelectionGroup();
248 if(sg != null && sg.getSize(false) != av.alignment.getHeight())
250 alignFrame.hideSelSequences_actionPerformed(null);
253 else if (!(toggleCols && av.colSel.getSelected().size() > 0))
254 alignFrame.showAllSeqs_actionPerformed(null);
259 if(av.colSel.getSelected().size() > 0)
261 alignFrame.hideSelColumns_actionPerformed(null);
263 av.selectionGroup = sg;
266 alignFrame.showAllColumns_actionPerformed(null);
279 public void fontChanged()
281 // set idCanvas bufferedImage to null
282 // to prevent drawing old image
283 FontMetrics fm = getFontMetrics(av.getFont());
285 scalePanelHolder.setPreferredSize(new Dimension(10,
286 av.charHeight + fm.getDescent()));
287 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
288 av.charHeight + fm.getDescent()));
290 idPanel.idCanvas.gg = null;
291 seqPanel.seqCanvas.img = null;
292 annotationPanel.adjustPanelHeight();
294 Dimension d = calculateIdWidth();
295 d.setSize(d.width + 4, d.height);
296 idPanel.idCanvas.setPreferredSize(d);
297 hscrollFillerPanel.setPreferredSize(d);
299 if (av.getWrapAlignment())
301 int max = av.alignment.getWidth() /
302 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
303 vscroll.setMaximum(max);
304 vscroll.setUnitIncrement(1);
305 vscroll.setVisibleAmount(1);
309 setScrollValues(av.getStartRes(), av.getStartSeq());
312 if (overviewPanel != null)
313 overviewPanel.setBoxPosition();
321 * @return DOCUMENT ME!
323 public Dimension calculateIdWidth()
325 Container c = new Container();
327 FontMetrics fm = c.getFontMetrics(av.font);
328 AlignmentI al = av.getAlignment();
334 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
336 SequenceI s = al.getSequenceAt(i);
338 id = s.getDisplayId(av.getShowJVSuffix());
340 if (fm.stringWidth(id) > idWidth)
342 idWidth = fm.stringWidth(id);
348 // Also check annotation label widths
351 if (al.getAlignmentAnnotation() != null)
353 fm = c.getFontMetrics(alabels.getFont());
355 while (i < al.getAlignmentAnnotation().length)
357 String label = al.getAlignmentAnnotation()[i].label;
359 if (fm.stringWidth(label) > idWidth)
361 idWidth = fm.stringWidth(label);
368 return new Dimension(idWidth, 12);
374 * @param results DOCUMENT ME!
376 public void highlightSearchResults(SearchResults results)
378 seqPanel.seqCanvas.highlightSearchResults(results);
380 // do we need to scroll the panel?
383 SequenceI seq = results.getResultSequence(0);
384 int seqIndex = av.alignment.findIndex(seq);
385 int start = seq.findIndex(results.getResultStart(0)) - 1;
386 int end = seq.findIndex(results.getResultEnd(0)) - 1;
388 if(!av.wrapAlignment)
390 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
391 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
393 setScrollValues(start, seqIndex);
398 scrollToWrappedVisible(start);
403 void scrollToWrappedVisible(int res)
405 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
406 if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) )
408 vscroll.setValue(res / cwidth);
409 av.startRes = vscroll.getValue() * cwidth;
416 * @return DOCUMENT ME!
418 public OverviewPanel getOverviewPanel()
420 return overviewPanel;
426 * @param op DOCUMENT ME!
428 public void setOverviewPanel(OverviewPanel op)
436 * @param b DOCUMENT ME!
438 public void setAnnotationVisible(boolean b)
440 if (!av.wrapAlignment)
442 annotationSpaceFillerHolder.setVisible(b);
443 annotationScroller.setVisible(b);
448 public void adjustAnnotationHeight()
450 javax.swing.SwingUtilities.invokeLater(new Runnable()
454 while(alignFrame.getHeight()==0)
459 int height = annotationPanel.adjustPanelHeight();
461 if (height > alignFrame.getHeight() / 2)
463 height = alignFrame.getHeight() / 2;
466 annotationScroller.setPreferredSize(
467 new Dimension(annotationScroller.getWidth(),
470 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
471 annotationSpaceFillerHolder.getWidth(),
474 annotationPanel.repaint();
483 * @param wrap DOCUMENT ME!
485 public void setWrapAlignment(boolean wrap)
488 scalePanelHolder.setVisible(!wrap);
489 hscroll.setVisible(!wrap);
490 idwidthAdjuster.setVisible(!wrap);
494 annotationScroller.setVisible(false);
495 annotationSpaceFillerHolder.setVisible(false);
497 else if (av.showAnnotation)
499 annotationScroller.setVisible(true);
500 annotationSpaceFillerHolder.setVisible(true);
503 idSpaceFillerPanel1.setVisible(!wrap);
508 // return value is true if the scroll is valid
509 public boolean scrollUp(boolean up)
513 if (vscroll.getValue() < 1)
519 vscroll.setValue(vscroll.getValue() - 1);
523 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
529 vscroll.setValue(vscroll.getValue() + 1);
540 * @param right DOCUMENT ME!
542 * @return DOCUMENT ME!
544 public boolean scrollRight(boolean right)
548 if (hscroll.getValue() < 1)
554 hscroll.setValue(hscroll.getValue() - 1);
558 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
564 hscroll.setValue(hscroll.getValue() + 1);
575 * @param x DOCUMENT ME!
576 * @param y DOCUMENT ME!
578 public void setScrollValues(int x, int y)
581 int width = av.alignment.getWidth();
582 int height = av.alignment.getHeight();
584 if(av.hasHiddenColumns)
585 width = av.getColumnSelection().findColumnPosition(width);
587 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
589 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
590 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
597 if (vextent > height)
602 if ( (hextent + x) > width)
607 if ( (vextent + y) > height)
609 y = height - vextent;
622 hscroll.setValues(x, hextent, 0, width);
623 vscroll.setValues(y, vextent, 0, height);
629 * @param evt DOCUMENT ME!
631 public void adjustmentValueChanged(AdjustmentEvent evt)
634 int oldX = av.getStartRes();
635 int oldY = av.getStartSeq();
637 if (evt.getSource() == hscroll)
639 int x = hscroll.getValue();
642 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
645 if (evt.getSource() == vscroll)
647 int offy = vscroll.getValue();
649 if (av.getWrapAlignment())
653 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
654 seqCanvas.getWidth());
655 av.setStartRes(offy * rowSize);
656 av.setEndRes( (offy + 1) * rowSize);
660 //This is only called if file loaded is a jar file that
661 //was wrapped when saved and user has wrap alignment true
662 //as preference setting
663 SwingUtilities.invokeLater(new Runnable()
667 setScrollValues(av.getStartRes(), av.getStartSeq());
674 av.setStartSeq(offy);
676 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
680 if (overviewPanel != null)
682 overviewPanel.setBoxPosition();
685 int scrollX = av.startRes - oldX;
686 int scrollY = av.startSeq - oldY;
688 if (av.getWrapAlignment() || !fastPaint)
694 // Make sure we're not trying to draw a panel
695 // larger than the visible window
696 if(scrollX>av.endRes-av.startRes)
697 scrollX = av.endRes-av.startRes;
698 else if(scrollX<av.startRes-av.endRes)
699 scrollX = av.startRes - av.endRes;
701 if(scrollX!=0 || scrollY!=0)
703 idPanel.idCanvas.fastPaint(scrollY);
704 seqPanel.seqCanvas.fastPaint(scrollX,
706 scalePanel.repaint();
708 if (av.getShowAnnotation())
710 annotationPanel.fastPaint(scrollX);
719 * @param g DOCUMENT ME!
721 public void paintComponent(Graphics g)
725 Dimension d = idPanel.idCanvas.getPreferredSize();
726 idPanelHolder.setPreferredSize(d);
727 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
730 if (av.getWrapAlignment())
732 int maxwidth = av.alignment.getWidth();
734 if (av.hasHiddenColumns)
735 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
738 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()) +
742 vscroll.setMaximum(max);
743 vscroll.setUnitIncrement(1);
744 vscroll.setVisibleAmount(1);
748 setScrollValues(av.getStartRes(), av.getStartSeq());
751 if( this.getVisibleRect().getBounds() == g.getClipBounds()
752 && overviewPanel != null)
753 overviewPanel.updateOverviewImage();
760 * @param pg DOCUMENT ME!
761 * @param pf DOCUMENT ME!
762 * @param pi DOCUMENT ME!
764 * @return DOCUMENT ME!
766 * @throws PrinterException DOCUMENT ME!
768 public int print(Graphics pg, PageFormat pf, int pi)
769 throws PrinterException
771 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
773 int pwidth = (int) pf.getImageableWidth();
774 int pheight = (int) pf.getImageableHeight();
776 if (av.getWrapAlignment())
778 return printWrappedAlignment(pg, pwidth, pheight, pi);
782 return printUnwrapped(pg, pwidth, pheight, pi);
789 * @param pg DOCUMENT ME!
790 * @param pwidth DOCUMENT ME!
791 * @param pheight DOCUMENT ME!
792 * @param pi DOCUMENT ME!
794 * @return DOCUMENT ME!
796 * @throws PrinterException DOCUMENT ME!
798 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
799 throws PrinterException
801 int idWidth = calculateIdWidth().width + 4;
802 FontMetrics fm = getFontMetrics(av.getFont());
803 int scaleHeight = av.charHeight + fm.getDescent();
805 pg.setColor(Color.white);
806 pg.fillRect(0, 0, pwidth, pheight);
807 pg.setFont(av.getFont());
809 ////////////////////////////////////
810 /// How many sequences and residues can we fit on a printable page?
811 int totalRes = (pwidth - idWidth) / av.getCharWidth();
813 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
816 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
818 /////////////////////////////
819 /// Only print these sequences and residues on this page
822 /////////////////////////////
823 /// Only print these sequences and residues on this page
826 /////////////////////////////
827 /// Only print these sequences and residues on this page
830 /////////////////////////////
831 /// Only print these sequences and residues on this page
833 startRes = (pi % pagesWide) * totalRes;
834 endRes = (startRes + totalRes) - 1;
836 if (endRes > (av.getAlignment().getWidth() - 1))
838 endRes = av.getAlignment().getWidth() - 1;
841 startSeq = (pi / pagesWide) * totalSeq;
842 endSeq = startSeq + totalSeq;
844 if (endSeq > av.getAlignment().getHeight())
846 endSeq = av.getAlignment().getHeight();
849 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
851 if (av.showAnnotation)
853 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
856 pagesHigh /= pheight;
858 if (pi >= (pagesWide * pagesHigh))
860 return Printable.NO_SUCH_PAGE;
864 pg.translate(idWidth, 0);
865 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
866 pg.translate( -idWidth, scaleHeight);
870 Color currentColor = null;
871 Color currentTextColor = null;
873 pg.setFont(new Font(av.getFont().getName(),
875 av.getFont().getSize()));
876 for (int i = startSeq; i < endSeq; i++)
878 if ( (av.getSelectionGroup() != null) &&
879 av.getSelectionGroup().getSequences(false).contains(
880 av.getAlignment().getSequenceAt(i)))
882 currentColor = Color.gray;
883 currentTextColor = Color.black;
887 currentColor = av.getAlignment().getSequenceAt(i).getColor();
888 currentTextColor = Color.black;
891 pg.setColor(currentColor);
892 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
895 pg.setColor(currentTextColor);
897 String string = av.getAlignment().getSequenceAt(i).getDisplayId
898 ( av.getShowJVSuffix());
900 pg.drawString(string, 0,
901 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
902 (av.getCharHeight() / 5));
905 pg.setFont(av.getFont());
907 // draw main sequence panel
908 pg.translate(idWidth, 0);
909 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
911 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
913 pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
914 alabels.drawComponent( (Graphics2D) pg, idWidth);
915 pg.translate(idWidth+3, 0);
916 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
920 return Printable.PAGE_EXISTS;
926 * @param pg DOCUMENT ME!
927 * @param pwidth DOCUMENT ME!
928 * @param pheight DOCUMENT ME!
929 * @param pi DOCUMENT ME!
931 * @return DOCUMENT ME!
933 * @throws PrinterException DOCUMENT ME!
935 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
937 throws PrinterException
940 int annotationHeight = 0;
941 AnnotationLabels labels = null;
942 if (av.showAnnotation)
944 annotationHeight = annotationPanel.adjustPanelHeight();
945 labels = new AnnotationLabels(av);
948 int hgap = av.charHeight;
949 if (av.scaleAboveWrapped)
950 hgap += av.charHeight;
952 int cHeight = av.getAlignment().getHeight() * av.charHeight
956 int idWidth = calculateIdWidth().width + 4;
958 int maxwidth = av.alignment.getWidth();
959 if (av.hasHiddenColumns)
960 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
963 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
966 int totalHeight = cHeight * (maxwidth / resWidth + 1);
968 pg.setColor(Color.white);
969 pg.fillRect(0, 0, pwidth, pheight);
970 pg.setFont(av.getFont());
974 pg.setColor(Color.black);
976 pg.translate(0, -pi * pheight);
978 pg.setClip(0, pi * pheight, pwidth, pheight);
981 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
982 av.getFont().getSize());
987 for (int i = 0; i < av.alignment.getHeight(); i++)
989 SequenceI s = av.alignment.getSequenceAt(i);
990 String string = s.getDisplayId( av.getShowJVSuffix());
992 pg.drawString(string, 0,
993 ( (i * av.charHeight) + ypos + av.charHeight) -
994 (av.charHeight / 5));
1000 (av.getAlignment().getHeight() * av.charHeight));
1002 pg.setFont(av.getFont());
1003 labels.drawComponent(pg, idWidth);
1007 (av.getAlignment().getHeight() * av.charHeight));
1012 while (ypos < totalHeight);
1014 pg.translate(idWidth, 0);
1016 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
1018 if ( (pi * pheight) < totalHeight)
1020 return Printable.PAGE_EXISTS;
1025 return Printable.NO_SUCH_PAGE;
1029 void makeAlignmentImage(int type, File file)
1031 int maxwidth = av.alignment.getWidth();
1032 if (av.hasHiddenColumns)
1033 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1035 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
1036 int width = idPanel.getWidth() + (maxwidth * av.charWidth);
1037 if (idPanel.getWidth() == 0)
1039 width += calculateIdWidth().getWidth() + 4;
1042 if (av.getWrapAlignment())
1044 height = getWrappedHeight();
1045 if (System.getProperty("java.awt.headless") != null
1046 && System.getProperty("java.awt.headless").equals("true"))
1048 width = alignFrame.getWidth() - 22;
1051 width = seqPanel.getWidth() + idPanel.getWidth();
1054 else if (av.getShowAnnotation())
1056 height += annotationPanel.adjustPanelHeight() + 3;
1059 jalview.util.ImageMaker im;
1060 if(type==jalview.util.ImageMaker.PNG)
1061 im = new jalview.util.ImageMaker(this,
1062 jalview.util.ImageMaker.PNG,
1063 "Create PNG image from alignment",
1064 width, height, file, null);
1066 im = new jalview.util.ImageMaker(this,
1067 jalview.util.ImageMaker.EPS,
1068 "Create EPS file from alignment",
1069 width, height, file, alignFrame.getTitle() );
1073 if (av.getWrapAlignment())
1075 if(im.getGraphics()!=null)
1077 printWrappedAlignment(im.getGraphics(), width, height, 0);
1083 if(im.getGraphics()!=null)
1085 printUnwrapped(im.getGraphics(), width, height, 0);
1090 catch (OutOfMemoryError err)
1092 System.out.println("########################\n"
1093 + "OUT OF MEMORY " + file + "\n"
1094 + "########################");
1096 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1097 "Out of Memory Creating Image!!"
1099 "\nSee help files for increasing Java Virtual Machine memory."
1101 JOptionPane.WARNING_MESSAGE);
1102 System.out.println("Create IMAGE: " + err);
1106 catch (Exception ex)
1108 ex.printStackTrace();
1114 public void makeEPS(File epsFile)
1116 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1122 public void makePNG(File pngFile)
1124 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1127 public void makePNGImageMap(File imgMapFile, String imageName)
1129 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1130 //////////////////////////////////////////////
1131 int idWidth = calculateIdWidth().width + 4;
1132 FontMetrics fm = getFontMetrics(av.getFont());
1133 int scaleHeight = av.charHeight + fm.getDescent();
1136 //////////////////////////////////
1137 if (imgMapFile != null)
1141 int s, sSize = av.alignment.getHeight(),
1142 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
1143 StringBuffer text = new StringBuffer();
1144 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1145 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1146 out.println("<img src=\"" + imageName +
1147 "\" border=\"0\" usemap=\"#Map\" >"
1148 + "<map name=\"Map\">");
1150 for (s = 0; s < sSize; s++)
1152 sy = s * av.charHeight + scaleHeight;
1154 SequenceI seq = av.alignment.getSequenceAt(s);
1155 SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures();
1156 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1157 for(res =0; res<alwidth; res++)
1159 text = new StringBuffer();
1161 if(av.alignment.isNucleotide())
1162 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)+"" );
1164 obj = ResidueProperties.aa2Triplet.get(
1165 seq.getCharAt(res) + "");
1170 String triplet = obj.toString();
1171 int alIndex = seq.findPosition(res);
1172 gSize = groups.length;
1173 for (g = 0; g < gSize; g++)
1177 text.append("<area shape=\"rect\" coords=\""
1178 + (idWidth + res * av.charWidth) + ","
1180 + (idWidth + (res + 1) * av.charWidth) + ","
1181 + (av.charHeight + sy) + "\""
1182 + " onMouseOver=\"toolTip('"
1183 + alIndex + " " + triplet );
1186 if(groups[g].getStartRes()<res && groups[g].getEndRes()>res)
1187 text.append("<br><em>" + groups[g].getName() + "</em>");
1190 if (features != null)
1194 text.append("<area shape=\"rect\" coords=\""
1195 + (idWidth + res * av.charWidth) + ","
1197 + (idWidth + (res + 1) * av.charWidth) + ","
1198 + (av.charHeight + sy) + "\""
1199 + " onMouseOver=\"toolTip('"
1200 + alIndex + " " + triplet );
1202 fSize = features.length;
1203 for (f = 0; f < fSize; f++)
1206 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
1207 (features[f].getEnd() >= seq.findPosition(res)))
1209 if (features[f].getType().equals("disulfide bond"))
1211 if (features[f].getBegin() == seq.findPosition(res)
1212 || features[f].getEnd() == seq.findPosition(res))
1214 text.append("<br>disulfide bond " + features[f].getBegin() + ":" +
1215 features[f].getEnd());
1220 text.append("<br>");
1221 text.append(features[f].getType());
1222 if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription()))
1223 text.append(" " + features[f].getDescription());
1225 if (features[f].getValue("status") != null )
1227 text.append(" (" + features[f].getValue("status") + ")");
1236 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1237 out.println(text.toString());
1241 out.println("</map></body></html>");
1245 catch (Exception ex)
1247 ex.printStackTrace();
1249 } ///////////END OF IMAGE MAP
1253 int getWrappedHeight()
1255 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1257 //If headless, seqPanel will have 0 width
1258 if (System.getProperty("java.awt.headless") != null
1259 && System.getProperty("java.awt.headless").equals("true"))
1261 int idWidth = calculateIdWidth().width + 4;
1262 seqPanelWidth = alignFrame.getWidth() - idWidth;
1265 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
1269 int hgap = av.charHeight;
1270 if (av.scaleAboveWrapped)
1271 hgap += av.charHeight;
1273 int annotationHeight = 0;
1274 if (av.showAnnotation)
1276 annotationHeight = annotationPanel.adjustPanelHeight();
1279 int cHeight = av.getAlignment().getHeight() * av.charHeight
1283 int maxwidth = av.alignment.getWidth();
1284 if (av.hasHiddenColumns)
1285 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1288 int height = ( (maxwidth / chunkWidth) + 1) * cHeight;
1297 * @version $Revision$
1303 * Creates a new Preview object.
1305 * @param image DOCUMENT ME!
1307 public Preview(Image image)
1310 setSize(image.getWidth(this), image.getHeight(this));
1312 getContentPane().setLayout(new BorderLayout());
1313 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
1323 * @version $Revision$
1331 * Creates a new PreviewPanel object.
1333 * @param image DOCUMENT ME!
1335 public PreviewPanel(Image image)
1343 * @param g DOCUMENT ME!
1345 public void paintComponent(Graphics g)
1349 g.drawImage(image, 0, 0, this);
1353 System.out.println("DEBUG:image is null");