From d4c35426ed3b7d4887bc73c142504731c3fc7859 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Wed, 24 Nov 2021 17:41:22 +0800 Subject: [PATCH] memory info detail --- .../moo/info/ui/form/DetailForm.java | 15 ++---- .../moo/info/ui/form/MemoryForm.form | 16 +++--- .../moo/info/ui/form/MemoryForm.java | 50 +++++++++++++------ .../moo/info/ui/form/OverviewForm.java | 2 +- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java index 6822db6..1bbfe64 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/DetailForm.java @@ -9,7 +9,9 @@ import com.luoboduner.moo.info.App; import com.luoboduner.moo.info.ui.Style; import com.luoboduner.moo.info.util.ScrollUtil; import lombok.Getter; -import oshi.hardware.*; +import oshi.hardware.Baseboard; +import oshi.hardware.ComputerSystem; +import oshi.hardware.HardwareAbstractionLayer; import oshi.software.os.OperatingSystem; import javax.swing.*; @@ -112,6 +114,7 @@ public class DetailForm { detailForm.getComputerTextPane().setText(getComputerInfo()); detailForm.getBaseBoardTextPane().setText(getBaseBoardInfo()); detailForm.getCpuTextPane().setText(CpuForm.getCpuInfo()); + detailForm.getMemoryTextPane().setText(MemoryForm.getMemoryInfo()); detailForm.getPowerSourceTextPane().setText(PowerSourceForm.getPowerInfoText(hardware.getPowerSources())); } @@ -165,16 +168,6 @@ public class DetailForm { return builder.toString(); } - /** - * @return - */ - private static String getMemoryInfo() { - StringBuilder builder = new StringBuilder(); - GlobalMemory globalMemory = App.si.getHardware().getMemory(); - - return builder.toString(); - } - { // GUI initializer generated by IntelliJ IDEA GUI Designer // >>> IMPORTANT!! <<< diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.form b/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.form index f44d9a6..452efc0 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.form +++ b/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.form @@ -214,16 +214,6 @@ - - - - - - - - - - @@ -232,6 +222,12 @@ + + + + + + diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.java index d1e07f2..a32e6eb 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/MemoryForm.java @@ -16,6 +16,8 @@ import oshi.hardware.VirtualMemory; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -49,9 +51,9 @@ public class MemoryForm { private JProgressBar jvmProgressBar; private JLabel jvmUsedLabel; private JLabel jvmAvailableLabel; - private JTextPane physicalMemoryInfoTextPane; private JLabel physicalMemoryInfoLabel; private JScrollPane scrollPane; + private JTextPane physicalMemoryInfoTextPane; public static MemoryForm getInstance() { if (memoryForm == null) { @@ -69,12 +71,10 @@ public class MemoryForm { ScheduledExecutorService serviceStartPerSecond = Executors.newSingleThreadScheduledExecutor(); serviceStartPerSecond.scheduleAtFixedRate(MemoryForm::initMemoryProgressInfo, 0, 1, TimeUnit.SECONDS); - ScrollUtil.smoothPane(memoryForm.getScrollPane()); - } private static void initPhysicalMemoryInfo() { - memoryForm.getPhysicalMemoryInfoTextPane().setText(updateMemoryText()); + memoryForm.getPhysicalMemoryInfoTextPane().setText(getMemoryInfo()); } private static void initUi() { @@ -90,6 +90,11 @@ public class MemoryForm { Dimension d = new Dimension(-1, 100); memoryForm.getPhysicalMemoryProgressBar().setMinimumSize(d); + ScrollUtil.smoothPane(memoryForm.getScrollPane()); + + String contentType = "text/html; charset=utf-8"; + memoryForm.getPhysicalMemoryInfoTextPane().setContentType(contentType); + } private static void initMemoryProgressInfo() { @@ -154,14 +159,32 @@ public class MemoryForm { } - private static String updateMemoryText() { - StringBuilder sb = new StringBuilder(); - GlobalMemory memory = App.si.getHardware().getMemory(); - List pmList = memory.getPhysicalMemory(); - for (PhysicalMemory pm : pmList) { - sb.append(pm.toString()).append('\n'); + /** + * @return + */ + public static String getMemoryInfo() { + StringBuilder builder = new StringBuilder(); + GlobalMemory globalMemory = App.si.getHardware().getMemory(); + + builder.append("Total: ").append(DataSizeUtil.format(globalMemory.getTotal())); + builder.append("
Page Size: ").append(DataSizeUtil.format(globalMemory.getPageSize())); + builder.append("
"); + + List physicalMemories = globalMemory.getPhysicalMemory(); + for (int i = 0; i < physicalMemories.size(); i++) { + PhysicalMemory physicalMemory = physicalMemories.get(i); + + builder.append("
Physical Memory: #").append(i); + builder.append("
BankLabel: ").append(physicalMemory.getBankLabel()); + builder.append("
Manufacturer: ").append(physicalMemory.getManufacturer()); + builder.append("
Capacity: ").append(DataSizeUtil.format(physicalMemory.getCapacity())); + builder.append("
Memory Type: ").append(physicalMemory.getMemoryType()); + builder.append("
Clock Speed: ").append(new BigDecimal(physicalMemory.getClockSpeed()).divide(new BigDecimal(1000000), 0, RoundingMode.HALF_UP)).append("MHz"); + + builder.append("
"); } - return sb.toString(); + + return builder.toString(); } { @@ -256,12 +279,11 @@ public class MemoryForm { 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)); + physicalMemoryInfoTextPane = new JTextPane(); + panel6.add(physicalMemoryInfoTextPane, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, 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)); } diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/OverviewForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/OverviewForm.java index 89f33eb..e138a3c 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/OverviewForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/OverviewForm.java @@ -146,7 +146,7 @@ public class OverviewForm { totalCapacity += physicalMemory.getCapacity(); detailBuilder.append(physicalMemory.getManufacturer()); detailBuilder.append(" ").append(physicalMemory.getMemoryType()); - detailBuilder.append(" ").append(new BigDecimal(physicalMemory.getClockSpeed()).divide(new BigDecimal(1000000), 0, RoundingMode.HALF_UP)).append("MHZ"); + detailBuilder.append(" ").append(new BigDecimal(physicalMemory.getClockSpeed()).divide(new BigDecimal(1000000), 0, RoundingMode.HALF_UP)).append("MHz"); detailBuilder.append(" ").append(DataSizeUtil.format(physicalMemory.getCapacity())); detailList.add(detailBuilder.toString()); }