+ else if (frames[i] instanceof SplitFrame)
+ {
+ /*
+ * Also check for a split frame containing an AlignFrame
+ */
+ GSplitFrame sf = (GSplitFrame) frames[i];
+ if (sf.getTopFrame() instanceof AlignFrame)
+ {
+ avp.add((AlignFrame) sf.getTopFrame());
+ }
+ if (sf.getBottomFrame() instanceof AlignFrame)
+ {
+ avp.add((AlignFrame) sf.getBottomFrame());
+ }
+ }
+ }
+ if (avp.size() == 0)
+ {
+ return null;
+ }
+ AlignFrame afs[] = avp.toArray(new AlignFrame[avp.size()]);
+ return afs;
+ }
+
+ /**
+ * Returns an array of any AppJmol frames in the Desktop (or null if none).
+ *
+ * @return
+ */
+ public GStructureViewer[] getJmols()
+ {
+ JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+
+ if (frames == null)
+ {
+ return null;
+ }
+ List<GStructureViewer> avp = new ArrayList<GStructureViewer>();
+ // REVERSE ORDER
+ for (int i = frames.length - 1; i > -1; i--)
+ {
+ if (frames[i] instanceof AppJmol)
+ {
+ GStructureViewer af = (GStructureViewer) frames[i];
+ avp.add(af);
+ }
+ }
+ if (avp.size() == 0)
+ {
+ return null;
+ }
+ GStructureViewer afs[] = avp.toArray(new GStructureViewer[avp.size()]);
+ return afs;
+ }
+
+ /**
+ * Add Groovy Support to Jalview
+ */
+ public void groovyShell_actionPerformed()
+ {
+ // use reflection to avoid creating compilation dependency.
+ if (!jalview.bin.Cache.groovyJarsPresent())
+ {
+ throw new Error(
+ MessageManager
+ .getString("error.implementation_error_cannot_create_groovyshell"));
+ }
+ try
+ {
+ Class<?> gcClass = Desktop.class.getClassLoader().loadClass(
+ "groovy.ui.Console");
+ Constructor<?> gccons = gcClass.getConstructor();
+ java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
+ new Class[] { String.class, Object.class });
+ java.lang.reflect.Method run = gcClass.getMethod("run");
+ Object gc = gccons.newInstance();
+ setvar.invoke(gc, new Object[] { "Jalview", this });
+ run.invoke(gc);
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+
+ MessageManager.getString("label.couldnt_create_groovy_shell"),
+ MessageManager.getString("label.groovy_support_failed"),
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ /**
+ * Progress bars managed by the IProgressIndicator method.
+ */
+ private Hashtable<Long, JPanel> progressBars;
+
+ private Hashtable<Long, IProgressIndicatorHandler> progressBarHandlers;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
+ */
+ public void setProgressBar(String message, long id)
+ {
+ if (progressBars == null)
+ {
+ progressBars = new Hashtable<Long, JPanel>();
+ progressBarHandlers = new Hashtable<Long, IProgressIndicatorHandler>();
+ }
+
+ if (progressBars.get(new Long(id)) != null)
+ {
+ JPanel panel = progressBars.remove(new Long(id));
+ if (progressBarHandlers.contains(new Long(id)))
+ {
+ progressBarHandlers.remove(new Long(id));
+ }
+ removeProgressPanel(panel);
+ }
+ else
+ {
+ progressBars.put(new Long(id), addProgressPanel(message));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.gui.IProgressIndicator#registerHandler(long,
+ * jalview.gui.IProgressIndicatorHandler)
+ */
+ public void registerHandler(final long id,
+ final IProgressIndicatorHandler handler)
+ {
+ if (progressBarHandlers == null
+ || !progressBars.containsKey(new Long(id)))
+ {
+ throw new Error(
+ MessageManager
+ .getString("error.call_setprogressbar_before_registering_handler"));
+ }
+ progressBarHandlers.put(new Long(id), handler);
+ final JPanel progressPanel = progressBars.get(new Long(id));
+ if (handler.canCancel())
+ {
+ JButton cancel = new JButton(
+ MessageManager.getString("action.cancel"));
+ final IProgressIndicator us = this;
+ cancel.addActionListener(new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ handler.cancelActivity(id);
+ us.setProgressBar(MessageManager.formatMessage(
+ "label.cancelled_params",
+ new Object[] { ((JLabel) progressPanel.getComponent(0))
+ .getText() }), id);
+ }
+ });
+ progressPanel.add(cancel, BorderLayout.EAST);
+ }
+ }
+
+ /**
+ *
+ * @return true if any progress bars are still active
+ */
+ @Override
+ public boolean operationInProgress()
+ {
+ if (progressBars != null && progressBars.size() > 0)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * This will return the first AlignFrame holding the given viewport instance.
+ * It will break if there are more than one AlignFrames viewing a particular
+ * av.
+ *
+ * @param viewport
+ * @return alignFrame for viewport
+ */
+ public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
+ {
+ if (desktop != null)
+ {
+ AlignmentPanel[] aps = getAlignmentPanels(viewport.getSequenceSetId());
+ for (int panel = 0; aps != null && panel < aps.length; panel++)