📄 sequencelist.java
字号:
/********************************************************************** This library is free software; you can redistribute it and/or* modify it under the terms of the GNU Library General Public* License as published by the Free Software Foundation; either* version 2 of the License, or (at your option) any later version.** This library is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU* Library General Public License for more details.** You should have received a copy of the GNU Library General Public* License along with this library; if not, write to the* Free Software Foundation, Inc., 59 Temple Place - Suite 330,* Boston, MA 02111-1307, USA.** @author: Copyright (C) Tim Carver*********************************************************************/package org.emboss.jemboss.gui;import java.awt.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.table.*;import javax.swing.border.*;import java.awt.event.*;import java.net.MalformedURLException;import java.net.URL;import java.awt.datatransfer.*;import java.awt.dnd.*;import org.emboss.jemboss.parser.*;import org.emboss.jemboss.soap.*;import org.emboss.jemboss.JembossParams;import org.emboss.jemboss.gui.filetree.*;import org.emboss.jemboss.programs.RunEmbossApplication2;/**** SequenceList extends JFrame to display a set of sequences* that the user is working on in a session. The sequence list* can be stored and read back in by the application. This allows* the user to usefully maintain a list of sequence that are* being worked on and easily drag and drop them into sequence* fields of applications.**/public class SequenceList extends JFrame{ /** drag and drop table containing the list of sequences */ private DragJTable table; /** model for the sequence table */ private SequenceListTableModel seqModel; /** select to save the sequence list between sessions */ private JCheckBoxMenuItem storeSeqList; final Cursor cbusy = new Cursor(Cursor.WAIT_CURSOR); final Cursor cdone = new Cursor(Cursor.DEFAULT_CURSOR); /** * * @param withSoap true if in client-server mode * @param mysettings jemboss properties * */ public SequenceList(final boolean withSoap,final JembossParams mysettings) { super("Sequence List"); setSize(400,155); seqModel = new SequenceListTableModel(); table = new DragJTable(seqModel); table.setModel(seqModel); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //column width for(int i=0;i<SequenceListTableModel.modelColumns.length;i++) { TableColumn column = table.getColumn( SequenceListTableModel.modelColumns[i].title); column.setPreferredWidth( SequenceListTableModel.modelColumns[i].width); } JScrollPane scrollpane = new JScrollPane(table); scrollpane.setSize(300,100); getContentPane().add(scrollpane, BorderLayout.CENTER);//setup menu bar JMenuBar menuPanel = new JMenuBar(); new BoxLayout(menuPanel,BoxLayout.X_AXIS); setJMenuBar(menuPanel); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuPanel.add(fileMenu); JMenu toolMenu = new JMenu("Tools"); toolMenu.setMnemonic(KeyEvent.VK_T); menuPanel.add(toolMenu); JMenuItem openMenuItem = new JMenuItem("Open"); openMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int nrow = table.getSelectedRow(); String fileName = (String)table.getValueAt(nrow, table.convertColumnIndexToView(SequenceListTableModel.COL_NAME)); SequenceData row = (SequenceData)seqModel.modelVector.elementAt(nrow); if(!(row.s_remote.booleanValue())) DragTree.showFilePane(fileName,mysettings); //local file else RemoteDragTree.showFilePane(fileName,mysettings); //remote file } }); fileMenu.add(openMenuItem); JMenuItem ajaxSeq = new JMenuItem("Calculate Sequence Attributes"); ajaxSeq.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); String fn = table.getFileName(row); if(!fn.equals("") && fn!=null) { setCursor(cbusy); if(table.isListFile(row).booleanValue()) fn = "list::"+fn; String fc = AjaxUtil.getFileOrDatabaseForAjax(fn, BuildProgramMenu.getDatabaseList(), null,withSoap); boolean ok = false; int ajaxLength=0; float ajaxWeight; boolean ajaxProtein; if(!withSoap && fc!=null) //Ajax without SOAP { if(mysettings.isCygwin()) { ajaxLength = cygwinSeqAttr(fc,mysettings); if(ajaxLength > -1) ok = true; } else { Ajax aj = new Ajax(); ok = aj.seqType(fc); if(ok) { ajaxLength = aj.length; ajaxWeight = aj.weight; ajaxProtein = aj.protein; } } } else if(fc!=null) //Ajax with SOAP { try { CallAjax ca = new CallAjax(fc,"sequence",mysettings); if(ca.getStatus().equals("0")) { ajaxLength = ca.getLength(); ajaxWeight = ca.getWeight(); ajaxProtein = ca.isProtein(); ok = true; } } catch (JembossSoapException eae) { System.out.println("Call to Ajax library failed"); setCursor(cdone); } } if(!ok && fc!=null) //Ajax failed { if( mysettings.getServicePasswdByte()!=null || mysettings.getUseAuth() == false ) { JOptionPane.showMessageDialog(null, "Sequence not found!", "Error Message", JOptionPane.ERROR_MESSAGE); } else { AuthPopup ap = new AuthPopup(mysettings,null); ap.setBottomPanel(); ap.setSize(380,170); ap.pack(); ap.setVisible(true); } } else { seqModel.setValueAt(new Integer(1),row, SequenceListTableModel.COL_BEG); seqModel.setValueAt(new Integer(ajaxLength),row, SequenceListTableModel.COL_END); table.repaint(); } setCursor(cdone); } } }); toolMenu.add(ajaxSeq); JMenuItem addSeq = new JMenuItem("Add Sequence"); addSeq.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); seqModel.insertRow(row+1); table.tableChanged(new TableModelEvent(seqModel, row+1, row+1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }); toolMenu.add(addSeq); JMenuItem deleteSeq = new JMenuItem("Delete Sequence"); deleteSeq.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); if(seqModel.deleteRow(row)) table.tableChanged(new TableModelEvent(seqModel, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); } }); toolMenu.add(deleteSeq); JMenuItem reset = new JMenuItem("Remove All Sequences"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { seqModel.setDefaultData(); table.repaint(); } }); toolMenu.add(reset); toolMenu.addSeparator(); storeSeqList = new JCheckBoxMenuItem("Save Sequence List"); File fseq = new File(System.getProperty("user.home") + System.getProperty("file.separator") + ".jembossSeqList"); if(fseq.canRead()) storeSeqList.setSelected(true); else storeSeqList.setSelected(false); toolMenu.add(storeSeqList); fileMenu.addSeparator(); JMenuItem closeFrame = new JMenuItem("Close"); closeFrame.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_E, ActionEvent.CTRL_MASK)); closeFrame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); fileMenu.add(closeFrame); // help menu JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); JMenuItem fmh = new JMenuItem("About Sequence List"); fmh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ClassLoader cl = this.getClass().getClassLoader(); try { URL inURL = cl.getResource("resources/seqList.html"); new Browser(inURL,"resources/seqList.html"); } catch (MalformedURLException mex) { System.out.println("Didn't find resources/seqList.html"); } catch (IOException iex) { System.out.println("Didn't find resources/seqList.html"); } } }); helpMenu.add(fmh); menuPanel.add(helpMenu); } /** * * Look for first set to default in the table. * @return index to row * */ private int getDefaultRow() { int nrow = seqModel.getRowCount(); for(int i =0;i<nrow;i++) { Boolean isDef = (Boolean)seqModel.getValueAt(i, SequenceListTableModel.COL_DEF); if(isDef.booleanValue()) return i; } return -1; } /** * * Cygwin uses infoseq to get sequence length and type * and uses infoalign to get the sequence weight. * */ private int cygwinSeqAttr(String fc, JembossParams mysettings) { String[] envp = new String[2]; /* environment vars */ String ps = new String(System.getProperty("path.separator")); String embossPath = mysettings.getEmbossPath(); embossPath = new String("PATH" + ps + embossPath + ps + mysettings.getEmbossBin() + ps); envp[0] = "PATH=" + embossPath; envp[1] = "EMBOSS_DATA=" + mysettings.getEmbossData(); String command = mysettings.getEmbossBin().concat( "infoseq -only -type -length -nohead -auto "+fc); RunEmbossApplication2 rea = new RunEmbossApplication2(command,envp,null); rea.waitFor(); String stdout = rea.getProcessStdout(); if(stdout.trim().equals("")) return -1; StringTokenizer stok = new StringTokenizer(stdout,"\n "); stok.nextToken(); return Integer.parseInt(stok.nextToken().trim()); } /** * * Get the default Sequence name * @return default sequence name or null if no default * */ public String getDefaultSequenceName() { int ndef = getDefaultRow(); if(ndef<0) return null; String seqName = (String)seqModel.getValueAt(ndef, SequenceListTableModel.COL_NAME); if(table.isListFile(ndef).booleanValue()) seqName = "@".concat(seqName); return seqName; } /** * * Return the number of rows in the table * @return number of rows in the table * */ public int getRowCount() { return seqModel.getRowCount(); } /** * * The <code>SequenceData</code> for a given row * number. * @param row number * @return <code>SequenceData</code> for the row * */ public SequenceData getSequenceData(int nrow) { return seqModel.getSequenceData(nrow); } /** * * Determines if a sequence list has been stored * ("~/.jembossSeqList") * @return true if a sequence list has been stored * */ public boolean isStoreSequenceList() { return storeSeqList.isSelected(); }}/**** Extend JTable to implement a drag and drop table for* storing sequence lists (SequenceList)**/class DragJTable extends JTable implements DragGestureListener, DragSourceListener, DropTargetListener{ /** model for the sequence table */ private SequenceListTableModel seqModel; /** * * @param seqModel model for the sequence table * */ public DragJTable(SequenceListTableModel seqModel) { super(); this.seqModel = seqModel; DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer( this, // component where drag originates DnDConstants.ACTION_COPY_OR_MOVE, // actions this); setDropTarget(new DropTarget(this,this)); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -