diff --git a/uk/ac/sanger/artemis/ExternalProgram.java b/uk/ac/sanger/artemis/ExternalProgram.java index 61779cc39c93020e1a65e92adec135b67e122b74..bb83140740abd0256ab41d324593d1dd1766cb5a 100644 --- a/uk/ac/sanger/artemis/ExternalProgram.java +++ b/uk/ac/sanger/artemis/ExternalProgram.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/ExternalProgram.java,v 1.5 2005-08-12 16:01:48 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/ExternalProgram.java,v 1.6 2005-08-17 17:03:06 tjc Exp $ **/ package uk.ac.sanger.artemis; @@ -41,7 +41,7 @@ import java.util.Enumeration; * and contains methods for invoking it. * * @author Kim Rutherford - * @version $Id: ExternalProgram.java,v 1.5 2005-08-12 16:01:48 tjc Exp $ + * @version $Id: ExternalProgram.java,v 1.6 2005-08-17 17:03:06 tjc Exp $ **/ public class ExternalProgram @@ -152,6 +152,7 @@ public class ExternalProgram String [] args = { "-f", file_of_filenames.getPath(), "-cmd", getRealName(), "-d", getProgramOptions()}; + uk.ac.sanger.artemis.j2ssh.SshPSUClient ssh = new uk.ac.sanger.artemis.j2ssh.SshPSUClient(args); ssh.start(); diff --git a/uk/ac/sanger/artemis/components/ArtemisMain.java b/uk/ac/sanger/artemis/components/ArtemisMain.java index 2c1671d07709f0e746cc521e6e65b81387e348c1..7cd6ca7a0b80a454f03d95abc4f330312c0d65a1 100644 --- a/uk/ac/sanger/artemis/components/ArtemisMain.java +++ b/uk/ac/sanger/artemis/components/ArtemisMain.java @@ -20,12 +20,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ArtemisMain.java,v 1.17 2005-08-17 08:43:05 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ArtemisMain.java,v 1.18 2005-08-17 17:03:06 tjc Exp $ */ package uk.ac.sanger.artemis.components; import uk.ac.sanger.artemis.components.filetree.FileManager; +import uk.ac.sanger.artemis.components.filetree.LocalAndRemoteFileManager; import uk.ac.sanger.artemis.*; import uk.ac.sanger.artemis.sequence.NoSequenceException; import uk.ac.sanger.artemis.sequence.Bases; @@ -46,7 +47,7 @@ import java.io.*; * The main window for the Artemis sequence editor. * * @author Kim Rutherford <kmr@sanger.ac.uk> - * @version $Id: ArtemisMain.java,v 1.17 2005-08-17 08:43:05 tjc Exp $ + * @version $Id: ArtemisMain.java,v 1.18 2005-08-17 17:03:06 tjc Exp $ **/ public class ArtemisMain extends Splash @@ -78,6 +79,22 @@ public class ArtemisMain extends Splash }; makeMenuItem(file_menu, "Open File Manager ...", menu_listener); + + ActionListener menu_listener_ssh = new ActionListener() + { + private LocalAndRemoteFileManager fm; + public void actionPerformed(ActionEvent event) + { + if(fm == null) + fm = new LocalAndRemoteFileManager(ArtemisMain.this); + else + fm.setVisible(true); + } + }; + makeMenuItem(file_menu, "Open SSH File Manager ...", menu_listener_ssh); + + + final EntrySourceVector entry_sources = getEntrySources(this); for(int source_index=0; source_index<entry_sources.size(); diff --git a/uk/ac/sanger/artemis/components/filetree/FileList.java b/uk/ac/sanger/artemis/components/filetree/FileList.java index e32322eadf835e5a280f60a7b19fa8e1bfa23497..2888f5e6f96a42b72b69e0427d3c8ccdab7f7e07 100644 --- a/uk/ac/sanger/artemis/components/filetree/FileList.java +++ b/uk/ac/sanger/artemis/components/filetree/FileList.java @@ -33,7 +33,7 @@ public class FileList private Vector vdir; private Vector vfile; private static SshFileManager ssh_client = new SshFileManager(); - + public FileList() { } @@ -125,7 +125,15 @@ public class FileList */ public Vector fileVector() { - return vfile; + final Vector vfile_filtered = new Vector(); + for(int i=0; i<vfile.size(); i++) + { + String sfile = (String)vfile.get(i); + if(!sfile.startsWith(".")) + vfile_filtered.add(sfile); + } + + return vfile_filtered; } diff --git a/uk/ac/sanger/artemis/components/filetree/FileManager.java b/uk/ac/sanger/artemis/components/filetree/FileManager.java index 85aca7e09dbf8bf8fb5289c05775f71b01f22f7b..706662834060f9ffbc225568e4387539f9a6846e 100644 --- a/uk/ac/sanger/artemis/components/filetree/FileManager.java +++ b/uk/ac/sanger/artemis/components/filetree/FileManager.java @@ -30,6 +30,9 @@ import java.io.FileFilter; import java.awt.event.*; import java.awt.geom.*; import java.awt.*; +import java.util.Properties; +import java.util.Vector; +import java.util.Enumeration; public class FileManager extends JFrame { @@ -54,7 +57,7 @@ public class FileManager extends JFrame { super("File Manager"); - FileTree ftree = new FileTree(new File(System.getProperty("user.dir")), + FileTree ftree = new FileTree(getLocalDirectories(), frame, filter); JScrollPane jsp = new JScrollPane(ftree); JPanel pane = (JPanel)getContentPane(); @@ -73,6 +76,45 @@ public class FileManager extends JFrame setVisible(true); } + /** + * + * Look in j2ssh.properties for local directories. + * + */ + private File[] getLocalDirectories() + { + final Properties settings = new Properties(); + ClassLoader cl = getClass().getClassLoader(); + // try out of the classpath + try + { + settings.load(cl.getResourceAsStream("j2ssh.properties")); + } + catch (Exception e) + { + } + + Enumeration enum_prop = settings.propertyNames(); + Vector dirs = new Vector(); + + dirs.add(new File(System.getProperty("user.home"))); + dirs.add(new File(System.getProperty("user.dir"))); + + while(enum_prop.hasMoreElements()) + { + final String property = (String)enum_prop.nextElement(); + File f = new File(settings.getProperty(property)); + if(property.startsWith("localdir") && f.exists()) + dirs.add(f); + } + + File fdirs[] = new File[dirs.size()]; + for(int i=0; i<dirs.size(); i++) + fdirs[i] = (File)dirs.get(i); + + return fdirs; + } + protected JComboBox getFileFileterComboBox(final FileTree ftree) { String[] filters = { "Artemis Files", "Sequence Files", @@ -229,45 +271,6 @@ public class FileManager extends JFrame JMenu fileMenu = new JMenu("File"); mBar.add(fileMenu); - JMenuItem fileMenuGoto = new JMenuItem("Go to Directory ..."); - fileMenuGoto.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - String dir = ftree.getRoot().getAbsolutePath(); - String newDir = JOptionPane.showInputDialog(FileManager.this, - "Go to Directory:",dir); - - if(newDir == null) - return; - - newDir = newDir.trim(); - File newDirFile = new File(newDir); - - if(newDirFile.exists() && - newDirFile.canRead() && - !newDir.equals(dir)) - ftree.newRoot(newDir); - else - { - String error = null; - if(!newDirFile.exists()) - error = new String(newDir+" doesn't exist!"); - else if(!newDirFile.canRead()) - error = new String(newDir+" cannot be read!"); - else if(newDir.equals(dir)) - error = new String("Same directory!"); - - if(error != null) - JOptionPane.showMessageDialog(FileManager.this, - error, "Warning", - JOptionPane.WARNING_MESSAGE); - } - } - }); - fileMenu.add(fileMenuGoto); - fileMenu.add(new JSeparator()); - JMenuItem fileMenuClose = new JMenuItem("Close"); fileMenuClose.addActionListener(new ActionListener() { @@ -278,138 +281,6 @@ public class FileManager extends JFrame }); fileMenu.add(fileMenuClose); - // tool bar set up - JToolBar toolBar = new JToolBar(); - Dimension buttonSize = new Dimension(22,24); - - JButton upBt = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - - g2.setColor(new Color(0,128,0)); - float loc1[][] = { {11,18}, {7,18}, {7,14}, - {3,14}, {11,4} }; - - g2.fill(makeShape(loc1)); - g2.setColor(Color.green); - - float loc2[][] = { {11,18}, {15,18}, {15,14}, - {19,14}, {11,4} }; - g2.fill(makeShape(loc2)); - - setSize(22,24); - } - }; - upBt.setPreferredSize(buttonSize); - upBt.setMinimumSize(buttonSize); - - upBt.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - FileManager.this.setCursor(cbusy); - File root = ftree.getRoot(); - String parent = root.getParent(); - if(parent != null) - ftree.newRoot(parent); - FileManager.this.setCursor(cdone); - } - }); - toolBar.add(upBt); - -// yeastpub - JButton shortCut1 = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - Font font = new Font("Monospaced", Font.BOLD, 14); - g2.setFont(font); - - g2.setColor(Color.black); - g2.drawString("Y",4,18); - g2.setColor(Color.red); - g2.drawString("P",10,15); - setSize(22,24); - } - }; - shortCut1.setPreferredSize(buttonSize); - shortCut1.setMinimumSize(buttonSize); - shortCut1.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot("/nfs/disk222/yeastpub"); - } - }); - - if((new File("/nfs/disk222/yeastpub")).exists()) - toolBar.add(shortCut1); - -// pathdata - JButton shortCut2 = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - Font font = new Font("Monospaced", Font.BOLD, 14); - g2.setFont(font); - - g2.setColor(Color.black); - g2.drawString("P",4,18); - g2.setColor(Color.red); - g2.drawString("D",10,15); - setSize(22,24); - } - }; - shortCut2.setPreferredSize(buttonSize); - shortCut2.setMinimumSize(buttonSize); - shortCut2.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot("/nfs/pathdata/"); - } - }); - - if((new File("/nfs/pathdata/")).exists()) - toolBar.add(shortCut2); - -// home button - JButton homeBt = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - - g2.setColor(Color.blue); - float loc1[][] = { {3,14}, {11,3}, {19,14}, - {17,14}, {17,18}, {5,18}, {5,14} }; - g2.fill(makeShape(loc1)); - - setSize(22,24); - } - }; - homeBt.setPreferredSize(buttonSize); - homeBt.setMinimumSize(buttonSize); - homeBt.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot(System.getProperty("user.home")); - } - }); - toolBar.add(homeBt); - - toolBar.add(Box.createVerticalStrut(35)); - pane.add(toolBar, BorderLayout.NORTH); - return mBar; } diff --git a/uk/ac/sanger/artemis/components/filetree/FileNode.java b/uk/ac/sanger/artemis/components/filetree/FileNode.java index 6542722e7c292e2c4d383102599d9c0a697e1529..94c66d4842b14328ebdcf3fec2233bcb0f59a1ab 100644 --- a/uk/ac/sanger/artemis/components/filetree/FileNode.java +++ b/uk/ac/sanger/artemis/components/filetree/FileNode.java @@ -34,6 +34,7 @@ import java.util.*; public class FileNode extends DefaultMutableTreeNode implements Transferable, Serializable { + private boolean isDir; /** true if explored */ private boolean explored = false; /** data flavour of a file node */ @@ -50,6 +51,7 @@ public class FileNode extends DefaultMutableTreeNode public FileNode(File file) { setUserObject(file); + this.isDir = file.isDirectory(); } /** Determine if this is a directory */ @@ -62,9 +64,13 @@ public class FileNode extends DefaultMutableTreeNode public boolean isExplored() { return explored; } /** Determine if this is a directory */ public boolean isDirectory() + { + return isDir; + } + + protected void setDirectory(boolean isDir) { - File file = getFile(); - return file.isDirectory(); + this.isDir = isDir; } /** diff --git a/uk/ac/sanger/artemis/components/filetree/FileTree.java b/uk/ac/sanger/artemis/components/filetree/FileTree.java index cd86e466b3b628700df6f045f9f24d55b1bc347f..4aa4a555d48c4f4b68397f10a4ee56b790752850 100644 --- a/uk/ac/sanger/artemis/components/filetree/FileTree.java +++ b/uk/ac/sanger/artemis/components/filetree/FileTree.java @@ -60,7 +60,7 @@ public class FileTree extends JTree implements DragGestureListener, { /** root directory */ - private File root; + private File root[]; /** store of directories that are opened */ private Vector openNode; /** file separator */ @@ -78,13 +78,14 @@ public class FileTree extends JTree implements DragGestureListener, /** file filter */ private FileFilter filter = null; + /** * * @param rt root directory * @param f frame * */ - public FileTree(File rt, final JFrame f, + public FileTree(File rt[], final JFrame f, FileFilter filter) { this.root = rt; @@ -193,7 +194,7 @@ public class FileTree extends JTree implements DragGestureListener, if(source.getText().equals("Refresh")) { if(node == null) - newRoot(root.getAbsolutePath()); + return; else if(node.isLeaf()) refresh((FileNode)node.getParent()); else @@ -369,7 +370,8 @@ public class FileTree extends JTree implements DragGestureListener, */ public void newRoot(String newRoot) { - root = new File(newRoot); +// root = new File(newRoot); + DefaultTreeModel model = (DefaultTreeModel)getModel(); model = createTreeModel(root); setModel(model); @@ -383,7 +385,7 @@ public class FileTree extends JTree implements DragGestureListener, */ public File getRoot() { - return root; + return null; } /** @@ -495,12 +497,24 @@ public class FileTree extends JTree implements DragGestureListener, * to the given directory * */ - private DefaultTreeModel createTreeModel(File root) + private DefaultTreeModel createTreeModel(File root[]) { - FileNode rootNode = new FileNode(root); - rootNode.explore(filter); - openNode = new Vector(); - openNode.add(rootNode); + FileNode rootNode = new FileNode(new File("")); + rootNode.setDirectory(true); + + for(int i=0; i<root.length; i++) + { + FileNode node = new FileNode(root[i]); + + if(i == 0) + { + node.explore(filter); + openNode = new Vector(); + openNode.add(node); + } + rootNode.add(node); + } + return new DefaultTreeModel(rootNode); } @@ -935,8 +949,10 @@ public class FileTree extends JTree implements DragGestureListener, public static void main(String[] args) { JFrame tree_frame = new JFrame("File Manager"); - FileTree ftree = new FileTree(new File(System.getProperty("user.home")), - tree_frame,null); + + File dirs[] = new File[1]; + dirs[0] = new File(System.getProperty("user.home")); + FileTree ftree = new FileTree(dirs, tree_frame, null); JScrollPane jsp = new JScrollPane(ftree); tree_frame.getContentPane().add(jsp); tree_frame.pack(); diff --git a/uk/ac/sanger/artemis/components/filetree/LocalAndRemoteFileManager.java b/uk/ac/sanger/artemis/components/filetree/LocalAndRemoteFileManager.java index b105a2e9c78404e48805148f64a1ad96c3bac0be..810e917ee4f5618deaab256c56a838c9b7f128bd 100644 --- a/uk/ac/sanger/artemis/components/filetree/LocalAndRemoteFileManager.java +++ b/uk/ac/sanger/artemis/components/filetree/LocalAndRemoteFileManager.java @@ -21,6 +21,7 @@ package uk.ac.sanger.artemis.components.filetree; +import uk.ac.sanger.artemis.j2ssh.SshLogin; import uk.ac.sanger.artemis.util.StringVector; import uk.ac.sanger.artemis.Options; @@ -30,6 +31,10 @@ import java.io.FileFilter; import java.awt.event.*; import java.awt.geom.*; import java.awt.*; +import java.util.Properties; +import java.util.Enumeration; +import java.util.Vector; +import javax.swing.border.Border; public class LocalAndRemoteFileManager extends JFrame { @@ -54,19 +59,24 @@ public class LocalAndRemoteFileManager extends JFrame { super("File Manager"); + FileList flist = new FileList(); final JPanel localPanel = new JPanel(new BorderLayout()); - FileTree ftree = new FileTree(new File(System.getProperty("user.dir")), - frame, filter); + + FileTree ftree = new FileTree(getLocalDirectories(), this, filter); JScrollPane localTree = new JScrollPane(ftree); localPanel.add(localTree,BorderLayout.CENTER); + final JLabel local_status_line = getStatusLabel("LOCAL"); + localPanel.add(local_status_line,BorderLayout.NORTH); + final JPanel remotePanel = new JPanel(new BorderLayout()); - FileList flist = new FileList(); - String pwd = flist.pwd(); - SshFileTree sshtree = new SshFileTree(pwd); + SshFileTree sshtree = new SshFileTree( getRemoteDirectories(flist.pwd()) ); JScrollPane remoteTree = new JScrollPane(sshtree); remotePanel.add(remoteTree,BorderLayout.CENTER); + + final JLabel remote_status_line = getStatusLabel("REMOTE"); + remotePanel.add(remote_status_line,BorderLayout.NORTH); final JSplitPane treePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, localPanel,remotePanel); @@ -76,7 +86,7 @@ public class LocalAndRemoteFileManager extends JFrame pane.add(treePane, BorderLayout.CENTER); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - Dimension panelSize = new Dimension(210, (int)(screen.getHeight()/3)); + Dimension panelSize = new Dimension(240, (int)(screen.getHeight()/2)); setJMenuBar(makeMenuBar(pane,ftree,sshtree,localPanel,remotePanel,treePane,panelSize)); localPanel.add(getFileFileterComboBox(ftree), BorderLayout.SOUTH); @@ -90,6 +100,82 @@ public class LocalAndRemoteFileManager extends JFrame setVisible(true); } + /** + * + * Create a status JLabel with bevelled border + * + */ + private JLabel getStatusLabel(String status) + { + final JLabel status_line = new JLabel(status); + Border loweredbevel = BorderFactory.createLoweredBevelBorder(); + Border raisedbevel = BorderFactory.createRaisedBevelBorder(); + Border compound = BorderFactory.createCompoundBorder(raisedbevel,loweredbevel); + status_line.setBorder(compound); + + final FontMetrics fm = + this.getFontMetrics(status_line.getFont()); + final int font_height = fm.getHeight()+10; + + status_line.setMinimumSize(new Dimension(100, font_height)); + status_line.setPreferredSize(new Dimension(100, font_height)); + return status_line; + } + + /** + * + * Look in j2ssh.properties for local directories. + * + */ + private File[] getLocalDirectories() + { + final Properties settings = SshLogin.getProperties(); + Enumeration enum_prop = settings.propertyNames(); + Vector dirs = new Vector(); + + dirs.add(new File(System.getProperty("user.home"))); + dirs.add(new File(System.getProperty("user.dir"))); + + while(enum_prop.hasMoreElements()) + { + final String property = (String)enum_prop.nextElement(); + File f = new File(settings.getProperty(property)); + if(property.startsWith("localdir") && f.exists()) + dirs.add(f); + } + + File fdirs[] = new File[dirs.size()]; + for(int i=0; i<dirs.size(); i++) + fdirs[i] = (File)dirs.get(i); + + return fdirs; + } + + /** + * + * Look in j2ssh.properties for remote directories. + * + */ + private String[] getRemoteDirectories(String pwd) + { + final Properties settings = SshLogin.getProperties(); + Enumeration enum_prop = settings.propertyNames(); + Vector dirs = new Vector(); + dirs.add(pwd); + while(enum_prop.hasMoreElements()) + { + final String property = (String)enum_prop.nextElement(); + if(property.startsWith("remotedir")) + dirs.add(settings.getProperty(property)); + } + + String sdirs[] = new String[dirs.size()]; + for(int i=0; i<dirs.size(); i++) + sdirs[i] = (String)dirs.get(i); + + return sdirs; + } + protected JComboBox getFileFileterComboBox(final FileTree ftree) { String[] filters = { "Artemis Files", "Sequence Files", @@ -248,45 +334,6 @@ public class LocalAndRemoteFileManager extends JFrame JMenu fileMenu = new JMenu("File"); mBar.add(fileMenu); - JMenuItem fileMenuGoto = new JMenuItem("Go to Directory ..."); - fileMenuGoto.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - String dir = ftree.getRoot().getAbsolutePath(); - String newDir = JOptionPane.showInputDialog(LocalAndRemoteFileManager.this, - "Go to Directory:",dir); - - if(newDir == null) - return; - - newDir = newDir.trim(); - File newDirFile = new File(newDir); - - if(newDirFile.exists() && - newDirFile.canRead() && - !newDir.equals(dir)) - ftree.newRoot(newDir); - else - { - String error = null; - if(!newDirFile.exists()) - error = new String(newDir+" doesn't exist!"); - else if(!newDirFile.canRead()) - error = new String(newDir+" cannot be read!"); - else if(newDir.equals(dir)) - error = new String("Same directory!"); - - if(error != null) - JOptionPane.showMessageDialog(LocalAndRemoteFileManager.this, - error, "Warning", - JOptionPane.WARNING_MESSAGE); - } - } - }); - fileMenu.add(fileMenuGoto); - fileMenu.add(new JSeparator()); - JRadioButtonMenuItem prefV = new JRadioButtonMenuItem("Vertical Split"); fileMenu.add(prefV); prefV.addActionListener(new ActionListener() @@ -342,137 +389,12 @@ public class LocalAndRemoteFileManager extends JFrame fileMenu.add(fileMenuClose); // remote tool bar set up - JToolBar remoteToolBar = new JToolBar(); - Dimension buttonSize = new Dimension(22,24); - - JButton remoteUpBt = new UpButton(); - remoteUpBt.setPreferredSize(buttonSize); - remoteUpBt.setMinimumSize(buttonSize); - - remoteUpBt.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - LocalAndRemoteFileManager.this.setCursor(cbusy); - sshtree.up(); - LocalAndRemoteFileManager.this.setCursor(cdone); - } - }); - remoteToolBar.add(remoteUpBt); - - remoteToolBar.add(Box.createVerticalStrut(35)); - remotePanel.add(remoteToolBar, BorderLayout.NORTH); +// JToolBar remoteToolBar = new JToolBar(); +// remotePanel.add(remoteToolBar, BorderLayout.NORTH); // local tool bar set up - JToolBar toolBar = new JToolBar(); - - JButton upBt = new UpButton(); - upBt.setPreferredSize(buttonSize); - upBt.setMinimumSize(buttonSize); - - upBt.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - LocalAndRemoteFileManager.this.setCursor(cbusy); - File root = ftree.getRoot(); - String parent = root.getParent(); - if(parent != null) - ftree.newRoot(parent); - LocalAndRemoteFileManager.this.setCursor(cdone); - } - }); - toolBar.add(upBt); - -// yeastpub - JButton shortCut1 = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - Font font = new Font("Monospaced", Font.BOLD, 14); - g2.setFont(font); - - g2.setColor(Color.black); - g2.drawString("Y",4,18); - g2.setColor(Color.red); - g2.drawString("P",10,15); - setSize(22,24); - } - }; - shortCut1.setPreferredSize(buttonSize); - shortCut1.setMinimumSize(buttonSize); - shortCut1.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot("/nfs/disk222/yeastpub"); - } - }); - - if((new File("/nfs/disk222/yeastpub")).exists()) - toolBar.add(shortCut1); - -// pathdata - JButton shortCut2 = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - Font font = new Font("Monospaced", Font.BOLD, 14); - g2.setFont(font); - - g2.setColor(Color.black); - g2.drawString("P",4,18); - g2.setColor(Color.red); - g2.drawString("D",10,15); - setSize(22,24); - } - }; - shortCut2.setPreferredSize(buttonSize); - shortCut2.setMinimumSize(buttonSize); - shortCut2.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot("/nfs/pathdata/"); - } - }); - - if((new File("/nfs/pathdata/")).exists()) - toolBar.add(shortCut2); - -// home button - JButton homeBt = new JButton() - { - public void paintComponent(Graphics g) - { - super.paintComponent(g); - Graphics2D g2 = (Graphics2D)g; - - g2.setColor(Color.blue); - float loc1[][] = { {3,14}, {11,3}, {19,14}, - {17,14}, {17,18}, {5,18}, {5,14} }; - g2.fill(makeShape(loc1)); - - setSize(22,24); - } - }; - homeBt.setPreferredSize(buttonSize); - homeBt.setMinimumSize(buttonSize); - homeBt.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ftree.newRoot(System.getProperty("user.home")); - } - }); - toolBar.add(homeBt); - - toolBar.add(Box.createVerticalStrut(35)); - localPanel.add(toolBar, BorderLayout.NORTH); +// JToolBar toolBar = new JToolBar(); +// localPanel.add(toolBar, BorderLayout.NORTH); return mBar; } @@ -516,6 +438,40 @@ public class LocalAndRemoteFileManager extends JFrame } } + class TextButton extends JButton + { + private String s1; + private String s2; + private Color c; + + public TextButton(String text) + { + this(text, Color.black); + } + + public TextButton(String text, Color c) + { + super(); + this.s1 = text.substring(0); + this.s2 = text.substring(1); + } + + public void paintComponent(Graphics g) + { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D)g; + Font font = new Font("Monospaced", Font.BOLD, 14); + g2.setFont(font); + + g2.setColor(c); + g2.drawString(s1,4,18); + g2.setColor(Color.red); + g2.drawString(s2,10,15); + setSize(22,24); + } + } + + public static void main(String args[]) { final javax.swing.LookAndFeel look_and_feel = diff --git a/uk/ac/sanger/artemis/components/filetree/RemoteFileNode.java b/uk/ac/sanger/artemis/components/filetree/RemoteFileNode.java index 4e7a678a716f57b9e8dbee715831beaddb72b90f..2b03b010434db0d5549716ac9900cfb4cc6dc29b 100644 --- a/uk/ac/sanger/artemis/components/filetree/RemoteFileNode.java +++ b/uk/ac/sanger/artemis/components/filetree/RemoteFileNode.java @@ -47,8 +47,6 @@ public class RemoteFileNode extends DefaultMutableTreeNode /** parent directory listing */ private transient FileList parentList; // make transient for - /** jemboss properties */ - private transient Properties mysettings; // Transferable to work /** remote server file roots */ private transient String froots; /** file separator for server files */ @@ -59,25 +57,27 @@ public class RemoteFileNode extends DefaultMutableTreeNode static DataFlavor remoteFlavors[] = { REMOTEFILENODE, DataFlavor.stringFlavor }; + public RemoteFileNode(boolean isDir) + { + this.isDir = isDir; + } /** * - * @param mysettings jemboss properties * @param froots remote server file roots * @param file file for this node * @param parentList parent directory listing * @param parent parent to this node * */ - public RemoteFileNode(Properties mysettings, String froots, - String file, FileList parentList, String parent) + public RemoteFileNode(String froots, String file, + FileList parentList, String parent) { - this(mysettings, froots, file, parentList, parent, false); + this(froots, file, parentList, parent, false); } /** * - * @param mysettings jemboss properties * @param froots remote server file roots * @param file file for this node * @param parentList parent directory listing @@ -85,11 +85,10 @@ public class RemoteFileNode extends DefaultMutableTreeNode * @param ldir true if the node is a directory * */ - public RemoteFileNode(Properties mysettings, String froots, - String file, FileList parentList, String parent, - boolean ldir) + public RemoteFileNode(String froots, String file, + FileList parentList, String parent, + boolean ldir) { - this.mysettings = mysettings; this.froots = froots; this.parentList = parentList; isDir = ldir; @@ -143,11 +142,6 @@ public class RemoteFileNode extends DefaultMutableTreeNode /** @return true if explored */ public boolean isExplored() { return explored; } - protected void setDir(boolean isDir) - { - this.isDir = isDir; - } - /** * * Get the server name @@ -190,7 +184,7 @@ public class RemoteFileNode extends DefaultMutableTreeNode flist.getDirList(dir); Vector children = flist.fileVector(); for(int i=0;i<children.size();i++) - add(new RemoteFileNode(mysettings,froots,(String)children.get(i), + add(new RemoteFileNode(froots,(String)children.get(i), flist,fullname)); } explored = true; diff --git a/uk/ac/sanger/artemis/components/filetree/SshFileTree.java b/uk/ac/sanger/artemis/components/filetree/SshFileTree.java index 19be4f2a0d514dccb5912bb23ac831eef8762594..a064863df4278e36846e3a490a883a9331920736 100644 --- a/uk/ac/sanger/artemis/components/filetree/SshFileTree.java +++ b/uk/ac/sanger/artemis/components/filetree/SshFileTree.java @@ -56,7 +56,7 @@ public class SshFileTree extends JTree implements DragGestureListener, /** properties */ private Properties mysettings; /** remote directory roots */ - private static String froots; + private static String froots[]; /** popup menu */ private JPopupMenu popup; /** file separator */ @@ -80,7 +80,7 @@ public class SshFileTree extends JTree implements DragGestureListener, * @param froots remote directory roots * */ - public SshFileTree(String froots) + public SshFileTree(String froots[]) { this.froots = froots; @@ -193,14 +193,31 @@ public class SshFileTree extends JTree implements DragGestureListener, * the tree. * */ +/* public void up() { File current = new File(froots); - froots = current.getParentFile().getAbsolutePath(); + String new_froots = current.getParentFile().getAbsolutePath(); + newRoot(new_froots); + } +*/ + + /** + * + * Define a directory root for the file tree + * @param newRoot directory to use as the root for + * the tree. + * + */ +/* + protected void newRoot(final String froots) + { + this.froots = froots; DefaultTreeModel model = (DefaultTreeModel)getModel(); model = createTreeModel(froots); setModel(model); } +*/ /** * @@ -457,8 +474,8 @@ public class SshFileTree extends JTree implements DragGestureListener, } else { - childNode = new RemoteFileNode(mysettings,froots, - child,null,path,ldir); + childNode = new RemoteFileNode(froots[0],child, + null,path,ldir); //find the index for the child int num = parentNode.getChildCount(); @@ -578,18 +595,28 @@ public class SshFileTree extends JTree implements DragGestureListener, * @return tree model * */ - private DefaultTreeModel createTreeModel(String root) + private DefaultTreeModel createTreeModel(String froot[]) { setCursor(cbusy); - File f = new File(root); - RemoteFileNode rootNode = new RemoteFileNode(mysettings,froots, - f.getName(),null,null); - - rootNode.setDir(true); - rootNode.explore(); - openNode = new Vector(); - openNode.add(rootNode); + RemoteFileNode rootNode = new RemoteFileNode(true); + + for(int i=0; i<froots.length; i++) + { + File f = new File(froot[i]); + RemoteFileNode node = new RemoteFileNode(froots[i], f.getName(), + null, null, true); + rootNode.add(node); + if(i == 0) + { + node.explore(); + openNode = new Vector(); + openNode.add(node); + } + } + + + setCursor(cdone); return new DefaultTreeModel(rootNode); } @@ -991,7 +1018,8 @@ public class SshFileTree extends JTree implements DragGestureListener, } JFrame frame = new JFrame("SSH :: File Manager"); - JScrollPane jsp = new JScrollPane(new SshFileTree("/nfs/team81/tjc")); + String roots[] = { "/nfs/team81/tjc" }; + JScrollPane jsp = new JScrollPane(new SshFileTree(roots)); frame.getContentPane().add(jsp); frame.pack(); frame.setVisible(true); diff --git a/uk/ac/sanger/artemis/j2ssh/SftpPSUClient.java b/uk/ac/sanger/artemis/j2ssh/SftpPSUClient.java deleted file mode 100644 index 684a52b53ccb0dff5a0c0ca1ee1297c9f1a9a2c5..0000000000000000000000000000000000000000 --- a/uk/ac/sanger/artemis/j2ssh/SftpPSUClient.java +++ /dev/null @@ -1,427 +0,0 @@ -/* ExternalProgram.java - * - * created: Aug 2005 - * - * This file is part of Artemis - * - * Copyright(C) 2005 Genome Research Limited - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or(at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - **/ - -package uk.ac.sanger.artemis.j2ssh; - - -import javax.swing.*; -import java.awt.*; -import java.io.*; -import com.sshtools.j2ssh.SshClient; -import com.sshtools.j2ssh.authentication.AuthenticationProtocolState; -import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; -import com.sshtools.j2ssh.io.UnsignedInteger32; -import com.sshtools.j2ssh.session.SessionChannelClient; -import com.sshtools.j2ssh.sftp.FileAttributes; -import com.sshtools.j2ssh.sftp.SftpFile; -import com.sshtools.j2ssh.sftp.SftpFileOutputStream; -import com.sshtools.j2ssh.SftpClient; -import com.sshtools.j2ssh.configuration.ConfigurationLoader; - -import java.util.Vector; -import java.util.Properties; -import java.util.logging.FileHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; - -/** - * - */ -public class SftpPSUClient extends Thread -{ - - private String hostname = null; - private String user = null; - private String listfilepath = null; - private String cmd = null; - private String bsub = null; - private String logfile = null; - private String db = null; - private String wdir = "/nfs/pathscratch1/scratch"; - private int port = -1; - - public SftpPSUClient(String args[]) - { - // process arguments - if(args != null && args.length > 0) - { - for(int i=0; i<args.length; i++) - { - if(args[i].equals("-h") && i < args.length-1) - hostname = args[i+1]; - else if(args[i].equals("-u") && i < args.length-1) - user = args[i+1]; - else if(args[i].equals("-f") && i < args.length-1) - listfilepath = args[i+1]; - else if(args[i].equals("-cmd") && i < args.length-1) - cmd = args[i+1]; - else if(args[i].equals("-bsub") && i < args.length-1) - bsub = args[i+1]; - else if(args[i].equals("-l") && i < args.length-1) - logfile = args[i+1]; - else if(args[i].equals("-p") && i < args.length-1) - port = Integer.parseInt(args[i+1]); - else if(args[i].equals("-d") && i < args.length-1) - db = args[i+1]; - else if(args[i].equals("-wdir") && i < args.length-1) - wdir = args[i+1]; - } - } - } - - public void run() - { - String program = cmd; - // get properties from j2ssh.properties - Properties settings = getProperties(); - if(hostname == null && settings.getProperty("host") != null) - hostname = settings.getProperty("host"); - if(port < 0 && settings.getProperty("port") != null) - port = Integer.parseInt(settings.getProperty("port")); - if(bsub == null && settings.getProperty("bsub") != null) - bsub = settings.getProperty("bsub"); - if(user == null) - user = System.getProperty("user.name"); - if(db == null) - { - if(settings.getProperty("default_db") != null) - db = settings.getProperty("default_db"); - else - db = "%uniprot"; - } - if(cmd.equals("blastp") && settings.getProperty("blastp") != null) - cmd = settings.getProperty("blastp"); - if(cmd.equals("fasta") && settings.getProperty("fasta") != null) - cmd = settings.getProperty("fasta"); - - try - { - // Setup a logfile - if(logfile != null) - { - Handler fh = new FileHandler(logfile); - fh.setFormatter(new SimpleFormatter()); - Logger.getLogger("com.sshtools").setUseParentHandlers(false); - Logger.getLogger("com.sshtools").addHandler(fh); - Logger.getLogger("com.sshtools").setLevel(Level.ALL); - } - else - Logger.getLogger("com.sshtools").setLevel(Level.OFF); - - ConfigurationLoader.initialize(false); - -// if(hostname == null) -// hostname = (String)JOptionPane.showInputDialog( -// null, "Name of server machine:", -// "Server hostname", -// JOptionPane.PLAIN_MESSAGE, null, -// null, null); - - BufferedReader reader = - new BufferedReader(new InputStreamReader(System.in)); - - // Create a password authentication instance - PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); - // Get the users name - - JPanel promptPanel = new JPanel(new GridLayout(4,2)); - - JTextField hostfield = new JTextField(16); - if(hostname != null) - hostfield.setText(hostname); - - JTextField portfield = new JTextField(16); - if(port >-1) - portfield.setText(Integer.toString(port)); - - JTextField ufield = new JTextField(16); - if(user != null) - ufield.setText(user); - JPasswordField pfield = new JPasswordField(16); - - JLabel hostlab = new JLabel(" Hostname:", SwingConstants.LEFT); - JLabel portlab = new JLabel(" Port:", SwingConstants.LEFT); - - JLabel ulab = new JLabel(" Username:", SwingConstants.LEFT); - JLabel plab = new JLabel(" Password:", SwingConstants.LEFT); - //add labels etc - promptPanel.add(hostlab); - promptPanel.add(hostfield); - - promptPanel.add(portlab); - promptPanel.add(portfield); - - promptPanel.add(ulab); - promptPanel.add(ufield); - - promptPanel.add(plab); - promptPanel.add(pfield); - - Object[] options = { "CANCEL", "LOGIN"}; - - int select = JOptionPane.showOptionDialog(null, promptPanel, - "LOGIN", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - options, - options[1]); - - if(select == 0) - return; - - // Make a client connection - SshClient ssh = new SshClient(); - hostname = hostfield.getText().trim(); - if(portfield.getText().trim().equals("")) - port = -1; - else - port = Integer.parseInt(portfield.getText().trim()); - - // Connect to the host - if(port < 0) - ssh.connect(hostname); - else - ssh.connect(hostname,port); - - user = ufield.getText().trim(); - pwd.setUsername(user); - pwd.setPassword(new String(pfield.getPassword())); - - // Try the authentication - int result = ssh.authenticate(pwd); - - // Evaluate the result - if(result == AuthenticationProtocolState.COMPLETE) - { - if(listfilepath == null) - { - JFileChooser chooser = new JFileChooser(); - int returnVal = chooser.showOpenDialog(null); - if(returnVal == JFileChooser.APPROVE_OPTION) - listfilepath = chooser.getSelectedFile().getAbsolutePath(); - else - return; - } - - SftpClient sftp = ssh.openSftpClient(); - Vector seqfile = readListFile(listfilepath); - for(int i=0; i<seqfile.size();i++) - { - String filepath = (String)seqfile.get(i); - int index = filepath.lastIndexOf(System.getProperty("file.separator")); - String filename = filepath; - if(index > -1) - filename = filename.substring(index+1); - - wdir = wdir+"/"+user+"/"; - try - { - sftp.mkdir(wdir); - sftp.put(filepath, wdir+filename); - } - catch(IOException ioe) - {} - - SessionChannelClient session = ssh.openSessionChannel(); - - String outputfile = wdir+filename+".out"; - final String actualCMD; - - if(cmd.indexOf("fasta33") > -1) - { - if(settings.getProperty(db) != null) - db = settings.getProperty(db); - actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " + - cmd+" "+wdir+filename+" "+db; - } - else - actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " + - cmd+" "+db+" "+wdir+filename; - - System.out.println(actualCMD); - session.executeCommand(actualCMD); - - // Reading from the session InputStream - StdoutStdErrHandler stdouth = new StdoutStdErrHandler(session, true); - StdoutStdErrHandler stderrh = new StdoutStdErrHandler(session, false); - - stdouth.start(); - stderrh.start(); - - boolean isFile = false; - try - { - // make sure we hang around for stdout - while(stdouth.isAlive() || stderrh.isAlive()) - Thread.currentThread().sleep(10); - - int count = 0; - - while(!isFile && count < 100) - { - Thread.currentThread().sleep(5000); - Object list[] = sftp.ls(wdir).toArray(); - - for(int j=0; j<list.length;j++) - { - if(((SftpFile)list[j]).getFilename().equals(filename+".out")) - isFile = true; - } - count++; - } - } - catch(InterruptedException ie) - { - ie.printStackTrace(); - } - catch(java.io.IOException ioe) - { - ioe.printStackTrace(); - } - - // stdout - System.out.println(stdouth.getOutput()); - System.out.println(stderrh.getOutput()); - -// ByteArrayOutputStream os = new ByteArrayOutputStream(); -// sftp.get(outputfile, os); -// System.out.println(os.toString()); - - sftp.get(outputfile, filepath+".out"); - - session.close(); - } - - // Quit - sftp.quit(); - ssh.disconnect(); - } - else - JOptionPane.showMessageDialog(null, - "Problem logging in!\nCheck username and password.", - "Authentication Problem", - JOptionPane.ERROR_MESSAGE); - - - } catch(IOException ioe){} - finally - { - JOptionPane.showMessageDialog(null, - "Finished \n" + program, - "Process Finished", - JOptionPane.INFORMATION_MESSAGE); - } - } - - private Vector readListFile(String file) - { - Vector seqfiles = new Vector(); - try - { - String line; - BufferedReader in = new BufferedReader(new FileReader(file)); - while((line = in.readLine()) != null ) - { - File seq = new File(line); - if(seq.exists()) - { - seqfiles.add(seq.getAbsolutePath()); - } - } - } - catch (IOException e) - { - System.out.println("Problem reading list file"); - } - return seqfiles; - } - - private Properties getProperties() - { - Properties settings = new Properties(); - ClassLoader cl = this.getClass().getClassLoader(); - // try out of the classpath - try - { - settings.load(cl.getResourceAsStream("j2ssh.properties")); - } - catch (Exception e) - { - } - return settings; - } - - - class StdoutStdErrHandler extends Thread - { - private SessionChannelClient session; - private boolean isStdout; - private StringBuffer buff = new StringBuffer(); - - protected StdoutStdErrHandler(SessionChannelClient session, - boolean isStdout) - { - this.session = session; - this.isStdout = isStdout; - } - - public void run() - { - try - { - final InputStream in; - if(isStdout) - in = session.getInputStream(); - else - in = session.getStderrInputStream(); - - byte buffer[] = new byte[100]; - int read; - while((read = in.read(buffer)) > 0) - buff.append(new String(buffer, 0, read)); - } - catch(IOException ioe){} - } - - public String getOutput() - { - return buff.toString(); - } - - } - - - /** - * The main program for the PasswordConnect class - * - * @param args The command line arguments - */ - public static void main(String args[]) - { - new SftpPSUClient(args); - } -} diff --git a/uk/ac/sanger/artemis/j2ssh/SshFileManager.java b/uk/ac/sanger/artemis/j2ssh/SshFileManager.java index bd20d0f7a96f08947ebdcbc68876af421fc0aad0..9f73cbf01be628eaf6d7fbf0bfe540c5ae187381 100644 --- a/uk/ac/sanger/artemis/j2ssh/SshFileManager.java +++ b/uk/ac/sanger/artemis/j2ssh/SshFileManager.java @@ -77,162 +77,12 @@ public class SshFileManager private String logfile = null; private String wdir = "/nfs/pathscratch1/scratch"; - // login variables - private String hostname = null; - private String user = null; - private int port = -1; - private static JPasswordField pfield = new JPasswordField(16); - private static JTextField portfield = new JTextField(16); - private static JTextField hostfield = new JTextField(16); - private static JTextField ufield = new JTextField(16); private SshClient ssh; public SshFileManager() { - try - { - // Setup a logfile - if(logfile != null) - { - Handler fh = new FileHandler(logfile); - fh.setFormatter(new SimpleFormatter()); - Logger.getLogger("com.sshtools").setUseParentHandlers(false); - Logger.getLogger("com.sshtools").addHandler(fh); - Logger.getLogger("com.sshtools").setLevel(Level.ALL); - } - else - Logger.getLogger("com.sshtools").setLevel(Level.OFF); - } - catch(IOException ioe){} - - Properties settings = getProperties(); - try - { - ssh = login(); - } - catch(IOException ioe){} - } - - /** - * - * Log the user in. - * - */ - private SshClient login() - throws IOException - { - SshClient ssh = null; - int result = AuthenticationProtocolState.FAILED; - - while(result != AuthenticationProtocolState.COMPLETE) - { - if(!setLogin()) - return null; - - // Create a password authentication instance - PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); - user = ufield.getText().trim(); - pwd.setUsername(user); - pwd.setPassword(new String(pfield.getPassword())); - - // Make a client connection - ssh = new SshClient(); - hostname = hostfield.getText().trim(); - if(portfield.getText().trim().equals("")) - port = -1; - else - port = Integer.parseInt(portfield.getText().trim()); - - if(port < 0) - ssh.connect(hostname); - else - ssh.connect(hostname,port); - - // Try the authentication - result = ssh.authenticate(pwd); - } - return ssh; - } - - /** - * - * Set the login information. - * - */ - private boolean setLogin() - { - JPanel promptPanel = new JPanel(new GridLayout(4,2)); - - if(hostname != null && hostfield.getText().equals("")) - hostfield.setText(hostname); - - if(port >-1 && portfield.getText().equals("")) - portfield.setText(Integer.toString(port)); - - if(user != null && ufield.getText().equals("")) - ufield.setText(user); - - JLabel hostlab = new JLabel(" Hostname:", SwingConstants.LEFT); - JLabel portlab = new JLabel(" Port:", SwingConstants.LEFT); - - JLabel ulab = new JLabel(" Username:", SwingConstants.LEFT); - JLabel plab = new JLabel(" Password:", SwingConstants.LEFT); - //add labels etc - promptPanel.add(hostlab); - promptPanel.add(hostfield); - - promptPanel.add(portlab); - promptPanel.add(portfield); - - promptPanel.add(ulab); - promptPanel.add(ufield); - - promptPanel.add(plab); - promptPanel.add(pfield); - - Object[] options = { "CANCEL", "LOGIN AND RUN"}; - - int select = JOptionPane.showOptionDialog(null, promptPanel, - "LOGIN", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - options, - options[1]); - - if(select == 0) - return false; - - return true; - } - - - /** - * - * Get the properties from the j2ssh.properties file. - * - */ - private Properties getProperties() - { - Properties settings = new Properties(); - ClassLoader cl = this.getClass().getClassLoader(); - // try out of the classpath - try - { - settings.load(cl.getResourceAsStream("j2ssh.properties")); - } - catch (Exception e) - { - } - - if(hostname == null && settings.getProperty("host") != null) - hostname = settings.getProperty("host"); - if(port < 0 && settings.getProperty("port") != null) - port = Integer.parseInt(settings.getProperty("port")); - if(user == null) - user = System.getProperty("user.name"); - - return settings; + SshLogin sshLogin = new SshLogin(); + ssh = sshLogin.getSshClient(); } public boolean remoteList(String remoteRootDir) diff --git a/uk/ac/sanger/artemis/j2ssh/SshLogin.java b/uk/ac/sanger/artemis/j2ssh/SshLogin.java index 5fdacae967c619e0b3524e169e93fdfbc80925f6..f40c249125ae5200c4ce96922e1d31f7f6aea601 100644 --- a/uk/ac/sanger/artemis/j2ssh/SshLogin.java +++ b/uk/ac/sanger/artemis/j2ssh/SshLogin.java @@ -74,6 +74,7 @@ public class SshLogin { try { + logfile = System.getProperty("logfile"); // Setup a logfile if(logfile != null) { @@ -89,7 +90,7 @@ public class SshLogin catch(IOException ioe){} if(settings == null) - settings = getProperties(); + settings = setProperties(); } public SshClient getSshClient() @@ -110,6 +111,11 @@ public class SshLogin return ufield.getText().trim(); } + public static Properties getProperties() + { + return settings; + } + /** * * Log the user in. @@ -208,7 +214,7 @@ public class SshLogin * Get the properties from the j2ssh.properties file. * */ - private Properties getProperties() + private Properties setProperties() { Properties settings = new Properties(); ClassLoader cl = this.getClass().getClassLoader(); diff --git a/uk/ac/sanger/artemis/j2ssh/SshPSUClient.java b/uk/ac/sanger/artemis/j2ssh/SshPSUClient.java index b4e3d116af9f6ff926d5c4df1c08ed5f947799c2..c6ed411bf1e232aab13d277326415dee90e2feec 100644 --- a/uk/ac/sanger/artemis/j2ssh/SshPSUClient.java +++ b/uk/ac/sanger/artemis/j2ssh/SshPSUClient.java @@ -43,19 +43,10 @@ import java.io.IOException; import java.util.Vector; import java.util.Properties; -import java.util.logging.FileHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; import com.sshtools.j2ssh.SshClient; -import com.sshtools.j2ssh.authentication.AuthenticationProtocolState; -import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; import com.sshtools.j2ssh.session.SessionChannelClient; -import com.sshtools.j2ssh.sftp.FileAttributes; import com.sshtools.j2ssh.sftp.SftpFile; -import com.sshtools.j2ssh.sftp.SftpFileOutputStream; import com.sshtools.j2ssh.SftpClient; import com.sshtools.j2ssh.configuration.ConfigurationLoader; @@ -76,14 +67,9 @@ public class SshPSUClient extends Thread private String db = null; private String wdir = "/nfs/pathscratch1/scratch"; - // login variables - private String hostname = null; - private String user = null; - private int port = -1; - private static JPasswordField pfield = new JPasswordField(16); - private static JTextField portfield = new JTextField(16); - private static JTextField hostfield = new JTextField(16); - private static JTextField ufield = new JTextField(16); + // + private SshClient ssh; + private String user; public SshPSUClient(String args[]) { @@ -92,11 +78,7 @@ public class SshPSUClient extends Thread { for(int i=0; i<args.length; i++) { - if(args[i].equals("-h") && i < args.length-1) - hostname = args[i+1]; - else if(args[i].equals("-u") && i < args.length-1) - user = args[i+1]; - else if(args[i].equals("-f") && i < args.length-1) + if(args[i].equals("-f") && i < args.length-1) listfilepath = args[i+1]; else if(args[i].equals("-cmd") && i < args.length-1) cmd = args[i+1]; @@ -104,8 +86,6 @@ public class SshPSUClient extends Thread bsub = args[i+1]; else if(args[i].equals("-l") && i < args.length-1) logfile = args[i+1]; - else if(args[i].equals("-p") && i < args.length-1) - port = Integer.parseInt(args[i+1]); else if(args[i].equals("-d") && i < args.length-1) db = args[i+1]; else if(args[i].equals("-wdir") && i < args.length-1) @@ -113,26 +93,15 @@ public class SshPSUClient extends Thread } } - try - { - // Setup a logfile - if(logfile != null) - { - Handler fh = new FileHandler(logfile); - fh.setFormatter(new SimpleFormatter()); - Logger.getLogger("com.sshtools").setUseParentHandlers(false); - Logger.getLogger("com.sshtools").addHandler(fh); - Logger.getLogger("com.sshtools").setLevel(Level.ALL); - } - else - Logger.getLogger("com.sshtools").setLevel(Level.OFF); - } - catch(IOException ioe){} + SshLogin sshLogin = new SshLogin(); + ssh = sshLogin.getSshClient(); + user = sshLogin.getUser(); } public void run() { String program = cmd; + // get properties from j2ssh.properties Properties settings = getProperties(); @@ -141,14 +110,13 @@ public class SshPSUClient extends Thread { ConfigurationLoader.initialize(false); - SshClient ssh = login(); if(ssh == null) return; completed = runBlastOrFasta(ssh, program, settings); // Quit - ssh.disconnect(); + //ssh.disconnect(); } catch(IOException ioe){} finally @@ -215,99 +183,6 @@ public class SshPSUClient extends Thread return false; } - /** - * - * Log the user in. - * - */ - private SshClient login() - throws IOException - { - SshClient ssh = null; - int result = AuthenticationProtocolState.FAILED; - - while(result != AuthenticationProtocolState.COMPLETE) - { - if(!setLogin()) - return null; - - // Create a password authentication instance - PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); - user = ufield.getText().trim(); - pwd.setUsername(user); - pwd.setPassword(new String(pfield.getPassword())); - - // Make a client connection - ssh = new SshClient(); - hostname = hostfield.getText().trim(); - if(portfield.getText().trim().equals("")) - port = -1; - else - port = Integer.parseInt(portfield.getText().trim()); - - if(port < 0) - ssh.connect(hostname); - else - ssh.connect(hostname,port); - - // Try the authentication - result = ssh.authenticate(pwd); - } - return ssh; - } - - /** - * - * Set the login information. - * - */ - private boolean setLogin() - { - JPanel promptPanel = new JPanel(new GridLayout(4,2)); - - if(hostname != null && hostfield.getText().equals("")) - hostfield.setText(hostname); - - if(port >-1 && portfield.getText().equals("")) - portfield.setText(Integer.toString(port)); - - if(user != null && ufield.getText().equals("")) - ufield.setText(user); - - JLabel hostlab = new JLabel(" Hostname:", SwingConstants.LEFT); - JLabel portlab = new JLabel(" Port:", SwingConstants.LEFT); - - JLabel ulab = new JLabel(" Username:", SwingConstants.LEFT); - JLabel plab = new JLabel(" Password:", SwingConstants.LEFT); - //add labels etc - promptPanel.add(hostlab); - promptPanel.add(hostfield); - - promptPanel.add(portlab); - promptPanel.add(portfield); - - promptPanel.add(ulab); - promptPanel.add(ufield); - - promptPanel.add(plab); - promptPanel.add(pfield); - - Object[] options = { "CANCEL", "LOGIN AND RUN"}; - - int select = JOptionPane.showOptionDialog(null, promptPanel, - "LOGIN", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - options, - options[1]); - - if(select == 0) - return false; - - return true; - } - /** * @@ -327,14 +202,8 @@ public class SshPSUClient extends Thread { } - if(hostname == null && settings.getProperty("host") != null) - hostname = settings.getProperty("host"); - if(port < 0 && settings.getProperty("port") != null) - port = Integer.parseInt(settings.getProperty("port")); if(bsub == null && settings.getProperty("bsub") != null) bsub = settings.getProperty("bsub"); - if(user == null) - user = System.getProperty("user.name"); if(db == null) { if(settings.getProperty("default_db") != null) @@ -404,7 +273,9 @@ public class SshPSUClient extends Thread sftp.put(filepath, wdir+filename); } catch(IOException ioe) - {} + { + ioe.printStackTrace(); + } SessionChannelClient session = ssh.openSessionChannel();