2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SearchResults;
29 import jalview.datamodel.SequenceFeature;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.jbgui.GAlignmentPanel;
33 import jalview.math.AlignmentDimension;
34 import jalview.schemes.ResidueProperties;
35 import jalview.structure.StructureSelectionManager;
36 import jalview.util.MessageManager;
38 import java.awt.BorderLayout;
39 import java.awt.Color;
40 import java.awt.Container;
41 import java.awt.Dimension;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.event.AdjustmentEvent;
46 import java.awt.event.AdjustmentListener;
47 import java.awt.print.PageFormat;
48 import java.awt.print.Printable;
49 import java.awt.print.PrinterException;
50 import java.beans.PropertyChangeEvent;
51 import java.beans.PropertyChangeListener;
53 import java.io.FileWriter;
54 import java.io.PrintWriter;
56 import javax.swing.SwingUtilities;
62 * @version $Revision: 1.161 $
64 public class AlignmentPanel extends GAlignmentPanel implements
65 AdjustmentListener, Printable, AlignmentViewPanel
67 public AlignViewport av;
69 OverviewPanel overviewPanel;
71 private SeqPanel seqPanel;
73 private IdPanel idPanel;
75 private boolean headless;
76 IdwidthAdjuster idwidthAdjuster;
79 public AlignFrame alignFrame;
81 private ScalePanel scalePanel;
83 private AnnotationPanel annotationPanel;
85 private AnnotationLabels alabels;
87 // this value is set false when selection area being dragged
88 boolean fastPaint = true;
95 * Creates a new AlignmentPanel object.
100 public AlignmentPanel(AlignFrame af, final AlignViewport av)
104 setSeqPanel(new SeqPanel(av, this));
105 setIdPanel(new IdPanel(av, this));
107 setScalePanel(new ScalePanel(av, this));
109 idPanelHolder.add(getIdPanel(), BorderLayout.CENTER);
110 idwidthAdjuster = new IdwidthAdjuster(this);
111 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
113 setAnnotationPanel(new AnnotationPanel(this));
114 setAlabels(new AnnotationLabels(this));
116 annotationScroller.setViewportView(getAnnotationPanel());
117 annotationSpaceFillerHolder.add(getAlabels(), BorderLayout.CENTER);
119 scalePanelHolder.add(getScalePanel(), BorderLayout.CENTER);
120 seqPanelHolder.add(getSeqPanel(), BorderLayout.CENTER);
122 setScrollValues(0, 0);
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();
145 public AlignViewportI getAlignViewport()
149 public void alignmentChanged()
151 av.alignmentChanged(this);
153 alignFrame.updateEditMenuBar();
155 paintAlignment(true);
162 public void fontChanged()
164 // set idCanvas bufferedImage to null
165 // to prevent drawing old image
166 FontMetrics fm = getFontMetrics(av.getFont());
168 scalePanelHolder.setPreferredSize(new Dimension(10, av.getCharHeight()
170 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av
174 getIdPanel().getIdCanvas().gg = null;
175 getSeqPanel().seqCanvas.img = null;
176 getAnnotationPanel().adjustPanelHeight();
178 Dimension d = calculateIdWidth();
180 d.setSize(d.width + 4, d.height);
181 getIdPanel().getIdCanvas().setPreferredSize(d);
182 hscrollFillerPanel.setPreferredSize(d);
184 if (overviewPanel != null)
186 overviewPanel.setBoxPosition();
188 if (this.alignFrame.getSplitViewContainer() != null)
190 ((SplitFrame) this.alignFrame.getSplitViewContainer()).adjustLayout();
197 * Calculate the width of the alignment labels based on the displayed names
198 * and any bounds on label width set in preferences.
200 * @return Dimension giving the maximum width of the alignment label panel
201 * that should be used.
203 public Dimension calculateIdWidth()
205 // calculate sensible default width when no preference is available
207 if (av.getIdWidth() < 0)
209 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
210 int maxwidth = Math.max(20, Math.min(afwidth - 200, 2 * afwidth / 3));
211 r = calculateIdWidth(maxwidth);
212 av.setIdWidth(r.width);
217 r.width = av.getIdWidth();
224 * Calculate the width of the alignment labels based on the displayed names
225 * and any bounds on label width set in preferences.
228 * -1 or maximum width allowed for IdWidth
229 * @return Dimension giving the maximum width of the alignment label panel
230 * that should be used.
232 public Dimension calculateIdWidth(int maxwidth)
234 Container c = new Container();
236 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
237 Font.ITALIC, av.font.getSize()));
239 AlignmentI al = av.getAlignment();
244 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
246 SequenceI s = al.getSequenceAt(i);
248 id = s.getDisplayId(av.getShowJVSuffix());
250 if (fm.stringWidth(id) > idWidth)
252 idWidth = fm.stringWidth(id);
258 // Also check annotation label widths
261 if (al.getAlignmentAnnotation() != null)
263 fm = c.getFontMetrics(getAlabels().getFont());
265 while (i < al.getAlignmentAnnotation().length)
267 String label = al.getAlignmentAnnotation()[i].label;
269 if (fm.stringWidth(label) > idWidth)
271 idWidth = fm.stringWidth(label);
278 return new Dimension(maxwidth < 0 ? idWidth : Math.min(maxwidth,
283 * Highlight the given results on the alignment.
286 public void highlightSearchResults(SearchResults results)
288 scrollToPosition(results);
289 getSeqPanel().seqCanvas.highlightSearchResults(results);
293 * scroll the view to show the position of the highlighted region in results
294 * (if any) and redraw the overview
298 public boolean scrollToPosition(SearchResults results)
300 return scrollToPosition(results, true);
304 * scroll the view to show the position of the highlighted region in results
308 * @param redrawOverview
309 * - when set, the overview will be recalculated (takes longer)
310 * @return false if results were not found
312 public boolean scrollToPosition(SearchResults results,
313 boolean redrawOverview)
315 int startv, endv, starts, ends, width;
316 // TODO: properly locate search results in view when large numbers of hidden
317 // columns exist before highlighted region
318 // do we need to scroll the panel?
319 // TODO: tons of nullpointereexceptions raised here.
320 if (results != null && results.getSize() > 0 && av != null
321 && av.getAlignment() != null)
323 int seqIndex = av.getAlignment().findIndex(results);
328 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
330 int[] r = results.getResults(seq, 0, av.getAlignment().getWidth());
337 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
343 if (end == seq.getEnd())
347 if (av.hasHiddenColumns())
349 start = av.getColumnSelection().findColumnPosition(start);
350 end = av.getColumnSelection().findColumnPosition(end);
353 if (!av.getColumnSelection().isVisible(r[0]))
355 // don't scroll - position isn't visible
360 if (!av.getWrapAlignment())
362 if ((startv = av.getStartRes()) >= start)
364 setScrollValues(start - 1, seqIndex);
366 else if ((endv = av.getEndRes()) <= end)
368 setScrollValues(startv + 1 + end - endv, seqIndex);
370 else if ((starts = av.getStartSeq()) > seqIndex)
372 setScrollValues(av.getStartRes(), seqIndex);
374 else if ((ends = av.getEndSeq()) <= seqIndex)
376 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
381 scrollToWrappedVisible(start);
384 if (redrawOverview && overviewPanel != null)
386 overviewPanel.setBoxPosition();
388 paintAlignment(redrawOverview);
392 void scrollToWrappedVisible(int res)
394 int cwidth = getSeqPanel().seqCanvas
395 .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth());
396 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
398 vscroll.setValue((res / cwidth));
399 av.startRes = vscroll.getValue() * cwidth;
407 * @return DOCUMENT ME!
409 public OverviewPanel getOverviewPanel()
411 return overviewPanel;
420 public void setOverviewPanel(OverviewPanel op)
428 * Hide or show annotation panel
431 public void setAnnotationVisible(boolean b)
433 if (!av.getWrapAlignment())
435 annotationSpaceFillerHolder.setVisible(b);
436 annotationScroller.setVisible(b);
442 * automatically adjust annotation panel height for new annotation whilst
443 * ensuring the alignment is still visible.
445 public void adjustAnnotationHeight()
447 // TODO: display vertical annotation scrollbar if necessary
448 // this is called after loading new annotation onto alignment
449 if (alignFrame.getHeight() == 0)
451 System.out.println("NEEDS FIXING");
453 validateAnnotationDimensions(true);
455 paintAlignment(true);
459 * calculate the annotation dimensions and refresh slider values accordingly.
460 * need to do repaints/notifys afterwards.
462 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
464 int height = getAnnotationPanel().adjustPanelHeight();
466 int theight = av.getCharHeight()
467 * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0
468 : av.getAlignment().getHiddenSequences().getSize()));
469 float sscaling = (float) (theight / (1.0 * theight + height));
470 float ascaling = (float) (height * 1.0 / alignFrame.getHeight());
471 int rheight = alignFrame.getHeight() - height - av.getCharHeight();
472 if (adjustPanelHeight)
474 // NOTE: this logic is different in the applet. Need a better algorithm to
476 // try and set height according to alignment
477 if (ascaling > 0 && sscaling < 0.5)
479 // if the alignment is too big then
480 // default is 0.5 split
481 height = alignFrame.getHeight() / 2;
485 // if space for more than one sequence row left when annotation is fully
486 // displayed then set height to annotation height
487 // otherwise, leave at least two lines of sequence shown.
488 height = (rheight > av.getCharHeight()) ? height
489 : (-av.getCharHeight() * 3 + (int) (alignFrame.getHeight() * (1 - sscaling)));
494 // maintain same window layout whilst updating sliders
495 height = annotationScroller.getSize().height;
499 annotationScroller.setPreferredSize(new Dimension(annotationScroller
500 .getWidth(), height));
502 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
503 annotationSpaceFillerHolder.getWidth(), height));
504 annotationScroller.validate();// repaint();
505 annotationScroller.addNotify();
509 * update alignment layout for viewport settings
514 public void updateLayout()
517 setAnnotationVisible(av.isShowAnnotation());
518 boolean wrap = av.getWrapAlignment();
520 scalePanelHolder.setVisible(!wrap);
521 hscroll.setVisible(!wrap);
522 idwidthAdjuster.setVisible(!wrap);
526 annotationScroller.setVisible(false);
527 annotationSpaceFillerHolder.setVisible(false);
529 else if (av.isShowAnnotation())
531 annotationScroller.setVisible(true);
532 annotationSpaceFillerHolder.setVisible(true);
535 idSpaceFillerPanel1.setVisible(!wrap);
540 // return value is true if the scroll is valid
541 public boolean scrollUp(boolean up)
545 if (vscroll.getValue() < 1)
551 vscroll.setValue(vscroll.getValue() - 1);
555 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
561 vscroll.setValue(vscroll.getValue() + 1);
575 * @return DOCUMENT ME!
577 public boolean scrollRight(boolean right)
581 if (hscroll.getValue() < 1)
587 hscroll.setValue(hscroll.getValue() - 1);
591 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
597 hscroll.setValue(hscroll.getValue() + 1);
606 * Adjust row/column scrollers to show a visible position in the alignment.
609 * visible column to scroll to DOCUMENT ME!
611 * visible row to scroll to
614 public void setScrollValues(int x, int y)
616 // System.err.println("Scroll to "+x+","+y);
617 if (av == null || av.getAlignment() == null)
621 int width = av.getAlignment().getWidth();
622 int height = av.getAlignment().getHeight();
624 if (av.hasHiddenColumns())
626 width = av.getColumnSelection().findColumnPosition(width);
629 av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av
630 .getCharWidth())) - 1);
632 hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
633 vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
640 if (vextent > height)
645 if ((hextent + x) > width)
650 if ((vextent + y) > height)
652 y = height - vextent;
665 hscroll.setValues(x, hextent, 0, width);
666 vscroll.setValues(y, vextent, 0, height);
675 public void adjustmentValueChanged(AdjustmentEvent evt)
677 int oldX = av.getStartRes();
678 int oldY = av.getStartSeq();
680 if (evt.getSource() == hscroll)
682 int x = hscroll.getValue();
684 av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av.getCharWidth())) - 1);
687 if (evt.getSource() == vscroll)
689 int offy = vscroll.getValue();
691 if (av.getWrapAlignment())
695 int rowSize = getSeqPanel().seqCanvas
696 .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth());
697 av.setStartRes(offy * rowSize);
698 av.setEndRes((offy + 1) * rowSize);
702 // This is only called if file loaded is a jar file that
703 // was wrapped when saved and user has wrap alignment true
704 // as preference setting
705 SwingUtilities.invokeLater(new Runnable()
709 setScrollValues(av.getStartRes(), av.getStartSeq());
716 av.setStartSeq(offy);
718 + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()));
722 if (overviewPanel != null)
724 overviewPanel.setBoxPosition();
727 int scrollX = av.startRes - oldX;
728 int scrollY = av.startSeq - oldY;
730 if (av.getWrapAlignment() || !fastPaint)
736 // Make sure we're not trying to draw a panel
737 // larger than the visible window
738 if (scrollX > av.endRes - av.startRes)
740 scrollX = av.endRes - av.startRes;
742 else if (scrollX < av.startRes - av.endRes)
744 scrollX = av.startRes - av.endRes;
747 if (scrollX != 0 || scrollY != 0)
749 getIdPanel().getIdCanvas().fastPaint(scrollY);
750 getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY);
751 getScalePanel().repaint();
753 if (av.isShowAnnotation() && scrollX != 0)
755 getAnnotationPanel().fastPaint(scrollX);
762 * Repaint the alignment including the annotations and overview panels (if
765 public void paintAlignment(boolean updateOverview)
767 final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
768 av.isShowAutocalculatedAbove());
769 sorter.sort(getAlignment()
770 .getAlignmentAnnotation(),
771 av.getSortAnnotationsBy());
776 av.getStructureSelectionManager().sequenceColoursChanged(this);
778 if (overviewPanel != null)
780 overviewPanel.updateOverviewImage();
791 public void paintComponent(Graphics g)
795 Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
796 idPanelHolder.setPreferredSize(d);
797 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
800 if (av.getWrapAlignment())
802 int maxwidth = av.getAlignment().getWidth();
804 if (av.hasHiddenColumns())
806 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
809 int canvasWidth = getSeqPanel().seqCanvas
810 .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth());
814 / getSeqPanel().seqCanvas
815 .getWrappedCanvasWidth(getSeqPanel().seqCanvas
817 vscroll.setMaximum(max);
818 vscroll.setUnitIncrement(1);
819 vscroll.setVisibleAmount(1);
824 setScrollValues(av.getStartRes(), av.getStartSeq());
838 * @return DOCUMENT ME!
840 * @throws PrinterException
843 public int print(Graphics pg, PageFormat pf, int pi)
844 throws PrinterException
846 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
848 int pwidth = (int) pf.getImageableWidth();
849 int pheight = (int) pf.getImageableHeight();
851 if (av.getWrapAlignment())
853 return printWrappedAlignment(pg, pwidth, pheight, pi);
857 return printUnwrapped(pg, pwidth, pheight, pi);
873 * @return DOCUMENT ME!
875 * @throws PrinterException
878 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
879 throws PrinterException
881 int idWidth = getVisibleIdWidth(false);
882 FontMetrics fm = getFontMetrics(av.getFont());
883 int scaleHeight = av.getCharHeight() + fm.getDescent();
885 pg.setColor(Color.white);
886 pg.fillRect(0, 0, pwidth, pheight);
887 pg.setFont(av.getFont());
889 // //////////////////////////////////
890 // / How many sequences and residues can we fit on a printable page?
891 int totalRes = (pwidth - idWidth) / av.getCharWidth();
893 int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
895 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
897 // ///////////////////////////
898 // / Only print these sequences and residues on this page
901 // ///////////////////////////
902 // / Only print these sequences and residues on this page
905 // ///////////////////////////
906 // / Only print these sequences and residues on this page
909 // ///////////////////////////
910 // / Only print these sequences and residues on this page
912 startRes = (pi % pagesWide) * totalRes;
913 endRes = (startRes + totalRes) - 1;
915 if (endRes > (av.getAlignment().getWidth() - 1))
917 endRes = av.getAlignment().getWidth() - 1;
920 startSeq = (pi / pagesWide) * totalSeq;
921 endSeq = startSeq + totalSeq;
923 if (endSeq > av.getAlignment().getHeight())
925 endSeq = av.getAlignment().getHeight();
928 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
931 if (av.isShowAnnotation())
933 pagesHigh += getAnnotationPanel().adjustPanelHeight() + 3;
936 pagesHigh /= pheight;
938 if (pi >= (pagesWide * pagesHigh))
940 return Printable.NO_SUCH_PAGE;
944 pg.translate(idWidth, 0);
945 getScalePanel().drawScale(pg, startRes, endRes, pwidth - idWidth,
947 pg.translate(-idWidth, scaleHeight);
951 Color currentColor = null;
952 Color currentTextColor = null;
954 pg.setFont(getIdPanel().getIdCanvas().getIdfont());
957 for (int i = startSeq; i < endSeq; i++)
959 seq = av.getAlignment().getSequenceAt(i);
960 if ((av.getSelectionGroup() != null)
961 && av.getSelectionGroup().getSequences(null).contains(seq))
963 currentColor = Color.gray;
964 currentTextColor = Color.black;
968 currentColor = av.getSequenceColour(seq);
969 currentTextColor = Color.black;
972 pg.setColor(currentColor);
973 pg.fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth,
976 pg.setColor(currentTextColor);
979 if (av.isRightAlignIds())
981 fm = pg.getFontMetrics();
983 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
988 seq.getDisplayId(av.getShowJVSuffix()),
990 (((i - startSeq) * av.getCharHeight()) + av.getCharHeight())
991 - (av.getCharHeight() / 5));
994 pg.setFont(av.getFont());
996 // draw main sequence panel
997 pg.translate(idWidth, 0);
998 getSeqPanel().seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
1000 if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight()))
1002 // draw annotation - need to offset for current scroll position
1003 int offset = -getAlabels().getScrollOffset();
1004 pg.translate(0, offset);
1005 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.getCharHeight()
1007 getAlabels().drawComponent(pg, idWidth);
1008 pg.translate(idWidth + 3, 0);
1009 getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av,
1010 pg, -1, startRes, endRes + 1);
1011 pg.translate(0, -offset);
1014 return Printable.PAGE_EXISTS;
1029 * @return DOCUMENT ME!
1031 * @throws PrinterException
1034 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
1035 int pi) throws PrinterException
1037 int annotationHeight = 0;
1038 AnnotationLabels labels = null;
1039 if (av.isShowAnnotation())
1041 annotationHeight = getAnnotationPanel().adjustPanelHeight();
1042 labels = new AnnotationLabels(av);
1045 int hgap = av.getCharHeight();
1046 if (av.getScaleAboveWrapped())
1048 hgap += av.getCharHeight();
1051 int cHeight = av.getAlignment().getHeight() * av.getCharHeight() + hgap
1054 int idWidth = getVisibleIdWidth(false);
1056 int maxwidth = av.getAlignment().getWidth();
1057 if (av.hasHiddenColumns())
1059 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1062 int resWidth = getSeqPanel().seqCanvas.getWrappedCanvasWidth(pwidth
1065 int totalHeight = cHeight * (maxwidth / resWidth + 1);
1067 pg.setColor(Color.white);
1068 pg.fillRect(0, 0, pwidth, pheight);
1069 pg.setFont(av.getFont());
1073 pg.setColor(Color.black);
1075 pg.translate(0, -pi * pheight);
1077 pg.setClip(0, pi * pheight, pwidth, pheight);
1083 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1085 pg.setFont(getIdPanel().getIdCanvas().getIdfont());
1086 SequenceI s = av.getAlignment().getSequenceAt(i);
1087 String string = s.getDisplayId(av.getShowJVSuffix());
1089 if (av.isRightAlignIds())
1091 FontMetrics fm = pg.getFontMetrics();
1092 xPos = idWidth - fm.stringWidth(string) - 4;
1094 pg.drawString(string, xPos,
1095 ((i * av.getCharHeight()) + ypos + av.getCharHeight())
1096 - (av.getCharHeight() / 5));
1100 pg.translate(-3, ypos
1101 + (av.getAlignment().getHeight() * av.getCharHeight()));
1103 pg.setFont(av.getFont());
1104 labels.drawComponent(pg, idWidth);
1105 pg.translate(+3, -ypos
1106 - (av.getAlignment().getHeight() * av
1111 } while (ypos < totalHeight);
1113 pg.translate(idWidth, 0);
1115 getSeqPanel().seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1118 if ((pi * pheight) < totalHeight)
1120 return Printable.PAGE_EXISTS;
1125 return Printable.NO_SUCH_PAGE;
1130 * get current sequence ID panel width, or nominal value if panel were to be
1131 * displayed using default settings
1135 public int getVisibleIdWidth()
1137 return getVisibleIdWidth(true);
1141 * get current sequence ID panel width, or nominal value if panel were to be
1142 * displayed using default settings
1145 * indicate if the Id width for onscreen or offscreen display should
1149 public int getVisibleIdWidth(boolean onscreen)
1151 // see if rendering offscreen - check preferences and calc width accordingly
1152 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1154 return calculateIdWidth(-1).width + 4;
1156 Integer idwidth = null;
1158 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1160 return (getIdPanel().getWidth() > 0 ? getIdPanel().getWidth()
1161 : calculateIdWidth().width + 4);
1163 return idwidth.intValue() + 4;
1166 void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
1168 long progress = System.currentTimeMillis();
1169 headless = (System.getProperty("java.awt.headless") != null && System
1170 .getProperty("java.awt.headless").equals("true"));
1171 if (alignFrame != null && !headless)
1173 alignFrame.setProgressBar(MessageManager.formatMessage(
1174 "status.saving_file", new Object[]
1175 { type.getLabel() }), progress);
1179 AlignmentDimension aDimension = getAlignmentDimension();
1182 jalview.util.ImageMaker im;
1183 final String imageAction, imageTitle;
1184 if (type == jalview.util.ImageMaker.TYPE.PNG)
1186 imageAction = "Create PNG image from alignment";
1189 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1191 imageAction = "Create EPS file from alignment";
1192 imageTitle = alignFrame.getTitle();
1196 imageAction = "Create SVG file from alignment";
1197 imageTitle = alignFrame.getTitle();
1200 im = new jalview.util.ImageMaker(this, type, imageAction,
1201 aDimension.getWidth(), aDimension.getHeight(), file,
1203 if (av.getWrapAlignment())
1205 if (im.getGraphics() != null)
1207 printWrappedAlignment(im.getGraphics(), aDimension.getWidth(),
1208 aDimension.getHeight(), 0);
1214 if (im.getGraphics() != null)
1216 printUnwrapped(im.getGraphics(), aDimension.getWidth(),
1217 aDimension.getHeight(), 0);
1221 } catch (OutOfMemoryError err)
1224 System.out.println("########################\n" + "OUT OF MEMORY "
1225 + file + "\n" + "########################");
1226 new OOMWarning("Creating Image for " + file, err);
1227 // System.out.println("Create IMAGE: " + err);
1228 } catch (Exception ex)
1230 ex.printStackTrace();
1234 if (alignFrame != null && !headless)
1236 alignFrame.setProgressBar(MessageManager.getString("status.export_complete"), progress);
1241 public AlignmentDimension getAlignmentDimension()
1243 int maxwidth = av.getAlignment().getWidth();
1244 if (av.hasHiddenColumns())
1246 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1249 int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight())
1250 + getScalePanel().getHeight();
1251 int width = getVisibleIdWidth(false) + (maxwidth * av.getCharWidth());
1253 if (av.getWrapAlignment())
1255 height = getWrappedHeight();
1258 // need to obtain default alignment width and then add in any
1259 // additional allowance for id margin
1260 // this duplicates the calculation in getWrappedHeight but adjusts for
1262 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1263 - alignFrame.getInsets().left
1264 - alignFrame.getInsets().right - getVisibleIdWidth()
1265 + getVisibleIdWidth(false);
1269 width = getSeqPanel().getWidth() + getVisibleIdWidth(false);
1273 else if (av.isShowAnnotation())
1275 height += getAnnotationPanel().adjustPanelHeight() + 3;
1277 return new AlignmentDimension(width, height);
1284 public void makeEPS(File epsFile)
1286 makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
1292 public void makePNG(File pngFile)
1294 makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
1297 public void makeSVG(File svgFile)
1299 makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
1301 public void makePNGImageMap(File imgMapFile, String imageName)
1303 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1304 // ////////////////////////////////////////////
1305 int idWidth = getVisibleIdWidth(false);
1306 FontMetrics fm = getFontMetrics(av.getFont());
1307 int scaleHeight = av.getCharHeight() + fm.getDescent();
1310 // ////////////////////////////////
1311 if (imgMapFile != null)
1315 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1316 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1317 StringBuffer text = new StringBuffer();
1318 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1319 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1320 out.println("<img src=\"" + imageName
1321 + "\" border=\"0\" usemap=\"#Map\" >"
1322 + "<map name=\"Map\">");
1324 for (s = 0; s < sSize; s++)
1326 sy = s * av.getCharHeight() + scaleHeight;
1328 SequenceI seq = av.getAlignment().getSequenceAt(s);
1329 SequenceFeature[] features = seq.getSequenceFeatures();
1330 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1331 for (res = 0; res < alwidth; res++)
1333 text = new StringBuffer();
1334 String triplet = null;
1335 if (av.getAlignment().isNucleotide())
1337 triplet = ResidueProperties.nucleotideName.get(seq
1343 triplet = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1347 if (triplet == null)
1352 int alIndex = seq.findPosition(res);
1353 gSize = groups.length;
1354 for (g = 0; g < gSize; g++)
1356 if (text.length() < 1)
1358 text.append("<area shape=\"rect\" coords=\""
1359 + (idWidth + res * av.getCharWidth()) + "," + sy
1360 + "," + (idWidth + (res + 1) * av.getCharWidth())
1362 + (av.getCharHeight() + sy) + "\""
1363 + " onMouseOver=\"toolTip('" + alIndex + " "
1367 if (groups[g].getStartRes() < res
1368 && groups[g].getEndRes() > res)
1370 text.append("<br><em>" + groups[g].getName() + "</em>");
1374 if (features != null)
1376 if (text.length() < 1)
1378 text.append("<area shape=\"rect\" coords=\""
1379 + (idWidth + res * av.getCharWidth()) + "," + sy
1380 + "," + (idWidth + (res + 1) * av.getCharWidth())
1382 + (av.getCharHeight() + sy) + "\""
1383 + " onMouseOver=\"toolTip('" + alIndex + " "
1386 fSize = features.length;
1387 for (f = 0; f < fSize; f++)
1390 if ((features[f].getBegin() <= seq.findPosition(res))
1391 && (features[f].getEnd() >= seq.findPosition(res)))
1393 if (features[f].getType().equals("disulfide bond"))
1395 if (features[f].getBegin() == seq.findPosition(res)
1396 || features[f].getEnd() == seq
1399 text.append("<br>disulfide bond "
1400 + features[f].getBegin() + ":"
1401 + features[f].getEnd());
1406 text.append("<br>");
1407 text.append(features[f].getType());
1408 if (features[f].getDescription() != null
1409 && !features[f].getType().equals(
1410 features[f].getDescription()))
1412 text.append(" " + features[f].getDescription());
1415 if (features[f].getValue("status") != null)
1417 text.append(" (" + features[f].getValue("status")
1425 if (text.length() > 1)
1427 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1428 out.println(text.toString());
1432 out.println("</map></body></html>");
1435 } catch (Exception ex)
1437 ex.printStackTrace();
1439 } // /////////END OF IMAGE MAP
1443 int getWrappedHeight()
1445 int seqPanelWidth = getSeqPanel().seqCanvas.getWidth();
1447 if (System.getProperty("java.awt.headless") != null
1448 && System.getProperty("java.awt.headless").equals("true"))
1450 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1451 - vscroll.getPreferredSize().width
1452 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1455 int chunkWidth = getSeqPanel().seqCanvas
1456 .getWrappedCanvasWidth(seqPanelWidth);
1458 int hgap = av.getCharHeight();
1459 if (av.getScaleAboveWrapped())
1461 hgap += av.getCharHeight();
1464 int annotationHeight = 0;
1465 if (av.isShowAnnotation())
1467 annotationHeight = getAnnotationPanel().adjustPanelHeight();
1470 int cHeight = av.getAlignment().getHeight() * av.getCharHeight() + hgap
1473 int maxwidth = av.getAlignment().getWidth();
1474 if (av.hasHiddenColumns())
1476 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1479 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1485 * close the panel - deregisters all listeners and nulls any references to
1488 public void closePanel()
1490 PaintRefresher.RemoveComponent(getSeqPanel().seqCanvas);
1491 PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas());
1492 PaintRefresher.RemoveComponent(this);
1495 jalview.structure.StructureSelectionManager ssm = av
1496 .getStructureSelectionManager();
1497 ssm.removeStructureViewerListener(getSeqPanel(), null);
1498 ssm.removeSelectionListener(getSeqPanel());
1499 ssm.removeCommandListener(av);
1500 ssm.removeStructureViewerListener(getSeqPanel(), null);
1501 ssm.removeSelectionListener(getSeqPanel());
1502 av.setAlignment(null);
1507 if (Cache.log.isDebugEnabled())
1509 Cache.log.warn("Closing alignment panel which is already closed.");
1515 * hides or shows dynamic annotation rows based on groups and av state flags
1517 public void updateAnnotation()
1519 updateAnnotation(false, false);
1522 public void updateAnnotation(boolean applyGlobalSettings)
1524 updateAnnotation(applyGlobalSettings, false);
1527 public void updateAnnotation(boolean applyGlobalSettings,
1528 boolean preserveNewGroupSettings)
1530 av.updateGroupAnnotationSettings(applyGlobalSettings,
1531 preserveNewGroupSettings);
1532 adjustAnnotationHeight();
1536 public AlignmentI getAlignment()
1538 return av.getAlignment();
1543 public String getViewName()
1549 * Make/Unmake this alignment panel the current input focus
1553 public void setSelected(boolean b)
1557 alignFrame.setSelected(b);
1558 } catch (Exception ex)
1565 alignFrame.setDisplayedView(this);
1570 public StructureSelectionManager getStructureSelectionManager()
1572 return av.getStructureSelectionManager();
1576 public void raiseOOMWarning(String string, OutOfMemoryError error)
1578 new OOMWarning(string, error, this);
1582 public jalview.api.FeatureRenderer cloneFeatureRenderer()
1585 return new FeatureRenderer(this);
1588 public jalview.api.FeatureRenderer getFeatureRenderer()
1590 return seqPanel.seqCanvas.getFeatureRenderer();
1592 public void updateFeatureRenderer(jalview.renderer.seqfeatures.FeatureRenderer fr)
1594 fr.transferSettings(getSeqPanel().seqCanvas.getFeatureRenderer());
1597 public void updateFeatureRendererFrom(jalview.api.FeatureRenderer fr)
1599 if (getSeqPanel().seqCanvas.getFeatureRenderer() != null)
1601 getSeqPanel().seqCanvas.getFeatureRenderer().transferSettings(fr);
1605 public ScalePanel getScalePanel()
1610 public void setScalePanel(ScalePanel scalePanel)
1612 this.scalePanel = scalePanel;
1615 public SeqPanel getSeqPanel()
1620 public void setSeqPanel(SeqPanel seqPanel)
1622 this.seqPanel = seqPanel;
1625 public AnnotationPanel getAnnotationPanel()
1627 return annotationPanel;
1630 public void setAnnotationPanel(AnnotationPanel annotationPanel)
1632 this.annotationPanel = annotationPanel;
1635 public AnnotationLabels getAlabels()
1640 public void setAlabels(AnnotationLabels alabels)
1642 this.alabels = alabels;
1645 public IdPanel getIdPanel()
1650 public void setIdPanel(IdPanel idPanel)
1652 this.idPanel = idPanel;