applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / test / simpleclient / simpleapp / VamsasClient.java
index d4b9ec0..67db315 100644 (file)
-/**
- * 
- */
-package uk.ac.vamsas.test.simpleclient.simpleapp;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.Vector;
-import java.util.jar.JarOutputStream;
-
-import javax.swing.JInternalFrame;
-
-
-import uk.ac.vamsas.client.UserHandle;
-import uk.ac.vamsas.client.simpleclient.FileWatcher;
-import uk.ac.vamsas.client.simpleclient.VamsasArchive;
-import uk.ac.vamsas.client.simpleclient.VamsasFile;
-import uk.ac.vamsas.objects.core.Entry;
-import uk.ac.vamsas.objects.core.VamsasDocument;
-import uk.ac.vamsas.test.simpleclient.ArchiveClient;
-import uk.ac.vamsas.test.simpleclient.ClientDoc;
-
-/**
- * @author jimp
- *
- */
-public class VamsasClient extends ArchiveClient {
-       org.apache.commons.logging.Log log=org.apache.commons.logging.LogFactory.getLog(VamsasClient.class);
-  /**
-   * create a new vamsas client session from the archive at sessionPath.
-   * @param sessionPath
-   */
-  public VamsasClient(File sessionPath) {
-               super(System.getProperty("user.name"),System.getProperty("host.name"), "SimpleVamsasClientApp","0.1",
-                               sessionPath);
-       }
-  /**
-   * Called by gui to read anything from the vamsas session into the apps datamodel
-   * after it has started up.
-   *
-   */
-       public void initial_update() {
-               log.info("Jalview loading the Vamsas Session.");
-               // load in the vamsas archive for the first time
-               ClientDoc cdoc = this.getUpdateable();
-               updateJalview(cdoc);
-               // TODO: flush any new VorbaIds to the document : updateVamsasClient may actually generate new Vamsas Document data in the form of vamsas element ids - these should be written back to the document. 
-    //doUpdate(cdoc); // JBPNote: this should flush new VorbaIds but I've not tested it yet.
-    cdoc.closeDoc();
-               // then tell app to update its display based on the datamodel changes.
-       }
-  VamsasClientWatcher watcher=null;
-       /**
-   * Called by app when internal datamodel should exported (syncrhonised outwards) to vamsas document 
-   *
-        */
-  public void push_update() {
-
-    watchForChange=false; // this makes any watch(long) loops return. 
-    // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped. 
-    try {
-      Thread.sleep(WATCH_SLEEP); 
-    } catch (Exception e) {
-      
-    };
-    
-    ClientDoc cdoc = getUpdateable();
-    updateVamsasDocument(cdoc);
-    doUpdate(cdoc);
-    cdoc.closeDoc();
-    cdoc=null;
-    watchForChange=true;
-    startWatcher();
-       }
-       public void end_session() {
-    watchForChange=false; // this makes any watch(long) loops return. 
-    // we should also wait arount for this.WATCH_SLEEP to really make sure the watcher thread has stopped. 
-    try {
-      Thread.sleep(WATCH_SLEEP); 
-    } catch (Exception e) {
-      
-    };
-    
-               // stop any update/watcher thread.
-               log.info("VamsasClientApplication disconnecting from the Vamsas Session.");
-       }
-       public void updateJalview(ClientDoc cdoc) {
-               ensureVamsasBindings();
-    VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj, baseProvEntry());
-    vds.updateToJalview();
-       }
-       private void ensureVamsasBindings() {
-    if (jv2vobj==null) {
-      jv2vobj = new IdentityHashMap();
-      vobj2jv = new Hashtable();
-    }
-       }
-       /**
-        * App's object binding to VorbaIds
-        */
-       IdentityHashMap jv2vobj = null;
-       Hashtable vobj2jv = null;
-       /**
-   * called with a vamsas document which will be updated with new data from the app
-   * @param doc
-        */
-  public void updateVamsasDocument(ClientDoc doc) {
-         ensureVamsasBindings();
-    VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj, baseProvEntry());
-    // wander through frames 
-    vds.storeVAMSAS(new Object()); // Object is the apps datamodel ;)
-       }
-  /**
-   * 
-   * @return a base provenance entry used by the VamsasDatastore object to get attributes from. this isn't particularly elegant either.
-   */
-       private Entry baseProvEntry() {
-    uk.ac.vamsas.objects.core.Entry pentry = new uk.ac.vamsas.objects.core.Entry();
-    pentry.setUser(this.getProvenanceUser());
-    pentry.setApp(this.getClientHandle().getClientName());
-    pentry.setDate(new java.util.Date());
-    pentry.setAction("created");
-    return pentry;
-       }
-  protected class VamsasClientWatcher extends Thread implements Runnable {
-               /* (non-Javadoc)
-                * @see java.lang.Thread#run()
-                */
-               VamsasClient client=null;
-               VamsasClientWatcher(VamsasClient client) {
-                       this.client = client;
-               }
-    boolean running=false;
-               public void run() {
-                 running=true;
-                       while (client.watchForChange) {
-                         ClientDoc docio = client.watch(0);
-                         if (docio!=null) {
-          // VamsasClient GUI bits should be disabled whilst an update is in progress so the user doesn't screw anything up.
-          client.disableGui(true);
-          log.debug("Updating VamsasClient app from changed vamsas document.");
-                           client.updateJalview(docio);
-          log.debug("Finished updating from document change.");
-          docio.closeDoc();
-          docio=null;
-          client.disableGui(false);
-                         }
-      }
-      running=false;
-      
-               }
-               
-       }
-       /**
-        * @param args
-        */
-       public static void main(String[] args) {
-               // TODO Auto-generated method stub
-
-       }
-  /**
-   * disable (if b is true) or enable (if b is true) the VamsasClient's vamsas session gui bits whilst a document change is being updated to the app.
-   * @param b 
-   */
-  public void disableGui(boolean b) {
-      // in jalview, we turn off the VAMSAS Session menu : Desktop.instance.setVamsasUpdate(b);    
-  }
-  /**
-   * spawn a new thread to start the VamsasClientWatcher.
-   *
-   */
-  public void startWatcher() {
-    if (watcher==null)
-      watcher=new VamsasClientWatcher(this);
-    Thread thr = new Thread() {
-      public void run() {
-        watcher.start();
-      }
-    };
-    thr.start();
-  }
-
-}
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ *  Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *  \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package uk.ac.vamsas.test.simpleclient.simpleapp;\r
+\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.PrintWriter;\r
+import java.util.Hashtable;\r
+import java.util.IdentityHashMap;\r
+import java.util.Vector;\r
+import java.util.jar.JarOutputStream;\r
+\r
+import javax.swing.JInternalFrame;\r
+\r
+import uk.ac.vamsas.client.UserHandle;\r
+import uk.ac.vamsas.client.simpleclient.FileWatcher;\r
+import uk.ac.vamsas.client.simpleclient.VamsasArchive;\r
+import uk.ac.vamsas.client.simpleclient.VamsasFile;\r
+import uk.ac.vamsas.objects.core.Entry;\r
+import uk.ac.vamsas.objects.core.VamsasDocument;\r
+import uk.ac.vamsas.test.simpleclient.ArchiveClient;\r
+import uk.ac.vamsas.test.simpleclient.ClientDoc;\r
+\r
+/**\r
+ * @author jimp\r
+ * \r
+ */\r
+public class VamsasClient extends ArchiveClient {\r
+  org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory\r
+      .getLog(VamsasClient.class);\r
+\r
+  /**\r
+   * create a new vamsas client session from the archive at sessionPath.\r
+   * \r
+   * @param sessionPath\r
+   */\r
+  public VamsasClient(File sessionPath) {\r
+    super(System.getProperty("user.name"), System.getProperty("host.name"),\r
+        "SimpleVamsasClientApp", "0.1", sessionPath);\r
+  }\r
+\r
+  /**\r
+   * Called by gui to read anything from the vamsas session into the apps\r
+   * datamodel after it has started up.\r
+   * \r
+   */\r
+  public void initial_update() {\r
+    log.info("Jalview loading the Vamsas Session.");\r
+    // load in the vamsas archive for the first time\r
+    ClientDoc cdoc = this.getUpdateable();\r
+    updateJalview(cdoc);\r
+    // TODO: flush any new VorbaIds to the document : updateVamsasClient may\r
+    // actually generate new Vamsas Document data in the form of vamsas element\r
+    // ids - these should be written back to the document.\r
+    // doUpdate(cdoc); // JBPNote: this should flush new VorbaIds but I've not\r
+    // tested it yet.\r
+    cdoc.closeDoc();\r
+    // then tell app to update its display based on the datamodel changes.\r
+  }\r
+\r
+  VamsasClientWatcher watcher = null;\r
+\r
+  /**\r
+   * Called by app when internal datamodel should exported (syncrhonised\r
+   * outwards) to vamsas document\r
+   * \r
+   */\r
+  public void push_update() {\r
+\r
+    watchForChange = false; // this makes any watch(long) loops return.\r
+    // we should also wait arount for this.WATCH_SLEEP to really make sure the\r
+    // watcher thread has stopped.\r
+    try {\r
+      Thread.sleep(WATCH_SLEEP);\r
+    } catch (Exception e) {\r
+\r
+    }\r
+    ;\r
+\r
+    ClientDoc cdoc = getUpdateable();\r
+    updateVamsasDocument(cdoc);\r
+    doUpdate(cdoc);\r
+    cdoc.closeDoc();\r
+    cdoc = null;\r
+    watchForChange = true;\r
+    startWatcher();\r
+  }\r
+\r
+  public void end_session() {\r
+    watchForChange = false; // this makes any watch(long) loops return.\r
+    // we should also wait arount for this.WATCH_SLEEP to really make sure the\r
+    // watcher thread has stopped.\r
+    try {\r
+      Thread.sleep(WATCH_SLEEP);\r
+    } catch (Exception e) {\r
+\r
+    }\r
+    ;\r
+\r
+    // stop any update/watcher thread.\r
+    log.info("VamsasClientApplication disconnecting from the Vamsas Session.");\r
+  }\r
+\r
+  public void updateJalview(ClientDoc cdoc) {\r
+    ensureVamsasBindings();\r
+    VamsasDatastore vds = new VamsasDatastore(cdoc, vobj2jv, jv2vobj,\r
+        baseProvEntry());\r
+    vds.updateToJalview();\r
+  }\r
+\r
+  private void ensureVamsasBindings() {\r
+    if (jv2vobj == null) {\r
+      jv2vobj = new IdentityHashMap();\r
+      vobj2jv = new Hashtable();\r
+    }\r
+  }\r
+\r
+  /**\r
+   * App's object binding to VorbaIds\r
+   */\r
+  IdentityHashMap jv2vobj = null;\r
+\r
+  Hashtable vobj2jv = null;\r
+\r
+  /**\r
+   * called with a vamsas document which will be updated with new data from the\r
+   * app\r
+   * \r
+   * @param doc\r
+   */\r
+  public void updateVamsasDocument(ClientDoc doc) {\r
+    ensureVamsasBindings();\r
+    VamsasDatastore vds = new VamsasDatastore(doc, vobj2jv, jv2vobj,\r
+        baseProvEntry());\r
+    // wander through frames\r
+    vds.storeVAMSAS(new Object()); // Object is the apps datamodel ;)\r
+  }\r
+\r
+  /**\r
+   * \r
+   * @return a base provenance entry used by the VamsasDatastore object to get\r
+   *         attributes from. this isn't particularly elegant either.\r
+   */\r
+  private Entry baseProvEntry() {\r
+    uk.ac.vamsas.objects.core.Entry pentry = new uk.ac.vamsas.objects.core.Entry();\r
+    pentry.setUser(this.getProvenanceUser());\r
+    pentry.setApp(this.getClientHandle().getClientName());\r
+    pentry.setDate(new java.util.Date());\r
+    pentry.setAction("created");\r
+    return pentry;\r
+  }\r
+\r
+  protected class VamsasClientWatcher extends Thread implements Runnable {\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see java.lang.Thread#run()\r
+     */\r
+    VamsasClient client = null;\r
+\r
+    VamsasClientWatcher(VamsasClient client) {\r
+      this.client = client;\r
+    }\r
+\r
+    boolean running = false;\r
+\r
+    public void run() {\r
+      running = true;\r
+      while (client.watchForChange) {\r
+        ClientDoc docio = client.watch(0);\r
+        if (docio != null) {\r
+          // VamsasClient GUI bits should be disabled whilst an update is in\r
+          // progress so the user doesn't screw anything up.\r
+          client.disableGui(true);\r
+          log.debug("Updating VamsasClient app from changed vamsas document.");\r
+          client.updateJalview(docio);\r
+          log.debug("Finished updating from document change.");\r
+          docio.closeDoc();\r
+          docio = null;\r
+          client.disableGui(false);\r
+        }\r
+      }\r
+      running = false;\r
+\r
+    }\r
+\r
+  }\r
+\r
+  /**\r
+   * @param args\r
+   */\r
+  public static void main(String[] args) {\r
+    // TODO Auto-generated method stub\r
+\r
+  }\r
+\r
+  /**\r
+   * disable (if b is true) or enable (if b is true) the VamsasClient's vamsas\r
+   * session gui bits whilst a document change is being updated to the app.\r
+   * \r
+   * @param b\r
+   */\r
+  public void disableGui(boolean b) {\r
+    // in jalview, we turn off the VAMSAS Session menu :\r
+    // Desktop.instance.setVamsasUpdate(b);\r
+  }\r
+\r
+  /**\r
+   * spawn a new thread to start the VamsasClientWatcher.\r
+   * \r
+   */\r
+  public void startWatcher() {\r
+    if (watcher == null)\r
+      watcher = new VamsasClientWatcher(this);\r
+    Thread thr = new Thread() {\r
+      public void run() {\r
+        watcher.start();\r
+      }\r
+    };\r
+    thr.start();\r
+  }\r
+\r
+}\r