X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=ec75ee5cb8397f4eee494846054f5bebf4e5e848;hb=57d6a9e73c82ce2663a56dde4e70d997198f9e12;hp=8af52d0e4dcc028acb9f6b9c9cd602aa6463400f;hpb=a9770d55354408173fddcf91fb90059c73497448;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 8af52d0..ec75ee5 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -16,14 +16,18 @@ 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 javax.swing.event.*; +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 +71,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,16 +114,93 @@ 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; - Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight); - } public void deselectAllColumnsMenuItem_actionPerformed(ActionEvent e) { @@ -162,6 +237,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 +250,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 +265,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 +293,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 +338,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 +353,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 +369,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() @@ -297,6 +388,13 @@ public class AlignFrame extends GAlignFrame } + protected void wrapMenuItem_actionPerformed(ActionEvent e) + { + viewport.setWrapAlignment( wrapMenuItem.isSelected() ); + alignPanel.RefreshPanels(); + } + + public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { viewport.setShowBoxes( viewBoxesMenuItem.isSelected() ); @@ -310,6 +408,13 @@ 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() ); @@ -336,76 +441,108 @@ public class AlignFrame extends GAlignFrame }catch(java.lang.OutOfMemoryError ex) { - JOptionPane.showMessageDialog(this, "Sequence alignment too large to\nproduce overview image!!", + 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.setColourScheme( new ClustalxColourScheme() ); + viewport.setGlobalColourScheme(new ClustalxColourScheme( )); + alignPanel.setColourScheme( ); } public void zappoColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new ZappoColourScheme() ); + viewport.setGlobalColourScheme(new ZappoColourScheme() ); + alignPanel.setColourScheme( ); } public void taylorColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new TaylorColourScheme() ); + viewport.setGlobalColourScheme(new TaylorColourScheme() ); + alignPanel.setColourScheme( ); } public void hydrophobicityColour_actionPerformed(ActionEvent e) { - alignPanel.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.setColourScheme( new StrandColourScheme() ); + viewport.setGlobalColourScheme(new StrandColourScheme() ); + alignPanel.setColourScheme( ); } + public void turnColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new TurnColourScheme() ); + viewport.setGlobalColourScheme(new TurnColourScheme() ); + alignPanel.setColourScheme( ); } + public void buriedColour_actionPerformed(ActionEvent e) { - alignPanel.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()); + alignPanel.setColourScheme(); + if(conservationMenuItem.isSelected()) + { + SliderPanel sp = new SliderPanel(alignPanel, 30, true, viewport.getGlobalColourScheme()); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(sp); + Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400, 90); + frame.setMaximizable(false); + } } - public void conservationColourIncMenuItem_actionPerformed(ActionEvent e) - { - - } - - public void abovePIDColour_actionPerformed(ActionEvent e) + public void abovePIDThreshold_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new PIDColourScheme() ); + if(abovePIDThreshold.isSelected()) + { + SliderPanel sp = new SliderPanel(alignPanel, 70, false, + viewport.getGlobalColourScheme()); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(sp); + Desktop.addInternalFrame(frame, "Percentage Identity Threshold", 400, 90); + frame.setMaximizable(false); + } } public void userDefinedColour_actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame(); - UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel.seqPanel ); + UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel, null); frame.setContentPane(chooser); Desktop.addInternalFrame(frame,"User defined colours", 450,540 ); frame.setResizable(false); @@ -415,43 +552,51 @@ public class AlignFrame extends GAlignFrame public void PIDColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new PIDColourScheme() ); + viewport.setGlobalColourScheme( new PIDColourScheme() ); + alignPanel.setColourScheme( ); } + public void BLOSUM62Colour_actionPerformed(ActionEvent e) { - alignPanel.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; @@ -467,7 +612,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(); @@ -481,17 +626,25 @@ public class AlignFrame extends GAlignFrame if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0) || viewport.getAlignment().getHeight()<4) { - JOptionPane.showMessageDialog(this, "Principal component analysis must take\n" + JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" +"at least 4 input sequences.", "Sequence selection insufficient", JOptionPane.WARNING_MESSAGE); return; } - PCAPanel pcaPanel = new PCAPanel(viewport, null); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(pcaPanel); - Desktop.addInternalFrame(frame, "Principal component analysis", 400,400); + 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) @@ -539,10 +692,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); + + } + + }