2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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/>.
24 import java.awt.event.*;
25 import java.awt.print.*;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.bin.Cache;
30 import jalview.datamodel.*;
31 import jalview.jbgui.*;
32 import jalview.schemes.*;
33 import jalview.structure.StructureSelectionManager;
39 * @version $Revision: 1.161 $
41 public class AlignmentPanel extends GAlignmentPanel implements
42 AdjustmentListener, Printable, AlignmentViewPanel
44 public AlignViewport av;
46 OverviewPanel overviewPanel;
52 IdwidthAdjuster idwidthAdjuster;
55 public AlignFrame alignFrame;
57 ScalePanel scalePanel;
59 AnnotationPanel annotationPanel;
61 AnnotationLabels alabels;
63 // this value is set false when selection area being dragged
64 boolean fastPaint = true;
71 * Creates a new AlignmentPanel object.
78 public AlignmentPanel(AlignFrame af, final AlignViewport av)
82 seqPanel = new SeqPanel(av, this);
83 idPanel = new IdPanel(av, this);
85 scalePanel = new ScalePanel(av, this);
87 idPanelHolder.add(idPanel, BorderLayout.CENTER);
88 idwidthAdjuster = new IdwidthAdjuster(this);
89 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
91 annotationPanel = new AnnotationPanel(this);
92 alabels = new AnnotationLabels(this);
94 annotationScroller.setViewportView(annotationPanel);
95 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
97 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
98 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
100 setScrollValues(0, 0);
102 setAnnotationVisible(av.getShowAnnotation());
104 hscroll.addAdjustmentListener(this);
105 vscroll.addAdjustmentListener(this);
107 final AlignmentPanel ap = this;
108 av.addPropertyChangeListener(new PropertyChangeListener()
110 public void propertyChange(PropertyChangeEvent evt)
112 if (evt.getPropertyName().equals("alignment"))
114 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
120 adjustAnnotationHeight();
124 public void alignmentChanged()
126 av.alignmentChanged(this);
128 alignFrame.updateEditMenuBar();
130 paintAlignment(true);
137 public void fontChanged()
139 // set idCanvas bufferedImage to null
140 // to prevent drawing old image
141 FontMetrics fm = getFontMetrics(av.getFont());
143 scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight
145 idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight
148 idPanel.idCanvas.gg = null;
149 seqPanel.seqCanvas.img = null;
150 annotationPanel.adjustPanelHeight();
152 Dimension d = calculateIdWidth();
153 d.setSize(d.width + 4, d.height);
154 idPanel.idCanvas.setPreferredSize(d);
155 hscrollFillerPanel.setPreferredSize(d);
157 if (overviewPanel != null)
159 overviewPanel.setBoxPosition();
166 * Calculate the width of the alignment labels based on the displayed names
167 * and any bounds on label width set in preferences.
169 * @return Dimension giving the maximum width of the alignment label panel
170 * that should be used.
172 public Dimension calculateIdWidth()
174 // calculate sensible default width when no preference is available
176 int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
177 int maxwidth = Math.max(20,
178 Math.min(afwidth - 200, (int) 2 * afwidth / 3));
179 return calculateIdWidth(maxwidth);
183 * Calculate the width of the alignment labels based on the displayed names
184 * and any bounds on label width set in preferences.
187 * -1 or maximum width allowed for IdWidth
188 * @return Dimension giving the maximum width of the alignment label panel
189 * that should be used.
191 public Dimension calculateIdWidth(int maxwidth)
193 Container c = new Container();
195 FontMetrics fm = c.getFontMetrics(new Font(av.font.getName(),
196 Font.ITALIC, av.font.getSize()));
198 AlignmentI al = av.getAlignment();
203 while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))
205 SequenceI s = al.getSequenceAt(i);
207 id = s.getDisplayId(av.getShowJVSuffix());
209 if (fm.stringWidth(id) > idWidth)
211 idWidth = fm.stringWidth(id);
217 // Also check annotation label widths
220 if (al.getAlignmentAnnotation() != null)
222 fm = c.getFontMetrics(alabels.getFont());
224 while (i < al.getAlignmentAnnotation().length)
226 String label = al.getAlignmentAnnotation()[i].label;
228 if (fm.stringWidth(label) > idWidth)
230 idWidth = fm.stringWidth(label);
237 return new Dimension(maxwidth < 0 ? idWidth : Math.min(maxwidth,
242 * Highlight the given results on the alignment.
245 public void highlightSearchResults(SearchResults results)
247 scrollToPosition(results);
248 seqPanel.seqCanvas.highlightSearchResults(results);
252 * scroll the view to show the position of the highlighted region in results
253 * (if any) and redraw the overview
257 public boolean scrollToPosition(SearchResults results)
259 return scrollToPosition(results, true);
263 * scroll the view to show the position of the highlighted region in results
267 * @param redrawOverview
268 * - when set, the overview will be recalculated (takes longer)
269 * @return false if results were not found
271 public boolean scrollToPosition(SearchResults results,
272 boolean redrawOverview)
274 int startv, endv, starts, ends, width;
275 // TODO: properly locate search results in view when large numbers of hidden
276 // columns exist before highlighted region
277 // do we need to scroll the panel?
278 // TODO: tons of nullpointereexceptions raised here.
279 if (results != null && results.getSize() > 0 && av != null
280 && av.getAlignment() != null)
282 int seqIndex = av.getAlignment().findIndex(results);
287 SequenceI seq = av.getAlignment().getSequenceAt(seqIndex);
289 int[] r = results.getResults(seq, 0, av.getAlignment().getWidth());
296 // System.err.println("Seq : "+seqIndex+" Scroll to "+start+","+end); //
302 if (end == seq.getEnd())
306 if (av.hasHiddenColumns())
308 start = av.getColumnSelection().findColumnPosition(start);
309 end = av.getColumnSelection().findColumnPosition(end);
312 if (!av.getColumnSelection().isVisible(r[0]))
314 // don't scroll - position isn't visible
319 if (!av.wrapAlignment)
321 if ((startv = av.getStartRes()) >= start)
323 setScrollValues(start - 1, seqIndex);
325 else if ((endv = av.getEndRes()) <= end)
327 setScrollValues(startv + 1 + end - endv, seqIndex);
329 else if ((starts = av.getStartSeq()) > seqIndex)
331 setScrollValues(av.getStartRes(), seqIndex);
333 else if ((ends = av.getEndSeq()) <= seqIndex)
335 setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1);
340 scrollToWrappedVisible(start);
343 if (redrawOverview && overviewPanel != null)
345 overviewPanel.setBoxPosition();
347 paintAlignment(redrawOverview);
351 void scrollToWrappedVisible(int res)
353 int cwidth = seqPanel.seqCanvas
354 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
355 if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth))
357 vscroll.setValue((res / cwidth));
358 av.startRes = vscroll.getValue() * cwidth;
366 * @return DOCUMENT ME!
368 public OverviewPanel getOverviewPanel()
370 return overviewPanel;
379 public void setOverviewPanel(OverviewPanel op)
387 * Hide or show annotation panel
390 public void setAnnotationVisible(boolean b)
392 if (!av.wrapAlignment)
394 annotationSpaceFillerHolder.setVisible(b);
395 annotationScroller.setVisible(b);
401 * automatically adjust annotation panel height for new annotation whilst
402 * ensuring the alignment is still visible.
404 public void adjustAnnotationHeight()
406 // TODO: display vertical annotation scrollbar if necessary
407 // this is called after loading new annotation onto alignment
408 if (alignFrame.getHeight() == 0)
410 System.out.println("NEEDS FIXING");
412 validateAnnotationDimensions(true);
414 paintAlignment(true);
418 * calculate the annotation dimensions and refresh slider values accordingly.
419 * need to do repaints/notifys afterwards.
421 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
423 int height = annotationPanel.adjustPanelHeight();
425 if (hscroll.isVisible())
427 height += hscroll.getPreferredSize().height;
429 if (height > alignFrame.getHeight() / 2)
431 height = alignFrame.getHeight() / 2;
433 if (!adjustPanelHeight)
435 // maintain same window layout whilst updating sliders
436 height = annotationScroller.getSize().height;
440 annotationScroller.setPreferredSize(new Dimension(annotationScroller
441 .getWidth(), height));
443 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
444 annotationSpaceFillerHolder.getWidth(), height));
445 annotationScroller.validate();// repaint();
446 annotationScroller.addNotify();
455 public void setWrapAlignment(boolean wrap)
458 scalePanelHolder.setVisible(!wrap);
459 hscroll.setVisible(!wrap);
460 idwidthAdjuster.setVisible(!wrap);
464 annotationScroller.setVisible(false);
465 annotationSpaceFillerHolder.setVisible(false);
467 else if (av.showAnnotation)
469 annotationScroller.setVisible(true);
470 annotationSpaceFillerHolder.setVisible(true);
473 idSpaceFillerPanel1.setVisible(!wrap);
478 // return value is true if the scroll is valid
479 public boolean scrollUp(boolean up)
483 if (vscroll.getValue() < 1)
489 vscroll.setValue(vscroll.getValue() - 1);
493 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
499 vscroll.setValue(vscroll.getValue() + 1);
513 * @return DOCUMENT ME!
515 public boolean scrollRight(boolean right)
519 if (hscroll.getValue() < 1)
525 hscroll.setValue(hscroll.getValue() - 1);
529 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
535 hscroll.setValue(hscroll.getValue() + 1);
544 * Adjust row/column scrollers to show a visible position in the alignment.
547 * visible column to scroll to DOCUMENT ME!
549 * visible row to scroll to
552 public void setScrollValues(int x, int y)
554 // System.err.println("Scroll to "+x+","+y);
555 if (av == null || av.getAlignment() == null)
559 int width = av.getAlignment().getWidth();
560 int height = av.getAlignment().getHeight();
562 if (av.hasHiddenColumns())
564 width = av.getColumnSelection().findColumnPosition(width);
567 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
569 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
570 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
577 if (vextent > height)
582 if ((hextent + x) > width)
587 if ((vextent + y) > height)
589 y = height - vextent;
602 hscroll.setValues(x, hextent, 0, width);
603 vscroll.setValues(y, vextent, 0, height);
612 public void adjustmentValueChanged(AdjustmentEvent evt)
615 int oldX = av.getStartRes();
616 int oldY = av.getStartSeq();
618 if (evt.getSource() == hscroll)
620 int x = hscroll.getValue();
622 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
625 if (evt.getSource() == vscroll)
627 int offy = vscroll.getValue();
629 if (av.getWrapAlignment())
633 int rowSize = seqPanel.seqCanvas
634 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
635 av.setStartRes(offy * rowSize);
636 av.setEndRes((offy + 1) * rowSize);
640 // This is only called if file loaded is a jar file that
641 // was wrapped when saved and user has wrap alignment true
642 // as preference setting
643 SwingUtilities.invokeLater(new Runnable()
647 setScrollValues(av.getStartRes(), av.getStartSeq());
654 av.setStartSeq(offy);
656 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
660 if (overviewPanel != null)
662 overviewPanel.setBoxPosition();
665 int scrollX = av.startRes - oldX;
666 int scrollY = av.startSeq - oldY;
668 if (av.getWrapAlignment() || !fastPaint)
674 // Make sure we're not trying to draw a panel
675 // larger than the visible window
676 if (scrollX > av.endRes - av.startRes)
678 scrollX = av.endRes - av.startRes;
680 else if (scrollX < av.startRes - av.endRes)
682 scrollX = av.startRes - av.endRes;
685 if (scrollX != 0 || scrollY != 0)
687 idPanel.idCanvas.fastPaint(scrollY);
688 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
689 scalePanel.repaint();
691 if (av.getShowAnnotation() && scrollX!=0)
693 annotationPanel.fastPaint(scrollX);
699 public void paintAlignment(boolean updateOverview)
705 av.getStructureSelectionManager().sequenceColoursChanged(this);
707 if (overviewPanel != null)
709 overviewPanel.updateOverviewImage();
720 public void paintComponent(Graphics g)
724 Dimension d = idPanel.idCanvas.getPreferredSize();
725 idPanelHolder.setPreferredSize(d);
726 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
729 if (av.getWrapAlignment())
731 int maxwidth = av.getAlignment().getWidth();
733 if (av.hasHiddenColumns())
735 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
738 int canvasWidth = seqPanel.seqCanvas
739 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
744 .getWrappedCanvasWidth(seqPanel.seqCanvas
746 vscroll.setMaximum(max);
747 vscroll.setUnitIncrement(1);
748 vscroll.setVisibleAmount(1);
753 setScrollValues(av.getStartRes(), av.getStartSeq());
767 * @return DOCUMENT ME!
769 * @throws PrinterException
772 public int print(Graphics pg, PageFormat pf, int pi)
773 throws PrinterException
775 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
777 int pwidth = (int) pf.getImageableWidth();
778 int pheight = (int) pf.getImageableHeight();
780 if (av.getWrapAlignment())
782 return printWrappedAlignment(pg, pwidth, pheight, pi);
786 return printUnwrapped(pg, pwidth, pheight, pi);
802 * @return DOCUMENT ME!
804 * @throws PrinterException
807 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
808 throws PrinterException
810 int idWidth = getVisibleIdWidth(false);
811 FontMetrics fm = getFontMetrics(av.getFont());
812 int scaleHeight = av.charHeight + fm.getDescent();
814 pg.setColor(Color.white);
815 pg.fillRect(0, 0, pwidth, pheight);
816 pg.setFont(av.getFont());
818 // //////////////////////////////////
819 // / How many sequences and residues can we fit on a printable page?
820 int totalRes = (pwidth - idWidth) / av.getCharWidth();
822 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
824 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
826 // ///////////////////////////
827 // / Only print these sequences and residues on this page
830 // ///////////////////////////
831 // / Only print these sequences and residues on this page
834 // ///////////////////////////
835 // / Only print these sequences and residues on this page
838 // ///////////////////////////
839 // / Only print these sequences and residues on this page
841 startRes = (pi % pagesWide) * totalRes;
842 endRes = (startRes + totalRes) - 1;
844 if (endRes > (av.getAlignment().getWidth() - 1))
846 endRes = av.getAlignment().getWidth() - 1;
849 startSeq = (pi / pagesWide) * totalSeq;
850 endSeq = startSeq + totalSeq;
852 if (endSeq > av.getAlignment().getHeight())
854 endSeq = av.getAlignment().getHeight();
857 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
860 if (av.showAnnotation)
862 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
865 pagesHigh /= pheight;
867 if (pi >= (pagesWide * pagesHigh))
869 return Printable.NO_SUCH_PAGE;
873 pg.translate(idWidth, 0);
874 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
876 pg.translate(-idWidth, scaleHeight);
880 Color currentColor = null;
881 Color currentTextColor = null;
883 pg.setFont(idPanel.idCanvas.idfont);
886 for (int i = startSeq; i < endSeq; i++)
888 seq = av.getAlignment().getSequenceAt(i);
889 if ((av.getSelectionGroup() != null)
890 && av.getSelectionGroup().getSequences(null).contains(seq))
892 currentColor = Color.gray;
893 currentTextColor = Color.black;
897 currentColor = av.getSequenceColour(seq);
898 currentTextColor = Color.black;
901 pg.setColor(currentColor);
902 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
905 pg.setColor(currentTextColor);
908 if (av.rightAlignIds)
910 fm = pg.getFontMetrics();
912 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
917 seq.getDisplayId(av.getShowJVSuffix()),
919 (((i - startSeq) * av.charHeight) + av.getCharHeight())
920 - (av.getCharHeight() / 5));
923 pg.setFont(av.getFont());
925 // draw main sequence panel
926 pg.translate(idWidth, 0);
927 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
929 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
931 // draw annotation - need to offset for current scroll position
932 int offset = -alabels.scrollOffset;
933 pg.translate(0, offset);
934 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
935 alabels.drawComponent((Graphics2D) pg, idWidth);
936 pg.translate(idWidth + 3, 0);
937 annotationPanel.renderer.drawComponent(annotationPanel, av,
938 (Graphics2D) pg, -1, startRes, endRes + 1);
939 pg.translate(0, -offset);
942 return Printable.PAGE_EXISTS;
957 * @return DOCUMENT ME!
959 * @throws PrinterException
962 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
963 int pi) throws PrinterException
966 int annotationHeight = 0;
967 AnnotationLabels labels = null;
968 if (av.showAnnotation)
970 annotationHeight = annotationPanel.adjustPanelHeight();
971 labels = new AnnotationLabels(av);
974 int hgap = av.charHeight;
975 if (av.scaleAboveWrapped)
977 hgap += av.charHeight;
980 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
983 int idWidth = getVisibleIdWidth(false);
985 int maxwidth = av.getAlignment().getWidth();
986 if (av.hasHiddenColumns())
988 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
991 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
994 int totalHeight = cHeight * (maxwidth / resWidth + 1);
996 pg.setColor(Color.white);
997 pg.fillRect(0, 0, pwidth, pheight);
998 pg.setFont(av.getFont());
1002 pg.setColor(Color.black);
1004 pg.translate(0, -pi * pheight);
1006 pg.setClip(0, pi * pheight, pwidth, pheight);
1012 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1014 pg.setFont(idPanel.idCanvas.idfont);
1015 SequenceI s = av.getAlignment().getSequenceAt(i);
1016 String string = s.getDisplayId(av.getShowJVSuffix());
1018 if (av.rightAlignIds)
1020 FontMetrics fm = pg.getFontMetrics();
1021 xPos = idWidth - fm.stringWidth(string) - 4;
1023 pg.drawString(string, xPos,
1024 ((i * av.charHeight) + ypos + av.charHeight)
1025 - (av.charHeight / 5));
1029 pg.translate(-3, ypos
1030 + (av.getAlignment().getHeight() * av.charHeight));
1032 pg.setFont(av.getFont());
1033 labels.drawComponent(pg, idWidth);
1034 pg.translate(+3, -ypos
1035 - (av.getAlignment().getHeight() * av.charHeight));
1039 } while (ypos < totalHeight);
1041 pg.translate(idWidth, 0);
1043 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1046 if ((pi * pheight) < totalHeight)
1048 return Printable.PAGE_EXISTS;
1053 return Printable.NO_SUCH_PAGE;
1058 * get current sequence ID panel width, or nominal value if panel were to be
1059 * displayed using default settings
1063 int getVisibleIdWidth()
1065 return getVisibleIdWidth(true);
1069 * get current sequence ID panel width, or nominal value if panel were to be
1070 * displayed using default settings
1073 * indicate if the Id width for onscreen or offscreen display should
1077 int getVisibleIdWidth(boolean onscreen)
1079 // see if rendering offscreen - check preferences and calc width accordingly
1080 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1082 return calculateIdWidth(-1).width + 4;
1084 Integer idwidth = null;
1086 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1088 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1089 : calculateIdWidth().width + 4);
1091 return idwidth.intValue() + 4;
1094 void makeAlignmentImage(int type, File file)
1096 long progress = System.currentTimeMillis();
1097 boolean headless = (System.getProperty("java.awt.headless") != null
1098 && System.getProperty("java.awt.headless").equals("true"));
1099 if (alignFrame != null && !headless)
1101 alignFrame.setProgressBar("Saving "
1102 + (type == jalview.util.ImageMaker.PNG ? "PNG image"
1103 : "EPS file"), progress);
1107 int maxwidth = av.getAlignment().getWidth();
1108 if (av.hasHiddenColumns())
1110 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1113 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1114 + scalePanel.getHeight();
1115 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1117 if (av.getWrapAlignment())
1119 height = getWrappedHeight();
1122 // need to obtain default alignment width and then add in any
1123 // additional allowance for id margin
1124 // this duplicates the calculation in getWrappedHeight but adjusts for
1126 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1127 - alignFrame.getInsets().left
1128 - alignFrame.getInsets().right - getVisibleIdWidth()
1129 + getVisibleIdWidth(false);
1133 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1137 else if (av.getShowAnnotation())
1139 height += annotationPanel.adjustPanelHeight() + 3;
1145 jalview.util.ImageMaker im;
1146 final String imageAction, imageTitle;
1147 if (type == jalview.util.ImageMaker.PNG)
1149 imageAction = "Create PNG image from alignment";
1154 imageAction = "Create EPS file from alignment";
1155 imageTitle = alignFrame.getTitle();
1157 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1158 height, file, imageTitle);
1159 if (av.getWrapAlignment())
1161 if (im.getGraphics() != null)
1163 printWrappedAlignment(im.getGraphics(), width, height, 0);
1169 if (im.getGraphics() != null)
1171 printUnwrapped(im.getGraphics(), width, height, 0);
1175 } catch (OutOfMemoryError err)
1178 System.out.println("########################\n" + "OUT OF MEMORY "
1179 + file + "\n" + "########################");
1180 new OOMWarning("Creating Image for " + file, err);
1181 // System.out.println("Create IMAGE: " + err);
1182 } catch (Exception ex)
1184 ex.printStackTrace();
1188 if (alignFrame != null && !headless)
1190 alignFrame.setProgressBar("Export complete.", progress);
1198 public void makeEPS(File epsFile)
1200 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1206 public void makePNG(File pngFile)
1208 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1211 public void makePNGImageMap(File imgMapFile, String imageName)
1213 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1214 // ////////////////////////////////////////////
1215 int idWidth = getVisibleIdWidth(false);
1216 FontMetrics fm = getFontMetrics(av.getFont());
1217 int scaleHeight = av.charHeight + fm.getDescent();
1220 // ////////////////////////////////
1221 if (imgMapFile != null)
1225 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1226 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1227 StringBuffer text = new StringBuffer();
1228 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1229 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1230 out.println("<img src=\"" + imageName
1231 + "\" border=\"0\" usemap=\"#Map\" >"
1232 + "<map name=\"Map\">");
1234 for (s = 0; s < sSize; s++)
1236 sy = s * av.charHeight + scaleHeight;
1238 SequenceI seq = av.getAlignment().getSequenceAt(s);
1239 SequenceFeature[] features = seq.getDatasetSequence()
1240 .getSequenceFeatures();
1241 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1242 for (res = 0; res < alwidth; res++)
1244 text = new StringBuffer();
1246 if (av.getAlignment().isNucleotide())
1248 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1253 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1262 String triplet = obj.toString();
1263 int alIndex = seq.findPosition(res);
1264 gSize = groups.length;
1265 for (g = 0; g < gSize; g++)
1267 if (text.length() < 1)
1269 text.append("<area shape=\"rect\" coords=\""
1270 + (idWidth + res * av.charWidth) + "," + sy + ","
1271 + (idWidth + (res + 1) * av.charWidth) + ","
1272 + (av.charHeight + sy) + "\""
1273 + " onMouseOver=\"toolTip('" + alIndex + " "
1277 if (groups[g].getStartRes() < res
1278 && groups[g].getEndRes() > res)
1280 text.append("<br><em>" + groups[g].getName() + "</em>");
1284 if (features != null)
1286 if (text.length() < 1)
1288 text.append("<area shape=\"rect\" coords=\""
1289 + (idWidth + res * av.charWidth) + "," + sy + ","
1290 + (idWidth + (res + 1) * av.charWidth) + ","
1291 + (av.charHeight + sy) + "\""
1292 + " onMouseOver=\"toolTip('" + alIndex + " "
1295 fSize = features.length;
1296 for (f = 0; f < fSize; f++)
1299 if ((features[f].getBegin() <= seq.findPosition(res))
1300 && (features[f].getEnd() >= seq.findPosition(res)))
1302 if (features[f].getType().equals("disulfide bond"))
1304 if (features[f].getBegin() == seq.findPosition(res)
1305 || features[f].getEnd() == seq
1308 text.append("<br>disulfide bond "
1309 + features[f].getBegin() + ":"
1310 + features[f].getEnd());
1315 text.append("<br>");
1316 text.append(features[f].getType());
1317 if (features[f].getDescription() != null
1318 && !features[f].getType().equals(
1319 features[f].getDescription()))
1321 text.append(" " + features[f].getDescription());
1324 if (features[f].getValue("status") != null)
1326 text.append(" (" + features[f].getValue("status")
1334 if (text.length() > 1)
1336 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1337 out.println(text.toString());
1341 out.println("</map></body></html>");
1344 } catch (Exception ex)
1346 ex.printStackTrace();
1348 } // /////////END OF IMAGE MAP
1352 int getWrappedHeight()
1354 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1356 if (System.getProperty("java.awt.headless") != null
1357 && System.getProperty("java.awt.headless").equals("true"))
1359 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1360 - vscroll.getPreferredSize().width
1361 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1364 int chunkWidth = seqPanel.seqCanvas
1365 .getWrappedCanvasWidth(seqPanelWidth);
1367 int hgap = av.charHeight;
1368 if (av.scaleAboveWrapped)
1370 hgap += av.charHeight;
1373 int annotationHeight = 0;
1374 if (av.showAnnotation)
1376 annotationHeight = annotationPanel.adjustPanelHeight();
1379 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1382 int maxwidth = av.getAlignment().getWidth();
1383 if (av.hasHiddenColumns())
1385 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1388 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1394 * close the panel - deregisters all listeners and nulls any references to
1397 public void closePanel()
1399 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1400 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1401 PaintRefresher.RemoveComponent(this);
1404 jalview.structure.StructureSelectionManager ssm = av
1405 .getStructureSelectionManager();
1406 ssm.removeStructureViewerListener(seqPanel, null);
1407 ssm.removeSelectionListener(seqPanel);
1408 av.setAlignment(null);
1413 if (Cache.log.isDebugEnabled())
1415 Cache.log.warn("Closing alignment panel which is already closed.");
1421 * hides or shows dynamic annotation rows based on groups and av state flags
1423 public void updateAnnotation()
1425 updateAnnotation(false, false);
1428 public void updateAnnotation(boolean applyGlobalSettings)
1430 updateAnnotation(applyGlobalSettings, false);
1433 public void updateAnnotation(boolean applyGlobalSettings,
1434 boolean preserveNewGroupSettings)
1436 av.updateGroupAnnotationSettings(applyGlobalSettings,
1437 preserveNewGroupSettings);
1438 adjustAnnotationHeight();
1442 public AlignmentI getAlignment()
1444 return av.getAlignment();
1448 * get the name for this view
1452 public String getViewName()
1458 * Make/Unmake this alignment panel the current input focus
1462 public void setSelected(boolean b)
1466 alignFrame.setSelected(b);
1467 } catch (Exception ex)
1474 alignFrame.setDisplayedView(this);
1479 public StructureSelectionManager getStructureSelectionManager()
1481 return av.getStructureSelectionManager();
1485 public void raiseOOMWarning(String string, OutOfMemoryError error)
1487 new OOMWarning(string, error, this);
1490 public FeatureRenderer cloneFeatureRenderer()
1493 return new FeatureRenderer(this);
1496 public void updateFeatureRenderer(FeatureRenderer fr)
1498 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1501 public void updateFeatureRendererFrom(FeatureRenderer fr)
1503 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1505 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);