2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import java.awt.event.*;
26 import java.awt.print.*;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.jbgui.*;
33 import jalview.schemes.*;
34 import jalview.structure.StructureSelectionManager;
40 * @version $Revision: 1.161 $
42 public class AlignmentPanel extends GAlignmentPanel implements
43 AdjustmentListener, Printable, AlignmentViewPanel
45 public AlignViewport av;
47 OverviewPanel overviewPanel;
53 IdwidthAdjuster idwidthAdjuster;
56 public AlignFrame alignFrame;
58 ScalePanel scalePanel;
60 AnnotationPanel annotationPanel;
62 AnnotationLabels alabels;
64 // this value is set false when selection area being dragged
65 boolean fastPaint = true;
72 * Creates a new AlignmentPanel object.
79 public AlignmentPanel(AlignFrame af, final AlignViewport av)
83 seqPanel = new SeqPanel(av, this);
84 idPanel = new IdPanel(av, this);
86 scalePanel = new ScalePanel(av, this);
88 idPanelHolder.add(idPanel, BorderLayout.CENTER);
89 idwidthAdjuster = new IdwidthAdjuster(this);
90 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
92 annotationPanel = new AnnotationPanel(this);
93 alabels = new AnnotationLabels(this);
95 annotationScroller.setViewportView(annotationPanel);
96 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
98 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
99 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
101 setScrollValues(0, 0);
103 setAnnotationVisible(av.getShowAnnotation());
105 hscroll.addAdjustmentListener(this);
106 vscroll.addAdjustmentListener(this);
108 final AlignmentPanel ap = this;
109 av.addPropertyChangeListener(new PropertyChangeListener()
111 public void propertyChange(PropertyChangeEvent evt)
113 if (evt.getPropertyName().equals("alignment"))
115 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
121 adjustAnnotationHeight();
125 public void alignmentChanged()
127 av.alignmentChanged(this);
129 alignFrame.updateEditMenuBar();
131 paintAlignment(true);
138 public void fontChanged()
140 // set idCanvas bufferedImage to null
141 // to prevent drawing old image
142 FontMetrics fm = getFontMetrics(av.getFont());
144 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
146 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
149 idPanel.idCanvas.gg = null;
150 seqPanel.seqCanvas.img = null;
151 annotationPanel.adjustPanelHeight();
153 Dimension d = calculateIdWidth();
154 d.setSize(d.width + 4, d.height);
155 idPanel.idCanvas.setPreferredSize(d);
156 hscrollFillerPanel.setPreferredSize(d);
158 if (overviewPanel != null)
160 overviewPanel.setBoxPosition();
167 * Calculate the width of the alignment labels based on the displayed names
168 * and any bounds on label width set in preferences.
170 * @return Dimension giving the maximum width of the alignment label panel
171 * that should be used.
173 public Dimension calculateIdWidth()
175 // calculate sensible default width when no preference is available
177 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
178 int maxwidth = Math.max(20,
179 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
180 return calculateIdWidth(maxwidth);
184 * Calculate the width of the alignment labels based on the displayed names
185 * and any bounds on label width set in preferences.
188 * -1 or maximum width allowed for IdWidth
189 * @return Dimension giving the maximum width of the alignment label panel
190 * that should be used.
192 public Dimension calculateIdWidth(int maxwidth)
194 Container c = new Container();
196 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
197 Font.ITALIC, av.font.getSize()));
199 AlignmentI al = av.getAlignment();
204 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
206 SequenceI s = al.getSequenceAt(i);
208 id = s.getDisplayId(av.getShowJVSuffix());
210 if (fm.stringWidth(id) > idWidth)
212 idWidth = fm.stringWidth(id);
218 // Also check annotation label widths
221 if (al.getAlignmentAnnotation() != null)
223 fm = c.getFontMetrics(alabels.getFont());
225 while (i < al.getAlignmentAnnotation().length)
227 String label = al.getAlignmentAnnotation()[i].label;
229 if (fm.stringWidth(label) > idWidth)
231 idWidth = fm.stringWidth(label);
238 return new Dimension(maxwidth < 0 ? idWidth : Math.min(maxwidth,
243 * Highlight the given results on the alignment.
246 public void highlightSearchResults(SearchResults results)
248 scrollToPosition(results);
249 seqPanel.seqCanvas.highlightSearchResults(results);
253 * scroll the view to show the position of the highlighted region in results
254 * (if any) and redraw the overview
258 public boolean scrollToPosition(SearchResults results)
260 return scrollToPosition(results, true);
264 * scroll the view to show the position of the highlighted region in results
268 * @param redrawOverview
269 * - when set, the overview will be recalculated (takes longer)
270 * @return false if results were not found
272 public boolean scrollToPosition(SearchResults results,
273 boolean redrawOverview)
275 int startv, endv, starts, ends, width;
276 // TODO: properly locate search results in view when large numbers of hidden
277 // columns exist before highlighted region
278 // do we need to scroll the panel?
279 // TODO: tons of nullpointereexceptions raised here.
280 if (results != null && results.getSize() > 0 && av != null
281 && av.getAlignment() != null)
283 int seqIndex = av.getAlignment().findIndex(results);
288 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
290 int[] r = results.getResults(seq, 0, av.getAlignment().getWidth());
297 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
303 if (end == seq.getEnd())
307 if (av.hasHiddenColumns())
309 start = av.getColumnSelection().findColumnPosition(start);
310 end = av.getColumnSelection().findColumnPosition(end);
313 if (!av.getColumnSelection().isVisible(r[0]))
315 // don't scroll - position isn't visible
320 if (!av.wrapAlignment)
322 if ((startv = av.getStartRes()) >= start)
324 setScrollValues(start - 1, seqIndex);
326 else if ((endv = av.getEndRes()) <= end)
328 setScrollValues(startv + 1 + end - endv, seqIndex);
330 else if ((starts = av.getStartSeq()) > seqIndex)
332 setScrollValues(av.getStartRes(), seqIndex);
334 else if ((ends = av.getEndSeq()) <= seqIndex)
336 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
341 scrollToWrappedVisible(start);
344 if (redrawOverview && overviewPanel != null)
346 overviewPanel.setBoxPosition();
348 paintAlignment(redrawOverview);
352 void scrollToWrappedVisible(int res)
354 int cwidth = seqPanel.seqCanvas
355 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
356 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
358 vscroll.setValue((res / cwidth));
359 av.startRes = vscroll.getValue() * cwidth;
367 * @return DOCUMENT ME!
369 public OverviewPanel getOverviewPanel()
371 return overviewPanel;
380 public void setOverviewPanel(OverviewPanel op)
388 * Hide or show annotation panel
391 public void setAnnotationVisible(boolean b)
393 if (!av.wrapAlignment)
395 annotationSpaceFillerHolder.setVisible(b);
396 annotationScroller.setVisible(b);
402 * automatically adjust annotation panel height for new annotation whilst
403 * ensuring the alignment is still visible.
405 public void adjustAnnotationHeight()
407 // TODO: display vertical annotation scrollbar if necessary
408 // this is called after loading new annotation onto alignment
409 if (alignFrame.getHeight() == 0)
411 System.out.println("NEEDS FIXING");
413 validateAnnotationDimensions(true);
415 paintAlignment(true);
419 * calculate the annotation dimensions and refresh slider values accordingly.
420 * need to do repaints/notifys afterwards.
422 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
424 int height = annotationPanel.adjustPanelHeight();
426 int theight = av.getCharHeight() * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0 : av.getAlignment().getHiddenSequences().getSize()));
427 float sscaling = (float) (theight/(1.0*theight+height));
428 float ascaling=(float)(height*1.0/alignFrame.getHeight());
429 int rheight = alignFrame.getHeight() - height - av.getCharHeight();
430 if (adjustPanelHeight)
432 // NOTE: this logic is different in the applet. Need a better algorithm to define behaviour
433 // try and set height according to alignment
434 if (ascaling>0 && sscaling < 0.5)
436 // if the alignment is too big then
437 // default is 0.5 split
438 height = alignFrame.getHeight() / 2;
442 // if space for more than one sequence row left when annotation is fully displayed then set height to annotation height
443 // otherwise, leave at least two lines of sequence shown.
444 height = (rheight>av.getCharHeight()) ? height : (-av.getCharHeight() * 3
445 + (int) (alignFrame.getHeight() * (1 - sscaling)));
450 // maintain same window layout whilst updating sliders
451 height = annotationScroller.getSize().height;
455 annotationScroller.setPreferredSize(new Dimension(annotationScroller
456 .getWidth(), height));
458 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
459 annotationSpaceFillerHolder.getWidth(), height));
460 annotationScroller.validate();// repaint();
461 annotationScroller.addNotify();
470 public void setWrapAlignment(boolean wrap)
473 scalePanelHolder.setVisible(!wrap);
474 hscroll.setVisible(!wrap);
475 idwidthAdjuster.setVisible(!wrap);
479 annotationScroller.setVisible(false);
480 annotationSpaceFillerHolder.setVisible(false);
482 else if (av.showAnnotation)
484 annotationScroller.setVisible(true);
485 annotationSpaceFillerHolder.setVisible(true);
488 idSpaceFillerPanel1.setVisible(!wrap);
493 // return value is true if the scroll is valid
494 public boolean scrollUp(boolean up)
498 if (vscroll.getValue() < 1)
504 vscroll.setValue(vscroll.getValue() - 1);
508 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
514 vscroll.setValue(vscroll.getValue() + 1);
528 * @return DOCUMENT ME!
530 public boolean scrollRight(boolean right)
534 if (hscroll.getValue() < 1)
540 hscroll.setValue(hscroll.getValue() - 1);
544 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
550 hscroll.setValue(hscroll.getValue() + 1);
559 * Adjust row/column scrollers to show a visible position in the alignment.
562 * visible column to scroll to DOCUMENT ME!
564 * visible row to scroll to
567 public void setScrollValues(int x, int y)
569 // System.err.println("Scroll to "+x+","+y);
570 if (av == null || av.getAlignment() == null)
574 int width = av.getAlignment().getWidth();
575 int height = av.getAlignment().getHeight();
577 if (av.hasHiddenColumns())
579 width = av.getColumnSelection().findColumnPosition(width);
582 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
584 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
585 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
592 if (vextent > height)
597 if ((hextent + x) > width)
602 if ((vextent + y) > height)
604 y = height - vextent;
617 hscroll.setValues(x, hextent, 0, width);
618 vscroll.setValues(y, vextent, 0, height);
627 public void adjustmentValueChanged(AdjustmentEvent evt)
630 int oldX = av.getStartRes();
631 int oldY = av.getStartSeq();
633 if (evt.getSource() == hscroll)
635 int x = hscroll.getValue();
637 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
640 if (evt.getSource() == vscroll)
642 int offy = vscroll.getValue();
644 if (av.getWrapAlignment())
648 int rowSize = seqPanel.seqCanvas
649 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
650 av.setStartRes(offy * rowSize);
651 av.setEndRes((offy + 1) * rowSize);
655 // This is only called if file loaded is a jar file that
656 // was wrapped when saved and user has wrap alignment true
657 // as preference setting
658 SwingUtilities.invokeLater(new Runnable()
662 setScrollValues(av.getStartRes(), av.getStartSeq());
669 av.setStartSeq(offy);
671 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
675 if (overviewPanel != null)
677 overviewPanel.setBoxPosition();
680 int scrollX = av.startRes - oldX;
681 int scrollY = av.startSeq - oldY;
683 if (av.getWrapAlignment() || !fastPaint)
689 // Make sure we're not trying to draw a panel
690 // larger than the visible window
691 if (scrollX > av.endRes - av.startRes)
693 scrollX = av.endRes - av.startRes;
695 else if (scrollX < av.startRes - av.endRes)
697 scrollX = av.startRes - av.endRes;
700 if (scrollX != 0 || scrollY != 0)
702 idPanel.idCanvas.fastPaint(scrollY);
703 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
704 scalePanel.repaint();
706 if (av.getShowAnnotation() && scrollX!=0)
708 annotationPanel.fastPaint(scrollX);
714 public void paintAlignment(boolean updateOverview)
720 av.getStructureSelectionManager().sequenceColoursChanged(this);
722 if (overviewPanel != null)
724 overviewPanel.updateOverviewImage();
735 public void paintComponent(Graphics g)
739 Dimension d = idPanel.idCanvas.getPreferredSize();
740 idPanelHolder.setPreferredSize(d);
741 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
744 if (av.getWrapAlignment())
746 int maxwidth = av.getAlignment().getWidth();
748 if (av.hasHiddenColumns())
750 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
753 int canvasWidth = seqPanel.seqCanvas
754 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
759 .getWrappedCanvasWidth(seqPanel.seqCanvas
761 vscroll.setMaximum(max);
762 vscroll.setUnitIncrement(1);
763 vscroll.setVisibleAmount(1);
768 setScrollValues(av.getStartRes(), av.getStartSeq());
782 * @return DOCUMENT ME!
784 * @throws PrinterException
787 public int print(Graphics pg, PageFormat pf, int pi)
788 throws PrinterException
790 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
792 int pwidth = (int) pf.getImageableWidth();
793 int pheight = (int) pf.getImageableHeight();
795 if (av.getWrapAlignment())
797 return printWrappedAlignment(pg, pwidth, pheight, pi);
801 return printUnwrapped(pg, pwidth, pheight, pi);
817 * @return DOCUMENT ME!
819 * @throws PrinterException
822 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
823 throws PrinterException
825 int idWidth = getVisibleIdWidth(false);
826 FontMetrics fm = getFontMetrics(av.getFont());
827 int scaleHeight = av.charHeight + fm.getDescent();
829 pg.setColor(Color.white);
830 pg.fillRect(0, 0, pwidth, pheight);
831 pg.setFont(av.getFont());
833 // //////////////////////////////////
834 // / How many sequences and residues can we fit on a printable page?
835 int totalRes = (pwidth - idWidth) / av.getCharWidth();
837 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
839 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
841 // ///////////////////////////
842 // / Only print these sequences and residues on this page
845 // ///////////////////////////
846 // / Only print these sequences and residues on this page
849 // ///////////////////////////
850 // / Only print these sequences and residues on this page
853 // ///////////////////////////
854 // / Only print these sequences and residues on this page
856 startRes = (pi % pagesWide) * totalRes;
857 endRes = (startRes + totalRes) - 1;
859 if (endRes > (av.getAlignment().getWidth() - 1))
861 endRes = av.getAlignment().getWidth() - 1;
864 startSeq = (pi / pagesWide) * totalSeq;
865 endSeq = startSeq + totalSeq;
867 if (endSeq > av.getAlignment().getHeight())
869 endSeq = av.getAlignment().getHeight();
872 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
875 if (av.showAnnotation)
877 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
880 pagesHigh /= pheight;
882 if (pi >= (pagesWide * pagesHigh))
884 return Printable.NO_SUCH_PAGE;
888 pg.translate(idWidth, 0);
889 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
891 pg.translate(-idWidth, scaleHeight);
895 Color currentColor = null;
896 Color currentTextColor = null;
898 pg.setFont(idPanel.idCanvas.idfont);
901 for (int i = startSeq; i < endSeq; i++)
903 seq = av.getAlignment().getSequenceAt(i);
904 if ((av.getSelectionGroup() != null)
905 && av.getSelectionGroup().getSequences(null).contains(seq))
907 currentColor = Color.gray;
908 currentTextColor = Color.black;
912 currentColor = av.getSequenceColour(seq);
913 currentTextColor = Color.black;
916 pg.setColor(currentColor);
917 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
920 pg.setColor(currentTextColor);
923 if (av.rightAlignIds)
925 fm = pg.getFontMetrics();
927 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
932 seq.getDisplayId(av.getShowJVSuffix()),
934 (((i - startSeq) * av.charHeight) + av.getCharHeight())
935 - (av.getCharHeight() / 5));
938 pg.setFont(av.getFont());
940 // draw main sequence panel
941 pg.translate(idWidth, 0);
942 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
944 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
946 // draw annotation - need to offset for current scroll position
947 int offset = -alabels.scrollOffset;
948 pg.translate(0, offset);
949 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
950 alabels.drawComponent((Graphics2D) pg, idWidth);
951 pg.translate(idWidth + 3, 0);
952 annotationPanel.renderer.drawComponent(annotationPanel, av,
953 (Graphics2D) pg, -1, startRes, endRes + 1);
954 pg.translate(0, -offset);
957 return Printable.PAGE_EXISTS;
972 * @return DOCUMENT ME!
974 * @throws PrinterException
977 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
978 int pi) throws PrinterException
981 int annotationHeight = 0;
982 AnnotationLabels labels = null;
983 if (av.showAnnotation)
985 annotationHeight = annotationPanel.adjustPanelHeight();
986 labels = new AnnotationLabels(av);
989 int hgap = av.charHeight;
990 if (av.scaleAboveWrapped)
992 hgap += av.charHeight;
995 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
998 int idWidth = getVisibleIdWidth(false);
1000 int maxwidth = av.getAlignment().getWidth();
1001 if (av.hasHiddenColumns())
1003 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1006 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
1009 int totalHeight = cHeight * (maxwidth / resWidth + 1);
1011 pg.setColor(Color.white);
1012 pg.fillRect(0, 0, pwidth, pheight);
1013 pg.setFont(av.getFont());
1017 pg.setColor(Color.black);
1019 pg.translate(0, -pi * pheight);
1021 pg.setClip(0, pi * pheight, pwidth, pheight);
1027 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1029 pg.setFont(idPanel.idCanvas.idfont);
1030 SequenceI s = av.getAlignment().getSequenceAt(i);
1031 String string = s.getDisplayId(av.getShowJVSuffix());
1033 if (av.rightAlignIds)
1035 FontMetrics fm = pg.getFontMetrics();
1036 xPos = idWidth - fm.stringWidth(string) - 4;
1038 pg.drawString(string, xPos,
1039 ((i * av.charHeight) + ypos + av.charHeight)
1040 - (av.charHeight / 5));
1044 pg.translate(-3, ypos
1045 + (av.getAlignment().getHeight() * av.charHeight));
1047 pg.setFont(av.getFont());
1048 labels.drawComponent(pg, idWidth);
1049 pg.translate(+3, -ypos
1050 - (av.getAlignment().getHeight() * av.charHeight));
1054 } while (ypos < totalHeight);
1056 pg.translate(idWidth, 0);
1058 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1061 if ((pi * pheight) < totalHeight)
1063 return Printable.PAGE_EXISTS;
1068 return Printable.NO_SUCH_PAGE;
1073 * get current sequence ID panel width, or nominal value if panel were to be
1074 * displayed using default settings
1078 int getVisibleIdWidth()
1080 return getVisibleIdWidth(true);
1084 * get current sequence ID panel width, or nominal value if panel were to be
1085 * displayed using default settings
1088 * indicate if the Id width for onscreen or offscreen display should
1092 int getVisibleIdWidth(boolean onscreen)
1094 // see if rendering offscreen - check preferences and calc width accordingly
1095 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1097 return calculateIdWidth(-1).width + 4;
1099 Integer idwidth = null;
1101 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1103 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1104 : calculateIdWidth().width + 4);
1106 return idwidth.intValue() + 4;
1109 void makeAlignmentImage(int type, File file)
1111 long progress = System.currentTimeMillis();
1112 boolean headless = (System.getProperty("java.awt.headless") != null
1113 && System.getProperty("java.awt.headless").equals("true"));
1114 if (alignFrame != null && !headless)
1116 alignFrame.setProgressBar("Saving "
1117 + (type == jalview.util.ImageMaker.PNG ? "PNG image"
1118 : "EPS file"), progress);
1122 int maxwidth = av.getAlignment().getWidth();
1123 if (av.hasHiddenColumns())
1125 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1128 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1129 + scalePanel.getHeight();
1130 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1132 if (av.getWrapAlignment())
1134 height = getWrappedHeight();
1137 // need to obtain default alignment width and then add in any
1138 // additional allowance for id margin
1139 // this duplicates the calculation in getWrappedHeight but adjusts for
1141 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1142 - alignFrame.getInsets().left
1143 - alignFrame.getInsets().right - getVisibleIdWidth()
1144 + getVisibleIdWidth(false);
1148 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1152 else if (av.getShowAnnotation())
1154 height += annotationPanel.adjustPanelHeight() + 3;
1160 jalview.util.ImageMaker im;
1161 final String imageAction, imageTitle;
1162 if (type == jalview.util.ImageMaker.PNG)
1164 imageAction = "Create PNG image from alignment";
1169 imageAction = "Create EPS file from alignment";
1170 imageTitle = alignFrame.getTitle();
1172 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1173 height, file, imageTitle);
1174 if (av.getWrapAlignment())
1176 if (im.getGraphics() != null)
1178 printWrappedAlignment(im.getGraphics(), width, height, 0);
1184 if (im.getGraphics() != null)
1186 printUnwrapped(im.getGraphics(), width, height, 0);
1190 } catch (OutOfMemoryError err)
1193 System.out.println("########################\n" + "OUT OF MEMORY "
1194 + file + "\n" + "########################");
1195 new OOMWarning("Creating Image for " + file, err);
1196 // System.out.println("Create IMAGE: " + err);
1197 } catch (Exception ex)
1199 ex.printStackTrace();
1203 if (alignFrame != null && !headless)
1205 alignFrame.setProgressBar("Export complete.", progress);
1213 public void makeEPS(File epsFile)
1215 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1221 public void makePNG(File pngFile)
1223 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1226 public void makePNGImageMap(File imgMapFile, String imageName)
1228 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1229 // ////////////////////////////////////////////
1230 int idWidth = getVisibleIdWidth(false);
1231 FontMetrics fm = getFontMetrics(av.getFont());
1232 int scaleHeight = av.charHeight + fm.getDescent();
1235 // ////////////////////////////////
1236 if (imgMapFile != null)
1240 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1241 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1242 StringBuffer text = new StringBuffer();
1243 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1244 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1245 out.println("<img src=\"" + imageName
1246 + "\" border=\"0\" usemap=\"#Map\" >"
1247 + "<map name=\"Map\">");
1249 for (s = 0; s < sSize; s++)
1251 sy = s * av.charHeight + scaleHeight;
1253 SequenceI seq = av.getAlignment().getSequenceAt(s);
1254 SequenceFeature[] features = seq.getDatasetSequence()
1255 .getSequenceFeatures();
1256 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1257 for (res = 0; res < alwidth; res++)
1259 text = new StringBuffer();
1261 if (av.getAlignment().isNucleotide())
1263 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1268 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1277 String triplet = obj.toString();
1278 int alIndex = seq.findPosition(res);
1279 gSize = groups.length;
1280 for (g = 0; g < gSize; g++)
1282 if (text.length() < 1)
1284 text.append("<area shape=\"rect\" coords=\""
1285 + (idWidth + res * av.charWidth) + "," + sy + ","
1286 + (idWidth + (res + 1) * av.charWidth) + ","
1287 + (av.charHeight + sy) + "\""
1288 + " onMouseOver=\"toolTip('" + alIndex + " "
1292 if (groups[g].getStartRes() < res
1293 && groups[g].getEndRes() > res)
1295 text.append("<br><em>" + groups[g].getName() + "</em>");
1299 if (features != null)
1301 if (text.length() < 1)
1303 text.append("<area shape=\"rect\" coords=\""
1304 + (idWidth + res * av.charWidth) + "," + sy + ","
1305 + (idWidth + (res + 1) * av.charWidth) + ","
1306 + (av.charHeight + sy) + "\""
1307 + " onMouseOver=\"toolTip('" + alIndex + " "
1310 fSize = features.length;
1311 for (f = 0; f < fSize; f++)
1314 if ((features[f].getBegin() <= seq.findPosition(res))
1315 && (features[f].getEnd() >= seq.findPosition(res)))
1317 if (features[f].getType().equals("disulfide bond"))
1319 if (features[f].getBegin() == seq.findPosition(res)
1320 || features[f].getEnd() == seq
1323 text.append("<br>disulfide bond "
1324 + features[f].getBegin() + ":"
1325 + features[f].getEnd());
1330 text.append("<br>");
1331 text.append(features[f].getType());
1332 if (features[f].getDescription() != null
1333 && !features[f].getType().equals(
1334 features[f].getDescription()))
1336 text.append(" " + features[f].getDescription());
1339 if (features[f].getValue("status") != null)
1341 text.append(" (" + features[f].getValue("status")
1349 if (text.length() > 1)
1351 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1352 out.println(text.toString());
1356 out.println("</map></body></html>");
1359 } catch (Exception ex)
1361 ex.printStackTrace();
1363 } // /////////END OF IMAGE MAP
1367 int getWrappedHeight()
1369 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1371 if (System.getProperty("java.awt.headless") != null
1372 && System.getProperty("java.awt.headless").equals("true"))
1374 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1375 - vscroll.getPreferredSize().width
1376 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1379 int chunkWidth = seqPanel.seqCanvas
1380 .getWrappedCanvasWidth(seqPanelWidth);
1382 int hgap = av.charHeight;
1383 if (av.scaleAboveWrapped)
1385 hgap += av.charHeight;
1388 int annotationHeight = 0;
1389 if (av.showAnnotation)
1391 annotationHeight = annotationPanel.adjustPanelHeight();
1394 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1397 int maxwidth = av.getAlignment().getWidth();
1398 if (av.hasHiddenColumns())
1400 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1403 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1409 * close the panel - deregisters all listeners and nulls any references to
1412 public void closePanel()
1414 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1415 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1416 PaintRefresher.RemoveComponent(this);
1419 jalview.structure.StructureSelectionManager ssm = av
1420 .getStructureSelectionManager();
1421 ssm.removeStructureViewerListener(seqPanel, null);
1422 ssm.removeSelectionListener(seqPanel);
1423 av.setAlignment(null);
1428 if (Cache.log.isDebugEnabled())
1430 Cache.log.warn("Closing alignment panel which is already closed.");
1436 * hides or shows dynamic annotation rows based on groups and av state flags
1438 public void updateAnnotation()
1440 updateAnnotation(false, false);
1443 public void updateAnnotation(boolean applyGlobalSettings)
1445 updateAnnotation(applyGlobalSettings, false);
1448 public void updateAnnotation(boolean applyGlobalSettings,
1449 boolean preserveNewGroupSettings)
1451 av.updateGroupAnnotationSettings(applyGlobalSettings,
1452 preserveNewGroupSettings);
1453 adjustAnnotationHeight();
1457 public AlignmentI getAlignment()
1459 return av.getAlignment();
1463 * get the name for this view
1467 public String getViewName()
1473 * Make/Unmake this alignment panel the current input focus
1477 public void setSelected(boolean b)
1481 alignFrame.setSelected(b);
1482 } catch (Exception ex)
1489 alignFrame.setDisplayedView(this);
1494 public StructureSelectionManager getStructureSelectionManager()
1496 return av.getStructureSelectionManager();
1500 public void raiseOOMWarning(String string, OutOfMemoryError error)
1502 new OOMWarning(string, error, this);
1505 public FeatureRenderer cloneFeatureRenderer()
1508 return new FeatureRenderer(this);
1511 public void updateFeatureRenderer(FeatureRenderer fr)
1513 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1516 public void updateFeatureRendererFrom(FeatureRenderer fr)
1518 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1520 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);