X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=c6795592ce8f0502d5d595664d6b217a62e726e0;hb=577f505f54fe343e89f581461e780ea8308c20ec;hp=a977623a7becdaff27bc068a4582ebbe911d524e;hpb=edd50f0798768bc48fc0ae7be6401db6c925d06a;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a977623..c679559 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -16,12 +16,15 @@ import jalview.schemes.*; import jalview.datamodel.*; import jalview.analysis.*; import jalview.io.*; -import MCview.*; +import jalview.ws.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; +import javax.swing.event.*; import java.util.*; +import java.awt.datatransfer.*; + public class AlignFrame extends GAlignFrame { @@ -31,22 +34,44 @@ public class AlignFrame extends GAlignFrame { super(); viewport = new AlignViewport(al,true,true,true,false); + + String fontName = jalview.bin.Cache.getProperty("FONT_NAME"); + String fontStyle= jalview.bin.Cache.getProperty("FONT_STYLE"); + String fontSize = jalview.bin.Cache.getProperty("FONT_SIZE"); + if(fontName!=null && fontStyle!=null && fontSize!=null) + viewport.setFont( new Font(fontName,Integer.parseInt(fontStyle),Integer.parseInt(fontSize)) ); + + + alignPanel = new AlignmentPanel(this, viewport); getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); - fontNameMenuItem.setText(viewport.getFont().getName()); - fontSizeMenuItem.setText(viewport.getFont().getSize()+""); + + addInternalFrameListener(new InternalFrameAdapter() + { + public void internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { alignPanel.requestFocus(); } + }); + + } + }); + } protected void saveAs_actionPerformed(ActionEvent e) { - JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY); + JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY")); + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); chooser.setToolTipText("Save"); int value = chooser.showSaveDialog(this); if(value == JFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.LAST_DIRECTORY = choice; + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); String output = FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences()); try{ java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) ); @@ -70,10 +95,27 @@ 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; } + protected void createJPG_actionPerformed(ActionEvent e) + { + + int height = (viewport.alignment.getWidth() / viewport.getChunkWidth() +1) * viewport.chunkHeight; + int width = alignPanel.seqPanel.getWidth() + alignPanel.idPanel.getWidth(); + + + if(!viewport.getWrapAlignment()) + { + height = viewport.alignment.getHeight() * viewport.charHeight; + width = alignPanel.idPanel.getWidth() + viewport.alignment.getWidth() * viewport.charWidth; + } + + alignPanel.makeJPG( width, height); + } + + public void printMenuItem_actionPerformed(ActionEvent e) { //Putting in a thread avoids Swing painting problems @@ -113,8 +155,8 @@ public class AlignFrame extends GAlignFrame }catch(Exception ex){} } - ArrayList historyList = new ArrayList(); - ArrayList redoList = new ArrayList(); + Stack historyList = new Stack(); + Stack redoList = new Stack(); void updateEditMenuBar() { @@ -179,6 +221,167 @@ public class AlignFrame extends GAlignFrame alignPanel.RefreshPanels(); } + public void moveSelectedSequences(boolean up) + { + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) + return; + + if (up) + { + for (int i = 1; i < viewport.alignment.getHeight(); i++) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); + if (!sg.sequences.contains(seq)) + continue; + + SequenceI temp = viewport.alignment.getSequenceAt(i - 1); + if (sg.sequences.contains(temp)) + continue; + + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i - 1); + } + } + else + { + for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); + if (!sg.sequences.contains(seq)) + continue; + + SequenceI temp = viewport.alignment.getSequenceAt(i + 1); + if (sg.sequences.contains(temp)) + continue; + + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i + 1); + } + } + + alignPanel.RefreshPanels(); + } + + + + protected void copy_actionPerformed(ActionEvent e) + { + if(viewport.getSelectionGroup()==null) + return; + + SequenceGroup sg = viewport.getSelectionGroup(); + + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer= new StringBuffer(); + + for(int i=0; i 500) + newHeight = 500; + Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight); + } + else + { + viewport.setEndSeq(viewport.alignment.getHeight()); + viewport.alignment.getWidth(); + alignPanel.RefreshPanels(); + } + + }catch(Exception ex){}// could be anything being pasted in here + + } + + + protected void cut_actionPerformed(ActionEvent e) + { + copy_actionPerformed(null); + delete_actionPerformed(null); + } + + protected void delete_actionPerformed(ActionEvent e) + { + addHistoryItem("Delete"); + if (viewport.getSelectionGroup() == null) + return; + + SequenceGroup sg = viewport.getSelectionGroup(); + for (int i=0;i < sg.sequences.size(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.getAlignment().findIndex(seq); + seq.deleteChars(sg.getStartRes(), sg.getEndRes()+1); + + if(seq.getSequence().length()<1) + viewport.getAlignment().deleteSequence(seq); + else + viewport.getAlignment().getSequences().setElementAt(seq, index); + } + + viewport.setSelectionGroup(null); + viewport.alignment.deleteGroup(sg); + viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight()); + if(viewport.getAlignment().getHeight()<1) + try + { + this.setClosed(true); + }catch(Exception ex){} + alignPanel.RefreshPanels(); + + } + + protected void redoMenuItem_actionPerformed(ActionEvent e) { @@ -190,7 +393,6 @@ public class AlignFrame extends GAlignFrame } - public void groupsMenuItem_actionPerformed(ActionEvent e) { GroupEditor geditor = new GroupEditor(viewport, alignPanel); @@ -200,72 +402,41 @@ public class AlignFrame extends GAlignFrame frame.setResizable(false); } - public void groupEditingMenuItem_actionPerformed(ActionEvent e) + protected void deleteGroups_actionPerformed(ActionEvent e) { - viewport.setGroupEdit( groupEditingMenuItem.isSelected() ); + viewport.alignment.deleteAllGroups(); + viewport.setSelectionGroup(null); + + alignPanel.RefreshPanels(); } + + public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { - Selection sel = viewport.getSelection(); + SequenceGroup sg = new SequenceGroup(); for (int i=0; i500) - newHeight=500; - Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight); - } public void deselectAllColumnsMenuItem_actionPerformed(ActionEvent e) { @@ -318,7 +489,7 @@ public class AlignFrame extends GAlignFrame current = viewport.getAlignment().getSequenceAt(i); jSize = current.getLength(); for (int j=0; j < jSize; j++) - if (current.getCharAt(j)=='-' || current.getCharAt(j)=='.' || current.getCharAt(j)==' ') + if(jalview.util.Comparison.isGap(current.getCharAt(j))) { current.deleteCharAt(j); j--; @@ -345,100 +516,46 @@ public class AlignFrame extends GAlignFrame 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.showInternalInputDialog(this, - "Select font", - "Font selection", - JOptionPane.QUESTION_MESSAGE, - null,fonts - ,fontNameMenuItem.getText()).toString(); - if(selection!=null) - { - fontNameMenuItem.setText(selection); - SetFont(); - } + JInternalFrame frame = new JInternalFrame(); + Finder finder = new Finder(viewport, alignPanel, frame); + frame.setContentPane(finder); + Desktop.addInternalFrame(frame, "Find", 340,110); } - public void fontSizeMenuItem_actionPerformed(ActionEvent e) - { - String selection = JOptionPane.showInternalInputDialog(this, - "Select font size", - "Font size", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"} - ,fontSizeMenuItem.getText()).toString(); - if(selection!=null) - { - fontSizeMenuItem.setText(selection); - SetFont(); - } - } - public void fontStyleMenuItem_actionPerformed(ActionEvent e) + public void font_actionPerformed(ActionEvent e) { - String selection = JOptionPane.showInternalInputDialog(this, - "Select font style", - "Font style", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"plain", "bold", "italic"} - ,fontStyleMenuItem.getText()).toString(); - if(selection!=null) - { - fontStyleMenuItem.setText(selection); - SetFont(); - } - + // JOptionPane op = new JOptionPane(); + JInternalFrame frame = new JInternalFrame(); + FontChooser fc = new FontChooser( alignPanel, frame ); + frame.setContentPane(fc); + Desktop.addInternalFrame(frame, "Change Font", 480,100); } protected void colourTextMenuItem_actionPerformed(ActionEvent e) { - updateResidueView(); - } - - void SetFont() - { - int style = java.awt.Font.PLAIN; - if(fontStyleMenuItem.getText().equals("bold")) - style = java.awt.Font.BOLD; - else if(fontStyleMenuItem.getText().equals("italic")) - style = java.awt.Font.ITALIC; - - viewport.setFont(new java.awt.Font(fontNameMenuItem.getText(), - style, - Integer.parseInt(fontSizeMenuItem.getText()))); + viewport.setColourText( colourTextMenuItem.isSelected() ); alignPanel.RefreshPanels(); - } protected void wrapMenuItem_actionPerformed(ActionEvent e) { - updateResidueView(); + viewport.setWrapAlignment( wrapMenuItem.isSelected() ); + alignPanel.setWrapAlignment( wrapMenuItem.isSelected() ); } public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { - updateResidueView(); + viewport.setShowBoxes( viewBoxesMenuItem.isSelected() ); + alignPanel.RefreshPanels(); } public void viewTextMenuItem_actionPerformed(ActionEvent e) { - updateResidueView(); + viewport.setShowText( viewTextMenuItem.isSelected() ); + alignPanel.RefreshPanels(); } @@ -448,44 +565,17 @@ public class AlignFrame extends GAlignFrame alignPanel.RefreshPanels(); } - - void updateResidueView() + public void sequenceFeatures_actionPerformed(ActionEvent evt) { - 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()); - } + viewport.showSequenceFeatures(sequenceFeatures.isSelected()); + if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded) + { + AlignmentUtil.fetchSequenceFeatures( viewport.alignment , alignPanel); + ((Alignment)viewport.alignment).featuresAdded = true; + } alignPanel.RefreshPanels(); } - public void consensusGraphMenuItem_actionPerformed(ActionEvent e) { alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); @@ -493,6 +583,8 @@ public class AlignFrame extends GAlignFrame public void overviewMenuItem_actionPerformed(ActionEvent e) { + if (alignPanel.overviewPanel != null) + return; JInternalFrame frame = new JInternalFrame(); OverviewPanel overview = alignPanel.getOverviewPanel(); @@ -522,83 +614,195 @@ public class AlignFrame extends GAlignFrame protected void noColourmenuItem_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme(null, false); + changeColour( null ); } public void clustalColour_actionPerformed(ActionEvent e) { - // alignPanel.setColourScheme( new ClustalxColourScheme() ); + abovePIDThreshold.setSelected(false); + changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth())); } public void zappoColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new ZappoColourScheme(), conservationMenuItem.isSelected() ); + changeColour(new ZappoColourScheme()); } public void taylorColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new TaylorColourScheme(),conservationMenuItem.isSelected() ); + changeColour(new TaylorColourScheme()); } public void hydrophobicityColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new HydrophobicColourScheme(),conservationMenuItem.isSelected() ); + changeColour( new HydrophobicColourScheme() ); } public void helixColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new HelixColourScheme(),conservationMenuItem.isSelected() ); + changeColour(new HelixColourScheme() ); } public void strandColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new StrandColourScheme() ,conservationMenuItem.isSelected() ); + changeColour(new StrandColourScheme()); } public void turnColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new TurnColourScheme() ,conservationMenuItem.isSelected() ); + changeColour(new TurnColourScheme()); } public void buriedColour_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme( new BuriedColourScheme() ,conservationMenuItem.isSelected() ); + changeColour(new BuriedColourScheme() ); + } + + public void nucleotideColour_actionPerformed(ActionEvent e) + { + changeColour(new NucleotideColourScheme()); } - protected void conservationMenuItem_actionPerformed(ActionEvent e) + protected void applyToAllGroups_actionPerformed(ActionEvent e) { - alignPanel.setColourScheme ( alignPanel.seqPanel.getColourScheme(),conservationMenuItem.isSelected() ); - conservationColourIncMenuItem.setEnabled( conservationMenuItem.isSelected() ); + viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected()); } - public void conservationColourIncMenuItem_actionPerformed(ActionEvent e) + void changeColour(ColourSchemeI cs) + { + + if(viewport.getColourAppliesToAllGroups()) + { + Vector groups = viewport.alignment.getGroups(); + for(int i=0; i0) + + if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0) || viewport.getAlignment().getHeight()<4) { JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" @@ -724,73 +928,134 @@ public class AlignFrame extends GAlignFrame void NewTreePanel(String type, String pwType, String title) { - JInternalFrame frame = new javax.swing.JInternalFrame(); + //are the sequences aligned? + if(!viewport.alignment.isAligned()) + { + JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.", + "Sequences not aligned", JOptionPane.WARNING_MESSAGE); + return; + } + TreePanel tp=null; - if (viewport.getSelection() != null && viewport.getSelection().size() > 3) + if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize() > 3) { - tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType, - viewport.getStartRes(), viewport.getEndRes()); + tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences,type, pwType, + 0, viewport.alignment.getWidth()); } else { tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, viewport.getStartRes(), - viewport.getEndRes()); + type, pwType, 0, viewport.alignment.getWidth()); } - frame.setContentPane(tp); - Desktop.addInternalFrame(frame, title, 600, 500); + Desktop.addInternalFrame(tp, title, 600, 500); } + public void clustalAlignMenuItem_actionPerformed(ActionEvent e) { - 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); + JInternalFrame frame = new JInternalFrame(); + ClustalThread ct = new ClustalThread(frame); + Thread t = new Thread(ct); + t.start(); + frame.setContentPane(ct); + Desktop.addInternalFrame(frame, title, 300, 80); + } - public void pdbTest_actionPerformed(ActionEvent e) + class ClustalThread extends JPanel implements Runnable { - 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; + Image [] image; + int imageIndex = 0; + boolean webServiceRunning = false; + JInternalFrame frame; + public ClustalThread(JInternalFrame frame) + { + this.frame = frame; + image = new Image[9]; + for(int i=0; i<9; i++) + { + java.net.URL url = getClass().getResource("/images/dna" + (i+1) + ".gif"); + if (url != null) + { + image[i] = java.awt.Toolkit.getDefaultToolkit().createImage(url); + MediaTracker mt = new MediaTracker(this); + mt.addImage(image[i], i); + try{mt.waitForID(i);} + catch(Exception ex){} + } + } + DNATwirler twirler = new DNATwirler(); + twirler.start(); + webServiceRunning = true; + } - 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(); - } + class DNATwirler extends Thread + { + public void run() + { + while(webServiceRunning) + { + try{ + Thread.sleep(100); + imageIndex++; + imageIndex %=9; + repaint(); + } + catch(Exception ex){} + } + } + } - } + // JBPNote + // Should check to see if the server settings are valid + // Need visual-delay indication here. + public void run() + { + jalview.ws.Jemboss jemboss = new jalview.ws.Jemboss(); + Vector sv = viewport.getAlignment().getSequences(); + SequenceI[] seqs = new SequenceI[sv.size()]; + int i = 0; + do + { + seqs[i] = (SequenceI) sv.elementAt(i); + } + while (++i < sv.size()); - public void doKeyPressed(KeyEvent evt) - { + SequenceI[] alignment = jemboss.clustalW(seqs); // gaps removed within method - System.out.println(evt.getKeyChar()); - if(evt.isControlDown() && evt.getKeyChar()=='f') - findMenuItem_actionPerformed(null); + if (alignment != null) + { + AlignFrame af = new AlignFrame(new Alignment(alignment)); + af.clustalColour.setSelected(true); + af.clustalColour_actionPerformed(null); + Desktop.addInternalFrame(af, getTitle().concat(" - ClustalW Alignment"), + 700, 500); // JBPNote - is there a new window geom. property ? + } + else + JOptionPane.showMessageDialog(Desktop.desktop, "Problem obtaining clustal alignment", "Web service error", + JOptionPane.WARNING_MESSAGE); + + webServiceRunning = false; + try{ + frame.setClosed(true); + }catch(Exception ex){} + } + public void paintComponent(Graphics g) + { + g.setColor(Color.white); + g.fillRect(0,0,getWidth(), getHeight()); + if(image!=null) + { + g.drawImage(image[imageIndex],10,10,this); + } + g.setFont(new Font("Arial", Font.BOLD, 12)); + g.setColor(Color.black); + g.drawString("Clustal Alignment Web Service running", 30,30); + } } - - }