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);
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
286 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
292 if (end == seq.getEnd())
296 if (!av.wrapAlignment)
298 if ((startv = av.getStartRes()) >= start)
300 setScrollValues(start - 1, seqIndex);
302 else if ((endv = av.getEndRes()) <= end)
304 setScrollValues(startv + 1 + end - endv, seqIndex);
306 else if ((starts = av.getStartSeq()) > seqIndex)
308 setScrollValues(av.getStartRes(), seqIndex);
310 else if ((ends = av.getEndSeq()) <= seqIndex)
312 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
317 scrollToWrappedVisible(start);
320 if (!redrawOverview && overviewPanel != null)
322 overviewPanel.setBoxPosition();
324 paintAlignment(!redrawOverview);
328 void scrollToWrappedVisible(int res)
330 int cwidth = seqPanel.seqCanvas
331 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
332 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
334 vscroll.setValue((res / cwidth));
335 av.startRes = vscroll.getValue() * cwidth;
343 * @return DOCUMENT ME!
345 public OverviewPanel getOverviewPanel()
347 return overviewPanel;
356 public void setOverviewPanel(OverviewPanel op)
367 public void setAnnotationVisible(boolean b)
369 if (!av.wrapAlignment)
371 annotationSpaceFillerHolder.setVisible(b);
372 annotationScroller.setVisible(b);
377 public void adjustAnnotationHeight()
379 // TODO: display vertical annotation scrollbar if necessary
380 // this is called after loading new annotation onto alignment
381 if (alignFrame.getHeight() == 0)
383 System.out.println("NEEDS FIXING");
386 int height = annotationPanel.adjustPanelHeight();
388 if (hscroll.isVisible())
390 height += hscroll.getPreferredSize().height;
392 if (height > alignFrame.getHeight() / 2)
394 height = alignFrame.getHeight() / 2;
399 annotationScroller.setPreferredSize(new Dimension(annotationScroller
400 .getWidth(), height));
402 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
403 annotationSpaceFillerHolder.getWidth(), height));
404 annotationScroller.validate();// repaint();
415 public void setWrapAlignment(boolean wrap)
418 scalePanelHolder.setVisible(!wrap);
419 hscroll.setVisible(!wrap);
420 idwidthAdjuster.setVisible(!wrap);
424 annotationScroller.setVisible(false);
425 annotationSpaceFillerHolder.setVisible(false);
427 else if (av.showAnnotation)
429 annotationScroller.setVisible(true);
430 annotationSpaceFillerHolder.setVisible(true);
433 idSpaceFillerPanel1.setVisible(!wrap);
438 // return value is true if the scroll is valid
439 public boolean scrollUp(boolean up)
443 if (vscroll.getValue() < 1)
449 vscroll.setValue(vscroll.getValue() - 1);
453 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
459 vscroll.setValue(vscroll.getValue() + 1);
473 * @return DOCUMENT ME!
475 public boolean scrollRight(boolean right)
479 if (hscroll.getValue() < 1)
485 hscroll.setValue(hscroll.getValue() - 1);
489 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
495 hscroll.setValue(hscroll.getValue() + 1);
511 public void setScrollValues(int x, int y)
513 // System.err.println("Scroll to "+x+","+y);
514 if (av == null || av.alignment == null)
518 int width = av.alignment.getWidth();
519 int height = av.alignment.getHeight();
521 if (av.hasHiddenColumns)
523 width = av.getColumnSelection().findColumnPosition(width);
526 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
528 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
529 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
536 if (vextent > height)
541 if ((hextent + x) > width)
546 if ((vextent + y) > height)
548 y = height - vextent;
561 hscroll.setValues(x, hextent, 0, width);
562 vscroll.setValues(y, vextent, 0, height);
571 public void adjustmentValueChanged(AdjustmentEvent evt)
574 int oldX = av.getStartRes();
575 int oldY = av.getStartSeq();
577 if (evt.getSource() == hscroll)
579 int x = hscroll.getValue();
581 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
584 if (evt.getSource() == vscroll)
586 int offy = vscroll.getValue();
588 if (av.getWrapAlignment())
592 int rowSize = seqPanel.seqCanvas
593 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
594 av.setStartRes(offy * rowSize);
595 av.setEndRes((offy + 1) * rowSize);
599 // This is only called if file loaded is a jar file that
600 // was wrapped when saved and user has wrap alignment true
601 // as preference setting
602 SwingUtilities.invokeLater(new Runnable()
606 setScrollValues(av.getStartRes(), av.getStartSeq());
613 av.setStartSeq(offy);
615 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
619 if (overviewPanel != null)
621 overviewPanel.setBoxPosition();
624 int scrollX = av.startRes - oldX;
625 int scrollY = av.startSeq - oldY;
627 if (av.getWrapAlignment() || !fastPaint)
633 // Make sure we're not trying to draw a panel
634 // larger than the visible window
635 if (scrollX > av.endRes - av.startRes)
637 scrollX = av.endRes - av.startRes;
639 else if (scrollX < av.startRes - av.endRes)
641 scrollX = av.startRes - av.endRes;
644 if (scrollX != 0 || scrollY != 0)
646 idPanel.idCanvas.fastPaint(scrollY);
647 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
648 scalePanel.repaint();
650 if (av.getShowAnnotation())
652 annotationPanel.fastPaint(scrollX);
658 public void paintAlignment(boolean updateOverview)
664 jalview.structure.StructureSelectionManager
665 .getStructureSelectionManager().sequenceColoursChanged(this);
667 if (overviewPanel != null)
669 overviewPanel.updateOverviewImage();
680 public void paintComponent(Graphics g)
684 Dimension d = idPanel.idCanvas.getPreferredSize();
685 idPanelHolder.setPreferredSize(d);
686 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
689 if (av.getWrapAlignment())
691 int maxwidth = av.alignment.getWidth();
693 if (av.hasHiddenColumns)
695 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
698 int canvasWidth = seqPanel.seqCanvas
699 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
704 .getWrappedCanvasWidth(seqPanel.seqCanvas
706 vscroll.setMaximum(max);
707 vscroll.setUnitIncrement(1);
708 vscroll.setVisibleAmount(1);
713 setScrollValues(av.getStartRes(), av.getStartSeq());
727 * @return DOCUMENT ME!
729 * @throws PrinterException
732 public int print(Graphics pg, PageFormat pf, int pi)
733 throws PrinterException
735 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
737 int pwidth = (int) pf.getImageableWidth();
738 int pheight = (int) pf.getImageableHeight();
740 if (av.getWrapAlignment())
742 return printWrappedAlignment(pg, pwidth, pheight, pi);
746 return printUnwrapped(pg, pwidth, pheight, pi);
762 * @return DOCUMENT ME!
764 * @throws PrinterException
767 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
768 throws PrinterException
770 int idWidth = getVisibleIdWidth();
771 FontMetrics fm = getFontMetrics(av.getFont());
772 int scaleHeight = av.charHeight + fm.getDescent();
774 pg.setColor(Color.white);
775 pg.fillRect(0, 0, pwidth, pheight);
776 pg.setFont(av.getFont());
778 // //////////////////////////////////
779 // / How many sequences and residues can we fit on a printable page?
780 int totalRes = (pwidth - idWidth) / av.getCharWidth();
782 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
784 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
786 // ///////////////////////////
787 // / Only print these sequences and residues on this page
790 // ///////////////////////////
791 // / Only print these sequences and residues on this page
794 // ///////////////////////////
795 // / Only print these sequences and residues on this page
798 // ///////////////////////////
799 // / Only print these sequences and residues on this page
801 startRes = (pi % pagesWide) * totalRes;
802 endRes = (startRes + totalRes) - 1;
804 if (endRes > (av.getAlignment().getWidth() - 1))
806 endRes = av.getAlignment().getWidth() - 1;
809 startSeq = (pi / pagesWide) * totalSeq;
810 endSeq = startSeq + totalSeq;
812 if (endSeq > av.getAlignment().getHeight())
814 endSeq = av.getAlignment().getHeight();
817 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
819 if (av.showAnnotation)
821 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
824 pagesHigh /= pheight;
826 if (pi >= (pagesWide * pagesHigh))
828 return Printable.NO_SUCH_PAGE;
832 pg.translate(idWidth, 0);
833 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
835 pg.translate(-idWidth, scaleHeight);
839 Color currentColor = null;
840 Color currentTextColor = null;
842 pg.setFont(idPanel.idCanvas.idfont);
845 for (int i = startSeq; i < endSeq; i++)
847 seq = av.getAlignment().getSequenceAt(i);
848 if ((av.getSelectionGroup() != null)
849 && av.getSelectionGroup().getSequences(null).contains(seq))
851 currentColor = Color.gray;
852 currentTextColor = Color.black;
856 currentColor = av.getSequenceColour(seq);
857 currentTextColor = Color.black;
860 pg.setColor(currentColor);
861 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
864 pg.setColor(currentTextColor);
867 if (av.rightAlignIds)
869 fm = pg.getFontMetrics();
871 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
876 seq.getDisplayId(av.getShowJVSuffix()),
878 (((i - startSeq) * av.charHeight) + av.getCharHeight())
879 - (av.getCharHeight() / 5));
882 pg.setFont(av.getFont());
884 // draw main sequence panel
885 pg.translate(idWidth, 0);
886 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
888 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
890 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
891 alabels.drawComponent((Graphics2D) pg, idWidth);
892 pg.translate(idWidth + 3, 0);
893 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
896 return Printable.PAGE_EXISTS;
911 * @return DOCUMENT ME!
913 * @throws PrinterException
916 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
917 int pi) throws PrinterException
920 int annotationHeight = 0;
921 AnnotationLabels labels = null;
922 if (av.showAnnotation)
924 annotationHeight = annotationPanel.adjustPanelHeight();
925 labels = new AnnotationLabels(av);
928 int hgap = av.charHeight;
929 if (av.scaleAboveWrapped)
931 hgap += av.charHeight;
934 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
937 int idWidth = getVisibleIdWidth();
939 int maxwidth = av.alignment.getWidth();
940 if (av.hasHiddenColumns)
942 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
945 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
948 int totalHeight = cHeight * (maxwidth / resWidth + 1);
950 pg.setColor(Color.white);
951 pg.fillRect(0, 0, pwidth, pheight);
952 pg.setFont(av.getFont());
956 pg.setColor(Color.black);
958 pg.translate(0, -pi * pheight);
960 pg.setClip(0, pi * pheight, pwidth, pheight);
966 for (int i = 0; i < av.alignment.getHeight(); i++)
968 pg.setFont(idPanel.idCanvas.idfont);
969 SequenceI s = av.alignment.getSequenceAt(i);
970 String string = s.getDisplayId(av.getShowJVSuffix());
972 if (av.rightAlignIds)
974 FontMetrics fm = pg.getFontMetrics();
975 xPos = idWidth - fm.stringWidth(string) - 4;
977 pg.drawString(string, xPos,
978 ((i * av.charHeight) + ypos + av.charHeight)
979 - (av.charHeight / 5));
983 pg.translate(-3, ypos
984 + (av.getAlignment().getHeight() * av.charHeight));
986 pg.setFont(av.getFont());
987 labels.drawComponent(pg, idWidth);
988 pg.translate(+3, -ypos
989 - (av.getAlignment().getHeight() * av.charHeight));
993 } while (ypos < totalHeight);
995 pg.translate(idWidth, 0);
997 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1000 if ((pi * pheight) < totalHeight)
1002 return Printable.PAGE_EXISTS;
1007 return Printable.NO_SUCH_PAGE;
1011 int getVisibleIdWidth()
1013 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1014 : calculateIdWidth().width + 4;
1017 void makeAlignmentImage(int type, File file)
1019 int maxwidth = av.alignment.getWidth();
1020 if (av.hasHiddenColumns)
1022 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1025 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1026 + scalePanel.getHeight();
1027 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1029 if (av.getWrapAlignment())
1031 height = getWrappedHeight();
1032 if (System.getProperty("java.awt.headless") != null
1033 && System.getProperty("java.awt.headless").equals("true"))
1035 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1036 - alignFrame.getInsets().left
1037 - alignFrame.getInsets().right;
1041 width = seqPanel.getWidth() + getVisibleIdWidth();
1045 else if (av.getShowAnnotation())
1047 height += annotationPanel.adjustPanelHeight() + 3;
1053 jalview.util.ImageMaker im;
1054 if (type == jalview.util.ImageMaker.PNG)
1056 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1057 "Create PNG image from alignment", width, height, file,
1062 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1063 "Create EPS file from alignment", width, height, file,
1064 alignFrame.getTitle());
1067 if (av.getWrapAlignment())
1069 if (im.getGraphics() != null)
1071 printWrappedAlignment(im.getGraphics(), width, height, 0);
1077 if (im.getGraphics() != null)
1079 printUnwrapped(im.getGraphics(), width, height, 0);
1083 } catch (OutOfMemoryError err)
1086 System.out.println("########################\n" + "OUT OF MEMORY "
1087 + file + "\n" + "########################");
1088 new OOMWarning("Creating Image for " + file, err);
1089 // System.out.println("Create IMAGE: " + err);
1090 } catch (Exception ex)
1092 ex.printStackTrace();
1099 public void makeEPS(File epsFile)
1101 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1107 public void makePNG(File pngFile)
1109 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1112 public void makePNGImageMap(File imgMapFile, String imageName)
1114 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1115 // ////////////////////////////////////////////
1116 int idWidth = getVisibleIdWidth();
1117 FontMetrics fm = getFontMetrics(av.getFont());
1118 int scaleHeight = av.charHeight + fm.getDescent();
1121 // ////////////////////////////////
1122 if (imgMapFile != null)
1126 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1127 .getWidth(), g, gSize, f, fSize, sy;
1128 StringBuffer text = new StringBuffer();
1129 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1130 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1131 out.println("<img src=\"" + imageName
1132 + "\" border=\"0\" usemap=\"#Map\" >"
1133 + "<map name=\"Map\">");
1135 for (s = 0; s < sSize; s++)
1137 sy = s * av.charHeight + scaleHeight;
1139 SequenceI seq = av.alignment.getSequenceAt(s);
1140 SequenceFeature[] features = seq.getDatasetSequence()
1141 .getSequenceFeatures();
1142 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1143 for (res = 0; res < alwidth; res++)
1145 text = new StringBuffer();
1147 if (av.alignment.isNucleotide())
1149 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1154 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1163 String triplet = obj.toString();
1164 int alIndex = seq.findPosition(res);
1165 gSize = groups.length;
1166 for (g = 0; g < gSize; g++)
1168 if (text.length() < 1)
1170 text.append("<area shape=\"rect\" coords=\""
1171 + (idWidth + res * av.charWidth) + "," + sy + ","
1172 + (idWidth + (res + 1) * av.charWidth) + ","
1173 + (av.charHeight + sy) + "\""
1174 + " onMouseOver=\"toolTip('" + alIndex + " "
1178 if (groups[g].getStartRes() < res
1179 && groups[g].getEndRes() > res)
1181 text.append("<br><em>" + groups[g].getName() + "</em>");
1185 if (features != null)
1187 if (text.length() < 1)
1189 text.append("<area shape=\"rect\" coords=\""
1190 + (idWidth + res * av.charWidth) + "," + sy + ","
1191 + (idWidth + (res + 1) * av.charWidth) + ","
1192 + (av.charHeight + sy) + "\""
1193 + " onMouseOver=\"toolTip('" + alIndex + " "
1196 fSize = features.length;
1197 for (f = 0; f < fSize; f++)
1200 if ((features[f].getBegin() <= seq.findPosition(res))
1201 && (features[f].getEnd() >= seq.findPosition(res)))
1203 if (features[f].getType().equals("disulfide bond"))
1205 if (features[f].getBegin() == seq.findPosition(res)
1206 || features[f].getEnd() == seq
1209 text.append("<br>disulfide bond "
1210 + features[f].getBegin() + ":"
1211 + features[f].getEnd());
1216 text.append("<br>");
1217 text.append(features[f].getType());
1218 if (features[f].getDescription() != null
1219 && !features[f].getType().equals(
1220 features[f].getDescription()))
1222 text.append(" " + features[f].getDescription());
1225 if (features[f].getValue("status") != null)
1227 text.append(" (" + features[f].getValue("status")
1235 if (text.length() > 1)
1237 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1238 out.println(text.toString());
1242 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 (System.getProperty("java.awt.headless") != null
1258 && System.getProperty("java.awt.headless").equals("true"))
1260 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1261 - vscroll.getPreferredSize().width
1262 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1265 int chunkWidth = seqPanel.seqCanvas
1266 .getWrappedCanvasWidth(seqPanelWidth);
1268 int hgap = av.charHeight;
1269 if (av.scaleAboveWrapped)
1271 hgap += av.charHeight;
1274 int annotationHeight = 0;
1275 if (av.showAnnotation)
1277 annotationHeight = annotationPanel.adjustPanelHeight();
1280 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1283 int maxwidth = av.alignment.getWidth();
1284 if (av.hasHiddenColumns)
1286 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1289 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1295 * close the panel - deregisters all listeners and nulls any references to
1298 public void closePanel()
1300 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1301 .getStructureSelectionManager();
1302 ssm.removeStructureViewerListener(seqPanel, null);
1303 ssm.removeSelectionListener(seqPanel);
1304 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1305 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1306 PaintRefresher.RemoveComponent(this);
1309 av.alignment = null;
1314 if (Cache.log.isDebugEnabled())
1316 Cache.log.warn("Closing alignment panel which is already closed.");
1322 * hides or shows dynamic annotation rows based on groups and av state flags
1324 public void updateAnnotation()
1326 updateAnnotation(false);
1329 public void updateAnnotation(boolean applyGlobalSettings)
1331 // TODO: this should be merged with other annotation update stuff - that
1332 // sits on AlignViewport
1333 boolean updateCalcs = false;
1334 boolean conv = av.isShowGroupConservation();
1335 boolean cons = av.isShowGroupConsensus();
1336 boolean showprf = av.isShowSequenceLogo();
1337 boolean showConsHist = av.isShowConsensusHistogram();
1339 boolean sortg = true;
1341 // remove old automatic annotation
1342 // add any new annotation
1344 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1345 // intersect alignment annotation with alignment groups
1347 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1348 Hashtable oldrfs = new Hashtable();
1351 for (int an = 0; an < aan.length; an++)
1353 if (aan[an].autoCalculated && aan[an].groupRef != null)
1355 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1356 av.alignment.deleteAnnotation(aan[an]);
1364 for (int g = 0; g < gr.size(); g++)
1366 updateCalcs = false;
1367 sg = (SequenceGroup) gr.elementAt(g);
1368 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1370 // set defaults for this group's conservation/consensus
1371 sg.setshowSequenceLogo(showprf);
1372 sg.setShowConsensusHistogram(showConsHist);
1377 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1382 av.alignment.addAnnotation(sg.getConsensus(), 0);
1384 // refresh the annotation rows
1387 sg.recalcConservation();
1392 adjustAnnotationHeight();