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.analysis.AnnotationSorter;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.bin.Cache;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.SearchResults;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.jbgui.GAlignmentPanel;
32 import jalview.schemes.ResidueProperties;
33 import jalview.structure.StructureSelectionManager;
34 import jalview.util.MessageManager;
36 import java.awt.BorderLayout;
37 import java.awt.Color;
38 import java.awt.Container;
39 import java.awt.Dimension;
41 import java.awt.FontMetrics;
42 import java.awt.Graphics;
43 import java.awt.event.AdjustmentEvent;
44 import java.awt.event.AdjustmentListener;
45 import java.awt.print.PageFormat;
46 import java.awt.print.Printable;
47 import java.awt.print.PrinterException;
48 import java.beans.PropertyChangeEvent;
49 import java.beans.PropertyChangeListener;
51 import java.io.FileWriter;
52 import java.io.PrintWriter;
54 import javax.swing.SwingUtilities;
60 * @version $Revision: 1.161 $
62 public class AlignmentPanel extends GAlignmentPanel implements
63 AdjustmentListener, Printable, AlignmentViewPanel
65 public AlignViewport av;
67 OverviewPanel overviewPanel;
73 IdwidthAdjuster idwidthAdjuster;
76 public AlignFrame alignFrame;
78 ScalePanel scalePanel;
80 AnnotationPanel annotationPanel;
82 AnnotationLabels alabels;
84 // this value is set false when selection area being dragged
85 boolean fastPaint = true;
92 * Creates a new AlignmentPanel object.
99 public AlignmentPanel(AlignFrame af, final AlignViewport av)
103 seqPanel = new SeqPanel(av, this);
104 idPanel = new IdPanel(av, this);
106 scalePanel = new ScalePanel(av, this);
108 idPanelHolder.add(idPanel, BorderLayout.CENTER);
109 idwidthAdjuster = new IdwidthAdjuster(this);
110 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
112 annotationPanel = new AnnotationPanel(this);
113 alabels = new AnnotationLabels(this);
115 annotationScroller.setViewportView(annotationPanel);
116 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
118 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
119 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
121 setScrollValues(0, 0);
123 setAnnotationVisible(av.getShowAnnotation());
125 hscroll.addAdjustmentListener(this);
126 vscroll.addAdjustmentListener(this);
128 final AlignmentPanel ap = this;
129 av.addPropertyChangeListener(new PropertyChangeListener()
131 public void propertyChange(PropertyChangeEvent evt)
133 if (evt.getPropertyName().equals("alignment"))
135 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
141 adjustAnnotationHeight();
145 public void alignmentChanged()
147 av.alignmentChanged(this);
149 alignFrame.updateEditMenuBar();
151 paintAlignment(true);
158 public void fontChanged()
160 // set idCanvas bufferedImage to null
161 // to prevent drawing old image
162 FontMetrics fm = getFontMetrics(av.getFont());
164 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
166 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
169 idPanel.idCanvas.gg = null;
170 seqPanel.seqCanvas.img = null;
171 annotationPanel.adjustPanelHeight();
173 Dimension d = calculateIdWidth();
174 d.setSize(d.width + 4, d.height);
175 idPanel.idCanvas.setPreferredSize(d);
176 hscrollFillerPanel.setPreferredSize(d);
178 if (overviewPanel != null)
180 overviewPanel.setBoxPosition();
187 * Calculate the width of the alignment labels based on the displayed names
188 * and any bounds on label width set in preferences.
190 * @return Dimension giving the maximum width of the alignment label panel
191 * that should be used.
193 public Dimension calculateIdWidth()
195 // calculate sensible default width when no preference is available
197 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
198 int maxwidth = Math.max(20,
199 Math.min(afwidth - 200, 2 * afwidth / 3));
200 return calculateIdWidth(maxwidth);
204 * Calculate the width of the alignment labels based on the displayed names
205 * and any bounds on label width set in preferences.
208 * -1 or maximum width allowed for IdWidth
209 * @return Dimension giving the maximum width of the alignment label panel
210 * that should be used.
212 public Dimension calculateIdWidth(int maxwidth)
214 Container c = new Container();
216 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
217 Font.ITALIC, av.font.getSize()));
219 AlignmentI al = av.getAlignment();
224 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
226 SequenceI s = al.getSequenceAt(i);
228 id = s.getDisplayId(av.getShowJVSuffix());
230 if (fm.stringWidth(id) > idWidth)
232 idWidth = fm.stringWidth(id);
238 // Also check annotation label widths
241 if (al.getAlignmentAnnotation() != null)
243 fm = c.getFontMetrics(alabels.getFont());
245 while (i < al.getAlignmentAnnotation().length)
247 String label = al.getAlignmentAnnotation()[i].label;
249 if (fm.stringWidth(label) > idWidth)
251 idWidth = fm.stringWidth(label);
258 return new Dimension(maxwidth < 0 ? idWidth : Math.min(maxwidth,
263 * Highlight the given results on the alignment.
266 public void highlightSearchResults(SearchResults results)
268 scrollToPosition(results);
269 seqPanel.seqCanvas.highlightSearchResults(results);
273 * scroll the view to show the position of the highlighted region in results
274 * (if any) and redraw the overview
278 public boolean scrollToPosition(SearchResults results)
280 return scrollToPosition(results, true);
284 * scroll the view to show the position of the highlighted region in results
288 * @param redrawOverview
289 * - when set, the overview will be recalculated (takes longer)
290 * @return false if results were not found
292 public boolean scrollToPosition(SearchResults results,
293 boolean redrawOverview)
295 int startv, endv, starts, ends, width;
296 // TODO: properly locate search results in view when large numbers of hidden
297 // columns exist before highlighted region
298 // do we need to scroll the panel?
299 // TODO: tons of nullpointereexceptions raised here.
300 if (results != null && results.getSize() > 0 && av != null
301 && av.getAlignment() != null)
303 int seqIndex = av.getAlignment().findIndex(results);
308 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
310 int[] r = results.getResults(seq, 0, av.getAlignment().getWidth());
317 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
323 if (end == seq.getEnd())
327 if (av.hasHiddenColumns())
329 start = av.getColumnSelection().findColumnPosition(start);
330 end = av.getColumnSelection().findColumnPosition(end);
333 if (!av.getColumnSelection().isVisible(r[0]))
335 // don't scroll - position isn't visible
340 if (!av.wrapAlignment)
342 if ((startv = av.getStartRes()) >= start)
344 setScrollValues(start - 1, seqIndex);
346 else if ((endv = av.getEndRes()) <= end)
348 setScrollValues(startv + 1 + end - endv, seqIndex);
350 else if ((starts = av.getStartSeq()) > seqIndex)
352 setScrollValues(av.getStartRes(), seqIndex);
354 else if ((ends = av.getEndSeq()) <= seqIndex)
356 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
361 scrollToWrappedVisible(start);
364 if (redrawOverview && overviewPanel != null)
366 overviewPanel.setBoxPosition();
368 paintAlignment(redrawOverview);
372 void scrollToWrappedVisible(int res)
374 int cwidth = seqPanel.seqCanvas
375 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
376 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
378 vscroll.setValue((res / cwidth));
379 av.startRes = vscroll.getValue() * cwidth;
387 * @return DOCUMENT ME!
389 public OverviewPanel getOverviewPanel()
391 return overviewPanel;
400 public void setOverviewPanel(OverviewPanel op)
408 * Hide or show annotation panel
411 public void setAnnotationVisible(boolean b)
413 if (!av.wrapAlignment)
415 annotationSpaceFillerHolder.setVisible(b);
416 annotationScroller.setVisible(b);
422 * automatically adjust annotation panel height for new annotation whilst
423 * ensuring the alignment is still visible.
425 public void adjustAnnotationHeight()
427 // TODO: display vertical annotation scrollbar if necessary
428 // this is called after loading new annotation onto alignment
429 if (alignFrame.getHeight() == 0)
431 System.out.println("NEEDS FIXING");
433 validateAnnotationDimensions(true);
435 paintAlignment(true);
439 * calculate the annotation dimensions and refresh slider values accordingly.
440 * need to do repaints/notifys afterwards.
442 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
444 int height = annotationPanel.adjustPanelHeight();
446 int theight = av.getCharHeight()
447 * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0
448 : av.getAlignment().getHiddenSequences().getSize()));
449 float sscaling = (float) (theight / (1.0 * theight + height));
450 float ascaling = (float) (height * 1.0 / alignFrame.getHeight());
451 int rheight = alignFrame.getHeight() - height - av.getCharHeight();
452 if (adjustPanelHeight)
454 // NOTE: this logic is different in the applet. Need a better algorithm to
456 // try and set height according to alignment
457 if (ascaling > 0 && sscaling < 0.5)
459 // if the alignment is too big then
460 // default is 0.5 split
461 height = alignFrame.getHeight() / 2;
465 // if space for more than one sequence row left when annotation is fully
466 // displayed then set height to annotation height
467 // otherwise, leave at least two lines of sequence shown.
468 height = (rheight > av.getCharHeight()) ? height
469 : (-av.getCharHeight() * 3 + (int) (alignFrame.getHeight() * (1 - sscaling)));
474 // maintain same window layout whilst updating sliders
475 height = annotationScroller.getSize().height;
479 annotationScroller.setPreferredSize(new Dimension(annotationScroller
480 .getWidth(), height));
482 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
483 annotationSpaceFillerHolder.getWidth(), height));
484 annotationScroller.validate();// repaint();
485 annotationScroller.addNotify();
494 public void setWrapAlignment(boolean wrap)
497 scalePanelHolder.setVisible(!wrap);
498 hscroll.setVisible(!wrap);
499 idwidthAdjuster.setVisible(!wrap);
503 annotationScroller.setVisible(false);
504 annotationSpaceFillerHolder.setVisible(false);
506 else if (av.showAnnotation)
508 annotationScroller.setVisible(true);
509 annotationSpaceFillerHolder.setVisible(true);
512 idSpaceFillerPanel1.setVisible(!wrap);
517 // return value is true if the scroll is valid
518 public boolean scrollUp(boolean up)
522 if (vscroll.getValue() < 1)
528 vscroll.setValue(vscroll.getValue() - 1);
532 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
538 vscroll.setValue(vscroll.getValue() + 1);
552 * @return DOCUMENT ME!
554 public boolean scrollRight(boolean right)
558 if (hscroll.getValue() < 1)
564 hscroll.setValue(hscroll.getValue() - 1);
568 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
574 hscroll.setValue(hscroll.getValue() + 1);
583 * Adjust row/column scrollers to show a visible position in the alignment.
586 * visible column to scroll to DOCUMENT ME!
588 * visible row to scroll to
591 public void setScrollValues(int x, int y)
593 // System.err.println("Scroll to "+x+","+y);
594 if (av == null || av.getAlignment() == null)
598 int width = av.getAlignment().getWidth();
599 int height = av.getAlignment().getHeight();
601 if (av.hasHiddenColumns())
603 width = av.getColumnSelection().findColumnPosition(width);
606 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
608 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
609 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
616 if (vextent > height)
621 if ((hextent + x) > width)
626 if ((vextent + y) > height)
628 y = height - vextent;
641 hscroll.setValues(x, hextent, 0, width);
642 vscroll.setValues(y, vextent, 0, height);
651 public void adjustmentValueChanged(AdjustmentEvent evt)
654 int oldX = av.getStartRes();
655 int oldY = av.getStartSeq();
657 if (evt.getSource() == hscroll)
659 int x = hscroll.getValue();
661 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
664 if (evt.getSource() == vscroll)
666 int offy = vscroll.getValue();
668 if (av.getWrapAlignment())
672 int rowSize = seqPanel.seqCanvas
673 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
674 av.setStartRes(offy * rowSize);
675 av.setEndRes((offy + 1) * rowSize);
679 // This is only called if file loaded is a jar file that
680 // was wrapped when saved and user has wrap alignment true
681 // as preference setting
682 SwingUtilities.invokeLater(new Runnable()
686 setScrollValues(av.getStartRes(), av.getStartSeq());
693 av.setStartSeq(offy);
695 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
699 if (overviewPanel != null)
701 overviewPanel.setBoxPosition();
704 int scrollX = av.startRes - oldX;
705 int scrollY = av.startSeq - oldY;
707 if (av.getWrapAlignment() || !fastPaint)
713 // Make sure we're not trying to draw a panel
714 // larger than the visible window
715 if (scrollX > av.endRes - av.startRes)
717 scrollX = av.endRes - av.startRes;
719 else if (scrollX < av.startRes - av.endRes)
721 scrollX = av.startRes - av.endRes;
724 if (scrollX != 0 || scrollY != 0)
726 idPanel.idCanvas.fastPaint(scrollY);
727 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
728 scalePanel.repaint();
730 if (av.getShowAnnotation() && scrollX != 0)
732 annotationPanel.fastPaint(scrollX);
739 * Repaint the alignment including the annotations and overview panels (if
742 public void paintAlignment(boolean updateOverview)
744 final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
745 av.isShowAutocalculatedAbove());
746 sorter.sort(getAlignment()
747 .getAlignmentAnnotation(),
748 av.getSortAnnotationsBy());
753 av.getStructureSelectionManager().sequenceColoursChanged(this);
755 if (overviewPanel != null)
757 overviewPanel.updateOverviewImage();
768 public void paintComponent(Graphics g)
772 Dimension d = idPanel.idCanvas.getPreferredSize();
773 idPanelHolder.setPreferredSize(d);
774 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
777 if (av.getWrapAlignment())
779 int maxwidth = av.getAlignment().getWidth();
781 if (av.hasHiddenColumns())
783 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
786 int canvasWidth = seqPanel.seqCanvas
787 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
792 .getWrappedCanvasWidth(seqPanel.seqCanvas
794 vscroll.setMaximum(max);
795 vscroll.setUnitIncrement(1);
796 vscroll.setVisibleAmount(1);
801 setScrollValues(av.getStartRes(), av.getStartSeq());
815 * @return DOCUMENT ME!
817 * @throws PrinterException
820 public int print(Graphics pg, PageFormat pf, int pi)
821 throws PrinterException
823 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
825 int pwidth = (int) pf.getImageableWidth();
826 int pheight = (int) pf.getImageableHeight();
828 if (av.getWrapAlignment())
830 return printWrappedAlignment(pg, pwidth, pheight, pi);
834 return printUnwrapped(pg, pwidth, pheight, pi);
850 * @return DOCUMENT ME!
852 * @throws PrinterException
855 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
856 throws PrinterException
858 int idWidth = getVisibleIdWidth(false);
859 FontMetrics fm = getFontMetrics(av.getFont());
860 int scaleHeight = av.charHeight + fm.getDescent();
862 pg.setColor(Color.white);
863 pg.fillRect(0, 0, pwidth, pheight);
864 pg.setFont(av.getFont());
866 // //////////////////////////////////
867 // / How many sequences and residues can we fit on a printable page?
868 int totalRes = (pwidth - idWidth) / av.getCharWidth();
870 int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
872 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
874 // ///////////////////////////
875 // / Only print these sequences and residues on this page
878 // ///////////////////////////
879 // / Only print these sequences and residues on this page
882 // ///////////////////////////
883 // / Only print these sequences and residues on this page
886 // ///////////////////////////
887 // / Only print these sequences and residues on this page
889 startRes = (pi % pagesWide) * totalRes;
890 endRes = (startRes + totalRes) - 1;
892 if (endRes > (av.getAlignment().getWidth() - 1))
894 endRes = av.getAlignment().getWidth() - 1;
897 startSeq = (pi / pagesWide) * totalSeq;
898 endSeq = startSeq + totalSeq;
900 if (endSeq > av.getAlignment().getHeight())
902 endSeq = av.getAlignment().getHeight();
905 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
908 if (av.showAnnotation)
910 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
913 pagesHigh /= pheight;
915 if (pi >= (pagesWide * pagesHigh))
917 return Printable.NO_SUCH_PAGE;
921 pg.translate(idWidth, 0);
922 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
924 pg.translate(-idWidth, scaleHeight);
928 Color currentColor = null;
929 Color currentTextColor = null;
931 pg.setFont(idPanel.idCanvas.idfont);
934 for (int i = startSeq; i < endSeq; i++)
936 seq = av.getAlignment().getSequenceAt(i);
937 if ((av.getSelectionGroup() != null)
938 && av.getSelectionGroup().getSequences(null).contains(seq))
940 currentColor = Color.gray;
941 currentTextColor = Color.black;
945 currentColor = av.getSequenceColour(seq);
946 currentTextColor = Color.black;
949 pg.setColor(currentColor);
950 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
953 pg.setColor(currentTextColor);
956 if (av.rightAlignIds)
958 fm = pg.getFontMetrics();
960 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
965 seq.getDisplayId(av.getShowJVSuffix()),
967 (((i - startSeq) * av.charHeight) + av.getCharHeight())
968 - (av.getCharHeight() / 5));
971 pg.setFont(av.getFont());
973 // draw main sequence panel
974 pg.translate(idWidth, 0);
975 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
977 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
979 // draw annotation - need to offset for current scroll position
980 int offset = -alabels.scrollOffset;
981 pg.translate(0, offset);
982 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
983 alabels.drawComponent(pg, idWidth);
984 pg.translate(idWidth + 3, 0);
985 annotationPanel.renderer.drawComponent(annotationPanel, av,
986 pg, -1, startRes, endRes + 1);
987 pg.translate(0, -offset);
990 return Printable.PAGE_EXISTS;
1005 * @return DOCUMENT ME!
1007 * @throws PrinterException
1010 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
1011 int pi) throws PrinterException
1014 int annotationHeight = 0;
1015 AnnotationLabels labels = null;
1016 if (av.showAnnotation)
1018 annotationHeight = annotationPanel.adjustPanelHeight();
1019 labels = new AnnotationLabels(av);
1022 int hgap = av.charHeight;
1023 if (av.scaleAboveWrapped)
1025 hgap += av.charHeight;
1028 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1031 int idWidth = getVisibleIdWidth(false);
1033 int maxwidth = av.getAlignment().getWidth();
1034 if (av.hasHiddenColumns())
1036 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1039 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
1042 int totalHeight = cHeight * (maxwidth / resWidth + 1);
1044 pg.setColor(Color.white);
1045 pg.fillRect(0, 0, pwidth, pheight);
1046 pg.setFont(av.getFont());
1050 pg.setColor(Color.black);
1052 pg.translate(0, -pi * pheight);
1054 pg.setClip(0, pi * pheight, pwidth, pheight);
1060 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1062 pg.setFont(idPanel.idCanvas.idfont);
1063 SequenceI s = av.getAlignment().getSequenceAt(i);
1064 String string = s.getDisplayId(av.getShowJVSuffix());
1066 if (av.rightAlignIds)
1068 FontMetrics fm = pg.getFontMetrics();
1069 xPos = idWidth - fm.stringWidth(string) - 4;
1071 pg.drawString(string, xPos,
1072 ((i * av.charHeight) + ypos + av.charHeight)
1073 - (av.charHeight / 5));
1077 pg.translate(-3, ypos
1078 + (av.getAlignment().getHeight() * av.charHeight));
1080 pg.setFont(av.getFont());
1081 labels.drawComponent(pg, idWidth);
1082 pg.translate(+3, -ypos
1083 - (av.getAlignment().getHeight() * av.charHeight));
1087 } while (ypos < totalHeight);
1089 pg.translate(idWidth, 0);
1091 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1094 if ((pi * pheight) < totalHeight)
1096 return Printable.PAGE_EXISTS;
1101 return Printable.NO_SUCH_PAGE;
1106 * get current sequence ID panel width, or nominal value if panel were to be
1107 * displayed using default settings
1111 int getVisibleIdWidth()
1113 return getVisibleIdWidth(true);
1117 * get current sequence ID panel width, or nominal value if panel were to be
1118 * displayed using default settings
1121 * indicate if the Id width for onscreen or offscreen display should
1125 int getVisibleIdWidth(boolean onscreen)
1127 // see if rendering offscreen - check preferences and calc width accordingly
1128 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1130 return calculateIdWidth(-1).width + 4;
1132 Integer idwidth = null;
1134 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1136 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1137 : calculateIdWidth().width + 4);
1139 return idwidth.intValue() + 4;
1142 void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
1144 long progress = System.currentTimeMillis();
1145 boolean headless = (System.getProperty("java.awt.headless") != null && System
1146 .getProperty("java.awt.headless").equals("true"));
1147 if (alignFrame != null && !headless)
1149 alignFrame.setProgressBar(MessageManager.formatMessage(
1150 "status.saving_file",
1152 { type.getLabel() }), progress);
1156 int maxwidth = av.getAlignment().getWidth();
1157 if (av.hasHiddenColumns())
1159 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1162 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1163 + scalePanel.getHeight();
1164 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1166 if (av.getWrapAlignment())
1168 height = getWrappedHeight();
1171 // need to obtain default alignment width and then add in any
1172 // additional allowance for id margin
1173 // this duplicates the calculation in getWrappedHeight but adjusts for
1175 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1176 - alignFrame.getInsets().left
1177 - alignFrame.getInsets().right - getVisibleIdWidth()
1178 + getVisibleIdWidth(false);
1182 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1186 else if (av.getShowAnnotation())
1188 height += annotationPanel.adjustPanelHeight() + 3;
1194 jalview.util.ImageMaker im;
1195 final String imageAction, imageTitle;
1196 if (type == jalview.util.ImageMaker.TYPE.PNG)
1198 imageAction = "Create PNG image from alignment";
1201 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1203 imageAction = "Create EPS file from alignment";
1204 imageTitle = alignFrame.getTitle();
1208 imageAction = "Create SVG file from alignment";
1209 imageTitle = alignFrame.getTitle();
1212 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1213 height, file, imageTitle);
1214 if (av.getWrapAlignment())
1216 if (im.getGraphics() != null)
1218 printWrappedAlignment(im.getGraphics(), width, height, 0);
1224 if (im.getGraphics() != null)
1226 printUnwrapped(im.getGraphics(), width, height, 0);
1230 } catch (OutOfMemoryError err)
1233 System.out.println("########################\n" + "OUT OF MEMORY "
1234 + file + "\n" + "########################");
1235 new OOMWarning("Creating Image for " + file, err);
1236 // System.out.println("Create IMAGE: " + err);
1237 } catch (Exception ex)
1239 ex.printStackTrace();
1243 if (alignFrame != null && !headless)
1245 alignFrame.setProgressBar(MessageManager.getString("status.export_complete"), progress);
1253 public void makeEPS(File epsFile)
1255 makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
1261 public void makePNG(File pngFile)
1263 makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
1266 public void makeSVG(File svgFile)
1268 makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
1270 public void makePNGImageMap(File imgMapFile, String imageName)
1272 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1273 // ////////////////////////////////////////////
1274 int idWidth = getVisibleIdWidth(false);
1275 FontMetrics fm = getFontMetrics(av.getFont());
1276 int scaleHeight = av.charHeight + fm.getDescent();
1279 // ////////////////////////////////
1280 if (imgMapFile != null)
1284 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1285 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1286 StringBuffer text = new StringBuffer();
1287 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1288 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1289 out.println("<img src=\"" + imageName
1290 + "\" border=\"0\" usemap=\"#Map\" >"
1291 + "<map name=\"Map\">");
1293 for (s = 0; s < sSize; s++)
1295 sy = s * av.charHeight + scaleHeight;
1297 SequenceI seq = av.getAlignment().getSequenceAt(s);
1298 SequenceFeature[] features = seq.getDatasetSequence()
1299 .getSequenceFeatures();
1300 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1301 for (res = 0; res < alwidth; res++)
1303 text = new StringBuffer();
1305 if (av.getAlignment().isNucleotide())
1307 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1312 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1321 String triplet = obj.toString();
1322 int alIndex = seq.findPosition(res);
1323 gSize = groups.length;
1324 for (g = 0; g < gSize; g++)
1326 if (text.length() < 1)
1328 text.append("<area shape=\"rect\" coords=\""
1329 + (idWidth + res * av.charWidth) + "," + sy + ","
1330 + (idWidth + (res + 1) * av.charWidth) + ","
1331 + (av.charHeight + sy) + "\""
1332 + " onMouseOver=\"toolTip('" + alIndex + " "
1336 if (groups[g].getStartRes() < res
1337 && groups[g].getEndRes() > res)
1339 text.append("<br><em>" + groups[g].getName() + "</em>");
1343 if (features != null)
1345 if (text.length() < 1)
1347 text.append("<area shape=\"rect\" coords=\""
1348 + (idWidth + res * av.charWidth) + "," + sy + ","
1349 + (idWidth + (res + 1) * av.charWidth) + ","
1350 + (av.charHeight + sy) + "\""
1351 + " onMouseOver=\"toolTip('" + alIndex + " "
1354 fSize = features.length;
1355 for (f = 0; f < fSize; f++)
1358 if ((features[f].getBegin() <= seq.findPosition(res))
1359 && (features[f].getEnd() >= seq.findPosition(res)))
1361 if (features[f].getType().equals("disulfide bond"))
1363 if (features[f].getBegin() == seq.findPosition(res)
1364 || features[f].getEnd() == seq
1367 text.append("<br>disulfide bond "
1368 + features[f].getBegin() + ":"
1369 + features[f].getEnd());
1374 text.append("<br>");
1375 text.append(features[f].getType());
1376 if (features[f].getDescription() != null
1377 && !features[f].getType().equals(
1378 features[f].getDescription()))
1380 text.append(" " + features[f].getDescription());
1383 if (features[f].getValue("status") != null)
1385 text.append(" (" + features[f].getValue("status")
1393 if (text.length() > 1)
1395 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1396 out.println(text.toString());
1400 out.println("</map></body></html>");
1403 } catch (Exception ex)
1405 ex.printStackTrace();
1407 } // /////////END OF IMAGE MAP
1411 int getWrappedHeight()
1413 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1415 if (System.getProperty("java.awt.headless") != null
1416 && System.getProperty("java.awt.headless").equals("true"))
1418 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1419 - vscroll.getPreferredSize().width
1420 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1423 int chunkWidth = seqPanel.seqCanvas
1424 .getWrappedCanvasWidth(seqPanelWidth);
1426 int hgap = av.charHeight;
1427 if (av.scaleAboveWrapped)
1429 hgap += av.charHeight;
1432 int annotationHeight = 0;
1433 if (av.showAnnotation)
1435 annotationHeight = annotationPanel.adjustPanelHeight();
1438 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1441 int maxwidth = av.getAlignment().getWidth();
1442 if (av.hasHiddenColumns())
1444 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1447 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1453 * close the panel - deregisters all listeners and nulls any references to
1456 public void closePanel()
1458 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1459 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1460 PaintRefresher.RemoveComponent(this);
1463 jalview.structure.StructureSelectionManager ssm = av
1464 .getStructureSelectionManager();
1465 ssm.removeStructureViewerListener(seqPanel, null);
1466 ssm.removeSelectionListener(seqPanel);
1467 av.setAlignment(null);
1472 if (Cache.log.isDebugEnabled())
1474 Cache.log.warn("Closing alignment panel which is already closed.");
1480 * hides or shows dynamic annotation rows based on groups and av state flags
1482 public void updateAnnotation()
1484 updateAnnotation(false, false);
1487 public void updateAnnotation(boolean applyGlobalSettings)
1489 updateAnnotation(applyGlobalSettings, false);
1492 public void updateAnnotation(boolean applyGlobalSettings,
1493 boolean preserveNewGroupSettings)
1495 av.updateGroupAnnotationSettings(applyGlobalSettings,
1496 preserveNewGroupSettings);
1497 adjustAnnotationHeight();
1501 public AlignmentI getAlignment()
1503 return av.getAlignment();
1507 * get the name for this view
1511 public String getViewName()
1517 * Make/Unmake this alignment panel the current input focus
1521 public void setSelected(boolean b)
1525 alignFrame.setSelected(b);
1526 } catch (Exception ex)
1533 alignFrame.setDisplayedView(this);
1538 public StructureSelectionManager getStructureSelectionManager()
1540 return av.getStructureSelectionManager();
1544 public void raiseOOMWarning(String string, OutOfMemoryError error)
1546 new OOMWarning(string, error, this);
1549 public FeatureRenderer cloneFeatureRenderer()
1552 return new FeatureRenderer(this);
1555 public void updateFeatureRenderer(FeatureRenderer fr)
1557 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1560 public void updateFeatureRendererFrom(FeatureRenderer fr)
1562 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1564 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);