overview first step

This commit is contained in:
RememBerBer 2021-11-20 18:31:49 +08:00
parent fad4c816f5
commit aa5b7455b6
2 changed files with 73 additions and 2 deletions

View File

@ -88,7 +88,7 @@
</constraints>
<properties/>
</component>
<grid id="9c58e" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="9c58e" layout-manager="GridLayoutManager" row-count="5" 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="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -128,6 +128,14 @@
<text value="BaseBoard"/>
</properties>
</component>
<component id="a9c3d" class="javax.swing.JLabel" binding="diskStorageLabel" default-binding="true">
<constraints>
<grid row="4" 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="DiskStorage"/>
</properties>
</component>
<component id="2892f" class="javax.swing.JLabel" binding="cpuInfo">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@ -160,6 +168,14 @@
<text value="BaseBoard info"/>
</properties>
</component>
<component id="4486c" class="javax.swing.JLabel" binding="diskStorageInfoLabel" default-binding="true">
<constraints>
<grid row="4" column="1" 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="DiskStorage info"/>
</properties>
</component>
<hspacer id="84083">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>

View File

@ -3,6 +3,7 @@ package com.luoboduner.moo.info.ui.form;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.google.common.collect.Maps;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
@ -12,6 +13,8 @@ import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import oshi.hardware.*;
import oshi.software.os.OperatingSystem;
import oshi.util.EdidUtil;
import oshi.util.FormatUtil;
import javax.swing.*;
import javax.swing.border.TitledBorder;
@ -20,6 +23,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* OverviewForm
@ -43,6 +47,8 @@ public class OverviewForm {
private JLabel graphicsCardInfo;
private JLabel baseBoardLabel;
private JLabel baseBoardInfoLabel;
private JLabel diskStorageLabel;
private JLabel diskStorageInfoLabel;
public static OverviewForm getInstance() {
if (overviewForm == null) {
@ -68,6 +74,7 @@ public class OverviewForm {
Style.emphaticLabelFont(overviewForm.getMemoryLabel());
Style.emphaticLabelFont(overviewForm.getGraphicsCardLabel());
Style.emphaticLabelFont(overviewForm.getBaseBoardLabel());
Style.emphaticLabelFont(overviewForm.getDiskStorageLabel());
}
private static void initInfo() {
@ -85,6 +92,28 @@ public class OverviewForm {
overviewForm.getMemoryInfo().setText(getMemoryInfo(hardware.getMemory()));
overviewForm.getGraphicsCardInfo().setText(getGraphicsCardInfo(hardware));
overviewForm.getBaseBoardInfoLabel().setText(getBaseBoardInfo(hardware.getComputerSystem().getBaseboard()));
overviewForm.getDiskStorageInfoLabel().setText(getDiskStorageInfo(hardware));
List<Display> displays = hardware.getDisplays();
for (Display display : displays) {
byte[] edid = display.getEdid();
byte[][] desc = EdidUtil.getDescriptors(edid);
Map<String, String> infoMap = Maps.newHashMap();
for (byte[] b : desc) {
int descriptorType = EdidUtil.getDescriptorType(b);
if (descriptorType == 0xff || descriptorType == 0xfe || descriptorType == 0xfd || descriptorType == 0xfb || descriptorType == 0xfa) {
} else if (descriptorType == 0xfc) {
infoMap.put("name", EdidUtil.getDescriptorText(b));
} else {
if (EdidUtil.getDescriptorType(b) > 0x0f || EdidUtil.getDescriptorType(b) < 0x00) {
infoMap.put("size", EdidUtil.getTimingDescriptor(b));
}
}
}
System.err.println(infoMap);
}
}
/**
@ -151,6 +180,26 @@ public class OverviewForm {
return detailBuilder.toString();
}
/**
* Disk Storage info text,like:"KBG40ZNV512G KIOXIA (标准磁盘驱动器) 512 GB"
*
* @param hardware
* @return
*/
private static String getDiskStorageInfo(HardwareAbstractionLayer hardware) {
List<String> detailList = new ArrayList<>();
StringBuilder detailBuilder;
List<HWDiskStore> diskStores = hardware.getDiskStores();
for (HWDiskStore hwDiskStore : diskStores) {
detailBuilder = new StringBuilder();
detailBuilder.append(hwDiskStore.getModel());
detailBuilder.append(" ").append(hwDiskStore.getSize() > 0 ? FormatUtil.formatBytesDecimal(hwDiskStore.getSize()) : "?");
detailList.add(detailBuilder.toString());
}
return StringUtils.join(detailList, " + ");
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
@ -198,7 +247,7 @@ public class OverviewForm {
final JSeparator separator1 = new JSeparator();
panel1.add(separator1, new GridConstraints(1, 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));
final JPanel panel5 = new JPanel();
panel5.setLayout(new GridLayoutManager(4, 3, new Insets(10, 10, 10, 10), -1, -1));
panel5.setLayout(new GridLayoutManager(5, 3, new Insets(10, 10, 10, 10), -1, -1));
panel1.add(panel5, new GridConstraints(2, 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));
cpuLabel = new JLabel();
cpuLabel.setText("CPU");
@ -212,6 +261,9 @@ public class OverviewForm {
baseBoardLabel = new JLabel();
baseBoardLabel.setText("BaseBoard");
panel5.add(baseBoardLabel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
diskStorageLabel = new JLabel();
diskStorageLabel.setText("DiskStorage");
panel5.add(diskStorageLabel, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
cpuInfo = new JLabel();
cpuInfo.setText("CPU info");
panel5.add(cpuInfo, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@ -224,6 +276,9 @@ public class OverviewForm {
baseBoardInfoLabel = new JLabel();
baseBoardInfoLabel.setText("BaseBoard info");
panel5.add(baseBoardInfoLabel, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
diskStorageInfoLabel = new JLabel();
diskStorageInfoLabel.setText("DiskStorage info");
panel5.add(diskStorageInfoLabel, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer4 = new Spacer();
panel5.add(spacer4, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
}