oshi first
This commit is contained in:
parent
e9aea68472
commit
955caf07c4
|
@ -23,7 +23,7 @@ public class App {
|
||||||
|
|
||||||
public static MainFrame mainFrame;
|
public static MainFrame mainFrame;
|
||||||
|
|
||||||
public static oshi.SystemInfo si = new oshi.SystemInfo();
|
public static oshi.SystemInfo si;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@ public class App {
|
||||||
UpgradeUtil.smoothUpgrade();
|
UpgradeUtil.smoothUpgrade();
|
||||||
|
|
||||||
mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
|
||||||
|
si = new oshi.SystemInfo();
|
||||||
|
|
||||||
Init.initGlobalFont();
|
Init.initGlobalFont();
|
||||||
mainFrame.setContentPane(MainWindow.getInstance().getMainPanel());
|
mainFrame.setContentPane(MainWindow.getInstance().getMainPanel());
|
||||||
MainWindow.getInstance().init();
|
MainWindow.getInstance().init();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.formdev.flatlaf.FlatLightLaf;
|
||||||
import com.formdev.flatlaf.IntelliJTheme;
|
import com.formdev.flatlaf.IntelliJTheme;
|
||||||
import com.luoboduner.moo.info.App;
|
import com.luoboduner.moo.info.App;
|
||||||
import com.luoboduner.moo.info.ui.component.TopMenuBar;
|
import com.luoboduner.moo.info.ui.component.TopMenuBar;
|
||||||
|
import com.luoboduner.moo.info.ui.form.NetworkForm;
|
||||||
import com.luoboduner.moo.info.ui.form.OverviewForm;
|
import com.luoboduner.moo.info.ui.form.OverviewForm;
|
||||||
import com.luoboduner.moo.info.util.SystemUtil;
|
import com.luoboduner.moo.info.util.SystemUtil;
|
||||||
import com.luoboduner.moo.info.util.UIUtil;
|
import com.luoboduner.moo.info.util.UIUtil;
|
||||||
|
@ -201,6 +202,7 @@ public class Init {
|
||||||
public static void initAllTab() {
|
public static void initAllTab() {
|
||||||
|
|
||||||
ThreadUtil.execute(OverviewForm::init);
|
ThreadUtil.execute(OverviewForm::init);
|
||||||
|
ThreadUtil.execute(NetworkForm::init);
|
||||||
|
|
||||||
// Check the new version
|
// Check the new version
|
||||||
if (App.config.isAutoCheckUpdate()) {
|
if (App.config.isAutoCheckUpdate()) {
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children/>
|
<children/>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="73e0b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="73e0b" binding="networkPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<tabbedpane title="Network"/>
|
<tabbedpane title="Network"/>
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class MainWindow {
|
||||||
private JTabbedPane tabbedPane;
|
private JTabbedPane tabbedPane;
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private JPanel overviewPanel;
|
private JPanel overviewPanel;
|
||||||
|
private JPanel networkPanel;
|
||||||
|
|
||||||
private static MainWindow mainWindow;
|
private static MainWindow mainWindow;
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ public class MainWindow {
|
||||||
public void init() {
|
public void init() {
|
||||||
mainWindow = getInstance();
|
mainWindow = getInstance();
|
||||||
mainWindow.getOverviewPanel().add(OverviewForm.getInstance().getMainPanel(), gridConstraints);
|
mainWindow.getOverviewPanel().add(OverviewForm.getInstance().getMainPanel(), gridConstraints);
|
||||||
|
mainWindow.getNetworkPanel().add(NetworkForm.getInstance().getMainPanel(), gridConstraints);
|
||||||
mainWindow.getMainPanel().updateUI();
|
mainWindow.getMainPanel().updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,18 +76,18 @@ public class MainWindow {
|
||||||
final JPanel panel4 = new JPanel();
|
final JPanel panel4 = new JPanel();
|
||||||
panel4.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
panel4.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
tabbedPane.addTab("Disk", panel4);
|
tabbedPane.addTab("Disk", panel4);
|
||||||
|
networkPanel = new JPanel();
|
||||||
|
networkPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
|
tabbedPane.addTab("Network", networkPanel);
|
||||||
final JPanel panel5 = new JPanel();
|
final JPanel panel5 = new JPanel();
|
||||||
panel5.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
panel5.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
tabbedPane.addTab("Network", panel5);
|
tabbedPane.addTab("Variables", panel5);
|
||||||
final JPanel panel6 = new JPanel();
|
final JPanel panel6 = new JPanel();
|
||||||
panel6.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
panel6.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
tabbedPane.addTab("Variables", panel6);
|
tabbedPane.addTab("Processes", panel6);
|
||||||
final JPanel panel7 = new JPanel();
|
final JPanel panel7 = new JPanel();
|
||||||
panel7.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
panel7.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
tabbedPane.addTab("Processes", panel7);
|
tabbedPane.addTab("USB Devices", panel7);
|
||||||
final JPanel panel8 = new JPanel();
|
|
||||||
panel8.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
|
||||||
tabbedPane.addTab("USB Devices", panel8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.luoboduner.moo.info.ui.form.NetworkForm">
|
||||||
|
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||||
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="a1ab0" 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="0" 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>
|
||||||
|
<grid id="51265" binding="paramatersPanel" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||||
|
<grid row="0" 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="82246" class="javax.swing.JTextPane" binding="parametersTextPane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<scrollpane id="efe72">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="2a917" class="javax.swing.JTable" binding="interfacesTable">
|
||||||
|
<constraints/>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</scrollpane>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
|
@ -0,0 +1,193 @@
|
||||||
|
package com.luoboduner.moo.info.ui.form;
|
||||||
|
|
||||||
|
import cn.hutool.log.Log;
|
||||||
|
import cn.hutool.log.LogFactory;
|
||||||
|
import com.intellij.uiDesigner.core.GridConstraints;
|
||||||
|
import com.intellij.uiDesigner.core.GridLayoutManager;
|
||||||
|
import com.luoboduner.moo.info.App;
|
||||||
|
import lombok.Getter;
|
||||||
|
import oshi.hardware.NetworkIF;
|
||||||
|
import oshi.software.os.NetworkParams;
|
||||||
|
import oshi.software.os.OperatingSystem;
|
||||||
|
import oshi.util.Constants;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
import javax.swing.table.TableColumnModel;
|
||||||
|
import javax.swing.table.TableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OverviewForm
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/rememberber">RememBerBer</a>
|
||||||
|
* @since 2021/11/12.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class NetworkForm {
|
||||||
|
private JPanel mainPanel;
|
||||||
|
private JTable interfacesTable;
|
||||||
|
private JPanel paramatersPanel;
|
||||||
|
private JTextPane parametersTextPane;
|
||||||
|
|
||||||
|
private static final int INIT_HASH_SIZE = 100;
|
||||||
|
private static final String IP_ADDRESS_SEPARATOR = "; ";
|
||||||
|
private static final String[] COLUMNS = {"Name", "Index", "Speed", "IPv4 Address", "IPv6 address", "MAC address"};
|
||||||
|
private static final double[] COLUMN_WIDTH_PERCENT = {0.02, 0.02, 0.1, 0.25, 0.45, 0.15};
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.get();
|
||||||
|
|
||||||
|
private static NetworkForm networkForm;
|
||||||
|
|
||||||
|
public static NetworkForm getInstance() {
|
||||||
|
if (networkForm == null) {
|
||||||
|
networkForm = new NetworkForm();
|
||||||
|
}
|
||||||
|
return networkForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
networkForm = getInstance();
|
||||||
|
|
||||||
|
initUi();
|
||||||
|
initInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initUi() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initInfo() {
|
||||||
|
initParameters();
|
||||||
|
initInterfaces();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initInterfaces() {
|
||||||
|
JTable interfacesTable = getInstance().getInterfacesTable();
|
||||||
|
|
||||||
|
List<NetworkIF> networkIfList = App.si.getHardware().getNetworkIFs(true);
|
||||||
|
|
||||||
|
TableModel model = new DefaultTableModel(parseInterfaces(networkIfList), COLUMNS);
|
||||||
|
interfacesTable.setModel(model);
|
||||||
|
resizeColumns(interfacesTable.getColumnModel());
|
||||||
|
interfacesTable.setShowGrid(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initParameters() {
|
||||||
|
JTextPane parametersTextPane = networkForm.getParametersTextPane();
|
||||||
|
parametersTextPane.setContentType("text/plain; charset=utf-8");
|
||||||
|
parametersTextPane.setEditable(false);
|
||||||
|
|
||||||
|
parametersTextPane.setText(buildParamsText(App.si.getOperatingSystem()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildParamsText(OperatingSystem os) {
|
||||||
|
NetworkParams params = os.getNetworkParams();
|
||||||
|
StringBuilder sb = new StringBuilder("Host Name: ").append(params.getHostName());
|
||||||
|
if (!params.getDomainName().isEmpty()) {
|
||||||
|
sb.append("\nDomain Name: ").append(params.getDomainName());
|
||||||
|
}
|
||||||
|
sb.append("\nIPv4 Default Gateway: ").append(params.getIpv4DefaultGateway());
|
||||||
|
if (!params.getIpv6DefaultGateway().isEmpty()) {
|
||||||
|
sb.append("\nIPv6 Default Gateway: ").append(params.getIpv6DefaultGateway());
|
||||||
|
}
|
||||||
|
sb.append("\nDNS Servers: ").append(getIPAddressesString(params.getDnsServers()));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getIPAddressesString(String[] ipAddressArr) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean first = true;
|
||||||
|
|
||||||
|
for (String ipAddress : ipAddressArr) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
sb.append(IP_ADDRESS_SEPARATOR);
|
||||||
|
}
|
||||||
|
sb.append(ipAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object[][] parseInterfaces(List<NetworkIF> list) {
|
||||||
|
Map<NetworkIF, Integer> intfSortValueMap = new HashMap<>(INIT_HASH_SIZE);
|
||||||
|
for (NetworkIF intf : list) {
|
||||||
|
intfSortValueMap.put(intf, intf.getIndex());
|
||||||
|
}
|
||||||
|
List<Map.Entry<NetworkIF, Integer>> intfList = new ArrayList<>(intfSortValueMap.entrySet());
|
||||||
|
intfList.sort(Map.Entry.comparingByValue());
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
Object[][] intfArr = new Object[intfList.size()][COLUMNS.length];
|
||||||
|
|
||||||
|
for (Map.Entry<NetworkIF, Integer> e : intfList) {
|
||||||
|
NetworkIF intf = e.getKey();
|
||||||
|
|
||||||
|
intfArr[i][0] = intf.getName();
|
||||||
|
intfArr[i][1] = intf.getIndex();
|
||||||
|
intfArr[i][2] = intf.getSpeed();
|
||||||
|
intfArr[i][3] = getIPAddressesString(intf.getIPv4addr());
|
||||||
|
intfArr[i][4] = getIPAddressesString(intf.getIPv6addr());
|
||||||
|
intfArr[i][5] = Constants.UNKNOWN.equals(intf.getMacaddr()) ? "" : intf.getMacaddr();
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intfArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resizeColumns(TableColumnModel tableColumnModel) {
|
||||||
|
TableColumn column;
|
||||||
|
int tW = tableColumnModel.getTotalColumnWidth();
|
||||||
|
int cantCols = tableColumnModel.getColumnCount();
|
||||||
|
for (int i = 0; i < cantCols; i++) {
|
||||||
|
column = tableColumnModel.getColumn(i);
|
||||||
|
int pWidth = (int) Math.round(COLUMN_WIDTH_PERCENT[i] * tW);
|
||||||
|
column.setPreferredWidth(pWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
||||||
|
// >>> IMPORTANT!! <<<
|
||||||
|
// DO NOT EDIT OR ADD ANY CODE HERE!
|
||||||
|
$$$setupUI$$$();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method generated by IntelliJ IDEA GUI Designer
|
||||||
|
* >>> IMPORTANT!! <<<
|
||||||
|
* DO NOT edit this method OR call it in your code!
|
||||||
|
*
|
||||||
|
* @noinspection ALL
|
||||||
|
*/
|
||||||
|
private void $$$setupUI$$$() {
|
||||||
|
mainPanel = new JPanel();
|
||||||
|
mainPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
|
final JPanel panel1 = new JPanel();
|
||||||
|
panel1.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
|
||||||
|
mainPanel.add(panel1, new GridConstraints(0, 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));
|
||||||
|
paramatersPanel = new JPanel();
|
||||||
|
paramatersPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
|
||||||
|
panel1.add(paramatersPanel, new GridConstraints(0, 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));
|
||||||
|
parametersTextPane = new JTextPane();
|
||||||
|
paramatersPanel.add(parametersTextPane, 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, new Dimension(150, 50), null, 0, false));
|
||||||
|
final JScrollPane scrollPane1 = new JScrollPane();
|
||||||
|
panel1.add(scrollPane1, 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_WANT_GROW, null, null, null, 0, false));
|
||||||
|
interfacesTable = new JTable();
|
||||||
|
scrollPane1.setViewportView(interfacesTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @noinspection ALL
|
||||||
|
*/
|
||||||
|
public JComponent $$$getRootComponent$$$() {
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ public class MainFrame extends JFrame {
|
||||||
TopMenuBar topMenuBar = TopMenuBar.getInstance();
|
TopMenuBar topMenuBar = TopMenuBar.getInstance();
|
||||||
topMenuBar.init();
|
topMenuBar.init();
|
||||||
setJMenuBar(topMenuBar);
|
setJMenuBar(topMenuBar);
|
||||||
ComponentUtil.setPreferSizeAndLocateToCenter(this, 0.6, 0.66);
|
ComponentUtil.setPreferSizeAndLocateToCenter(this, 0.6, 0.68);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue