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 long progress=System.currentTimeMillis();
1079 if (alignFrame!=null) {
1080 alignFrame.setProgressBar("Saving "+(type == jalview.util.ImageMaker.PNG ? "PNG image":"EPS file") , progress);
1083 int maxwidth = av.getAlignment().getWidth();
1084 if (av.hasHiddenColumns())
1086 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1089 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1090 + scalePanel.getHeight();
1091 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1093 if (av.getWrapAlignment())
1095 height = getWrappedHeight();
1096 if (System.getProperty("java.awt.headless") != null
1097 && System.getProperty("java.awt.headless").equals("true"))
1099 // need to obtain default alignment width and then add in any additional allowance for id margin
1100 // this duplicates the calculation in getWrappedHeight but adjusts for offscreen idWith
1101 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1102 - alignFrame.getInsets().left
1103 - alignFrame.getInsets().right
1104 - getVisibleIdWidth()+getVisibleIdWidth(false);
1108 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1112 else if (av.getShowAnnotation())
1114 height += annotationPanel.adjustPanelHeight() + 3;
1120 jalview.util.ImageMaker im;
1121 final String imageAction,imageTitle;
1122 if (type == jalview.util.ImageMaker.PNG)
1124 imageAction="Create PNG image from alignment";
1127 imageAction="Create EPS file from alignment";
1128 imageTitle=alignFrame.getTitle();
1130 im = new jalview.util.ImageMaker(this, type, imageAction, width, height, file,
1132 if (av.getWrapAlignment())
1134 if (im.getGraphics() != null)
1136 printWrappedAlignment(im.getGraphics(), width, height, 0);
1142 if (im.getGraphics() != null)
1144 printUnwrapped(im.getGraphics(), width, height, 0);
1148 } catch (OutOfMemoryError err)
1151 System.out.println("########################\n" + "OUT OF MEMORY "
1152 + file + "\n" + "########################");
1153 new OOMWarning("Creating Image for " + file, err);
1154 // System.out.println("Create IMAGE: " + err);
1155 } catch (Exception ex)
1157 ex.printStackTrace();
1161 if (alignFrame!=null)
1163 alignFrame.setProgressBar("Export complete.", progress);
1171 public void makeEPS(File epsFile)
1173 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1179 public void makePNG(File pngFile)
1181 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1184 public void makePNGImageMap(File imgMapFile, String imageName)
1186 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1187 // ////////////////////////////////////////////
1188 int idWidth = getVisibleIdWidth(false);
1189 FontMetrics fm = getFontMetrics(av.getFont());
1190 int scaleHeight = av.charHeight + fm.getDescent();
1193 // ////////////////////////////////
1194 if (imgMapFile != null)
1198 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av.getAlignment()
1199 .getWidth(), g, gSize, f, fSize, sy;
1200 StringBuffer text = new StringBuffer();
1201 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1202 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1203 out.println("<img src=\"" + imageName
1204 + "\" border=\"0\" usemap=\"#Map\" >"
1205 + "<map name=\"Map\">");
1207 for (s = 0; s < sSize; s++)
1209 sy = s * av.charHeight + scaleHeight;
1211 SequenceI seq = av.getAlignment().getSequenceAt(s);
1212 SequenceFeature[] features = seq.getDatasetSequence()
1213 .getSequenceFeatures();
1214 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1215 for (res = 0; res < alwidth; res++)
1217 text = new StringBuffer();
1219 if (av.getAlignment().isNucleotide())
1221 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1226 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1235 String triplet = obj.toString();
1236 int alIndex = seq.findPosition(res);
1237 gSize = groups.length;
1238 for (g = 0; g < gSize; g++)
1240 if (text.length() < 1)
1242 text.append("<area shape=\"rect\" coords=\""
1243 + (idWidth + res * av.charWidth) + "," + sy + ","
1244 + (idWidth + (res + 1) * av.charWidth) + ","
1245 + (av.charHeight + sy) + "\""
1246 + " onMouseOver=\"toolTip('" + alIndex + " "
1250 if (groups[g].getStartRes() < res
1251 && groups[g].getEndRes() > res)
1253 text.append("<br><em>" + groups[g].getName() + "</em>");
1257 if (features != null)
1259 if (text.length() < 1)
1261 text.append("<area shape=\"rect\" coords=\""
1262 + (idWidth + res * av.charWidth) + "," + sy + ","
1263 + (idWidth + (res + 1) * av.charWidth) + ","
1264 + (av.charHeight + sy) + "\""
1265 + " onMouseOver=\"toolTip('" + alIndex + " "
1268 fSize = features.length;
1269 for (f = 0; f < fSize; f++)
1272 if ((features[f].getBegin() <= seq.findPosition(res))
1273 && (features[f].getEnd() >= seq.findPosition(res)))
1275 if (features[f].getType().equals("disulfide bond"))
1277 if (features[f].getBegin() == seq.findPosition(res)
1278 || features[f].getEnd() == seq
1281 text.append("<br>disulfide bond "
1282 + features[f].getBegin() + ":"
1283 + features[f].getEnd());
1288 text.append("<br>");
1289 text.append(features[f].getType());
1290 if (features[f].getDescription() != null
1291 && !features[f].getType().equals(
1292 features[f].getDescription()))
1294 text.append(" " + features[f].getDescription());
1297 if (features[f].getValue("status") != null)
1299 text.append(" (" + features[f].getValue("status")
1307 if (text.length() > 1)
1309 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1310 out.println(text.toString());
1314 out.println("</map></body></html>");
1317 } catch (Exception ex)
1319 ex.printStackTrace();
1321 } // /////////END OF IMAGE MAP
1325 int getWrappedHeight()
1327 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1329 if (System.getProperty("java.awt.headless") != null
1330 && System.getProperty("java.awt.headless").equals("true"))
1332 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1333 - vscroll.getPreferredSize().width
1334 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1337 int chunkWidth = seqPanel.seqCanvas
1338 .getWrappedCanvasWidth(seqPanelWidth);
1340 int hgap = av.charHeight;
1341 if (av.scaleAboveWrapped)
1343 hgap += av.charHeight;
1346 int annotationHeight = 0;
1347 if (av.showAnnotation)
1349 annotationHeight = annotationPanel.adjustPanelHeight();
1352 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1355 int maxwidth = av.getAlignment().getWidth();
1356 if (av.hasHiddenColumns())
1358 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1361 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1367 * close the panel - deregisters all listeners and nulls any references to
1370 public void closePanel()
1372 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1373 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1374 PaintRefresher.RemoveComponent(this);
1377 jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager();
1378 ssm.removeStructureViewerListener(seqPanel, null);
1379 ssm.removeSelectionListener(seqPanel);
1380 av.setAlignment(null);
1385 if (Cache.log.isDebugEnabled())
1387 Cache.log.warn("Closing alignment panel which is already closed.");
1393 * hides or shows dynamic annotation rows based on groups and av state flags
1395 public void updateAnnotation()
1397 updateAnnotation(false, false);
1399 public void updateAnnotation(boolean applyGlobalSettings)
1401 updateAnnotation(applyGlobalSettings,false);
1403 public void updateAnnotation(boolean applyGlobalSettings, boolean preserveNewGroupSettings)
1405 av.updateGroupAnnotationSettings(applyGlobalSettings, preserveNewGroupSettings);
1406 adjustAnnotationHeight();
1410 public AlignmentI getAlignment()
1412 return av.getAlignment();
1416 * get the name for this view
1419 public String getViewName()
1425 * Make/Unmake this alignment panel the current input focus
1428 public void setSelected(boolean b)
1431 alignFrame.setSelected(b);
1432 } catch (Exception ex) {};
1436 alignFrame.setDisplayedView(this);
1441 public StructureSelectionManager getStructureSelectionManager()
1443 return av.getStructureSelectionManager();
1447 public void raiseOOMWarning(String string, OutOfMemoryError error)
1449 new OOMWarning(string, error, this);
1452 public FeatureRenderer cloneFeatureRenderer()
1455 return new FeatureRenderer(this);
1458 public void updateFeatureRenderer(FeatureRenderer fr)
1460 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1463 public void updateFeatureRendererFrom(FeatureRenderer fr)
1465 if (seqPanel.seqCanvas.getFeatureRenderer()!=null) {
1466 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);