X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=997966fa97e8e0fc17bc886afcfced1ff2b4512f;hb=ff2e8d0b23e91c4d7f19dd1922e48e5a718ee0f1;hp=33b86651dde4deced7d41e611158f823453d46a2;hpb=4679c58949f642fd64e9726ec5bf2c3f338a0861;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 33b8665..997966f 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1,11 +1,20 @@ package jalview.gui; import jalview.jbgui.GAlignmentPanel; +import jalview.schemes.*; +import jalview.analysis.*; +import jalview.datamodel.*; import java.awt.*; -import java.awt.image.*; import java.awt.event.*; import java.awt.print.*; -import javax.swing.*; + +import com.sun.image.codec.jpeg.*; +import java.io.*; +import java.awt.image.*; + +import org.jibble.epsgraphics.*; +import javax.imageio.*; + public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable { @@ -14,21 +23,33 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene OverviewPanel overviewPanel; SeqPanel seqPanel; IdPanel idPanel; + SecondaryStructurePanel ssPanel; public AlignFrame alignFrame; ScalePanel scalePanel; ScorePanel scorePanel; - 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); + + scalePanel = new ScalePanel(av, this); scorePanel = new ScorePanel(av); + ssPanel = new SecondaryStructurePanel(av); + + secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER); idPanelHolder.add(idPanel, BorderLayout.CENTER); - idPanel.addNotify(); + IdwidthAdjuster iap = new IdwidthAdjuster(this); + idSpaceFillerPanel1.add(iap, 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); @@ -39,13 +60,86 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent evt) + public void componentResized(ComponentEvent evt) { RefreshPanels(); } }); + + + // hscroll.setFocusable(false); + // vscroll.setFocusable(false); + 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: + 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); + 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; + } + } + }); } + 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 ); @@ -74,51 +168,134 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public void setGraphPanelVisible(boolean b) { - scorePanelHolder.setVisible(b); idSpaceFillerPanel.setVisible(b); + scorePanelHolder.setVisible(b); + + RefreshPanels(); + // bit annoying to call this twice, can you do better? + RefreshPanels(); + } + + public void setSecondaryStructureVisible(boolean b) + { + secondaryPanelHolder.setVisible(b); RefreshPanels(); } public void setWrapAlignment(boolean wrap) { - scalePanelHolder.setVisible(!wrap); - scorePanelHolder.setVisible(!wrap); + scorePanelHolder.setVisible(!wrap); + scalePanelHolder.setVisible(!wrap); + secondaryPanelHolder.setVisible(!wrap); - hscroll.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); - } + hscroll.setVisible(!wrap); + idSpaceFillerPanel.setVisible(!wrap); + idSpaceFillerPanel1.setVisible(!wrap); + + RefreshPanels(); - public void setColourScheme(jalview.schemes.ColourSchemeI cs, boolean conservation) - { - seqPanel.setColourScheme(cs, conservation); - if(overviewPanel!=null) - overviewPanel.updateOverviewImage(); } - public void RefreshPanels() + public void setColourScheme() { - invalidate(); - seqPanel.seqCanvas.paintFlag = true; - idPanel.idCanvas.paintFlag = true; - idPanelHolder.setPreferredSize( idPanel.idCanvas.getPreferredSize() ); - setScrollValues(av.getStartRes(), av.getStartSeq()); - av.getConsensus(true); - repaint(); - validate(); - if(overviewPanel!=null) - overviewPanel.updateOverviewImage(); + ColourSchemeI cs = av.getGlobalColourScheme(); + + if(av.getConservationSelected()) + { + + Alignment al = (Alignment)av.getAlignment(); + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, al.getSequences(), 0, + al.getWidth() ); + + c.calculate(); + c.verdict(false, 100); + ConservationColourScheme ccs = new ConservationColourScheme(c, cs); + + av.setGlobalColourScheme( ccs ); + + } + RefreshPanels(); } + 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; + + int h = (av.alignment.getHeight() + 2) * av.charHeight; + vextent = seqPanel.seqCanvas.getHeight() / h; + vscroll.setValues(0, vextent, 0, max); + } + else + + setScrollValues(av.getStartRes(), av.getStartSeq()); + av.getConsensus(true); + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); + + validate(); + repaint(); + } int hextent = 0; int vextent = 0; + + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if(up) + { + if(vscroll.getValue()<1) + return false; + vscroll.setValue(vscroll.getValue() - 1); + } + else + { + if(vextent+vscroll.getValue() >= av.getAlignment().getHeight()) + return false; + vscroll.setValue(vscroll.getValue() + 1); + } + + 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; + } + + public void setScrollValues(int x, int y) { - hextent = (int)(seqPanel.seqCanvas.getWidth()/av.getCharWidth()); + hextent = seqPanel.seqCanvas.getWidth()/av.getCharWidth(); vextent = seqPanel.seqCanvas.getHeight()/av.getCharHeight(); if(hextent+x > av.getAlignment().getWidth()) @@ -135,6 +312,8 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene hscroll.setValues(x,hextent,0,av.getAlignment().getWidth()); vscroll.setValues(y,vextent,0,av.getAlignment().getHeight() ); + + repaint(); } @@ -147,43 +326,56 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene { int x = hscroll.getValue(); av.setStartRes(x); - av.setEndRes(x + (int)(seqPanel.seqCanvas.getWidth()/av.getCharWidth()-1)); + av.setEndRes(x + seqPanel.seqCanvas.getWidth()/av.getCharWidth()-1); } 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(); } - 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; + - //BufferedImage printImage = new BufferedImage(pwidth,pheight,BufferedImage.TYPE_INT_RGB); - // Graphics pg = printImage.getGraphics(); 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 = (int)((pwidth - idWidth)/av.getCharWidth()); + 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; @@ -207,17 +399,17 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene //////////////// //draw Scale - pg.translate(idWidth,0); - scalePanel.scaleCanvas.drawScale(pg, startRes, endRes, pwidth-idWidth); + pg.translate(30,0); + scalePanel.drawScale(pg, startRes, endRes, pwidth-idWidth); - pg.translate(-idWidth, 30); + pg.translate(-30, 30); //////////////// // Draw the ids Color currentColor=null; 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