2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignmentViewPanel;
24 import jalview.bin.Cache;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SearchResults;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.jbgui.GAlignmentPanel;
31 import jalview.schemes.ResidueProperties;
32 import jalview.structure.StructureSelectionManager;
33 import jalview.util.MessageManager;
35 import java.awt.BorderLayout;
36 import java.awt.Color;
37 import java.awt.Container;
38 import java.awt.Dimension;
40 import java.awt.FontMetrics;
41 import java.awt.Graphics;
42 import java.awt.event.AdjustmentEvent;
43 import java.awt.event.AdjustmentListener;
44 import java.awt.print.PageFormat;
45 import java.awt.print.Printable;
46 import java.awt.print.PrinterException;
47 import java.beans.PropertyChangeEvent;
48 import java.beans.PropertyChangeListener;
50 import java.io.FileWriter;
51 import java.io.PrintWriter;
53 import javax.swing.SwingUtilities;
59 * @version $Revision: 1.161 $
61 public class AlignmentPanel extends GAlignmentPanel implements
62 AdjustmentListener, Printable, AlignmentViewPanel
64 public AlignViewport av;
66 OverviewPanel overviewPanel;
72 IdwidthAdjuster idwidthAdjuster;
75 public AlignFrame alignFrame;
77 ScalePanel scalePanel;
79 AnnotationPanel annotationPanel;
81 AnnotationLabels alabels;
83 // this value is set false when selection area being dragged
84 boolean fastPaint = true;
91 * Creates a new AlignmentPanel object.
98 public AlignmentPanel(AlignFrame af, final AlignViewport av)
102 seqPanel = new SeqPanel(av, this);
103 idPanel = new IdPanel(av, this);
105 scalePanel = new ScalePanel(av, this);
107 idPanelHolder.add(idPanel, BorderLayout.CENTER);
108 idwidthAdjuster = new IdwidthAdjuster(this);
109 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
111 annotationPanel = new AnnotationPanel(this);
112 alabels = new AnnotationLabels(this);
114 annotationScroller.setViewportView(annotationPanel);
115 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
117 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
118 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
120 setScrollValues(0, 0);
122 setAnnotationVisible(av.getShowAnnotation());
124 hscroll.addAdjustmentListener(this);
125 vscroll.addAdjustmentListener(this);
127 final AlignmentPanel ap = this;
128 av.addPropertyChangeListener(new PropertyChangeListener()
130 public void propertyChange(PropertyChangeEvent evt)
132 if (evt.getPropertyName().equals("alignment"))
134 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
140 adjustAnnotationHeight();
144 public void alignmentChanged()
146 av.alignmentChanged(this);
148 alignFrame.updateEditMenuBar();
150 paintAlignment(true);
157 public void fontChanged()
159 // set idCanvas bufferedImage to null
160 // to prevent drawing old image
161 FontMetrics fm = getFontMetrics(av.getFont());
163 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
165 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
168 idPanel.idCanvas.gg = null;
169 seqPanel.seqCanvas.img = null;
170 annotationPanel.adjustPanelHeight();
172 Dimension d = calculateIdWidth();
173 d.setSize(d.width + 4, d.height);
174 idPanel.idCanvas.setPreferredSize(d);
175 hscrollFillerPanel.setPreferredSize(d);
177 if (overviewPanel != null)
179 overviewPanel.setBoxPosition();
186 * Calculate the width of the alignment labels based on the displayed names
187 * and any bounds on label width set in preferences.
189 * @return Dimension giving the maximum width of the alignment label panel
190 * that should be used.
192 public Dimension calculateIdWidth()
194 // calculate sensible default width when no preference is available
196 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
197 int maxwidth = Math.max(20,
198 Math.min(afwidth - 200, 2 * afwidth / 3));
199 return calculateIdWidth(maxwidth);
203 * Calculate the width of the alignment labels based on the displayed names
204 * and any bounds on label width set in preferences.
207 * -1 or maximum width allowed for IdWidth
208 * @return Dimension giving the maximum width of the alignment label panel
209 * that should be used.
211 public Dimension calculateIdWidth(int maxwidth)
213 Container c = new Container();
215 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
216 Font.ITALIC, av.font.getSize()));
218 AlignmentI al = av.getAlignment();
223 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
225 SequenceI s = al.getSequenceAt(i);
227 id = s.getDisplayId(av.getShowJVSuffix());
229 if (fm.stringWidth(id) > idWidth)
231 idWidth = fm.stringWidth(id);
237 // Also check annotation label widths
240 if (al.getAlignmentAnnotation() != null)
242 fm = c.getFontMetrics(alabels.getFont());
244 while (i < al.getAlignmentAnnotation().length)
246 String label = al.getAlignmentAnnotation()[i].label;
248 if (fm.stringWidth(label) > idWidth)
250 idWidth = fm.stringWidth(label);
257 return new Dimension(maxwidth < 0 ? idWidth : Math.min(maxwidth,
262 * Highlight the given results on the alignment.
265 public void highlightSearchResults(SearchResults results)
267 scrollToPosition(results);
268 seqPanel.seqCanvas.highlightSearchResults(results);
272 * scroll the view to show the position of the highlighted region in results
273 * (if any) and redraw the overview
277 public boolean scrollToPosition(SearchResults results)
279 return scrollToPosition(results, true);
283 * scroll the view to show the position of the highlighted region in results
287 * @param redrawOverview
288 * - when set, the overview will be recalculated (takes longer)
289 * @return false if results were not found
291 public boolean scrollToPosition(SearchResults results,
292 boolean redrawOverview)
294 int startv, endv, starts, ends, width;
295 // TODO: properly locate search results in view when large numbers of hidden
296 // columns exist before highlighted region
297 // do we need to scroll the panel?
298 // TODO: tons of nullpointereexceptions raised here.
299 if (results != null && results.getSize() > 0 && av != null
300 && av.getAlignment() != null)
302 int seqIndex = av.getAlignment().findIndex(results);
307 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
309 int[] r = results.getResults(seq, 0, av.getAlignment().getWidth());
316 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
322 if (end == seq.getEnd())
326 if (av.hasHiddenColumns())
328 start = av.getColumnSelection().findColumnPosition(start);
329 end = av.getColumnSelection().findColumnPosition(end);
332 if (!av.getColumnSelection().isVisible(r[0]))
334 // don't scroll - position isn't visible
339 if (!av.wrapAlignment)
341 if ((startv = av.getStartRes()) >= start)
343 setScrollValues(start - 1, seqIndex);
345 else if ((endv = av.getEndRes()) <= end)
347 setScrollValues(startv + 1 + end - endv, seqIndex);
349 else if ((starts = av.getStartSeq()) > seqIndex)
351 setScrollValues(av.getStartRes(), seqIndex);
353 else if ((ends = av.getEndSeq()) <= seqIndex)
355 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
360 scrollToWrappedVisible(start);
363 if (redrawOverview && overviewPanel != null)
365 overviewPanel.setBoxPosition();
367 paintAlignment(redrawOverview);
371 void scrollToWrappedVisible(int res)
373 int cwidth = seqPanel.seqCanvas
374 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
375 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
377 vscroll.setValue((res / cwidth));
378 av.startRes = vscroll.getValue() * cwidth;
386 * @return DOCUMENT ME!
388 public OverviewPanel getOverviewPanel()
390 return overviewPanel;
399 public void setOverviewPanel(OverviewPanel op)
407 * Hide or show annotation panel
410 public void setAnnotationVisible(boolean b)
412 if (!av.wrapAlignment)
414 annotationSpaceFillerHolder.setVisible(b);
415 annotationScroller.setVisible(b);
421 * automatically adjust annotation panel height for new annotation whilst
422 * ensuring the alignment is still visible.
424 public void adjustAnnotationHeight()
426 // TODO: display vertical annotation scrollbar if necessary
427 // this is called after loading new annotation onto alignment
428 if (alignFrame.getHeight() == 0)
430 System.out.println("NEEDS FIXING");
432 validateAnnotationDimensions(true);
434 paintAlignment(true);
438 * calculate the annotation dimensions and refresh slider values accordingly.
439 * need to do repaints/notifys afterwards.
441 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
443 int height = annotationPanel.adjustPanelHeight();
445 int theight = av.getCharHeight()
446 * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0
447 : av.getAlignment().getHiddenSequences().getSize()));
448 float sscaling = (float) (theight / (1.0 * theight + height));
449 float ascaling = (float) (height * 1.0 / alignFrame.getHeight());
450 int rheight = alignFrame.getHeight() - height - av.getCharHeight();
451 if (adjustPanelHeight)
453 // NOTE: this logic is different in the applet. Need a better algorithm to
455 // try and set height according to alignment
456 if (ascaling > 0 && sscaling < 0.5)
458 // if the alignment is too big then
459 // default is 0.5 split
460 height = alignFrame.getHeight() / 2;
464 // if space for more than one sequence row left when annotation is fully
465 // displayed then set height to annotation height
466 // otherwise, leave at least two lines of sequence shown.
467 height = (rheight > av.getCharHeight()) ? height
468 : (-av.getCharHeight() * 3 + (int) (alignFrame.getHeight() * (1 - sscaling)));
473 // maintain same window layout whilst updating sliders
474 height = annotationScroller.getSize().height;
478 annotationScroller.setPreferredSize(new Dimension(annotationScroller
479 .getWidth(), height));
481 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
482 annotationSpaceFillerHolder.getWidth(), height));
483 annotationScroller.validate();// repaint();
484 annotationScroller.addNotify();
493 public void setWrapAlignment(boolean wrap)
496 scalePanelHolder.setVisible(!wrap);
497 hscroll.setVisible(!wrap);
498 idwidthAdjuster.setVisible(!wrap);
502 annotationScroller.setVisible(false);
503 annotationSpaceFillerHolder.setVisible(false);
505 else if (av.showAnnotation)
507 annotationScroller.setVisible(true);
508 annotationSpaceFillerHolder.setVisible(true);
511 idSpaceFillerPanel1.setVisible(!wrap);
516 // return value is true if the scroll is valid
517 public boolean scrollUp(boolean up)
521 if (vscroll.getValue() < 1)
527 vscroll.setValue(vscroll.getValue() - 1);
531 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
537 vscroll.setValue(vscroll.getValue() + 1);
551 * @return DOCUMENT ME!
553 public boolean scrollRight(boolean right)
557 if (hscroll.getValue() < 1)
563 hscroll.setValue(hscroll.getValue() - 1);
567 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
573 hscroll.setValue(hscroll.getValue() + 1);
582 * Adjust row/column scrollers to show a visible position in the alignment.
585 * visible column to scroll to DOCUMENT ME!
587 * visible row to scroll to
590 public void setScrollValues(int x, int y)
592 // System.err.println("Scroll to "+x+","+y);
593 if (av == null || av.getAlignment() == null)
597 int width = av.getAlignment().getWidth();
598 int height = av.getAlignment().getHeight();
600 if (av.hasHiddenColumns())
602 width = av.getColumnSelection().findColumnPosition(width);
605 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
607 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
608 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
615 if (vextent > height)
620 if ((hextent + x) > width)
625 if ((vextent + y) > height)
627 y = height - vextent;
640 hscroll.setValues(x, hextent, 0, width);
641 vscroll.setValues(y, vextent, 0, height);
650 public void adjustmentValueChanged(AdjustmentEvent evt)
653 int oldX = av.getStartRes();
654 int oldY = av.getStartSeq();
656 if (evt.getSource() == hscroll)
658 int x = hscroll.getValue();
660 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
663 if (evt.getSource() == vscroll)
665 int offy = vscroll.getValue();
667 if (av.getWrapAlignment())
671 int rowSize = seqPanel.seqCanvas
672 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
673 av.setStartRes(offy * rowSize);
674 av.setEndRes((offy + 1) * rowSize);
678 // This is only called if file loaded is a jar file that
679 // was wrapped when saved and user has wrap alignment true
680 // as preference setting
681 SwingUtilities.invokeLater(new Runnable()
685 setScrollValues(av.getStartRes(), av.getStartSeq());
692 av.setStartSeq(offy);
694 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
698 if (overviewPanel != null)
700 overviewPanel.setBoxPosition();
703 int scrollX = av.startRes - oldX;
704 int scrollY = av.startSeq - oldY;
706 if (av.getWrapAlignment() || !fastPaint)
712 // Make sure we're not trying to draw a panel
713 // larger than the visible window
714 if (scrollX > av.endRes - av.startRes)
716 scrollX = av.endRes - av.startRes;
718 else if (scrollX < av.startRes - av.endRes)
720 scrollX = av.startRes - av.endRes;
723 if (scrollX != 0 || scrollY != 0)
725 idPanel.idCanvas.fastPaint(scrollY);
726 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
727 scalePanel.repaint();
729 if (av.getShowAnnotation() && scrollX != 0)
731 annotationPanel.fastPaint(scrollX);
737 public void paintAlignment(boolean updateOverview)
743 av.getStructureSelectionManager().sequenceColoursChanged(this);
745 if (overviewPanel != null)
747 overviewPanel.updateOverviewImage();
758 public void paintComponent(Graphics g)
762 Dimension d = idPanel.idCanvas.getPreferredSize();
763 idPanelHolder.setPreferredSize(d);
764 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
767 if (av.getWrapAlignment())
769 int maxwidth = av.getAlignment().getWidth();
771 if (av.hasHiddenColumns())
773 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
776 int canvasWidth = seqPanel.seqCanvas
777 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
782 .getWrappedCanvasWidth(seqPanel.seqCanvas
784 vscroll.setMaximum(max);
785 vscroll.setUnitIncrement(1);
786 vscroll.setVisibleAmount(1);
791 setScrollValues(av.getStartRes(), av.getStartSeq());
805 * @return DOCUMENT ME!
807 * @throws PrinterException
810 public int print(Graphics pg, PageFormat pf, int pi)
811 throws PrinterException
813 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
815 int pwidth = (int) pf.getImageableWidth();
816 int pheight = (int) pf.getImageableHeight();
818 if (av.getWrapAlignment())
820 return printWrappedAlignment(pg, pwidth, pheight, pi);
824 return printUnwrapped(pg, pwidth, pheight, pi);
840 * @return DOCUMENT ME!
842 * @throws PrinterException
845 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
846 throws PrinterException
848 int idWidth = getVisibleIdWidth(false);
849 FontMetrics fm = getFontMetrics(av.getFont());
850 int scaleHeight = av.charHeight + fm.getDescent();
852 pg.setColor(Color.white);
853 pg.fillRect(0, 0, pwidth, pheight);
854 pg.setFont(av.getFont());
856 // //////////////////////////////////
857 // / How many sequences and residues can we fit on a printable page?
858 int totalRes = (pwidth - idWidth) / av.getCharWidth();
860 int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
862 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
864 // ///////////////////////////
865 // / Only print these sequences and residues on this page
868 // ///////////////////////////
869 // / Only print these sequences and residues on this page
872 // ///////////////////////////
873 // / Only print these sequences and residues on this page
876 // ///////////////////////////
877 // / Only print these sequences and residues on this page
879 startRes = (pi % pagesWide) * totalRes;
880 endRes = (startRes + totalRes) - 1;
882 if (endRes > (av.getAlignment().getWidth() - 1))
884 endRes = av.getAlignment().getWidth() - 1;
887 startSeq = (pi / pagesWide) * totalSeq;
888 endSeq = startSeq + totalSeq;
890 if (endSeq > av.getAlignment().getHeight())
892 endSeq = av.getAlignment().getHeight();
895 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
898 if (av.showAnnotation)
900 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
903 pagesHigh /= pheight;
905 if (pi >= (pagesWide * pagesHigh))
907 return Printable.NO_SUCH_PAGE;
911 pg.translate(idWidth, 0);
912 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
914 pg.translate(-idWidth, scaleHeight);
918 Color currentColor = null;
919 Color currentTextColor = null;
921 pg.setFont(idPanel.idCanvas.idfont);
924 for (int i = startSeq; i < endSeq; i++)
926 seq = av.getAlignment().getSequenceAt(i);
927 if ((av.getSelectionGroup() != null)
928 && av.getSelectionGroup().getSequences(null).contains(seq))
930 currentColor = Color.gray;
931 currentTextColor = Color.black;
935 currentColor = av.getSequenceColour(seq);
936 currentTextColor = Color.black;
939 pg.setColor(currentColor);
940 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
943 pg.setColor(currentTextColor);
946 if (av.rightAlignIds)
948 fm = pg.getFontMetrics();
950 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
955 seq.getDisplayId(av.getShowJVSuffix()),
957 (((i - startSeq) * av.charHeight) + av.getCharHeight())
958 - (av.getCharHeight() / 5));
961 pg.setFont(av.getFont());
963 // draw main sequence panel
964 pg.translate(idWidth, 0);
965 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
967 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
969 // draw annotation - need to offset for current scroll position
970 int offset = -alabels.scrollOffset;
971 pg.translate(0, offset);
972 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
973 alabels.drawComponent(pg, idWidth);
974 pg.translate(idWidth + 3, 0);
975 annotationPanel.renderer.drawComponent(annotationPanel, av,
976 pg, -1, startRes, endRes + 1);
977 pg.translate(0, -offset);
980 return Printable.PAGE_EXISTS;
995 * @return DOCUMENT ME!
997 * @throws PrinterException
1000 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
1001 int pi) throws PrinterException
1004 int annotationHeight = 0;
1005 AnnotationLabels labels = null;
1006 if (av.showAnnotation)
1008 annotationHeight = annotationPanel.adjustPanelHeight();
1009 labels = new AnnotationLabels(av);
1012 int hgap = av.charHeight;
1013 if (av.scaleAboveWrapped)
1015 hgap += av.charHeight;
1018 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1021 int idWidth = getVisibleIdWidth(false);
1023 int maxwidth = av.getAlignment().getWidth();
1024 if (av.hasHiddenColumns())
1026 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1029 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
1032 int totalHeight = cHeight * (maxwidth / resWidth + 1);
1034 pg.setColor(Color.white);
1035 pg.fillRect(0, 0, pwidth, pheight);
1036 pg.setFont(av.getFont());
1040 pg.setColor(Color.black);
1042 pg.translate(0, -pi * pheight);
1044 pg.setClip(0, pi * pheight, pwidth, pheight);
1050 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1052 pg.setFont(idPanel.idCanvas.idfont);
1053 SequenceI s = av.getAlignment().getSequenceAt(i);
1054 String string = s.getDisplayId(av.getShowJVSuffix());
1056 if (av.rightAlignIds)
1058 FontMetrics fm = pg.getFontMetrics();
1059 xPos = idWidth - fm.stringWidth(string) - 4;
1061 pg.drawString(string, xPos,
1062 ((i * av.charHeight) + ypos + av.charHeight)
1063 - (av.charHeight / 5));
1067 pg.translate(-3, ypos
1068 + (av.getAlignment().getHeight() * av.charHeight));
1070 pg.setFont(av.getFont());
1071 labels.drawComponent(pg, idWidth);
1072 pg.translate(+3, -ypos
1073 - (av.getAlignment().getHeight() * av.charHeight));
1077 } while (ypos < totalHeight);
1079 pg.translate(idWidth, 0);
1081 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1084 if ((pi * pheight) < totalHeight)
1086 return Printable.PAGE_EXISTS;
1091 return Printable.NO_SUCH_PAGE;
1096 * get current sequence ID panel width, or nominal value if panel were to be
1097 * displayed using default settings
1101 int getVisibleIdWidth()
1103 return getVisibleIdWidth(true);
1107 * get current sequence ID panel width, or nominal value if panel were to be
1108 * displayed using default settings
1111 * indicate if the Id width for onscreen or offscreen display should
1115 int getVisibleIdWidth(boolean onscreen)
1117 // see if rendering offscreen - check preferences and calc width accordingly
1118 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1120 return calculateIdWidth(-1).width + 4;
1122 Integer idwidth = null;
1124 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1126 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1127 : calculateIdWidth().width + 4);
1129 return idwidth.intValue() + 4;
1132 void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
1134 long progress = System.currentTimeMillis();
1135 boolean headless = (System.getProperty("java.awt.headless") != null && System
1136 .getProperty("java.awt.headless").equals("true"));
1137 if (alignFrame != null && !headless)
1139 alignFrame.setProgressBar(MessageManager.formatMessage(
1140 "status.saving_file",
1142 { type.getLabel() }), progress);
1146 int maxwidth = av.getAlignment().getWidth();
1147 if (av.hasHiddenColumns())
1149 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1152 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1153 + scalePanel.getHeight();
1154 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1156 if (av.getWrapAlignment())
1158 height = getWrappedHeight();
1161 // need to obtain default alignment width and then add in any
1162 // additional allowance for id margin
1163 // this duplicates the calculation in getWrappedHeight but adjusts for
1165 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1166 - alignFrame.getInsets().left
1167 - alignFrame.getInsets().right - getVisibleIdWidth()
1168 + getVisibleIdWidth(false);
1172 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1176 else if (av.getShowAnnotation())
1178 height += annotationPanel.adjustPanelHeight() + 3;
1184 jalview.util.ImageMaker im;
1185 final String imageAction, imageTitle;
1186 if (type == jalview.util.ImageMaker.TYPE.PNG)
1188 imageAction = "Create PNG image from alignment";
1191 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1193 imageAction = "Create EPS file from alignment";
1194 imageTitle = alignFrame.getTitle();
1198 imageAction = "Create SVG file from alignment";
1199 imageTitle = alignFrame.getTitle();
1202 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1203 height, file, imageTitle);
1204 if (av.getWrapAlignment())
1206 if (im.getGraphics() != null)
1208 printWrappedAlignment(im.getGraphics(), width, height, 0);
1214 if (im.getGraphics() != null)
1216 printUnwrapped(im.getGraphics(), width, height, 0);
1220 } catch (OutOfMemoryError err)
1223 System.out.println("########################\n" + "OUT OF MEMORY "
1224 + file + "\n" + "########################");
1225 new OOMWarning("Creating Image for " + file, err);
1226 // System.out.println("Create IMAGE: " + err);
1227 } catch (Exception ex)
1229 ex.printStackTrace();
1233 if (alignFrame != null && !headless)
1235 alignFrame.setProgressBar(MessageManager.getString("status.export_complete"), progress);
1243 public void makeEPS(File epsFile)
1245 makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
1251 public void makePNG(File pngFile)
1253 makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
1256 public void makeSVG(File svgFile)
1258 makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
1260 public void makePNGImageMap(File imgMapFile, String imageName)
1262 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1263 // ////////////////////////////////////////////
1264 int idWidth = getVisibleIdWidth(false);
1265 FontMetrics fm = getFontMetrics(av.getFont());
1266 int scaleHeight = av.charHeight + fm.getDescent();
1269 // ////////////////////////////////
1270 if (imgMapFile != null)
1274 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1275 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1276 StringBuffer text = new StringBuffer();
1277 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1278 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1279 out.println("<img src=\"" + imageName
1280 + "\" border=\"0\" usemap=\"#Map\" >"
1281 + "<map name=\"Map\">");
1283 for (s = 0; s < sSize; s++)
1285 sy = s * av.charHeight + scaleHeight;
1287 SequenceI seq = av.getAlignment().getSequenceAt(s);
1288 SequenceFeature[] features = seq.getDatasetSequence()
1289 .getSequenceFeatures();
1290 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1291 for (res = 0; res < alwidth; res++)
1293 text = new StringBuffer();
1295 if (av.getAlignment().isNucleotide())
1297 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1302 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1311 String triplet = obj.toString();
1312 int alIndex = seq.findPosition(res);
1313 gSize = groups.length;
1314 for (g = 0; g < gSize; g++)
1316 if (text.length() < 1)
1318 text.append("<area shape=\"rect\" coords=\""
1319 + (idWidth + res * av.charWidth) + "," + sy + ","
1320 + (idWidth + (res + 1) * av.charWidth) + ","
1321 + (av.charHeight + sy) + "\""
1322 + " onMouseOver=\"toolTip('" + alIndex + " "
1326 if (groups[g].getStartRes() < res
1327 && groups[g].getEndRes() > res)
1329 text.append("<br><em>" + groups[g].getName() + "</em>");
1333 if (features != null)
1335 if (text.length() < 1)
1337 text.append("<area shape=\"rect\" coords=\""
1338 + (idWidth + res * av.charWidth) + "," + sy + ","
1339 + (idWidth + (res + 1) * av.charWidth) + ","
1340 + (av.charHeight + sy) + "\""
1341 + " onMouseOver=\"toolTip('" + alIndex + " "
1344 fSize = features.length;
1345 for (f = 0; f < fSize; f++)
1348 if ((features[f].getBegin() <= seq.findPosition(res))
1349 && (features[f].getEnd() >= seq.findPosition(res)))
1351 if (features[f].getType().equals("disulfide bond"))
1353 if (features[f].getBegin() == seq.findPosition(res)
1354 || features[f].getEnd() == seq
1357 text.append("<br>disulfide bond "
1358 + features[f].getBegin() + ":"
1359 + features[f].getEnd());
1364 text.append("<br>");
1365 text.append(features[f].getType());
1366 if (features[f].getDescription() != null
1367 && !features[f].getType().equals(
1368 features[f].getDescription()))
1370 text.append(" " + features[f].getDescription());
1373 if (features[f].getValue("status") != null)
1375 text.append(" (" + features[f].getValue("status")
1383 if (text.length() > 1)
1385 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1386 out.println(text.toString());
1390 out.println("</map></body></html>");
1393 } catch (Exception ex)
1395 ex.printStackTrace();
1397 } // /////////END OF IMAGE MAP
1401 int getWrappedHeight()
1403 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1405 if (System.getProperty("java.awt.headless") != null
1406 && System.getProperty("java.awt.headless").equals("true"))
1408 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1409 - vscroll.getPreferredSize().width
1410 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1413 int chunkWidth = seqPanel.seqCanvas
1414 .getWrappedCanvasWidth(seqPanelWidth);
1416 int hgap = av.charHeight;
1417 if (av.scaleAboveWrapped)
1419 hgap += av.charHeight;
1422 int annotationHeight = 0;
1423 if (av.showAnnotation)
1425 annotationHeight = annotationPanel.adjustPanelHeight();
1428 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1431 int maxwidth = av.getAlignment().getWidth();
1432 if (av.hasHiddenColumns())
1434 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1437 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1443 * close the panel - deregisters all listeners and nulls any references to
1446 public void closePanel()
1448 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1449 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1450 PaintRefresher.RemoveComponent(this);
1453 jalview.structure.StructureSelectionManager ssm = av
1454 .getStructureSelectionManager();
1455 ssm.removeStructureViewerListener(seqPanel, null);
1456 ssm.removeSelectionListener(seqPanel);
1457 av.setAlignment(null);
1462 if (Cache.log.isDebugEnabled())
1464 Cache.log.warn("Closing alignment panel which is already closed.");
1470 * hides or shows dynamic annotation rows based on groups and av state flags
1472 public void updateAnnotation()
1474 updateAnnotation(false, false);
1477 public void updateAnnotation(boolean applyGlobalSettings)
1479 updateAnnotation(applyGlobalSettings, false);
1482 public void updateAnnotation(boolean applyGlobalSettings,
1483 boolean preserveNewGroupSettings)
1485 av.updateGroupAnnotationSettings(applyGlobalSettings,
1486 preserveNewGroupSettings);
1487 adjustAnnotationHeight();
1491 public AlignmentI getAlignment()
1493 return av.getAlignment();
1497 * get the name for this view
1501 public String getViewName()
1507 * Make/Unmake this alignment panel the current input focus
1511 public void setSelected(boolean b)
1515 alignFrame.setSelected(b);
1516 } catch (Exception ex)
1523 alignFrame.setDisplayedView(this);
1528 public StructureSelectionManager getStructureSelectionManager()
1530 return av.getStructureSelectionManager();
1534 public void raiseOOMWarning(String string, OutOfMemoryError error)
1536 new OOMWarning(string, error, this);
1539 public FeatureRenderer cloneFeatureRenderer()
1542 return new FeatureRenderer(this);
1545 public void updateFeatureRenderer(FeatureRenderer fr)
1547 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1550 public void updateFeatureRendererFrom(FeatureRenderer fr)
1552 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1554 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);