/******************** * 2004 Jalview Reengineered * Barton Group * Dundee University * * AM Waterhouse *******************/ package jalview.gui; import jalview.jbgui.GAlignFrame; import jalview.schemes.*; import jalview.datamodel.*; import jalview.analysis.*; import jalview.io.*; import MCview.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; import java.util.*; public class AlignFrame extends GAlignFrame { final AlignmentPanel alignPanel; final AlignViewport viewport; public AlignFrame(AlignmentI al) { super(); viewport = new AlignViewport(al,true,true,true,false); alignPanel = new AlignmentPanel(this, viewport); getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); fontNameMenuItem.setText(viewport.getFont().getName()); fontSizeMenuItem.setText(viewport.getFont().getSize()+""); } protected void saveAs_actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY); 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; String output = FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences()); try{ java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) ); out.println(output); out.close(); } catch(Exception ex){} } } protected void outputText_actionPerformed(ActionEvent e) { CutAndPasteTransfer cap = new CutAndPasteTransfer(false); JInternalFrame frame = new JInternalFrame(); cap.formatForOutput(); frame.setContentPane(cap); Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500); cap.setText( FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences())); } protected void htmlMenuItem_actionPerformed(ActionEvent e) { HTMLOutput htmlOutput = new HTMLOutput(viewport.getAlignment(), alignPanel.seqPanel.getColourScheme()); htmlOutput = null; } 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{ this.setClosed(true); }catch(Exception ex){} } 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 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) { viewport.getColumnSelection().clear(); repaint(); } public void remove2LeftMenuItem_actionPerformed(ActionEvent e) { addHistoryItem("delete columns"); ColumnSelection colSel = viewport.getColumnSelection(); if (colSel.size() > 0) { int min = colSel.getMin(); viewport.getAlignment().trimLeft(min); colSel.compensateForEdit(0,min); alignPanel.RefreshPanels(); } } public void remove2RightMenuItem_actionPerformed(ActionEvent e) { addHistoryItem("delete columns"); ColumnSelection colSel = viewport.getColumnSelection(); if (colSel.size() > 0) { int max = colSel.getMax(); if(max>1) viewport.getAlignment().trimRight(max); alignPanel.RefreshPanels(); } } 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++) { 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)==' ') { current.deleteCharAt(j); j--; jSize--; } } alignPanel.RefreshPanels(); } public void setGapCharMenuItem_actionPerformed(ActionEvent e) { char thisChar = '-'; char nextChar = '.'; if(viewport.getGapCharacter()=='-') { 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.showInternalInputDialog(this, "Select font", "Font selection", JOptionPane.QUESTION_MESSAGE, null,fonts ,fontNameMenuItem.getText()).toString(); if(selection!=null) { fontNameMenuItem.setText(selection); SetFont(); } } 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) { 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(); } } 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()))); alignPanel.RefreshPanels(); } protected void wrapMenuItem_actionPerformed(ActionEvent e) { updateResidueView(); } public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { updateResidueView(); } public void viewTextMenuItem_actionPerformed(ActionEvent e) { updateResidueView(); } protected void renderGapsMenuItem_actionPerformed(ActionEvent e) { viewport.setRenderGaps(renderGapsMenuItem.isSelected()); alignPanel.RefreshPanels(); } 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 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) { alignPanel.setColourScheme(null, false); } public void clustalColour_actionPerformed(ActionEvent e) { // alignPanel.setColourScheme( new ClustalxColourScheme() ); } public void zappoColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new ZappoColourScheme(), conservationMenuItem.isSelected() ); } public void taylorColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new TaylorColourScheme(),conservationMenuItem.isSelected() ); } public void hydrophobicityColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new HydrophobicColourScheme(),conservationMenuItem.isSelected() ); } public void helixColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new HelixColourScheme(),conservationMenuItem.isSelected() ); } public void strandColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new StrandColourScheme() ,conservationMenuItem.isSelected() ); } public void turnColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new TurnColourScheme() ,conservationMenuItem.isSelected() ); } public void buriedColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new BuriedColourScheme() ,conservationMenuItem.isSelected() ); } protected void conservationMenuItem_actionPerformed(ActionEvent e) { alignPanel.setColourScheme ( alignPanel.seqPanel.getColourScheme(),conservationMenuItem.isSelected() ); conservationColourIncMenuItem.setEnabled( conservationMenuItem.isSelected() ); } 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.setColourScheme( new PIDColourScheme() ,conservationMenuItem.isSelected() ); } public void userDefinedColour_actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame(); UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel.seqPanel ); frame.setContentPane(chooser); Desktop.addInternalFrame(frame,"User defined colours", 450,540 ); frame.setResizable(false); frame.setIconifiable(false); frame.setMaximizable(false); } public void PIDColour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new PIDColourScheme(),conservationMenuItem.isSelected() ); } public void BLOSUM62Colour_actionPerformed(ActionEvent e) { alignPanel.setColourScheme( new Blosum62ColourScheme(viewport) ,conservationMenuItem.isSelected() ); } protected void schemeKeyMenuItem_actionPerformed(ActionEvent e) { ColourKey colourKey = new ColourKey( alignPanel.seqPanel.getColourScheme() ); 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) { addHistoryItem("sort"); AlignmentSorter.sortGroups(viewport.getAlignment()); AlignmentSorter.sortGroups(viewport.getAlignment()); alignPanel.RefreshPanels(); } public void sortTreeOrderMenuItem_actionPerformed(ActionEvent e) { addHistoryItem("sort"); if(viewport.getCurrentTree()==null) return; AlignmentSorter.sortByTree(viewport.getAlignment(), viewport.getCurrentTree()); alignPanel.RefreshPanels(); } public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) { } public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { if(viewport.getSelection().size()<2) JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); else { JInternalFrame frame = new JInternalFrame(); frame.setContentPane(new PairwiseAlignPanel(viewport)); Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500); } } public void PCAMenuItem_actionPerformed(ActionEvent e) { 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) { NewTreePanel("AV", "PID", "Average distance tree using PID"); } public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); } protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); } protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID"); } void NewTreePanel(String type, String pwType, String title) { JInternalFrame frame = new javax.swing.JInternalFrame(); TreePanel tp=null; if (viewport.getSelection() != null && viewport.getSelection().size() > 3) { tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType, viewport.getStartRes(), viewport.getEndRes()); } else { tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), type, pwType, viewport.getStartRes(), viewport.getEndRes()); } frame.setContentPane(tp); Desktop.addInternalFrame(frame, 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); } 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); } }