cpu and memory form added

This commit is contained in:
RememBerBer 2021-11-17 11:15:32 +08:00
parent d4fbeb1fb8
commit 0fe2f8237a
2 changed files with 92 additions and 7 deletions

View File

@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="500" height="572"/>
</constraints>
<properties/>
<border type="none"/>
@ -15,7 +15,7 @@
<properties/>
<border type="empty"/>
<children>
<grid id="bbcf8" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="bbcf8" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
@ -156,9 +156,54 @@
</hspacer>
</children>
</grid>
<grid id="de034" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4efa" class="javax.swing.JLabel" binding="jvmMemoryTitle">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Java Runtime Memory of MooInfo"/>
</properties>
</component>
<component id="cd7f7" class="javax.swing.JProgressBar" binding="jvmProgressBar">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="6d093" class="javax.swing.JLabel" binding="jvmUsedLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Used -"/>
</properties>
</component>
<component id="c7d5b" class="javax.swing.JLabel" binding="jvmAvailableLabel">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="- Available"/>
</properties>
</component>
<hspacer id="bd1ea">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<vspacer id="d87ac">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>

View File

@ -42,6 +42,10 @@ public class MemoryForm {
private JProgressBar swapProgressBar;
private JLabel swapAvailableLabel;
private JLabel swapTitle;
private JLabel jvmMemoryTitle;
private JProgressBar jvmProgressBar;
private JLabel jvmUsedLabel;
private JLabel jvmAvailableLabel;
public static MemoryForm getInstance() {
if (memoryForm == null) {
@ -67,6 +71,10 @@ public class MemoryForm {
memoryForm.getPhysicalMemoryTitle().setFont(emphaticFont);
memoryForm.getVirtualMemoryTitle().setFont(emphaticFont);
memoryForm.getSwapTitle().setFont(emphaticFont);
memoryForm.getJvmMemoryTitle().setFont(emphaticFont);
Dimension d = new Dimension(-1, 100);
memoryForm.getPhysicalMemoryProgressBar().setMinimumSize(d);
}
private static void initInfo() {
@ -80,7 +88,10 @@ public class MemoryForm {
physicalMemoryProgressBar.setMaximum(100);
int usagePercent = (int) ((total - available) * 100 / total);
physicalMemoryProgressBar.setValue(usagePercent);
physicalMemoryProgressBar.setToolTipText(usagePercent + "%");
String progressStr = usagePercent + "%";
physicalMemoryProgressBar.setToolTipText(progressStr);
physicalMemoryProgressBar.setStringPainted(true);
physicalMemoryProgressBar.setString(progressStr);
memoryForm.getPhysicalMemoryUsed().setText("Used " + DataSizeUtil.format(total - available) + "/" + DataSizeUtil.format(total));
memoryForm.getPhysicalMemoryAvailable().setText(DataSizeUtil.format(available) + "/" + DataSizeUtil.format(total) + " Available");
@ -105,9 +116,22 @@ public class MemoryForm {
int swapUsagePercent = (int) (swapUsed * 100 / swapTotal);
swapProgressBar.setValue(swapUsagePercent);
swapProgressBar.setToolTipText(swapUsagePercent + "%");
memoryForm.getSwapUsedLabel().setText("Used " + DataSizeUtil.format(swapUsed) + "/" + DataSizeUtil.format(swapTotal));
memoryForm.getSwapUsedLabel().setText("Used " + DataSizeUtil.format(swapUsed) + "/" + DataSizeUtil.format(swapTotal) + " | page in " + virtualMemory.getSwapPagesIn() + " page out " + virtualMemory.getSwapPagesOut());
memoryForm.getSwapAvailableLabel().setText(DataSizeUtil.format(swapTotal - swapUsed) + "/" + DataSizeUtil.format(swapTotal) + " Available");
long jvmTotal = Runtime.getRuntime().totalMemory();
long jvmMax = Runtime.getRuntime().maxMemory();
long jvmFree = Runtime.getRuntime().freeMemory();
long jvmUsed = jvmTotal - jvmFree;
JProgressBar jvmProgressBar = memoryForm.getJvmProgressBar();
jvmProgressBar.setMaximum(100);
int jvmUsagePercent = (int) (jvmUsed * 100 / jvmTotal);
jvmProgressBar.setValue(jvmUsagePercent);
jvmProgressBar.setToolTipText(jvmUsagePercent + "%");
memoryForm.getJvmUsedLabel().setText("Used " + DataSizeUtil.format(jvmUsed) + " / Total " + DataSizeUtil.format(jvmTotal) + " / Max " + DataSizeUtil.format(jvmMax));
memoryForm.getJvmAvailableLabel().setText("");
List<PhysicalMemory> physicalMemory = memory.getPhysicalMemory();
}
@ -132,7 +156,7 @@ public class MemoryForm {
mainPanel.add(scrollPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
scrollPane1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1));
scrollPane1.setViewportView(panel1);
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1));
@ -182,8 +206,24 @@ public class MemoryForm {
panel4.add(swapAvailableLabel, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer3 = new Spacer();
panel4.add(spacer3, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
final JPanel panel5 = new JPanel();
panel5.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1));
panel1.add(panel5, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
jvmMemoryTitle = new JLabel();
jvmMemoryTitle.setText("Java Runtime Memory of MooInfo");
panel5.add(jvmMemoryTitle, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
jvmProgressBar = new JProgressBar();
panel5.add(jvmProgressBar, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
jvmUsedLabel = new JLabel();
jvmUsedLabel.setText("Used -");
panel5.add(jvmUsedLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
jvmAvailableLabel = new JLabel();
jvmAvailableLabel.setText("- Available");
panel5.add(jvmAvailableLabel, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer4 = new Spacer();
panel1.add(spacer4, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
panel5.add(spacer4, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
final Spacer spacer5 = new Spacer();
panel1.add(spacer5, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
}
/**