2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 import java.awt.datatransfer.*;
24 import java.awt.dnd.*;
25 import java.awt.event.*;
37 extends jalview.jbgui.GDesktop implements DropTargetListener,
41 public static Desktop instance;
43 //Need to decide if the Memory Usage is to be included in
44 //Next release or not.
45 // public static MyDesktopPane desktop;
46 public static JDesktopPane desktop;
49 static int openFrameCount = 0;
50 static final int xOffset = 30;
51 static final int yOffset = 30;
52 public static jalview.ws.Discoverer discoverer;
54 public static Object[] jalviewClipboard;
55 public static boolean internalCopy = false;
57 static int fileLoadingCount = 0;
60 * Creates a new Desktop object.
65 doVamsasClientCheck();
71 java.net.URL url = getClass().getResource("/images/logo.gif");
75 image = java.awt.Toolkit.getDefaultToolkit().createImage(url);
77 MediaTracker mt = new MediaTracker(this);
78 mt.addImage(image, 0);
87 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
88 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
90 // desktop = new MyDesktopPane(true);
91 desktop = new JDesktopPane();
92 desktop.setBackground(Color.white);
93 getContentPane().setLayout(new BorderLayout());
94 getContentPane().add(desktop, BorderLayout.CENTER);
95 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
97 // This line prevents Windows Look&Feel resizing all new windows to maximum
98 // if previous window was maximised
99 desktop.setDesktopManager(new DefaultDesktopManager());
101 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
102 String x = jalview.bin.Cache.getProperty("SCREEN_X");
103 String y = jalview.bin.Cache.getProperty("SCREEN_Y");
104 String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH");
105 String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT");
107 if ( (x != null) && (y != null) && (width != null) && (height != null))
109 setBounds(Integer.parseInt(x), Integer.parseInt(y),
110 Integer.parseInt(width), Integer.parseInt(height));
114 setBounds( (int) (screenSize.width - 900) / 2,
115 (int) (screenSize.height - 650) / 2, 900, 650);
118 this.addWindowListener(new WindowAdapter()
120 public void windowClosing(WindowEvent evt)
126 this.addMouseListener(new MouseAdapter()
128 public void mousePressed(MouseEvent evt)
130 if(SwingUtilities.isRightMouseButton(evt))
132 showPasteMenu(evt.getX(), evt.getY());
138 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
140 /////////Add a splashscreen on startup
141 /////////Add a splashscreen on startup
142 JInternalFrame frame = new JInternalFrame();
144 SplashScreen splash = new SplashScreen(frame, image);
145 frame.setContentPane(splash);
146 frame.setLayer(JLayeredPane.PALETTE_LAYER);
147 frame.setLocation( (int) ( (getWidth() - 750) / 2),
148 (int) ( (getHeight() - 160) / 2));
150 addInternalFrame(frame, "", 750, 160, false);
152 discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is displayed.
155 private void doVamsasClientCheck()
157 if (jalview.bin.Cache.vamsasJarsPresent())
159 VamsasMenu.setVisible(true);
160 vamsasLoad.setVisible(true);
164 void showPasteMenu(int x, int y)
166 JPopupMenu popup = new JPopupMenu();
167 JMenuItem item = new JMenuItem("Paste To New Window");
168 item.addActionListener(new ActionListener()
170 public void actionPerformed(ActionEvent evt)
177 popup.show(this, x, y);
184 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
185 Transferable contents = c.getContents(this);
187 if (contents != null)
189 String file = (String) contents
190 .getTransferData(DataFlavor.stringFlavor);
192 String format = new IdentifyFile().Identify(file,
193 FormatAdapter.PASTE);
195 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
201 System.out.println("Unable to paste alignment from system clipboard:\n"
209 * @param frame DOCUMENT ME!
210 * @param title DOCUMENT ME!
211 * @param w DOCUMENT ME!
212 * @param h DOCUMENT ME!
214 public static synchronized void addInternalFrame(final JInternalFrame frame,
215 String title, int w, int h)
217 addInternalFrame(frame, title, w, h, true);
223 * @param frame DOCUMENT ME!
224 * @param title DOCUMENT ME!
225 * @param w DOCUMENT ME!
226 * @param h DOCUMENT ME!
227 * @param resizable DOCUMENT ME!
229 public static synchronized void addInternalFrame(final JInternalFrame frame,
230 String title, int w, int h, boolean resizable)
233 frame.setTitle(title);
234 if (frame.getWidth() < 1 || frame.getHeight() < 1)
238 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
239 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
240 // IF JALVIEW IS RUNNING HEADLESS
241 /////////////////////////////////////////////////
242 if (System.getProperty("java.awt.headless") != null
243 && System.getProperty("java.awt.headless").equals("true"))
250 frame.setVisible(true);
251 frame.setClosable(true);
252 frame.setResizable(resizable);
253 frame.setMaximizable(resizable);
254 frame.setIconifiable(resizable);
255 frame.setFrameIcon(null);
257 if (frame.getX() < 1 && frame.getY() < 1)
259 frame.setLocation(xOffset * openFrameCount,
260 yOffset * ( (openFrameCount - 1) % 10) + yOffset);
263 final JMenuItem menuItem = new JMenuItem(title);
264 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
266 public void internalFrameActivated(javax.swing.event.
267 InternalFrameEvent evt)
269 JInternalFrame itf = desktop.getSelectedFrame();
277 public void internalFrameClosed(
278 javax.swing.event.InternalFrameEvent evt)
280 PaintRefresher.RemoveComponent(frame);
282 windowMenu.remove(menuItem);
283 JInternalFrame itf = desktop.getSelectedFrame();
293 menuItem.addActionListener(new ActionListener()
295 public void actionPerformed(ActionEvent e)
299 frame.setSelected(true);
300 frame.setIcon(false);
302 catch (java.beans.PropertyVetoException ex)
309 windowMenu.add(menuItem);
315 frame.setSelected(true);
316 frame.requestFocus();
318 catch (java.beans.PropertyVetoException ve)
322 public void lostOwnership(Clipboard clipboard, Transferable contents)
326 Desktop.jalviewClipboard = null;
329 internalCopy = false;
332 public void dragEnter(DropTargetDragEvent evt)
335 public void dragExit(DropTargetEvent evt)
338 public void dragOver(DropTargetDragEvent evt)
341 public void dropActionChanged(DropTargetDragEvent evt)
347 * @param evt DOCUMENT ME!
349 public void drop(DropTargetDropEvent evt)
351 Transferable t = evt.getTransferable();
352 java.util.List files = null;
356 DataFlavor uriListFlavor = new DataFlavor(
357 "text/uri-list;class=java.lang.String");
358 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
360 //Works on Windows and MacOSX
361 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
362 files = (java.util.List) t.getTransferData(DataFlavor.
365 else if (t.isDataFlavorSupported(uriListFlavor))
367 // This is used by Unix drag system
368 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
369 String data = (String) t.getTransferData(uriListFlavor);
370 files = new java.util.ArrayList(1);
371 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
374 st.hasMoreTokens(); )
376 String s = st.nextToken();
377 if (s.startsWith("#"))
379 // the line is a comment (as per the RFC 2483)
383 java.net.URI uri = new java.net.URI(s);
384 java.io.File file = new java.io.File(uri);
396 for (int i = 0; i < files.size(); i++)
398 String file = files.get(i).toString();
399 String protocol = FormatAdapter.FILE;
400 String format = null;
402 if (file.endsWith(".jar"))
409 format = new IdentifyFile().Identify(file,
413 new FileLoader().LoadFile(file, protocol, format);
425 * @param e DOCUMENT ME!
427 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
429 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
434 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
439 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
440 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
442 chooser.setFileView(new JalviewFileView());
443 chooser.setDialogTitle("Open local file");
444 chooser.setToolTipText("Open");
446 int value = chooser.showOpenDialog(this);
448 if (value == JalviewFileChooser.APPROVE_OPTION)
450 String choice = chooser.getSelectedFile().getPath();
451 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
452 chooser.getSelectedFile().getParent());
454 String format = null;
455 if (chooser.getSelectedFormat().equals("Jalview"))
461 format = new IdentifyFile().Identify(choice, FormatAdapter.FILE);
464 if (viewport != null)
466 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format);
470 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
478 * @param e DOCUMENT ME!
480 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
482 // This construct allows us to have a wider textfield
484 JLabel label = new JLabel("Enter URL of Input File");
485 final JComboBox history = new JComboBox();
487 JPanel panel = new JPanel(new GridLayout(2, 1));
490 history.setPreferredSize(new Dimension(400, 20));
491 history.setEditable(true);
492 history.addItem("http://www.");
494 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
498 if (historyItems != null)
500 st = new StringTokenizer(historyItems, "\t");
502 while (st.hasMoreTokens())
504 history.addItem(st.nextElement());
508 int reply = JOptionPane.showInternalConfirmDialog(desktop,
509 panel, "Input Alignment From URL",
510 JOptionPane.OK_CANCEL_OPTION);
512 if (reply != JOptionPane.OK_OPTION)
517 String url = history.getSelectedItem().toString();
519 if (url.toLowerCase().endsWith(".jar"))
521 if (viewport != null)
523 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, "Jalview");
527 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
532 String format = new IdentifyFile().Identify(url, FormatAdapter.URL);
534 if (format.equals("URL NOT FOUND"))
536 JOptionPane.showInternalMessageDialog(Desktop.desktop,
537 "Couldn't locate " + url,
539 JOptionPane.WARNING_MESSAGE);
544 if (viewport != null)
546 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
550 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
558 * @param e DOCUMENT ME!
560 public void inputTextboxMenuItem_actionPerformed(AlignViewport viewport)
562 CutAndPasteTransfer cap = new CutAndPasteTransfer();
563 cap.setForInput(viewport);
564 Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500);
572 jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + "");
573 jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + "");
574 jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + "");
575 jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + "");
582 * @param e DOCUMENT ME!
584 public void aboutMenuItem_actionPerformed(ActionEvent e)
586 StringBuffer message = new StringBuffer("JalView version " +
587 jalview.bin.Cache.getProperty(
591 Cache.getDefault("BUILD_DATE",
594 if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals(
595 jalview.bin.Cache.getProperty("VERSION")))
597 message.append("\n\n!! Jalview version "
598 + jalview.bin.Cache.getProperty("LATEST_VERSION")
600 " is available for download from http://www.jalview.org !!\n");
604 message.append("\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." +
605 "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." +
606 "\nFor all issues relating to Jalview, email help@jalview.org" +
607 "\n\nIf you use JalView, please cite:" +
608 "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" +
609 "\nBioinformatics, 2004 20;426-7.");
611 JOptionPane.showInternalMessageDialog(Desktop.desktop,
613 message.toString(), "About Jalview",
614 JOptionPane.INFORMATION_MESSAGE);
620 * @param e DOCUMENT ME!
622 public void documentationMenuItem_actionPerformed(ActionEvent e)
626 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
627 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
628 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
630 javax.help.HelpBroker hb = hs.createHelpBroker();
631 hb.setCurrentID("home");
632 hb.setDisplayed(true);
638 public void closeAll_actionPerformed(ActionEvent e)
640 JInternalFrame[] frames = desktop.getAllFrames();
641 for (int i = 0; i < frames.length; i++)
645 frames[i].setClosed(true);
647 catch (java.beans.PropertyVetoException ex)
650 System.out.println("ALL CLOSED");
654 public void raiseRelated_actionPerformed(ActionEvent e)
656 reorderAssociatedWindows(false, false);
659 public void minimizeAssociated_actionPerformed(ActionEvent e)
661 reorderAssociatedWindows(true, false);
664 void closeAssociatedWindows()
666 reorderAssociatedWindows(false, true);
669 void reorderAssociatedWindows(boolean minimize, boolean close)
671 JInternalFrame[] frames = desktop.getAllFrames();
672 if (frames == null || frames.length < 1)
677 AlignViewport source = null, target = null;
678 if (frames[0] instanceof AlignFrame)
680 source = ( (AlignFrame) frames[0]).getCurrentView();
682 else if (frames[0] instanceof TreePanel)
684 source = ( (TreePanel) frames[0]).getViewPort();
686 else if (frames[0] instanceof PCAPanel)
688 source = ( (PCAPanel) frames[0]).av;
690 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
692 source = ( (PairwiseAlignPanel) frames[0].getContentPane()).av;
697 for (int i = 0; i < frames.length; i++)
700 if (frames[i] == null)
704 if (frames[i] instanceof AlignFrame)
706 target = ( (AlignFrame) frames[i]).getCurrentView();
708 else if (frames[i] instanceof TreePanel)
710 target = ( (TreePanel) frames[i]).getViewPort();
712 else if (frames[i] instanceof PCAPanel)
714 target = ( (PCAPanel) frames[i]).av;
716 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
718 target = ( (PairwiseAlignPanel) frames[i].getContentPane()).av;
721 if (source == target)
727 frames[i].setClosed(true);
731 frames[i].setIcon(minimize);
739 catch (java.beans.PropertyVetoException ex)
749 * @param e DOCUMENT ME!
751 protected void preferences_actionPerformed(ActionEvent e)
759 * @param e DOCUMENT ME!
761 public void saveState_actionPerformed(ActionEvent e)
763 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
765 "LAST_DIRECTORY"), new String[]
768 {"Jalview Project"}, "Jalview Project");
770 chooser.setFileView(new JalviewFileView());
771 chooser.setDialogTitle("Save State");
773 int value = chooser.showSaveDialog(this);
775 if (value == JalviewFileChooser.APPROVE_OPTION)
777 java.io.File choice = chooser.getSelectedFile();
778 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
779 new Jalview2XML().SaveState(choice);
786 * @param e DOCUMENT ME!
788 public void loadState_actionPerformed(ActionEvent e)
790 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
792 "LAST_DIRECTORY"), new String[]
795 {"Jalview Project"}, "Jalview Project");
796 chooser.setFileView(new JalviewFileView());
797 chooser.setDialogTitle("Restore state");
799 int value = chooser.showOpenDialog(this);
801 if (value == JalviewFileChooser.APPROVE_OPTION)
803 String choice = chooser.getSelectedFile().getAbsolutePath();
804 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
805 chooser.getSelectedFile().getParent());
806 new Jalview2XML().LoadJalviewAlign(choice);
810 /* public void vamsasLoad_actionPerformed(ActionEvent e)
812 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
813 getProperty("LAST_DIRECTORY"));
815 chooser.setFileView(new JalviewFileView());
816 chooser.setDialogTitle("Load Vamsas file");
817 chooser.setToolTipText("Import");
819 int value = chooser.showOpenDialog(this);
821 if (value == JalviewFileChooser.APPROVE_OPTION)
823 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null);
825 chooser.getSelectedFile().getAbsolutePath()
832 public void inputSequence_actionPerformed(ActionEvent e)
834 new SequenceFetcher(null);
837 JPanel progressPanel;
839 public void startLoading(final String fileName)
841 if (fileLoadingCount == 0)
843 progressPanel = new JPanel(new BorderLayout());
844 JProgressBar progressBar = new JProgressBar();
845 progressBar.setIndeterminate(true);
847 progressPanel.add(new JLabel("Loading File: " + fileName + " "),
850 progressPanel.add(progressBar, BorderLayout.CENTER);
852 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
858 public void stopLoading()
861 if (fileLoadingCount < 1)
863 if (progressPanel != null)
865 this.getContentPane().remove(progressPanel);
866 progressPanel = null;
868 fileLoadingCount = 0;
873 public static int getViewCount(String viewId)
876 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
877 for (int t = 0; t < frames.length; t++)
879 if (frames[t] instanceof AlignFrame)
881 AlignFrame af = (AlignFrame) frames[t];
882 for (int a = 0; a < af.alignPanels.size(); a++)
885 ( (AlignmentPanel) af.alignPanels.elementAt(a)).av.
898 public void explodeViews(AlignFrame af)
900 int size = af.alignPanels.size();
906 for (int i = 0; i < size; i++)
908 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(i);
909 AlignFrame newaf = new AlignFrame(ap);
910 if (ap.av.explodedPosition != null &&
911 !ap.av.explodedPosition.equals(af.getBounds()))
913 newaf.setBounds(ap.av.explodedPosition);
916 ap.av.gatherViewsHere = false;
918 addInternalFrame(newaf, af.getTitle(),
919 AlignFrame.DEFAULT_WIDTH,
920 AlignFrame.DEFAULT_HEIGHT);
923 af.alignPanels.clear();
924 af.closeMenuItem_actionPerformed(true);
928 public void gatherViews(AlignFrame source)
930 source.viewport.gatherViewsHere = true;
931 source.viewport.explodedPosition = source.getBounds();
932 JInternalFrame[] frames = desktop.getAllFrames();
933 String viewId = source.viewport.sequenceSetID;
935 for (int t = 0; t < frames.length; t++)
937 if (frames[t] instanceof AlignFrame && frames[t] != source)
939 AlignFrame af = (AlignFrame) frames[t];
940 boolean gatherThis = false;
941 for (int a = 0; a < af.alignPanels.size(); a++)
943 AlignmentPanel ap = (AlignmentPanel) af.alignPanels.elementAt(a);
944 if (viewId.equals(ap.av.getSequenceSetId()))
947 ap.av.gatherViewsHere = false;
948 ap.av.explodedPosition = af.getBounds();
949 source.addAlignmentPanel(ap, false);
955 af.alignPanels.clear();
956 af.closeMenuItem_actionPerformed(true);
963 jalview.gui.VamsasClient v_client = null;
964 public void vamsasLoad_actionPerformed(ActionEvent e)
966 if (v_client == null)
969 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
970 getProperty("LAST_DIRECTORY"));
972 chooser.setFileView(new JalviewFileView());
973 chooser.setDialogTitle("Load Vamsas file");
974 chooser.setToolTipText("Import");
976 int value = chooser.showOpenDialog(this);
978 if (value == JalviewFileChooser.APPROVE_OPTION)
980 v_client = new jalview.gui.VamsasClient(this,
981 chooser.getSelectedFile());
982 this.vamsasLoad.setText("Session Update");
983 this.vamsasStop.setVisible(true);
984 v_client.initial_update();
985 v_client.startWatcher();
990 // store current data in session.
991 v_client.push_update();
995 public void vamsasStop_actionPerformed(ActionEvent e)
997 if (v_client != null)
999 v_client.end_session();
1001 this.vamsasStop.setVisible(false);
1002 this.vamsasLoad.setText("Start Vamsas Session...");
1007 * hide vamsas user gui bits when a vamsas document event is being handled.
1008 * @param b true to hide gui, false to reveal gui
1010 public void setVamsasUpdate(boolean b)
1012 jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
1013 (b ? "in progress" : "finished"));
1014 vamsasLoad.setVisible(!b);
1015 vamsasStop.setVisible(!b);
1019 public JInternalFrame[] getAllFrames()
1021 return desktop.getAllFrames();
1026 * Checks the given url to see if it gives a response indicating that
1027 * the user should be informed of a new questionnaire.
1030 public void checkForQuestionnaire(String url)
1032 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
1033 javax.swing.SwingUtilities.invokeLater(jvq);
1037 class MyDesktopPane extends JDesktopPane implements Runnable
1039 boolean showMemoryUsage = false;
1041 java.text.NumberFormat df;
1043 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory, percentUsage;
1045 public MyDesktopPane(boolean showMemoryUsage)
1047 showMemoryUsage(showMemoryUsage);
1050 public void showMemoryUsage(boolean showMemoryUsage)
1052 this.showMemoryUsage = showMemoryUsage;
1053 if (showMemoryUsage)
1055 Thread worker = new Thread(this);
1062 df = java.text.NumberFormat.getNumberInstance();
1063 df.setMaximumFractionDigits(2);
1064 runtime = Runtime.getRuntime();
1066 while (showMemoryUsage)
1071 maxMemory = runtime.maxMemory() / 1048576f;
1072 allocatedMemory = runtime.totalMemory() / 1048576f;
1073 freeMemory = runtime.freeMemory() / 1048576f;
1074 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
1076 percentUsage = (totalFreeMemory / maxMemory) * 100;
1078 // if (percentUsage < 20)
1080 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12, Color.red);
1081 // instance.set.setBorder(border1);
1086 catch (Exception ex)
1088 ex.printStackTrace();
1093 public void paintComponent(Graphics g)
1097 if (percentUsage < 20)
1098 g.setColor(Color.red);
1100 g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
1101 + "MB; Max Memory: " + df.format(maxMemory)
1102 + "MB; " + df.format(percentUsage) + "%", 10,
1103 getHeight() - g.getFontMetrics().getHeight());