2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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
23 import java.util.Vector;
26 import java.awt.event.*;
27 import java.awt.print.*;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.jbgui.*;
33 import jalview.schemes.*;
34 import jalview.structure.SelectionSource;
42 public class AlignmentPanel extends GAlignmentPanel implements
43 AdjustmentListener, Printable
45 public AlignViewport av;
47 OverviewPanel overviewPanel;
53 IdwidthAdjuster idwidthAdjuster;
56 public AlignFrame alignFrame;
58 ScalePanel scalePanel;
60 AnnotationPanel annotationPanel;
62 AnnotationLabels alabels;
64 // this value is set false when selection area being dragged
65 boolean fastPaint = true;
72 * Creates a new AlignmentPanel object.
79 public AlignmentPanel(AlignFrame af, final AlignViewport av)
83 seqPanel = new SeqPanel(av, this);
84 idPanel = new IdPanel(av, this);
86 scalePanel = new ScalePanel(av, this);
88 idPanelHolder.add(idPanel, BorderLayout.CENTER);
89 idwidthAdjuster = new IdwidthAdjuster(this);
90 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
92 annotationPanel = new AnnotationPanel(this);
93 alabels = new AnnotationLabels(this);
95 annotationScroller.setViewportView(annotationPanel);
96 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
98 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
99 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
101 setScrollValues(0, 0);
103 setAnnotationVisible(av.getShowAnnotation());
105 hscroll.addAdjustmentListener(this);
106 vscroll.addAdjustmentListener(this);
108 final AlignmentPanel ap = this;
109 av.addPropertyChangeListener(new PropertyChangeListener()
111 public void propertyChange(PropertyChangeEvent evt)
113 if (evt.getPropertyName().equals("alignment"))
115 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
121 adjustAnnotationHeight();
125 public void alignmentChanged()
127 av.alignmentChanged(this);
129 alignFrame.updateEditMenuBar();
131 paintAlignment(true);
138 public void fontChanged()
140 // set idCanvas bufferedImage to null
141 // to prevent drawing old image
142 FontMetrics fm = getFontMetrics(av.getFont());
144 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
146 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
149 idPanel.idCanvas.gg = null;
150 seqPanel.seqCanvas.img = null;
151 annotationPanel.adjustPanelHeight();
153 Dimension d = calculateIdWidth();
154 d.setSize(d.width + 4, d.height);
155 idPanel.idCanvas.setPreferredSize(d);
156 hscrollFillerPanel.setPreferredSize(d);
158 if (overviewPanel != null)
160 overviewPanel.setBoxPosition();
167 * Calculate the width of the alignment labels based on the displayed names
168 * and any bounds on label width set in preferences.
170 * @return Dimension giving the maximum width of the alignment label panel
171 * that should be used.
173 public Dimension calculateIdWidth()
175 Container c = new Container();
177 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
178 Font.ITALIC, av.font.getSize()));
180 AlignmentI al = av.getAlignment();
181 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
182 int maxwidth = Math.max(20, Math.min(afwidth - 200, (int) 2 * afwidth
188 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
190 SequenceI s = al.getSequenceAt(i);
192 id = s.getDisplayId(av.getShowJVSuffix());
194 if (fm.stringWidth(id) > idWidth)
196 idWidth = fm.stringWidth(id);
202 // Also check annotation label widths
205 if (al.getAlignmentAnnotation() != null)
207 fm = c.getFontMetrics(alabels.getFont());
209 while (i < al.getAlignmentAnnotation().length)
211 String label = al.getAlignmentAnnotation()[i].label;
213 if (fm.stringWidth(label) > idWidth)
215 idWidth = fm.stringWidth(label);
222 return new Dimension(Math.min(maxwidth, idWidth), 12);
231 public void highlightSearchResults(SearchResults results)
233 scrollToPosition(results);
234 seqPanel.seqCanvas.highlightSearchResults(results);
238 * scroll the view to show the position of the highlighted region in results
239 * (if any) and redraw the overview
243 public boolean scrollToPosition(SearchResults results)
245 return scrollToPosition(results, true);
249 * scroll the view to show the position of the highlighted region in results
253 * @param redrawOverview
254 * - when set, the overview will be recalculated (takes longer)
255 * @return false if results were not found
257 public boolean scrollToPosition(SearchResults results,
258 boolean redrawOverview)
260 int startv, endv, starts, ends, width;
261 // TODO: properly locate search results in view when large numbers of hidden
262 // columns exist before highlighted region
263 // do we need to scroll the panel?
264 // TODO: tons of nullpointereexceptions raised here.
265 if (results != null && results.getSize() > 0 && av != null
266 && av.alignment != null)
268 int seqIndex = av.alignment.findIndex(results);
273 SequenceI seq = av.alignment.getSequenceAt(seqIndex);
275 int[] r = results.getResults(seq, 0, av.alignment.getWidth()); // results.getResults(seq,
278 // TODO: VAMSAS: fix hidden column issue where scroll to left from C
279 // terminus is not visible
290 if (end == seq.getEnd())
294 if (!av.wrapAlignment)
296 if ((startv = av.getStartRes()) >= start)
298 setScrollValues(start - 1, seqIndex);
300 else if ((endv = av.getEndRes()) <= end)
302 setScrollValues(startv + 1 + end - endv, seqIndex);
304 else if ((starts = av.getStartSeq()) > seqIndex)
306 setScrollValues(av.getStartRes(), seqIndex);
308 else if ((ends = av.getEndSeq()) <= seqIndex)
310 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
315 scrollToWrappedVisible(start);
318 if (!redrawOverview && overviewPanel != null)
320 overviewPanel.setBoxPosition();
322 paintAlignment(!redrawOverview);
326 void scrollToWrappedVisible(int res)
328 int cwidth = seqPanel.seqCanvas
329 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
330 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
332 vscroll.setValue((res / cwidth));
333 av.startRes = vscroll.getValue() * cwidth;
341 * @return DOCUMENT ME!
343 public OverviewPanel getOverviewPanel()
345 return overviewPanel;
354 public void setOverviewPanel(OverviewPanel op)
365 public void setAnnotationVisible(boolean b)
367 if (!av.wrapAlignment)
369 annotationSpaceFillerHolder.setVisible(b);
370 annotationScroller.setVisible(b);
375 public void adjustAnnotationHeight()
377 // TODO: display vertical annotation scrollbar if necessary
378 // this is called after loading new annotation onto alignment
379 if (alignFrame.getHeight() == 0)
381 System.out.println("NEEDS FIXING");
384 int height = annotationPanel.adjustPanelHeight();
386 if (hscroll.isVisible())
388 height += hscroll.getPreferredSize().height;
390 if (height > alignFrame.getHeight() / 2)
392 height = alignFrame.getHeight() / 2;
397 annotationScroller.setPreferredSize(new Dimension(annotationScroller
398 .getWidth(), height));
400 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
401 annotationSpaceFillerHolder.getWidth(), height));
402 annotationScroller.validate();// repaint();
412 public void setWrapAlignment(boolean wrap)
415 scalePanelHolder.setVisible(!wrap);
416 hscroll.setVisible(!wrap);
417 idwidthAdjuster.setVisible(!wrap);
421 annotationScroller.setVisible(false);
422 annotationSpaceFillerHolder.setVisible(false);
424 else if (av.showAnnotation)
426 annotationScroller.setVisible(true);
427 annotationSpaceFillerHolder.setVisible(true);
430 idSpaceFillerPanel1.setVisible(!wrap);
435 // return value is true if the scroll is valid
436 public boolean scrollUp(boolean up)
440 if (vscroll.getValue() < 1)
446 vscroll.setValue(vscroll.getValue() - 1);
450 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
456 vscroll.setValue(vscroll.getValue() + 1);
470 * @return DOCUMENT ME!
472 public boolean scrollRight(boolean right)
476 if (hscroll.getValue() < 1)
482 hscroll.setValue(hscroll.getValue() - 1);
486 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
492 hscroll.setValue(hscroll.getValue() + 1);
508 public void setScrollValues(int x, int y)
510 // System.err.println("Scroll to "+x+","+y);
511 if (av == null || av.alignment == null)
515 int width = av.alignment.getWidth();
516 int height = av.alignment.getHeight();
518 if (av.hasHiddenColumns)
520 width = av.getColumnSelection().findColumnPosition(width);
523 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
525 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
526 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
533 if (vextent > height)
538 if ((hextent + x) > width)
543 if ((vextent + y) > height)
545 y = height - vextent;
558 hscroll.setValues(x, hextent, 0, width);
559 vscroll.setValues(y, vextent, 0, height);
568 public void adjustmentValueChanged(AdjustmentEvent evt)
571 int oldX = av.getStartRes();
572 int oldY = av.getStartSeq();
574 if (evt.getSource() == hscroll)
576 int x = hscroll.getValue();
579 .setEndRes((x + (seqPanel.seqCanvas.getWidth() / av
580 .getCharWidth())) - 1);
583 if (evt.getSource() == vscroll)
585 int offy = vscroll.getValue();
587 if (av.getWrapAlignment())
591 int rowSize = seqPanel.seqCanvas
592 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
593 av.setStartRes(offy * rowSize);
594 av.setEndRes((offy + 1) * rowSize);
598 // This is only called if file loaded is a jar file that
599 // was wrapped when saved and user has wrap alignment true
600 // as preference setting
601 SwingUtilities.invokeLater(new Runnable()
605 setScrollValues(av.getStartRes(), av.getStartSeq());
612 av.setStartSeq(offy);
614 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
618 if (overviewPanel != null)
620 overviewPanel.setBoxPosition();
623 int scrollX = av.startRes - oldX;
624 int scrollY = av.startSeq - oldY;
626 if (av.getWrapAlignment() || !fastPaint)
632 // Make sure we're not trying to draw a panel
633 // larger than the visible window
634 if (scrollX > av.endRes - av.startRes)
636 scrollX = av.endRes - av.startRes;
638 else if (scrollX < av.startRes - av.endRes)
640 scrollX = av.startRes - av.endRes;
643 if (scrollX != 0 || scrollY != 0)
645 idPanel.idCanvas.fastPaint(scrollY);
646 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
647 scalePanel.repaint();
649 if (av.getShowAnnotation())
651 annotationPanel.fastPaint(scrollX);
657 public void paintAlignment(boolean updateOverview)
663 jalview.structure.StructureSelectionManager
664 .getStructureSelectionManager().sequenceColoursChanged(this);
666 if (overviewPanel != null)
668 overviewPanel.updateOverviewImage();
679 public void paintComponent(Graphics g)
683 Dimension d = idPanel.idCanvas.getPreferredSize();
684 idPanelHolder.setPreferredSize(d);
685 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
688 if (av.getWrapAlignment())
690 int maxwidth = av.alignment.getWidth();
692 if (av.hasHiddenColumns)
694 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
697 int canvasWidth = seqPanel.seqCanvas
698 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
703 .getWrappedCanvasWidth(seqPanel.seqCanvas
705 vscroll.setMaximum(max);
706 vscroll.setUnitIncrement(1);
707 vscroll.setVisibleAmount(1);
712 setScrollValues(av.getStartRes(), av.getStartSeq());
726 * @return DOCUMENT ME!
728 * @throws PrinterException
731 public int print(Graphics pg, PageFormat pf, int pi)
732 throws PrinterException
734 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
736 int pwidth = (int) pf.getImageableWidth();
737 int pheight = (int) pf.getImageableHeight();
739 if (av.getWrapAlignment())
741 return printWrappedAlignment(pg, pwidth, pheight, pi);
745 return printUnwrapped(pg, pwidth, pheight, pi);
761 * @return DOCUMENT ME!
763 * @throws PrinterException
766 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
767 throws PrinterException
769 int idWidth = getVisibleIdWidth();
770 FontMetrics fm = getFontMetrics(av.getFont());
771 int scaleHeight = av.charHeight + fm.getDescent();
773 pg.setColor(Color.white);
774 pg.fillRect(0, 0, pwidth, pheight);
775 pg.setFont(av.getFont());
777 // //////////////////////////////////
778 // / How many sequences and residues can we fit on a printable page?
779 int totalRes = (pwidth - idWidth) / av.getCharWidth();
781 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
783 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
785 // ///////////////////////////
786 // / Only print these sequences and residues on this page
789 // ///////////////////////////
790 // / Only print these sequences and residues on this page
793 // ///////////////////////////
794 // / Only print these sequences and residues on this page
797 // ///////////////////////////
798 // / Only print these sequences and residues on this page
800 startRes = (pi % pagesWide) * totalRes;
801 endRes = (startRes + totalRes) - 1;
803 if (endRes > (av.getAlignment().getWidth() - 1))
805 endRes = av.getAlignment().getWidth() - 1;
808 startSeq = (pi / pagesWide) * totalSeq;
809 endSeq = startSeq + totalSeq;
811 if (endSeq > av.getAlignment().getHeight())
813 endSeq = av.getAlignment().getHeight();
816 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
818 if (av.showAnnotation)
820 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
823 pagesHigh /= pheight;
825 if (pi >= (pagesWide * pagesHigh))
827 return Printable.NO_SUCH_PAGE;
831 pg.translate(idWidth, 0);
832 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
834 pg.translate(-idWidth, scaleHeight);
838 Color currentColor = null;
839 Color currentTextColor = null;
841 pg.setFont(idPanel.idCanvas.idfont);
844 for (int i = startSeq; i < endSeq; i++)
846 seq = av.getAlignment().getSequenceAt(i);
847 if ((av.getSelectionGroup() != null)
848 && av.getSelectionGroup().getSequences(null).contains(seq))
850 currentColor = Color.gray;
851 currentTextColor = Color.black;
855 currentColor = av.getSequenceColour(seq);
856 currentTextColor = Color.black;
859 pg.setColor(currentColor);
860 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, av
863 pg.setColor(currentTextColor);
866 if (av.rightAlignIds)
868 fm = pg.getFontMetrics();
870 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
874 pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
875 (((i - startSeq) * av.charHeight) + av.getCharHeight())
876 - (av.getCharHeight() / 5));
879 pg.setFont(av.getFont());
881 // draw main sequence panel
882 pg.translate(idWidth, 0);
883 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
885 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
887 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
888 alabels.drawComponent((Graphics2D) pg, idWidth);
889 pg.translate(idWidth + 3, 0);
890 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
893 return Printable.PAGE_EXISTS;
908 * @return DOCUMENT ME!
910 * @throws PrinterException
913 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
914 int pi) throws PrinterException
917 int annotationHeight = 0;
918 AnnotationLabels labels = null;
919 if (av.showAnnotation)
921 annotationHeight = annotationPanel.adjustPanelHeight();
922 labels = new AnnotationLabels(av);
925 int hgap = av.charHeight;
926 if (av.scaleAboveWrapped)
928 hgap += av.charHeight;
931 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
934 int idWidth = getVisibleIdWidth();
936 int maxwidth = av.alignment.getWidth();
937 if (av.hasHiddenColumns)
939 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
942 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
945 int totalHeight = cHeight * (maxwidth / resWidth + 1);
947 pg.setColor(Color.white);
948 pg.fillRect(0, 0, pwidth, pheight);
949 pg.setFont(av.getFont());
953 pg.setColor(Color.black);
955 pg.translate(0, -pi * pheight);
957 pg.setClip(0, pi * pheight, pwidth, pheight);
963 for (int i = 0; i < av.alignment.getHeight(); i++)
965 pg.setFont(idPanel.idCanvas.idfont);
966 SequenceI s = av.alignment.getSequenceAt(i);
967 String string = s.getDisplayId(av.getShowJVSuffix());
969 if (av.rightAlignIds)
971 FontMetrics fm = pg.getFontMetrics();
972 xPos = idWidth - fm.stringWidth(string) - 4;
974 pg.drawString(string, xPos,
975 ((i * av.charHeight) + ypos + av.charHeight)
976 - (av.charHeight / 5));
980 pg.translate(-3, ypos
981 + (av.getAlignment().getHeight() * av.charHeight));
983 pg.setFont(av.getFont());
984 labels.drawComponent(pg, idWidth);
985 pg.translate(+3, -ypos
986 - (av.getAlignment().getHeight() * av.charHeight));
990 } while (ypos < totalHeight);
992 pg.translate(idWidth, 0);
994 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
997 if ((pi * pheight) < totalHeight)
999 return Printable.PAGE_EXISTS;
1004 return Printable.NO_SUCH_PAGE;
1008 int getVisibleIdWidth()
1010 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1011 : calculateIdWidth().width + 4;
1014 void makeAlignmentImage(int type, File file)
1016 int maxwidth = av.alignment.getWidth();
1017 if (av.hasHiddenColumns)
1019 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1022 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1023 + scalePanel.getHeight();
1024 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1026 if (av.getWrapAlignment())
1028 height = getWrappedHeight();
1029 if (System.getProperty("java.awt.headless") != null
1030 && System.getProperty("java.awt.headless").equals("true"))
1032 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1033 - alignFrame.getInsets().left
1034 - alignFrame.getInsets().right;
1038 width = seqPanel.getWidth() + getVisibleIdWidth();
1042 else if (av.getShowAnnotation())
1044 height += annotationPanel.adjustPanelHeight() + 3;
1050 jalview.util.ImageMaker im;
1051 if (type == jalview.util.ImageMaker.PNG)
1053 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1054 "Create PNG image from alignment", width, height, file,
1059 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1060 "Create EPS file from alignment", width, height, file,
1061 alignFrame.getTitle());
1064 if (av.getWrapAlignment())
1066 if (im.getGraphics() != null)
1068 printWrappedAlignment(im.getGraphics(), width, height, 0);
1074 if (im.getGraphics() != null)
1076 printUnwrapped(im.getGraphics(), width, height, 0);
1080 } catch (OutOfMemoryError err)
1083 System.out.println("########################\n" + "OUT OF MEMORY "
1084 + file + "\n" + "########################");
1085 new OOMWarning("Creating Image for " + file, err);
1086 // System.out.println("Create IMAGE: " + err);
1087 } catch (Exception ex)
1089 ex.printStackTrace();
1096 public void makeEPS(File epsFile)
1098 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1104 public void makePNG(File pngFile)
1106 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1109 public void makePNGImageMap(File imgMapFile, String imageName)
1111 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1112 // ////////////////////////////////////////////
1113 int idWidth = getVisibleIdWidth();
1114 FontMetrics fm = getFontMetrics(av.getFont());
1115 int scaleHeight = av.charHeight + fm.getDescent();
1118 // ////////////////////////////////
1119 if (imgMapFile != null)
1123 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1124 .getWidth(), g, gSize, f, fSize, sy;
1125 StringBuffer text = new StringBuffer();
1126 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1127 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1128 out.println("<img src=\"" + imageName
1129 + "\" border=\"0\" usemap=\"#Map\" >"
1130 + "<map name=\"Map\">");
1132 for (s = 0; s < sSize; s++)
1134 sy = s * av.charHeight + scaleHeight;
1136 SequenceI seq = av.alignment.getSequenceAt(s);
1137 SequenceFeature[] features = seq.getDatasetSequence()
1138 .getSequenceFeatures();
1139 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1140 for (res = 0; res < alwidth; res++)
1142 text = new StringBuffer();
1144 if (av.alignment.isNucleotide())
1146 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1151 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1160 String triplet = obj.toString();
1161 int alIndex = seq.findPosition(res);
1162 gSize = groups.length;
1163 for (g = 0; g < gSize; g++)
1165 if (text.length() < 1)
1167 text.append("<area shape=\"rect\" coords=\""
1168 + (idWidth + res * av.charWidth) + "," + sy + ","
1169 + (idWidth + (res + 1) * av.charWidth) + ","
1170 + (av.charHeight + sy) + "\""
1171 + " onMouseOver=\"toolTip('" + alIndex + " "
1175 if (groups[g].getStartRes() < res
1176 && groups[g].getEndRes() > res)
1178 text.append("<br><em>" + groups[g].getName() + "</em>");
1182 if (features != null)
1184 if (text.length() < 1)
1186 text.append("<area shape=\"rect\" coords=\""
1187 + (idWidth + res * av.charWidth) + "," + sy + ","
1188 + (idWidth + (res + 1) * av.charWidth) + ","
1189 + (av.charHeight + sy) + "\""
1190 + " onMouseOver=\"toolTip('" + alIndex + " "
1193 fSize = features.length;
1194 for (f = 0; f < fSize; f++)
1197 if ((features[f].getBegin() <= seq.findPosition(res))
1198 && (features[f].getEnd() >= seq.findPosition(res)))
1200 if (features[f].getType().equals("disulfide bond"))
1202 if (features[f].getBegin() == seq.findPosition(res)
1203 || features[f].getEnd() == seq
1206 text.append("<br>disulfide bond "
1207 + features[f].getBegin() + ":"
1208 + features[f].getEnd());
1213 text.append("<br>");
1214 text.append(features[f].getType());
1215 if (features[f].getDescription() != null
1216 && !features[f].getType().equals(
1217 features[f].getDescription()))
1219 text.append(" " + features[f].getDescription());
1222 if (features[f].getValue("status") != null)
1224 text.append(" (" + features[f].getValue("status")
1232 if (text.length() > 1)
1234 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1235 out.println(text.toString());
1239 out.println("</map></body></html>");
1242 } catch (Exception ex)
1244 ex.printStackTrace();
1246 } // /////////END OF IMAGE MAP
1250 int getWrappedHeight()
1252 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1254 if (System.getProperty("java.awt.headless") != null
1255 && System.getProperty("java.awt.headless").equals("true"))
1257 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1258 - vscroll.getPreferredSize().width
1259 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1262 int chunkWidth = seqPanel.seqCanvas
1263 .getWrappedCanvasWidth(seqPanelWidth);
1265 int hgap = av.charHeight;
1266 if (av.scaleAboveWrapped)
1268 hgap += av.charHeight;
1271 int annotationHeight = 0;
1272 if (av.showAnnotation)
1274 annotationHeight = annotationPanel.adjustPanelHeight();
1277 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1280 int maxwidth = av.alignment.getWidth();
1281 if (av.hasHiddenColumns)
1283 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1286 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1292 * close the panel - deregisters all listeners and nulls any references to
1295 public void closePanel()
1297 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1298 .getStructureSelectionManager();
1299 ssm.removeStructureViewerListener(seqPanel, null);
1300 ssm.removeSelectionListener(seqPanel);
1301 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1302 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1303 PaintRefresher.RemoveComponent(this);
1306 av.alignment = null;
1311 if (Cache.log.isDebugEnabled())
1313 Cache.log.warn("Closing alignment panel which is already closed.");
1319 * hides or shows dynamic annotation rows based on groups and av state flags
1321 public void updateAnnotation()
1323 boolean updateCalcs = false;
1324 boolean conv = av.isShowGroupConservation();
1325 boolean cons = av.isShowGroupConsensus();
1326 boolean sortg = true;
1328 // remove old automatic annotation
1329 // add any new annotation
1331 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1332 // intersect alignment annotation with alignment groups
1334 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1335 for (int an = 0; an < aan.length; an++)
1337 if (aan[an].autoCalculated && aan[an].groupRef != null)
1339 av.alignment.deleteAnnotation(aan[an]);
1344 for (int g = 0; g < gr.size(); g++)
1346 updateCalcs = false;
1347 sg = (SequenceGroup) gr.elementAt(g);
1352 av.alignment.addAnnotation(sg.getConservationRow(),0);
1357 av.alignment.addAnnotation(sg.getConsensus(),0);
1359 // refresh the annotation rows
1362 sg.recalcConservation();
1365 adjustAnnotationHeight();