+ FontMetrics fm = g.getFontMetrics();
+ if (fm != null)
+ {
+ g.drawString(
+ "Total Free Memory: " + df.format(totalFreeMemory)
+ + "MB; Max Memory: " + df.format(maxMemory)
+ + "MB; " + df.format(percentUsage) + "%", 10,
+ getHeight() - fm.getHeight());
+ }
+ }
+ }
+
+ }
+
+ /**
+ * fixes stacking order after a modal dialog to ensure windows that should be on top actually are
+ */
+ public void relayerWindows()
+ {
+ if (jvnews!=null && jvnews.isVisible())
+ {
+ jvnews.toFront();
+ }
+ }
+
+ protected JMenuItem groovyShell;
+
+ public void doGroovyCheck()
+ {
+ if (jalview.bin.Cache.groovyJarsPresent())
+ {
+ groovyShell = new JMenuItem();
+ groovyShell.setText("Groovy Console...");
+ groovyShell.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ groovyShell_actionPerformed(e);
+ }
+ });
+ toolsMenu.add(groovyShell);
+ groovyShell.setVisible(true);
+ }
+ }
+
+ /**
+ * Accessor method to quickly get all the AlignmentFrames loaded.
+ */
+ public static AlignFrame[] getAlignframes()
+ {
+ JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+
+ if (frames == null)
+ {
+ return null;
+ }
+ Vector avp = new Vector();
+ try
+ {
+ // REVERSE ORDER
+ for (int i = frames.length - 1; i > -1; i--)
+ {
+ if (frames[i] instanceof AlignFrame)
+ {
+ AlignFrame af = (AlignFrame) frames[i];
+ avp.addElement(af);
+ }
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ if (avp.size() == 0)
+ {
+ return null;
+ }
+ AlignFrame afs[] = new AlignFrame[avp.size()];
+ for (int i = 0, j = avp.size(); i < j; i++)
+ {
+ afs[i] = (AlignFrame) avp.elementAt(i);
+ }
+ avp.clear();
+ return afs;
+ }
+ public AppJmol[] getJmols()
+ {
+ JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+
+ if (frames == null)
+ {
+ return null;
+ }
+ Vector avp = new Vector();
+ try
+ {
+ // REVERSE ORDER
+ for (int i = frames.length - 1; i > -1; i--)
+ {
+ if (frames[i] instanceof AppJmol)
+ {
+ AppJmol af = (AppJmol) frames[i];
+ avp.addElement(af);
+ }
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ if (avp.size() == 0)
+ {
+ return null;
+ }
+ AppJmol afs[] = new AppJmol[avp.size()];
+ for (int i = 0, j = avp.size(); i < j; i++)
+ {
+ afs[i] = (AppJmol) avp.elementAt(i);
+ }
+ avp.clear();
+ return afs;
+ }
+
+ /**
+ * Add Groovy Support to Jalview
+ */
+ public void groovyShell_actionPerformed(ActionEvent e)
+ {
+ // use reflection to avoid creating compilation dependency.
+ if (!jalview.bin.Cache.groovyJarsPresent())
+ {
+ throw new Error(
+ "Implementation Error. Cannot create groovyShell without Groovy on the classpath!");
+ }
+ try
+ {
+ Class gcClass = Desktop.class.getClassLoader().loadClass(
+ "groovy.ui.Console");
+ Constructor gccons = gcClass.getConstructor(null);
+ java.lang.reflect.Method setvar = gcClass.getMethod("setVariable",
+ new Class[]
+ { String.class, Object.class });
+ java.lang.reflect.Method run = gcClass.getMethod("run", null);
+ Object gc = gccons.newInstance(null);
+ setvar.invoke(gc, new Object[]
+ { "Jalview", this });
+ run.invoke(gc, null);
+ } catch (Exception ex)
+ {
+ jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
+ JOptionPane
+ .showInternalMessageDialog(
+ Desktop.desktop,
+
+ "Couldn't create the groovy Shell. Check the error log for the details of what went wrong.",
+ "Jalview 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 progressPanel = progressBars
+ .remove(new Long(id));
+ if (progressBarHandlers.contains(new Long(id)))
+ {
+ progressBarHandlers.remove(new Long(id));
+ }
+ removeProgressPanel(progressPanel);
+ }
+ 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.contains(new Long(id)))
+ {
+ throw new Error(
+ "call setProgressBar before registering the progress bar's handler.");
+ }
+ progressBarHandlers.put(new Long(id), handler);
+ final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
+ if (handler.canCancel())
+ {
+ JButton cancel = new JButton("Cancel");
+ final IProgressIndicator us = this;
+ cancel.addActionListener(new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ handler.cancelActivity(id);
+ us.setProgressBar(
+ "Cancelled "
+ + ((JLabel) progressPanel.getComponent(0))
+ .getText(), id);
+ }
+ });
+ progressPanel.add(cancel, BorderLayout.EAST);
+ }
+ }