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.api.AlignmentViewPanel;
31 import jalview.bin.Cache;
32 import jalview.datamodel.*;
33 import jalview.jbgui.*;
34 import jalview.schemes.*;
35 import jalview.structure.SelectionSource;
43 public class AlignmentPanel extends GAlignmentPanel implements
44 AdjustmentListener, Printable, AlignmentViewPanel
46 public AlignViewport av;
48 OverviewPanel overviewPanel;
54 IdwidthAdjuster idwidthAdjuster;
57 public AlignFrame alignFrame;
59 ScalePanel scalePanel;
61 AnnotationPanel annotationPanel;
63 AnnotationLabels alabels;
65 // this value is set false when selection area being dragged
66 boolean fastPaint = true;
73 * Creates a new AlignmentPanel object.
80 public AlignmentPanel(AlignFrame af, final AlignViewport av)
84 seqPanel = new SeqPanel(av, this);
85 idPanel = new IdPanel(av, this);
87 scalePanel = new ScalePanel(av, this);
89 idPanelHolder.add(idPanel, BorderLayout.CENTER);
90 idwidthAdjuster = new IdwidthAdjuster(this);
91 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
93 annotationPanel = new AnnotationPanel(this);
94 alabels = new AnnotationLabels(this);
96 annotationScroller.setViewportView(annotationPanel);
97 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
99 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
100 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
102 setScrollValues(0, 0);
104 setAnnotationVisible(av.getShowAnnotation());
106 hscroll.addAdjustmentListener(this);
107 vscroll.addAdjustmentListener(this);
109 final AlignmentPanel ap = this;
110 av.addPropertyChangeListener(new PropertyChangeListener()
112 public void propertyChange(PropertyChangeEvent evt)
114 if (evt.getPropertyName().equals("alignment"))
116 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
122 adjustAnnotationHeight();
126 public void alignmentChanged()
128 av.alignmentChanged(this);
130 alignFrame.updateEditMenuBar();
132 paintAlignment(true);
139 public void fontChanged()
141 // set idCanvas bufferedImage to null
142 // to prevent drawing old image
143 FontMetrics fm = getFontMetrics(av.getFont());
145 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
147 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
150 idPanel.idCanvas.gg = null;
151 seqPanel.seqCanvas.img = null;
152 annotationPanel.adjustPanelHeight();
154 Dimension d = calculateIdWidth();
155 d.setSize(d.width + 4, d.height);
156 idPanel.idCanvas.setPreferredSize(d);
157 hscrollFillerPanel.setPreferredSize(d);
159 if (overviewPanel != null)
161 overviewPanel.setBoxPosition();
168 * Calculate the width of the alignment labels based on the displayed names
169 * and any bounds on label width set in preferences.
171 * @return Dimension giving the maximum width of the alignment label panel
172 * that should be used.
174 public Dimension calculateIdWidth()
176 Container c = new Container();
178 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
179 Font.ITALIC, av.font.getSize()));
181 AlignmentI al = av.getAlignment();
182 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
183 int maxwidth = Math.max(20,
184 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
189 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
191 SequenceI s = al.getSequenceAt(i);
193 id = s.getDisplayId(av.getShowJVSuffix());
195 if (fm.stringWidth(id) > idWidth)
197 idWidth = fm.stringWidth(id);
203 // Also check annotation label widths
206 if (al.getAlignmentAnnotation() != null)
208 fm = c.getFontMetrics(alabels.getFont());
210 while (i < al.getAlignmentAnnotation().length)
212 String label = al.getAlignmentAnnotation()[i].label;
214 if (fm.stringWidth(label) > idWidth)
216 idWidth = fm.stringWidth(label);
223 return new Dimension(Math.min(maxwidth, idWidth), 12);
227 * Highlight the given results on the alignment.
230 public void highlightSearchResults(SearchResults results)
232 scrollToPosition(results);
233 seqPanel.seqCanvas.highlightSearchResults(results);
237 * scroll the view to show the position of the highlighted region in results
238 * (if any) and redraw the overview
242 public boolean scrollToPosition(SearchResults results)
244 return scrollToPosition(results, true);
248 * scroll the view to show the position of the highlighted region in results
252 * @param redrawOverview
253 * - when set, the overview will be recalculated (takes longer)
254 * @return false if results were not found
256 public boolean scrollToPosition(SearchResults results,
257 boolean redrawOverview)
259 int startv, endv, starts, ends, width;
260 // TODO: properly locate search results in view when large numbers of hidden
261 // columns exist before highlighted region
262 // do we need to scroll the panel?
263 // TODO: tons of nullpointereexceptions raised here.
264 if (results != null && results.getSize() > 0 && av != null
265 && av.alignment != null)
267 int seqIndex = av.alignment.findIndex(results);
272 SequenceI seq = av.alignment.getSequenceAt(seqIndex);
274 int[] r=results.getResults(seq, 0, av.alignment.getWidth());
281 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
287 if (end == seq.getEnd())
291 if (av.hasHiddenColumns)
293 start = av.getColumnSelection().findColumnPosition(start);
294 end = av.getColumnSelection().findColumnPosition(end);
297 if (!av.colSel.isVisible(r[0]))
299 // don't scroll - position isn't visible
304 if (!av.wrapAlignment)
306 if ((startv = av.getStartRes()) >= start)
308 setScrollValues(start - 1, seqIndex);
310 else if ((endv = av.getEndRes()) <= end)
312 setScrollValues(startv + 1 + end - endv, seqIndex);
314 else if ((starts = av.getStartSeq()) > seqIndex)
316 setScrollValues(av.getStartRes(), seqIndex);
318 else if ((ends = av.getEndSeq()) <= seqIndex)
320 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
325 scrollToWrappedVisible(start);
328 if (redrawOverview && overviewPanel != null)
330 overviewPanel.setBoxPosition();
332 paintAlignment(redrawOverview);
336 void scrollToWrappedVisible(int res)
338 int cwidth = seqPanel.seqCanvas
339 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
340 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
342 vscroll.setValue((res / cwidth));
343 av.startRes = vscroll.getValue() * cwidth;
351 * @return DOCUMENT ME!
353 public OverviewPanel getOverviewPanel()
355 return overviewPanel;
364 public void setOverviewPanel(OverviewPanel op)
371 * @param b Hide or show annotation panel
374 public void setAnnotationVisible(boolean b)
376 if (!av.wrapAlignment)
378 annotationSpaceFillerHolder.setVisible(b);
379 annotationScroller.setVisible(b);
385 * automatically adjust annotation panel height for new annotation
386 * whilst ensuring the alignment is still visible.
388 public void adjustAnnotationHeight()
390 // TODO: display vertical annotation scrollbar if necessary
391 // this is called after loading new annotation onto alignment
392 if (alignFrame.getHeight() == 0)
394 System.out.println("NEEDS FIXING");
397 int height = annotationPanel.adjustPanelHeight();
399 if (hscroll.isVisible())
401 height += hscroll.getPreferredSize().height;
403 if (height > alignFrame.getHeight() / 2)
405 height = alignFrame.getHeight() / 2;
410 annotationScroller.setPreferredSize(new Dimension(annotationScroller
411 .getWidth(), height));
413 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
414 annotationSpaceFillerHolder.getWidth(), height));
415 annotationScroller.validate();// repaint();
426 public void setWrapAlignment(boolean wrap)
429 scalePanelHolder.setVisible(!wrap);
430 hscroll.setVisible(!wrap);
431 idwidthAdjuster.setVisible(!wrap);
435 annotationScroller.setVisible(false);
436 annotationSpaceFillerHolder.setVisible(false);
438 else if (av.showAnnotation)
440 annotationScroller.setVisible(true);
441 annotationSpaceFillerHolder.setVisible(true);
444 idSpaceFillerPanel1.setVisible(!wrap);
449 // return value is true if the scroll is valid
450 public boolean scrollUp(boolean up)
454 if (vscroll.getValue() < 1)
460 vscroll.setValue(vscroll.getValue() - 1);
464 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
470 vscroll.setValue(vscroll.getValue() + 1);
484 * @return DOCUMENT ME!
486 public boolean scrollRight(boolean right)
490 if (hscroll.getValue() < 1)
496 hscroll.setValue(hscroll.getValue() - 1);
500 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
506 hscroll.setValue(hscroll.getValue() + 1);
515 * Adjust row/column scrollers to show a visible position in the alignment.
517 * @param x visible column to scroll to
519 * @param y visible row to scroll to
522 public void setScrollValues(int x, int y)
524 // System.err.println("Scroll to "+x+","+y);
525 if (av == null || av.alignment == null)
529 int width = av.alignment.getWidth();
530 int height = av.alignment.getHeight();
532 if (av.hasHiddenColumns)
534 width = av.getColumnSelection().findColumnPosition(width);
537 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
539 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
540 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
547 if (vextent > height)
552 if ((hextent + x) > width)
557 if ((vextent + y) > height)
559 y = height - vextent;
572 hscroll.setValues(x, hextent, 0, width);
573 vscroll.setValues(y, vextent, 0, height);
582 public void adjustmentValueChanged(AdjustmentEvent evt)
585 int oldX = av.getStartRes();
586 int oldY = av.getStartSeq();
588 if (evt.getSource() == hscroll)
590 int x = hscroll.getValue();
592 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
595 if (evt.getSource() == vscroll)
597 int offy = vscroll.getValue();
599 if (av.getWrapAlignment())
603 int rowSize = seqPanel.seqCanvas
604 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
605 av.setStartRes(offy * rowSize);
606 av.setEndRes((offy + 1) * rowSize);
610 // This is only called if file loaded is a jar file that
611 // was wrapped when saved and user has wrap alignment true
612 // as preference setting
613 SwingUtilities.invokeLater(new Runnable()
617 setScrollValues(av.getStartRes(), av.getStartSeq());
624 av.setStartSeq(offy);
626 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
630 if (overviewPanel != null)
632 overviewPanel.setBoxPosition();
635 int scrollX = av.startRes - oldX;
636 int scrollY = av.startSeq - oldY;
638 if (av.getWrapAlignment() || !fastPaint)
644 // Make sure we're not trying to draw a panel
645 // larger than the visible window
646 if (scrollX > av.endRes - av.startRes)
648 scrollX = av.endRes - av.startRes;
650 else if (scrollX < av.startRes - av.endRes)
652 scrollX = av.startRes - av.endRes;
655 if (scrollX != 0 || scrollY != 0)
657 idPanel.idCanvas.fastPaint(scrollY);
658 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
659 scalePanel.repaint();
661 if (av.getShowAnnotation())
663 annotationPanel.fastPaint(scrollX);
669 public void paintAlignment(boolean updateOverview)
675 jalview.structure.StructureSelectionManager
676 .getStructureSelectionManager().sequenceColoursChanged(this);
678 if (overviewPanel != null)
680 overviewPanel.updateOverviewImage();
691 public void paintComponent(Graphics g)
695 Dimension d = idPanel.idCanvas.getPreferredSize();
696 idPanelHolder.setPreferredSize(d);
697 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
700 if (av.getWrapAlignment())
702 int maxwidth = av.alignment.getWidth();
704 if (av.hasHiddenColumns)
706 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
709 int canvasWidth = seqPanel.seqCanvas
710 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
715 .getWrappedCanvasWidth(seqPanel.seqCanvas
717 vscroll.setMaximum(max);
718 vscroll.setUnitIncrement(1);
719 vscroll.setVisibleAmount(1);
724 setScrollValues(av.getStartRes(), av.getStartSeq());
738 * @return DOCUMENT ME!
740 * @throws PrinterException
743 public int print(Graphics pg, PageFormat pf, int pi)
744 throws PrinterException
746 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
748 int pwidth = (int) pf.getImageableWidth();
749 int pheight = (int) pf.getImageableHeight();
751 if (av.getWrapAlignment())
753 return printWrappedAlignment(pg, pwidth, pheight, pi);
757 return printUnwrapped(pg, pwidth, pheight, pi);
773 * @return DOCUMENT ME!
775 * @throws PrinterException
778 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
779 throws PrinterException
781 int idWidth = getVisibleIdWidth();
782 FontMetrics fm = getFontMetrics(av.getFont());
783 int scaleHeight = av.charHeight + fm.getDescent();
785 pg.setColor(Color.white);
786 pg.fillRect(0, 0, pwidth, pheight);
787 pg.setFont(av.getFont());
789 // //////////////////////////////////
790 // / How many sequences and residues can we fit on a printable page?
791 int totalRes = (pwidth - idWidth) / av.getCharWidth();
793 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
795 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
797 // ///////////////////////////
798 // / Only print these sequences and residues on this page
801 // ///////////////////////////
802 // / Only print these sequences and residues on this page
805 // ///////////////////////////
806 // / Only print these sequences and residues on this page
809 // ///////////////////////////
810 // / Only print these sequences and residues on this page
812 startRes = (pi % pagesWide) * totalRes;
813 endRes = (startRes + totalRes) - 1;
815 if (endRes > (av.getAlignment().getWidth() - 1))
817 endRes = av.getAlignment().getWidth() - 1;
820 startSeq = (pi / pagesWide) * totalSeq;
821 endSeq = startSeq + totalSeq;
823 if (endSeq > av.getAlignment().getHeight())
825 endSeq = av.getAlignment().getHeight();
828 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
830 if (av.showAnnotation)
832 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
835 pagesHigh /= pheight;
837 if (pi >= (pagesWide * pagesHigh))
839 return Printable.NO_SUCH_PAGE;
843 pg.translate(idWidth, 0);
844 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
846 pg.translate(-idWidth, scaleHeight);
850 Color currentColor = null;
851 Color currentTextColor = null;
853 pg.setFont(idPanel.idCanvas.idfont);
856 for (int i = startSeq; i < endSeq; i++)
858 seq = av.getAlignment().getSequenceAt(i);
859 if ((av.getSelectionGroup() != null)
860 && av.getSelectionGroup().getSequences(null).contains(seq))
862 currentColor = Color.gray;
863 currentTextColor = Color.black;
867 currentColor = av.getSequenceColour(seq);
868 currentTextColor = Color.black;
871 pg.setColor(currentColor);
872 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
875 pg.setColor(currentTextColor);
878 if (av.rightAlignIds)
880 fm = pg.getFontMetrics();
882 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
887 seq.getDisplayId(av.getShowJVSuffix()),
889 (((i - startSeq) * av.charHeight) + av.getCharHeight())
890 - (av.getCharHeight() / 5));
893 pg.setFont(av.getFont());
895 // draw main sequence panel
896 pg.translate(idWidth, 0);
897 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
899 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
901 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
902 alabels.drawComponent((Graphics2D) pg, idWidth);
903 pg.translate(idWidth + 3, 0);
904 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
907 return Printable.PAGE_EXISTS;
922 * @return DOCUMENT ME!
924 * @throws PrinterException
927 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
928 int pi) throws PrinterException
931 int annotationHeight = 0;
932 AnnotationLabels labels = null;
933 if (av.showAnnotation)
935 annotationHeight = annotationPanel.adjustPanelHeight();
936 labels = new AnnotationLabels(av);
939 int hgap = av.charHeight;
940 if (av.scaleAboveWrapped)
942 hgap += av.charHeight;
945 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
948 int idWidth = getVisibleIdWidth();
950 int maxwidth = av.alignment.getWidth();
951 if (av.hasHiddenColumns)
953 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
956 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
959 int totalHeight = cHeight * (maxwidth / resWidth + 1);
961 pg.setColor(Color.white);
962 pg.fillRect(0, 0, pwidth, pheight);
963 pg.setFont(av.getFont());
967 pg.setColor(Color.black);
969 pg.translate(0, -pi * pheight);
971 pg.setClip(0, pi * pheight, pwidth, pheight);
977 for (int i = 0; i < av.alignment.getHeight(); i++)
979 pg.setFont(idPanel.idCanvas.idfont);
980 SequenceI s = av.alignment.getSequenceAt(i);
981 String string = s.getDisplayId(av.getShowJVSuffix());
983 if (av.rightAlignIds)
985 FontMetrics fm = pg.getFontMetrics();
986 xPos = idWidth - fm.stringWidth(string) - 4;
988 pg.drawString(string, xPos,
989 ((i * av.charHeight) + ypos + av.charHeight)
990 - (av.charHeight / 5));
994 pg.translate(-3, ypos
995 + (av.getAlignment().getHeight() * av.charHeight));
997 pg.setFont(av.getFont());
998 labels.drawComponent(pg, idWidth);
999 pg.translate(+3, -ypos
1000 - (av.getAlignment().getHeight() * av.charHeight));
1004 } while (ypos < totalHeight);
1006 pg.translate(idWidth, 0);
1008 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1011 if ((pi * pheight) < totalHeight)
1013 return Printable.PAGE_EXISTS;
1018 return Printable.NO_SUCH_PAGE;
1022 int getVisibleIdWidth()
1024 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1025 : calculateIdWidth().width + 4;
1028 void makeAlignmentImage(int type, File file)
1030 int maxwidth = av.alignment.getWidth();
1031 if (av.hasHiddenColumns)
1033 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1036 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1037 + scalePanel.getHeight();
1038 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1040 if (av.getWrapAlignment())
1042 height = getWrappedHeight();
1043 if (System.getProperty("java.awt.headless") != null
1044 && System.getProperty("java.awt.headless").equals("true"))
1047 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1048 - alignFrame.getInsets().left
1049 - alignFrame.getInsets().right;
1053 width = seqPanel.getWidth() + getVisibleIdWidth();
1057 else if (av.getShowAnnotation())
1059 height += annotationPanel.adjustPanelHeight() + 3;
1065 jalview.util.ImageMaker im;
1066 if (type == jalview.util.ImageMaker.PNG)
1068 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1069 "Create PNG image from alignment", width, height, file,
1074 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1075 "Create EPS file from alignment", width, height, file,
1076 alignFrame.getTitle());
1079 if (av.getWrapAlignment())
1081 if (im.getGraphics() != null)
1083 printWrappedAlignment(im.getGraphics(), width, height, 0);
1089 if (im.getGraphics() != null)
1091 printUnwrapped(im.getGraphics(), width, height, 0);
1095 } catch (OutOfMemoryError err)
1098 System.out.println("########################\n" + "OUT OF MEMORY "
1099 + file + "\n" + "########################");
1100 new OOMWarning("Creating Image for " + file, err);
1101 // System.out.println("Create IMAGE: " + err);
1102 } catch (Exception ex)
1104 ex.printStackTrace();
1111 public void makeEPS(File epsFile)
1113 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1119 public void makePNG(File pngFile)
1121 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1124 public void makePNGImageMap(File imgMapFile, String imageName)
1126 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1127 // ////////////////////////////////////////////
1128 int idWidth = getVisibleIdWidth();
1129 FontMetrics fm = getFontMetrics(av.getFont());
1130 int scaleHeight = av.charHeight + fm.getDescent();
1133 // ////////////////////////////////
1134 if (imgMapFile != null)
1138 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1139 .getWidth(), g, gSize, f, fSize, sy;
1140 StringBuffer text = new StringBuffer();
1141 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1142 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1143 out.println("<img src=\"" + imageName
1144 + "\" border=\"0\" usemap=\"#Map\" >"
1145 + "<map name=\"Map\">");
1147 for (s = 0; s < sSize; s++)
1149 sy = s * av.charHeight + scaleHeight;
1151 SequenceI seq = av.alignment.getSequenceAt(s);
1152 SequenceFeature[] features = seq.getDatasetSequence()
1153 .getSequenceFeatures();
1154 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1155 for (res = 0; res < alwidth; res++)
1157 text = new StringBuffer();
1159 if (av.alignment.isNucleotide())
1161 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1166 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1175 String triplet = obj.toString();
1176 int alIndex = seq.findPosition(res);
1177 gSize = groups.length;
1178 for (g = 0; g < gSize; g++)
1180 if (text.length() < 1)
1182 text.append("<area shape=\"rect\" coords=\""
1183 + (idWidth + res * av.charWidth) + "," + sy + ","
1184 + (idWidth + (res + 1) * av.charWidth) + ","
1185 + (av.charHeight + sy) + "\""
1186 + " onMouseOver=\"toolTip('" + alIndex + " "
1190 if (groups[g].getStartRes() < res
1191 && groups[g].getEndRes() > res)
1193 text.append("<br><em>" + groups[g].getName() + "</em>");
1197 if (features != null)
1199 if (text.length() < 1)
1201 text.append("<area shape=\"rect\" coords=\""
1202 + (idWidth + res * av.charWidth) + "," + sy + ","
1203 + (idWidth + (res + 1) * av.charWidth) + ","
1204 + (av.charHeight + sy) + "\""
1205 + " onMouseOver=\"toolTip('" + alIndex + " "
1208 fSize = features.length;
1209 for (f = 0; f < fSize; f++)
1212 if ((features[f].getBegin() <= seq.findPosition(res))
1213 && (features[f].getEnd() >= seq.findPosition(res)))
1215 if (features[f].getType().equals("disulfide bond"))
1217 if (features[f].getBegin() == seq.findPosition(res)
1218 || features[f].getEnd() == seq
1221 text.append("<br>disulfide bond "
1222 + features[f].getBegin() + ":"
1223 + features[f].getEnd());
1228 text.append("<br>");
1229 text.append(features[f].getType());
1230 if (features[f].getDescription() != null
1231 && !features[f].getType().equals(
1232 features[f].getDescription()))
1234 text.append(" " + features[f].getDescription());
1237 if (features[f].getValue("status") != null)
1239 text.append(" (" + features[f].getValue("status")
1247 if (text.length() > 1)
1249 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1250 out.println(text.toString());
1254 out.println("</map></body></html>");
1257 } catch (Exception ex)
1259 ex.printStackTrace();
1261 } // /////////END OF IMAGE MAP
1265 int getWrappedHeight()
1267 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1269 if (System.getProperty("java.awt.headless") != null
1270 && System.getProperty("java.awt.headless").equals("true"))
1272 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1273 - vscroll.getPreferredSize().width
1274 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1277 int chunkWidth = seqPanel.seqCanvas
1278 .getWrappedCanvasWidth(seqPanelWidth);
1280 int hgap = av.charHeight;
1281 if (av.scaleAboveWrapped)
1283 hgap += av.charHeight;
1286 int annotationHeight = 0;
1287 if (av.showAnnotation)
1289 annotationHeight = annotationPanel.adjustPanelHeight();
1292 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1295 int maxwidth = av.alignment.getWidth();
1296 if (av.hasHiddenColumns)
1298 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1301 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1307 * close the panel - deregisters all listeners and nulls any references to
1310 public void closePanel()
1312 jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager
1313 .getStructureSelectionManager();
1314 ssm.removeStructureViewerListener(seqPanel, null);
1315 ssm.removeSelectionListener(seqPanel);
1316 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1317 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1318 PaintRefresher.RemoveComponent(this);
1321 av.alignment = null;
1326 if (Cache.log.isDebugEnabled())
1328 Cache.log.warn("Closing alignment panel which is already closed.");
1334 * hides or shows dynamic annotation rows based on groups and av state flags
1336 public void updateAnnotation()
1338 updateAnnotation(false);
1341 public void updateAnnotation(boolean applyGlobalSettings)
1343 // TODO: this should be merged with other annotation update stuff - that
1344 // sits on AlignViewport
1345 boolean updateCalcs = false;
1346 boolean conv = av.isShowGroupConservation();
1347 boolean cons = av.isShowGroupConsensus();
1348 boolean showprf = av.isShowSequenceLogo();
1349 boolean showConsHist = av.isShowConsensusHistogram();
1351 boolean sortg = true;
1353 // remove old automatic annotation
1354 // add any new annotation
1356 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1357 // intersect alignment annotation with alignment groups
1359 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1360 Hashtable oldrfs = new Hashtable();
1363 for (int an = 0; an < aan.length; an++)
1365 if (aan[an].autoCalculated && aan[an].groupRef != null)
1367 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1368 av.alignment.deleteAnnotation(aan[an]);
1376 for (int g = 0; g < gr.size(); g++)
1378 updateCalcs = false;
1379 sg = (SequenceGroup) gr.elementAt(g);
1380 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1382 // set defaults for this group's conservation/consensus
1383 sg.setshowSequenceLogo(showprf);
1384 sg.setShowConsensusHistogram(showConsHist);
1389 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1394 av.alignment.addAnnotation(sg.getConsensus(), 0);
1396 // refresh the annotation rows
1399 sg.recalcConservation();
1404 adjustAnnotationHeight();
1408 public AlignmentI getAlignment()
1410 return av.alignment;
1414 * get the name for this view
1417 public String getViewName()
1423 * Make/Unmake this alignment panel the current input focus
1426 public void setSelected(boolean b)
1429 alignFrame.setSelected(b);
1430 } catch (Exception ex) {};
1434 alignFrame.setDisplayedView(this);