2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.jbgui.*;
\r
25 import jalview.schemes.*;
\r
28 import java.awt.event.*;
\r
29 import java.awt.print.*;
\r
33 import javax.swing.*;
\r
35 import org.biojava.dasobert.eventmodel.*;
\r
42 * @version $Revision$
\r
44 public class AlignmentPanel extends GAlignmentPanel
\r
45 implements AdjustmentListener, Printable, FeatureListener
\r
47 public AlignViewport av;
\r
48 OverviewPanel overviewPanel;
\r
51 IdwidthAdjuster idwidthAdjuster;
\r
53 /** DOCUMENT ME!! */
\r
54 public AlignFrame alignFrame;
\r
55 ScalePanel scalePanel;
\r
56 AnnotationPanel annotationPanel;
\r
57 AnnotationLabels alabels;
\r
59 // this value is set false when selection area being dragged
\r
60 boolean fastPaint = true;
\r
65 * Creates a new AlignmentPanel object.
\r
67 * @param af DOCUMENT ME!
\r
68 * @param av DOCUMENT ME!
\r
70 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
74 seqPanel = new SeqPanel(av, this);
\r
75 idPanel = new IdPanel(av, this);
\r
77 scalePanel = new ScalePanel(av, this);
\r
79 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
80 idwidthAdjuster = new IdwidthAdjuster(this);
\r
81 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
83 annotationPanel = new AnnotationPanel(this);
\r
84 alabels = new AnnotationLabels(this);
\r
87 annotationScroller.setViewportView(annotationPanel);
\r
88 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
92 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
93 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
95 setScrollValues(0, 0);
\r
97 adjustAnnotationHeight();
\r
99 setAnnotationVisible(av.getShowAnnotation());
\r
101 hscroll.addAdjustmentListener(this);
\r
102 vscroll.addAdjustmentListener(this);
\r
104 af.addKeyListener(new KeyAdapter()
\r
106 public void keyPressed(KeyEvent evt)
\r
109 && evt.getKeyCode()>=KeyEvent.VK_0
\r
110 && evt.getKeyCode()<=KeyEvent.VK_9)
\r
112 seqPanel.numberPressed(evt.getKeyChar());
\r
115 switch (evt.getKeyCode())
\r
117 case 27: // escape key
\r
118 av.setSelectionGroup(null);
\r
123 case KeyEvent.VK_DOWN:
\r
126 seqPanel.moveCursor(0,1);
\r
129 alignFrame.moveSelectedSequences(false);
\r
132 case KeyEvent.VK_UP:
\r
135 seqPanel.moveCursor(0,-1);
\r
138 alignFrame.moveSelectedSequences(true);
\r
141 case KeyEvent.VK_LEFT:
\r
144 seqPanel.moveCursor(-1,0);
\r
148 case KeyEvent.VK_RIGHT:
\r
151 seqPanel.moveCursor(1,0);
\r
155 case KeyEvent.VK_SPACE:
\r
158 seqPanel.insertGapAtCursor(evt.isControlDown() || evt.isShiftDown());
\r
162 case KeyEvent.VK_DELETE:
\r
163 case KeyEvent.VK_BACK_SPACE:
\r
166 alignFrame.cut_actionPerformed(null);
\r
167 seqPanel.seqCanvas.repaint();
\r
170 seqPanel.deleteGapAtCursor(evt.isControlDown() || evt.isShiftDown());
\r
174 case KeyEvent.VK_S:
\r
177 seqPanel.setCursorRow();
\r
180 case KeyEvent.VK_C:
\r
183 seqPanel.setCursorColumn();
\r
186 case KeyEvent.VK_P:
\r
189 seqPanel.setCursorPosition();
\r
193 case KeyEvent.VK_ENTER:
\r
194 case KeyEvent.VK_COMMA:
\r
197 seqPanel.setCursorRowAndColumn();
\r
201 case KeyEvent.VK_Q:
\r
204 seqPanel.setSelectionAreaAtCursor(true);
\r
207 case KeyEvent.VK_M:
\r
210 seqPanel.setSelectionAreaAtCursor(false);
\r
214 case KeyEvent.VK_F2:
\r
215 av.cursorMode = ! av.cursorMode;
\r
216 alignFrame.statusBar.setText("Keyboard editing mode is "+
\r
217 (av.cursorMode ? "on" : "off"));
\r
220 seqPanel.seqCanvas.cursorX = av.startRes;
\r
221 seqPanel.seqCanvas.cursorY = av.startSeq;
\r
223 seqPanel.seqCanvas.repaint();
\r
226 case KeyEvent.VK_F1:
\r
229 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
230 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
\r
231 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
\r
233 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
234 hb.setCurrentID("home");
\r
235 hb.setDisplayed(true);
\r
237 catch (Exception ex)
\r
239 ex.printStackTrace();
\r
248 public void comeBackLater(FeatureEvent evt)
\r
251 public void newFeatures(FeatureEvent evt)
\r
253 seqPanel.seqCanvas.fr.findAllFeatures();
\r
260 public void fontChanged()
\r
262 // set idCanvas bufferedImage to null
\r
263 // to prevent drawing old image
\r
264 FontMetrics fm = getFontMetrics(av.getFont());
\r
266 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
267 av.charHeight + fm.getDescent()));
\r
268 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
269 av.charHeight + fm.getDescent()));
\r
271 idPanel.idCanvas.gg = null;
\r
272 seqPanel.seqCanvas.img = null;
\r
273 annotationPanel.adjustPanelHeight();
\r
275 Dimension d = calculateIdWidth();
\r
276 d.setSize(d.width + 4, d.height);
\r
277 idPanel.idCanvas.setPreferredSize(d);
\r
278 hscrollFillerPanel.setPreferredSize(d);
\r
280 if (av.getWrapAlignment())
\r
282 int max = av.alignment.getWidth() /
\r
283 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
284 vscroll.setMaximum(max);
\r
285 vscroll.setUnitIncrement(1);
\r
286 vscroll.setVisibleAmount(1);
\r
290 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
293 if (overviewPanel != null)
\r
294 overviewPanel.setBoxPosition();
\r
302 * @return DOCUMENT ME!
\r
304 public Dimension calculateIdWidth()
\r
306 Container c = new Container();
\r
308 FontMetrics fm = c.getFontMetrics(av.font);
\r
309 AlignmentI al = av.getAlignment();
\r
315 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
317 SequenceI s = al.getSequenceAt(i);
\r
319 id = s.getDisplayId(av.getShowJVSuffix());
\r
321 if (fm.stringWidth(id) > idWidth)
\r
323 idWidth = fm.stringWidth(id);
\r
329 // Also check annotation label widths
\r
332 if (al.getAlignmentAnnotation() != null)
\r
334 fm = c.getFontMetrics(alabels.getFont());
\r
336 while (i < al.getAlignmentAnnotation().length)
\r
338 String label = al.getAlignmentAnnotation()[i].label;
\r
340 if (fm.stringWidth(label) > idWidth)
\r
342 idWidth = fm.stringWidth(label);
\r
349 return new Dimension(idWidth, 12);
\r
355 * @param results DOCUMENT ME!
\r
357 public void highlightSearchResults(SearchResults results)
\r
359 seqPanel.seqCanvas.highlightSearchResults(results);
\r
361 // do we need to scroll the panel?
\r
362 if (results != null)
\r
364 SequenceI seq = results.getResultSequence(0);
\r
365 int seqIndex = av.alignment.findIndex(seq);
\r
366 int start = seq.findIndex(results.getResultStart(0)) - 1;
\r
367 int end = seq.findIndex(results.getResultEnd(0)) - 1;
\r
369 if(!av.wrapAlignment)
\r
371 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
\r
372 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
\r
374 setScrollValues(start, seqIndex);
\r
379 scrollToWrappedVisible(start);
\r
384 void scrollToWrappedVisible(int res)
\r
386 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
387 if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) )
\r
389 vscroll.setValue(res / cwidth);
\r
390 av.startRes = vscroll.getValue() * cwidth;
\r
397 * @return DOCUMENT ME!
\r
399 public OverviewPanel getOverviewPanel()
\r
401 return overviewPanel;
\r
407 * @param op DOCUMENT ME!
\r
409 public void setOverviewPanel(OverviewPanel op)
\r
411 overviewPanel = op;
\r
417 * @param b DOCUMENT ME!
\r
419 public void setAnnotationVisible(boolean b)
\r
421 if (!av.wrapAlignment)
\r
423 annotationSpaceFillerHolder.setVisible(b);
\r
424 annotationScroller.setVisible(b);
\r
429 public void adjustAnnotationHeight()
\r
431 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
435 while(alignFrame.getHeight()==0)
\r
440 int height = annotationPanel.adjustPanelHeight();
\r
442 if (height > alignFrame.getHeight() / 2)
\r
444 height = alignFrame.getHeight() / 2;
\r
447 annotationScroller.setPreferredSize(
\r
448 new Dimension(annotationScroller.getWidth(),
\r
451 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
452 annotationSpaceFillerHolder.getWidth(),
\r
455 annotationPanel.repaint();
\r
463 * @param wrap DOCUMENT ME!
\r
465 public void setWrapAlignment(boolean wrap)
\r
468 scalePanelHolder.setVisible(!wrap);
\r
469 hscroll.setVisible(!wrap);
\r
470 idwidthAdjuster.setVisible(!wrap);
\r
474 annotationScroller.setVisible(false);
\r
475 annotationSpaceFillerHolder.setVisible(false);
\r
477 else if (av.showAnnotation)
\r
479 annotationScroller.setVisible(true);
\r
480 annotationSpaceFillerHolder.setVisible(true);
\r
483 idSpaceFillerPanel1.setVisible(!wrap);
\r
488 // return value is true if the scroll is valid
\r
489 public boolean scrollUp(boolean up)
\r
493 if (vscroll.getValue() < 1)
\r
499 vscroll.setValue(vscroll.getValue() - 1);
\r
503 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
509 vscroll.setValue(vscroll.getValue() + 1);
\r
520 * @param right DOCUMENT ME!
\r
522 * @return DOCUMENT ME!
\r
524 public boolean scrollRight(boolean right)
\r
528 if (hscroll.getValue() < 1)
\r
534 hscroll.setValue(hscroll.getValue() - 1);
\r
538 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
544 hscroll.setValue(hscroll.getValue() + 1);
\r
555 * @param x DOCUMENT ME!
\r
556 * @param y DOCUMENT ME!
\r
558 public void setScrollValues(int x, int y)
\r
561 int width = av.alignment.getWidth();
\r
562 int height = av.alignment.getHeight();
\r
564 if(av.hasHiddenColumns)
\r
565 width = av.getColumnSelection().findColumnPosition(width);
\r
567 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
\r
569 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
570 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
572 if (hextent > width)
\r
577 if (vextent > height)
\r
582 if ( (hextent + x) > width)
\r
584 x = width - hextent;
\r
587 if ( (vextent + y) > height)
\r
589 y = height - vextent;
\r
602 hscroll.setValues(x, hextent, 0, width);
\r
603 vscroll.setValues(y, vextent, 0, height);
\r
609 * @param evt DOCUMENT ME!
\r
611 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
613 int oldX = av.getStartRes();
\r
614 int oldY = av.getStartSeq();
\r
616 if (evt.getSource() == hscroll)
\r
618 int x = hscroll.getValue();
\r
621 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
624 if (evt.getSource() == vscroll)
\r
626 int offy = vscroll.getValue();
\r
628 if (av.getWrapAlignment())
\r
630 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
631 seqCanvas.getWidth());
\r
632 av.setStartRes(vscroll.getValue() * rowSize);
\r
633 av.setEndRes( (vscroll.getValue() + 1) * rowSize);
\r
637 av.setStartSeq(offy);
\r
638 av.setEndSeq(offy +
\r
639 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
643 if (overviewPanel != null)
\r
645 overviewPanel.setBoxPosition();
\r
648 int scrollX = av.startRes - oldX;
\r
649 int scrollY = av.startSeq - oldY;
\r
651 if (av.getWrapAlignment() || !fastPaint)
\r
657 // Make sure we're not trying to draw a panel
\r
658 // larger than the visible window
\r
659 if(scrollX>av.endRes-av.startRes)
\r
660 scrollX = av.endRes-av.startRes;
\r
661 else if(scrollX<av.startRes-av.endRes)
\r
662 scrollX = av.startRes - av.endRes;
\r
664 if(scrollX!=0 || scrollY!=0)
\r
666 idPanel.idCanvas.fastPaint(scrollY);
\r
667 seqPanel.seqCanvas.fastPaint(scrollX,
\r
669 scalePanel.repaint();
\r
671 if (av.getShowAnnotation())
\r
673 annotationPanel.fastPaint(scrollX);
\r
682 * @param g DOCUMENT ME!
\r
684 public void paintComponent(Graphics g)
\r
688 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
689 idPanelHolder.setPreferredSize(d);
\r
690 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
693 if (av.getWrapAlignment())
\r
695 int max = av.alignment.getWidth() /
\r
696 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()) +1;
\r
699 vscroll.setMaximum(max);
\r
700 vscroll.setUnitIncrement(1);
\r
701 vscroll.setVisibleAmount(1);
\r
705 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
708 if( this.getVisibleRect().getBounds() == g.getClipBounds()
\r
709 && overviewPanel != null)
\r
710 overviewPanel.updateOverviewImage();
\r
717 * @param pg DOCUMENT ME!
\r
718 * @param pf DOCUMENT ME!
\r
719 * @param pi DOCUMENT ME!
\r
721 * @return DOCUMENT ME!
\r
723 * @throws PrinterException DOCUMENT ME!
\r
725 public int print(Graphics pg, PageFormat pf, int pi)
\r
726 throws PrinterException
\r
728 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
\r
730 int pwidth = (int) pf.getImageableWidth();
\r
731 int pheight = (int) pf.getImageableHeight();
\r
733 if (av.getWrapAlignment())
\r
735 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
739 return printUnwrapped(pg, pwidth, pheight, pi);
\r
746 * @param pg DOCUMENT ME!
\r
747 * @param pwidth DOCUMENT ME!
\r
748 * @param pheight DOCUMENT ME!
\r
749 * @param pi DOCUMENT ME!
\r
751 * @return DOCUMENT ME!
\r
753 * @throws PrinterException DOCUMENT ME!
\r
755 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
756 throws PrinterException
\r
758 int idWidth = calculateIdWidth().width + 4;
\r
759 FontMetrics fm = getFontMetrics(av.getFont());
\r
760 int scaleHeight = av.charHeight + fm.getDescent();
\r
762 pg.setColor(Color.white);
\r
763 pg.fillRect(0, 0, pwidth, pheight);
\r
764 pg.setFont(av.getFont());
\r
766 ////////////////////////////////////
\r
767 /// How many sequences and residues can we fit on a printable page?
\r
768 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
770 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
\r
773 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
775 /////////////////////////////
\r
776 /// Only print these sequences and residues on this page
\r
779 /////////////////////////////
\r
780 /// Only print these sequences and residues on this page
\r
783 /////////////////////////////
\r
784 /// Only print these sequences and residues on this page
\r
787 /////////////////////////////
\r
788 /// Only print these sequences and residues on this page
\r
790 startRes = (pi % pagesWide) * totalRes;
\r
791 endRes = (startRes + totalRes) - 1;
\r
793 if (endRes > (av.getAlignment().getWidth() - 1))
\r
795 endRes = av.getAlignment().getWidth() - 1;
\r
798 startSeq = (pi / pagesWide) * totalSeq;
\r
799 endSeq = startSeq + totalSeq;
\r
801 if (endSeq > av.getAlignment().getHeight())
\r
803 endSeq = av.getAlignment().getHeight();
\r
806 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
808 if (av.showAnnotation)
\r
810 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
\r
813 pagesHigh /= pheight;
\r
815 if (pi >= (pagesWide * pagesHigh))
\r
817 return Printable.NO_SUCH_PAGE;
\r
821 pg.translate(idWidth, 0);
\r
822 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
823 pg.translate( -idWidth, scaleHeight);
\r
827 Color currentColor = null;
\r
828 Color currentTextColor = null;
\r
830 pg.setFont(new Font(av.getFont().getName(),
\r
832 av.getFont().getSize()));
\r
833 for (int i = startSeq; i < endSeq; i++)
\r
835 if ( (av.getSelectionGroup() != null) &&
\r
836 av.getSelectionGroup().sequences.contains(
\r
837 av.getAlignment().getSequenceAt(i)))
\r
839 currentColor = Color.gray;
\r
840 currentTextColor = Color.black;
\r
844 currentColor = av.getAlignment().getSequenceAt(i).getColor();
\r
845 currentTextColor = Color.black;
\r
848 pg.setColor(currentColor);
\r
849 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
\r
850 av.getCharHeight());
\r
852 pg.setColor(currentTextColor);
\r
854 String string = av.getAlignment().getSequenceAt(i).getDisplayId
\r
855 ( av.getShowJVSuffix());
\r
857 pg.drawString(string, 0,
\r
858 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
\r
859 (av.getCharHeight() / 5));
\r
862 pg.setFont(av.getFont());
\r
864 // draw main sequence panel
\r
865 pg.translate(idWidth, 0);
\r
866 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
\r
868 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
870 pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
\r
871 alabels.drawComponent( (Graphics2D) pg, idWidth);
\r
872 pg.translate(idWidth+3, 0);
\r
873 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
\r
877 return Printable.PAGE_EXISTS;
\r
883 * @param pg DOCUMENT ME!
\r
884 * @param pwidth DOCUMENT ME!
\r
885 * @param pheight DOCUMENT ME!
\r
886 * @param pi DOCUMENT ME!
\r
888 * @return DOCUMENT ME!
\r
890 * @throws PrinterException DOCUMENT ME!
\r
892 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
894 throws PrinterException
\r
897 int annotationHeight = 0;
\r
898 AnnotationLabels labels = null;
\r
899 if (av.showAnnotation)
\r
901 annotationHeight = annotationPanel.adjustPanelHeight();
\r
902 labels = new AnnotationLabels(av);
\r
905 int hgap = av.charHeight;
\r
906 if (av.scaleAboveWrapped)
\r
907 hgap += av.charHeight;
\r
909 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
911 + annotationHeight;
\r
913 int idWidth = calculateIdWidth().width + 4;
\r
915 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
918 int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1);
\r
920 pg.setColor(Color.white);
\r
921 pg.fillRect(0, 0, pwidth, pheight);
\r
922 pg.setFont(av.getFont());
\r
926 pg.setColor(Color.black);
\r
928 pg.translate(0, -pi * pheight);
\r
930 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
933 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
934 av.getFont().getSize());
\r
935 pg.setFont(italic);
\r
939 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
941 SequenceI s = av.alignment.getSequenceAt(i);
\r
942 String string = s.getDisplayId( av.getShowJVSuffix());
\r
944 pg.drawString(string, 0,
\r
945 ( (i * av.charHeight) + ypos + av.charHeight) -
\r
946 (av.charHeight / 5));
\r
948 if (labels != null)
\r
952 (av.getAlignment().getHeight() * av.charHeight));
\r
954 pg.setFont(av.getFont());
\r
955 labels.drawComponent(pg, idWidth);
\r
956 pg.setFont(italic);
\r
959 (av.getAlignment().getHeight() * av.charHeight));
\r
964 while (ypos < totalHeight);
\r
966 pg.translate(idWidth, 0);
\r
968 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
970 if ( (pi * pheight) < totalHeight)
\r
972 return Printable.PAGE_EXISTS;
\r
977 return Printable.NO_SUCH_PAGE;
\r
981 void makeAlignmentImage(int type, File file)
\r
983 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
984 int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
\r
985 if (idPanel.getWidth() == 0)
\r
987 width += calculateIdWidth().getWidth() + 4;
\r
990 if (av.getWrapAlignment())
\r
992 height = getWrappedHeight();
\r
993 if (System.getProperty("java.awt.headless") != null
\r
994 && System.getProperty("java.awt.headless").equals("true"))
\r
996 width = alignFrame.getWidth() - 22;
\r
1000 width = seqPanel.getWidth() + idPanel.getWidth();
\r
1003 else if (av.getShowAnnotation())
\r
1005 height += annotationPanel.adjustPanelHeight() + 3;
\r
1008 jalview.util.ImageMaker im;
\r
1009 if(type==jalview.util.ImageMaker.PNG)
\r
1010 im = new jalview.util.ImageMaker(this,
\r
1011 jalview.util.ImageMaker.PNG,
\r
1012 "Create PNG image from alignment",
\r
1013 width, height, file, null);
\r
1015 im = new jalview.util.ImageMaker(this,
\r
1016 jalview.util.ImageMaker.EPS,
\r
1017 "Create EPS file from alignment",
\r
1018 width, height, file, alignFrame.getTitle() );
\r
1022 if (av.getWrapAlignment())
\r
1024 if(im.getGraphics()!=null)
\r
1026 printWrappedAlignment(im.getGraphics(), width, height, 0);
\r
1032 if(im.getGraphics()!=null)
\r
1034 printUnwrapped(im.getGraphics(), width, height, 0);
\r
1039 catch (OutOfMemoryError err)
\r
1041 System.out.println("########################\n"
\r
1042 + "OUT OF MEMORY " + file + "\n"
\r
1043 + "########################");
\r
1045 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1046 "Out of Memory Creating Image!!"
\r
1048 "\nSee help files for increasing Java Virtual Machine memory."
\r
1049 , "Out of memory",
\r
1050 JOptionPane.WARNING_MESSAGE);
\r
1051 System.out.println("Create IMAGE: " + err);
\r
1055 catch (Exception ex)
\r
1057 ex.printStackTrace();
\r
1063 public void makeEPS(File epsFile)
\r
1065 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
\r
1071 public void makePNG(File pngFile)
\r
1073 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
\r
1076 public void makePNGImageMap(File imgMapFile, String imageName)
\r
1078 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
1079 //////////////////////////////////////////////
\r
1080 int idWidth = calculateIdWidth().width + 4;
\r
1081 FontMetrics fm = getFontMetrics(av.getFont());
\r
1082 int scaleHeight = av.charHeight + fm.getDescent();
\r
1085 //////////////////////////////////
\r
1086 if (imgMapFile != null)
\r
1090 int s, sSize = av.alignment.getHeight(),
\r
1091 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
\r
1092 StringBuffer text = new StringBuffer();
\r
1093 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
1094 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
1095 out.println("<img src=\"" + imageName +
\r
1096 "\" border=\"0\" usemap=\"#Map\" >"
\r
1097 + "<map name=\"Map\">");
\r
1099 for (s = 0; s < sSize; s++)
\r
1101 sy = s * av.charHeight + scaleHeight;
\r
1103 SequenceI seq = av.alignment.getSequenceAt(s);
\r
1104 SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures();
\r
1105 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
1106 for(res =0; res<alwidth; res++)
\r
1108 text = new StringBuffer();
\r
1109 Object obj = null;
\r
1110 if(av.alignment.isNucleotide())
\r
1111 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)+"" );
\r
1113 obj = ResidueProperties.aa2Triplet.get(
\r
1114 seq.getCharAt(res) + "");
\r
1119 String triplet = obj.toString();
\r
1120 int alIndex = seq.findPosition(res);
\r
1121 gSize = groups.length;
\r
1122 for (g = 0; g < gSize; g++)
\r
1124 if(text.length()<1)
\r
1126 text.append("<area shape=\"rect\" coords=\""
\r
1127 + (idWidth + res * av.charWidth) + ","
\r
1129 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1130 + (av.charHeight + sy) + "\""
\r
1131 + " onMouseOver=\"toolTip('"
\r
1132 + alIndex + " " + triplet );
\r
1135 if(groups[g].getStartRes()<res && groups[g].getEndRes()>res)
\r
1136 text.append("<br><em>" + groups[g].getName() + "</em>");
\r
1139 if (features != null)
\r
1141 if(text.length()<1)
\r
1143 text.append("<area shape=\"rect\" coords=\""
\r
1144 + (idWidth + res * av.charWidth) + ","
\r
1146 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1147 + (av.charHeight + sy) + "\""
\r
1148 + " onMouseOver=\"toolTip('"
\r
1149 + alIndex + " " + triplet );
\r
1151 fSize = features.length;
\r
1152 for (f = 0; f < fSize; f++)
\r
1155 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
\r
1156 (features[f].getEnd() >= seq.findPosition(res)))
\r
1158 if (features[f].getType().equals("disulfide bond"))
\r
1160 if (features[f].getBegin() == seq.findPosition(res)
\r
1161 || features[f].getEnd() == seq.findPosition(res))
\r
1163 text.append("<br>disulfide bond " + features[f].getBegin() + ":" +
\r
1164 features[f].getEnd());
\r
1169 text.append("<br>");
\r
1170 text.append(features[f].getType());
\r
1171 if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription()))
\r
1172 text.append(" " + features[f].getDescription());
\r
1174 if (features[f].getValue("status") != null )
\r
1176 text.append(" (" + features[f].getValue("status") + ")");
\r
1183 if(text.length()>1)
\r
1185 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
\r
1186 out.println(text.toString());
\r
1190 out.println("</map></body></html>");
\r
1194 catch (Exception ex)
\r
1196 ex.printStackTrace();
\r
1198 } ///////////END OF IMAGE MAP
\r
1202 int getWrappedHeight()
\r
1204 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
\r
1206 //If headless, seqPanel will have 0 width
\r
1207 if (System.getProperty("java.awt.headless") != null
\r
1208 && System.getProperty("java.awt.headless").equals("true"))
\r
1210 int idWidth = calculateIdWidth().width + 4;
\r
1211 seqPanelWidth = alignFrame.getWidth() - idWidth;
\r
1214 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
1218 int hgap = av.charHeight;
\r
1219 if (av.scaleAboveWrapped)
\r
1220 hgap += av.charHeight;
\r
1222 int annotationHeight = 0;
\r
1223 if (av.showAnnotation)
\r
1225 annotationHeight = annotationPanel.adjustPanelHeight();
\r
1228 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
1230 + annotationHeight;
\r
1232 int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight;
\r
1240 * @author $author$
\r
1241 * @version $Revision$
\r
1247 * Creates a new Preview object.
\r
1249 * @param image DOCUMENT ME!
\r
1251 public Preview(Image image)
\r
1253 setResizable(true);
\r
1254 setSize(image.getWidth(this), image.getHeight(this));
\r
1256 getContentPane().setLayout(new BorderLayout());
\r
1257 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
\r
1266 * @author $author$
\r
1267 * @version $Revision$
\r
1269 class PreviewPanel
\r
1275 * Creates a new PreviewPanel object.
\r
1277 * @param image DOCUMENT ME!
\r
1279 public PreviewPanel(Image image)
\r
1281 this.image = image;
\r
1287 * @param g DOCUMENT ME!
\r
1289 public void paintComponent(Graphics g)
\r
1291 if (image != null)
\r
1293 g.drawImage(image, 0, 0, this);
\r
1297 System.out.println("DEBUG:image is null");
\r