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
40 * @version $Revision$
\r
42 public class AlignmentPanel extends GAlignmentPanel
\r
43 implements AdjustmentListener, Printable
\r
45 public AlignViewport av;
\r
46 OverviewPanel overviewPanel;
\r
49 IdwidthAdjuster idwidthAdjuster;
\r
51 /** DOCUMENT ME!! */
\r
52 public AlignFrame alignFrame;
\r
53 ScalePanel scalePanel;
\r
54 AnnotationPanel annotationPanel;
\r
55 AnnotationLabels alabels;
\r
57 // this value is set false when selection area being dragged
\r
58 boolean fastPaint = true;
\r
63 * Creates a new AlignmentPanel object.
\r
65 * @param af DOCUMENT ME!
\r
66 * @param av DOCUMENT ME!
\r
68 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
72 seqPanel = new SeqPanel(av, this);
\r
73 idPanel = new IdPanel(av, this);
\r
75 scalePanel = new ScalePanel(av, this);
\r
77 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
78 idwidthAdjuster = new IdwidthAdjuster(this);
\r
79 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
81 annotationPanel = new AnnotationPanel(this);
\r
82 alabels = new AnnotationLabels(this);
\r
85 annotationScroller.setViewportView(annotationPanel);
\r
86 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
90 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
91 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
93 setScrollValues(0, 0);
\r
95 adjustAnnotationHeight();
\r
97 setAnnotationVisible(av.getShowAnnotation());
\r
99 hscroll.addAdjustmentListener(this);
\r
100 vscroll.addAdjustmentListener(this);
\r
102 af.addKeyListener(new KeyAdapter()
\r
104 public void keyPressed(KeyEvent evt)
\r
107 && evt.getKeyCode()>=KeyEvent.VK_0
\r
108 && evt.getKeyCode()<=KeyEvent.VK_9)
\r
110 seqPanel.numberPressed(evt.getKeyChar());
\r
113 switch (evt.getKeyCode())
\r
115 case 27: // escape key
\r
116 av.setSelectionGroup(null);
\r
121 case KeyEvent.VK_DOWN:
\r
124 seqPanel.moveCursor(0,1);
\r
127 alignFrame.moveSelectedSequences(false);
\r
130 case KeyEvent.VK_UP:
\r
133 seqPanel.moveCursor(0,-1);
\r
136 alignFrame.moveSelectedSequences(true);
\r
139 case KeyEvent.VK_LEFT:
\r
142 seqPanel.moveCursor(-1,0);
\r
146 case KeyEvent.VK_RIGHT:
\r
149 seqPanel.moveCursor(1,0);
\r
153 case KeyEvent.VK_SPACE:
\r
156 seqPanel.insertGapAtCursor(evt.isControlDown() || evt.isShiftDown());
\r
160 case KeyEvent.VK_DELETE:
\r
161 case KeyEvent.VK_BACK_SPACE:
\r
164 alignFrame.cut_actionPerformed(null);
\r
165 seqPanel.seqCanvas.repaint();
\r
168 seqPanel.deleteGapAtCursor(evt.isControlDown() || evt.isShiftDown());
\r
172 case KeyEvent.VK_S:
\r
175 seqPanel.setCursorRow();
\r
178 case KeyEvent.VK_C:
\r
179 if(av.cursorMode && !evt.isControlDown())
\r
181 seqPanel.setCursorColumn();
\r
184 case KeyEvent.VK_P:
\r
187 seqPanel.setCursorPosition();
\r
191 case KeyEvent.VK_ENTER:
\r
192 case KeyEvent.VK_COMMA:
\r
195 seqPanel.setCursorRowAndColumn();
\r
199 case KeyEvent.VK_Q:
\r
202 seqPanel.setSelectionAreaAtCursor(true);
\r
205 case KeyEvent.VK_M:
\r
208 seqPanel.setSelectionAreaAtCursor(false);
\r
212 case KeyEvent.VK_F2:
\r
213 av.cursorMode = ! av.cursorMode;
\r
214 alignFrame.statusBar.setText("Keyboard editing mode is "+
\r
215 (av.cursorMode ? "on" : "off"));
\r
218 seqPanel.seqCanvas.cursorX = av.startRes;
\r
219 seqPanel.seqCanvas.cursorY = av.startSeq;
\r
221 seqPanel.seqCanvas.repaint();
\r
224 case KeyEvent.VK_F1:
\r
227 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
\r
228 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
\r
229 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
\r
231 javax.help.HelpBroker hb = hs.createHelpBroker();
\r
232 hb.setCurrentID("home");
\r
233 hb.setDisplayed(true);
\r
235 catch (Exception ex)
\r
237 ex.printStackTrace();
\r
249 public void fontChanged()
\r
251 // set idCanvas bufferedImage to null
\r
252 // to prevent drawing old image
\r
253 FontMetrics fm = getFontMetrics(av.getFont());
\r
255 scalePanelHolder.setPreferredSize(new Dimension(10,
\r
256 av.charHeight + fm.getDescent()));
\r
257 idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
\r
258 av.charHeight + fm.getDescent()));
\r
260 idPanel.idCanvas.gg = null;
\r
261 seqPanel.seqCanvas.img = null;
\r
262 annotationPanel.adjustPanelHeight();
\r
264 Dimension d = calculateIdWidth();
\r
265 d.setSize(d.width + 4, d.height);
\r
266 idPanel.idCanvas.setPreferredSize(d);
\r
267 hscrollFillerPanel.setPreferredSize(d);
\r
269 if (av.getWrapAlignment())
\r
271 int max = av.alignment.getWidth() /
\r
272 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
273 vscroll.setMaximum(max);
\r
274 vscroll.setUnitIncrement(1);
\r
275 vscroll.setVisibleAmount(1);
\r
279 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
282 if (overviewPanel != null)
\r
283 overviewPanel.setBoxPosition();
\r
291 * @return DOCUMENT ME!
\r
293 public Dimension calculateIdWidth()
\r
295 Container c = new Container();
\r
297 FontMetrics fm = c.getFontMetrics(av.font);
\r
298 AlignmentI al = av.getAlignment();
\r
304 while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))
\r
306 SequenceI s = al.getSequenceAt(i);
\r
308 id = s.getDisplayId(av.getShowJVSuffix());
\r
310 if (fm.stringWidth(id) > idWidth)
\r
312 idWidth = fm.stringWidth(id);
\r
318 // Also check annotation label widths
\r
321 if (al.getAlignmentAnnotation() != null)
\r
323 fm = c.getFontMetrics(alabels.getFont());
\r
325 while (i < al.getAlignmentAnnotation().length)
\r
327 String label = al.getAlignmentAnnotation()[i].label;
\r
329 if (fm.stringWidth(label) > idWidth)
\r
331 idWidth = fm.stringWidth(label);
\r
338 return new Dimension(idWidth, 12);
\r
344 * @param results DOCUMENT ME!
\r
346 public void highlightSearchResults(SearchResults results)
\r
348 seqPanel.seqCanvas.highlightSearchResults(results);
\r
350 // do we need to scroll the panel?
\r
351 if (results != null)
\r
353 SequenceI seq = results.getResultSequence(0);
\r
354 int seqIndex = av.alignment.findIndex(seq);
\r
355 int start = seq.findIndex(results.getResultStart(0)) - 1;
\r
356 int end = seq.findIndex(results.getResultEnd(0)) - 1;
\r
358 if(!av.wrapAlignment)
\r
360 if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
\r
361 ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
\r
363 setScrollValues(start, seqIndex);
\r
368 scrollToWrappedVisible(start);
\r
373 void scrollToWrappedVisible(int res)
\r
375 int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
\r
376 if( res<=av.getStartRes() || res>=(av.getStartRes()+cwidth) )
\r
378 vscroll.setValue(res / cwidth);
\r
379 av.startRes = vscroll.getValue() * cwidth;
\r
386 * @return DOCUMENT ME!
\r
388 public OverviewPanel getOverviewPanel()
\r
390 return overviewPanel;
\r
396 * @param op DOCUMENT ME!
\r
398 public void setOverviewPanel(OverviewPanel op)
\r
400 overviewPanel = op;
\r
406 * @param b DOCUMENT ME!
\r
408 public void setAnnotationVisible(boolean b)
\r
410 if (!av.wrapAlignment)
\r
412 annotationSpaceFillerHolder.setVisible(b);
\r
413 annotationScroller.setVisible(b);
\r
418 public void adjustAnnotationHeight()
\r
420 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
424 while(alignFrame.getHeight()==0)
\r
429 int height = annotationPanel.adjustPanelHeight();
\r
431 if (height > alignFrame.getHeight() / 2)
\r
433 height = alignFrame.getHeight() / 2;
\r
436 annotationScroller.setPreferredSize(
\r
437 new Dimension(annotationScroller.getWidth(),
\r
440 annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
441 annotationSpaceFillerHolder.getWidth(),
\r
444 annotationPanel.repaint();
\r
452 * @param wrap DOCUMENT ME!
\r
454 public void setWrapAlignment(boolean wrap)
\r
457 scalePanelHolder.setVisible(!wrap);
\r
458 hscroll.setVisible(!wrap);
\r
459 idwidthAdjuster.setVisible(!wrap);
\r
463 annotationScroller.setVisible(false);
\r
464 annotationSpaceFillerHolder.setVisible(false);
\r
466 else if (av.showAnnotation)
\r
468 annotationScroller.setVisible(true);
\r
469 annotationSpaceFillerHolder.setVisible(true);
\r
472 idSpaceFillerPanel1.setVisible(!wrap);
\r
477 // return value is true if the scroll is valid
\r
478 public boolean scrollUp(boolean up)
\r
482 if (vscroll.getValue() < 1)
\r
488 vscroll.setValue(vscroll.getValue() - 1);
\r
492 if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
\r
498 vscroll.setValue(vscroll.getValue() + 1);
\r
509 * @param right DOCUMENT ME!
\r
511 * @return DOCUMENT ME!
\r
513 public boolean scrollRight(boolean right)
\r
517 if (hscroll.getValue() < 1)
\r
523 hscroll.setValue(hscroll.getValue() - 1);
\r
527 if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
\r
533 hscroll.setValue(hscroll.getValue() + 1);
\r
544 * @param x DOCUMENT ME!
\r
545 * @param y DOCUMENT ME!
\r
547 public void setScrollValues(int x, int y)
\r
550 int width = av.alignment.getWidth();
\r
551 int height = av.alignment.getHeight();
\r
553 if(av.hasHiddenColumns)
\r
554 width = av.getColumnSelection().findColumnPosition(width);
\r
556 av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1);
\r
558 hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
\r
559 vextent = seqPanel.seqCanvas.getHeight() / av.charHeight;
\r
561 if (hextent > width)
\r
566 if (vextent > height)
\r
571 if ( (hextent + x) > width)
\r
573 x = width - hextent;
\r
576 if ( (vextent + y) > height)
\r
578 y = height - vextent;
\r
591 hscroll.setValues(x, hextent, 0, width);
\r
592 vscroll.setValues(y, vextent, 0, height);
\r
598 * @param evt DOCUMENT ME!
\r
600 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
603 int oldX = av.getStartRes();
\r
604 int oldY = av.getStartSeq();
\r
606 if (evt.getSource() == hscroll)
\r
608 int x = hscroll.getValue();
\r
611 (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
\r
614 if (evt.getSource() == vscroll)
\r
616 int offy = vscroll.getValue();
\r
618 if (av.getWrapAlignment())
\r
622 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
623 seqCanvas.getWidth());
\r
624 av.setStartRes(offy * rowSize);
\r
625 av.setEndRes( (offy + 1) * rowSize);
\r
629 //This is only called if file loaded is a jar file that
\r
630 //was wrapped when saved and user has wrap alignment true
\r
631 //as preference setting
\r
632 SwingUtilities.invokeLater(new Runnable()
\r
636 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
643 av.setStartSeq(offy);
\r
644 av.setEndSeq(offy +
\r
645 (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
\r
649 if (overviewPanel != null)
\r
651 overviewPanel.setBoxPosition();
\r
654 int scrollX = av.startRes - oldX;
\r
655 int scrollY = av.startSeq - oldY;
\r
657 if (av.getWrapAlignment() || !fastPaint)
\r
663 // Make sure we're not trying to draw a panel
\r
664 // larger than the visible window
\r
665 if(scrollX>av.endRes-av.startRes)
\r
666 scrollX = av.endRes-av.startRes;
\r
667 else if(scrollX<av.startRes-av.endRes)
\r
668 scrollX = av.startRes - av.endRes;
\r
670 if(scrollX!=0 || scrollY!=0)
\r
672 idPanel.idCanvas.fastPaint(scrollY);
\r
673 seqPanel.seqCanvas.fastPaint(scrollX,
\r
675 scalePanel.repaint();
\r
677 if (av.getShowAnnotation())
\r
679 annotationPanel.fastPaint(scrollX);
\r
688 * @param g DOCUMENT ME!
\r
690 public void paintComponent(Graphics g)
\r
694 Dimension d = idPanel.idCanvas.getPreferredSize();
\r
695 idPanelHolder.setPreferredSize(d);
\r
696 hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
\r
699 if (av.getWrapAlignment())
\r
701 int max = av.alignment.getWidth() /
\r
702 seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()) +1;
\r
705 vscroll.setMaximum(max);
\r
706 vscroll.setUnitIncrement(1);
\r
707 vscroll.setVisibleAmount(1);
\r
711 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
714 if( this.getVisibleRect().getBounds() == g.getClipBounds()
\r
715 && overviewPanel != null)
\r
716 overviewPanel.updateOverviewImage();
\r
723 * @param pg DOCUMENT ME!
\r
724 * @param pf DOCUMENT ME!
\r
725 * @param pi DOCUMENT ME!
\r
727 * @return DOCUMENT ME!
\r
729 * @throws PrinterException DOCUMENT ME!
\r
731 public int print(Graphics pg, PageFormat pf, int pi)
\r
732 throws PrinterException
\r
734 pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
\r
736 int pwidth = (int) pf.getImageableWidth();
\r
737 int pheight = (int) pf.getImageableHeight();
\r
739 if (av.getWrapAlignment())
\r
741 return printWrappedAlignment(pg, pwidth, pheight, pi);
\r
745 return printUnwrapped(pg, pwidth, pheight, pi);
\r
752 * @param pg DOCUMENT ME!
\r
753 * @param pwidth DOCUMENT ME!
\r
754 * @param pheight DOCUMENT ME!
\r
755 * @param pi DOCUMENT ME!
\r
757 * @return DOCUMENT ME!
\r
759 * @throws PrinterException DOCUMENT ME!
\r
761 public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
\r
762 throws PrinterException
\r
764 int idWidth = calculateIdWidth().width + 4;
\r
765 FontMetrics fm = getFontMetrics(av.getFont());
\r
766 int scaleHeight = av.charHeight + fm.getDescent();
\r
768 pg.setColor(Color.white);
\r
769 pg.fillRect(0, 0, pwidth, pheight);
\r
770 pg.setFont(av.getFont());
\r
772 ////////////////////////////////////
\r
773 /// How many sequences and residues can we fit on a printable page?
\r
774 int totalRes = (pwidth - idWidth) / av.getCharWidth();
\r
776 int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
\r
779 int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
\r
781 /////////////////////////////
\r
782 /// Only print these sequences and residues on this page
\r
785 /////////////////////////////
\r
786 /// Only print these sequences and residues on this page
\r
789 /////////////////////////////
\r
790 /// Only print these sequences and residues on this page
\r
793 /////////////////////////////
\r
794 /// Only print these sequences and residues on this page
\r
796 startRes = (pi % pagesWide) * totalRes;
\r
797 endRes = (startRes + totalRes) - 1;
\r
799 if (endRes > (av.getAlignment().getWidth() - 1))
\r
801 endRes = av.getAlignment().getWidth() - 1;
\r
804 startSeq = (pi / pagesWide) * totalSeq;
\r
805 endSeq = startSeq + totalSeq;
\r
807 if (endSeq > av.getAlignment().getHeight())
\r
809 endSeq = av.getAlignment().getHeight();
\r
812 int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
\r
814 if (av.showAnnotation)
\r
816 pagesHigh += annotationPanel.adjustPanelHeight() + 3;
\r
819 pagesHigh /= pheight;
\r
821 if (pi >= (pagesWide * pagesHigh))
\r
823 return Printable.NO_SUCH_PAGE;
\r
827 pg.translate(idWidth, 0);
\r
828 scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
\r
829 pg.translate( -idWidth, scaleHeight);
\r
833 Color currentColor = null;
\r
834 Color currentTextColor = null;
\r
836 pg.setFont(new Font(av.getFont().getName(),
\r
838 av.getFont().getSize()));
\r
839 for (int i = startSeq; i < endSeq; i++)
\r
841 if ( (av.getSelectionGroup() != null) &&
\r
842 av.getSelectionGroup().sequences.contains(
\r
843 av.getAlignment().getSequenceAt(i)))
\r
845 currentColor = Color.gray;
\r
846 currentTextColor = Color.black;
\r
850 currentColor = av.getAlignment().getSequenceAt(i).getColor();
\r
851 currentTextColor = Color.black;
\r
854 pg.setColor(currentColor);
\r
855 pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
\r
856 av.getCharHeight());
\r
858 pg.setColor(currentTextColor);
\r
860 String string = av.getAlignment().getSequenceAt(i).getDisplayId
\r
861 ( av.getShowJVSuffix());
\r
863 pg.drawString(string, 0,
\r
864 ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
\r
865 (av.getCharHeight() / 5));
\r
868 pg.setFont(av.getFont());
\r
870 // draw main sequence panel
\r
871 pg.translate(idWidth, 0);
\r
872 seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
\r
874 if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
\r
876 pg.translate( -idWidth-3, (endSeq - startSeq) * av.charHeight + 3);
\r
877 alabels.drawComponent( (Graphics2D) pg, idWidth);
\r
878 pg.translate(idWidth+3, 0);
\r
879 annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
\r
883 return Printable.PAGE_EXISTS;
\r
889 * @param pg DOCUMENT ME!
\r
890 * @param pwidth DOCUMENT ME!
\r
891 * @param pheight DOCUMENT ME!
\r
892 * @param pi DOCUMENT ME!
\r
894 * @return DOCUMENT ME!
\r
896 * @throws PrinterException DOCUMENT ME!
\r
898 public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
\r
900 throws PrinterException
\r
903 int annotationHeight = 0;
\r
904 AnnotationLabels labels = null;
\r
905 if (av.showAnnotation)
\r
907 annotationHeight = annotationPanel.adjustPanelHeight();
\r
908 labels = new AnnotationLabels(av);
\r
911 int hgap = av.charHeight;
\r
912 if (av.scaleAboveWrapped)
\r
913 hgap += av.charHeight;
\r
915 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
917 + annotationHeight;
\r
919 int idWidth = calculateIdWidth().width + 4;
\r
921 int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
\r
924 int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1);
\r
926 pg.setColor(Color.white);
\r
927 pg.fillRect(0, 0, pwidth, pheight);
\r
928 pg.setFont(av.getFont());
\r
932 pg.setColor(Color.black);
\r
934 pg.translate(0, -pi * pheight);
\r
936 pg.setClip(0, pi * pheight, pwidth, pheight);
\r
939 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
940 av.getFont().getSize());
\r
941 pg.setFont(italic);
\r
945 for (int i = 0; i < av.alignment.getHeight(); i++)
\r
947 SequenceI s = av.alignment.getSequenceAt(i);
\r
948 String string = s.getDisplayId( av.getShowJVSuffix());
\r
950 pg.drawString(string, 0,
\r
951 ( (i * av.charHeight) + ypos + av.charHeight) -
\r
952 (av.charHeight / 5));
\r
954 if (labels != null)
\r
958 (av.getAlignment().getHeight() * av.charHeight));
\r
960 pg.setFont(av.getFont());
\r
961 labels.drawComponent(pg, idWidth);
\r
962 pg.setFont(italic);
\r
965 (av.getAlignment().getHeight() * av.charHeight));
\r
970 while (ypos < totalHeight);
\r
972 pg.translate(idWidth, 0);
\r
974 seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
\r
976 if ( (pi * pheight) < totalHeight)
\r
978 return Printable.PAGE_EXISTS;
\r
983 return Printable.NO_SUCH_PAGE;
\r
987 void makeAlignmentImage(int type, File file)
\r
989 int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;
\r
990 int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth);
\r
991 if (idPanel.getWidth() == 0)
\r
993 width += calculateIdWidth().getWidth() + 4;
\r
996 if (av.getWrapAlignment())
\r
998 height = getWrappedHeight();
\r
999 if (System.getProperty("java.awt.headless") != null
\r
1000 && System.getProperty("java.awt.headless").equals("true"))
\r
1002 width = alignFrame.getWidth() - 22;
\r
1006 width = seqPanel.getWidth() + idPanel.getWidth();
\r
1009 else if (av.getShowAnnotation())
\r
1011 height += annotationPanel.adjustPanelHeight() + 3;
\r
1014 jalview.util.ImageMaker im;
\r
1015 if(type==jalview.util.ImageMaker.PNG)
\r
1016 im = new jalview.util.ImageMaker(this,
\r
1017 jalview.util.ImageMaker.PNG,
\r
1018 "Create PNG image from alignment",
\r
1019 width, height, file, null);
\r
1021 im = new jalview.util.ImageMaker(this,
\r
1022 jalview.util.ImageMaker.EPS,
\r
1023 "Create EPS file from alignment",
\r
1024 width, height, file, alignFrame.getTitle() );
\r
1028 if (av.getWrapAlignment())
\r
1030 if(im.getGraphics()!=null)
\r
1032 printWrappedAlignment(im.getGraphics(), width, height, 0);
\r
1038 if(im.getGraphics()!=null)
\r
1040 printUnwrapped(im.getGraphics(), width, height, 0);
\r
1045 catch (OutOfMemoryError err)
\r
1047 System.out.println("########################\n"
\r
1048 + "OUT OF MEMORY " + file + "\n"
\r
1049 + "########################");
\r
1051 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1052 "Out of Memory Creating Image!!"
\r
1054 "\nSee help files for increasing Java Virtual Machine memory."
\r
1055 , "Out of memory",
\r
1056 JOptionPane.WARNING_MESSAGE);
\r
1057 System.out.println("Create IMAGE: " + err);
\r
1061 catch (Exception ex)
\r
1063 ex.printStackTrace();
\r
1069 public void makeEPS(File epsFile)
\r
1071 makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
\r
1077 public void makePNG(File pngFile)
\r
1079 makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
\r
1082 public void makePNGImageMap(File imgMapFile, String imageName)
\r
1084 ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
\r
1085 //////////////////////////////////////////////
\r
1086 int idWidth = calculateIdWidth().width + 4;
\r
1087 FontMetrics fm = getFontMetrics(av.getFont());
\r
1088 int scaleHeight = av.charHeight + fm.getDescent();
\r
1091 //////////////////////////////////
\r
1092 if (imgMapFile != null)
\r
1096 int s, sSize = av.alignment.getHeight(),
\r
1097 res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
\r
1098 StringBuffer text = new StringBuffer();
\r
1099 PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
\r
1100 out.println(jalview.io.HTMLOutput.getImageMapHTML());
\r
1101 out.println("<img src=\"" + imageName +
\r
1102 "\" border=\"0\" usemap=\"#Map\" >"
\r
1103 + "<map name=\"Map\">");
\r
1105 for (s = 0; s < sSize; s++)
\r
1107 sy = s * av.charHeight + scaleHeight;
\r
1109 SequenceI seq = av.alignment.getSequenceAt(s);
\r
1110 SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures();
\r
1111 SequenceGroup[] groups = av.alignment.findAllGroups(seq);
\r
1112 for(res =0; res<alwidth; res++)
\r
1114 text = new StringBuffer();
\r
1115 Object obj = null;
\r
1116 if(av.alignment.isNucleotide())
\r
1117 obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res)+"" );
\r
1119 obj = ResidueProperties.aa2Triplet.get(
\r
1120 seq.getCharAt(res) + "");
\r
1125 String triplet = obj.toString();
\r
1126 int alIndex = seq.findPosition(res);
\r
1127 gSize = groups.length;
\r
1128 for (g = 0; g < gSize; g++)
\r
1130 if(text.length()<1)
\r
1132 text.append("<area shape=\"rect\" coords=\""
\r
1133 + (idWidth + res * av.charWidth) + ","
\r
1135 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1136 + (av.charHeight + sy) + "\""
\r
1137 + " onMouseOver=\"toolTip('"
\r
1138 + alIndex + " " + triplet );
\r
1141 if(groups[g].getStartRes()<res && groups[g].getEndRes()>res)
\r
1142 text.append("<br><em>" + groups[g].getName() + "</em>");
\r
1145 if (features != null)
\r
1147 if(text.length()<1)
\r
1149 text.append("<area shape=\"rect\" coords=\""
\r
1150 + (idWidth + res * av.charWidth) + ","
\r
1152 + (idWidth + (res + 1) * av.charWidth) + ","
\r
1153 + (av.charHeight + sy) + "\""
\r
1154 + " onMouseOver=\"toolTip('"
\r
1155 + alIndex + " " + triplet );
\r
1157 fSize = features.length;
\r
1158 for (f = 0; f < fSize; f++)
\r
1161 if ( (features[f].getBegin() <= seq.findPosition(res)) &&
\r
1162 (features[f].getEnd() >= seq.findPosition(res)))
\r
1164 if (features[f].getType().equals("disulfide bond"))
\r
1166 if (features[f].getBegin() == seq.findPosition(res)
\r
1167 || features[f].getEnd() == seq.findPosition(res))
\r
1169 text.append("<br>disulfide bond " + features[f].getBegin() + ":" +
\r
1170 features[f].getEnd());
\r
1175 text.append("<br>");
\r
1176 text.append(features[f].getType());
\r
1177 if (features[f].getDescription() != null && !features[f].getType().equals(features[f].getDescription()))
\r
1178 text.append(" " + features[f].getDescription());
\r
1180 if (features[f].getValue("status") != null )
\r
1182 text.append(" (" + features[f].getValue("status") + ")");
\r
1189 if(text.length()>1)
\r
1191 text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">");
\r
1192 out.println(text.toString());
\r
1196 out.println("</map></body></html>");
\r
1200 catch (Exception ex)
\r
1202 ex.printStackTrace();
\r
1204 } ///////////END OF IMAGE MAP
\r
1208 int getWrappedHeight()
\r
1210 int seqPanelWidth = seqPanel.seqCanvas.getWidth();
\r
1212 //If headless, seqPanel will have 0 width
\r
1213 if (System.getProperty("java.awt.headless") != null
\r
1214 && System.getProperty("java.awt.headless").equals("true"))
\r
1216 int idWidth = calculateIdWidth().width + 4;
\r
1217 seqPanelWidth = alignFrame.getWidth() - idWidth;
\r
1220 int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
\r
1224 int hgap = av.charHeight;
\r
1225 if (av.scaleAboveWrapped)
\r
1226 hgap += av.charHeight;
\r
1228 int annotationHeight = 0;
\r
1229 if (av.showAnnotation)
\r
1231 annotationHeight = annotationPanel.adjustPanelHeight();
\r
1234 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
1236 + annotationHeight;
\r
1238 int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight;
\r
1246 * @author $author$
\r
1247 * @version $Revision$
\r
1253 * Creates a new Preview object.
\r
1255 * @param image DOCUMENT ME!
\r
1257 public Preview(Image image)
\r
1259 setResizable(true);
\r
1260 setSize(image.getWidth(this), image.getHeight(this));
\r
1262 getContentPane().setLayout(new BorderLayout());
\r
1263 getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER);
\r
1272 * @author $author$
\r
1273 * @version $Revision$
\r
1275 class PreviewPanel
\r
1281 * Creates a new PreviewPanel object.
\r
1283 * @param image DOCUMENT ME!
\r
1285 public PreviewPanel(Image image)
\r
1287 this.image = image;
\r
1293 * @param g DOCUMENT ME!
\r
1295 public void paintComponent(Graphics g)
\r
1297 if (image != null)
\r
1299 g.drawImage(image, 0, 0, this);
\r
1303 System.out.println("DEBUG:image is null");
\r