2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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, 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
286 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); // DEBUG
291 if (end == seq.getEnd())
295 if (!av.wrapAlignment)
297 if ((startv = av.getStartRes()) >= start)
299 setScrollValues(start - 1, seqIndex);
301 else if ((endv = av.getEndRes()) <= end)
303 setScrollValues(startv + 1 + end - endv, seqIndex);
305 else if ((starts = av.getStartSeq()) > seqIndex)
307 setScrollValues(av.getStartRes(), seqIndex);
309 else if ((ends = av.getEndSeq()) <= seqIndex)
311 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
316 scrollToWrappedVisible(start);
319 if (!redrawOverview && overviewPanel != null)
321 overviewPanel.setBoxPosition();
323 paintAlignment(!redrawOverview);
327 void scrollToWrappedVisible(int res)
329 int cwidth = seqPanel.seqCanvas
330 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
331 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
333 vscroll.setValue((res / cwidth));
334 av.startRes = vscroll.getValue() * cwidth;
342 * @return DOCUMENT ME!
344 public OverviewPanel getOverviewPanel()
346 return overviewPanel;
355 public void setOverviewPanel(OverviewPanel op)
366 public void setAnnotationVisible(boolean b)
368 if (!av.wrapAlignment)
370 annotationSpaceFillerHolder.setVisible(b);
371 annotationScroller.setVisible(b);
376 public void adjustAnnotationHeight()
378 // TODO: display vertical annotation scrollbar if necessary
379 // this is called after loading new annotation onto alignment
380 if (alignFrame.getHeight() == 0)
382 System.out.println("NEEDS FIXING");
385 int height = annotationPanel.adjustPanelHeight();
387 if (hscroll.isVisible())
389 height += hscroll.getPreferredSize().height;
391 if (height > alignFrame.getHeight() / 2)
393 height = alignFrame.getHeight() / 2;
398 annotationScroller.setPreferredSize(new Dimension(annotationScroller
399 .getWidth(), height));
401 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
402 annotationSpaceFillerHolder.getWidth(), height));
403 annotationScroller.validate();// repaint();
414 public void setWrapAlignment(boolean wrap)
417 scalePanelHolder.setVisible(!wrap);
418 hscroll.setVisible(!wrap);
419 idwidthAdjuster.setVisible(!wrap);
423 annotationScroller.setVisible(false);
424 annotationSpaceFillerHolder.setVisible(false);
426 else if (av.showAnnotation)
428 annotationScroller.setVisible(true);
429 annotationSpaceFillerHolder.setVisible(true);
432 idSpaceFillerPanel1.setVisible(!wrap);
437 // return value is true if the scroll is valid
438 public boolean scrollUp(boolean up)
442 if (vscroll.getValue() < 1)
448 vscroll.setValue(vscroll.getValue() - 1);
452 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
458 vscroll.setValue(vscroll.getValue() + 1);
472 * @return DOCUMENT ME!
474 public boolean scrollRight(boolean right)
478 if (hscroll.getValue() < 1)
484 hscroll.setValue(hscroll.getValue() - 1);
488 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
494 hscroll.setValue(hscroll.getValue() + 1);
510 public void setScrollValues(int x, int y)
512 // System.err.println("Scroll to "+x+","+y);
513 if (av == null || av.alignment == null)
517 int width = av.alignment.getWidth();
518 int height = av.alignment.getHeight();
520 if (av.hasHiddenColumns)
522 width = av.getColumnSelection().findColumnPosition(width);
525 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
527 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
528 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
535 if (vextent > height)
540 if ((hextent + x) > width)
545 if ((vextent + y) > height)
547 y = height - vextent;
560 hscroll.setValues(x, hextent, 0, width);
561 vscroll.setValues(y, vextent, 0, height);
570 public void adjustmentValueChanged(AdjustmentEvent evt)
573 int oldX = av.getStartRes();
574 int oldY = av.getStartSeq();
576 if (evt.getSource() == hscroll)
578 int x = hscroll.getValue();
581 .setEndRes((x + (seqPanel.seqCanvas.getWidth() / av
582 .getCharWidth())) - 1);
585 if (evt.getSource() == vscroll)
587 int offy = vscroll.getValue();
589 if (av.getWrapAlignment())
593 int rowSize = seqPanel.seqCanvas
594 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
595 av.setStartRes(offy * rowSize);
596 av.setEndRes((offy + 1) * rowSize);
600 // This is only called if file loaded is a jar file that
601 // was wrapped when saved and user has wrap alignment true
602 // as preference setting
603 SwingUtilities.invokeLater(new Runnable()
607 setScrollValues(av.getStartRes(), av.getStartSeq());
614 av.setStartSeq(offy);
616 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
620 if (overviewPanel != null)
622 overviewPanel.setBoxPosition();
625 int scrollX = av.startRes - oldX;
626 int scrollY = av.startSeq - oldY;
628 if (av.getWrapAlignment() || !fastPaint)
634 // Make sure we're not trying to draw a panel
635 // larger than the visible window
636 if (scrollX > av.endRes - av.startRes)
638 scrollX = av.endRes - av.startRes;
640 else if (scrollX < av.startRes - av.endRes)
642 scrollX = av.startRes - av.endRes;
645 if (scrollX != 0 || scrollY != 0)
647 idPanel.idCanvas.fastPaint(scrollY);
648 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
649 scalePanel.repaint();
651 if (av.getShowAnnotation())
653 annotationPanel.fastPaint(scrollX);
659 public void paintAlignment(boolean updateOverview)
665 jalview.structure.StructureSelectionManager
666 .getStructureSelectionManager().sequenceColoursChanged(this);
668 if (overviewPanel != null)
670 overviewPanel.updateOverviewImage();
681 public void paintComponent(Graphics g)
685 Dimension d = idPanel.idCanvas.getPreferredSize();
686 idPanelHolder.setPreferredSize(d);
687 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
690 if (av.getWrapAlignment())
692 int maxwidth = av.alignment.getWidth();
694 if (av.hasHiddenColumns)
696 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
699 int canvasWidth = seqPanel.seqCanvas
700 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
705 .getWrappedCanvasWidth(seqPanel.seqCanvas
707 vscroll.setMaximum(max);
708 vscroll.setUnitIncrement(1);
709 vscroll.setVisibleAmount(1);
714 setScrollValues(av.getStartRes(), av.getStartSeq());
728 * @return DOCUMENT ME!
730 * @throws PrinterException
733 public int print(Graphics pg, PageFormat pf, int pi)
734 throws PrinterException
736 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
738 int pwidth = (int) pf.getImageableWidth();
739 int pheight = (int) pf.getImageableHeight();
741 if (av.getWrapAlignment())
743 return printWrappedAlignment(pg, pwidth, pheight, pi);
747 return printUnwrapped(pg, pwidth, pheight, pi);
763 * @return DOCUMENT ME!
765 * @throws PrinterException
768 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
769 throws PrinterException
771 int idWidth = getVisibleIdWidth();
772 FontMetrics fm = getFontMetrics(av.getFont());
773 int scaleHeight = av.charHeight + fm.getDescent();
775 pg.setColor(Color.white);
776 pg.fillRect(0, 0, pwidth, pheight);
777 pg.setFont(av.getFont());
779 // //////////////////////////////////
780 // / How many sequences and residues can we fit on a printable page?
781 int totalRes = (pwidth - idWidth) / av.getCharWidth();
783 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
785 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
787 // ///////////////////////////
788 // / Only print these sequences and residues on this page
791 // ///////////////////////////
792 // / Only print these sequences and residues on this page
795 // ///////////////////////////
796 // / Only print these sequences and residues on this page
799 // ///////////////////////////
800 // / Only print these sequences and residues on this page
802 startRes = (pi % pagesWide) * totalRes;
803 endRes = (startRes + totalRes) - 1;
805 if (endRes > (av.getAlignment().getWidth() - 1))
807 endRes = av.getAlignment().getWidth() - 1;
810 startSeq = (pi / pagesWide) * totalSeq;
811 endSeq = startSeq + totalSeq;
813 if (endSeq > av.getAlignment().getHeight())
815 endSeq = av.getAlignment().getHeight();
818 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
820 if (av.showAnnotation)
822 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
825 pagesHigh /= pheight;
827 if (pi >= (pagesWide * pagesHigh))
829 return Printable.NO_SUCH_PAGE;
833 pg.translate(idWidth, 0);
834 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
836 pg.translate(-idWidth, scaleHeight);
840 Color currentColor = null;
841 Color currentTextColor = null;
843 pg.setFont(idPanel.idCanvas.idfont);
846 for (int i = startSeq; i < endSeq; i++)
848 seq = av.getAlignment().getSequenceAt(i);
849 if ((av.getSelectionGroup() != null)
850 && av.getSelectionGroup().getSequences(null).contains(seq))
852 currentColor = Color.gray;
853 currentTextColor = Color.black;
857 currentColor = av.getSequenceColour(seq);
858 currentTextColor = Color.black;
861 pg.setColor(currentColor);
862 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, av
865 pg.setColor(currentTextColor);
868 if (av.rightAlignIds)
870 fm = pg.getFontMetrics();
872 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
876 pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos,
877 (((i - startSeq) * av.charHeight) + av.getCharHeight())
878 - (av.getCharHeight() / 5));
881 pg.setFont(av.getFont());
883 // draw main sequence panel
884 pg.translate(idWidth, 0);
885 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
887 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
889 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
890 alabels.drawComponent((Graphics2D) pg, idWidth);
891 pg.translate(idWidth + 3, 0);
892 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
895 return Printable.PAGE_EXISTS;
910 * @return DOCUMENT ME!
912 * @throws PrinterException
915 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
916 int pi) throws PrinterException
919 int annotationHeight = 0;
920 AnnotationLabels labels = null;
921 if (av.showAnnotation)
923 annotationHeight = annotationPanel.adjustPanelHeight();
924 labels = new AnnotationLabels(av);
927 int hgap = av.charHeight;
928 if (av.scaleAboveWrapped)
930 hgap += av.charHeight;
933 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
936 int idWidth = getVisibleIdWidth();
938 int maxwidth = av.alignment.getWidth();
939 if (av.hasHiddenColumns)
941 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
944 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
947 int totalHeight = cHeight * (maxwidth / resWidth + 1);
949 pg.setColor(Color.white);
950 pg.fillRect(0, 0, pwidth, pheight);
951 pg.setFont(av.getFont());
955 pg.setColor(Color.black);
957 pg.translate(0, -pi * pheight);
959 pg.setClip(0, pi * pheight, pwidth, pheight);
965 for (int i = 0; i < av.alignment.getHeight(); i++)
967 pg.setFont(idPanel.idCanvas.idfont);
968 SequenceI s = av.alignment.getSequenceAt(i);
969 String string = s.getDisplayId(av.getShowJVSuffix());
971 if (av.rightAlignIds)
973 FontMetrics fm = pg.getFontMetrics();
974 xPos = idWidth - fm.stringWidth(string) - 4;
976 pg.drawString(string, xPos,
977 ((i * av.charHeight) + ypos + av.charHeight)
978 - (av.charHeight / 5));
982 pg.translate(-3, ypos
983 + (av.getAlignment().getHeight() * av.charHeight));
985 pg.setFont(av.getFont());
986 labels.drawComponent(pg, idWidth);
987 pg.translate(+3, -ypos
988 - (av.getAlignment().getHeight() * av.charHeight));
992 } while (ypos < totalHeight);
994 pg.translate(idWidth, 0);
996 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
999 if ((pi * pheight) < totalHeight)
1001 return Printable.PAGE_EXISTS;
1006 return Printable.NO_SUCH_PAGE;
1010 int getVisibleIdWidth()
1012 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1013 : calculateIdWidth().width + 4;
1016 void makeAlignmentImage(int type, File file)
1018 int maxwidth = av.alignment.getWidth();
1019 if (av.hasHiddenColumns)
1021 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1024 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1025 + scalePanel.getHeight();
1026 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1028 if (av.getWrapAlignment())
1030 height = getWrappedHeight();
1031 if (System.getProperty("java.awt.headless") != null
1032 && System.getProperty("java.awt.headless").equals("true"))
1034 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1035 - alignFrame.getInsets().left
1036 - alignFrame.getInsets().right;
1040 width = seqPanel.getWidth() + getVisibleIdWidth();
1044 else if (av.getShowAnnotation())
1046 height += annotationPanel.adjustPanelHeight() + 3;
1052 jalview.util.ImageMaker im;
1053 if (type == jalview.util.ImageMaker.PNG)
1055 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1056 "Create PNG image from alignment", width, height, file,
1061 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1062 "Create EPS file from alignment", width, height, file,
1063 alignFrame.getTitle());
1066 if (av.getWrapAlignment())
1068 if (im.getGraphics() != null)
1070 printWrappedAlignment(im.getGraphics(), width, height, 0);
1076 if (im.getGraphics() != null)
1078 printUnwrapped(im.getGraphics(), width, height, 0);
1082 } catch (OutOfMemoryError err)
1085 System.out.println("########################\n" + "OUT OF MEMORY "
1086 + file + "\n" + "########################");
1087 new OOMWarning("Creating Image for " + file, err);
1088 // System.out.println("Create IMAGE: " + err);
1089 } catch (Exception ex)
1091 ex.printStackTrace();
1098 public void makeEPS(File epsFile)
1100 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1106 public void makePNG(File pngFile)
1108 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1111 public void makePNGImageMap(File imgMapFile, String imageName)
1113 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1114 // ////////////////////////////////////////////
1115 int idWidth = getVisibleIdWidth();
1116 FontMetrics fm = getFontMetrics(av.getFont());
1117 int scaleHeight = av.charHeight + fm.getDescent();
1120 // ////////////////////////////////
1121 if (imgMapFile != null)
1125 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1126 .getWidth(), g, gSize, f, fSize, sy;
1127 StringBuffer text = new StringBuffer();
1128 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1129 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1130 out.println("<img src=\"" + imageName
1131 + "\" border=\"0\" usemap=\"#Map\" >"
1132 + "<map name=\"Map\">");
1134 for (s = 0; s < sSize; s++)
1136 sy = s * av.charHeight + scaleHeight;
1138 SequenceI seq = av.alignment.getSequenceAt(s);
1139 SequenceFeature[] features = seq.getDatasetSequence()
1140 .getSequenceFeatures();
1141 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1142 for (res = 0; res < alwidth; res++)
1144 text = new StringBuffer();
1146 if (av.alignment.isNucleotide())
1148 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1153 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1162 String triplet = obj.toString();
1163 int alIndex = seq.findPosition(res);
1164 gSize = groups.length;
1165 for (g = 0; g < gSize; g++)
1167 if (text.length() < 1)
1169 text.append("<area shape=\"rect\" coords=\""
1170 + (idWidth + res * av.charWidth) + "," + sy + ","
1171 + (idWidth + (res + 1) * av.charWidth) + ","
1172 + (av.charHeight + sy) + "\""
1173 + " onMouseOver=\"toolTip('" + alIndex + " "
1177 if (groups[g].getStartRes() < res
1178 && groups[g].getEndRes() > res)
1180 text.append("<br><em>" + groups[g].getName() + "</em>");
1184 if (features != null)
1186 if (text.length() < 1)
1188 text.append("<area shape=\"rect\" coords=\""
1189 + (idWidth + res * av.charWidth) + "," + sy + ","
1190 + (idWidth + (res + 1) * av.charWidth) + ","
1191 + (av.charHeight + sy) + "\""
1192 + " onMouseOver=\"toolTip('" + alIndex + " "
1195 fSize = features.length;
1196 for (f = 0; f < fSize; f++)
1199 if ((features[f].getBegin() <= seq.findPosition(res))
1200 && (features[f].getEnd() >= seq.findPosition(res)))
1202 if (features[f].getType().equals("disulfide bond"))
1204 if (features[f].getBegin() == seq.findPosition(res)
1205 || features[f].getEnd() == seq
1208 text.append("<br>disulfide bond "
1209 + features[f].getBegin() + ":"
1210 + features[f].getEnd());
1215 text.append("<br>");
1216 text.append(features[f].getType());
1217 if (features[f].getDescription() != null
1218 && !features[f].getType().equals(
1219 features[f].getDescription()))
1221 text.append(" " + features[f].getDescription());
1224 if (features[f].getValue("status") != null)
1226 text.append(" (" + features[f].getValue("status")
1234 if (text.length() > 1)
1236 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1237 out.println(text.toString());
1241 out.println("</map></body></html>");
1244 } catch (Exception ex)
1246 ex.printStackTrace();
1248 } // /////////END OF IMAGE MAP
1252 int getWrappedHeight()
1254 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1256 if (System.getProperty("java.awt.headless") != null
1257 && System.getProperty("java.awt.headless").equals("true"))
1259 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1260 - vscroll.getPreferredSize().width
1261 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1264 int chunkWidth = seqPanel.seqCanvas
1265 .getWrappedCanvasWidth(seqPanelWidth);
1267 int hgap = av.charHeight;
1268 if (av.scaleAboveWrapped)
1270 hgap += av.charHeight;
1273 int annotationHeight = 0;
1274 if (av.showAnnotation)
1276 annotationHeight = annotationPanel.adjustPanelHeight();
1279 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1282 int maxwidth = av.alignment.getWidth();
1283 if (av.hasHiddenColumns)
1285 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1288 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1294 * close the panel - deregisters all listeners and nulls any references to
1297 public void closePanel()
1299 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1300 .getStructureSelectionManager();
1301 ssm.removeStructureViewerListener(seqPanel, null);
1302 ssm.removeSelectionListener(seqPanel);
1303 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1304 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1305 PaintRefresher.RemoveComponent(this);
1308 av.alignment = null;
1313 if (Cache.log.isDebugEnabled())
1315 Cache.log.warn("Closing alignment panel which is already closed.");
1321 * hides or shows dynamic annotation rows based on groups and av state flags
1323 public void updateAnnotation()
1325 updateAnnotation(false);
1328 public void updateAnnotation(boolean applyGlobalSettings)
1330 boolean updateCalcs = false;
1331 boolean conv = av.isShowGroupConservation();
1332 boolean cons = av.isShowGroupConsensus();
1333 boolean showprf = av.isShowSequenceLogo();
1334 boolean showConsHist = av.isShowConsensusHistogram();
1336 boolean sortg = true;
1338 // remove old automatic annotation
1339 // add any new annotation
1341 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1342 // intersect alignment annotation with alignment groups
1344 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1345 Hashtable oldrfs = new Hashtable();
1346 for (int an = 0; an < aan.length; an++)
1348 if (aan[an].autoCalculated && aan[an].groupRef != null)
1350 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1351 av.alignment.deleteAnnotation(aan[an]);
1356 for (int g = 0; g < gr.size(); g++)
1358 updateCalcs = false;
1359 sg = (SequenceGroup) gr.elementAt(g);
1360 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1362 // set defaults for this group's conservation/consensus
1363 sg.setIncludeAllConsSymbols(showprf);
1364 sg.setShowConsensusHistogram(showConsHist);
1369 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1374 av.alignment.addAnnotation(sg.getConsensus(), 0);
1376 // refresh the annotation rows
1379 sg.recalcConservation();
1383 adjustAnnotationHeight();