From c2404cecc845332c659d1a42bda51576235ba92b Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 5 Apr 2007 11:22:35 +0000 Subject: [PATCH] Paste menu item dispalyed on right click. Memory settings visible in this version --- src/jalview/gui/Desktop.java | 148 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 3 deletions(-) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 26b28e7..fd741be 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -39,7 +39,13 @@ public class Desktop { /** DOCUMENT ME!! */ public static Desktop instance; - public static JDesktopPane desktop; + + //Need to decide if the Memory Usage is to be included in + //Next release or not. + public static MyDesktopPane desktop; + // public static JDesktopPane desktop; + + static int openFrameCount = 0; static final int xOffset = 30; static final int yOffset = 30; @@ -59,6 +65,7 @@ public class Desktop doVamsasClientCheck(); Image image = null; + try { java.net.URL url = getClass().getResource("/images/logo.gif"); @@ -79,7 +86,9 @@ public class Desktop setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - desktop = new JDesktopPane(); + + desktop = new MyDesktopPane(true); + // desktop = new JDesktopPane(); desktop.setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); getContentPane().add(desktop, BorderLayout.CENTER); @@ -114,6 +123,18 @@ public class Desktop } }); + this.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if(SwingUtilities.isRightMouseButton(evt)) + { + showPasteMenu(evt.getX(), evt.getY()); + } + } + }); + + this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); /////////Add a splashscreen on startup @@ -138,7 +159,48 @@ public class Desktop VamsasMenu.setVisible(true); vamsasLoad.setVisible(true); } + } + + void showPasteMenu(int x, int y) + { + JPopupMenu popup = new JPopupMenu(); + JMenuItem item = new JMenuItem("Paste To New Window"); + item.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + paste(); + } + }); + popup.add(item); + popup.show(this, x, y); + } + + public void paste() + { + try + { + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents = c.getContents(this); + + if (contents != null) + { + String file = (String) contents + .getTransferData(DataFlavor.stringFlavor); + + String format = new IdentifyFile().Identify(file, + FormatAdapter.PASTE); + + new FileLoader().LoadFile(file, FormatAdapter.PASTE, format); + + } + } + catch (Exception ex) + { + System.out.println("Unable to paste alignment from system clipboard:\n" + + ex); + } } /** @@ -223,6 +285,7 @@ public class Desktop { itf.requestFocus(); } + System.gc(); } ; }); @@ -584,6 +647,8 @@ public class Desktop catch (java.beans.PropertyVetoException ex) {} } + System.out.println("ALL CLOSED"); + } public void raiseRelated_actionPerformed(ActionEvent e) @@ -951,6 +1016,12 @@ public class Desktop } + 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. @@ -962,4 +1033,75 @@ public class Desktop javax.swing.SwingUtilities.invokeLater(jvq); } -} + 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 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()); + } + } + } + + } -- 1.7.10.2