X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=b339e5165f97191d5e122dbdb11927c52bac271f;hb=5150ffd5baa1f58bb6b4059616bc6b9050326553;hp=506fb0967b8e4dc6d61b410413fe0838b7ed2613;hpb=46be82307a1be9c637e0f3e2a34631692731eeb7;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 506fb09..b339e51 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -11,6 +11,7 @@ import java.io.*; import java.awt.image.*; import org.jibble.epsgraphics.*; import javax.imageio.*; +import javax.swing.*; @@ -22,10 +23,13 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene SeqPanel seqPanel; IdPanel idPanel; IdwidthAdjuster idwidthAdjuster; - SecondaryStructurePanel ssPanel; public AlignFrame alignFrame; ScalePanel scalePanel; - ScorePanel scorePanel; + AnnotationPanel annotationPanel; + AnnotationLabels alabels; + + // this value is set false when selection area being dragged + boolean fastPaint = true; public AlignmentPanel(AlignFrame af, final AlignViewport av) { @@ -35,51 +39,29 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene idPanel = new IdPanel (av, this); scalePanel = new ScalePanel(av, this); - scorePanel = new ScorePanel(av); - ssPanel = new SecondaryStructurePanel(av); - - secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER); idPanelHolder.add(idPanel, BorderLayout.CENTER); idwidthAdjuster = new IdwidthAdjuster(this); idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); - Dimension d = calculateIdWidth(); - d.setSize( d.width+4, d.height); - idPanel.idCanvas.setPreferredSize( d ); - hscrollFillerPanel.setPreferredSize( d ); + annotationPanel = new AnnotationPanel(this); + alabels = new AnnotationLabels(this); - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - scorePanelHolder.add(scorePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setViewportView(annotationPanel); + annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + fontChanged(); - if(seqPanel.seqCanvas.getWidth()==0) - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - setScrollValues(0,0); - Dimension d = calculateIdWidth(); - d.setSize( d.width+4, d.height); - idPanel.idCanvas.setPreferredSize( d ); - hscrollFillerPanel.setPreferredSize( d ); - RefreshPanels(); - } - }); + scalePanelHolder.add(scalePanel, BorderLayout.CENTER); + seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + setScrollValues(0, 0); hscroll.addAdjustmentListener(this); vscroll.addAdjustmentListener(this); - addComponentListener(new ComponentAdapter() - { - public void componentResized(ComponentEvent evt) - { - RefreshPanels(); - } - }); - setFocusable(true); addKeyListener(new KeyAdapter() { @@ -89,34 +71,39 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene { case 27: // escape key av.setSelectionGroup(null); - RefreshPanels(); - break; - case KeyEvent.VK_X: - alignFrame.cut_actionPerformed(null); - break; - case KeyEvent.VK_C: - alignFrame.copy_actionPerformed(null); - break; - case KeyEvent.VK_V: - alignFrame.paste(true); - break; - case KeyEvent.VK_A: - alignFrame.selectAllSequenceMenuItem_actionPerformed(null); + repaint(); break; + case KeyEvent.VK_DOWN: alignFrame.moveSelectedSequences(false); break; case KeyEvent.VK_UP: alignFrame.moveSelectedSequences(true); break; - case KeyEvent.VK_F: - alignFrame.findMenuItem_actionPerformed(null); - break; } } }); } + public void fontChanged() + { + // set idCanvas bufferedImage to null + // to prevent drawing old image + FontMetrics fm = getFontMetrics(av.getFont()); + + scalePanelHolder.setPreferredSize(new Dimension(10, av.charHeight+fm.getDescent())); + idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight+fm.getDescent())); + + idPanel.idCanvas.gg = null; + annotationPanel.adjustPanelHeight(); + Dimension d = calculateIdWidth(); + d.setSize(d.width + 4, d.height); + idPanel.idCanvas.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(d); + repaint(); + } + + Dimension calculateIdWidth() { Graphics g = this.getGraphics(); @@ -146,6 +133,20 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene i++; } + // Also check annotation label widths + i=0; + if(al.getAlignmentAnnotation()!=null) + { + fm = g.getFontMetrics(alabels.getFont()); + while (i < al.getAlignmentAnnotation().length) + { + String label = al.getAlignmentAnnotation()[i].label; + if (fm.stringWidth(label) > idWidth) + idWidth = fm.stringWidth(label); + i++; + } + } + return new Dimension(idWidth, 12); } @@ -155,12 +156,17 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene seqPanel.seqCanvas.highlightSearchResults( results ); // do we need to scroll the panel? - if(results!=null && (av.getStartSeq()>results[0] - || av.getEndSeq()results[1] - || av.getEndRes() start + || av.getEndRes() < end + || (av.getStartSeq() > results[0] + || av.getEndSeq() < results[0])) + setScrollValues(start, results[0]); + } } @@ -176,35 +182,25 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } - public void setGraphPanelVisible(boolean b) + public void setAnnotationVisible(boolean b) { - idSpaceFillerPanel.setVisible(b); - scorePanelHolder.setVisible(b); - - RefreshPanels(); - // bit annoying to call this twice, can you do better? - RefreshPanels(); + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); } - public void setSecondaryStructureVisible(boolean b) - { - secondaryPanelHolder.setVisible(b); - RefreshPanels(); - } public void setWrapAlignment(boolean wrap) { - scorePanelHolder.setVisible(!wrap); scalePanelHolder.setVisible(!wrap); - secondaryPanelHolder.setVisible(!wrap); - hscroll.setVisible(!wrap); - idwidthAdjuster.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); + + av.setShowAnnotation(!wrap); + annotationScroller.setVisible(!wrap); + annotationSpaceFillerHolder.setVisible(!wrap); idSpaceFillerPanel1.setVisible(!wrap); - RefreshPanels(); + repaint(); } @@ -222,46 +218,16 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene al.getWidth() ); c.calculate(); - c.verdict(false, 100); + c.verdict(false, av.ConsPercGaps); ConservationColourScheme ccs = new ConservationColourScheme(c, cs); av.setGlobalColourScheme( ccs ); } - RefreshPanels(); + repaint(); } - public void RefreshPanels() - { - - requestFocus(); - invalidate(); - idPanelHolder.setPreferredSize(idPanel.idCanvas.getPreferredSize()); - if(idPanel.idCanvas.getPreferredSize()!=null) - hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.getPreferredSize().width, 12)); - idSpaceFillerPanel1.setPreferredSize(new Dimension(500, - av.charHeight / 2 + 12)); - scalePanelHolder.setPreferredSize(new Dimension(500, - av.charHeight / 2 + 12)); - - if (av.getWrapAlignment()) - { - int max = av.alignment.getWidth() / - (seqPanel.seqCanvas.getWidth() / av.charWidth)+1 ; - - vscroll.setValues(0, 1, 0, max); - } - else - { - av.getConsensus(true); - if (overviewPanel != null) - overviewPanel.updateOverviewImage(); - setScrollValues(av.getStartRes(), av.getStartSeq()); - } - - repaint(); - } int hextent = 0; int vextent = 0; @@ -273,39 +239,46 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene { if(vscroll.getValue()<1) return false; + fastPaint = false; vscroll.setValue(vscroll.getValue() - 1); } else { if(vextent+vscroll.getValue() >= av.getAlignment().getHeight()) return false; + fastPaint = false; vscroll.setValue(vscroll.getValue() + 1); } - + fastPaint = true; return true; } public boolean scrollRight(boolean right) { - if(right) - { - if(hscroll.getValue()<1) - return false; - hscroll.setValue(hscroll.getValue() - 1); - } - else - { - if(hextent+hscroll.getValue() >= av.getAlignment().getWidth()) - return false; - hscroll.setValue(hscroll.getValue() + 1); - } - return true; - } + if (right) + { + if (hscroll.getValue() < 1) + return false; + fastPaint = false; + hscroll.setValue(hscroll.getValue() - 1); + } + else + { + if (hextent + hscroll.getValue() >= av.getAlignment().getWidth()) + return false; + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); + } + fastPaint = true; + return true; + } public void setScrollValues(int x, int y) { + av.setEndRes(x + seqPanel.seqCanvas.getWidth()/av.getCharWidth()-1); + hextent = seqPanel.seqCanvas.getWidth()/av.charWidth; vextent = seqPanel.seqCanvas.getHeight()/av.charHeight; @@ -329,13 +302,15 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene hscroll.setValues(x,hextent,0,av.getAlignment().getWidth()); vscroll.setValues(y,vextent,0,av.getAlignment().getHeight() ); - repaint(); + } public void adjustmentValueChanged(AdjustmentEvent evt) { + int oldX = av.getStartRes(); + int oldY = av.getStartSeq(); if (evt.getSource() == hscroll) { @@ -349,7 +324,9 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene int offy = vscroll.getValue(); if (av.getWrapAlignment()) { - av.setStartRes( vscroll.getValue() * av.getChunkWidth()); + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + av.setStartRes( vscroll.getValue() * rowSize ); + av.setEndRes( (vscroll.getValue()+1) * rowSize ); } else { @@ -358,11 +335,47 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } } - if(overviewPanel!=null) overviewPanel.setBoxPosition(); - repaint(); + if(av.getWrapAlignment() || !fastPaint) + repaint(); + else + { + idPanel.idCanvas.fastPaint(av.getStartSeq() - oldY); + seqPanel.seqCanvas.fastPaint(av.getStartRes() - oldX, + av.getStartSeq() - oldY); + + scalePanel.repaint(); + if (av.getShowAnnotation()) + annotationPanel.fastPaint(av.getStartRes() - oldX); + } + + } + + + public void paintComponent(Graphics g) + { + invalidate(); + Dimension d = idPanel.idCanvas.getPreferredSize(); + idPanelHolder.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); + validate(); + + if (av.getWrapAlignment()) + { + int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + vscroll.setMaximum(max); + vscroll.setUnitIncrement(1); + vscroll.setVisibleAmount(1); + } + else + { + setScrollValues(av.getStartRes(), av.getStartSeq()); + } + + + } public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException @@ -381,139 +394,159 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = calculateIdWidth().width; + int idWidth = calculateIdWidth().width + 4; + FontMetrics fm = getFontMetrics(av.getFont()); + int scaleHeight = av.charHeight + fm.getDescent(); + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - pg.setColor(Color.white); - pg.fillRect(0,0,pwidth, pheight); - pg.setFont( av.getFont() ); + //////////////////////////////////// + /// How many sequences and residues can we fit on a printable page? + int totalRes = (pwidth - idWidth) / av.getCharWidth(); - //////////////////////////////////// - /// How many sequences and residues can we fit on a printable page? - int totalRes = (pwidth - idWidth)/av.getCharWidth(); - int totalSeq = (int)((pheight - 30)/av.getCharHeight())-1; - int pagesWide = av.getAlignment().getWidth() / totalRes +1; - int pagesHigh = av.getAlignment().getHeight() / totalSeq +1; + int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) - 1; - if (pi >= pagesWide*pagesHigh) - return Printable.NO_SUCH_PAGE; + int pagesWide = av.getAlignment().getWidth() / totalRes + 1; - ///////////////////////////// - /// Only print these sequences and residues on this page - int startRes, endRes, startSeq, endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = startRes + totalRes-1; - if(endRes>av.getAlignment().getWidth()) - endRes = av.getAlignment().getWidth(); + ///////////////////////////// + /// Only print these sequences and residues on this page + int startRes, endRes, startSeq, endSeq; + startRes = (pi % pagesWide) * totalRes; + endRes = startRes + totalRes - 1; + if (endRes > av.getAlignment().getWidth()-1) + endRes = av.getAlignment().getWidth()-1; - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; - if(endSeq > av.getAlignment().getHeight()) - endSeq = av.getAlignment().getHeight(); + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; + if (endSeq > av.getAlignment().getHeight()) + endSeq = av.getAlignment().getHeight(); + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - //////////////// - //draw Scale - pg.translate(30,0); - scalePanel.drawScale(pg, startRes, endRes, pwidth-idWidth); + if (av.showAnnotation) + pagesHigh += annotationPanel.getHeight(); - pg.translate(-30, 30); - //////////////// - // Draw the ids - Color currentColor=null; - Color currentTextColor=null; - for(int i=startSeq; i= pagesWide * pagesHigh) + return Printable.NO_SUCH_PAGE; + + //draw Scale + pg.translate(idWidth, 0); + scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); + pg.translate( -idWidth, scaleHeight); + //////////////// + // Draw the ids + Color currentColor = null; + Color currentTextColor = null; + for (int i = startSeq; i < endSeq; i++) { - currentColor = av.getAlignment().getSequenceAt(i).getColor(); - currentTextColor = Color.black; - } + if (av.getSelectionGroup() != null && + av.getSelectionGroup().sequences. + contains(av.getAlignment().getSequenceAt(i))) + { + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getAlignment().getSequenceAt(i).getColor(); + currentTextColor = Color.black; + } + + pg.setColor(currentColor); + pg.fillRect(0, + jalview.analysis.AlignmentUtil.getPixelHeight(startSeq, i, + av.getCharHeight()), + idWidth, + av.getCharHeight()); - pg.setColor(currentColor); - pg.fillRect(0, jalview.analysis.AlignmentUtil.getPixelHeight(startSeq, i, av.getCharHeight()), - idWidth, - av.getCharHeight()); + pg.setColor(currentTextColor); - pg.setColor(currentTextColor); + String string = av.getAlignment().getSequenceAt(i).getName(); + if (av.getShowFullId()) + string = av.getAlignment().getSequenceAt(i).getDisplayId(); - String string = av.getAlignment().getSequenceAt(i).getName(); - if(av.getShowFullId()) - string = av.getAlignment().getSequenceAt(i).getDisplayId(); + pg.drawString(string, 0, jalview.analysis.AlignmentUtil.getPixelHeight + (startSeq, i, av.getCharHeight()) + av.getCharHeight() - + (av.getCharHeight() / 5)); + } - pg.drawString(string, 0, jalview.analysis.AlignmentUtil.getPixelHeight - (startSeq, i, av.getCharHeight()) + av.getCharHeight() - (av.getCharHeight() / 5)); - } + // draw main sequence panel + pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, + startRes, startSeq, 0); - // draw main sequence panel - pg.translate(idWidth+4,0); - pg.setClip(0,0,pwidth-idWidth, pheight); - seqPanel.seqCanvas.drawPanel(pg,startRes,endRes,startSeq,endSeq,startRes,startSeq,0); - return Printable.PAGE_EXISTS; + if (av.showAnnotation && endSeq == av.alignment.getHeight()) + { + pg.translate( -idWidth, (endSeq - startSeq) * av.charHeight); + alabels.drawComponent( (Graphics2D) pg); + pg.translate(idWidth, 0); + annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes+1); + } + + return Printable.PAGE_EXISTS; + } public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { + int idWidth = calculateIdWidth().width + 4; + + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); + int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * + ( (av.alignment.getWidth() + / resWidth) + 1) * av.charHeight; - int idWidth = calculateIdWidth().width; - if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth) - pwidth = seqPanel.seqCanvas.getWidth() + idWidth; + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); + //////////////// + // Draw the ids + pg.setColor(Color.black); - pg.setColor(Color.white); - pg.fillRect(0,0,pwidth, pheight); - pg.setFont( av.getFont() ); + pg.translate(0, -pi * pheight); - //////////////////////////////////// - /// How many sequences and residues can we fit on a printable page? - AlignmentI da = av.alignment; - int endy = da.getHeight(); - int chunkHeight = (da.getHeight() + 2)*av.charHeight; - int chunkWidth = (pwidth-idWidth)/av.charWidth; + pg.setClip(0,pi*pheight,pwidth, pheight); - int noChunksOnPage = pheight / chunkHeight; - int totalChunks = da.getWidth() / chunkWidth; + int ypos = 2 * av.charHeight; + do + { + for (int i = 0; i < av.alignment.getHeight(); i++) + { + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getName(); + if (av.getShowFullId()) + string = s.getDisplayId(); - if ( pi*noChunksOnPage > totalChunks ) - return Printable.NO_SUCH_PAGE; + pg.drawString(string, 0, + AlignmentUtil.getPixelHeight(0, i, av.charHeight) + + ypos + + av.charHeight - (av.charHeight / 5)); - //////////////// - // Draw the ids - pg.setClip(0,0,pwidth, noChunksOnPage*chunkHeight); + } - int row = pi*noChunksOnPage; - pg.setColor(Color.black); - for(int ypos=2*av.charHeight; - ypos <= pheight && row*chunkWidth