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 if (hscroll.isVisible())
428 height += hscroll.getPreferredSize().height;
430 if (height > alignFrame.getHeight() / 2)
432 height = alignFrame.getHeight() / 2;
434 if (!adjustPanelHeight)
436 // maintain same window layout whilst updating sliders
437 height = annotationScroller.getSize().height;
441 annotationScroller.setPreferredSize(new Dimension(annotationScroller
442 .getWidth(), height));
444 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
445 annotationSpaceFillerHolder.getWidth(), height));
446 annotationScroller.validate();// repaint();
447 annotationScroller.addNotify();
456 public void setWrapAlignment(boolean wrap)
459 scalePanelHolder.setVisible(!wrap);
460 hscroll.setVisible(!wrap);
461 idwidthAdjuster.setVisible(!wrap);
465 annotationScroller.setVisible(false);
466 annotationSpaceFillerHolder.setVisible(false);
468 else if (av.showAnnotation)
470 annotationScroller.setVisible(true);
471 annotationSpaceFillerHolder.setVisible(true);
474 idSpaceFillerPanel1.setVisible(!wrap);
479 // return value is true if the scroll is valid
480 public boolean scrollUp(boolean up)
484 if (vscroll.getValue() < 1)
490 vscroll.setValue(vscroll.getValue() - 1);
494 if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
500 vscroll.setValue(vscroll.getValue() + 1);
514 * @return DOCUMENT ME!
516 public boolean scrollRight(boolean right)
520 if (hscroll.getValue() < 1)
526 hscroll.setValue(hscroll.getValue() - 1);
530 if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
536 hscroll.setValue(hscroll.getValue() + 1);
545 * Adjust row/column scrollers to show a visible position in the alignment.
548 * visible column to scroll to DOCUMENT ME!
550 * visible row to scroll to
553 public void setScrollValues(int x, int y)
555 // System.err.println("Scroll to "+x+","+y);
556 if (av == null || av.getAlignment() == null)
560 int width = av.getAlignment().getWidth();
561 int height = av.getAlignment().getHeight();
563 if (av.hasHiddenColumns())
565 width = av.getColumnSelection().findColumnPosition(width);
568 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
570 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
571 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
578 if (vextent > height)
583 if ((hextent + x) > width)
588 if ((vextent + y) > height)
590 y = height - vextent;
603 hscroll.setValues(x, hextent, 0, width);
604 vscroll.setValues(y, vextent, 0, height);
613 public void adjustmentValueChanged(AdjustmentEvent evt)
616 int oldX = av.getStartRes();
617 int oldY = av.getStartSeq();
619 if (evt.getSource() == hscroll)
621 int x = hscroll.getValue();
623 av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
626 if (evt.getSource() == vscroll)
628 int offy = vscroll.getValue();
630 if (av.getWrapAlignment())
634 int rowSize = seqPanel.seqCanvas
635 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
636 av.setStartRes(offy * rowSize);
637 av.setEndRes((offy + 1) * rowSize);
641 // This is only called if file loaded is a jar file that
642 // was wrapped when saved and user has wrap alignment true
643 // as preference setting
644 SwingUtilities.invokeLater(new Runnable()
648 setScrollValues(av.getStartRes(), av.getStartSeq());
655 av.setStartSeq(offy);
657 + (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
661 if (overviewPanel != null)
663 overviewPanel.setBoxPosition();
666 int scrollX = av.startRes - oldX;
667 int scrollY = av.startSeq - oldY;
669 if (av.getWrapAlignment() || !fastPaint)
675 // Make sure we're not trying to draw a panel
676 // larger than the visible window
677 if (scrollX > av.endRes - av.startRes)
679 scrollX = av.endRes - av.startRes;
681 else if (scrollX < av.startRes - av.endRes)
683 scrollX = av.startRes - av.endRes;
686 if (scrollX != 0 || scrollY != 0)
688 idPanel.idCanvas.fastPaint(scrollY);
689 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
690 scalePanel.repaint();
692 if (av.getShowAnnotation() && scrollX!=0)
694 annotationPanel.fastPaint(scrollX);
700 public void paintAlignment(boolean updateOverview)
706 av.getStructureSelectionManager().sequenceColoursChanged(this);
708 if (overviewPanel != null)
710 overviewPanel.updateOverviewImage();
721 public void paintComponent(Graphics g)
725 Dimension d = idPanel.idCanvas.getPreferredSize();
726 idPanelHolder.setPreferredSize(d);
727 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
730 if (av.getWrapAlignment())
732 int maxwidth = av.getAlignment().getWidth();
734 if (av.hasHiddenColumns())
736 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
739 int canvasWidth = seqPanel.seqCanvas
740 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
745 .getWrappedCanvasWidth(seqPanel.seqCanvas
747 vscroll.setMaximum(max);
748 vscroll.setUnitIncrement(1);
749 vscroll.setVisibleAmount(1);
754 setScrollValues(av.getStartRes(), av.getStartSeq());
768 * @return DOCUMENT ME!
770 * @throws PrinterException
773 public int print(Graphics pg, PageFormat pf, int pi)
774 throws PrinterException
776 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
778 int pwidth = (int) pf.getImageableWidth();
779 int pheight = (int) pf.getImageableHeight();
781 if (av.getWrapAlignment())
783 return printWrappedAlignment(pg, pwidth, pheight, pi);
787 return printUnwrapped(pg, pwidth, pheight, pi);
803 * @return DOCUMENT ME!
805 * @throws PrinterException
808 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
809 throws PrinterException
811 int idWidth = getVisibleIdWidth(false);
812 FontMetrics fm = getFontMetrics(av.getFont());
813 int scaleHeight = av.charHeight + fm.getDescent();
815 pg.setColor(Color.white);
816 pg.fillRect(0, 0, pwidth, pheight);
817 pg.setFont(av.getFont());
819 // //////////////////////////////////
820 // / How many sequences and residues can we fit on a printable page?
821 int totalRes = (pwidth - idWidth) / av.getCharWidth();
823 int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
825 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
827 // ///////////////////////////
828 // / Only print these sequences and residues on this page
831 // ///////////////////////////
832 // / Only print these sequences and residues on this page
835 // ///////////////////////////
836 // / Only print these sequences and residues on this page
839 // ///////////////////////////
840 // / Only print these sequences and residues on this page
842 startRes = (pi % pagesWide) * totalRes;
843 endRes = (startRes + totalRes) - 1;
845 if (endRes > (av.getAlignment().getWidth() - 1))
847 endRes = av.getAlignment().getWidth() - 1;
850 startSeq = (pi / pagesWide) * totalSeq;
851 endSeq = startSeq + totalSeq;
853 if (endSeq > av.getAlignment().getHeight())
855 endSeq = av.getAlignment().getHeight();
858 int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1)
861 if (av.showAnnotation)
863 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
866 pagesHigh /= pheight;
868 if (pi >= (pagesWide * pagesHigh))
870 return Printable.NO_SUCH_PAGE;
874 pg.translate(idWidth, 0);
875 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth,
877 pg.translate(-idWidth, scaleHeight);
881 Color currentColor = null;
882 Color currentTextColor = null;
884 pg.setFont(idPanel.idCanvas.idfont);
887 for (int i = startSeq; i < endSeq; i++)
889 seq = av.getAlignment().getSequenceAt(i);
890 if ((av.getSelectionGroup() != null)
891 && av.getSelectionGroup().getSequences(null).contains(seq))
893 currentColor = Color.gray;
894 currentTextColor = Color.black;
898 currentColor = av.getSequenceColour(seq);
899 currentTextColor = Color.black;
902 pg.setColor(currentColor);
903 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
906 pg.setColor(currentTextColor);
909 if (av.rightAlignIds)
911 fm = pg.getFontMetrics();
913 - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix()))
918 seq.getDisplayId(av.getShowJVSuffix()),
920 (((i - startSeq) * av.charHeight) + av.getCharHeight())
921 - (av.getCharHeight() / 5));
924 pg.setFont(av.getFont());
926 // draw main sequence panel
927 pg.translate(idWidth, 0);
928 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
930 if (av.showAnnotation && (endSeq == av.getAlignment().getHeight()))
932 // draw annotation - need to offset for current scroll position
933 int offset = -alabels.scrollOffset;
934 pg.translate(0, offset);
935 pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
936 alabels.drawComponent((Graphics2D) pg, idWidth);
937 pg.translate(idWidth + 3, 0);
938 annotationPanel.renderer.drawComponent(annotationPanel, av,
939 (Graphics2D) pg, -1, startRes, endRes + 1);
940 pg.translate(0, -offset);
943 return Printable.PAGE_EXISTS;
958 * @return DOCUMENT ME!
960 * @throws PrinterException
963 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
964 int pi) throws PrinterException
967 int annotationHeight = 0;
968 AnnotationLabels labels = null;
969 if (av.showAnnotation)
971 annotationHeight = annotationPanel.adjustPanelHeight();
972 labels = new AnnotationLabels(av);
975 int hgap = av.charHeight;
976 if (av.scaleAboveWrapped)
978 hgap += av.charHeight;
981 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
984 int idWidth = getVisibleIdWidth(false);
986 int maxwidth = av.getAlignment().getWidth();
987 if (av.hasHiddenColumns())
989 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
992 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth
995 int totalHeight = cHeight * (maxwidth / resWidth + 1);
997 pg.setColor(Color.white);
998 pg.fillRect(0, 0, pwidth, pheight);
999 pg.setFont(av.getFont());
1003 pg.setColor(Color.black);
1005 pg.translate(0, -pi * pheight);
1007 pg.setClip(0, pi * pheight, pwidth, pheight);
1013 for (int i = 0; i < av.getAlignment().getHeight(); i++)
1015 pg.setFont(idPanel.idCanvas.idfont);
1016 SequenceI s = av.getAlignment().getSequenceAt(i);
1017 String string = s.getDisplayId(av.getShowJVSuffix());
1019 if (av.rightAlignIds)
1021 FontMetrics fm = pg.getFontMetrics();
1022 xPos = idWidth - fm.stringWidth(string) - 4;
1024 pg.drawString(string, xPos,
1025 ((i * av.charHeight) + ypos + av.charHeight)
1026 - (av.charHeight / 5));
1030 pg.translate(-3, ypos
1031 + (av.getAlignment().getHeight() * av.charHeight));
1033 pg.setFont(av.getFont());
1034 labels.drawComponent(pg, idWidth);
1035 pg.translate(+3, -ypos
1036 - (av.getAlignment().getHeight() * av.charHeight));
1040 } while (ypos < totalHeight);
1042 pg.translate(idWidth, 0);
1044 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight,
1047 if ((pi * pheight) < totalHeight)
1049 return Printable.PAGE_EXISTS;
1054 return Printable.NO_SUCH_PAGE;
1059 * get current sequence ID panel width, or nominal value if panel were to be
1060 * displayed using default settings
1064 int getVisibleIdWidth()
1066 return getVisibleIdWidth(true);
1070 * get current sequence ID panel width, or nominal value if panel were to be
1071 * displayed using default settings
1074 * indicate if the Id width for onscreen or offscreen display should
1078 int getVisibleIdWidth(boolean onscreen)
1080 // see if rendering offscreen - check preferences and calc width accordingly
1081 if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
1083 return calculateIdWidth(-1).width + 4;
1085 Integer idwidth = null;
1087 || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null)
1089 return (idPanel.getWidth() > 0 ? idPanel.getWidth()
1090 : calculateIdWidth().width + 4);
1092 return idwidth.intValue() + 4;
1095 void makeAlignmentImage(int type, File file)
1097 long progress = System.currentTimeMillis();
1098 boolean headless = (System.getProperty("java.awt.headless") != null
1099 && System.getProperty("java.awt.headless").equals("true"));
1100 if (alignFrame != null && !headless)
1102 alignFrame.setProgressBar("Saving "
1103 + (type == jalview.util.ImageMaker.PNG ? "PNG image"
1104 : "EPS file"), progress);
1108 int maxwidth = av.getAlignment().getWidth();
1109 if (av.hasHiddenColumns())
1111 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1114 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1115 + scalePanel.getHeight();
1116 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1118 if (av.getWrapAlignment())
1120 height = getWrappedHeight();
1123 // need to obtain default alignment width and then add in any
1124 // additional allowance for id margin
1125 // this duplicates the calculation in getWrappedHeight but adjusts for
1127 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1128 - alignFrame.getInsets().left
1129 - alignFrame.getInsets().right - getVisibleIdWidth()
1130 + getVisibleIdWidth(false);
1134 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1138 else if (av.getShowAnnotation())
1140 height += annotationPanel.adjustPanelHeight() + 3;
1146 jalview.util.ImageMaker im;
1147 final String imageAction, imageTitle;
1148 if (type == jalview.util.ImageMaker.PNG)
1150 imageAction = "Create PNG image from alignment";
1155 imageAction = "Create EPS file from alignment";
1156 imageTitle = alignFrame.getTitle();
1158 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1159 height, file, imageTitle);
1160 if (av.getWrapAlignment())
1162 if (im.getGraphics() != null)
1164 printWrappedAlignment(im.getGraphics(), width, height, 0);
1170 if (im.getGraphics() != null)
1172 printUnwrapped(im.getGraphics(), width, height, 0);
1176 } catch (OutOfMemoryError err)
1179 System.out.println("########################\n" + "OUT OF MEMORY "
1180 + file + "\n" + "########################");
1181 new OOMWarning("Creating Image for " + file, err);
1182 // System.out.println("Create IMAGE: " + err);
1183 } catch (Exception ex)
1185 ex.printStackTrace();
1189 if (alignFrame != null && !headless)
1191 alignFrame.setProgressBar("Export complete.", progress);
1199 public void makeEPS(File epsFile)
1201 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1207 public void makePNG(File pngFile)
1209 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1212 public void makePNGImageMap(File imgMapFile, String imageName)
1214 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1215 // ////////////////////////////////////////////
1216 int idWidth = getVisibleIdWidth(false);
1217 FontMetrics fm = getFontMetrics(av.getFont());
1218 int scaleHeight = av.charHeight + fm.getDescent();
1221 // ////////////////////////////////
1222 if (imgMapFile != null)
1226 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1227 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1228 StringBuffer text = new StringBuffer();
1229 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1230 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1231 out.println("<img src=\"" + imageName
1232 + "\" border=\"0\" usemap=\"#Map\" >"
1233 + "<map name=\"Map\">");
1235 for (s = 0; s < sSize; s++)
1237 sy = s * av.charHeight + scaleHeight;
1239 SequenceI seq = av.getAlignment().getSequenceAt(s);
1240 SequenceFeature[] features = seq.getDatasetSequence()
1241 .getSequenceFeatures();
1242 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1243 for (res = 0; res < alwidth; res++)
1245 text = new StringBuffer();
1247 if (av.getAlignment().isNucleotide())
1249 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1254 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1263 String triplet = obj.toString();
1264 int alIndex = seq.findPosition(res);
1265 gSize = groups.length;
1266 for (g = 0; g < gSize; g++)
1268 if (text.length() < 1)
1270 text.append("<area shape=\"rect\" coords=\""
1271 + (idWidth + res * av.charWidth) + "," + sy + ","
1272 + (idWidth + (res + 1) * av.charWidth) + ","
1273 + (av.charHeight + sy) + "\""
1274 + " onMouseOver=\"toolTip('" + alIndex + " "
1278 if (groups[g].getStartRes() < res
1279 && groups[g].getEndRes() > res)
1281 text.append("<br><em>" + groups[g].getName() + "</em>");
1285 if (features != null)
1287 if (text.length() < 1)
1289 text.append("<area shape=\"rect\" coords=\""
1290 + (idWidth + res * av.charWidth) + "," + sy + ","
1291 + (idWidth + (res + 1) * av.charWidth) + ","
1292 + (av.charHeight + sy) + "\""
1293 + " onMouseOver=\"toolTip('" + alIndex + " "
1296 fSize = features.length;
1297 for (f = 0; f < fSize; f++)
1300 if ((features[f].getBegin() <= seq.findPosition(res))
1301 && (features[f].getEnd() >= seq.findPosition(res)))
1303 if (features[f].getType().equals("disulfide bond"))
1305 if (features[f].getBegin() == seq.findPosition(res)
1306 || features[f].getEnd() == seq
1309 text.append("<br>disulfide bond "
1310 + features[f].getBegin() + ":"
1311 + features[f].getEnd());
1316 text.append("<br>");
1317 text.append(features[f].getType());
1318 if (features[f].getDescription() != null
1319 && !features[f].getType().equals(
1320 features[f].getDescription()))
1322 text.append(" " + features[f].getDescription());
1325 if (features[f].getValue("status") != null)
1327 text.append(" (" + features[f].getValue("status")
1335 if (text.length() > 1)
1337 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1338 out.println(text.toString());
1342 out.println("</map></body></html>");
1345 } catch (Exception ex)
1347 ex.printStackTrace();
1349 } // /////////END OF IMAGE MAP
1353 int getWrappedHeight()
1355 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1357 if (System.getProperty("java.awt.headless") != null
1358 && System.getProperty("java.awt.headless").equals("true"))
1360 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1361 - vscroll.getPreferredSize().width
1362 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1365 int chunkWidth = seqPanel.seqCanvas
1366 .getWrappedCanvasWidth(seqPanelWidth);
1368 int hgap = av.charHeight;
1369 if (av.scaleAboveWrapped)
1371 hgap += av.charHeight;
1374 int annotationHeight = 0;
1375 if (av.showAnnotation)
1377 annotationHeight = annotationPanel.adjustPanelHeight();
1380 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1383 int maxwidth = av.getAlignment().getWidth();
1384 if (av.hasHiddenColumns())
1386 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1389 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1395 * close the panel - deregisters all listeners and nulls any references to
1398 public void closePanel()
1400 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1401 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1402 PaintRefresher.RemoveComponent(this);
1405 jalview.structure.StructureSelectionManager ssm = av
1406 .getStructureSelectionManager();
1407 ssm.removeStructureViewerListener(seqPanel, null);
1408 ssm.removeSelectionListener(seqPanel);
1409 av.setAlignment(null);
1414 if (Cache.log.isDebugEnabled())
1416 Cache.log.warn("Closing alignment panel which is already closed.");
1422 * hides or shows dynamic annotation rows based on groups and av state flags
1424 public void updateAnnotation()
1426 updateAnnotation(false, false);
1429 public void updateAnnotation(boolean applyGlobalSettings)
1431 updateAnnotation(applyGlobalSettings, false);
1434 public void updateAnnotation(boolean applyGlobalSettings,
1435 boolean preserveNewGroupSettings)
1437 av.updateGroupAnnotationSettings(applyGlobalSettings,
1438 preserveNewGroupSettings);
1439 adjustAnnotationHeight();
1443 public AlignmentI getAlignment()
1445 return av.getAlignment();
1449 * get the name for this view
1453 public String getViewName()
1459 * Make/Unmake this alignment panel the current input focus
1463 public void setSelected(boolean b)
1467 alignFrame.setSelected(b);
1468 } catch (Exception ex)
1475 alignFrame.setDisplayedView(this);
1480 public StructureSelectionManager getStructureSelectionManager()
1482 return av.getStructureSelectionManager();
1486 public void raiseOOMWarning(String string, OutOfMemoryError error)
1488 new OOMWarning(string, error, this);
1491 public FeatureRenderer cloneFeatureRenderer()
1494 return new FeatureRenderer(this);
1497 public void updateFeatureRenderer(FeatureRenderer fr)
1499 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1502 public void updateFeatureRendererFrom(FeatureRenderer fr)
1504 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1506 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);