r210 - trunk/msm-monitoring-plugins/src/main/java/org/nuiton/monitoring
Author: dlanglais Date: 2010-03-11 02:13:57 +0100 (Thu, 11 Mar 2010) New Revision: 210 Log: modification : - Arrondi des espaces m?\195?\169moires en Go (2 chiffres apr?\195?\168s la virgule). - Suppression magic numbers. Correction : - la fermeture de la fen?\195?\170tre du plugin fermait l'application enti?\195?\168re.. Modified: trunk/msm-monitoring-plugins/src/main/java/org/nuiton/monitoring/ShowDiskSpace.java Modified: trunk/msm-monitoring-plugins/src/main/java/org/nuiton/monitoring/ShowDiskSpace.java =================================================================== --- trunk/msm-monitoring-plugins/src/main/java/org/nuiton/monitoring/ShowDiskSpace.java 2010-03-10 22:50:08 UTC (rev 209) +++ trunk/msm-monitoring-plugins/src/main/java/org/nuiton/monitoring/ShowDiskSpace.java 2010-03-11 01:13:57 UTC (rev 210) @@ -2,6 +2,7 @@ import java.awt.GridLayout; import java.io.File; +import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @@ -17,64 +18,94 @@ * Number for division byte -> Mb -> Gb. */ private static final int DIV = 1024; - /** + * Width of the frame. + */ + private static final int FRAME_WIDTH = 300; + /** + * Height of the frame. + */ + private static final int FRAME_HEIGHT = 300; + + /** * Constructor. */ - public ShowDiskSpace(){ + public ShowDiskSpace() { } - + /** * Display. */ @Override - public void display(){ - this.setTitle("Plugin ShowDiskSpace"); - this.setSize(300, 300); - this.setLocationRelativeTo(null); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + public void display() { - JPanel content = new JPanel(); - File f = new File(new File("").getAbsolutePath()).getParentFile(); - if (f.exists()) { - long freeSpaceByte = f.getFreeSpace(); - long totalSpaceByte = f.getTotalSpace(); - long usableSpaceByte = f.getUsableSpace(); - double freeSpaceMb = freeSpaceByte / (DIV * DIV); - double totalSpaceMb = totalSpaceByte / (DIV * DIV); - double usableSpaceMb = usableSpaceByte / (DIV * DIV); - double freeSpaceGb = freeSpaceMb / DIV; - double totalSpaceGb = totalSpaceMb / DIV; - double usableSpaceGb = usableSpaceMb / DIV; - content.setLayout(new GridLayout(7,1)); + this.setTitle("Plugin ShowDiskSpace"); + this.setSize(FRAME_WIDTH, FRAME_HEIGHT); + this.setLocationRelativeTo(null); +// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // exit MSM... + + JPanel content = new JPanel(); + File f = new File(new File("").getAbsolutePath()).getParentFile(); + if (f.exists()) { + + final long freeSpaceByte = f.getFreeSpace(); + final long totalSpaceByte = f.getTotalSpace(); + final long usableSpaceByte = f.getUsableSpace(); + + final double freeSpaceMb = freeSpaceByte / (DIV * DIV); + final double totalSpaceMb = totalSpaceByte / (DIV * DIV); + final double usableSpaceMb = usableSpaceByte / (DIV * DIV); + + final double freeSpaceGb = freeSpaceMb / DIV; + final double totalSpaceGb = totalSpaceMb / DIV; + final double usableSpaceGb = usableSpaceMb / DIV; + + final int rows = 7, cols = 1; + content.setLayout(new GridLayout(rows, cols)); + content.add(new JLabel( - "freeSpace : " + freeSpaceMb + " Mb (" + freeSpaceGb + " Gb)")); + "freeSpace : " + freeSpaceMb + " Mb (" + + new DecimalFormat("0.00").format(freeSpaceGb) + " Gb)")); content.add(new JLabel( - "totalSpace : " + totalSpaceMb + " Mb (" + totalSpaceGb + " Gb)")); + "totalSpace : " + totalSpaceMb + " Mb (" + + new DecimalFormat("0.00").format(totalSpaceGb) + " Gb)")); content.add(new JLabel( - "usableSpace : " + usableSpaceMb + " Mb (" + usableSpaceGb + " Gb)")); + "usableSpace : " + usableSpaceMb + " Mb (" + + new DecimalFormat("0.00").format(usableSpaceGb) + " Gb)")); content.add(new JLabel("")); - } - Runtime runtime = Runtime.getRuntime(); - long freeMemoryByte = runtime.freeMemory(); - long totalMemoryByte = runtime.totalMemory(); - long maxMemoryByte = runtime.maxMemory(); - double freeMemoryMb = freeMemoryByte/(DIV*DIV); - double totalMemoryMb = totalMemoryByte/(DIV*DIV); - double maxMemoryMb = maxMemoryByte/(DIV*DIV); - double freeMemoryGb = freeMemoryMb/DIV; - double totalMemoryGb = totalMemoryMb/DIV; - double maxMemoryGb = maxMemoryMb/DIV; - content.add(new JLabel( - "freeMemory : " + freeMemoryMb + " Mb (" + freeMemoryGb + " Gb)")); - content.add(new JLabel( - "totalMemory : " + totalMemoryMb + " Mb (" + totalMemoryGb + " Gb)")); - content.add(new JLabel( - "maxMemory : " + maxMemoryMb + " Mb (" + maxMemoryGb + " Gb)")); - this.setContentPane(content); - this.pack(); - this.setVisible(true); + } else { + final int rows = 3, cols = 1; + content.setLayout(new GridLayout(rows, cols)); + } + + Runtime runtime = Runtime.getRuntime(); + + final long freeMemoryByte = runtime.freeMemory(); + final long totalMemoryByte = runtime.totalMemory(); + final long maxMemoryByte = runtime.maxMemory(); + + final double freeMemoryMb = freeMemoryByte / (DIV * DIV); + final double totalMemoryMb = totalMemoryByte / (DIV * DIV); + final double maxMemoryMb = maxMemoryByte / (DIV * DIV); + + final double freeMemoryGb = freeMemoryMb / DIV; + final double totalMemoryGb = totalMemoryMb / DIV; + final double maxMemoryGb = maxMemoryMb / DIV; + + content.add(new JLabel( + "freeMemory : " + freeMemoryMb + " Mb (" + + new DecimalFormat("0.00").format(freeMemoryGb) + " Gb)")); + content.add(new JLabel( + "totalMemory : " + totalMemoryMb + " Mb (" + + new DecimalFormat("0.00").format(totalMemoryGb) + " Gb)")); + content.add(new JLabel( + "maxMemory : " + maxMemoryMb + " Mb (" + + new DecimalFormat("0.00").format(maxMemoryGb) + " Gb)")); + + this.setContentPane(content); + this.pack(); + this.setVisible(true); } public String getPluginName() {
participants (1)
-
dlanglais@users.nuiton.org