X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=262a9becfa450a194e9a3f3a5684c917a23cfa45;hb=dbbd8851fe0e30aa9606657b5f4eb41e0db21563;hp=464ec5965f196dbaf6d40ba6a38ddb049d5315d0;hpb=90bd6677b1f44a0608dcccde1ff59632cc9a54a1;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 464ec59..262a9be 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1,264 +1,1417 @@ -/******************** - * 2004 Jalview Reengineered - * Barton Group - * Dundee University - * - * AM Waterhouse - *******************/ - - -package jalview.gui; - -import jalview.gui.*; -import jalview.io.*; -import jalview.datamodel.*; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; - - -public class Desktop extends jalview.jbgui.GDesktop -{ - public static JDesktopPane desktop; - static int openFrameCount = 0; - static final int xOffset = 30, yOffset = 30; - - public Desktop() - { - Image image =null; - try{ - java.net.URL url = getClass().getResource("/BartonGroupBanner.gif"); - if(url!=null) - { - image = java.awt.Toolkit.getDefaultToolkit().createImage(url); - MediaTracker mt = new MediaTracker(this); - mt.addImage(image, 0); - mt.waitForID(0); - setIconImage(image); - } - - }catch(Exception ex){} - - setTitle("Jalview 2005"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setVisible(true); - desktop = new JDesktopPane(); - setContentPane(desktop); - desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - int width = 1200, height = 800; - if(screenSize.getWidth()0); + + } + else + { + jalview.bin.Cache.log.debug("No current vamsas sessions."); + VamsasStMenu.removeAll(); + VamsasStMenu.setVisible(false); + } + } else { + // Not interested in the content. Just hide ourselves. + VamsasStMenu.setVisible(false); + } + } + public void vamsasSave_actionPerformed(ActionEvent e) + { + if (v_client != null) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty( + "LAST_DIRECTORY"), new String[] + {"vdj"}, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ + new String[] + {"Vamsas Document"}, "Vamsas Document"); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save Vamsas Document Archive"); + + int value = chooser.showSaveDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + java.io.File choice = chooser.getSelectedFile(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); + String warnmsg=null; + String warnttl=null; + try { + v_client.vclient.storeDocument(choice); + } + catch (Error ex) + { + warnttl = "Serious Problem saving Vamsas Document"; + warnmsg = ex.toString(); + jalview.bin.Cache.log.error("Error Whilst saving document to "+choice,ex); + + } + catch (Exception ex) + { + warnttl = "Problem saving Vamsas Document."; + warnmsg = ex.toString(); + jalview.bin.Cache.log.warn("Exception Whilst saving document to "+choice,ex); + + } + if (warnmsg!=null) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + + warnmsg, warnttl, + JOptionPane.ERROR_MESSAGE); + } + } + } + } + JProgressBar vamUpdate = null; + /** + * hide vamsas user gui bits when a vamsas document event is being handled. + * @param b true to hide gui, false to reveal gui + */ + public void setVamsasUpdate(boolean b) + { + jalview.bin.Cache.log.debug("Setting gui for Vamsas update " + + (b ? "in progress" : "finished")); + + if (vamUpdate!=null) + { + this.removeProgressPanel(vamUpdate); + } + if (b) + { + vamUpdate = this.addProgressPanel("Updating vamsas session"); + } + vamsasStart.setVisible(!b); + vamsasStop.setVisible(!b); + vamsasSave.setVisible(!b); + } + + public JInternalFrame[] getAllFrames() + { + return desktop.getAllFrames(); + } + + + /** + * Checks the given url to see if it gives a response indicating that + * the user should be informed of a new questionnaire. + * @param url + */ + public void checkForQuestionnaire(String url) + { + UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url); + //javax.swing.SwingUtilities.invokeLater(jvq); + new Thread(jvq).start(); + } + /** + * Proxy class for JDesktopPane which optionally + * displays the current memory usage and highlights + * the desktop area with a red bar if free memory runs low. + * @author AMW + */ + public class MyDesktopPane extends JDesktopPane implements Runnable + { + + boolean showMemoryUsage = false; + Runtime runtime; + java.text.NumberFormat df; + + float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage; + + public MyDesktopPane(boolean showMemoryUsage) + { + showMemoryUsage(showMemoryUsage); + } + + public void showMemoryUsage(boolean showMemoryUsage) + { + this.showMemoryUsage = showMemoryUsage; + if (showMemoryUsage) + { + Thread worker = new Thread(this); + worker.start(); + } + } + public boolean isShowMemoryUsage() + { + return showMemoryUsage; + } + public void run() + { + df = java.text.NumberFormat.getNumberInstance(); + df.setMaximumFractionDigits(2); + runtime = Runtime.getRuntime(); + + while (showMemoryUsage) + { + try + { + Thread.sleep(3000); + maxMemory = runtime.maxMemory() / 1048576f; + allocatedMemory = runtime.totalMemory() / 1048576f; + freeMemory = runtime.freeMemory() / 1048576f; + totalFreeMemory = freeMemory + (maxMemory - allocatedMemory); + + percentUsage = (totalFreeMemory / maxMemory) * 100; + + // if (percentUsage < 20) + { + // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red); + // instance.set.setBorder(border1); + } + repaint(); + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + + public void paintComponent(Graphics g) + { + if(showMemoryUsage) + { + if (percentUsage < 20) + g.setColor(Color.red); + + g.drawString("Total Free Memory: " + df.format(totalFreeMemory) + + "MB; Max Memory: " + df.format(maxMemory) + + "MB; " + df.format(percentUsage) + "%", 10, + getHeight() - g.getFontMetrics().getHeight()); + } + } + + + + } + 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