memory info detail

This commit is contained in:
RememBerBer 2021-11-24 17:41:22 +08:00
parent 5d1f9b4a1c
commit d4c35426ed
4 changed files with 47 additions and 36 deletions

View File

@ -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!! <<<

View File

@ -214,16 +214,6 @@
<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"/>
@ -232,6 +222,12 @@
<text value="Physical Memory Info"/>
</properties>
</component>
<component id="2ec66" class="javax.swing.JTextPane" binding="physicalMemoryInfoTextPane">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<component id="f44e3" class="javax.swing.JSeparator">

View File

@ -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<PhysicalMemory> 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("<b>Total: </b>").append(DataSizeUtil.format(globalMemory.getTotal()));
builder.append("<br/><b>Page Size: </b>").append(DataSizeUtil.format(globalMemory.getPageSize()));
builder.append("<br/>");
List<PhysicalMemory> physicalMemories = globalMemory.getPhysicalMemory();
for (int i = 0; i < physicalMemories.size(); i++) {
PhysicalMemory physicalMemory = physicalMemories.get(i);
builder.append("<br/><b>Physical Memory: </b>#").append(i);
builder.append("<br/><b>BankLabel: </b>").append(physicalMemory.getBankLabel());
builder.append("<br/><b>Manufacturer: </b>").append(physicalMemory.getManufacturer());
builder.append("<br/><b>Capacity: </b>").append(DataSizeUtil.format(physicalMemory.getCapacity()));
builder.append("<br/><b>Memory Type: </b>").append(physicalMemory.getMemoryType());
builder.append("<br/><b>Clock Speed: </b>").append(new BigDecimal(physicalMemory.getClockSpeed()).divide(new BigDecimal(1000000), 0, RoundingMode.HALF_UP)).append("MHz");
builder.append("<br/>");
}
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));
}

View File

@ -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());
}