/** * */ 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 } }