X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=9b57ae1b2c53dc5cd5c7c88ff405e2208b26ed55;hb=8548008f4fbd321b445c7e69fbdffda26e21f457;hp=eda94a046dc545fda0470ac783de07a4eb213687;hpb=b455b63542dbdceadd35a6e1ba7a655aeebb410a;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index eda94a0..9b57ae1 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -7,6 +7,12 @@ import jalview.datamodel.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; +import java.io.*; +import java.awt.image.*; +import org.jibble.epsgraphics.*; +import javax.imageio.*; + + public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable { @@ -15,38 +21,146 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene OverviewPanel overviewPanel; SeqPanel seqPanel; IdPanel idPanel; + IdwidthAdjuster idwidthAdjuster; public AlignFrame alignFrame; ScalePanel scalePanel; - ScorePanel scorePanel; + AnnotationPanel annotationPanel; + AnnotationLabels alabels; - public AlignmentPanel(AlignFrame af, AlignViewport av) + // this value is set false when selection area being dragged + boolean fastPaint = true; + + public AlignmentPanel(AlignFrame af, final AlignViewport av) { alignFrame = af; this.av = av; seqPanel = new SeqPanel (av, this); idPanel = new IdPanel (av, this); - scalePanel = new ScalePanel(av); - scorePanel = new ScorePanel(av); + + scalePanel = new ScalePanel(av, this); idPanelHolder.add(idPanel, BorderLayout.CENTER); - idPanel.addNotify(); + idwidthAdjuster = new IdwidthAdjuster(this); + idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); + + annotationPanel = new AnnotationPanel(this); + alabels = new AnnotationLabels(this); + + annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setViewportView(annotationPanel); + annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + + Dimension d = calculateIdWidth(); + d.setSize( d.width+4, d.height); + idPanel.idCanvas.setPreferredSize( d ); + hscrollFillerPanel.setPreferredSize( d ); + scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - scorePanelHolder.add(scorePanel, BorderLayout.CENTER); seqPanelHolder.add(seqPanel, BorderLayout.CENTER); - setScrollValues(0,0); + + setScrollValues(0, 0); hscroll.addAdjustmentListener(this); vscroll.addAdjustmentListener(this); addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent evt) + public void componentResized(ComponentEvent evt) { - RefreshPanels(); + repaint(); } }); + + setFocusable(true); + addKeyListener(new KeyAdapter() + { + public void keyPressed(KeyEvent evt) + { + switch(evt.getKeyCode()) + { + case 27: // escape key + av.setSelectionGroup(null); + repaint(); + break; + case KeyEvent.VK_X: + if(evt.isControlDown()) + alignFrame.cut_actionPerformed(null); + break; + case KeyEvent.VK_C: + if(evt.isControlDown()) + alignFrame.copy_actionPerformed(null); + break; + case KeyEvent.VK_V: + if(evt.isControlDown()) + alignFrame.paste(true); + break; + case KeyEvent.VK_A: + if(evt.isControlDown()) + alignFrame.selectAllSequenceMenuItem_actionPerformed(null); + break; + case KeyEvent.VK_DOWN: + alignFrame.moveSelectedSequences(false); + break; + case KeyEvent.VK_UP: + alignFrame.moveSelectedSequences(true); + break; + case KeyEvent.VK_F: + if(evt.isControlDown()) + alignFrame.findMenuItem_actionPerformed(null); + break; + } + } + }); + } + + Dimension calculateIdWidth() + { + Graphics g = this.getGraphics(); + if(g==null) + { + javax.swing.JFrame f = new javax.swing.JFrame(); + f.addNotify(); + g = f.getGraphics(); + } + + FontMetrics fm = g.getFontMetrics(av.font); + AlignmentI al = av.getAlignment(); + + int i = 0; + int idWidth = 0; + String id; + while (i < al.getHeight() && al.getSequenceAt(i) != null) + { + SequenceI s = al.getSequenceAt(i); + if(av.getShowFullId()) + id = s.getDisplayId(); + else + id = s.getName(); + + if (fm.stringWidth(id) > idWidth) + idWidth = fm.stringWidth(id); + 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); } + public void highlightSearchResults(int [] results) { seqPanel.seqCanvas.highlightSearchResults( results ); @@ -73,21 +187,26 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } - public void setGraphPanelVisible(boolean b) + public void setAnnotationVisible(boolean b) { - scorePanelHolder.setVisible(b); - idSpaceFillerPanel.setVisible(b); - RefreshPanels(); + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); } + public void setWrapAlignment(boolean wrap) { - scalePanelHolder.setVisible(!wrap); - scorePanelHolder.setVisible(!wrap); + scalePanelHolder.setVisible(!wrap); + hscroll.setVisible(!wrap); + idwidthAdjuster.setVisible(!wrap); + + av.setShowAnnotation(!wrap); + annotationScroller.setVisible(!wrap); + annotationSpaceFillerHolder.setVisible(!wrap); + idSpaceFillerPanel1.setVisible(!wrap); + + repaint(); - hscroll.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); } @@ -98,192 +217,78 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if(av.getConservationSelected()) { - Alignment al = (Alignment)av.getAlignment(); - Conservation c = new Conservation("All", al.cons, + Alignment al = (Alignment)av.getAlignment(); + Conservation c = new Conservation("All", ResidueProperties.propHash, 3, al.getSequences(), 0, al.getWidth() ); c.calculate(); - c.verdict(false, 100); + c.verdict(false, av.ConsPercGaps); ConservationColourScheme ccs = new ConservationColourScheme(c, cs); av.setGlobalColourScheme( ccs ); } - seqPanel.seqCanvas.paintFlag = true; + repaint(); } - /* - seqCanvas.paintFlag = true; - if (av.getSelection().size() == 0) - { - seqCanvas.globalColorScheme = cs; - for (int i = 0; i < av.alignment.getGroups().size();i++) - { - SequenceGroup sg = (SequenceGroup)av.alignment.getGroups().elementAt(i); - sg.cs = cs; - if(!showConservation - && !(sg.cs instanceof Blosum62ColourScheme) - && sg.cs instanceof ConservationColourScheme) - { - // remove ConservationColouring from existing Conservation group - ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; - sg.cs = ccs.cs; - } - else if(showConservation && !(sg.cs instanceof ConservationColourScheme)) - { - // add ConservationColouring to new group - Conservation c = sg.getConservation(); - Alignment al = (Alignment) av.getAlignment(); - c = new Conservation("All", al.cons, - ResidueProperties.propHash, 3, sg.sequences, 0, - al.getWidth() ); - c.calculate(); - c.verdict(false, 100); - sg.setConservation(c); - sg.cs = new ConservationColourScheme(sg); - } - } - } - else - { - SequenceGroup sg = av.alignment.findGroup((Sequence)av.sel.sequenceAt(0)); - - if( isNewSelection(sg) ) - { - sg = av.getAlignment().addGroup(); - for (int i=0; i < av.getSelection().size(); i++) - { - av.alignment.removeFromGroup(av.alignment.findGroup( (Sequence) av. - sel.sequenceAt(i)), - (Sequence) av.sel.sequenceAt(i)); - av.alignment.addToGroup(sg, (Sequence) av.sel.sequenceAt(i)); - } - } - sg.cs = cs; + int hextent = 0; + int vextent = 0; - // Selection is made, we only want to change the conservationColour for selected group - if( showConservation - && !(sg.cs instanceof ConservationColourScheme) - && !(sg.cs instanceof Blosum62ColourScheme)) - { - Conservation c = sg.getConservation(); - Alignment al = (Alignment) av.getAlignment(); - - c = new Conservation("All", al.cons, - ResidueProperties.propHash, 3, sg.sequences, 0, - al.getWidth() ); - c.calculate(); - c.verdict(false, 100); - sg.setConservation(c); - sg.cs = new ConservationColourScheme(sg); + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if(up) + { + if(vscroll.getValue()<1) + return false; + fastPaint = false; + vscroll.setValue(vscroll.getValue() - 1); } - else if( !showConservation && sg.cs instanceof ConservationColourScheme) + else { - ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; - sg.cs = ccs.cs; + if(vextent+vscroll.getValue() >= av.getAlignment().getHeight()) + return false; + fastPaint = false; + vscroll.setValue(vscroll.getValue() + 1); } - } - repaint(); + fastPaint = true; + return true; } - boolean isNewSelection(SequenceGroup sg) + public boolean scrollRight(boolean right) { - if(sg==null) - return true; - - if(sg.getSize()!=av.getSelection().size()) - return true; - for(int i=0; i0) - return av.alignment.findGroup((Sequence)av.sel.sequenceAt(0)).cs; + if (right) + { + if (hscroll.getValue() < 1) + return false; + fastPaint = false; + hscroll.setValue(hscroll.getValue() - 1); + } else - return seqCanvas.globalColorScheme; - } -*/ - -/* public void setColourScheme(jalview.schemes.ColourSchemeI cs, boolean conservation) - { - seqPanel.setColourScheme(cs, conservation); - - av.setGlobalColourScheme(cs); - - if(overviewPanel!=null) - overviewPanel.updateOverviewImage(); - } - - void updateResidueView() - { - if (viewport.getSelection().size() == 0) - { - for (int i = 0; i < viewport.alignment.getGroups().size(); i++) - { - SequenceGroup sg = (SequenceGroup) viewport.alignment.getGroups().elementAt(i); - sg.setDisplayBoxes( viewBoxesMenuItem.isSelected() ); - sg.setDisplayText( viewTextMenuItem.isSelected() ); - sg.setColourText( colourTextMenuItem.isSelected() ); - } - } - else - { - SequenceGroup sg = viewport.alignment.findGroup( (Sequence) viewport.sel.sequenceAt(0)); - if (alignPanel.seqPanel.isNewSelection(sg)) - { - sg = viewport.getAlignment().addGroup(); - for (int i = 0; i < viewport.getSelection().size(); i++) - { - viewport.alignment.removeFromGroup(viewport.alignment.findGroup( ( - Sequence) viewport.sel.sequenceAt(i)), - (Sequence) viewport.sel.sequenceAt( - i)); - viewport.alignment.addToGroup(sg, - (Sequence) viewport.sel.sequenceAt(i)); - } - } - - sg.setDisplayBoxes(viewBoxesMenuItem.isSelected()); - sg.setDisplayText(viewTextMenuItem.isSelected()); - sg.setColourText(colourTextMenuItem.isSelected()); - } - alignPanel.RefreshPanels(); - }*/ - - - - public void RefreshPanels() - { - invalidate(); - seqPanel.seqCanvas.paintFlag = true; - idPanel.idCanvas.paintFlag = true; - idPanelHolder.setPreferredSize( idPanel.idCanvas.getPreferredSize() ); - setScrollValues(av.getStartRes(), av.getStartSeq()); - av.getConsensus(true); - validate(); - repaint(); - if(overviewPanel!=null) - overviewPanel.updateOverviewImage(); - + { + if (hextent + hscroll.getValue() >= av.getAlignment().getWidth()) + return false; + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); + } + fastPaint = true; + return true; } - int hextent = 0; - int vextent = 0; public void setScrollValues(int x, int y) { - hextent = seqPanel.seqCanvas.getWidth()/av.getCharWidth(); - vextent = seqPanel.seqCanvas.getHeight()/av.getCharHeight(); + hextent = seqPanel.seqCanvas.getWidth()/av.charWidth; + vextent = seqPanel.seqCanvas.getHeight()/av.charHeight; + + if(hextent > av.alignment.getWidth()) + hextent = av.alignment.getWidth(); + if(vextent > av.alignment.getHeight()) + vextent = av.alignment.getHeight(); if(hextent+x > av.getAlignment().getWidth()) x = av.getAlignment().getWidth()- hextent; @@ -299,13 +304,14 @@ 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) { @@ -316,28 +322,82 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if (evt.getSource() == vscroll) { - int offy = vscroll.getValue(); + int offy = vscroll.getValue(); + if (av.getWrapAlignment()) + { + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + av.setStartRes( vscroll.getValue() * rowSize ); + av.setEndRes( (vscroll.getValue()+1) * rowSize ); + } + else + { av.setStartSeq(offy); - av.setEndSeq(offy + seqPanel.seqCanvas.getHeight()/av.getCharHeight()); + av.setEndSeq(offy + seqPanel.seqCanvas.getHeight() / av.getCharHeight()); + } } if(overviewPanel!=null) overviewPanel.setBoxPosition(); - seqPanel.seqCanvas.paintFlag=true; - repaint(); + if(av.getWrapAlignment() || !fastPaint) + repaint(); + else + { + seqPanel.seqCanvas.fastPaint(av.getStartRes() - oldX, + av.getStartSeq() - oldY); + idPanel.idCanvas.fastPaint(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)); + + if (av.getWrapAlignment()) + { + int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + vscroll.setMaximum(max); + vscroll.setUnitIncrement(1); + vscroll.setVisibleAmount(1); + } + else + { + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); + setScrollValues(av.getStartRes(), av.getStartSeq()); + } + + validate(); + + } public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException { - pg.translate((int)pf.getImageableX(), (int)pf.getImageableY()); - int pwidth = (int)pf.getImageableWidth(); - int pheight = (int)pf.getImageableHeight(); - int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth(); + int pwidth = (int) pf.getImageableWidth(); + int pheight = (int) pf.getImageableHeight(); + + if (av.getWrapAlignment()) + return printWrappedAlignment(pg, pwidth,pheight, pi); + else + return printUnwrapped(pg,pwidth, pheight,pi); + } + + public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException + { + + int idWidth = calculateIdWidth().width + 4; + pg.setColor(Color.white); pg.fillRect(0,0,pwidth, pheight); @@ -370,7 +430,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene //////////////// //draw Scale pg.translate(idWidth,0); - scalePanel.scaleCanvas.drawScale(pg, startRes, endRes, pwidth-idWidth); + scalePanel.drawScale(pg, startRes, endRes, pwidth-idWidth); pg.translate(-idWidth, 30); //////////////// @@ -379,7 +439,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene Color currentTextColor=null; for(int i=startSeq; i totalChunks ) + return Printable.NO_SUCH_PAGE; + + //////////////// + // Draw the ids + pg.setClip(0,0,pwidth, noChunksOnPage*chunkHeight); + + pg.setColor(Color.black); + + int rowSize = av.getEndRes() - av.getStartRes(); + // Draw the rest of the panels + + for(int ypos=2*av.charHeight, row=av.getEndRes(); row