2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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/>.
22 import java.util.Hashtable;
23 import java.util.Vector;
26 import java.awt.event.*;
27 import java.awt.print.*;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.bin.Cache;
32 import jalview.datamodel.*;
33 import jalview.jbgui.*;
34 import jalview.schemes.*;
35 import jalview.structure.StructureSelectionManager;
41 * @version $Revision: 1.161 $
43 public class AlignmentPanel extends GAlignmentPanel implements
44 AdjustmentListener, Printable, AlignmentViewPanel
46 public AlignViewport av;
48 OverviewPanel overviewPanel;
54 IdwidthAdjuster idwidthAdjuster;
57 public AlignFrame alignFrame;
59 ScalePanel scalePanel;
61 AnnotationPanel annotationPanel;
63 AnnotationLabels alabels;
65 // this value is set false when selection area being dragged
66 boolean fastPaint = true;
73 * Creates a new AlignmentPanel object.
80 public AlignmentPanel(AlignFrame af, final AlignViewport av)
84 seqPanel = new SeqPanel(av, this);
85 idPanel = new IdPanel(av, this);
87 scalePanel = new ScalePanel(av, this);
89 idPanelHolder.add(idPanel, BorderLayout.CENTER);
90 idwidthAdjuster = new IdwidthAdjuster(this);
91 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
93 annotationPanel = new AnnotationPanel(this);
94 alabels = new AnnotationLabels(this);
96 annotationScroller.setViewportView(annotationPanel);
97 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
99 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
100 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
102 setScrollValues(0, 0);
104 setAnnotationVisible(av.getShowAnnotation());
106 hscroll.addAdjustmentListener(this);
107 vscroll.addAdjustmentListener(this);
109 final AlignmentPanel ap = this;
110 av.addPropertyChangeListener(new PropertyChangeListener()
112 public void propertyChange(PropertyChangeEvent evt)
114 if (evt.getPropertyName().equals("alignment"))
116 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
122 adjustAnnotationHeight();
126 public void alignmentChanged()
128 av.alignmentChanged(this);
130 alignFrame.updateEditMenuBar();
132 paintAlignment(true);
139 public void fontChanged()
141 // set idCanvas bufferedImage to null
142 // to prevent drawing old image
143 FontMetrics fm = getFontMetrics(av.getFont());
145 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
147 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
150 idPanel.idCanvas.gg = null;
151 seqPanel.seqCanvas.img = null;
152 annotationPanel.adjustPanelHeight();
154 Dimension d = calculateIdWidth();
155 d.setSize(d.width + 4, d.height);
156 idPanel.idCanvas.setPreferredSize(d);
157 hscrollFillerPanel.setPreferredSize(d);
159 if (overviewPanel != null)
161 overviewPanel.setBoxPosition();
168 * Calculate the width of the alignment labels based on the displayed names
169 * and any bounds on label width set in preferences.
171 * @return Dimension giving the maximum width of the alignment label panel
172 * that should be used.
174 public Dimension calculateIdWidth()
176 // calculate sensible default width when no preference is available
178 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
179 int maxwidth = Math.max(20,
180 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
181 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.
186 * @param maxwidth -1 or maximum width allowed for IdWidth
187 * @return Dimension giving the maximum width of the alignment label panel
188 * that should be used.
190 public Dimension calculateIdWidth(int maxwidth)
192 Container c = new Container();
194 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
195 Font.ITALIC, av.font.getSize()));
197 AlignmentI al = av.getAlignment();
202 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
204 SequenceI s = al.getSequenceAt(i);
206 id = s.getDisplayId(av.getShowJVSuffix());
208 if (fm.stringWidth(id) > idWidth)
210 idWidth = fm.stringWidth(id);
216 // Also check annotation label widths
219 if (al.getAlignmentAnnotation() != null)
221 fm = c.getFontMetrics(alabels.getFont());
223 while (i < al.getAlignmentAnnotation().length)
225 String label = al.getAlignmentAnnotation()[i].label;
227 if (fm.stringWidth(label) > idWidth)
229 idWidth = fm.stringWidth(label);
236 return new Dimension(maxwidth<0 ? idWidth : Math.min(maxwidth, idWidth), 12);
240 * Highlight the given results on the alignment.
243 public void highlightSearchResults(SearchResults results)
245 scrollToPosition(results);
246 seqPanel.seqCanvas.highlightSearchResults(results);
250 * scroll the view to show the position of the highlighted region in results
251 * (if any) and redraw the overview
255 public boolean scrollToPosition(SearchResults results)
257 return scrollToPosition(results, true);
261 * scroll the view to show the position of the highlighted region in results
265 * @param redrawOverview
266 * - when set, the overview will be recalculated (takes longer)
267 * @return false if results were not found
269 public boolean scrollToPosition(SearchResults results,
270 boolean redrawOverview)
272 int startv, endv, starts, ends, width;
273 // TODO: properly locate search results in view when large numbers of hidden
274 // columns exist before highlighted region
275 // do we need to scroll the panel?
276 // TODO: tons of nullpointereexceptions raised here.
277 if (results != null && results.getSize() > 0 && av != null
278 && av.getAlignment() != null)
280 int seqIndex = av.getAlignment().findIndex(results);
285 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
287 int[] r=results.getResults(seq, 0, av.getAlignment().getWidth());
294 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
300 if (end == seq.getEnd())
304 if (av.hasHiddenColumns())
306 start = av.getColumnSelection().findColumnPosition(start);
307 end = av.getColumnSelection().findColumnPosition(end);
310 if (!av.getColumnSelection().isVisible(r[0]))
312 // don't scroll - position isn't visible
317 if (!av.wrapAlignment)
319 if ((startv = av.getStartRes()) >= start)
321 setScrollValues(start - 1, seqIndex);
323 else if ((endv = av.getEndRes()) <= end)
325 setScrollValues(startv + 1 + end - endv, seqIndex);
327 else if ((starts = av.getStartSeq()) > seqIndex)
329 setScrollValues(av.getStartRes(), seqIndex);
331 else if ((ends = av.getEndSeq()) <= seqIndex)
333 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
338 scrollToWrappedVisible(start);
341 if (redrawOverview && overviewPanel != null)
343 overviewPanel.setBoxPosition();
345 paintAlignment(redrawOverview);
349 void scrollToWrappedVisible(int res)
351 int cwidth = seqPanel.seqCanvas
352 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
353 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
355 vscroll.setValue((res / cwidth));
356 av.startRes = vscroll.getValue() * cwidth;
364 * @return DOCUMENT ME!
366 public OverviewPanel getOverviewPanel()
368 return overviewPanel;
377 public void setOverviewPanel(OverviewPanel op)
384 * @param b Hide or show annotation panel
387 public void setAnnotationVisible(boolean b)
389 if (!av.wrapAlignment)
391 annotationSpaceFillerHolder.setVisible(b);
392 annotationScroller.setVisible(b);
398 * automatically adjust annotation panel height for new annotation
399 * whilst ensuring the alignment is still visible.
401 public void adjustAnnotationHeight()
403 // TODO: display vertical annotation scrollbar if necessary
404 // this is called after loading new annotation onto alignment
405 if (alignFrame.getHeight() == 0)
407 System.out.println("NEEDS FIXING");
409 validateAnnotationDimensions(true);
411 paintAlignment(true);
414 * calculate the annotation dimensions and refresh slider values accordingly.
415 * need to do repaints/notifys afterwards.
417 protected void validateAnnotationDimensions(boolean adjustPanelHeight) {
418 int height = annotationPanel.adjustPanelHeight();
420 if (hscroll.isVisible())
422 height += hscroll.getPreferredSize().height;
424 if (height > alignFrame.getHeight() / 2)
426 height = alignFrame.getHeight() / 2;
428 if (!adjustPanelHeight)
430 // maintain same window layout whilst updating sliders
431 height=annotationScroller.getSize().height;
435 annotationScroller.setPreferredSize(new Dimension(annotationScroller
436 .getWidth(), height));
438 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
439 annotationSpaceFillerHolder.getWidth(), height));
440 annotationScroller.validate();// repaint();
441 annotationScroller.addNotify();
450 public void setWrapAlignment(boolean wrap)
453 scalePanelHolder.setVisible(!wrap);
454 hscroll.setVisible(!wrap);
455 idwidthAdjuster.setVisible(!wrap);
459 annotationScroller.setVisible(false);
460 annotationSpaceFillerHolder.setVisible(false);
462 else if (av.showAnnotation)
464 annotationScroller.setVisible(true);
465 annotationSpaceFillerHolder.setVisible(true);
468 idSpaceFillerPanel1.setVisible(!wrap);
473 // return value is true if the scroll is valid
474 public boolean scrollUp(boolean up)
478 if (vscroll.getValue() < 1)
484 vscroll.setValue(vscroll.getValue() - 1);
488 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
494 vscroll.setValue(vscroll.getValue() + 1);
508 * @return DOCUMENT ME!
510 public boolean scrollRight(boolean right)
514 if (hscroll.getValue() < 1)
520 hscroll.setValue(hscroll.getValue() - 1);
524 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
530 hscroll.setValue(hscroll.getValue() + 1);
539 * Adjust row/column scrollers to show a visible position in the alignment.
541 * @param x visible column to scroll to
543 * @param y visible row to scroll to
546 public void setScrollValues(int x, int y)
548 // System.err.println("Scroll to "+x+","+y);
549 if (av == null || av.getAlignment() == null)
553 int width = av.getAlignment().getWidth();
554 int height = av.getAlignment().getHeight();
556 if (av.hasHiddenColumns())
558 width = av.getColumnSelection().findColumnPosition(width);
561 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
563 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
564 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
571 if (vextent > height)
576 if ((hextent + x) > width)
581 if ((vextent + y) > height)
583 y = height - vextent;
596 hscroll.setValues(x, hextent, 0, width);
597 vscroll.setValues(y, vextent, 0, height);
606 public void adjustmentValueChanged(AdjustmentEvent evt)
609 int oldX = av.getStartRes();
610 int oldY = av.getStartSeq();
612 if (evt.getSource() == hscroll)
614 int x = hscroll.getValue();
616 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
619 if (evt.getSource() == vscroll)
621 int offy = vscroll.getValue();
623 if (av.getWrapAlignment())
627 int rowSize = seqPanel.seqCanvas
628 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
629 av.setStartRes(offy * rowSize);
630 av.setEndRes((offy + 1) * rowSize);
634 // This is only called if file loaded is a jar file that
635 // was wrapped when saved and user has wrap alignment true
636 // as preference setting
637 SwingUtilities.invokeLater(new Runnable()
641 setScrollValues(av.getStartRes(), av.getStartSeq());
648 av.setStartSeq(offy);
650 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
654 if (overviewPanel != null)
656 overviewPanel.setBoxPosition();
659 int scrollX = av.startRes - oldX;
660 int scrollY = av.startSeq - oldY;
662 if (av.getWrapAlignment() || !fastPaint)
668 // Make sure we're not trying to draw a panel
669 // larger than the visible window
670 if (scrollX > av.endRes - av.startRes)
672 scrollX = av.endRes - av.startRes;
674 else if (scrollX < av.startRes - av.endRes)
676 scrollX = av.startRes - av.endRes;
679 if (scrollX != 0 || scrollY != 0)
681 idPanel.idCanvas.fastPaint(scrollY);
682 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
683 scalePanel.repaint();
685 if (av.getShowAnnotation())
687 annotationPanel.fastPaint(scrollX);
693 public void paintAlignment(boolean updateOverview)
699 av.getStructureSelectionManager().sequenceColoursChanged(this);
701 if (overviewPanel != null)
703 overviewPanel.updateOverviewImage();
714 public void paintComponent(Graphics g)
718 Dimension d = idPanel.idCanvas.getPreferredSize();
719 idPanelHolder.setPreferredSize(d);
720 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
723 if (av.getWrapAlignment())
725 int maxwidth = av.getAlignment().getWidth();
727 if (av.hasHiddenColumns())
729 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
732 int canvasWidth = seqPanel.seqCanvas
733 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
738 .getWrappedCanvasWidth(seqPanel.seqCanvas
740 vscroll.setMaximum(max);
741 vscroll.setUnitIncrement(1);
742 vscroll.setVisibleAmount(1);
747 setScrollValues(av.getStartRes(), av.getStartSeq());
761 * @return DOCUMENT ME!
763 * @throws PrinterException
766 public int print(Graphics pg, PageFormat pf, int pi)
767 throws PrinterException
769 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
771 int pwidth = (int) pf.getImageableWidth();
772 int pheight = (int) pf.getImageableHeight();
774 if (av.getWrapAlignment())
776 return printWrappedAlignment(pg, pwidth, pheight, pi);
780 return printUnwrapped(pg, pwidth, pheight, pi);
796 * @return DOCUMENT ME!
798 * @throws PrinterException
801 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
802 throws PrinterException
804 int idWidth = getVisibleIdWidth(false);
805 FontMetrics fm = getFontMetrics(av.getFont());
806 int scaleHeight = av.charHeight + fm.getDescent();
808 pg.setColor(Color.white);
809 pg.fillRect(0, 0, pwidth, pheight);
810 pg.setFont(av.getFont());
812 // //////////////////////////////////
813 // / How many sequences and residues can we fit on a printable page?
814 int totalRes = (pwidth - idWidth) / av.getCharWidth();
816 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
818 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
820 // ///////////////////////////
821 // / Only print these sequences and residues on this page
824 // ///////////////////////////
825 // / Only print these sequences and residues on this page
828 // ///////////////////////////
829 // / Only print these sequences and residues on this page
832 // ///////////////////////////
833 // / Only print these sequences and residues on this page
835 startRes = (pi % pagesWide) * totalRes;
836 endRes = (startRes + totalRes) - 1;
838 if (endRes > (av.getAlignment().getWidth() - 1))
840 endRes = av.getAlignment().getWidth() - 1;
843 startSeq = (pi / pagesWide) * totalSeq;
844 endSeq = startSeq + totalSeq;
846 if (endSeq > av.getAlignment().getHeight())
848 endSeq = av.getAlignment().getHeight();
851 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1) * pheight;
853 if (av.showAnnotation)
855 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
858 pagesHigh /= pheight;
860 if (pi >= (pagesWide * pagesHigh))
862 return Printable.NO_SUCH_PAGE;
866 pg.translate(idWidth, 0);
867 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
869 pg.translate(-idWidth, scaleHeight);
873 Color currentColor = null;
874 Color currentTextColor = null;
876 pg.setFont(idPanel.idCanvas.idfont);
879 for (int i = startSeq; i < endSeq; i++)
881 seq = av.getAlignment().getSequenceAt(i);
882 if ((av.getSelectionGroup() != null)
883 && av.getSelectionGroup().getSequences(null).contains(seq))
885 currentColor = Color.gray;
886 currentTextColor = Color.black;
890 currentColor = av.getSequenceColour(seq);
891 currentTextColor = Color.black;
894 pg.setColor(currentColor);
895 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
898 pg.setColor(currentTextColor);
901 if (av.rightAlignIds)
903 fm = pg.getFontMetrics();
905 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
910 seq.getDisplayId(av.getShowJVSuffix()),
912 (((i - startSeq) * av.charHeight) + av.getCharHeight())
913 - (av.getCharHeight() / 5));
916 pg.setFont(av.getFont());
918 // draw main sequence panel
919 pg.translate(idWidth, 0);
920 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
922 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
924 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
925 alabels.drawComponent((Graphics2D) pg, idWidth);
926 pg.translate(idWidth + 3, 0);
927 annotationPanel.renderer.drawComponent(annotationPanel, av, (Graphics2D) pg, -1, startRes, endRes + 1);
930 return Printable.PAGE_EXISTS;
945 * @return DOCUMENT ME!
947 * @throws PrinterException
950 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
951 int pi) throws PrinterException
954 int annotationHeight = 0;
955 AnnotationLabels labels = null;
956 if (av.showAnnotation)
958 annotationHeight = annotationPanel.adjustPanelHeight();
959 labels = new AnnotationLabels(av);
962 int hgap = av.charHeight;
963 if (av.scaleAboveWrapped)
965 hgap += av.charHeight;
968 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
971 int idWidth = getVisibleIdWidth(false);
973 int maxwidth = av.getAlignment().getWidth();
974 if (av.hasHiddenColumns())
976 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
979 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
982 int totalHeight = cHeight * (maxwidth / resWidth + 1);
984 pg.setColor(Color.white);
985 pg.fillRect(0, 0, pwidth, pheight);
986 pg.setFont(av.getFont());
990 pg.setColor(Color.black);
992 pg.translate(0, -pi * pheight);
994 pg.setClip(0, pi * pheight, pwidth, pheight);
1000 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1002 pg.setFont(idPanel.idCanvas.idfont);
1003 SequenceI s = av.getAlignment().getSequenceAt(i);
1004 String string = s.getDisplayId(av.getShowJVSuffix());
1006 if (av.rightAlignIds)
1008 FontMetrics fm = pg.getFontMetrics();
1009 xPos = idWidth - fm.stringWidth(string) - 4;
1011 pg.drawString(string, xPos,
1012 ((i * av.charHeight) + ypos + av.charHeight)
1013 - (av.charHeight / 5));
1017 pg.translate(-3, ypos
1018 + (av.getAlignment().getHeight() * av.charHeight));
1020 pg.setFont(av.getFont());
1021 labels.drawComponent(pg, idWidth);
1022 pg.translate(+3, -ypos
1023 - (av.getAlignment().getHeight() * av.charHeight));
1027 } while (ypos < totalHeight);
1029 pg.translate(idWidth, 0);
1031 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1034 if ((pi * pheight) < totalHeight)
1036 return Printable.PAGE_EXISTS;
1041 return Printable.NO_SUCH_PAGE;
1045 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1048 int getVisibleIdWidth()
1050 return getVisibleIdWidth(true);
1054 * get current sequence ID panel width, or nominal value if panel were to be displayed using default settings
1055 * @param onscreen indicate if the Id width for onscreen or offscreen display should be returned
1058 int getVisibleIdWidth(boolean onscreen)
1060 // see if rendering offscreen - check preferences and calc width accordingly
1061 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1063 return calculateIdWidth(-1).width+4;
1065 Integer idwidth=null;
1066 if (onscreen || (idwidth=Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH"))==null) {
1067 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1068 : calculateIdWidth().width + 4);
1070 return idwidth.intValue()+4;
1073 void makeAlignmentImage(int type, File file)
1075 int maxwidth = av.getAlignment().getWidth();
1076 if (av.hasHiddenColumns())
1078 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1081 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1082 + scalePanel.getHeight();
1083 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1085 if (av.getWrapAlignment())
1087 height = getWrappedHeight();
1088 if (System.getProperty("java.awt.headless") != null
1089 && System.getProperty("java.awt.headless").equals("true"))
1091 // need to obtain default alignment width and then add in any additional allowance for id margin
1092 // this duplicates the calculation in getWrappedHeight but adjusts for offscreen idWith
1093 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1094 - alignFrame.getInsets().left
1095 - alignFrame.getInsets().right
1096 - getVisibleIdWidth()+getVisibleIdWidth(false);
1100 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1104 else if (av.getShowAnnotation())
1106 height += annotationPanel.adjustPanelHeight() + 3;
1112 jalview.util.ImageMaker im;
1113 if (type == jalview.util.ImageMaker.PNG)
1115 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
1116 "Create PNG image from alignment", width, height, file,
1121 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
1122 "Create EPS file from alignment", width, height, file,
1123 alignFrame.getTitle());
1126 if (av.getWrapAlignment())
1128 if (im.getGraphics() != null)
1130 printWrappedAlignment(im.getGraphics(), width, height, 0);
1136 if (im.getGraphics() != null)
1138 printUnwrapped(im.getGraphics(), width, height, 0);
1142 } catch (OutOfMemoryError err)
1145 System.out.println("########################\n" + "OUT OF MEMORY "
1146 + file + "\n" + "########################");
1147 new OOMWarning("Creating Image for " + file, err);
1148 // System.out.println("Create IMAGE: " + err);
1149 } catch (Exception ex)
1151 ex.printStackTrace();
1158 public void makeEPS(File epsFile)
1160 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1166 public void makePNG(File pngFile)
1168 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1171 public void makePNGImageMap(File imgMapFile, String imageName)
1173 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1174 // ////////////////////////////////////////////
1175 int idWidth = getVisibleIdWidth(false);
1176 FontMetrics fm = getFontMetrics(av.getFont());
1177 int scaleHeight = av.charHeight + fm.getDescent();
1180 // ////////////////////////////////
1181 if (imgMapFile != null)
1185 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av.getAlignment()
1186 .getWidth(), g, gSize, f, fSize, sy;
1187 StringBuffer text = new StringBuffer();
1188 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1189 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1190 out.println("<img src=\"" + imageName
1191 + "\" border=\"0\" usemap=\"#Map\" >"
1192 + "<map name=\"Map\">");
1194 for (s = 0; s < sSize; s++)
1196 sy = s * av.charHeight + scaleHeight;
1198 SequenceI seq = av.getAlignment().getSequenceAt(s);
1199 SequenceFeature[] features = seq.getDatasetSequence()
1200 .getSequenceFeatures();
1201 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1202 for (res = 0; res < alwidth; res++)
1204 text = new StringBuffer();
1206 if (av.getAlignment().isNucleotide())
1208 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1213 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1222 String triplet = obj.toString();
1223 int alIndex = seq.findPosition(res);
1224 gSize = groups.length;
1225 for (g = 0; g < gSize; g++)
1227 if (text.length() < 1)
1229 text.append("<area shape=\"rect\" coords=\""
1230 + (idWidth + res * av.charWidth) + "," + sy + ","
1231 + (idWidth + (res + 1) * av.charWidth) + ","
1232 + (av.charHeight + sy) + "\""
1233 + " onMouseOver=\"toolTip('" + alIndex + " "
1237 if (groups[g].getStartRes() < res
1238 && groups[g].getEndRes() > res)
1240 text.append("<br><em>" + groups[g].getName() + "</em>");
1244 if (features != null)
1246 if (text.length() < 1)
1248 text.append("<area shape=\"rect\" coords=\""
1249 + (idWidth + res * av.charWidth) + "," + sy + ","
1250 + (idWidth + (res + 1) * av.charWidth) + ","
1251 + (av.charHeight + sy) + "\""
1252 + " onMouseOver=\"toolTip('" + alIndex + " "
1255 fSize = features.length;
1256 for (f = 0; f < fSize; f++)
1259 if ((features[f].getBegin() <= seq.findPosition(res))
1260 && (features[f].getEnd() >= seq.findPosition(res)))
1262 if (features[f].getType().equals("disulfide bond"))
1264 if (features[f].getBegin() == seq.findPosition(res)
1265 || features[f].getEnd() == seq
1268 text.append("<br>disulfide bond "
1269 + features[f].getBegin() + ":"
1270 + features[f].getEnd());
1275 text.append("<br>");
1276 text.append(features[f].getType());
1277 if (features[f].getDescription() != null
1278 && !features[f].getType().equals(
1279 features[f].getDescription()))
1281 text.append(" " + features[f].getDescription());
1284 if (features[f].getValue("status") != null)
1286 text.append(" (" + features[f].getValue("status")
1294 if (text.length() > 1)
1296 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1297 out.println(text.toString());
1301 out.println("</map></body></html>");
1304 } catch (Exception ex)
1306 ex.printStackTrace();
1308 } // /////////END OF IMAGE MAP
1312 int getWrappedHeight()
1314 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1316 if (System.getProperty("java.awt.headless") != null
1317 && System.getProperty("java.awt.headless").equals("true"))
1319 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1320 - vscroll.getPreferredSize().width
1321 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1324 int chunkWidth = seqPanel.seqCanvas
1325 .getWrappedCanvasWidth(seqPanelWidth);
1327 int hgap = av.charHeight;
1328 if (av.scaleAboveWrapped)
1330 hgap += av.charHeight;
1333 int annotationHeight = 0;
1334 if (av.showAnnotation)
1336 annotationHeight = annotationPanel.adjustPanelHeight();
1339 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1342 int maxwidth = av.getAlignment().getWidth();
1343 if (av.hasHiddenColumns())
1345 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1348 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1354 * close the panel - deregisters all listeners and nulls any references to
1357 public void closePanel()
1359 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1360 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1361 PaintRefresher.RemoveComponent(this);
1364 jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager();
1365 ssm.removeStructureViewerListener(seqPanel, null);
1366 ssm.removeSelectionListener(seqPanel);
1367 av.setAlignment(null);
1372 if (Cache.log.isDebugEnabled())
1374 Cache.log.warn("Closing alignment panel which is already closed.");
1380 * hides or shows dynamic annotation rows based on groups and av state flags
1382 public void updateAnnotation()
1384 updateAnnotation(false);
1387 public void updateAnnotation(boolean applyGlobalSettings)
1389 // TODO: this should be merged with other annotation update stuff - that
1390 // sits on AlignViewport
1391 boolean updateCalcs = false;
1392 boolean conv = av.isShowGroupConservation();
1393 boolean cons = av.isShowGroupConsensus();
1394 boolean showprf = av.isShowSequenceLogo();
1395 boolean showConsHist = av.isShowConsensusHistogram();
1396 boolean normLogo = av.isNormaliseSequenceLogo();
1398 boolean sortg = true;
1400 // remove old automatic annotation
1401 // add any new annotation
1403 Vector gr = av.getAlignment().getGroups(); // OrderedBy(av.getAlignment().getSequencesArray());
1404 // intersect alignment annotation with alignment groups
1406 AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation();
1407 Hashtable oldrfs = new Hashtable();
1410 for (int an = 0; an < aan.length; an++)
1412 if (aan[an].autoCalculated && aan[an].groupRef != null)
1414 oldrfs.put(aan[an].groupRef, aan[an].groupRef);
1415 av.getAlignment().deleteAnnotation(aan[an]);
1423 for (int g = 0; g < gr.size(); g++)
1425 updateCalcs = false;
1426 sg = (SequenceGroup) gr.elementAt(g);
1427 if (applyGlobalSettings || !oldrfs.containsKey(sg))
1429 // set defaults for this group's conservation/consensus
1430 sg.setshowSequenceLogo(showprf);
1431 sg.setShowConsensusHistogram(showConsHist);
1432 sg.setNormaliseSequenceLogo(normLogo);
1437 av.getAlignment().addAnnotation(sg.getConservationRow(), 0);
1442 av.getAlignment().addAnnotation(sg.getConsensus(), 0);
1444 // refresh the annotation rows
1447 sg.recalcConservation();
1452 adjustAnnotationHeight();
1456 public AlignmentI getAlignment()
1458 return av.getAlignment();
1462 * get the name for this view
1465 public String getViewName()
1471 * Make/Unmake this alignment panel the current input focus
1474 public void setSelected(boolean b)
1477 alignFrame.setSelected(b);
1478 } catch (Exception ex) {};
1482 alignFrame.setDisplayedView(this);
1487 public StructureSelectionManager getStructureSelectionManager()
1489 return av.getStructureSelectionManager();
1493 public void raiseOOMWarning(String string, OutOfMemoryError error)
1495 new OOMWarning(string, error, this);