overview first step

This commit is contained in:
RememBerBer 2021-11-19 17:34:04 +08:00
parent 2f8d16491e
commit 80b61e1300
3 changed files with 63 additions and 18 deletions

View File

@ -23,6 +23,16 @@ public class Style {
component.setFont(new Font(font.getName(), Font.BOLD, font.getSize() + 2)); component.setFont(new Font(font.getName(), Font.BOLD, font.getSize() + 2));
} }
/**
* emphatic font for label
*
* @param component
*/
public static void emphaticLabelFont(JComponent component) {
Font font = MainWindow.getInstance().getMainPanel().getFont();
component.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
}
/** /**
* emphatic font for indicator * emphatic font for indicator
* *

View File

@ -112,7 +112,7 @@
<text value="Memory"/> <text value="Memory"/>
</properties> </properties>
</component> </component>
<component id="2892f" class="javax.swing.JLabel" binding="cpuName"> <component id="2892f" class="javax.swing.JLabel" binding="cpuInfo">
<constraints> <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"/> <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"/>
</constraints> </constraints>
@ -120,7 +120,7 @@
<text value="cpu name"/> <text value="cpu name"/>
</properties> </properties>
</component> </component>
<component id="12e52" class="javax.swing.JLabel" binding="memoryName"> <component id="12e52" class="javax.swing.JLabel" binding="memoryInfo">
<constraints> <constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" 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> </constraints>

View File

@ -1,5 +1,6 @@
package com.luoboduner.moo.info.ui.form; package com.luoboduner.moo.info.ui.form;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.log.Log; import cn.hutool.log.Log;
import cn.hutool.log.LogFactory; import cn.hutool.log.LogFactory;
import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridConstraints;
@ -8,13 +9,20 @@ import com.intellij.uiDesigner.core.Spacer;
import com.luoboduner.moo.info.App; import com.luoboduner.moo.info.App;
import com.luoboduner.moo.info.ui.Style; import com.luoboduner.moo.info.ui.Style;
import lombok.Getter; import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import oshi.hardware.ComputerSystem; import oshi.hardware.ComputerSystem;
import oshi.hardware.GlobalMemory;
import oshi.hardware.HardwareAbstractionLayer; import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.PhysicalMemory;
import oshi.software.os.OperatingSystem; import oshi.software.os.OperatingSystem;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import java.awt.*; import java.awt.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
/** /**
* OverviewForm * OverviewForm
@ -31,9 +39,9 @@ public class OverviewForm {
private JLabel deviceNameLabel; private JLabel deviceNameLabel;
private JLabel osNameLabel; private JLabel osNameLabel;
private JLabel cpuLabel; private JLabel cpuLabel;
private JLabel cpuName; private JLabel cpuInfo;
private JLabel memoryLabel; private JLabel memoryLabel;
private JLabel memoryName; private JLabel memoryInfo;
public static OverviewForm getInstance() { public static OverviewForm getInstance() {
if (overviewForm == null) { if (overviewForm == null) {
@ -51,8 +59,12 @@ public class OverviewForm {
private static void initUi() { private static void initUi() {
OverviewForm overviewForm = getInstance(); OverviewForm overviewForm = getInstance();
Style.emphaticIndicatorFont(overviewForm.getDeviceNameLabel()); Style.emphaticIndicatorFont(overviewForm.getDeviceNameLabel());
Style.emphaticIndicatorFont(overviewForm.getOsNameLabel()); Style.emphaticIndicatorFont(overviewForm.getOsNameLabel());
Style.emphaticLabelFont(overviewForm.getCpuLabel());
Style.emphaticLabelFont(overviewForm.getMemoryLabel());
} }
private static void initInfo() { private static void initInfo() {
@ -66,14 +78,37 @@ public class OverviewForm {
OperatingSystem operatingSystem = App.si.getOperatingSystem(); OperatingSystem operatingSystem = App.si.getOperatingSystem();
overviewForm.getOsNameLabel().setText(operatingSystem.toString()); overviewForm.getOsNameLabel().setText(operatingSystem.toString());
overviewForm.getCpuName().setText(hardware.getProcessor().getProcessorIdentifier().getName()); overviewForm.getCpuInfo().setText(hardware.getProcessor().getProcessorIdentifier().getName());
System.err.println(hardware.toString()); overviewForm.getMemoryInfo().setText(getMemoryInfo(hardware.getMemory()));
System.err.println(); }
System.err.println(hardware.getProcessor().toString());
System.err.println(); /**
System.err.println(hardware.getMemory().toString()); * memory info text,like:"16 GB (SamSung DDR4 3200MHZ 8GB + SamSung DDR4 3200MHZ 8GB)"
System.err.println(hardware.getMemory().getPhysicalMemory().get(0).toString()); *
System.err.println(hardware.getMemory().getPhysicalMemory().get(0).getCapacity() + hardware.getMemory().getPhysicalMemory().get(1).getCapacity()); * @param memory
* @return
*/
private static String getMemoryInfo(GlobalMemory memory) {
StringBuilder memoryInfoBuilder = new StringBuilder();
long totalCapacity = 0;
List<String> detailList = new ArrayList<>();
List<PhysicalMemory> physicalMemories = memory.getPhysicalMemory();
StringBuilder detailBuilder;
for (PhysicalMemory physicalMemory : physicalMemories) {
detailBuilder = new StringBuilder();
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(DataSizeUtil.format(physicalMemory.getCapacity()));
detailList.add(detailBuilder.toString());
}
memoryInfoBuilder.append(DataSizeUtil.format(totalCapacity));
memoryInfoBuilder.append(" (").append(StringUtils.join(detailList, " + ")).append(")");
return memoryInfoBuilder.toString();
} }
{ {
@ -131,12 +166,12 @@ public class OverviewForm {
memoryLabel = new JLabel(); memoryLabel = new JLabel();
memoryLabel.setText("Memory"); memoryLabel.setText("Memory");
panel5.add(memoryLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel5.add(memoryLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
cpuName = new JLabel(); cpuInfo = new JLabel();
cpuName.setText("cpu name"); cpuInfo.setText("cpu name");
panel5.add(cpuName, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); 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));
memoryName = new JLabel(); memoryInfo = new JLabel();
memoryName.setText("memory name"); memoryInfo.setText("memory name");
panel5.add(memoryName, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel5.add(memoryInfo, new GridConstraints(1, 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(); 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)); 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));
} }