From 9126ec7ce6e35d4e9e2a984f53a10ac14f71bca3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Sun, 26 Mar 2006 12:29:34 +0000 Subject: [PATCH] refactored VamsasClient to jalview.gui, and created Vamsas session menu. --- src/jalview/gui/Desktop.java | 4 +- src/jalview/gui/VamsasClient.java | 138 +++++++++++++++++++++++++++++++++++++ src/jalview/io/VamsasClient.java | 67 ------------------ src/jalview/jbgui/GDesktop.java | 10 ++- 4 files changed, 147 insertions(+), 72 deletions(-) create mode 100755 src/jalview/gui/VamsasClient.java delete mode 100755 src/jalview/io/VamsasClient.java diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 3bc2613..902d564 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -578,7 +578,7 @@ public class Desktop extends jalview.jbgui.GDesktop Jalview2XML.LoadJalviewAlign(choice); } } - jalview.io.VamsasClient v_client=null; + jalview.gui.VamsasClient v_client=null; public void vamsasLoad_actionPerformed(ActionEvent e) { if (v_client==null) { @@ -594,7 +594,7 @@ public class Desktop extends jalview.jbgui.GDesktop if (value == JalviewFileChooser.APPROVE_OPTION) { - v_client = new jalview.io.VamsasClient(this, + v_client = new jalview.gui.VamsasClient(this, chooser.getSelectedFile().getAbsolutePath() ); this.vamsasLoad.setText("Session Update"); diff --git a/src/jalview/gui/VamsasClient.java b/src/jalview/gui/VamsasClient.java new file mode 100755 index 0000000..d17f746 --- /dev/null +++ b/src/jalview/gui/VamsasClient.java @@ -0,0 +1,138 @@ +/** + * + */ +package jalview.gui; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.Vector; +import java.util.jar.JarOutputStream; + +import javax.swing.JInternalFrame; + +import jalview.bin.Cache; + +import org.vamsas.client.UserHandle; +import org.vamsas.client.simpleclient.FileWatcher; +import org.vamsas.client.simpleclient.VamsasArchive; +import org.vamsas.client.simpleclient.VamsasFile; +import org.vamsas.objects.core.VamsasDocument; +import org.vamsas.test.simpleclient.ArchiveClient; + +/** + * @author jimp + * + */ +public class VamsasClient extends ArchiveClient { + Desktop us; + // Cache.preferences for vamsas client session arena + // preferences for check for default session at startup. + // user and organisation stuff. + public VamsasClient(Desktop jdesktop, + String sessionPath) { + super("Jalview User", "Dundee", // new org.vamsas.client.ClientHandle("jalview","2.7"), + sessionPath); + us=jdesktop; + } + public void initial_update() { + Cache.log.info("Jalview loading the Vamsas Session."); + // load in the vamsas archive for the first time + + // VamsasArchive doc = new VamsasArchive(); + } + public void get_update(VamsasArchive doc) { + Cache.log.info("Jalview updating from Vamsas Session."); + } + public void push_update() { + // collect all uncached alignments and put them into the vamsas dataset. + // store them. + Cache.log.info("Jalview updating the Vamsas Session."); + } + public void end_session() { + // stop any update/watcher thread. + Cache.log.info("Jalview disconnecting from the Vamsas Session."); + } + public void updateVamsasDocument(VamsasDocument doc) { + // wander through frames + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); + + if (frames == null) + { + return; + } + + try + { + Vector shortNames = new Vector(); + + //REVERSE ORDER + for (int i = frames.length - 1; i > -1; i--) + { + if (frames[i] instanceof AlignFrame) + { + AlignFrame af = (AlignFrame) frames[i]; + // check if this frame has an associated alignment object ? + // update alignment and root from frame. + + + String shortName = af.getTitle(); + + if (shortName.indexOf(File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + File.separatorChar) + 1); + } + + int count = 1; + + while (shortNames.contains(shortName)) + { + if (shortName.endsWith("_" + (count - 1))) + { + shortName = shortName.substring(0, + shortName.lastIndexOf("_")); + } + + shortName = shortName.concat("_" + count); + count++; + } + + shortNames.addElement(shortName); + + if (!shortName.endsWith(".xml")) + { + shortName = shortName + ".xml"; + } + + } + } + } + catch (Exception e) { + Cache.log.error("Vamsas Document store exception",e); + } + } + protected class VamsasClientWatcher extends Thread implements Runnable { + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ + VamsasClient client=null; + VamsasClientWatcher(VamsasClient client) { + this.client = client; + } + public void run() { + VamsasArchive docio = client.watch(0); + client.get_update(docio); + } + + } + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/jalview/io/VamsasClient.java b/src/jalview/io/VamsasClient.java deleted file mode 100755 index ca62b09..0000000 --- a/src/jalview/io/VamsasClient.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - */ -package jalview.io; - -import jalview.bin.Cache; -import jalview.gui.Desktop; - -import org.vamsas.client.UserHandle; -import org.vamsas.client.simpleclient.FileWatcher; -import org.vamsas.client.simpleclient.VamsasArchive; -import org.vamsas.client.simpleclient.VamsasFile; -import org.vamsas.test.simpleclient.ArchiveClient; - -/** - * @author jimp - * - */ -public class VamsasClient extends ArchiveClient { - Desktop us; - public VamsasClient(Desktop jdesktop, - String sessionPath) { - super("Jalview User", "Dundee", // new org.vamsas.client.ClientHandle("jalview","2.7"), - sessionPath); - us=jdesktop; - } - public void initial_update() { - Cache.log.info("Jalview loading the Vamsas Session."); - // load in the vamsas archive for the first time - - // VamsasArchive doc = new VamsasArchive(); - } - public void get_update(VamsasArchive doc) { - Cache.log.info("Jalview updating from Vamsas Session."); - } - public void push_update() { - // collect all uncached alignments and put them into the vamsas dataset. - // store them. - Cache.log.info("Jalview updating the Vamsas Session."); - } - public void end_session() { - // stop any update/watcher thread. - Cache.log.info("Jalview disconnecting from the Vamsas Session."); - } - protected class VamsasClientWatcher extends Thread implements Runnable { - /* (non-Javadoc) - * @see java.lang.Thread#run() - */ - VamsasClient client=null; - VamsasClientWatcher(VamsasClient client) { - this.client = client; - } - public void run() { - VamsasArchive docio = client.watch(0); - client.get_update(docio); - } - - } - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 4ecf779..499efd5 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -36,6 +36,7 @@ public class GDesktop extends JFrame JMenuBar DesktopMenubar = new JMenuBar(); JMenu FileMenu = new JMenu(); JMenu HelpMenu = new JMenu(); + protected JMenu VamsasMenu = new JMenu(); JMenuItem inputLocalFileMenuItem = new JMenuItem(); JMenuItem inputURLMenuItem = new JMenuItem(); JMenuItem inputTextboxMenuItem = new JMenuItem(); @@ -78,6 +79,9 @@ public class GDesktop extends JFrame FileMenu.setMnemonic('F'); FileMenu.setText("File"); HelpMenu.setText("Help"); + VamsasMenu.setText("Vamsas"); + VamsasMenu.setMnemonic('V'); + VamsasMenu.setToolTipText("Share data with other vamsas applications."); inputLocalFileMenuItem.setMnemonic('L'); inputLocalFileMenuItem.setText("from File"); inputLocalFileMenuItem.addActionListener(new java.awt.event.ActionListener() @@ -188,6 +192,7 @@ public class GDesktop extends JFrame } }); DesktopMenubar.add(FileMenu); DesktopMenubar.add(toolsMenu); + DesktopMenubar.add(VamsasMenu); DesktopMenubar.add(HelpMenu); DesktopMenubar.add(windowMenu); FileMenu.addSeparator(); @@ -196,13 +201,12 @@ public class GDesktop extends JFrame FileMenu.addSeparator(); FileMenu.add(saveState); FileMenu.add(loadState); - FileMenu.addSeparator(); - FileMenu.add(vamsasLoad); - FileMenu.add(vamsasStop); FileMenu.addSeparator(); FileMenu.add(quit); HelpMenu.add(aboutMenuItem); HelpMenu.add(documentationMenuItem); + VamsasMenu.add(vamsasLoad); + VamsasMenu.add(vamsasStop); toolsMenu.add(preferences); jMenu1.add(inputLocalFileMenuItem); jMenu1.add(inputURLMenuItem); -- 1.7.10.2