- AlignFrame[] frames = Desktop.getAlignFrames();
-
- for (AlignFrame afr : frames)
- {
- if (sequenceSetId == null
- || afr.getViewport().getSequenceSetId()
- .equals(sequenceSetId))
- {
- if (afr.alignPanels != null)
- {
- for (AlignmentPanel ap : afr.alignPanels)
- {
- if (sequenceSetId == null
- || sequenceSetId.equals(ap.av.getSequenceSetId()))
- {
- viewp.add(ap.av);
- }
- }
- }
- else
- {
- viewp.add(afr.getViewport());
- }
- }
- }
- if (viewp.size() > 0)
- {
- return viewp.toArray(new AlignmentViewport[viewp.size()]);
- }
- }
- return null;
- }
-
- /**
- * Explode the views in the given frame into separate AlignFrame
- *
- * @param af
- */
- public static void explodeViews(AlignFrame af)
- {
- int size = af.alignPanels.size();
- if (size < 2)
- {
- return;
- }
-
- for (int i = 0; i < size; i++)
- {
- AlignmentPanel ap = af.alignPanels.get(i);
- AlignFrame newaf = new AlignFrame(ap);
-
- /*
- * Restore the view's last exploded frame geometry if known. Multiple
- * views from one exploded frame share and restore the same (frame)
- * position and size.
- */
- Rectangle geometry = ap.av.getExplodedGeometry();
- if (geometry != null)
- {
- newaf.setBounds(geometry);
- }
-
- ap.av.setGatherViewsHere(false);
-
- addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
- AlignFrame.DEFAULT_HEIGHT);
- }
-
- af.alignPanels.clear();
- af.closeMenuItem_actionPerformed(true);
-
- }
-
- /**
- * Gather expanded views (separate AlignFrame's) with the same sequence set
- * identifier back in to this frame as additional views, and close the
- * expanded views. Note the expanded frames may themselves have multiple
- * views. We take the lot.
- *
- * @param source
- */
- public void gatherViews(AlignFrame source)
- {
- source.viewport.setGatherViewsHere(true);
- source.viewport.setExplodedGeometry(source.getBounds());
- JInternalFrame[] frames = desktop.getAllFrames();
- String viewId = source.viewport.getSequenceSetId();
-
- for (int t = 0; t < frames.length; t++)
- {
- if (frames[t] instanceof AlignFrame && frames[t] != source)
- {
- AlignFrame af = (AlignFrame) frames[t];
- boolean gatherThis = false;
- for (int a = 0; a < af.alignPanels.size(); a++)
- {
- AlignmentPanel ap = af.alignPanels.get(a);
- if (viewId.equals(ap.av.getSequenceSetId()))
- {
- gatherThis = true;
- ap.av.setGatherViewsHere(false);
- ap.av.setExplodedGeometry(af.getBounds());
- source.addAlignmentPanel(ap, false);
- }
- }
-
- if (gatherThis)
- {
- af.alignPanels.clear();
- af.closeMenuItem_actionPerformed(true);
- }
- }
- }
-
- }
-
- jalview.gui.VamsasApplication v_client = null;
-
- @Override
- public void vamsasImport_actionPerformed(ActionEvent e)
- {
- if (v_client == null)
- {
- // Load and try to start a session.
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager
- .getString("label.open_saved_vamsas_session"));
- chooser.setToolTipText(MessageManager
- .getString("label.select_vamsas_session_opened_as_new_vamsas_session"));
-
- int value = chooser.showOpenDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- String fle = chooser.getSelectedFile().toString();
- if (!vamsasImport(chooser.getSelectedFile()))
- {
- JvOptionPane
- .showInternalMessageDialog(
- Desktop.desktop,
- MessageManager.formatMessage(
- "label.couldnt_import_as_vamsas_session",
- new Object[] { fle }),
- MessageManager
- .getString("label.vamsas_document_import_failed"),
- JvOptionPane.ERROR_MESSAGE);
- }
- }
- }
- else
- {
- jalview.bin.Cache.log
- .error("Implementation error - load session from a running session is not supported.");
- }
- }
-
- /**
- * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
- *
- * @param file
- * @return true if import was a success and a session was started.
- */
- public boolean vamsasImport(URL url)
- {
- // TODO: create progress bar
- if (v_client != null)
- {
-
- jalview.bin.Cache.log
- .error("Implementation error - load session from a running session is not supported.");
- return false;
- }
-
- try
- {
- // copy the URL content to a temporary local file
- // TODO: be a bit cleverer here with nio (?!)
- File file = File.createTempFile("vdocfromurl", ".vdj");
- FileOutputStream fos = new FileOutputStream(file);
- BufferedInputStream bis = new BufferedInputStream(url.openStream());
- byte[] buffer = new byte[2048];
- int ln;
- while ((ln = bis.read(buffer)) > -1)
- {
- fos.write(buffer, 0, ln);
- }
- bis.close();
- fos.close();
- v_client = new jalview.gui.VamsasApplication(this, file,
- url.toExternalForm());
- } catch (Exception ex)
- {
- jalview.bin.Cache.log.error(
- "Failed to create new vamsas session from contents of URL "
- + url, ex);
- return false;
- }
- setupVamsasConnectedGui();
- v_client.initial_update(); // TODO: thread ?
- return v_client.inSession();
- }
-
- /**
- * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
- *
- * @param file
- * @return true if import was a success and a session was started.
- */
- public boolean vamsasImport(File file)
- {
- if (v_client != null)
- {
-
- jalview.bin.Cache.log
- .error("Implementation error - load session from a running session is not supported.");
- return false;
- }
-
- setProgressBar(MessageManager.formatMessage(
- "status.importing_vamsas_session_from",
- new Object[] { file.getName() }), file.hashCode());
- try
- {
- v_client = new jalview.gui.VamsasApplication(this, file, null);
- } catch (Exception ex)
- {
- setProgressBar(MessageManager.formatMessage(
- "status.importing_vamsas_session_from",
- new Object[] { file.getName() }), file.hashCode());
- jalview.bin.Cache.log.error(
- "New vamsas session from existing session file failed:", ex);
- return false;
- }
- setupVamsasConnectedGui();
- v_client.initial_update(); // TODO: thread ?
- setProgressBar(MessageManager.formatMessage(
- "status.importing_vamsas_session_from",
- new Object[] { file.getName() }), file.hashCode());
- return v_client.inSession();
- }
-
- public boolean joinVamsasSession(String mysesid)
- {
- if (v_client != null)
- {
- throw new Error(
- MessageManager
- .getString("error.try_join_vamsas_session_another"));
- }
- if (mysesid == null)
- {
- throw new Error(
- MessageManager.getString("error.invalid_vamsas_session_id"));
- }
- v_client = new VamsasApplication(this, mysesid);
- setupVamsasConnectedGui();
- v_client.initial_update();
- return (v_client.inSession());
- }
-
- @Override
- public void vamsasStart_actionPerformed(ActionEvent e)
- {
- if (v_client == null)
- {
- // Start a session.
- // we just start a default session for moment.
- /*
- * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
- * getProperty("LAST_DIRECTORY"));
- *
- * chooser.setFileView(new JalviewFileView());
- * chooser.setDialogTitle("Load Vamsas file");
- * chooser.setToolTipText("Import");
- *
- * int value = chooser.showOpenDialog(this);
- *
- * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
- * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
- */
- v_client = new VamsasApplication(this);
- setupVamsasConnectedGui();
- v_client.initial_update(); // TODO: thread ?
- }
- else
- {
- // store current data in session.
- v_client.push_update(); // TODO: thread
- }
- }
-
- protected void setupVamsasConnectedGui()
- {
- vamsasStart.setText(MessageManager.getString("label.session_update"));
- vamsasSave.setVisible(true);
- vamsasStop.setVisible(true);
- vamsasImport.setVisible(false); // Document import to existing session is
- // not possible for vamsas-client-1.0.
- }
-
- protected void setupVamsasDisconnectedGui()
- {
- vamsasSave.setVisible(false);
- vamsasStop.setVisible(false);
- vamsasImport.setVisible(true);
- vamsasStart.setText(MessageManager
- .getString("label.new_vamsas_session"));
- }
-
- @Override
- public void vamsasStop_actionPerformed(ActionEvent e)
- {
- if (v_client != null)
- {
- v_client.end_session();
- v_client = null;
- setupVamsasDisconnectedGui();
- }
- }
-
- protected void buildVamsasStMenu()
- {
- if (v_client == null)
- {
- String[] sess = null;
- try
- {
- sess = VamsasApplication.getSessionList();
- } catch (Exception e)
- {
- jalview.bin.Cache.log.warn(
- "Problem getting current sessions list.", e);
- sess = null;
- }
- if (sess != null)