2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
22 import java.util.Hashtable;
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,
183 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
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);
226 * Highlight the given results on the alignment.
229 public void highlightSearchResults(SearchResults results)
231 scrollToPosition(results);
232 seqPanel.seqCanvas.highlightSearchResults(results);
236 * scroll the view to show the position of the highlighted region in results
237 * (if any) and redraw the overview
241 public boolean scrollToPosition(SearchResults results)
243 return scrollToPosition(results, true);
247 * scroll the view to show the position of the highlighted region in results
251 * @param redrawOverview
252 * - when set, the overview will be recalculated (takes longer)
253 * @return false if results were not found
255 public boolean scrollToPosition(SearchResults results,
256 boolean redrawOverview)
258 int startv, endv, starts, ends, width;
259 // TODO: properly locate search results in view when large numbers of hidden
260 // columns exist before highlighted region
261 // do we need to scroll the panel?
262 // TODO: tons of nullpointereexceptions raised here.
263 if (results != null && results.getSize() > 0 && av != null
264 && av.alignment != null)
266 int seqIndex = av.alignment.findIndex(results);
271 SequenceI seq = av.alignment.getSequenceAt(seqIndex);
273 int[] r=results.getResults(seq, 0, av.alignment.getWidth());
280 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
286 if (end == seq.getEnd())
290 if (av.hasHiddenColumns)
292 start = av.getColumnSelection().findColumnPosition(start);
293 end = av.getColumnSelection().findColumnPosition(end);
296 if (!av.colSel.isVisible(r[0]))
298 // don't scroll - position isn't visible
303 if (!av.wrapAlignment)
305 if ((startv = av.getStartRes()) >= start)
307 setScrollValues(start - 1, seqIndex);
309 else if ((endv = av.getEndRes()) <= end)
311 setScrollValues(startv + 1 + end - endv, seqIndex);
313 else if ((starts = av.getStartSeq()) > seqIndex)
315 setScrollValues(av.getStartRes(), seqIndex);
317 else if ((ends = av.getEndSeq()) <= seqIndex)
319 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
324 scrollToWrappedVisible(start);
327 if (!redrawOverview && overviewPanel != null)
329 overviewPanel.setBoxPosition();
331 paintAlignment(!redrawOverview);
335 void scrollToWrappedVisible(int res)
337 int cwidth = seqPanel.seqCanvas
338 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
339 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
341 vscroll.setValue((res / cwidth));
342 av.startRes = vscroll.getValue() * cwidth;
350 * @return DOCUMENT ME!
352 public OverviewPanel getOverviewPanel()
354 return overviewPanel;
363 public void setOverviewPanel(OverviewPanel op)
374 public void setAnnotationVisible(boolean b)
376 if (!av.wrapAlignment)
378 annotationSpaceFillerHolder.setVisible(b);
379 annotationScroller.setVisible(b);
384 public void adjustAnnotationHeight()
386 // TODO: display vertical annotation scrollbar if necessary
387 // this is called after loading new annotation onto alignment
388 if (alignFrame.getHeight() == 0)
390 System.out.println("NEEDS FIXING");
393 int height = annotationPanel.adjustPanelHeight();
395 if (hscroll.isVisible())
397 height += hscroll.getPreferredSize().height;
399 if (height > alignFrame.getHeight() / 2)
401 height = alignFrame.getHeight() / 2;
406 annotationScroller.setPreferredSize(new Dimension(annotationScroller
407 .getWidth(), height));
409 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
410 annotationSpaceFillerHolder.getWidth(), height));
411 annotationScroller.validate();// repaint();
422 public void setWrapAlignment(boolean wrap)
425 scalePanelHolder.setVisible(!wrap);
426 hscroll.setVisible(!wrap);
427 idwidthAdjuster.setVisible(!wrap);
431 annotationScroller.setVisible(false);
432 annotationSpaceFillerHolder.setVisible(false);
434 else if (av.showAnnotation)
436 annotationScroller.setVisible(true);
437 annotationSpaceFillerHolder.setVisible(true);
440 idSpaceFillerPanel1.setVisible(!wrap);
445 // return value is true if the scroll is valid
446 public boolean scrollUp(boolean up)
450 if (vscroll.getValue() < 1)
456 vscroll.setValue(vscroll.getValue() - 1);
460 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
466 vscroll.setValue(vscroll.getValue() + 1);
480 * @return DOCUMENT ME!
482 public boolean scrollRight(boolean right)
486 if (hscroll.getValue() < 1)
492 hscroll.setValue(hscroll.getValue() - 1);
496 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
502 hscroll.setValue(hscroll.getValue() + 1);
511 * Adjust row/column scrollers to show a visible position in the alignment.
513 * @param x visible column to scroll to
515 * @param y visible row to scroll to
518 public void setScrollValues(int x, int y)
520 // System.err.println("Scroll to "+x+","+y);
521 if (av == null || av.alignment == null)
525 int width = av.alignment.getWidth();
526 int height = av.alignment.getHeight();
528 if (av.hasHiddenColumns)
530 width = av.getColumnSelection().findColumnPosition(width);
533 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
535 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
536 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
543 if (vextent > height)
548 if ((hextent + x) > width)
553 if ((vextent + y) > height)
555 y = height - vextent;
568 hscroll.setValues(x, hextent, 0, width);
569 vscroll.setValues(y, vextent, 0, height);
578 public void adjustmentValueChanged(AdjustmentEvent evt)
581 int oldX = av.getStartRes();
582 int oldY = av.getStartSeq();
584 if (evt.getSource() == hscroll)
586 int x = hscroll.getValue();
588 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
591 if (evt.getSource() == vscroll)
593 int offy = vscroll.getValue();
595 if (av.getWrapAlignment())
599 int rowSize = seqPanel.seqCanvas
600 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
601 av.setStartRes(offy * rowSize);
602 av.setEndRes((offy + 1) * rowSize);
606 // This is only called if file loaded is a jar file that
607 // was wrapped when saved and user has wrap alignment true
608 // as preference setting
609 SwingUtilities.invokeLater(new Runnable()
613 setScrollValues(av.getStartRes(), av.getStartSeq());
620 av.setStartSeq(offy);
622 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
626 if (overviewPanel != null)
628 overviewPanel.setBoxPosition();
631 int scrollX = av.startRes - oldX;
632 int scrollY = av.startSeq - oldY;
634 if (av.getWrapAlignment() || !fastPaint)
640 // Make sure we're not trying to draw a panel
641 // larger than the visible window
642 if (scrollX > av.endRes - av.startRes)
644 scrollX = av.endRes - av.startRes;
646 else if (scrollX < av.startRes - av.endRes)
648 scrollX = av.startRes - av.endRes;
651 if (scrollX != 0 || scrollY != 0)
653 idPanel.idCanvas.fastPaint(scrollY);
654 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
655 scalePanel.repaint();
657 if (av.getShowAnnotation())
659 annotationPanel.fastPaint(scrollX);
665 public void paintAlignment(boolean updateOverview)
671 jalview.structure.StructureSelectionManager
672 .getStructureSelectionManager().sequenceColoursChanged(this);
674 if (overviewPanel != null)
676 overviewPanel.updateOverviewImage();
687 public void paintComponent(Graphics g)
691 Dimension d = idPanel.idCanvas.getPreferredSize();
692 idPanelHolder.setPreferredSize(d);
693 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
696 if (av.getWrapAlignment())
698 int maxwidth = av.alignment.getWidth();
700 if (av.hasHiddenColumns)
702 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
705 int canvasWidth = seqPanel.seqCanvas
706 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
711 .getWrappedCanvasWidth(seqPanel.seqCanvas
713 vscroll.setMaximum(max);
714 vscroll.setUnitIncrement(1);
715 vscroll.setVisibleAmount(1);
720 setScrollValues(av.getStartRes(), av.getStartSeq());
734 * @return DOCUMENT ME!
736 * @throws PrinterException
739 public int print(Graphics pg, PageFormat pf, int pi)
740 throws PrinterException
742 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
744 int pwidth = (int) pf.getImageableWidth();
745 int pheight = (int) pf.getImageableHeight();
747 if (av.getWrapAlignment())
749 return printWrappedAlignment(pg, pwidth, pheight, pi);
753 return printUnwrapped(pg, pwidth, pheight, pi);
769 * @return DOCUMENT ME!
771 * @throws PrinterException
774 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
775 throws PrinterException
777 int idWidth = getVisibleIdWidth();
778 FontMetrics fm = getFontMetrics(av.getFont());
779 int scaleHeight = av.charHeight + fm.getDescent();
781 pg.setColor(Color.white);
782 pg.fillRect(0, 0, pwidth, pheight);
783 pg.setFont(av.getFont());
785 // //////////////////////////////////
786 // / How many sequences and residues can we fit on a printable page?
787 int totalRes = (pwidth - idWidth) / av.getCharWidth();
789 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
791 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
793 // ///////////////////////////
794 // / Only print these sequences and residues on this page
797 // ///////////////////////////
798 // / Only print these sequences and residues on this page
801 // ///////////////////////////
802 // / Only print these sequences and residues on this page
805 // ///////////////////////////
806 // / Only print these sequences and residues on this page
808 startRes = (pi % pagesWide) * totalRes;
809 endRes = (startRes + totalRes) - 1;
811 if (endRes > (av.getAlignment().getWidth() - 1))
813 endRes = av.getAlignment().getWidth() - 1;
816 startSeq = (pi / pagesWide) * totalSeq;
817 endSeq = startSeq + totalSeq;
819 if (endSeq > av.getAlignment().getHeight())
821 endSeq = av.getAlignment().getHeight();
824 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
826 if (av.showAnnotation)
828 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
831 pagesHigh /= pheight;
833 if (pi >= (pagesWide * pagesHigh))
835 return Printable.NO_SUCH_PAGE;
839 pg.translate(idWidth, 0);
840 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
842 pg.translate(-idWidth, scaleHeight);
846 Color currentColor = null;
847 Color currentTextColor = null;
849 pg.setFont(idPanel.idCanvas.idfont);
852 for (int i = startSeq; i < endSeq; i++)
854 seq = av.getAlignment().getSequenceAt(i);
855 if ((av.getSelectionGroup() != null)
856 && av.getSelectionGroup().getSequences(null).contains(seq))
858 currentColor = Color.gray;
859 currentTextColor = Color.black;
863 currentColor = av.getSequenceColour(seq);
864 currentTextColor = Color.black;
867 pg.setColor(currentColor);
868 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
871 pg.setColor(currentTextColor);
874 if (av.rightAlignIds)
876 fm = pg.getFontMetrics();
878 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
883 seq.getDisplayId(av.getShowJVSuffix()),
885 (((i - startSeq) * av.charHeight) + av.getCharHeight())
886 - (av.getCharHeight() / 5));
889 pg.setFont(av.getFont());
891 // draw main sequence panel
892 pg.translate(idWidth, 0);
893 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
895 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
897 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
898 alabels.drawComponent((Graphics2D) pg, idWidth);
899 pg.translate(idWidth + 3, 0);
900 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
903 return Printable.PAGE_EXISTS;
918 * @return DOCUMENT ME!
920 * @throws PrinterException
923 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
924 int pi) throws PrinterException
927 int annotationHeight = 0;
928 AnnotationLabels labels = null;
929 if (av.showAnnotation)
931 annotationHeight = annotationPanel.adjustPanelHeight();
932 labels = new AnnotationLabels(av);
935 int hgap = av.charHeight;
936 if (av.scaleAboveWrapped)
938 hgap += av.charHeight;
941 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
944 int idWidth = getVisibleIdWidth();
946 int maxwidth = av.alignment.getWidth();
947 if (av.hasHiddenColumns)
949 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
952 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
955 int totalHeight = cHeight * (maxwidth / resWidth + 1);
957 pg.setColor(Color.white);
958 pg.fillRect(0, 0, pwidth, pheight);
959 pg.setFont(av.getFont());
963 pg.setColor(Color.black);
965 pg.translate(0, -pi * pheight);
967 pg.setClip(0, pi * pheight, pwidth, pheight);
973 for (int i = 0; i < av.alignment.getHeight(); i++)
975 pg.setFont(idPanel.idCanvas.idfont);
976 SequenceI s = av.alignment.getSequenceAt(i);
977 String string = s.getDisplayId(av.getShowJVSuffix());
979 if (av.rightAlignIds)
981 FontMetrics fm = pg.getFontMetrics();
982 xPos = idWidth - fm.stringWidth(string) - 4;
984 pg.drawString(string, xPos,
985 ((i * av.charHeight) + ypos + av.charHeight)
986 - (av.charHeight / 5));
990 pg.translate(-3, ypos
991 + (av.getAlignment().getHeight() * av.charHeight));
993 pg.setFont(av.getFont());
994 labels.drawComponent(pg, idWidth);
995 pg.translate(+3, -ypos
996 - (av.getAlignment().getHeight() * av.charHeight));
1000 } while (ypos < totalHeight);
1002 pg.translate(idWidth, 0);
1004 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1007 if ((pi * pheight) < totalHeight)
1009 return Printable.PAGE_EXISTS;
1014 return Printable.NO_SUCH_PAGE;
1018 int getVisibleIdWidth()
1020 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1021 : calculateIdWidth().width + 4;
1024 void makeAlignmentImage(int type, File file)
1026 int maxwidth = av.alignment.getWidth();
1027 if (av.hasHiddenColumns)
1029 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1032 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1033 + scalePanel.getHeight();
1034 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1036 if (av.getWrapAlignment())
1038 height = getWrappedHeight();
1039 if (System.getProperty("java.awt.headless") != null
1040 && System.getProperty("java.awt.headless").equals("true"))
1042 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1043 - alignFrame.getInsets().left
1044 - alignFrame.getInsets().right;
1048 width = seqPanel.getWidth() + getVisibleIdWidth();
1052 else if (av.getShowAnnotation())
1054 height += annotationPanel.adjustPanelHeight() + 3;
1060 jalview.util.ImageMaker im;
1061 if (type == jalview.util.ImageMaker.PNG)
1063 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1064 "Create PNG image from alignment", width, height, file,
1069 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1070 "Create EPS file from alignment", width, height, file,
1071 alignFrame.getTitle());
1074 if (av.getWrapAlignment())
1076 if (im.getGraphics() != null)
1078 printWrappedAlignment(im.getGraphics(), width, height, 0);
1084 if (im.getGraphics() != null)
1086 printUnwrapped(im.getGraphics(), width, height, 0);
1090 } catch (OutOfMemoryError err)
1093 System.out.println("########################\n" + "OUT OF MEMORY "
1094 + file + "\n" + "########################");
1095 new OOMWarning("Creating Image for " + file, err);
1096 // System.out.println("Create IMAGE: " + err);
1097 } catch (Exception ex)
1099 ex.printStackTrace();
1106 public void makeEPS(File epsFile)
1108 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1114 public void makePNG(File pngFile)
1116 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1119 public void makePNGImageMap(File imgMapFile, String imageName)
1121 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1122 // ////////////////////////////////////////////
1123 int idWidth = getVisibleIdWidth();
1124 FontMetrics fm = getFontMetrics(av.getFont());
1125 int scaleHeight = av.charHeight + fm.getDescent();
1128 // ////////////////////////////////
1129 if (imgMapFile != null)
1133 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1134 .getWidth(), g, gSize, f, fSize, sy;
1135 StringBuffer text = new StringBuffer();
1136 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1137 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1138 out.println("<img src=\"" + imageName
1139 + "\" border=\"0\" usemap=\"#Map\" >"
1140 + "<map name=\"Map\">");
1142 for (s = 0; s < sSize; s++)
1144 sy = s * av.charHeight + scaleHeight;
1146 SequenceI seq = av.alignment.getSequenceAt(s);
1147 SequenceFeature[] features = seq.getDatasetSequence()
1148 .getSequenceFeatures();
1149 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1150 for (res = 0; res < alwidth; res++)
1152 text = new StringBuffer();
1154 if (av.alignment.isNucleotide())
1156 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1161 obj = ResidueProperties.aa2Triplet.get(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++)
1175 if (text.length() < 1)
1177 text.append("<area shape=\"rect\" coords=\""
1178 + (idWidth + res * av.charWidth) + "," + sy + ","
1179 + (idWidth + (res + 1) * av.charWidth) + ","
1180 + (av.charHeight + sy) + "\""
1181 + " onMouseOver=\"toolTip('" + alIndex + " "
1185 if (groups[g].getStartRes() < res
1186 && groups[g].getEndRes() > res)
1188 text.append("<br><em>" + groups[g].getName() + "</em>");
1192 if (features != null)
1194 if (text.length() < 1)
1196 text.append("<area shape=\"rect\" coords=\""
1197 + (idWidth + res * av.charWidth) + "," + sy + ","
1198 + (idWidth + (res + 1) * av.charWidth) + ","
1199 + (av.charHeight + sy) + "\""
1200 + " onMouseOver=\"toolTip('" + alIndex + " "
1203 fSize = features.length;
1204 for (f = 0; f < fSize; f++)
1207 if ((features[f].getBegin() <= seq.findPosition(res))
1208 && (features[f].getEnd() >= seq.findPosition(res)))
1210 if (features[f].getType().equals("disulfide bond"))
1212 if (features[f].getBegin() == seq.findPosition(res)
1213 || features[f].getEnd() == seq
1216 text.append("<br>disulfide bond "
1217 + features[f].getBegin() + ":"
1218 + features[f].getEnd());
1223 text.append("<br>");
1224 text.append(features[f].getType());
1225 if (features[f].getDescription() != null
1226 && !features[f].getType().equals(
1227 features[f].getDescription()))
1229 text.append(" " + features[f].getDescription());
1232 if (features[f].getValue("status") != null)
1234 text.append(" (" + features[f].getValue("status")
1242 if (text.length() > 1)
1244 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1245 out.println(text.toString());
1249 out.println("</map></body></html>");
1252 } catch (Exception ex)
1254 ex.printStackTrace();
1256 } // /////////END OF IMAGE MAP
1260 int getWrappedHeight()
1262 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1264 if (System.getProperty("java.awt.headless") != null
1265 && System.getProperty("java.awt.headless").equals("true"))
1267 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1268 - vscroll.getPreferredSize().width
1269 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1272 int chunkWidth = seqPanel.seqCanvas
1273 .getWrappedCanvasWidth(seqPanelWidth);
1275 int hgap = av.charHeight;
1276 if (av.scaleAboveWrapped)
1278 hgap += av.charHeight;
1281 int annotationHeight = 0;
1282 if (av.showAnnotation)
1284 annotationHeight = annotationPanel.adjustPanelHeight();
1287 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1290 int maxwidth = av.alignment.getWidth();
1291 if (av.hasHiddenColumns)
1293 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1296 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1302 * close the panel - deregisters all listeners and nulls any references to
1305 public void closePanel()
1307 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1308 .getStructureSelectionManager();
1309 ssm.removeStructureViewerListener(seqPanel, null);
1310 ssm.removeSelectionListener(seqPanel);
1311 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1312 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1313 PaintRefresher.RemoveComponent(this);
1316 av.alignment = null;
1321 if (Cache.log.isDebugEnabled())
1323 Cache.log.warn("Closing alignment panel which is already closed.");
1329 * hides or shows dynamic annotation rows based on groups and av state flags
1331 public void updateAnnotation()
1333 updateAnnotation(false);
1336 public void updateAnnotation(boolean applyGlobalSettings)
1338 // TODO: this should be merged with other annotation update stuff - that
1339 // sits on AlignViewport
1340 boolean updateCalcs = false;
1341 boolean conv = av.isShowGroupConservation();
1342 boolean cons = av.isShowGroupConsensus();
1343 boolean showprf = av.isShowSequenceLogo();
1344 boolean showConsHist = av.isShowConsensusHistogram();
1346 boolean sortg = true;
1348 // remove old automatic annotation
1349 // add any new annotation
1351 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1352 // intersect alignment annotation with alignment groups
1354 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1355 Hashtable oldrfs = new Hashtable();
1358 for (int an = 0; an < aan.length; an++)
1360 if (aan[an].autoCalculated && aan[an].groupRef != null)
1362 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1363 av.alignment.deleteAnnotation(aan[an]);
1371 for (int g = 0; g < gr.size(); g++)
1373 updateCalcs = false;
1374 sg = (SequenceGroup) gr.elementAt(g);
1375 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1377 // set defaults for this group's conservation/consensus
1378 sg.setshowSequenceLogo(showprf);
1379 sg.setShowConsensusHistogram(showConsHist);
1384 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1389 av.alignment.addAnnotation(sg.getConsensus(), 0);
1391 // refresh the annotation rows
1394 sg.recalcConservation();
1399 adjustAnnotationHeight();