X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=ab5fb17bdb6ac808581b722f15788bac4ed33ef1;hb=48555d99e5255063a40ed1818a9090dd88f9a665;hp=af8a6c06ab723aa553b035f36f5e8c98fe94fcae;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index af8a6c0..ab5fb17 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -16,14 +16,17 @@ import jalview.schemes.*; import jalview.datamodel.*; import jalview.analysis.*; import jalview.io.*; -import java.awt.event.*; +import MCview.*; import java.awt.*; +import java.awt.event.*; +import java.awt.print.*; import javax.swing.*; +import java.util.*; public class AlignFrame extends GAlignFrame { - AlignmentPanel alignPanel; - AlignViewport viewport; + final AlignmentPanel alignPanel; + final AlignViewport viewport; public AlignFrame(AlignmentI al) { super(); @@ -67,15 +70,42 @@ public class AlignFrame extends GAlignFrame protected void htmlMenuItem_actionPerformed(ActionEvent e) { - HTMLOutput htmlOutput = new HTMLOutput(viewport.getAlignment(), alignPanel.seqPanel.getColourScheme()); + HTMLOutput htmlOutput = new HTMLOutput(viewport); htmlOutput = null; } - public void saveAsPostscriptMenuItem_actionPerformed(ActionEvent e) + public void printMenuItem_actionPerformed(ActionEvent e) + { + //Putting in a thread avoids Swing painting problems + PrintThread thread = new PrintThread(); + thread.start(); + } + + class PrintThread extends Thread { + public void run() + { + PrinterJob printJob = PrinterJob.getPrinterJob(); + PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + printJob.setPrintable(alignPanel, pf); + if (printJob.printDialog()) + { + try + { + printJob.print(); + } + catch (Exception PrintException) + { + PrintException.printStackTrace(); + } + } + } } + + + public void closeMenuItem_actionPerformed(ActionEvent e) { try{ @@ -83,14 +113,96 @@ public class AlignFrame extends GAlignFrame }catch(Exception ex){} } - public void groupsMenuItem_actionPerformed(ActionEvent e) + ArrayList historyList = new ArrayList(); + ArrayList redoList = new ArrayList(); + + void updateEditMenuBar() { + if(historyList.size()>0) + { + undoMenuItem.setEnabled(true); + Object [] history = (Object[])historyList.get(0); + undoMenuItem.setText("Undo "+history[0]); + } + else + { + undoMenuItem.setEnabled(false); + undoMenuItem.setText("Undo"); + } + if(redoList.size()>0) + { + redoMenuItem.setEnabled(true); + Object [] history = (Object[])redoList.get(0); + redoMenuItem.setText("Redo "+history[0]); + } + else + { + redoMenuItem.setEnabled(false); + redoMenuItem.setText("Redo"); + } } - public void groupEditingMenuItem_actionPerformed(ActionEvent e) + public void addHistoryItem(String type) + { + // must make sure we add new sequence objects her, not refs to the existing sequences + redoList.clear(); + SequenceI[] seq = new SequenceI[viewport.getAlignment().getHeight()]; + for(int i=0; i500) newHeight=500; @@ -162,6 +275,7 @@ public class AlignFrame extends GAlignFrame public void remove2LeftMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("delete columns"); ColumnSelection colSel = viewport.getColumnSelection(); if (colSel.size() > 0) { @@ -174,6 +288,7 @@ public class AlignFrame extends GAlignFrame public void remove2RightMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("delete columns"); ColumnSelection colSel = viewport.getColumnSelection(); if (colSel.size() > 0) { @@ -188,12 +303,14 @@ public class AlignFrame extends GAlignFrame public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("delete gapped columns"); viewport.getAlignment().removeGaps(); alignPanel.RefreshPanels(); } public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("delete all gaps"); SequenceI current; int jSize; for (int i=0; i < viewport.getAlignment().getSequences().size();i++) @@ -214,24 +331,36 @@ public class AlignFrame extends GAlignFrame public void setGapCharMenuItem_actionPerformed(ActionEvent e) { - String thisChar = "-"; - String nextChar = "."; - if(viewport.getGapCharacter().equals("-")) + char thisChar = '-'; + char nextChar = '.'; + if(viewport.getGapCharacter()=='-') { - thisChar = "."; - nextChar = "-"; + thisChar = '.'; + nextChar = '-'; } setGapCharMenuItem.setText("Set gap character to \""+nextChar+"\""); viewport.setGapCharacter(thisChar); + alignPanel.RefreshPanels(); } + public void findMenuItem_actionPerformed(ActionEvent e) + { + JOptionPane op = new JOptionPane(); + JInternalFrame frame = op.createInternalFrame(this, "Find"); + Finder finder = new Finder(viewport, alignPanel, frame); + frame.setContentPane(finder); + frame.setSize(300,110); + frame.setVisible(true); + } + + public void fontNameMenuItem_actionPerformed(ActionEvent e) { String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); - String selection = JOptionPane.showInputDialog(this, + String selection = JOptionPane.showInternalInputDialog(this, "Select font", "Font selection", JOptionPane.QUESTION_MESSAGE, @@ -247,7 +376,7 @@ public class AlignFrame extends GAlignFrame public void fontSizeMenuItem_actionPerformed(ActionEvent e) { - String selection = JOptionPane.showInputDialog(this, + String selection = JOptionPane.showInternalInputDialog(this, "Select font size", "Font size", JOptionPane.QUESTION_MESSAGE, @@ -262,7 +391,7 @@ public class AlignFrame extends GAlignFrame public void fontStyleMenuItem_actionPerformed(ActionEvent e) { - String selection = JOptionPane.showInputDialog(this, + String selection = JOptionPane.showInternalInputDialog(this, "Select font style", "Font style", JOptionPane.QUESTION_MESSAGE, @@ -278,8 +407,8 @@ public class AlignFrame extends GAlignFrame protected void colourTextMenuItem_actionPerformed(ActionEvent e) { - viewport.setColourText( colourTextMenuItem.isSelected() ); - alignPanel.RefreshPanels(); + viewport.setColourText( colourTextMenuItem.isSelected() ); + alignPanel.RefreshPanels(); } void SetFont() @@ -294,8 +423,16 @@ public class AlignFrame extends GAlignFrame style, Integer.parseInt(fontSizeMenuItem.getText()))); alignPanel.RefreshPanels(); + + } + + protected void wrapMenuItem_actionPerformed(ActionEvent e) + { + viewport.setWrapAlignment( wrapMenuItem.isSelected() ); + alignPanel.RefreshPanels(); } + public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { viewport.setShowBoxes( viewBoxesMenuItem.isSelected() ); @@ -309,74 +446,134 @@ public class AlignFrame extends GAlignFrame } + protected void renderGapsMenuItem_actionPerformed(ActionEvent e) + { + viewport.setRenderGaps(renderGapsMenuItem.isSelected()); + alignPanel.RefreshPanels(); + } + + public void consensusGraphMenuItem_actionPerformed(ActionEvent e) { alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); } + public void overviewMenuItem_actionPerformed(ActionEvent e) + { + + JInternalFrame frame = new JInternalFrame(); + OverviewPanel overview = alignPanel.getOverviewPanel(); + try{ + overview = new OverviewPanel(alignPanel, viewport); + frame.setContentPane(overview); + Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), + frame.getWidth(), frame.getHeight()); + frame.pack(); + frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) + { + alignPanel.setOverviewPanel(null); + }; + }); + alignPanel.setOverviewPanel( overview ); + + }catch(java.lang.OutOfMemoryError ex) + { + JOptionPane.showInternalMessageDialog(this, "Sequence alignment too large to\nproduce overview image!!" + +"\nTry reducing the font size.", + "Out of memory", JOptionPane.WARNING_MESSAGE); + } + + + } + + protected void noColourmenuItem_actionPerformed(ActionEvent e) + { + viewport.setGlobalColourScheme( null ); + alignPanel.setColourScheme(); + } + public void clustalColour_actionPerformed(ActionEvent e) { - // alignPanel.seqPanel.setColourScheme( new ClustalxColourScheme() ); + // alignPanel.setColourScheme( new ClustalxColourScheme() ); } public void zappoColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new ZappoColourScheme() ); + viewport.setGlobalColourScheme(new ZappoColourScheme() ); + alignPanel.setColourScheme( ); } public void taylorColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new TaylorColourScheme() ); + viewport.setGlobalColourScheme(new TaylorColourScheme() ); + alignPanel.setColourScheme( ); } public void hydrophobicityColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new HydrophobicColourScheme() ); + viewport.setGlobalColourScheme( new HydrophobicColourScheme() ); + alignPanel.setColourScheme( ); } public void helixColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new HelixColourScheme() ); + viewport.setGlobalColourScheme( new HelixColourScheme() ); + alignPanel.setColourScheme(); } + public void strandColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new StrandColourScheme() ); + viewport.setGlobalColourScheme(new StrandColourScheme() ); + alignPanel.setColourScheme( ); } + public void turnColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new TurnColourScheme() ); + viewport.setGlobalColourScheme(new TurnColourScheme() ); + alignPanel.setColourScheme( ); } + public void buriedColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new BuriedColourScheme() ); + viewport.setGlobalColourScheme( new BuriedColourScheme() ); + alignPanel.setColourScheme( ); } - public void conservationColour_actionPerformed(ActionEvent e) - { + protected void conservationMenuItem_actionPerformed(ActionEvent e) + { + viewport.setConservationSelected(conservationMenuItem.isSelected()); + conservationColourIncMenuItem.setEnabled( conservationMenuItem.isSelected() ); + alignPanel.setColourScheme(); } public void conservationColourIncMenuItem_actionPerformed(ActionEvent e) { - + ConservationIncrementPanel cip = new ConservationIncrementPanel(viewport, alignPanel); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(cip); + Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400,90); + frame.setMaximizable(false); } public void abovePIDColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new PIDColourScheme() ); + viewport.setGlobalColourScheme(new PIDColourScheme()); + alignPanel.setColourScheme( ); } public void userDefinedColour_actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame(); - UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel.seqPanel ); + UserDefinedColours chooser = new UserDefinedColours( frame, viewport ); frame.setContentPane(chooser); Desktop.addInternalFrame(frame,"User defined colours", 450,540 ); frame.setResizable(false); @@ -386,43 +583,51 @@ public class AlignFrame extends GAlignFrame public void PIDColour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new PIDColourScheme() ); + viewport.setGlobalColourScheme(new PIDColourScheme() ); + alignPanel.setColourScheme( ); } + public void BLOSUM62Colour_actionPerformed(ActionEvent e) { - alignPanel.seqPanel.setColourScheme( new Blosum62ColourScheme(viewport) ); + viewport.setGlobalColourScheme( new Blosum62ColourScheme(viewport) ); + alignPanel.setColourScheme(); } + protected void schemeKeyMenuItem_actionPerformed(ActionEvent e) { - ColourKey colourKey = new ColourKey( alignPanel.seqPanel.getColourScheme() ); + ColourKey colourKey = new ColourKey( viewport.getGlobalColourScheme() ); Desktop.addInternalFrame(colourKey, "Colour scheme key", 400, 320); } public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("sort"); AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0)); alignPanel.RefreshPanels(); } public void sortIDMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("sort"); AlignmentSorter.sortByID( viewport.getAlignment() ); alignPanel.RefreshPanels(); } public void sortGroupMenuItem_actionPerformed(ActionEvent e) { - AlignmentSorter.sortGroups(viewport.getAlignment()); + addHistoryItem("sort"); + AlignmentSorter.sortByGroup(viewport.getAlignment()); AlignmentSorter.sortGroups(viewport.getAlignment()); alignPanel.RefreshPanels(); } public void sortTreeOrderMenuItem_actionPerformed(ActionEvent e) { + addHistoryItem("sort"); if(viewport.getCurrentTree()==null) return; @@ -438,7 +643,7 @@ public class AlignFrame extends GAlignFrame public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { if(viewport.getSelection().size()<2) - JOptionPane.showMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); + JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); else { JInternalFrame frame = new JInternalFrame(); @@ -449,10 +654,28 @@ public class AlignFrame extends GAlignFrame public void PCAMenuItem_actionPerformed(ActionEvent e) { - PCAPanel pcaPanel = new PCAPanel(viewport, null); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(pcaPanel); - Desktop.addInternalFrame(frame, "Principal component analysis", 400,400); + if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0) + || viewport.getAlignment().getHeight()<4) + { + JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" + +"at least 4 input sequences.", + "Sequence selection insufficient", + JOptionPane.WARNING_MESSAGE); + return; + } + + try{ + PCAPanel pcaPanel = new PCAPanel(viewport, null); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(pcaPanel); + Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400); + }catch(java.lang.OutOfMemoryError ex) + { + JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!", + "Out of memory", JOptionPane.WARNING_MESSAGE); + } + + } public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) @@ -500,10 +723,51 @@ public class AlignFrame extends GAlignFrame public void clustalAlignMenuItem_actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(this, "Jalview is currently being reengineered" + JOptionPane.showInternalMessageDialog(this, "Jalview is currently being reengineered" +"\nwithin the Barton Group, Dundee University." +"\nThis will be available as a web service 2005", "Web service", JOptionPane.INFORMATION_MESSAGE); } + public void pdbTest_actionPerformed(ActionEvent e) + { + String reply = JOptionPane.showInternalInputDialog(this, "Enter pdb code", "PDB test viewer", JOptionPane.QUESTION_MESSAGE); + + String url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id=1a4u"; + if (reply.length()>1) + url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id="+reply; + + try + { + PDBfile pdb = new PDBfile(url, + "URL"); + Sequence seq = (Sequence)viewport.getAlignment().getSequenceAt(0); + seq.setPDBfile(pdb); + ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).isVisible = true; + ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).sequence = seq; + // ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).colourBySequence(); + + rotCanvas rc = new rotCanvas(pdb); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(rc); + Desktop.addInternalFrame(frame, url, 400,400); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + + public void doKeyPressed(KeyEvent evt) + { + + System.out.println(evt.getKeyChar()); + if(evt.isControlDown() && evt.getKeyChar()=='f') + findMenuItem_actionPerformed(null); + + } + + }