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;
25 import java.awt.event.*;
26 import java.awt.print.*;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.jbgui.*;
33 import jalview.schemes.*;
34 import jalview.structure.StructureSelectionManager;
40 * @version $Revision: 1.161 $
42 public class AlignmentPanel extends GAlignmentPanel implements
43 AdjustmentListener, Printable, AlignmentViewPanel
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 // calculate sensible default width when no preference is available
177 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
178 int maxwidth = Math.max(20,
179 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
180 return calculateIdWidth(maxwidth);
183 * Calculate the width of the alignment labels based on the displayed names
184 * and any bounds on label width set in preferences.
185 * @param maxwidth -1 or maximum width allowed for IdWidth
186 * @return Dimension giving the maximum width of the alignment label panel
187 * that should be used.
189 public Dimension calculateIdWidth(int maxwidth)
191 Container c = new Container();
193 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
194 Font.ITALIC, av.font.getSize()));
196 AlignmentI al = av.getAlignment();
201 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
203 SequenceI s = al.getSequenceAt(i);
205 id = s.getDisplayId(av.getShowJVSuffix());
207 if (fm.stringWidth(id) > idWidth)
209 idWidth = fm.stringWidth(id);
215 // Also check annotation label widths
218 if (al.getAlignmentAnnotation() != null)
220 fm = c.getFontMetrics(alabels.getFont());
222 while (i < al.getAlignmentAnnotation().length)
224 String label = al.getAlignmentAnnotation()[i].label;
226 if (fm.stringWidth(label) > idWidth)
228 idWidth = fm.stringWidth(label);
235 return new Dimension(maxwidth<0 ? idWidth : Math.min(maxwidth, idWidth), 12);
239 * Highlight the given results on the alignment.
242 public void highlightSearchResults(SearchResults results)
244 scrollToPosition(results);
245 seqPanel.seqCanvas.highlightSearchResults(results);
249 * scroll the view to show the position of the highlighted region in results
250 * (if any) and redraw the overview
254 public boolean scrollToPosition(SearchResults results)
256 return scrollToPosition(results, true);
260 * scroll the view to show the position of the highlighted region in results
264 * @param redrawOverview
265 * - when set, the overview will be recalculated (takes longer)
266 * @return false if results were not found
268 public boolean scrollToPosition(SearchResults results,
269 boolean redrawOverview)
271 int startv, endv, starts, ends, width;
272 // TODO: properly locate search results in view when large numbers of hidden
273 // columns exist before highlighted region
274 // do we need to scroll the panel?
275 // TODO: tons of nullpointereexceptions raised here.
276 if (results != null && results.getSize() > 0 && av != null
277 && av.getAlignment() != null)
279 int seqIndex = av.getAlignment().findIndex(results);
284 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
286 int[] r=results.getResults(seq, 0, av.getAlignment().getWidth());
293 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
299 if (end == seq.getEnd())
303 if (av.hasHiddenColumns())
305 start = av.getColumnSelection().findColumnPosition(start);
306 end = av.getColumnSelection().findColumnPosition(end);
309 if (!av.getColumnSelection().isVisible(r[0]))
311 // don't scroll - position isn't visible
316 if (!av.wrapAlignment)
318 if ((startv = av.getStartRes()) >= start)
320 setScrollValues(start - 1, seqIndex);
322 else if ((endv = av.getEndRes()) <= end)
324 setScrollValues(startv + 1 + end - endv, seqIndex);
326 else if ((starts = av.getStartSeq()) > seqIndex)
328 setScrollValues(av.getStartRes(), seqIndex);
330 else if ((ends = av.getEndSeq()) <= seqIndex)
332 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
337 scrollToWrappedVisible(start);
340 if (redrawOverview && overviewPanel != null)
342 overviewPanel.setBoxPosition();
344 paintAlignment(redrawOverview);
348 void scrollToWrappedVisible(int res)
350 int cwidth = seqPanel.seqCanvas
351 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
352 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
354 vscroll.setValue((res / cwidth));
355 av.startRes = vscroll.getValue() * cwidth;
363 * @return DOCUMENT ME!
365 public OverviewPanel getOverviewPanel()
367 return overviewPanel;
376 public void setOverviewPanel(OverviewPanel op)
383 * @param b Hide or show annotation panel
386 public void setAnnotationVisible(boolean b)
388 if (!av.wrapAlignment)
390 annotationSpaceFillerHolder.setVisible(b);
391 annotationScroller.setVisible(b);
397 * automatically adjust annotation panel height for new annotation
398 * whilst ensuring the alignment is still visible.
400 public void adjustAnnotationHeight()
402 // TODO: display vertical annotation scrollbar if necessary
403 // this is called after loading new annotation onto alignment
404 if (alignFrame.getHeight() == 0)
406 System.out.println("NEEDS FIXING");
408 validateAnnotationDimensions(true);
410 paintAlignment(true);
413 * calculate the annotation dimensions and refresh slider values accordingly.
414 * need to do repaints/notifys afterwards.
416 protected void validateAnnotationDimensions(boolean adjustPanelHeight) {
417 int height = annotationPanel.adjustPanelHeight();
419 if (hscroll.isVisible())
421 height += hscroll.getPreferredSize().height;
423 if (height > alignFrame.getHeight() / 2)
425 height = alignFrame.getHeight() / 2;
427 if (!adjustPanelHeight)
429 // maintain same window layout whilst updating sliders
430 height=annotationScroller.getSize().height;
434 annotationScroller.setPreferredSize(new Dimension(annotationScroller
435 .getWidth(), height));
437 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
438 annotationSpaceFillerHolder.getWidth(), height));
439 annotationScroller.validate();// repaint();
440 annotationScroller.addNotify();
449 public void setWrapAlignment(boolean wrap)
452 scalePanelHolder.setVisible(!wrap);
453 hscroll.setVisible(!wrap);
454 idwidthAdjuster.setVisible(!wrap);
458 annotationScroller.setVisible(false);
459 annotationSpaceFillerHolder.setVisible(false);
461 else if (av.showAnnotation)
463 annotationScroller.setVisible(true);
464 annotationSpaceFillerHolder.setVisible(true);
467 idSpaceFillerPanel1.setVisible(!wrap);
472 // return value is true if the scroll is valid
473 public boolean scrollUp(boolean up)
477 if (vscroll.getValue() < 1)
483 vscroll.setValue(vscroll.getValue() - 1);
487 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
493 vscroll.setValue(vscroll.getValue() + 1);
507 * @return DOCUMENT ME!
509 public boolean scrollRight(boolean right)
513 if (hscroll.getValue() < 1)
519 hscroll.setValue(hscroll.getValue() - 1);
523 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
529 hscroll.setValue(hscroll.getValue() + 1);
538 * Adjust row/column scrollers to show a visible position in the alignment.
540 * @param x visible column to scroll to
542 * @param y visible row to scroll to
545 public void setScrollValues(int x, int y)
547 // System.err.println("Scroll to "+x+","+y);
548 if (av == null || av.getAlignment() == null)
552 int width = av.getAlignment().getWidth();
553 int height = av.getAlignment().getHeight();
555 if (av.hasHiddenColumns())
557 width = av.getColumnSelection().findColumnPosition(width);
560 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
562 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
563 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
570 if (vextent > height)
575 if ((hextent + x) > width)
580 if ((vextent + y) > height)
582 y = height - vextent;
595 hscroll.setValues(x, hextent, 0, width);
596 vscroll.setValues(y, vextent, 0, height);
605 public void adjustmentValueChanged(AdjustmentEvent evt)
608 int oldX = av.getStartRes();
609 int oldY = av.getStartSeq();
611 if (evt.getSource() == hscroll)
613 int x = hscroll.getValue();
615 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
618 if (evt.getSource() == vscroll)
620 int offy = vscroll.getValue();
622 if (av.getWrapAlignment())
626 int rowSize = seqPanel.seqCanvas
627 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
628 av.setStartRes(offy * rowSize);
629 av.setEndRes((offy + 1) * rowSize);
633 // This is only called if file loaded is a jar file that
634 // was wrapped when saved and user has wrap alignment true
635 // as preference setting
636 SwingUtilities.invokeLater(new Runnable()
640 setScrollValues(av.getStartRes(), av.getStartSeq());
647 av.setStartSeq(offy);
649 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
653 if (overviewPanel != null)
655 overviewPanel.setBoxPosition();
658 int scrollX = av.startRes - oldX;
659 int scrollY = av.startSeq - oldY;
661 if (av.getWrapAlignment() || !fastPaint)
667 // Make sure we're not trying to draw a panel
668 // larger than the visible window
669 if (scrollX > av.endRes - av.startRes)
671 scrollX = av.endRes - av.startRes;
673 else if (scrollX < av.startRes - av.endRes)
675 scrollX = av.startRes - av.endRes;
678 if (scrollX != 0 || scrollY != 0)
680 idPanel.idCanvas.fastPaint(scrollY);
681 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
682 scalePanel.repaint();
684 if (av.getShowAnnotation())
686 annotationPanel.fastPaint(scrollX);
692 public void paintAlignment(boolean updateOverview)
698 av.getStructureSelectionManager().sequenceColoursChanged(this);
700 if (overviewPanel != null)
702 overviewPanel.updateOverviewImage();
713 public void paintComponent(Graphics g)
717 Dimension d = idPanel.idCanvas.getPreferredSize();
718 idPanelHolder.setPreferredSize(d);
719 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
722 if (av.getWrapAlignment())
724 int maxwidth = av.getAlignment().getWidth();
726 if (av.hasHiddenColumns())
728 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
731 int canvasWidth = seqPanel.seqCanvas
732 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
737 .getWrappedCanvasWidth(seqPanel.seqCanvas
739 vscroll.setMaximum(max);
740 vscroll.setUnitIncrement(1);
741 vscroll.setVisibleAmount(1);
746 setScrollValues(av.getStartRes(), av.getStartSeq());
760 * @return DOCUMENT ME!
762 * @throws PrinterException
765 public int print(Graphics pg, PageFormat pf, int pi)
766 throws PrinterException
768 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
770 int pwidth = (int) pf.getImageableWidth();
771 int pheight = (int) pf.getImageableHeight();
773 if (av.getWrapAlignment())
775 return printWrappedAlignment(pg, pwidth, pheight, pi);
779 return printUnwrapped(pg, pwidth, pheight, pi);
795 * @return DOCUMENT ME!
797 * @throws PrinterException
800 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
801 throws PrinterException
803 int idWidth = getVisibleIdWidth(false);
804 FontMetrics fm = getFontMetrics(av.getFont());
805 int scaleHeight = av.charHeight + fm.getDescent();
807 pg.setColor(Color.white);
808 pg.fillRect(0, 0, pwidth, pheight);
809 pg.setFont(av.getFont());
811 // //////////////////////////////////
812 // / How many sequences and residues can we fit on a printable page?
813 int totalRes = (pwidth - idWidth) / av.getCharWidth();
815 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
817 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
819 // ///////////////////////////
820 // / Only print these sequences and residues on this page
823 // ///////////////////////////
824 // / Only print these sequences and residues on this page
827 // ///////////////////////////
828 // / Only print these sequences and residues on this page
831 // ///////////////////////////
832 // / Only print these sequences and residues on this page
834 startRes = (pi % pagesWide) * totalRes;
835 endRes = (startRes + totalRes) - 1;
837 if (endRes > (av.getAlignment().getWidth() - 1))
839 endRes = av.getAlignment().getWidth() - 1;
842 startSeq = (pi / pagesWide) * totalSeq;
843 endSeq = startSeq + totalSeq;
845 if (endSeq > av.getAlignment().getHeight())
847 endSeq = av.getAlignment().getHeight();
850 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1) * pheight;
852 if (av.showAnnotation)
854 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
857 pagesHigh /= pheight;
859 if (pi >= (pagesWide * pagesHigh))
861 return Printable.NO_SUCH_PAGE;
865 pg.translate(idWidth, 0);
866 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
868 pg.translate(-idWidth, scaleHeight);
872 Color currentColor = null;
873 Color currentTextColor = null;
875 pg.setFont(idPanel.idCanvas.idfont);
878 for (int i = startSeq; i < endSeq; i++)
880 seq = av.getAlignment().getSequenceAt(i);
881 if ((av.getSelectionGroup() != null)
882 && av.getSelectionGroup().getSequences(null).contains(seq))
884 currentColor = Color.gray;
885 currentTextColor = Color.black;
889 currentColor = av.getSequenceColour(seq);
890 currentTextColor = Color.black;
893 pg.setColor(currentColor);
894 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
897 pg.setColor(currentTextColor);
900 if (av.rightAlignIds)
902 fm = pg.getFontMetrics();
904 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
909 seq.getDisplayId(av.getShowJVSuffix()),
911 (((i - startSeq) * av.charHeight) + av.getCharHeight())
912 - (av.getCharHeight() / 5));
915 pg.setFont(av.getFont());
917 // draw main sequence panel
918 pg.translate(idWidth, 0);
919 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
921 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
923 // draw annotation - need to offset for current scroll position
924 int offset=-alabels.scrollOffset;
925 pg.translate(0, offset);
926 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
927 alabels.drawComponent((Graphics2D) pg, idWidth);
928 pg.translate(idWidth + 3, 0);
929 annotationPanel.renderer.drawComponent(annotationPanel, av, (Graphics2D) pg, -1, startRes, endRes + 1);
930 pg.translate(0, -offset);
933 return Printable.PAGE_EXISTS;
948 * @return DOCUMENT ME!
950 * @throws PrinterException
953 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
954 int pi) throws PrinterException
957 int annotationHeight = 0;
958 AnnotationLabels labels = null;
959 if (av.showAnnotation)
961 annotationHeight = annotationPanel.adjustPanelHeight();
962 labels = new AnnotationLabels(av);
965 int hgap = av.charHeight;
966 if (av.scaleAboveWrapped)
968 hgap += av.charHeight;
971 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
974 int idWidth = getVisibleIdWidth(false);
976 int maxwidth = av.getAlignment().getWidth();
977 if (av.hasHiddenColumns())
979 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
982 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
985 int totalHeight = cHeight * (maxwidth / resWidth + 1);
987 pg.setColor(Color.white);
988 pg.fillRect(0, 0, pwidth, pheight);
989 pg.setFont(av.getFont());
993 pg.setColor(Color.black);
995 pg.translate(0, -pi * pheight);
997 pg.setClip(0, pi * pheight, pwidth, pheight);
1003 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1005 pg.setFont(idPanel.idCanvas.idfont);
1006 SequenceI s = av.getAlignment().getSequenceAt(i);
1007 String string = s.getDisplayId(av.getShowJVSuffix());
1009 if (av.rightAlignIds)
1011 FontMetrics fm = pg.getFontMetrics();
1012 xPos = idWidth - fm.stringWidth(string) - 4;
1014 pg.drawString(string, xPos,
1015 ((i * av.charHeight) + ypos + av.charHeight)
1016 - (av.charHeight / 5));
1020 pg.translate(-3, ypos
1021 + (av.getAlignment().getHeight() * av.charHeight));
1023 pg.setFont(av.getFont());
1024 labels.drawComponent(pg, idWidth);
1025 pg.translate(+3, -ypos
1026 - (av.getAlignment().getHeight() * av.charHeight));
1030 } while (ypos < totalHeight);
1032 pg.translate(idWidth, 0);
1034 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1037 if ((pi * pheight) < totalHeight)
1039 return Printable.PAGE_EXISTS;
1044 return Printable.NO_SUCH_PAGE;
1048 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1051 int getVisibleIdWidth()
1053 return getVisibleIdWidth(true);
1057 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1058 * @param onscreen indicate if the Id width for onscreen or offscreen display should be returned
1061 int getVisibleIdWidth(boolean onscreen)
1063 // see if rendering offscreen - check preferences and calc width accordingly
1064 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1066 return calculateIdWidth(-1).width+4;
1068 Integer idwidth=null;
1069 if (onscreen || (idwidth=Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH"))==null) {
1070 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1071 : calculateIdWidth().width + 4);
1073 return idwidth.intValue()+4;
1076 void makeAlignmentImage(int type, File file)
1078 int maxwidth = av.getAlignment().getWidth();
1079 if (av.hasHiddenColumns())
1081 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1084 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1085 + scalePanel.getHeight();
1086 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1088 if (av.getWrapAlignment())
1090 height = getWrappedHeight();
1091 if (System.getProperty("java.awt.headless") != null
1092 && System.getProperty("java.awt.headless").equals("true"))
1094 // need to obtain default alignment width and then add in any additional allowance for id margin
1095 // this duplicates the calculation in getWrappedHeight but adjusts for offscreen idWith
1096 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1097 - alignFrame.getInsets().left
1098 - alignFrame.getInsets().right
1099 - getVisibleIdWidth()+getVisibleIdWidth(false);
1103 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1107 else if (av.getShowAnnotation())
1109 height += annotationPanel.adjustPanelHeight() + 3;
1115 jalview.util.ImageMaker im;
1116 if (type == jalview.util.ImageMaker.PNG)
1118 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1119 "Create PNG image from alignment", width, height, file,
1124 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1125 "Create EPS file from alignment", width, height, file,
1126 alignFrame.getTitle());
1129 if (av.getWrapAlignment())
1131 if (im.getGraphics() != null)
1133 printWrappedAlignment(im.getGraphics(), width, height, 0);
1139 if (im.getGraphics() != null)
1141 printUnwrapped(im.getGraphics(), width, height, 0);
1145 } catch (OutOfMemoryError err)
1148 System.out.println("########################\n" + "OUT OF MEMORY "
1149 + file + "\n" + "########################");
1150 new OOMWarning("Creating Image for " + file, err);
1151 // System.out.println("Create IMAGE: " + err);
1152 } catch (Exception ex)
1154 ex.printStackTrace();
1161 public void makeEPS(File epsFile)
1163 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1169 public void makePNG(File pngFile)
1171 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1174 public void makePNGImageMap(File imgMapFile, String imageName)
1176 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1177 // ////////////////////////////////////////////
1178 int idWidth = getVisibleIdWidth(false);
1179 FontMetrics fm = getFontMetrics(av.getFont());
1180 int scaleHeight = av.charHeight + fm.getDescent();
1183 // ////////////////////////////////
1184 if (imgMapFile != null)
1188 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av.getAlignment()
1189 .getWidth(), g, gSize, f, fSize, sy;
1190 StringBuffer text = new StringBuffer();
1191 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1192 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1193 out.println("<img src=\"" + imageName
1194 + "\" border=\"0\" usemap=\"#Map\" >"
1195 + "<map name=\"Map\">");
1197 for (s = 0; s < sSize; s++)
1199 sy = s * av.charHeight + scaleHeight;
1201 SequenceI seq = av.getAlignment().getSequenceAt(s);
1202 SequenceFeature[] features = seq.getDatasetSequence()
1203 .getSequenceFeatures();
1204 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1205 for (res = 0; res < alwidth; res++)
1207 text = new StringBuffer();
1209 if (av.getAlignment().isNucleotide())
1211 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1216 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1225 String triplet = obj.toString();
1226 int alIndex = seq.findPosition(res);
1227 gSize = groups.length;
1228 for (g = 0; g < gSize; g++)
1230 if (text.length() < 1)
1232 text.append("<area shape=\"rect\" coords=\""
1233 + (idWidth + res * av.charWidth) + "," + sy + ","
1234 + (idWidth + (res + 1) * av.charWidth) + ","
1235 + (av.charHeight + sy) + "\""
1236 + " onMouseOver=\"toolTip('" + alIndex + " "
1240 if (groups[g].getStartRes() < res
1241 && groups[g].getEndRes() > res)
1243 text.append("<br><em>" + groups[g].getName() + "</em>");
1247 if (features != null)
1249 if (text.length() < 1)
1251 text.append("<area shape=\"rect\" coords=\""
1252 + (idWidth + res * av.charWidth) + "," + sy + ","
1253 + (idWidth + (res + 1) * av.charWidth) + ","
1254 + (av.charHeight + sy) + "\""
1255 + " onMouseOver=\"toolTip('" + alIndex + " "
1258 fSize = features.length;
1259 for (f = 0; f < fSize; f++)
1262 if ((features[f].getBegin() <= seq.findPosition(res))
1263 && (features[f].getEnd() >= seq.findPosition(res)))
1265 if (features[f].getType().equals("disulfide bond"))
1267 if (features[f].getBegin() == seq.findPosition(res)
1268 || features[f].getEnd() == seq
1271 text.append("<br>disulfide bond "
1272 + features[f].getBegin() + ":"
1273 + features[f].getEnd());
1278 text.append("<br>");
1279 text.append(features[f].getType());
1280 if (features[f].getDescription() != null
1281 && !features[f].getType().equals(
1282 features[f].getDescription()))
1284 text.append(" " + features[f].getDescription());
1287 if (features[f].getValue("status") != null)
1289 text.append(" (" + features[f].getValue("status")
1297 if (text.length() > 1)
1299 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1300 out.println(text.toString());
1304 out.println("</map></body></html>");
1307 } catch (Exception ex)
1309 ex.printStackTrace();
1311 } // /////////END OF IMAGE MAP
1315 int getWrappedHeight()
1317 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1319 if (System.getProperty("java.awt.headless") != null
1320 && System.getProperty("java.awt.headless").equals("true"))
1322 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1323 - vscroll.getPreferredSize().width
1324 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1327 int chunkWidth = seqPanel.seqCanvas
1328 .getWrappedCanvasWidth(seqPanelWidth);
1330 int hgap = av.charHeight;
1331 if (av.scaleAboveWrapped)
1333 hgap += av.charHeight;
1336 int annotationHeight = 0;
1337 if (av.showAnnotation)
1339 annotationHeight = annotationPanel.adjustPanelHeight();
1342 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1345 int maxwidth = av.getAlignment().getWidth();
1346 if (av.hasHiddenColumns())
1348 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1351 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1357 * close the panel - deregisters all listeners and nulls any references to
1360 public void closePanel()
1362 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1363 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1364 PaintRefresher.RemoveComponent(this);
1367 jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager();
1368 ssm.removeStructureViewerListener(seqPanel, null);
1369 ssm.removeSelectionListener(seqPanel);
1370 av.setAlignment(null);
1375 if (Cache.log.isDebugEnabled())
1377 Cache.log.warn("Closing alignment panel which is already closed.");
1383 * hides or shows dynamic annotation rows based on groups and av state flags
1385 public void updateAnnotation()
1387 updateAnnotation(false);
1390 public void updateAnnotation(boolean applyGlobalSettings)
1392 // TODO: this should be merged with other annotation update stuff - that
1393 // sits on AlignViewport
1394 boolean updateCalcs = false;
1395 boolean conv = av.isShowGroupConservation();
1396 boolean cons = av.isShowGroupConsensus();
1397 boolean showprf = av.isShowSequenceLogo();
1398 boolean showConsHist = av.isShowConsensusHistogram();
1399 boolean normLogo = av.isNormaliseSequenceLogo();
1401 boolean sortg = true;
1403 // remove old automatic annotation
1404 // add any new annotation
1406 // intersect alignment annotation with alignment groups
1408 AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation();
1409 Hashtable oldrfs = new Hashtable();
1412 for (int an = 0; an < aan.length; an++)
1414 if (aan[an].autoCalculated && aan[an].groupRef != null)
1416 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1417 av.getAlignment().deleteAnnotation(aan[an]);
1422 if (av.getAlignment().getGroups()!=null)
1424 for (SequenceGroup sg:av.getAlignment().getGroups())
1426 updateCalcs = false;
1427 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1429 // set defaults for this group's conservation/consensus
1430 sg.setshowSequenceLogo(showprf);
1431 sg.setShowConsensusHistogram(showConsHist);
1432 sg.setNormaliseSequenceLogo(normLogo);
1437 av.getAlignment().addAnnotation(sg.getConservationRow(), 0);
1442 av.getAlignment().addAnnotation(sg.getConsensus(), 0);
1444 // refresh the annotation rows
1447 sg.recalcConservation();
1452 adjustAnnotationHeight();
1456 public AlignmentI getAlignment()
1458 return av.getAlignment();
1462 * get the name for this view
1465 public String getViewName()
1471 * Make/Unmake this alignment panel the current input focus
1474 public void setSelected(boolean b)
1477 alignFrame.setSelected(b);
1478 } catch (Exception ex) {};
1482 alignFrame.setDisplayedView(this);
1487 public StructureSelectionManager getStructureSelectionManager()
1489 return av.getStructureSelectionManager();
1493 public void raiseOOMWarning(String string, OutOfMemoryError error)
1495 new OOMWarning(string, error, this);
1498 public FeatureRenderer cloneFeatureRenderer()
1501 return new FeatureRenderer(this);
1504 public void updateFeatureRenderer(FeatureRenderer fr)
1506 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1509 public void updateFeatureRendererFrom(FeatureRenderer fr)
1511 if (seqPanel.seqCanvas.getFeatureRenderer()!=null) {
1512 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);