2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.StructureSelectionManager;
41 * @version $Revision: 1.161 $
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.getAlignment() != null)
267 int seqIndex = av.getAlignment().findIndex(results);
272 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
274 int[] r=results.getResults(seq, 0, av.getAlignment().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.getColumnSelection().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");
396 validateAnnotationDimensions(true);
398 paintAlignment(true);
401 * calculate the annotation dimensions and refresh slider values accordingly.
402 * need to do repaints/notifys afterwards.
404 protected void validateAnnotationDimensions(boolean adjustPanelHeight) {
405 int height = annotationPanel.adjustPanelHeight();
407 if (hscroll.isVisible())
409 height += hscroll.getPreferredSize().height;
411 if (height > alignFrame.getHeight() / 2)
413 height = alignFrame.getHeight() / 2;
415 if (!adjustPanelHeight)
417 // maintain same window layout whilst updating sliders
418 height=annotationScroller.getSize().height;
422 annotationScroller.setPreferredSize(new Dimension(annotationScroller
423 .getWidth(), height));
425 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
426 annotationSpaceFillerHolder.getWidth(), height));
427 annotationScroller.validate();// repaint();
428 annotationScroller.addNotify();
437 public void setWrapAlignment(boolean wrap)
440 scalePanelHolder.setVisible(!wrap);
441 hscroll.setVisible(!wrap);
442 idwidthAdjuster.setVisible(!wrap);
446 annotationScroller.setVisible(false);
447 annotationSpaceFillerHolder.setVisible(false);
449 else if (av.showAnnotation)
451 annotationScroller.setVisible(true);
452 annotationSpaceFillerHolder.setVisible(true);
455 idSpaceFillerPanel1.setVisible(!wrap);
460 // return value is true if the scroll is valid
461 public boolean scrollUp(boolean up)
465 if (vscroll.getValue() < 1)
471 vscroll.setValue(vscroll.getValue() - 1);
475 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
481 vscroll.setValue(vscroll.getValue() + 1);
495 * @return DOCUMENT ME!
497 public boolean scrollRight(boolean right)
501 if (hscroll.getValue() < 1)
507 hscroll.setValue(hscroll.getValue() - 1);
511 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
517 hscroll.setValue(hscroll.getValue() + 1);
526 * Adjust row/column scrollers to show a visible position in the alignment.
528 * @param x visible column to scroll to
530 * @param y visible row to scroll to
533 public void setScrollValues(int x, int y)
535 // System.err.println("Scroll to "+x+","+y);
536 if (av == null || av.getAlignment() == null)
540 int width = av.getAlignment().getWidth();
541 int height = av.getAlignment().getHeight();
543 if (av.hasHiddenColumns())
545 width = av.getColumnSelection().findColumnPosition(width);
548 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
550 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
551 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
558 if (vextent > height)
563 if ((hextent + x) > width)
568 if ((vextent + y) > height)
570 y = height - vextent;
583 hscroll.setValues(x, hextent, 0, width);
584 vscroll.setValues(y, vextent, 0, height);
593 public void adjustmentValueChanged(AdjustmentEvent evt)
596 int oldX = av.getStartRes();
597 int oldY = av.getStartSeq();
599 if (evt.getSource() == hscroll)
601 int x = hscroll.getValue();
603 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
606 if (evt.getSource() == vscroll)
608 int offy = vscroll.getValue();
610 if (av.getWrapAlignment())
614 int rowSize = seqPanel.seqCanvas
615 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
616 av.setStartRes(offy * rowSize);
617 av.setEndRes((offy + 1) * rowSize);
621 // This is only called if file loaded is a jar file that
622 // was wrapped when saved and user has wrap alignment true
623 // as preference setting
624 SwingUtilities.invokeLater(new Runnable()
628 setScrollValues(av.getStartRes(), av.getStartSeq());
635 av.setStartSeq(offy);
637 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
641 if (overviewPanel != null)
643 overviewPanel.setBoxPosition();
646 int scrollX = av.startRes - oldX;
647 int scrollY = av.startSeq - oldY;
649 if (av.getWrapAlignment() || !fastPaint)
655 // Make sure we're not trying to draw a panel
656 // larger than the visible window
657 if (scrollX > av.endRes - av.startRes)
659 scrollX = av.endRes - av.startRes;
661 else if (scrollX < av.startRes - av.endRes)
663 scrollX = av.startRes - av.endRes;
666 if (scrollX != 0 || scrollY != 0)
668 idPanel.idCanvas.fastPaint(scrollY);
669 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
670 scalePanel.repaint();
672 if (av.getShowAnnotation())
674 annotationPanel.fastPaint(scrollX);
680 public void paintAlignment(boolean updateOverview)
686 av.getStructureSelectionManager().sequenceColoursChanged(this);
688 if (overviewPanel != null)
690 overviewPanel.updateOverviewImage();
701 public void paintComponent(Graphics g)
705 Dimension d = idPanel.idCanvas.getPreferredSize();
706 idPanelHolder.setPreferredSize(d);
707 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
710 if (av.getWrapAlignment())
712 int maxwidth = av.getAlignment().getWidth();
714 if (av.hasHiddenColumns())
716 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
719 int canvasWidth = seqPanel.seqCanvas
720 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
725 .getWrappedCanvasWidth(seqPanel.seqCanvas
727 vscroll.setMaximum(max);
728 vscroll.setUnitIncrement(1);
729 vscroll.setVisibleAmount(1);
734 setScrollValues(av.getStartRes(), av.getStartSeq());
748 * @return DOCUMENT ME!
750 * @throws PrinterException
753 public int print(Graphics pg, PageFormat pf, int pi)
754 throws PrinterException
756 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
758 int pwidth = (int) pf.getImageableWidth();
759 int pheight = (int) pf.getImageableHeight();
761 if (av.getWrapAlignment())
763 return printWrappedAlignment(pg, pwidth, pheight, pi);
767 return printUnwrapped(pg, pwidth, pheight, pi);
783 * @return DOCUMENT ME!
785 * @throws PrinterException
788 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
789 throws PrinterException
791 int idWidth = getVisibleIdWidth();
792 FontMetrics fm = getFontMetrics(av.getFont());
793 int scaleHeight = av.charHeight + fm.getDescent();
795 pg.setColor(Color.white);
796 pg.fillRect(0, 0, pwidth, pheight);
797 pg.setFont(av.getFont());
799 // //////////////////////////////////
800 // / How many sequences and residues can we fit on a printable page?
801 int totalRes = (pwidth - idWidth) / av.getCharWidth();
803 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
805 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
807 // ///////////////////////////
808 // / Only print these sequences and residues on this page
811 // ///////////////////////////
812 // / Only print these sequences and residues on this page
815 // ///////////////////////////
816 // / Only print these sequences and residues on this page
819 // ///////////////////////////
820 // / Only print these sequences and residues on this page
822 startRes = (pi % pagesWide) * totalRes;
823 endRes = (startRes + totalRes) - 1;
825 if (endRes > (av.getAlignment().getWidth() - 1))
827 endRes = av.getAlignment().getWidth() - 1;
830 startSeq = (pi / pagesWide) * totalSeq;
831 endSeq = startSeq + totalSeq;
833 if (endSeq > av.getAlignment().getHeight())
835 endSeq = av.getAlignment().getHeight();
838 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1) * pheight;
840 if (av.showAnnotation)
842 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
845 pagesHigh /= pheight;
847 if (pi >= (pagesWide * pagesHigh))
849 return Printable.NO_SUCH_PAGE;
853 pg.translate(idWidth, 0);
854 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
856 pg.translate(-idWidth, scaleHeight);
860 Color currentColor = null;
861 Color currentTextColor = null;
863 pg.setFont(idPanel.idCanvas.idfont);
866 for (int i = startSeq; i < endSeq; i++)
868 seq = av.getAlignment().getSequenceAt(i);
869 if ((av.getSelectionGroup() != null)
870 && av.getSelectionGroup().getSequences(null).contains(seq))
872 currentColor = Color.gray;
873 currentTextColor = Color.black;
877 currentColor = av.getSequenceColour(seq);
878 currentTextColor = Color.black;
881 pg.setColor(currentColor);
882 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
885 pg.setColor(currentTextColor);
888 if (av.rightAlignIds)
890 fm = pg.getFontMetrics();
892 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
897 seq.getDisplayId(av.getShowJVSuffix()),
899 (((i - startSeq) * av.charHeight) + av.getCharHeight())
900 - (av.getCharHeight() / 5));
903 pg.setFont(av.getFont());
905 // draw main sequence panel
906 pg.translate(idWidth, 0);
907 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
909 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
911 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
912 alabels.drawComponent((Graphics2D) pg, idWidth);
913 pg.translate(idWidth + 3, 0);
914 annotationPanel.renderer.drawComponent(annotationPanel, av, (Graphics2D) pg, -1, startRes, endRes + 1);
917 return Printable.PAGE_EXISTS;
932 * @return DOCUMENT ME!
934 * @throws PrinterException
937 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
938 int pi) throws PrinterException
941 int annotationHeight = 0;
942 AnnotationLabels labels = null;
943 if (av.showAnnotation)
945 annotationHeight = annotationPanel.adjustPanelHeight();
946 labels = new AnnotationLabels(av);
949 int hgap = av.charHeight;
950 if (av.scaleAboveWrapped)
952 hgap += av.charHeight;
955 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
958 int idWidth = getVisibleIdWidth();
960 int maxwidth = av.getAlignment().getWidth();
961 if (av.hasHiddenColumns())
963 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
966 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
969 int totalHeight = cHeight * (maxwidth / resWidth + 1);
971 pg.setColor(Color.white);
972 pg.fillRect(0, 0, pwidth, pheight);
973 pg.setFont(av.getFont());
977 pg.setColor(Color.black);
979 pg.translate(0, -pi * pheight);
981 pg.setClip(0, pi * pheight, pwidth, pheight);
987 for (int i = 0; i < av.getAlignment().getHeight(); i++)
989 pg.setFont(idPanel.idCanvas.idfont);
990 SequenceI s = av.getAlignment().getSequenceAt(i);
991 String string = s.getDisplayId(av.getShowJVSuffix());
993 if (av.rightAlignIds)
995 FontMetrics fm = pg.getFontMetrics();
996 xPos = idWidth - fm.stringWidth(string) - 4;
998 pg.drawString(string, xPos,
999 ((i * av.charHeight) + ypos + av.charHeight)
1000 - (av.charHeight / 5));
1004 pg.translate(-3, ypos
1005 + (av.getAlignment().getHeight() * av.charHeight));
1007 pg.setFont(av.getFont());
1008 labels.drawComponent(pg, idWidth);
1009 pg.translate(+3, -ypos
1010 - (av.getAlignment().getHeight() * av.charHeight));
1014 } while (ypos < totalHeight);
1016 pg.translate(idWidth, 0);
1018 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1021 if ((pi * pheight) < totalHeight)
1023 return Printable.PAGE_EXISTS;
1028 return Printable.NO_SUCH_PAGE;
1032 int getVisibleIdWidth()
1034 return idPanel.getWidth() > 0 ? idPanel.getWidth()
1035 : calculateIdWidth().width + 4;
1038 void makeAlignmentImage(int type, File file)
1040 int maxwidth = av.getAlignment().getWidth();
1041 if (av.hasHiddenColumns())
1043 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1046 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1047 + scalePanel.getHeight();
1048 int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
1050 if (av.getWrapAlignment())
1052 height = getWrappedHeight();
1053 if (System.getProperty("java.awt.headless") != null
1054 && System.getProperty("java.awt.headless").equals("true"))
1057 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1058 - alignFrame.getInsets().left
1059 - alignFrame.getInsets().right;
1063 width = seqPanel.getWidth() + getVisibleIdWidth();
1067 else if (av.getShowAnnotation())
1069 height += annotationPanel.adjustPanelHeight() + 3;
1075 jalview.util.ImageMaker im;
1076 if (type == jalview.util.ImageMaker.PNG)
1078 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1079 "Create PNG image from alignment", width, height, file,
1084 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1085 "Create EPS file from alignment", width, height, file,
1086 alignFrame.getTitle());
1089 if (av.getWrapAlignment())
1091 if (im.getGraphics() != null)
1093 printWrappedAlignment(im.getGraphics(), width, height, 0);
1099 if (im.getGraphics() != null)
1101 printUnwrapped(im.getGraphics(), width, height, 0);
1105 } catch (OutOfMemoryError err)
1108 System.out.println("########################\n" + "OUT OF MEMORY "
1109 + file + "\n" + "########################");
1110 new OOMWarning("Creating Image for " + file, err);
1111 // System.out.println("Create IMAGE: " + err);
1112 } catch (Exception ex)
1114 ex.printStackTrace();
1121 public void makeEPS(File epsFile)
1123 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1129 public void makePNG(File pngFile)
1131 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1134 public void makePNGImageMap(File imgMapFile, String imageName)
1136 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1137 // ////////////////////////////////////////////
1138 int idWidth = getVisibleIdWidth();
1139 FontMetrics fm = getFontMetrics(av.getFont());
1140 int scaleHeight = av.charHeight + fm.getDescent();
1143 // ////////////////////////////////
1144 if (imgMapFile != null)
1148 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av.getAlignment()
1149 .getWidth(), g, gSize, f, fSize, sy;
1150 StringBuffer text = new StringBuffer();
1151 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1152 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1153 out.println("<img src=\"" + imageName
1154 + "\" border=\"0\" usemap=\"#Map\" >"
1155 + "<map name=\"Map\">");
1157 for (s = 0; s < sSize; s++)
1159 sy = s * av.charHeight + scaleHeight;
1161 SequenceI seq = av.getAlignment().getSequenceAt(s);
1162 SequenceFeature[] features = seq.getDatasetSequence()
1163 .getSequenceFeatures();
1164 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1165 for (res = 0; res < alwidth; res++)
1167 text = new StringBuffer();
1169 if (av.getAlignment().isNucleotide())
1171 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1176 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1185 String triplet = obj.toString();
1186 int alIndex = seq.findPosition(res);
1187 gSize = groups.length;
1188 for (g = 0; g < gSize; g++)
1190 if (text.length() < 1)
1192 text.append("<area shape=\"rect\" coords=\""
1193 + (idWidth + res * av.charWidth) + "," + sy + ","
1194 + (idWidth + (res + 1) * av.charWidth) + ","
1195 + (av.charHeight + sy) + "\""
1196 + " onMouseOver=\"toolTip('" + alIndex + " "
1200 if (groups[g].getStartRes() < res
1201 && groups[g].getEndRes() > res)
1203 text.append("<br><em>" + groups[g].getName() + "</em>");
1207 if (features != null)
1209 if (text.length() < 1)
1211 text.append("<area shape=\"rect\" coords=\""
1212 + (idWidth + res * av.charWidth) + "," + sy + ","
1213 + (idWidth + (res + 1) * av.charWidth) + ","
1214 + (av.charHeight + sy) + "\""
1215 + " onMouseOver=\"toolTip('" + alIndex + " "
1218 fSize = features.length;
1219 for (f = 0; f < fSize; f++)
1222 if ((features[f].getBegin() <= seq.findPosition(res))
1223 && (features[f].getEnd() >= seq.findPosition(res)))
1225 if (features[f].getType().equals("disulfide bond"))
1227 if (features[f].getBegin() == seq.findPosition(res)
1228 || features[f].getEnd() == seq
1231 text.append("<br>disulfide bond "
1232 + features[f].getBegin() + ":"
1233 + features[f].getEnd());
1238 text.append("<br>");
1239 text.append(features[f].getType());
1240 if (features[f].getDescription() != null
1241 && !features[f].getType().equals(
1242 features[f].getDescription()))
1244 text.append(" " + features[f].getDescription());
1247 if (features[f].getValue("status") != null)
1249 text.append(" (" + features[f].getValue("status")
1257 if (text.length() > 1)
1259 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1260 out.println(text.toString());
1264 out.println("</map></body></html>");
1267 } catch (Exception ex)
1269 ex.printStackTrace();
1271 } // /////////END OF IMAGE MAP
1275 int getWrappedHeight()
1277 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1279 if (System.getProperty("java.awt.headless") != null
1280 && System.getProperty("java.awt.headless").equals("true"))
1282 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1283 - vscroll.getPreferredSize().width
1284 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1287 int chunkWidth = seqPanel.seqCanvas
1288 .getWrappedCanvasWidth(seqPanelWidth);
1290 int hgap = av.charHeight;
1291 if (av.scaleAboveWrapped)
1293 hgap += av.charHeight;
1296 int annotationHeight = 0;
1297 if (av.showAnnotation)
1299 annotationHeight = annotationPanel.adjustPanelHeight();
1302 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1305 int maxwidth = av.getAlignment().getWidth();
1306 if (av.hasHiddenColumns())
1308 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1311 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1317 * close the panel - deregisters all listeners and nulls any references to
1320 public void closePanel()
1322 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1323 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1324 PaintRefresher.RemoveComponent(this);
1327 jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager();
1328 ssm.removeStructureViewerListener(seqPanel, null);
1329 ssm.removeSelectionListener(seqPanel);
1330 av.setAlignment(null);
1335 if (Cache.log.isDebugEnabled())
1337 Cache.log.warn("Closing alignment panel which is already closed.");
1343 * hides or shows dynamic annotation rows based on groups and av state flags
1345 public void updateAnnotation()
1347 updateAnnotation(false);
1350 public void updateAnnotation(boolean applyGlobalSettings)
1352 // TODO: this should be merged with other annotation update stuff - that
1353 // sits on AlignViewport
1354 boolean updateCalcs = false;
1355 boolean conv = av.isShowGroupConservation();
1356 boolean cons = av.isShowGroupConsensus();
1357 boolean showprf = av.isShowSequenceLogo();
1358 boolean showConsHist = av.isShowConsensusHistogram();
1359 boolean normLogo = av.isNormaliseSequenceLogo();
1361 boolean sortg = true;
1363 // remove old automatic annotation
1364 // add any new annotation
1366 Vector gr = av.getAlignment().getGroups(); // OrderedBy(av.getAlignment().getSequencesArray());
1367 // intersect alignment annotation with alignment groups
1369 AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation();
1370 Hashtable oldrfs = new Hashtable();
1373 for (int an = 0; an < aan.length; an++)
1375 if (aan[an].autoCalculated && aan[an].groupRef != null)
1377 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1378 av.getAlignment().deleteAnnotation(aan[an]);
1386 for (int g = 0; g < gr.size(); g++)
1388 updateCalcs = false;
1389 sg = (SequenceGroup) gr.elementAt(g);
1390 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1392 // set defaults for this group's conservation/consensus
1393 sg.setshowSequenceLogo(showprf);
1394 sg.setShowConsensusHistogram(showConsHist);
1395 sg.setNormaliseSequenceLogo(normLogo);
1400 av.getAlignment().addAnnotation(sg.getConservationRow(), 0);
1405 av.getAlignment().addAnnotation(sg.getConsensus(), 0);
1407 // refresh the annotation rows
1410 sg.recalcConservation();
1415 adjustAnnotationHeight();
1419 public AlignmentI getAlignment()
1421 return av.getAlignment();
1425 * get the name for this view
1428 public String getViewName()
1434 * Make/Unmake this alignment panel the current input focus
1437 public void setSelected(boolean b)
1440 alignFrame.setSelected(b);
1441 } catch (Exception ex) {};
1445 alignFrame.setDisplayedView(this);
1450 public StructureSelectionManager getStructureSelectionManager()
1452 return av.getStructureSelectionManager();
1456 public void raiseOOMWarning(String string, OutOfMemoryError error)
1458 new OOMWarning(string, error, this);