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();
413 public void setWrapAlignment(boolean wrap)
416 scalePanelHolder.setVisible(!wrap);
417 hscroll.setVisible(!wrap);
418 idwidthAdjuster.setVisible(!wrap);
422 annotationScroller.setVisible(false);
423 annotationSpaceFillerHolder.setVisible(false);
425 else if (av.showAnnotation)
427 annotationScroller.setVisible(true);
428 annotationSpaceFillerHolder.setVisible(true);
431 idSpaceFillerPanel1.setVisible(!wrap);
436 // return value is true if the scroll is valid
437 public boolean scrollUp(boolean up)
441 if (vscroll.getValue() < 1)
447 vscroll.setValue(vscroll.getValue() - 1);
451 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
457 vscroll.setValue(vscroll.getValue() + 1);
471 * @return DOCUMENT ME!
473 public boolean scrollRight(boolean right)
477 if (hscroll.getValue() < 1)
483 hscroll.setValue(hscroll.getValue() - 1);
487 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
493 hscroll.setValue(hscroll.getValue() + 1);
509 public void setScrollValues(int x, int y)
511 // System.err.println("Scroll to "+x+","+y);
512 if (av == null || av.alignment == null)
516 int width = av.alignment.getWidth();
517 int height = av.alignment.getHeight();
519 if (av.hasHiddenColumns)
521 width = av.getColumnSelection().findColumnPosition(width);
524 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
526 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
527 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
534 if (vextent > height)
539 if ((hextent + x) > width)
544 if ((vextent + y) > height)
546 y = height - vextent;
559 hscroll.setValues(x, hextent, 0, width);
560 vscroll.setValues(y, vextent, 0, height);
569 public void adjustmentValueChanged(AdjustmentEvent evt)
572 int oldX = av.getStartRes();
573 int oldY = av.getStartSeq();
575 if (evt.getSource() == hscroll)
577 int x = hscroll.getValue();
580 .setEndRes((x + (seqPanel.seqCanvas.getWidth() / av
581 .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, av
864 pg.setColor(currentTextColor);
867 if (av.rightAlignIds)
869 fm = pg.getFontMetrics();
871 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
875 pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
876 (((i - startSeq) * av.charHeight) + av.getCharHeight())
877 - (av.getCharHeight() / 5));
880 pg.setFont(av.getFont());
882 // draw main sequence panel
883 pg.translate(idWidth, 0);
884 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
886 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
888 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
889 alabels.drawComponent((Graphics2D) pg, idWidth);
890 pg.translate(idWidth + 3, 0);
891 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
894 return Printable.PAGE_EXISTS;
909 * @return DOCUMENT ME!
911 * @throws PrinterException
914 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
915 int pi) throws PrinterException
918 int annotationHeight = 0;
919 AnnotationLabels labels = null;
920 if (av.showAnnotation)
922 annotationHeight = annotationPanel.adjustPanelHeight();
923 labels = new AnnotationLabels(av);
926 int hgap = av.charHeight;
927 if (av.scaleAboveWrapped)
929 hgap += av.charHeight;
932 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
935 int idWidth = getVisibleIdWidth();
937 int maxwidth = av.alignment.getWidth();
938 if (av.hasHiddenColumns)
940 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
943 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
946 int totalHeight = cHeight * (maxwidth / resWidth + 1);
948 pg.setColor(Color.white);
949 pg.fillRect(0, 0, pwidth, pheight);
950 pg.setFont(av.getFont());
954 pg.setColor(Color.black);
956 pg.translate(0, -pi * pheight);
958 pg.setClip(0, pi * pheight, pwidth, pheight);
964 for (int i = 0; i < av.alignment.getHeight(); i++)
966 pg.setFont(idPanel.idCanvas.idfont);
967 SequenceI s = av.alignment.getSequenceAt(i);
968 String string = s.getDisplayId(av.getShowJVSuffix());
970 if (av.rightAlignIds)
972 FontMetrics fm = pg.getFontMetrics();
973 xPos = idWidth - fm.stringWidth(string) - 4;
975 pg.drawString(string, xPos,
976 ((i * av.charHeight) + ypos + av.charHeight)
977 - (av.charHeight / 5));
981 pg.translate(-3, ypos
982 + (av.getAlignment().getHeight() * av.charHeight));
984 pg.setFont(av.getFont());
985 labels.drawComponent(pg, idWidth);
986 pg.translate(+3, -ypos
987 - (av.getAlignment().getHeight() * av.charHeight));
991 } while (ypos < totalHeight);
993 pg.translate(idWidth, 0);
995 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
998 if ((pi * pheight) < totalHeight)
1000 return Printable.PAGE_EXISTS;
1005 return Printable.NO_SUCH_PAGE;
1009 int getVisibleIdWidth()
1011 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1012 : calculateIdWidth().width + 4;
1015 void makeAlignmentImage(int type, File file)
1017 int maxwidth = av.alignment.getWidth();
1018 if (av.hasHiddenColumns)
1020 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1023 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1024 + scalePanel.getHeight();
1025 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1027 if (av.getWrapAlignment())
1029 height = getWrappedHeight();
1030 if (System.getProperty("java.awt.headless") != null
1031 && System.getProperty("java.awt.headless").equals("true"))
1033 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1034 - alignFrame.getInsets().left
1035 - alignFrame.getInsets().right;
1039 width = seqPanel.getWidth() + getVisibleIdWidth();
1043 else if (av.getShowAnnotation())
1045 height += annotationPanel.adjustPanelHeight() + 3;
1051 jalview.util.ImageMaker im;
1052 if (type == jalview.util.ImageMaker.PNG)
1054 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1055 "Create PNG image from alignment", width, height, file,
1060 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1061 "Create EPS file from alignment", width, height, file,
1062 alignFrame.getTitle());
1065 if (av.getWrapAlignment())
1067 if (im.getGraphics() != null)
1069 printWrappedAlignment(im.getGraphics(), width, height, 0);
1075 if (im.getGraphics() != null)
1077 printUnwrapped(im.getGraphics(), width, height, 0);
1081 } catch (OutOfMemoryError err)
1084 System.out.println("########################\n" + "OUT OF MEMORY "
1085 + file + "\n" + "########################");
1086 new OOMWarning("Creating Image for " + file, err);
1087 // System.out.println("Create IMAGE: " + err);
1088 } catch (Exception ex)
1090 ex.printStackTrace();
1097 public void makeEPS(File epsFile)
1099 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1105 public void makePNG(File pngFile)
1107 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1110 public void makePNGImageMap(File imgMapFile, String imageName)
1112 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1113 // ////////////////////////////////////////////
1114 int idWidth = getVisibleIdWidth();
1115 FontMetrics fm = getFontMetrics(av.getFont());
1116 int scaleHeight = av.charHeight + fm.getDescent();
1119 // ////////////////////////////////
1120 if (imgMapFile != null)
1124 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1125 .getWidth(), g, gSize, f, fSize, sy;
1126 StringBuffer text = new StringBuffer();
1127 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1128 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1129 out.println("<img src=\"" + imageName
1130 + "\" border=\"0\" usemap=\"#Map\" >"
1131 + "<map name=\"Map\">");
1133 for (s = 0; s < sSize; s++)
1135 sy = s * av.charHeight + scaleHeight;
1137 SequenceI seq = av.alignment.getSequenceAt(s);
1138 SequenceFeature[] features = seq.getDatasetSequence()
1139 .getSequenceFeatures();
1140 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1141 for (res = 0; res < alwidth; res++)
1143 text = new StringBuffer();
1145 if (av.alignment.isNucleotide())
1147 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1152 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1161 String triplet = obj.toString();
1162 int alIndex = seq.findPosition(res);
1163 gSize = groups.length;
1164 for (g = 0; g < gSize; g++)
1166 if (text.length() < 1)
1168 text.append("<area shape=\"rect\" coords=\""
1169 + (idWidth + res * av.charWidth) + "," + sy + ","
1170 + (idWidth + (res + 1) * av.charWidth) + ","
1171 + (av.charHeight + sy) + "\""
1172 + " onMouseOver=\"toolTip('" + alIndex + " "
1176 if (groups[g].getStartRes() < res
1177 && groups[g].getEndRes() > res)
1179 text.append("<br><em>" + groups[g].getName() + "</em>");
1183 if (features != null)
1185 if (text.length() < 1)
1187 text.append("<area shape=\"rect\" coords=\""
1188 + (idWidth + res * av.charWidth) + "," + sy + ","
1189 + (idWidth + (res + 1) * av.charWidth) + ","
1190 + (av.charHeight + sy) + "\""
1191 + " onMouseOver=\"toolTip('" + alIndex + " "
1194 fSize = features.length;
1195 for (f = 0; f < fSize; f++)
1198 if ((features[f].getBegin() <= seq.findPosition(res))
1199 && (features[f].getEnd() >= seq.findPosition(res)))
1201 if (features[f].getType().equals("disulfide bond"))
1203 if (features[f].getBegin() == seq.findPosition(res)
1204 || features[f].getEnd() == seq
1207 text.append("<br>disulfide bond "
1208 + features[f].getBegin() + ":"
1209 + features[f].getEnd());
1214 text.append("<br>");
1215 text.append(features[f].getType());
1216 if (features[f].getDescription() != null
1217 && !features[f].getType().equals(
1218 features[f].getDescription()))
1220 text.append(" " + features[f].getDescription());
1223 if (features[f].getValue("status") != null)
1225 text.append(" (" + features[f].getValue("status")
1233 if (text.length() > 1)
1235 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1236 out.println(text.toString());
1240 out.println("</map></body></html>");
1243 } catch (Exception ex)
1245 ex.printStackTrace();
1247 } // /////////END OF IMAGE MAP
1251 int getWrappedHeight()
1253 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1255 if (System.getProperty("java.awt.headless") != null
1256 && System.getProperty("java.awt.headless").equals("true"))
1258 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1259 - vscroll.getPreferredSize().width
1260 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1263 int chunkWidth = seqPanel.seqCanvas
1264 .getWrappedCanvasWidth(seqPanelWidth);
1266 int hgap = av.charHeight;
1267 if (av.scaleAboveWrapped)
1269 hgap += av.charHeight;
1272 int annotationHeight = 0;
1273 if (av.showAnnotation)
1275 annotationHeight = annotationPanel.adjustPanelHeight();
1278 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1281 int maxwidth = av.alignment.getWidth();
1282 if (av.hasHiddenColumns)
1284 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1287 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1293 * close the panel - deregisters all listeners and nulls any references to
1296 public void closePanel()
1298 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1299 .getStructureSelectionManager();
1300 ssm.removeStructureViewerListener(seqPanel, null);
1301 ssm.removeSelectionListener(seqPanel);
1302 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1303 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1304 PaintRefresher.RemoveComponent(this);
1307 av.alignment = null;
1312 if (Cache.log.isDebugEnabled())
1314 Cache.log.warn("Closing alignment panel which is already closed.");
1320 * hides or shows dynamic annotation rows based on groups and av state flags
1322 public void updateAnnotation()
1324 boolean updateCalcs = false;
1325 boolean conv = av.isShowGroupConservation();
1326 boolean cons = av.isShowGroupConsensus();
1327 boolean sortg = true;
1329 // remove old automatic annotation
1330 // add any new annotation
1332 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1333 // intersect alignment annotation with alignment groups
1335 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1336 for (int an = 0; an < aan.length; an++)
1338 if (aan[an].autoCalculated && aan[an].groupRef != null)
1340 av.alignment.deleteAnnotation(aan[an]);
1345 for (int g = 0; g < gr.size(); g++)
1347 updateCalcs = false;
1348 sg = (SequenceGroup) gr.elementAt(g);
1353 av.alignment.addAnnotation(sg.getConservationRow(),0);
1358 av.alignment.addAnnotation(sg.getConsensus(),0);
1360 // refresh the annotation rows
1363 sg.recalcConservation();
1366 adjustAnnotationHeight();