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())
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 if (alignFrame != null)
1099 alignFrame.setProgressBar("Saving "
1100 + (type == jalview.util.ImageMaker.PNG ? "PNG image"
1101 : "EPS file"), progress);
1105 int maxwidth = av.getAlignment().getWidth();
1106 if (av.hasHiddenColumns())
1108 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
1111 int height = ((av.getAlignment().getHeight() + 1) * av.charHeight)
1112 + scalePanel.getHeight();
1113 int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth);
1115 if (av.getWrapAlignment())
1117 height = getWrappedHeight();
1118 if (System.getProperty("java.awt.headless") != null
1119 && System.getProperty("java.awt.headless").equals("true"))
1121 // need to obtain default alignment width and then add in any
1122 // additional allowance for id margin
1123 // this duplicates the calculation in getWrappedHeight but adjusts for
1125 width = alignFrame.getWidth() - vscroll.getPreferredSize().width
1126 - alignFrame.getInsets().left
1127 - alignFrame.getInsets().right - getVisibleIdWidth()
1128 + getVisibleIdWidth(false);
1132 width = seqPanel.getWidth() + getVisibleIdWidth(false);
1136 else if (av.getShowAnnotation())
1138 height += annotationPanel.adjustPanelHeight() + 3;
1144 jalview.util.ImageMaker im;
1145 final String imageAction, imageTitle;
1146 if (type == jalview.util.ImageMaker.PNG)
1148 imageAction = "Create PNG image from alignment";
1153 imageAction = "Create EPS file from alignment";
1154 imageTitle = alignFrame.getTitle();
1156 im = new jalview.util.ImageMaker(this, type, imageAction, width,
1157 height, file, imageTitle);
1158 if (av.getWrapAlignment())
1160 if (im.getGraphics() != null)
1162 printWrappedAlignment(im.getGraphics(), width, height, 0);
1168 if (im.getGraphics() != null)
1170 printUnwrapped(im.getGraphics(), width, height, 0);
1174 } catch (OutOfMemoryError err)
1177 System.out.println("########################\n" + "OUT OF MEMORY "
1178 + file + "\n" + "########################");
1179 new OOMWarning("Creating Image for " + file, err);
1180 // System.out.println("Create IMAGE: " + err);
1181 } catch (Exception ex)
1183 ex.printStackTrace();
1187 if (alignFrame != null)
1189 alignFrame.setProgressBar("Export complete.", progress);
1197 public void makeEPS(File epsFile)
1199 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
1205 public void makePNG(File pngFile)
1207 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
1210 public void makePNGImageMap(File imgMapFile, String imageName)
1212 // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
1213 // ////////////////////////////////////////////
1214 int idWidth = getVisibleIdWidth(false);
1215 FontMetrics fm = getFontMetrics(av.getFont());
1216 int scaleHeight = av.charHeight + fm.getDescent();
1219 // ////////////////////////////////
1220 if (imgMapFile != null)
1224 int s, sSize = av.getAlignment().getHeight(), res, alwidth = av
1225 .getAlignment().getWidth(), g, gSize, f, fSize, sy;
1226 StringBuffer text = new StringBuffer();
1227 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
1228 out.println(jalview.io.HTMLOutput.getImageMapHTML());
1229 out.println("<img src=\"" + imageName
1230 + "\" border=\"0\" usemap=\"#Map\" >"
1231 + "<map name=\"Map\">");
1233 for (s = 0; s < sSize; s++)
1235 sy = s * av.charHeight + scaleHeight;
1237 SequenceI seq = av.getAlignment().getSequenceAt(s);
1238 SequenceFeature[] features = seq.getDatasetSequence()
1239 .getSequenceFeatures();
1240 SequenceGroup[] groups = av.getAlignment().findAllGroups(seq);
1241 for (res = 0; res < alwidth; res++)
1243 text = new StringBuffer();
1245 if (av.getAlignment().isNucleotide())
1247 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)
1252 obj = ResidueProperties.aa2Triplet.get(seq.getCharAt(res)
1261 String triplet = obj.toString();
1262 int alIndex = seq.findPosition(res);
1263 gSize = groups.length;
1264 for (g = 0; g < gSize; g++)
1266 if (text.length() < 1)
1268 text.append("<area shape=\"rect\" coords=\""
1269 + (idWidth + res * av.charWidth) + "," + sy + ","
1270 + (idWidth + (res + 1) * av.charWidth) + ","
1271 + (av.charHeight + sy) + "\""
1272 + " onMouseOver=\"toolTip('" + alIndex + " "
1276 if (groups[g].getStartRes() < res
1277 && groups[g].getEndRes() > res)
1279 text.append("<br><em>" + groups[g].getName() + "</em>");
1283 if (features != null)
1285 if (text.length() < 1)
1287 text.append("<area shape=\"rect\" coords=\""
1288 + (idWidth + res * av.charWidth) + "," + sy + ","
1289 + (idWidth + (res + 1) * av.charWidth) + ","
1290 + (av.charHeight + sy) + "\""
1291 + " onMouseOver=\"toolTip('" + alIndex + " "
1294 fSize = features.length;
1295 for (f = 0; f < fSize; f++)
1298 if ((features[f].getBegin() <= seq.findPosition(res))
1299 && (features[f].getEnd() >= seq.findPosition(res)))
1301 if (features[f].getType().equals("disulfide bond"))
1303 if (features[f].getBegin() == seq.findPosition(res)
1304 || features[f].getEnd() == seq
1307 text.append("<br>disulfide bond "
1308 + features[f].getBegin() + ":"
1309 + features[f].getEnd());
1314 text.append("<br>");
1315 text.append(features[f].getType());
1316 if (features[f].getDescription() != null
1317 && !features[f].getType().equals(
1318 features[f].getDescription()))
1320 text.append(" " + features[f].getDescription());
1323 if (features[f].getValue("status") != null)
1325 text.append(" (" + features[f].getValue("status")
1333 if (text.length() > 1)
1335 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
1336 out.println(text.toString());
1340 out.println("</map></body></html>");
1343 } catch (Exception ex)
1345 ex.printStackTrace();
1347 } // /////////END OF IMAGE MAP
1351 int getWrappedHeight()
1353 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
1355 if (System.getProperty("java.awt.headless") != null
1356 && System.getProperty("java.awt.headless").equals("true"))
1358 seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth()
1359 - vscroll.getPreferredSize().width
1360 - alignFrame.getInsets().left - alignFrame.getInsets().right;
1363 int chunkWidth = seqPanel.seqCanvas
1364 .getWrappedCanvasWidth(seqPanelWidth);
1366 int hgap = av.charHeight;
1367 if (av.scaleAboveWrapped)
1369 hgap += av.charHeight;
1372 int annotationHeight = 0;
1373 if (av.showAnnotation)
1375 annotationHeight = annotationPanel.adjustPanelHeight();
1378 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
1381 int maxwidth = av.getAlignment().getWidth();
1382 if (av.hasHiddenColumns())
1384 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1387 int height = ((maxwidth / chunkWidth) + 1) * cHeight;
1393 * close the panel - deregisters all listeners and nulls any references to
1396 public void closePanel()
1398 PaintRefresher.RemoveComponent(seqPanel.seqCanvas);
1399 PaintRefresher.RemoveComponent(idPanel.idCanvas);
1400 PaintRefresher.RemoveComponent(this);
1403 jalview.structure.StructureSelectionManager ssm = av
1404 .getStructureSelectionManager();
1405 ssm.removeStructureViewerListener(seqPanel, null);
1406 ssm.removeSelectionListener(seqPanel);
1407 av.setAlignment(null);
1412 if (Cache.log.isDebugEnabled())
1414 Cache.log.warn("Closing alignment panel which is already closed.");
1420 * hides or shows dynamic annotation rows based on groups and av state flags
1422 public void updateAnnotation()
1424 updateAnnotation(false, false);
1427 public void updateAnnotation(boolean applyGlobalSettings)
1429 updateAnnotation(applyGlobalSettings, false);
1432 public void updateAnnotation(boolean applyGlobalSettings,
1433 boolean preserveNewGroupSettings)
1435 av.updateGroupAnnotationSettings(applyGlobalSettings,
1436 preserveNewGroupSettings);
1437 adjustAnnotationHeight();
1441 public AlignmentI getAlignment()
1443 return av.getAlignment();
1447 * get the name for this view
1451 public String getViewName()
1457 * Make/Unmake this alignment panel the current input focus
1461 public void setSelected(boolean b)
1465 alignFrame.setSelected(b);
1466 } catch (Exception ex)
1473 alignFrame.setDisplayedView(this);
1478 public StructureSelectionManager getStructureSelectionManager()
1480 return av.getStructureSelectionManager();
1484 public void raiseOOMWarning(String string, OutOfMemoryError error)
1486 new OOMWarning(string, error, this);
1489 public FeatureRenderer cloneFeatureRenderer()
1492 return new FeatureRenderer(this);
1495 public void updateFeatureRenderer(FeatureRenderer fr)
1497 fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer());
1500 public void updateFeatureRendererFrom(FeatureRenderer fr)
1502 if (seqPanel.seqCanvas.getFeatureRenderer() != null)
1504 seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr);