X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=75729c330775e2b93ab5067126233e926b726e18;hb=24efbd38f2c3dceaf6d3e305eef41ba0b0c9ebdc;hp=fcb5a57a4849009c96b240c5f8ce0ffc9b584276;hpb=bfdb9a55949b38a89878959278a8b8ed82a55e49;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index fcb5a57..75729c3 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,145 @@ 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; + + // this value is set false when selection area being dragged + boolean fastPaint = true; - public AlignmentPanel(AlignFrame af, AlignViewport av) + 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, this); - scorePanel = new ScorePanel(av); 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); + + + 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 ); + RefreshPanels(); + } + }); + hscroll.addAdjustmentListener(this); vscroll.addAdjustmentListener(this); addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent evt) + public void componentResized(ComponentEvent evt) { RefreshPanels(); } }); + + setFocusable(true); + addKeyListener(new KeyAdapter() + { + public void keyPressed(KeyEvent evt) + { + switch(evt.getKeyCode()) + { + case 27: // escape key + av.setSelectionGroup(null); + RefreshPanels(); + 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++; + } + + return new Dimension(idWidth, 12); } + public void highlightSearchResults(int [] results) { seqPanel.seqCanvas.highlightSearchResults( results ); @@ -73,21 +186,34 @@ 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); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + RefreshPanels(); + } + }); + } + 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); + + RefreshPanels(); - hscroll.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); } @@ -98,8 +224,8 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if(av.getConservationSelected()) { - Alignment al = (Alignment)av.getAlignment(); - Conservation c = new Conservation("All", + Alignment al = (Alignment)av.getAlignment(); + Conservation c = new Conservation("All", ResidueProperties.propHash, 3, al.getSequences(), 0, al.getWidth() ); @@ -110,180 +236,92 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene av.setGlobalColourScheme( ccs ); } - seqPanel.seqCanvas.paintFlag = true; - repaint(); + + RefreshPanels(); } - /* - 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)); - } - } + public void RefreshPanels() + { + requestFocus(); + invalidate(); - sg.cs = cs; + Dimension d = idPanel.idCanvas.getPreferredSize(); + idPanelHolder.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - // 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); + if (av.getWrapAlignment()) + { + int max = av.alignment.getWidth() / + (seqPanel.seqCanvas.getWidth() / av.charWidth) + 1; + vscroll.setValues(0, 1, 0, max); } - else if( !showConservation && sg.cs instanceof ConservationColourScheme) + else { - ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; - sg.cs = ccs.cs; + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); + setScrollValues(av.getStartRes(), av.getStartSeq()); } - } - repaint(); - } - - boolean isNewSelection(SequenceGroup sg) - { - 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(up) + { + if(vscroll.getValue()<1) + return false; + fastPaint = false; + vscroll.setValue(vscroll.getValue() - 1); + } else - return seqCanvas.globalColorScheme; + { + if(vextent+vscroll.getValue() >= av.getAlignment().getHeight()) + return false; + fastPaint = false; + vscroll.setValue(vscroll.getValue() + 1); + } + fastPaint = true; + return true; } -*/ -/* public void setColourScheme(jalview.schemes.ColourSchemeI cs, boolean conservation) + public boolean scrollRight(boolean right) { - 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 (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; } - 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 +337,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 +355,54 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene if (evt.getSource() == vscroll) { - int offy = vscroll.getValue(); + int offy = vscroll.getValue(); + if (av.getWrapAlignment()) + { + av.setStartRes( vscroll.getValue() * av.getChunkWidth()); + } + 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 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 +435,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 +444,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); + + int row = pi*noChunksOnPage; + pg.setColor(Color.black); + for(int ypos=2*av.charHeight; + ypos <= pheight && row*chunkWidth