refactored VamsasClient to jalview.gui, and created Vamsas session menu.
authorjprocter <Jim Procter>
Sun, 26 Mar 2006 12:29:34 +0000 (12:29 +0000)
committerjprocter <Jim Procter>
Sun, 26 Mar 2006 12:29:34 +0000 (12:29 +0000)
src/jalview/gui/Desktop.java
src/jalview/gui/VamsasClient.java [new file with mode: 0755]
src/jalview/io/VamsasClient.java [deleted file]
src/jalview/jbgui/GDesktop.java

index 3bc2613..902d564 100755 (executable)
@@ -578,7 +578,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             Jalview2XML.LoadJalviewAlign(choice);\r
         }\r
     }\r
-    jalview.io.VamsasClient v_client=null;\r
+    jalview.gui.VamsasClient v_client=null;\r
     public void vamsasLoad_actionPerformed(ActionEvent e)\r
     {\r
       if (v_client==null) {\r
@@ -594,7 +594,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 \r
         if (value == JalviewFileChooser.APPROVE_OPTION)\r
         {\r
-          v_client = new jalview.io.VamsasClient(this,\r
+          v_client = new jalview.gui.VamsasClient(this,\r
               chooser.getSelectedFile().getAbsolutePath()\r
               );\r
           this.vamsasLoad.setText("Session Update");\r
diff --git a/src/jalview/gui/VamsasClient.java b/src/jalview/gui/VamsasClient.java
new file mode 100755 (executable)
index 0000000..d17f746
--- /dev/null
@@ -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 (executable)
index ca62b09..0000000
+++ /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
-
-       }
-
-}
index 4ecf779..499efd5 100755 (executable)
@@ -36,6 +36,7 @@ public class GDesktop extends JFrame
     JMenuBar DesktopMenubar = new JMenuBar();\r
     JMenu FileMenu = new JMenu();\r
     JMenu HelpMenu = new JMenu();\r
+    protected JMenu VamsasMenu = new JMenu();\r
     JMenuItem inputLocalFileMenuItem = new JMenuItem();\r
     JMenuItem inputURLMenuItem = new JMenuItem();\r
     JMenuItem inputTextboxMenuItem = new JMenuItem();\r
@@ -78,6 +79,9 @@ public class GDesktop extends JFrame
         FileMenu.setMnemonic('F');\r
         FileMenu.setText("File");\r
         HelpMenu.setText("Help");\r
+        VamsasMenu.setText("Vamsas");\r
+        VamsasMenu.setMnemonic('V');\r
+        VamsasMenu.setToolTipText("Share data with other vamsas applications.");\r
         inputLocalFileMenuItem.setMnemonic('L');\r
         inputLocalFileMenuItem.setText("from File");\r
         inputLocalFileMenuItem.addActionListener(new java.awt.event.ActionListener()\r
@@ -188,6 +192,7 @@ public class GDesktop extends JFrame
       }\r
     });    DesktopMenubar.add(FileMenu);\r
         DesktopMenubar.add(toolsMenu);\r
+        DesktopMenubar.add(VamsasMenu);\r
         DesktopMenubar.add(HelpMenu);\r
         DesktopMenubar.add(windowMenu);\r
         FileMenu.addSeparator();\r
@@ -196,13 +201,12 @@ public class GDesktop extends JFrame
     FileMenu.addSeparator();\r
         FileMenu.add(saveState);\r
         FileMenu.add(loadState);\r
-        FileMenu.addSeparator();\r
-        FileMenu.add(vamsasLoad);\r
-        FileMenu.add(vamsasStop);\r
     FileMenu.addSeparator();\r
     FileMenu.add(quit);\r
         HelpMenu.add(aboutMenuItem);\r
         HelpMenu.add(documentationMenuItem);\r
+        VamsasMenu.add(vamsasLoad);\r
+        VamsasMenu.add(vamsasStop);\r
         toolsMenu.add(preferences);\r
         jMenu1.add(inputLocalFileMenuItem);\r
         jMenu1.add(inputURLMenuItem);\r