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.math.AlignmentDimension;
33 import jalview.schemes.ResidueProperties;
34 import jalview.structure.StructureSelectionManager;
35 import jalview.util.MessageManager;
37 import java.awt.BorderLayout;
38 import java.awt.Color;
39 import java.awt.Container;
40 import java.awt.Dimension;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.event.AdjustmentEvent;
45 import java.awt.event.AdjustmentListener;
46 import java.awt.print.PageFormat;
47 import java.awt.print.Printable;
48 import java.awt.print.PrinterException;
49 import java.beans.PropertyChangeEvent;
50 import java.beans.PropertyChangeListener;
52 import java.io.FileWriter;
53 import java.io.PrintWriter;
55 import javax.swing.SwingUtilities;
61 * @version $Revision: 1.161 $
63 public class AlignmentPanel extends GAlignmentPanel implements
64 AdjustmentListener, Printable, AlignmentViewPanel
66 public AlignViewport av;
68 OverviewPanel overviewPanel;
70 private SeqPanel seqPanel;
72 private IdPanel idPanel;
74 private boolean headless;
75 IdwidthAdjuster idwidthAdjuster;
78 public AlignFrame alignFrame;
80 private ScalePanel scalePanel;
82 private AnnotationPanel annotationPanel;
84 private AnnotationLabels alabels;
86 // this value is set false when selection area being dragged
87 boolean fastPaint = true;
94 * Creates a new AlignmentPanel object.
99 public AlignmentPanel(AlignFrame af, final AlignViewport av)
103 setSeqPanel(new SeqPanel(av, this));
104 setIdPanel(new IdPanel(av, this));
106 setScalePanel(new ScalePanel(av, this));
108 idPanelHolder.add(getIdPanel(), BorderLayout.CENTER);
109 idwidthAdjuster = new IdwidthAdjuster(this);
110 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
112 setAnnotationPanel(new AnnotationPanel(this));
113 setAlabels(new AnnotationLabels(this));
115 annotationScroller.setViewportView(getAnnotationPanel());
116 annotationSpaceFillerHolder.add(getAlabels(), BorderLayout.CENTER);
118 scalePanelHolder.add(getScalePanel(), BorderLayout.CENTER);
119 seqPanelHolder.add(getSeqPanel(), BorderLayout.CENTER);
121 setScrollValues(0, 0);
123 setAnnotationVisible(av.isShowAnnotation());
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 getIdPanel().getIdCanvas().gg = null;
170 getSeqPanel().seqCanvas.img = null;
171 getAnnotationPanel().adjustPanelHeight();
173 Dimension d = calculateIdWidth();
174 d.setSize(d.width + 4, d.height);
175 getIdPanel().getIdCanvas().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(getAlabels().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 getSeqPanel().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 = getSeqPanel().seqCanvas
375 .getWrappedCanvasWidth(getSeqPanel().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 = getAnnotationPanel().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.isShowAnnotation())
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 + (getSeqPanel().seqCanvas.getWidth() / av.charWidth)) - 1);
608 hextent = getSeqPanel().seqCanvas.getWidth() / av.charWidth;
609 vextent = getSeqPanel().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)
653 int oldX = av.getStartRes();
654 int oldY = av.getStartSeq();
656 if (evt.getSource() == hscroll)
658 int x = hscroll.getValue();
660 av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av.getCharWidth())) - 1);
663 if (evt.getSource() == vscroll)
665 int offy = vscroll.getValue();
667 if (av.getWrapAlignment())
671 int rowSize = getSeqPanel().seqCanvas
672 .getWrappedCanvasWidth(getSeqPanel().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 + (getSeqPanel().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 getIdPanel().getIdCanvas().fastPaint(scrollY);
726 getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY);
727 getScalePanel().repaint();
729 if (av.isShowAnnotation() && scrollX != 0)
731 getAnnotationPanel().fastPaint(scrollX);
738 * Repaint the alignment including the annotations and overview panels (if
741 public void paintAlignment(boolean updateOverview)
743 final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
744 av.isShowAutocalculatedAbove());
745 sorter.sort(getAlignment()
746 .getAlignmentAnnotation(),
747 av.getSortAnnotationsBy());
752 av.getStructureSelectionManager().sequenceColoursChanged(this);
754 if (overviewPanel != null)
756 overviewPanel.updateOverviewImage();
767 public void paintComponent(Graphics g)
771 Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
772 idPanelHolder.setPreferredSize(d);
773 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
776 if (av.getWrapAlignment())
778 int maxwidth = av.getAlignment().getWidth();
780 if (av.hasHiddenColumns())
782 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
785 int canvasWidth = getSeqPanel().seqCanvas
786 .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth());
790 / getSeqPanel().seqCanvas
791 .getWrappedCanvasWidth(getSeqPanel().seqCanvas
793 vscroll.setMaximum(max);
794 vscroll.setUnitIncrement(1);
795 vscroll.setVisibleAmount(1);
800 setScrollValues(av.getStartRes(), av.getStartSeq());
814 * @return DOCUMENT ME!
816 * @throws PrinterException
819 public int print(Graphics pg, PageFormat pf, int pi)
820 throws PrinterException
822 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
824 int pwidth = (int) pf.getImageableWidth();
825 int pheight = (int) pf.getImageableHeight();
827 if (av.getWrapAlignment())
829 return printWrappedAlignment(pg, pwidth, pheight, pi);
833 return printUnwrapped(pg, pwidth, pheight, pi);
849 * @return DOCUMENT ME!
851 * @throws PrinterException
854 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
855 throws PrinterException
857 int idWidth = getVisibleIdWidth(false);
858 FontMetrics fm = getFontMetrics(av.getFont());
859 int scaleHeight = av.charHeight + fm.getDescent();
861 pg.setColor(Color.white);
862 pg.fillRect(0, 0, pwidth, pheight);
863 pg.setFont(av.getFont());
865 // //////////////////////////////////
866 // / How many sequences and residues can we fit on a printable page?
867 int totalRes = (pwidth - idWidth) / av.getCharWidth();
869 int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
871 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
873 // ///////////////////////////
874 // / Only print these sequences and residues on this page
877 // ///////////////////////////
878 // / Only print these sequences and residues on this page
881 // ///////////////////////////
882 // / Only print these sequences and residues on this page
885 // ///////////////////////////
886 // / Only print these sequences and residues on this page
888 startRes = (pi % pagesWide) * totalRes;
889 endRes = (startRes + totalRes) - 1;
891 if (endRes > (av.getAlignment().getWidth() - 1))
893 endRes = av.getAlignment().getWidth() - 1;
896 startSeq = (pi / pagesWide) * totalSeq;
897 endSeq = startSeq + totalSeq;
899 if (endSeq > av.getAlignment().getHeight())
901 endSeq = av.getAlignment().getHeight();
904 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
907 if (av.isShowAnnotation())
909 pagesHigh += getAnnotationPanel().adjustPanelHeight() + 3;
912 pagesHigh /= pheight;
914 if (pi >= (pagesWide * pagesHigh))
916 return Printable.NO_SUCH_PAGE;
920 pg.translate(idWidth, 0);
921 getScalePanel().drawScale(pg, startRes, endRes, pwidth - idWidth,
923 pg.translate(-idWidth, scaleHeight);
927 Color currentColor = null;
928 Color currentTextColor = null;
930 pg.setFont(getIdPanel().getIdCanvas().getIdfont());
933 for (int i = startSeq; i < endSeq; i++)
935 seq = av.getAlignment().getSequenceAt(i);
936 if ((av.getSelectionGroup() != null)
937 && av.getSelectionGroup().getSequences(null).contains(seq))
939 currentColor = Color.gray;
940 currentTextColor = Color.black;
944 currentColor = av.getSequenceColour(seq);
945 currentTextColor = Color.black;
948 pg.setColor(currentColor);
949 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
952 pg.setColor(currentTextColor);
955 if (av.isRightAlignIds())
957 fm = pg.getFontMetrics();
959 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
964 seq.getDisplayId(av.getShowJVSuffix()),
966 (((i - startSeq) * av.charHeight) + av.getCharHeight())
967 - (av.getCharHeight() / 5));
970 pg.setFont(av.getFont());
972 // draw main sequence panel
973 pg.translate(idWidth, 0);
974 getSeqPanel().seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
976 if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight()))
978 // draw annotation - need to offset for current scroll position
979 int offset = -getAlabels().getScrollOffset();
980 pg.translate(0, offset);
981 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
982 getAlabels().drawComponent(pg, idWidth);
983 pg.translate(idWidth + 3, 0);
984 getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av,
985 pg, -1, startRes, endRes + 1);
986 pg.translate(0, -offset);
989 return Printable.PAGE_EXISTS;
1004 * @return DOCUMENT ME!
1006 * @throws PrinterException
1009 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
1010 int pi) throws PrinterException
1013 int annotationHeight = 0;
1014 AnnotationLabels labels = null;
1015 if (av.isShowAnnotation())
1017 annotationHeight = getAnnotationPanel().adjustPanelHeight();
1018 labels = new AnnotationLabels(av);
1021 int hgap = av.charHeight;
1022 if (av.scaleAboveWrapped)
1024 hgap += av.charHeight;
1027 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1030 int idWidth = getVisibleIdWidth(false);
1032 int maxwidth = av.getAlignment().getWidth();
1033 if (av.hasHiddenColumns())
1035 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1038 int resWidth = getSeqPanel().seqCanvas.getWrappedCanvasWidth(pwidth
1041 int totalHeight = cHeight * (maxwidth / resWidth + 1);
1043 pg.setColor(Color.white);
1044 pg.fillRect(0, 0, pwidth, pheight);
1045 pg.setFont(av.getFont());
1049 pg.setColor(Color.black);
1051 pg.translate(0, -pi * pheight);
1053 pg.setClip(0, pi * pheight, pwidth, pheight);
1059 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1061 pg.setFont(getIdPanel().getIdCanvas().getIdfont());
1062 SequenceI s = av.getAlignment().getSequenceAt(i);
1063 String string = s.getDisplayId(av.getShowJVSuffix());
1065 if (av.isRightAlignIds())
1067 FontMetrics fm = pg.getFontMetrics();
1068 xPos = idWidth - fm.stringWidth(string) - 4;
1070 pg.drawString(string, xPos,
1071 ((i * av.charHeight) + ypos + av.charHeight)
1072 - (av.charHeight / 5));
1076 pg.translate(-3, ypos
1077 + (av.getAlignment().getHeight() * av.charHeight));
1079 pg.setFont(av.getFont());
1080 labels.drawComponent(pg, idWidth);
1081 pg.translate(+3, -ypos
1082 - (av.getAlignment().getHeight() * av.charHeight));
1086 } while (ypos < totalHeight);
1088 pg.translate(idWidth, 0);
1090 getSeqPanel().seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1093 if ((pi * pheight) < totalHeight)
1095 return Printable.PAGE_EXISTS;
1100 return Printable.NO_SUCH_PAGE;
1105 * get current sequence ID panel width, or nominal value if panel were to be
1106 * displayed using default settings
1110 public int getVisibleIdWidth()
1112 return getVisibleIdWidth(true);
1116 * get current sequence ID panel width, or nominal value if panel were to be
1117 * displayed using default settings
1120 * indicate if the Id width for onscreen or offscreen display should
1124 public int getVisibleIdWidth(boolean onscreen)
1126 // see if rendering offscreen - check preferences and calc width accordingly
1127 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1129 return calculateIdWidth(-1).width + 4;
1131 Integer idwidth = null;
1133 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1135 return (getIdPanel().getWidth() > 0 ? getIdPanel().getWidth()
1136 : calculateIdWidth().width + 4);
1138 return idwidth.intValue() + 4;
1141 void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
1143 long progress = System.currentTimeMillis();
1144 headless = (System.getProperty("java.awt.headless") != null && System
1145 .getProperty("java.awt.headless").equals("true"));
1146 if (alignFrame != null && !headless)
1148 alignFrame.setProgressBar(MessageManager.formatMessage(
1149 "status.saving_file", new Object[]
1150 { type.getLabel() }), progress);
1154 AlignmentDimension aDimension = getAlignmentDimension();
1157 jalview.util.ImageMaker im;
1158 final String imageAction, imageTitle;
1159 if (type == jalview.util.ImageMaker.TYPE.PNG)
1161 imageAction = "Create PNG image from alignment";
1164 else if (type == jalview.util.ImageMaker.TYPE.EPS)
1166 imageAction = "Create EPS file from alignment";
1167 imageTitle = alignFrame.getTitle();
1171 imageAction = "Create SVG file from alignment";
1172 imageTitle = alignFrame.getTitle();
1175 im = new jalview.util.ImageMaker(this, type, imageAction,
1176 aDimension.getWidth(), aDimension.getHeight(), file,
1178 if (av.getWrapAlignment())
1180 if (im.getGraphics() != null)
1182 printWrappedAlignment(im.getGraphics(), aDimension.getWidth(),
1183 aDimension.getHeight(), 0);
1189 if (im.getGraphics() != null)
1191 printUnwrapped(im.getGraphics(), aDimension.getWidth(),
1192 aDimension.getHeight(), 0);
1196 } catch (OutOfMemoryError err)
1199 System.out.println("########################\n" + "OUT OF MEMORY "
1200 + file + "\n" + "########################");
1201 new OOMWarning("Creating Image for " + file, err);
1202 // System.out.println("Create IMAGE: " + err);
1203 } catch (Exception ex)
1205 ex.printStackTrace();
1209 if (alignFrame != null && !headless)
1211 alignFrame.setProgressBar(MessageManager.getString("status.export_complete"), progress);
1216 public AlignmentDimension getAlignmentDimension()
1218 int maxwidth = av.getAlignment().getWidth();
1219 if (av.hasHiddenColumns())
1221 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1224 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1225 + getScalePanel().getHeight();
1226 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1228 if (av.getWrapAlignment())
1230 height = getWrappedHeight();
1233 // need to obtain default alignment width and then add in any
1234 // additional allowance for id margin
1235 // this duplicates the calculation in getWrappedHeight but adjusts for
1237 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1238 - alignFrame.getInsets().left
1239 - alignFrame.getInsets().right - getVisibleIdWidth()
1240 + getVisibleIdWidth(false);
1244 width = getSeqPanel().getWidth() + getVisibleIdWidth(false);
1248 else if (av.isShowAnnotation())
1250 height += getAnnotationPanel().adjustPanelHeight() + 3;
1252 return new AlignmentDimension(width, height);
1259 public void makeEPS(File epsFile)
1261 makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
1267 public void makePNG(File pngFile)
1269 makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
1272 public void makeSVG(File svgFile)
1274 makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
1276 public void makePNGImageMap(File imgMapFile, String imageName)
1278 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1279 // ////////////////////////////////////////////
1280 int idWidth = getVisibleIdWidth(false);
1281 FontMetrics fm = getFontMetrics(av.getFont());
1282 int scaleHeight = av.charHeight + fm.getDescent();
1285 // ////////////////////////////////
1286 if (imgMapFile != null)
1290 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1291 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1292 StringBuffer text = new StringBuffer();
1293 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1294 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1295 out.println("<img src=\"" + imageName
1296 + "\" border=\"0\" usemap=\"#Map\" >"
1297 + "<map name=\"Map\">");
1299 for (s = 0; s < sSize; s++)
1301 sy = s * av.charHeight + scaleHeight;
1303 SequenceI seq = av.getAlignment().getSequenceAt(s);
1304 SequenceFeature[] features = seq.getDatasetSequence()
1305 .getSequenceFeatures();
1306 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1307 for (res = 0; res < alwidth; res++)
1309 text = new StringBuffer();
1311 if (av.getAlignment().isNucleotide())
1313 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1318 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1327 String triplet = obj.toString();
1328 int alIndex = seq.findPosition(res);
1329 gSize = groups.length;
1330 for (g = 0; g < gSize; g++)
1332 if (text.length() < 1)
1334 text.append("<area shape=\"rect\" coords=\""
1335 + (idWidth + res * av.charWidth) + "," + sy + ","
1336 + (idWidth + (res + 1) * av.charWidth) + ","
1337 + (av.charHeight + sy) + "\""
1338 + " onMouseOver=\"toolTip('" + alIndex + " "
1342 if (groups[g].getStartRes() < res
1343 && groups[g].getEndRes() > res)
1345 text.append("<br><em>" + groups[g].getName() + "</em>");
1349 if (features != null)
1351 if (text.length() < 1)
1353 text.append("<area shape=\"rect\" coords=\""
1354 + (idWidth + res * av.charWidth) + "," + sy + ","
1355 + (idWidth + (res + 1) * av.charWidth) + ","
1356 + (av.charHeight + sy) + "\""
1357 + " onMouseOver=\"toolTip('" + alIndex + " "
1360 fSize = features.length;
1361 for (f = 0; f < fSize; f++)
1364 if ((features[f].getBegin() <= seq.findPosition(res))
1365 && (features[f].getEnd() >= seq.findPosition(res)))
1367 if (features[f].getType().equals("disulfide bond"))
1369 if (features[f].getBegin() == seq.findPosition(res)
1370 || features[f].getEnd() == seq
1373 text.append("<br>disulfide bond "
1374 + features[f].getBegin() + ":"
1375 + features[f].getEnd());
1380 text.append("<br>");
1381 text.append(features[f].getType());
1382 if (features[f].getDescription() != null
1383 && !features[f].getType().equals(
1384 features[f].getDescription()))
1386 text.append(" " + features[f].getDescription());
1389 if (features[f].getValue("status") != null)
1391 text.append(" (" + features[f].getValue("status")
1399 if (text.length() > 1)
1401 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1402 out.println(text.toString());
1406 out.println("</map></body></html>");
1409 } catch (Exception ex)
1411 ex.printStackTrace();
1413 } // /////////END OF IMAGE MAP
1417 int getWrappedHeight()
1419 int seqPanelWidth = getSeqPanel().seqCanvas.getWidth();
1421 if (System.getProperty("java.awt.headless") != null
1422 && System.getProperty("java.awt.headless").equals("true"))
1424 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1425 - vscroll.getPreferredSize().width
1426 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1429 int chunkWidth = getSeqPanel().seqCanvas
1430 .getWrappedCanvasWidth(seqPanelWidth);
1432 int hgap = av.charHeight;
1433 if (av.scaleAboveWrapped)
1435 hgap += av.charHeight;
1438 int annotationHeight = 0;
1439 if (av.isShowAnnotation())
1441 annotationHeight = getAnnotationPanel().adjustPanelHeight();
1444 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1447 int maxwidth = av.getAlignment().getWidth();
1448 if (av.hasHiddenColumns())
1450 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1453 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1459 * close the panel - deregisters all listeners and nulls any references to
1462 public void closePanel()
1464 PaintRefresher.RemoveComponent(getSeqPanel().seqCanvas);
1465 PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas());
1466 PaintRefresher.RemoveComponent(this);
1469 jalview.structure.StructureSelectionManager ssm = av
1470 .getStructureSelectionManager();
1471 ssm.removeStructureViewerListener(getSeqPanel(), null);
1472 ssm.removeSelectionListener(getSeqPanel());
1473 ssm.removeEditListener(av);
1474 ssm.removeStructureViewerListener(getSeqPanel(), null);
1475 ssm.removeSelectionListener(getSeqPanel());
1476 av.setAlignment(null);
1481 if (Cache.log.isDebugEnabled())
1483 Cache.log.warn("Closing alignment panel which is already closed.");
1489 * hides or shows dynamic annotation rows based on groups and av state flags
1491 public void updateAnnotation()
1493 updateAnnotation(false, false);
1496 public void updateAnnotation(boolean applyGlobalSettings)
1498 updateAnnotation(applyGlobalSettings, false);
1501 public void updateAnnotation(boolean applyGlobalSettings,
1502 boolean preserveNewGroupSettings)
1504 av.updateGroupAnnotationSettings(applyGlobalSettings,
1505 preserveNewGroupSettings);
1506 adjustAnnotationHeight();
1510 public AlignmentI getAlignment()
1512 return av.getAlignment();
1517 public String getViewName()
1523 * Make/Unmake this alignment panel the current input focus
1527 public void setSelected(boolean b)
1531 alignFrame.setSelected(b);
1532 } catch (Exception ex)
1539 alignFrame.setDisplayedView(this);
1544 public StructureSelectionManager getStructureSelectionManager()
1546 return av.getStructureSelectionManager();
1550 public void raiseOOMWarning(String string, OutOfMemoryError error)
1552 new OOMWarning(string, error, this);
1556 public jalview.api.FeatureRenderer cloneFeatureRenderer()
1559 return new FeatureRenderer(this);
1562 public jalview.api.FeatureRenderer getFeatureRenderer()
1564 return seqPanel.seqCanvas.getFeatureRenderer();
1566 public void updateFeatureRenderer(jalview.renderer.seqfeatures.FeatureRenderer fr)
1568 fr.transferSettings(getSeqPanel().seqCanvas.getFeatureRenderer());
1571 public void updateFeatureRendererFrom(jalview.api.FeatureRenderer fr)
1573 if (getSeqPanel().seqCanvas.getFeatureRenderer() != null)
1575 getSeqPanel().seqCanvas.getFeatureRenderer().transferSettings(fr);
1579 public ScalePanel getScalePanel()
1584 public void setScalePanel(ScalePanel scalePanel)
1586 this.scalePanel = scalePanel;
1589 public SeqPanel getSeqPanel()
1594 public void setSeqPanel(SeqPanel seqPanel)
1596 this.seqPanel = seqPanel;
1599 public AnnotationPanel getAnnotationPanel()
1601 return annotationPanel;
1604 public void setAnnotationPanel(AnnotationPanel annotationPanel)
1606 this.annotationPanel = annotationPanel;
1609 public AnnotationLabels getAlabels()
1614 public void setAlabels(AnnotationLabels alabels)
1616 this.alabels = alabels;
1619 public IdPanel getIdPanel()
1624 public void setIdPanel(IdPanel idPanel)
1626 this.idPanel = idPanel;