2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 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;
36 import jalview.structure.StructureSelectionManager;
42 * @version $Revision: 1.161 $
44 public class AlignmentPanel extends GAlignmentPanel implements
45 AdjustmentListener, Printable, AlignmentViewPanel
47 public AlignViewport av;
49 OverviewPanel overviewPanel;
55 IdwidthAdjuster idwidthAdjuster;
58 public AlignFrame alignFrame;
60 ScalePanel scalePanel;
62 AnnotationPanel annotationPanel;
64 AnnotationLabels alabels;
66 // this value is set false when selection area being dragged
67 boolean fastPaint = true;
74 * Creates a new AlignmentPanel object.
81 public AlignmentPanel(AlignFrame af, final AlignViewport av)
85 seqPanel = new SeqPanel(av, this);
86 idPanel = new IdPanel(av, this);
88 scalePanel = new ScalePanel(av, this);
90 idPanelHolder.add(idPanel, BorderLayout.CENTER);
91 idwidthAdjuster = new IdwidthAdjuster(this);
92 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
94 annotationPanel = new AnnotationPanel(this);
95 alabels = new AnnotationLabels(this);
97 annotationScroller.setViewportView(annotationPanel);
98 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
100 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
101 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
103 setScrollValues(0, 0);
105 setAnnotationVisible(av.getShowAnnotation());
107 hscroll.addAdjustmentListener(this);
108 vscroll.addAdjustmentListener(this);
110 final AlignmentPanel ap = this;
111 av.addPropertyChangeListener(new PropertyChangeListener()
113 public void propertyChange(PropertyChangeEvent evt)
115 if (evt.getPropertyName().equals("alignment"))
117 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
123 adjustAnnotationHeight();
127 public void alignmentChanged()
129 av.alignmentChanged(this);
131 alignFrame.updateEditMenuBar();
133 paintAlignment(true);
140 public void fontChanged()
142 // set idCanvas bufferedImage to null
143 // to prevent drawing old image
144 FontMetrics fm = getFontMetrics(av.getFont());
146 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
148 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
151 idPanel.idCanvas.gg = null;
152 seqPanel.seqCanvas.img = null;
153 annotationPanel.adjustPanelHeight();
155 Dimension d = calculateIdWidth();
156 d.setSize(d.width + 4, d.height);
157 idPanel.idCanvas.setPreferredSize(d);
158 hscrollFillerPanel.setPreferredSize(d);
160 if (overviewPanel != null)
162 overviewPanel.setBoxPosition();
169 * Calculate the width of the alignment labels based on the displayed names
170 * and any bounds on label width set in preferences.
172 * @return Dimension giving the maximum width of the alignment label panel
173 * that should be used.
175 public Dimension calculateIdWidth()
177 // calculate sensible default width when no preference is available
179 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
180 int maxwidth = Math.max(20,
181 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
182 return calculateIdWidth(maxwidth);
185 * Calculate the width of the alignment labels based on the displayed names
186 * and any bounds on label width set in preferences.
187 * @param maxwidth -1 or maximum width allowed for IdWidth
188 * @return Dimension giving the maximum width of the alignment label panel
189 * that should be used.
191 public Dimension calculateIdWidth(int maxwidth)
193 Container c = new Container();
195 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
196 Font.ITALIC, av.font.getSize()));
198 AlignmentI al = av.getAlignment();
203 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
205 SequenceI s = al.getSequenceAt(i);
207 id = s.getDisplayId(av.getShowJVSuffix());
209 if (fm.stringWidth(id) > idWidth)
211 idWidth = fm.stringWidth(id);
217 // Also check annotation label widths
220 if (al.getAlignmentAnnotation() != null)
222 fm = c.getFontMetrics(alabels.getFont());
224 while (i < al.getAlignmentAnnotation().length)
226 String label = al.getAlignmentAnnotation()[i].label;
228 if (fm.stringWidth(label) > idWidth)
230 idWidth = fm.stringWidth(label);
237 return new Dimension(maxwidth<0 ? idWidth : Math.min(maxwidth, idWidth), 12);
241 * Highlight the given results on the alignment.
244 public void highlightSearchResults(SearchResults results)
246 scrollToPosition(results);
247 seqPanel.seqCanvas.highlightSearchResults(results);
251 * scroll the view to show the position of the highlighted region in results
252 * (if any) and redraw the overview
256 public boolean scrollToPosition(SearchResults results)
258 return scrollToPosition(results, true);
262 * scroll the view to show the position of the highlighted region in results
266 * @param redrawOverview
267 * - when set, the overview will be recalculated (takes longer)
268 * @return false if results were not found
270 public boolean scrollToPosition(SearchResults results,
271 boolean redrawOverview)
273 int startv, endv, starts, ends, width;
274 // TODO: properly locate search results in view when large numbers of hidden
275 // columns exist before highlighted region
276 // do we need to scroll the panel?
277 // TODO: tons of nullpointereexceptions raised here.
278 if (results != null && results.getSize() > 0 && av != null
279 && av.alignment != null)
281 int seqIndex = av.alignment.findIndex(results);
286 SequenceI seq = av.alignment.getSequenceAt(seqIndex);
288 int[] r=results.getResults(seq, 0, av.alignment.getWidth());
295 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
301 if (end == seq.getEnd())
305 if (av.hasHiddenColumns)
307 start = av.getColumnSelection().findColumnPosition(start);
308 end = av.getColumnSelection().findColumnPosition(end);
311 if (!av.colSel.isVisible(r[0]))
313 // don't scroll - position isn't visible
318 if (!av.wrapAlignment)
320 if ((startv = av.getStartRes()) >= start)
322 setScrollValues(start - 1, seqIndex);
324 else if ((endv = av.getEndRes()) <= end)
326 setScrollValues(startv + 1 + end - endv, seqIndex);
328 else if ((starts = av.getStartSeq()) > seqIndex)
330 setScrollValues(av.getStartRes(), seqIndex);
332 else if ((ends = av.getEndSeq()) <= seqIndex)
334 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
339 scrollToWrappedVisible(start);
342 if (redrawOverview && overviewPanel != null)
344 overviewPanel.setBoxPosition();
346 paintAlignment(redrawOverview);
350 void scrollToWrappedVisible(int res)
352 int cwidth = seqPanel.seqCanvas
353 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
354 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
356 vscroll.setValue((res / cwidth));
357 av.startRes = vscroll.getValue() * cwidth;
365 * @return DOCUMENT ME!
367 public OverviewPanel getOverviewPanel()
369 return overviewPanel;
378 public void setOverviewPanel(OverviewPanel op)
385 * @param b Hide or show annotation panel
388 public void setAnnotationVisible(boolean b)
390 if (!av.wrapAlignment)
392 annotationSpaceFillerHolder.setVisible(b);
393 annotationScroller.setVisible(b);
399 * automatically adjust annotation panel height for new annotation
400 * whilst ensuring the alignment is still visible.
402 public void adjustAnnotationHeight()
404 // TODO: display vertical annotation scrollbar if necessary
405 // this is called after loading new annotation onto alignment
406 if (alignFrame.getHeight() == 0)
408 System.out.println("NEEDS FIXING");
410 validateAnnotationDimensions(true);
412 paintAlignment(true);
415 * calculate the annotation dimensions and refresh slider values accordingly.
416 * need to do repaints/notifys afterwards.
418 protected void validateAnnotationDimensions(boolean adjustPanelHeight) {
419 int height = annotationPanel.adjustPanelHeight();
421 if (hscroll.isVisible())
423 height += hscroll.getPreferredSize().height;
425 if (height > alignFrame.getHeight() / 2)
427 height = alignFrame.getHeight() / 2;
429 if (!adjustPanelHeight)
431 // maintain same window layout whilst updating sliders
432 height=annotationScroller.getSize().height;
436 annotationScroller.setPreferredSize(new Dimension(annotationScroller
437 .getWidth(), height));
439 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
440 annotationSpaceFillerHolder.getWidth(), height));
441 annotationScroller.validate();// repaint();
442 annotationScroller.addNotify();
451 public void setWrapAlignment(boolean wrap)
454 scalePanelHolder.setVisible(!wrap);
455 hscroll.setVisible(!wrap);
456 idwidthAdjuster.setVisible(!wrap);
460 annotationScroller.setVisible(false);
461 annotationSpaceFillerHolder.setVisible(false);
463 else if (av.showAnnotation)
465 annotationScroller.setVisible(true);
466 annotationSpaceFillerHolder.setVisible(true);
469 idSpaceFillerPanel1.setVisible(!wrap);
474 // return value is true if the scroll is valid
475 public boolean scrollUp(boolean up)
479 if (vscroll.getValue() < 1)
485 vscroll.setValue(vscroll.getValue() - 1);
489 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
495 vscroll.setValue(vscroll.getValue() + 1);
509 * @return DOCUMENT ME!
511 public boolean scrollRight(boolean right)
515 if (hscroll.getValue() < 1)
521 hscroll.setValue(hscroll.getValue() - 1);
525 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
531 hscroll.setValue(hscroll.getValue() + 1);
540 * Adjust row/column scrollers to show a visible position in the alignment.
542 * @param x visible column to scroll to
544 * @param y visible row to scroll to
547 public void setScrollValues(int x, int y)
549 // System.err.println("Scroll to "+x+","+y);
550 if (av == null || av.alignment == null)
554 int width = av.alignment.getWidth();
555 int height = av.alignment.getHeight();
557 if (av.hasHiddenColumns)
559 width = av.getColumnSelection().findColumnPosition(width);
562 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
564 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
565 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
572 if (vextent > height)
577 if ((hextent + x) > width)
582 if ((vextent + y) > height)
584 y = height - vextent;
597 hscroll.setValues(x, hextent, 0, width);
598 vscroll.setValues(y, vextent, 0, height);
607 public void adjustmentValueChanged(AdjustmentEvent evt)
610 int oldX = av.getStartRes();
611 int oldY = av.getStartSeq();
613 if (evt.getSource() == hscroll)
615 int x = hscroll.getValue();
617 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
620 if (evt.getSource() == vscroll)
622 int offy = vscroll.getValue();
624 if (av.getWrapAlignment())
628 int rowSize = seqPanel.seqCanvas
629 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
630 av.setStartRes(offy * rowSize);
631 av.setEndRes((offy + 1) * rowSize);
635 // This is only called if file loaded is a jar file that
636 // was wrapped when saved and user has wrap alignment true
637 // as preference setting
638 SwingUtilities.invokeLater(new Runnable()
642 setScrollValues(av.getStartRes(), av.getStartSeq());
649 av.setStartSeq(offy);
651 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
655 if (overviewPanel != null)
657 overviewPanel.setBoxPosition();
660 int scrollX = av.startRes - oldX;
661 int scrollY = av.startSeq - oldY;
663 if (av.getWrapAlignment() || !fastPaint)
669 // Make sure we're not trying to draw a panel
670 // larger than the visible window
671 if (scrollX > av.endRes - av.startRes)
673 scrollX = av.endRes - av.startRes;
675 else if (scrollX < av.startRes - av.endRes)
677 scrollX = av.startRes - av.endRes;
680 if (scrollX != 0 || scrollY != 0)
682 idPanel.idCanvas.fastPaint(scrollY);
683 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
684 scalePanel.repaint();
686 if (av.getShowAnnotation())
688 annotationPanel.fastPaint(scrollX);
694 public void paintAlignment(boolean updateOverview)
700 av.getStructureSelectionManager().sequenceColoursChanged(this);
702 if (overviewPanel != null)
704 overviewPanel.updateOverviewImage();
715 public void paintComponent(Graphics g)
719 Dimension d = idPanel.idCanvas.getPreferredSize();
720 idPanelHolder.setPreferredSize(d);
721 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
724 if (av.getWrapAlignment())
726 int maxwidth = av.alignment.getWidth();
728 if (av.hasHiddenColumns)
730 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
733 int canvasWidth = seqPanel.seqCanvas
734 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
739 .getWrappedCanvasWidth(seqPanel.seqCanvas
741 vscroll.setMaximum(max);
742 vscroll.setUnitIncrement(1);
743 vscroll.setVisibleAmount(1);
748 setScrollValues(av.getStartRes(), av.getStartSeq());
762 * @return DOCUMENT ME!
764 * @throws PrinterException
767 public int print(Graphics pg, PageFormat pf, int pi)
768 throws PrinterException
770 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
772 int pwidth = (int) pf.getImageableWidth();
773 int pheight = (int) pf.getImageableHeight();
775 if (av.getWrapAlignment())
777 return printWrappedAlignment(pg, pwidth, pheight, pi);
781 return printUnwrapped(pg, pwidth, pheight, pi);
797 * @return DOCUMENT ME!
799 * @throws PrinterException
802 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
803 throws PrinterException
805 int idWidth = getVisibleIdWidth(false);
806 FontMetrics fm = getFontMetrics(av.getFont());
807 int scaleHeight = av.charHeight + fm.getDescent();
809 pg.setColor(Color.white);
810 pg.fillRect(0, 0, pwidth, pheight);
811 pg.setFont(av.getFont());
813 // //////////////////////////////////
814 // / How many sequences and residues can we fit on a printable page?
815 int totalRes = (pwidth - idWidth) / av.getCharWidth();
817 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
819 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
821 // ///////////////////////////
822 // / Only print these sequences and residues on this page
825 // ///////////////////////////
826 // / Only print these sequences and residues on this page
829 // ///////////////////////////
830 // / Only print these sequences and residues on this page
833 // ///////////////////////////
834 // / Only print these sequences and residues on this page
836 startRes = (pi % pagesWide) * totalRes;
837 endRes = (startRes + totalRes) - 1;
839 if (endRes > (av.getAlignment().getWidth() - 1))
841 endRes = av.getAlignment().getWidth() - 1;
844 startSeq = (pi / pagesWide) * totalSeq;
845 endSeq = startSeq + totalSeq;
847 if (endSeq > av.getAlignment().getHeight())
849 endSeq = av.getAlignment().getHeight();
852 int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight;
854 if (av.showAnnotation)
856 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
859 pagesHigh /= pheight;
861 if (pi >= (pagesWide * pagesHigh))
863 return Printable.NO_SUCH_PAGE;
867 pg.translate(idWidth, 0);
868 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
870 pg.translate(-idWidth, scaleHeight);
874 Color currentColor = null;
875 Color currentTextColor = null;
877 pg.setFont(idPanel.idCanvas.idfont);
880 for (int i = startSeq; i < endSeq; i++)
882 seq = av.getAlignment().getSequenceAt(i);
883 if ((av.getSelectionGroup() != null)
884 && av.getSelectionGroup().getSequences(null).contains(seq))
886 currentColor = Color.gray;
887 currentTextColor = Color.black;
891 currentColor = av.getSequenceColour(seq);
892 currentTextColor = Color.black;
895 pg.setColor(currentColor);
896 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
899 pg.setColor(currentTextColor);
902 if (av.rightAlignIds)
904 fm = pg.getFontMetrics();
906 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
911 seq.getDisplayId(av.getShowJVSuffix()),
913 (((i - startSeq) * av.charHeight) + av.getCharHeight())
914 - (av.getCharHeight() / 5));
917 pg.setFont(av.getFont());
919 // draw main sequence panel
920 pg.translate(idWidth, 0);
921 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
923 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
925 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
926 alabels.drawComponent((Graphics2D) pg, idWidth);
927 pg.translate(idWidth + 3, 0);
928 annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + 1);
931 return Printable.PAGE_EXISTS;
946 * @return DOCUMENT ME!
948 * @throws PrinterException
951 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
952 int pi) throws PrinterException
955 int annotationHeight = 0;
956 AnnotationLabels labels = null;
957 if (av.showAnnotation)
959 annotationHeight = annotationPanel.adjustPanelHeight();
960 labels = new AnnotationLabels(av);
963 int hgap = av.charHeight;
964 if (av.scaleAboveWrapped)
966 hgap += av.charHeight;
969 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
972 int idWidth = getVisibleIdWidth(false);
974 int maxwidth = av.alignment.getWidth();
975 if (av.hasHiddenColumns)
977 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
980 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
983 int totalHeight = cHeight * (maxwidth / resWidth + 1);
985 pg.setColor(Color.white);
986 pg.fillRect(0, 0, pwidth, pheight);
987 pg.setFont(av.getFont());
991 pg.setColor(Color.black);
993 pg.translate(0, -pi * pheight);
995 pg.setClip(0, pi * pheight, pwidth, pheight);
1001 for (int i = 0; i < av.alignment.getHeight(); i++)
1003 pg.setFont(idPanel.idCanvas.idfont);
1004 SequenceI s = av.alignment.getSequenceAt(i);
1005 String string = s.getDisplayId(av.getShowJVSuffix());
1007 if (av.rightAlignIds)
1009 FontMetrics fm = pg.getFontMetrics();
1010 xPos = idWidth - fm.stringWidth(string) - 4;
1012 pg.drawString(string, xPos,
1013 ((i * av.charHeight) + ypos + av.charHeight)
1014 - (av.charHeight / 5));
1018 pg.translate(-3, ypos
1019 + (av.getAlignment().getHeight() * av.charHeight));
1021 pg.setFont(av.getFont());
1022 labels.drawComponent(pg, idWidth);
1023 pg.translate(+3, -ypos
1024 - (av.getAlignment().getHeight() * av.charHeight));
1028 } while (ypos < totalHeight);
1030 pg.translate(idWidth, 0);
1032 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1035 if ((pi * pheight) < totalHeight)
1037 return Printable.PAGE_EXISTS;
1042 return Printable.NO_SUCH_PAGE;
1046 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1049 int getVisibleIdWidth()
1051 return getVisibleIdWidth(true);
1055 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1056 * @param onscreen indicate if the Id width for onscreen or offscreen display should be returned
1059 int getVisibleIdWidth(boolean onscreen)
1061 // see if rendering offscreen - check preferences and calc width accordingly
1062 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1064 return calculateIdWidth(-1).width+4;
1066 Integer idwidth=null;
1067 if (onscreen || (idwidth=Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH"))==null) {
1068 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1069 : calculateIdWidth().width + 4);
1071 return idwidth.intValue()+4;
1074 void makeAlignmentImage(int type, File file)
1076 int maxwidth = av.alignment.getWidth();
1077 if (av.hasHiddenColumns)
1079 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1082 int height = ((av.alignment.getHeight() + 1) * av.charHeight)
1083 + scalePanel.getHeight();
1084 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1086 if (av.getWrapAlignment())
1088 height = getWrappedHeight();
1089 if (System.getProperty("java.awt.headless") != null
1090 && System.getProperty("java.awt.headless").equals("true"))
1092 // need to obtain default alignment width and then add in any additional allowance for id margin
1093 // this duplicates the calculation in getWrappedHeight but adjusts for offscreen idWith
1094 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1095 - alignFrame.getInsets().left
1096 - alignFrame.getInsets().right
1097 - getVisibleIdWidth()+getVisibleIdWidth(false);
1101 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1105 else if (av.getShowAnnotation())
1107 height += annotationPanel.adjustPanelHeight() + 3;
1113 jalview.util.ImageMaker im;
1114 if (type == jalview.util.ImageMaker.PNG)
1116 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1117 "Create PNG image from alignment", width, height, file,
1122 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1123 "Create EPS file from alignment", width, height, file,
1124 alignFrame.getTitle());
1127 if (av.getWrapAlignment())
1129 if (im.getGraphics() != null)
1131 printWrappedAlignment(im.getGraphics(), width, height, 0);
1137 if (im.getGraphics() != null)
1139 printUnwrapped(im.getGraphics(), width, height, 0);
1143 } catch (OutOfMemoryError err)
1146 System.out.println("########################\n" + "OUT OF MEMORY "
1147 + file + "\n" + "########################");
1148 new OOMWarning("Creating Image for " + file, err);
1149 // System.out.println("Create IMAGE: " + err);
1150 } catch (Exception ex)
1152 ex.printStackTrace();
1159 public void makeEPS(File epsFile)
1161 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1167 public void makePNG(File pngFile)
1169 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1172 public void makePNGImageMap(File imgMapFile, String imageName)
1174 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1175 // ////////////////////////////////////////////
1176 int idWidth = getVisibleIdWidth(false);
1177 FontMetrics fm = getFontMetrics(av.getFont());
1178 int scaleHeight = av.charHeight + fm.getDescent();
1181 // ////////////////////////////////
1182 if (imgMapFile != null)
1186 int s, sSize = av.alignment.getHeight(), res, alwidth = av.alignment
1187 .getWidth(), g, gSize, f, fSize, sy;
1188 StringBuffer text = new StringBuffer();
1189 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1190 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1191 out.println("<img src=\"" + imageName
1192 + "\" border=\"0\" usemap=\"#Map\" >"
1193 + "<map name=\"Map\">");
1195 for (s = 0; s < sSize; s++)
1197 sy = s * av.charHeight + scaleHeight;
1199 SequenceI seq = av.alignment.getSequenceAt(s);
1200 SequenceFeature[] features = seq.getDatasetSequence()
1201 .getSequenceFeatures();
1202 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
1203 for (res = 0; res < alwidth; res++)
1205 text = new StringBuffer();
1207 if (av.alignment.isNucleotide())
1209 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1214 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1223 String triplet = obj.toString();
1224 int alIndex = seq.findPosition(res);
1225 gSize = groups.length;
1226 for (g = 0; g < gSize; g++)
1228 if (text.length() < 1)
1230 text.append("<area shape=\"rect\" coords=\""
1231 + (idWidth + res * av.charWidth) + "," + sy + ","
1232 + (idWidth + (res + 1) * av.charWidth) + ","
1233 + (av.charHeight + sy) + "\""
1234 + " onMouseOver=\"toolTip('" + alIndex + " "
1238 if (groups[g].getStartRes() < res
1239 && groups[g].getEndRes() > res)
1241 text.append("<br><em>" + groups[g].getName() + "</em>");
1245 if (features != null)
1247 if (text.length() < 1)
1249 text.append("<area shape=\"rect\" coords=\""
1250 + (idWidth + res * av.charWidth) + "," + sy + ","
1251 + (idWidth + (res + 1) * av.charWidth) + ","
1252 + (av.charHeight + sy) + "\""
1253 + " onMouseOver=\"toolTip('" + alIndex + " "
1256 fSize = features.length;
1257 for (f = 0; f < fSize; f++)
1260 if ((features[f].getBegin() <= seq.findPosition(res))
1261 && (features[f].getEnd() >= seq.findPosition(res)))
1263 if (features[f].getType().equals("disulfide bond"))
1265 if (features[f].getBegin() == seq.findPosition(res)
1266 || features[f].getEnd() == seq
1269 text.append("<br>disulfide bond "
1270 + features[f].getBegin() + ":"
1271 + features[f].getEnd());
1276 text.append("<br>");
1277 text.append(features[f].getType());
1278 if (features[f].getDescription() != null
1279 && !features[f].getType().equals(
1280 features[f].getDescription()))
1282 text.append(" " + features[f].getDescription());
1285 if (features[f].getValue("status") != null)
1287 text.append(" (" + features[f].getValue("status")
1295 if (text.length() > 1)
1297 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1298 out.println(text.toString());
1302 out.println("</map></body></html>");
1305 } catch (Exception ex)
1307 ex.printStackTrace();
1309 } // /////////END OF IMAGE MAP
1313 int getWrappedHeight()
1315 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1317 if (System.getProperty("java.awt.headless") != null
1318 && System.getProperty("java.awt.headless").equals("true"))
1320 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1321 - vscroll.getPreferredSize().width
1322 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1325 int chunkWidth = seqPanel.seqCanvas
1326 .getWrappedCanvasWidth(seqPanelWidth);
1328 int hgap = av.charHeight;
1329 if (av.scaleAboveWrapped)
1331 hgap += av.charHeight;
1334 int annotationHeight = 0;
1335 if (av.showAnnotation)
1337 annotationHeight = annotationPanel.adjustPanelHeight();
1340 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1343 int maxwidth = av.alignment.getWidth();
1344 if (av.hasHiddenColumns)
1346 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1349 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1355 * close the panel - deregisters all listeners and nulls any references to
1358 public void closePanel()
1360 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1361 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1362 PaintRefresher.RemoveComponent(this);
1365 jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager();
1366 ssm.removeStructureViewerListener(seqPanel, null);
1367 ssm.removeSelectionListener(seqPanel);
1368 av.alignment = null;
1373 if (Cache.log.isDebugEnabled())
1375 Cache.log.warn("Closing alignment panel which is already closed.");
1381 * hides or shows dynamic annotation rows based on groups and av state flags
1383 public void updateAnnotation()
1385 updateAnnotation(false);
1388 public void updateAnnotation(boolean applyGlobalSettings)
1390 // TODO: this should be merged with other annotation update stuff - that
1391 // sits on AlignViewport
1392 boolean updateCalcs = false;
1393 boolean conv = av.isShowGroupConservation();
1394 boolean cons = av.isShowGroupConsensus();
1395 boolean showprf = av.isShowSequenceLogo();
1396 boolean showConsHist = av.isShowConsensusHistogram();
1398 boolean sortg = true;
1400 // remove old automatic annotation
1401 // add any new annotation
1403 Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
1404 // intersect alignment annotation with alignment groups
1406 AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
1407 Hashtable oldrfs = new Hashtable();
1410 for (int an = 0; an < aan.length; an++)
1412 if (aan[an].autoCalculated && aan[an].groupRef != null)
1414 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1415 av.alignment.deleteAnnotation(aan[an]);
1423 for (int g = 0; g < gr.size(); g++)
1425 updateCalcs = false;
1426 sg = (SequenceGroup) gr.elementAt(g);
1427 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1429 // set defaults for this group's conservation/consensus
1430 sg.setshowSequenceLogo(showprf);
1431 sg.setShowConsensusHistogram(showConsHist);
1436 av.alignment.addAnnotation(sg.getConservationRow(), 0);
1441 av.alignment.addAnnotation(sg.getConsensus(), 0);
1443 // refresh the annotation rows
1446 sg.recalcConservation();
1451 adjustAnnotationHeight();
1455 public AlignmentI getAlignment()
1457 return av.alignment;
1461 * get the name for this view
1464 public String getViewName()
1470 * Make/Unmake this alignment panel the current input focus
1473 public void setSelected(boolean b)
1476 alignFrame.setSelected(b);
1477 } catch (Exception ex) {};
1481 alignFrame.setDisplayedView(this);
1486 public StructureSelectionManager getStructureSelectionManager()
1488 return av.getStructureSelectionManager();