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)
370 * @param b Hide or show annotation panel
373 public void setAnnotationVisible(boolean b)
375 if (!av.wrapAlignment)
377 annotationSpaceFillerHolder.setVisible(b);
378 annotationScroller.setVisible(b);
384 * automatically adjust annotation panel height for new annotation
385 * whilst ensuring the alignment is still visible.
387 public void adjustAnnotationHeight()
389 // TODO: display vertical annotation scrollbar if necessary
390 // this is called after loading new annotation onto alignment
391 if (alignFrame.getHeight() == 0)
393 System.out.println("NEEDS FIXING");
396 int height = annotationPanel.adjustPanelHeight();
398 if (hscroll.isVisible())
400 height += hscroll.getPreferredSize().height;
402 if (height > alignFrame.getHeight() / 2)
404 height = alignFrame.getHeight() / 2;
409 annotationScroller.setPreferredSize(new Dimension(annotationScroller
410 .getWidth(), height));
412 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
413 annotationSpaceFillerHolder.getWidth(), height));
414 annotationScroller.validate();// repaint();
425 public void setWrapAlignment(boolean wrap)
428 scalePanelHolder.setVisible(!wrap);
429 hscroll.setVisible(!wrap);
430 idwidthAdjuster.setVisible(!wrap);
434 annotationScroller.setVisible(false);
435 annotationSpaceFillerHolder.setVisible(false);
437 else if (av.showAnnotation)
439 annotationScroller.setVisible(true);
440 annotationSpaceFillerHolder.setVisible(true);
443 idSpaceFillerPanel1.setVisible(!wrap);
448 // return value is true if the scroll is valid
449 public boolean scrollUp(boolean up)
453 if (vscroll.getValue() < 1)
459 vscroll.setValue(vscroll.getValue() - 1);
463 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
469 vscroll.setValue(vscroll.getValue() + 1);
483 * @return DOCUMENT ME!
485 public boolean scrollRight(boolean right)
489 if (hscroll.getValue() < 1)
495 hscroll.setValue(hscroll.getValue() - 1);
499 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
505 hscroll.setValue(hscroll.getValue() + 1);
514 * Adjust row/column scrollers to show a visible position in the alignment.
516 * @param x visible column to scroll to
518 * @param y visible row to scroll to
521 public void setScrollValues(int x, int y)
523 // System.err.println("Scroll to "+x+","+y);
524 if (av == null || av.alignment == null)
528 int width = av.alignment.getWidth();
529 int height = av.alignment.getHeight();
531 if (av.hasHiddenColumns)
533 width = av.getColumnSelection().findColumnPosition(width);
536 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
538 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
539 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
546 if (vextent > height)
551 if ((hextent + x) > width)
556 if ((vextent + y) > height)
558 y = height - vextent;
571 hscroll.setValues(x, hextent, 0, width);
572 vscroll.setValues(y, vextent, 0, height);
581 public void adjustmentValueChanged(AdjustmentEvent evt)
584 int oldX = av.getStartRes();
585 int oldY = av.getStartSeq();
587 if (evt.getSource() == hscroll)
589 int x = hscroll.getValue();
591 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
594 if (evt.getSource() == vscroll)
596 int offy = vscroll.getValue();
598 if (av.getWrapAlignment())
602 int rowSize = seqPanel.seqCanvas
603 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
604 av.setStartRes(offy * rowSize);
605 av.setEndRes((offy + 1) * rowSize);
609 // This is only called if file loaded is a jar file that
610 // was wrapped when saved and user has wrap alignment true
611 // as preference setting
612 SwingUtilities.invokeLater(new Runnable()
616 setScrollValues(av.getStartRes(), av.getStartSeq());
623 av.setStartSeq(offy);
625 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
629 if (overviewPanel != null)
631 overviewPanel.setBoxPosition();
634 int scrollX = av.startRes - oldX;
635 int scrollY = av.startSeq - oldY;
637 if (av.getWrapAlignment() || !fastPaint)
643 // Make sure we're not trying to draw a panel
644 // larger than the visible window
645 if (scrollX > av.endRes - av.startRes)
647 scrollX = av.endRes - av.startRes;
649 else if (scrollX < av.startRes - av.endRes)
651 scrollX = av.startRes - av.endRes;
654 if (scrollX != 0 || scrollY != 0)
656 idPanel.idCanvas.fastPaint(scrollY);
657 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
658 scalePanel.repaint();
660 if (av.getShowAnnotation())
662 annotationPanel.fastPaint(scrollX);
668 public void paintAlignment(boolean updateOverview)
674 jalview.structure.StructureSelectionManager
675 .getStructureSelectionManager().sequenceColoursChanged(this);
677 if (overviewPanel != null)
679 overviewPanel.updateOverviewImage();
690 public void paintComponent(Graphics g)
694 Dimension d = idPanel.idCanvas.getPreferredSize();
695 idPanelHolder.setPreferredSize(d);
696 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
699 if (av.getWrapAlignment())
701 int maxwidth = av.alignment.getWidth();
703 if (av.hasHiddenColumns)
705 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
708 int canvasWidth = seqPanel.seqCanvas
709 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
714 .getWrappedCanvasWidth(seqPanel.seqCanvas
716 vscroll.setMaximum(max);
717 vscroll.setUnitIncrement(1);
718 vscroll.setVisibleAmount(1);
723 setScrollValues(av.getStartRes(), av.getStartSeq());
737 * @return DOCUMENT ME!
739 * @throws PrinterException
742 public int print(Graphics pg, PageFormat pf, int pi)
743 throws PrinterException
745 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
747 int pwidth = (int) pf.getImageableWidth();
748 int pheight = (int) pf.getImageableHeight();
750 if (av.getWrapAlignment())
752 return printWrappedAlignment(pg, pwidth, pheight, pi);
756 return printUnwrapped(pg, pwidth, pheight, pi);
772 * @return DOCUMENT ME!
774 * @throws PrinterException
777 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
778 throws PrinterException
780 int idWidth = getVisibleIdWidth();
781 FontMetrics fm = getFontMetrics(av.getFont());
782 int scaleHeight = av.charHeight + fm.getDescent();
784 pg.setColor(Color.white);
785 pg.fillRect(0, 0, pwidth, pheight);
786 pg.setFont(av.getFont());
788 // //////////////////////////////////
789 // / How many sequences and residues can we fit on a printable page?
790 int totalRes = (pwidth - idWidth) / av.getCharWidth();
792 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
794 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
796 // ///////////////////////////
797 // / Only print these sequences and residues on this page
800 // ///////////////////////////
801 // / Only print these sequences and residues on this page
804 // ///////////////////////////
805 // / Only print these sequences and residues on this page
808 // ///////////////////////////
809 // / Only print these sequences and residues on this page
811 startRes = (pi % pagesWide) * totalRes;
812 endRes = (startRes + totalRes) - 1;
814 if (endRes > (av.getAlignment().getWidth() - 1))
816 endRes = av.getAlignment().getWidth() - 1;
819 startSeq = (pi / pagesWide) * totalSeq;
820 endSeq = startSeq + totalSeq;
822 if (endSeq > av.getAlignment().getHeight())
824 endSeq = av.getAlignment().getHeight();
827 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
829 if (av.showAnnotation)
831 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
834 pagesHigh /= pheight;
836 if (pi >= (pagesWide * pagesHigh))
838 return Printable.NO_SUCH_PAGE;
842 pg.translate(idWidth, 0);
843 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
845 pg.translate(-idWidth, scaleHeight);
849 Color currentColor = null;
850 Color currentTextColor = null;
852 pg.setFont(idPanel.idCanvas.idfont);
855 for (int i = startSeq; i < endSeq; i++)
857 seq = av.getAlignment().getSequenceAt(i);
858 if ((av.getSelectionGroup() != null)
859 && av.getSelectionGroup().getSequences(null).contains(seq))
861 currentColor = Color.gray;
862 currentTextColor = Color.black;
866 currentColor = av.getSequenceColour(seq);
867 currentTextColor = Color.black;
870 pg.setColor(currentColor);
871 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
874 pg.setColor(currentTextColor);
877 if (av.rightAlignIds)
879 fm = pg.getFontMetrics();
881 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
886 seq.getDisplayId(av.getShowJVSuffix()),
888 (((i - startSeq) * av.charHeight) + av.getCharHeight())
889 - (av.getCharHeight() / 5));
892 pg.setFont(av.getFont());
894 // draw main sequence panel
895 pg.translate(idWidth, 0);
896 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
898 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
900 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
901 alabels.drawComponent((Graphics2D) pg, idWidth);
902 pg.translate(idWidth + 3, 0);
903 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
906 return Printable.PAGE_EXISTS;
921 * @return DOCUMENT ME!
923 * @throws PrinterException
926 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
927 int pi) throws PrinterException
930 int annotationHeight = 0;
931 AnnotationLabels labels = null;
932 if (av.showAnnotation)
934 annotationHeight = annotationPanel.adjustPanelHeight();
935 labels = new AnnotationLabels(av);
938 int hgap = av.charHeight;
939 if (av.scaleAboveWrapped)
941 hgap += av.charHeight;
944 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
947 int idWidth = getVisibleIdWidth();
949 int maxwidth = av.alignment.getWidth();
950 if (av.hasHiddenColumns)
952 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
955 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
958 int totalHeight = cHeight * (maxwidth / resWidth + 1);
960 pg.setColor(Color.white);
961 pg.fillRect(0, 0, pwidth, pheight);
962 pg.setFont(av.getFont());
966 pg.setColor(Color.black);
968 pg.translate(0, -pi * pheight);
970 pg.setClip(0, pi * pheight, pwidth, pheight);
976 for (int i = 0; i < av.alignment.getHeight(); i++)
978 pg.setFont(idPanel.idCanvas.idfont);
979 SequenceI s = av.alignment.getSequenceAt(i);
980 String string = s.getDisplayId(av.getShowJVSuffix());
982 if (av.rightAlignIds)
984 FontMetrics fm = pg.getFontMetrics();
985 xPos = idWidth - fm.stringWidth(string) - 4;
987 pg.drawString(string, xPos,
988 ((i * av.charHeight) + ypos + av.charHeight)
989 - (av.charHeight / 5));
993 pg.translate(-3, ypos
994 + (av.getAlignment().getHeight() * av.charHeight));
996 pg.setFont(av.getFont());
997 labels.drawComponent(pg, idWidth);
998 pg.translate(+3, -ypos
999 - (av.getAlignment().getHeight() * av.charHeight));
1003 } while (ypos < totalHeight);
1005 pg.translate(idWidth, 0);
1007 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1010 if ((pi * pheight) < totalHeight)
1012 return Printable.PAGE_EXISTS;
1017 return Printable.NO_SUCH_PAGE;
1021 int getVisibleIdWidth()
1023 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1024 : calculateIdWidth().width + 4;
1027 void makeAlignmentImage(int type, File file)
1029 int maxwidth = av.alignment.getWidth();
1030 if (av.hasHiddenColumns)
1032 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1035 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1036 + scalePanel.getHeight();
1037 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1039 if (av.getWrapAlignment())
1041 height = getWrappedHeight();
1042 if (System.getProperty("java.awt.headless") != null
1043 && System.getProperty("java.awt.headless").equals("true"))
1045 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1046 - alignFrame.getInsets().left
1047 - alignFrame.getInsets().right;
1051 width = seqPanel.getWidth() + getVisibleIdWidth();
1055 else if (av.getShowAnnotation())
1057 height += annotationPanel.adjustPanelHeight() + 3;
1063 jalview.util.ImageMaker im;
1064 if (type == jalview.util.ImageMaker.PNG)
1066 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1067 "Create PNG image from alignment", width, height, file,
1072 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1073 "Create EPS file from alignment", width, height, file,
1074 alignFrame.getTitle());
1077 if (av.getWrapAlignment())
1079 if (im.getGraphics() != null)
1081 printWrappedAlignment(im.getGraphics(), width, height, 0);
1087 if (im.getGraphics() != null)
1089 printUnwrapped(im.getGraphics(), width, height, 0);
1093 } catch (OutOfMemoryError err)
1096 System.out.println("########################\n" + "OUT OF MEMORY "
1097 + file + "\n" + "########################");
1098 new OOMWarning("Creating Image for " + file, err);
1099 // System.out.println("Create IMAGE: " + err);
1100 } catch (Exception ex)
1102 ex.printStackTrace();
1109 public void makeEPS(File epsFile)
1111 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1117 public void makePNG(File pngFile)
1119 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1122 public void makePNGImageMap(File imgMapFile, String imageName)
1124 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1125 // ////////////////////////////////////////////
1126 int idWidth = getVisibleIdWidth();
1127 FontMetrics fm = getFontMetrics(av.getFont());
1128 int scaleHeight = av.charHeight + fm.getDescent();
1131 // ////////////////////////////////
1132 if (imgMapFile != null)
1136 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1137 .getWidth(), g, gSize, f, fSize, sy;
1138 StringBuffer text = new StringBuffer();
1139 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1140 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1141 out.println("<img src=\"" + imageName
1142 + "\" border=\"0\" usemap=\"#Map\" >"
1143 + "<map name=\"Map\">");
1145 for (s = 0; s < sSize; s++)
1147 sy = s * av.charHeight + scaleHeight;
1149 SequenceI seq = av.alignment.getSequenceAt(s);
1150 SequenceFeature[] features = seq.getDatasetSequence()
1151 .getSequenceFeatures();
1152 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1153 for (res = 0; res < alwidth; res++)
1155 text = new StringBuffer();
1157 if (av.alignment.isNucleotide())
1159 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1164 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1173 String triplet = obj.toString();
1174 int alIndex = seq.findPosition(res);
1175 gSize = groups.length;
1176 for (g = 0; g < gSize; g++)
1178 if (text.length() < 1)
1180 text.append("<area shape=\"rect\" coords=\""
1181 + (idWidth + res * av.charWidth) + "," + sy + ","
1182 + (idWidth + (res + 1) * av.charWidth) + ","
1183 + (av.charHeight + sy) + "\""
1184 + " onMouseOver=\"toolTip('" + alIndex + " "
1188 if (groups[g].getStartRes() < res
1189 && groups[g].getEndRes() > res)
1191 text.append("<br><em>" + groups[g].getName() + "</em>");
1195 if (features != null)
1197 if (text.length() < 1)
1199 text.append("<area shape=\"rect\" coords=\""
1200 + (idWidth + res * av.charWidth) + "," + sy + ","
1201 + (idWidth + (res + 1) * av.charWidth) + ","
1202 + (av.charHeight + sy) + "\""
1203 + " onMouseOver=\"toolTip('" + alIndex + " "
1206 fSize = features.length;
1207 for (f = 0; f < fSize; f++)
1210 if ((features[f].getBegin() <= seq.findPosition(res))
1211 && (features[f].getEnd() >= seq.findPosition(res)))
1213 if (features[f].getType().equals("disulfide bond"))
1215 if (features[f].getBegin() == seq.findPosition(res)
1216 || features[f].getEnd() == seq
1219 text.append("<br>disulfide bond "
1220 + features[f].getBegin() + ":"
1221 + features[f].getEnd());
1226 text.append("<br>");
1227 text.append(features[f].getType());
1228 if (features[f].getDescription() != null
1229 && !features[f].getType().equals(
1230 features[f].getDescription()))
1232 text.append(" " + features[f].getDescription());
1235 if (features[f].getValue("status") != null)
1237 text.append(" (" + features[f].getValue("status")
1245 if (text.length() > 1)
1247 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1248 out.println(text.toString());
1252 out.println("</map></body></html>");
1255 } catch (Exception ex)
1257 ex.printStackTrace();
1259 } // /////////END OF IMAGE MAP
1263 int getWrappedHeight()
1265 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1267 if (System.getProperty("java.awt.headless") != null
1268 && System.getProperty("java.awt.headless").equals("true"))
1270 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1271 - vscroll.getPreferredSize().width
1272 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1275 int chunkWidth = seqPanel.seqCanvas
1276 .getWrappedCanvasWidth(seqPanelWidth);
1278 int hgap = av.charHeight;
1279 if (av.scaleAboveWrapped)
1281 hgap += av.charHeight;
1284 int annotationHeight = 0;
1285 if (av.showAnnotation)
1287 annotationHeight = annotationPanel.adjustPanelHeight();
1290 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1293 int maxwidth = av.alignment.getWidth();
1294 if (av.hasHiddenColumns)
1296 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1299 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1305 * close the panel - deregisters all listeners and nulls any references to
1308 public void closePanel()
1310 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1311 .getStructureSelectionManager();
1312 ssm.removeStructureViewerListener(seqPanel, null);
1313 ssm.removeSelectionListener(seqPanel);
1314 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1315 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1316 PaintRefresher.RemoveComponent(this);
1319 av.alignment = null;
1324 if (Cache.log.isDebugEnabled())
1326 Cache.log.warn("Closing alignment panel which is already closed.");
1332 * hides or shows dynamic annotation rows based on groups and av state flags
1334 public void updateAnnotation()
1336 updateAnnotation(false);
1339 public void updateAnnotation(boolean applyGlobalSettings)
1341 // TODO: this should be merged with other annotation update stuff - that
1342 // sits on AlignViewport
1343 boolean updateCalcs = false;
1344 boolean conv = av.isShowGroupConservation();
1345 boolean cons = av.isShowGroupConsensus();
1346 boolean showprf = av.isShowSequenceLogo();
1347 boolean showConsHist = av.isShowConsensusHistogram();
1349 boolean sortg = true;
1351 // remove old automatic annotation
1352 // add any new annotation
1354 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1355 // intersect alignment annotation with alignment groups
1357 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1358 Hashtable oldrfs = new Hashtable();
1361 for (int an = 0; an < aan.length; an++)
1363 if (aan[an].autoCalculated && aan[an].groupRef != null)
1365 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1366 av.alignment.deleteAnnotation(aan[an]);
1374 for (int g = 0; g < gr.size(); g++)
1376 updateCalcs = false;
1377 sg = (SequenceGroup) gr.elementAt(g);
1378 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1380 // set defaults for this group's conservation/consensus
1381 sg.setshowSequenceLogo(showprf);
1382 sg.setShowConsensusHistogram(showConsHist);
1387 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1392 av.alignment.addAnnotation(sg.getConsensus(), 0);
1394 // refresh the annotation rows
1397 sg.recalcConservation();
1402 adjustAnnotationHeight();