cpu and memory form added

This commit is contained in:
RememBerBer 2021-11-17 13:44:18 +08:00
parent 0fe2f8237a
commit ec4afe8a57
2 changed files with 64 additions and 5 deletions

View File

@ -15,7 +15,7 @@
<properties/>
<border type="empty"/>
<children>
<grid id="bbcf8" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="bbcf8" layout-manager="GridLayoutManager" row-count="7" 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/>
@ -203,9 +203,43 @@
</grid>
<vspacer id="d87ac">
<constraints>
<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"/>
<grid row="6" 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>
<grid id="67c48" layout-manager="GridLayoutManager" row-count="2" 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>
<grid row="5" 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="1bb21" class="javax.swing.JTextPane" binding="physicalMemoryInfoTextPane">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="1" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<component id="7fbe5" class="javax.swing.JLabel" binding="physicalMemoryInfoLabel">
<constraints>
<grid row="0" 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="Physical Memory Info"/>
</properties>
</component>
</children>
</grid>
<component id="f44e3" class="javax.swing.JSeparator">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>

View File

@ -46,6 +46,8 @@ public class MemoryForm {
private JProgressBar jvmProgressBar;
private JLabel jvmUsedLabel;
private JLabel jvmAvailableLabel;
private JTextPane physicalMemoryInfoTextPane;
private JLabel physicalMemoryInfoLabel;
public static MemoryForm getInstance() {
if (memoryForm == null) {
@ -60,6 +62,7 @@ public class MemoryForm {
initUi();
Timer timer = new Timer(UiConsts.REFRESH_FAST, e -> {
initInfo();
memoryForm.getPhysicalMemoryInfoTextPane().setText(updateMemoryText());
});
timer.start();
}
@ -72,9 +75,11 @@ public class MemoryForm {
memoryForm.getVirtualMemoryTitle().setFont(emphaticFont);
memoryForm.getSwapTitle().setFont(emphaticFont);
memoryForm.getJvmMemoryTitle().setFont(emphaticFont);
memoryForm.getPhysicalMemoryInfoLabel().setFont(emphaticFont);
Dimension d = new Dimension(-1, 100);
memoryForm.getPhysicalMemoryProgressBar().setMinimumSize(d);
}
private static void initInfo() {
@ -132,7 +137,16 @@ public class MemoryForm {
memoryForm.getJvmUsedLabel().setText("Used " + DataSizeUtil.format(jvmUsed) + " / Total " + DataSizeUtil.format(jvmTotal) + " / Max " + DataSizeUtil.format(jvmMax));
memoryForm.getJvmAvailableLabel().setText("");
List<PhysicalMemory> physicalMemory = memory.getPhysicalMemory();
}
private static String updateMemoryText() {
StringBuilder sb = new StringBuilder();
GlobalMemory memory = App.si.getHardware().getMemory();
List<PhysicalMemory> pmList = memory.getPhysicalMemory();
for (PhysicalMemory pm : pmList) {
sb.append('\n').append(pm.toString());
}
return sb.toString();
}
{
@ -156,7 +170,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(5, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.setLayout(new GridLayoutManager(7, 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));
@ -223,7 +237,18 @@ public class MemoryForm {
final Spacer spacer4 = new Spacer();
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));
panel1.add(spacer5, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
final JPanel panel6 = new JPanel();
panel6.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
panel1.add(panel6, new GridConstraints(5, 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));
physicalMemoryInfoTextPane = new JTextPane();
physicalMemoryInfoTextPane.setEditable(false);
panel6.add(physicalMemoryInfoTextPane, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(1, -1), null, 0, false));
physicalMemoryInfoLabel = new JLabel();
physicalMemoryInfoLabel.setText("Physical Memory Info");
panel6.add(physicalMemoryInfoLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JSeparator separator1 = new JSeparator();
panel1.add(separator1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
}
/**