From ab4d34d9496c54fbd0e2f904c30ac8fcd9fbc072 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Mon, 22 Nov 2021 13:36:59 +0800 Subject: [PATCH] power source first step --- .../moo/info/ui/form/OverviewForm.java | 2 + .../moo/info/ui/form/PowerSourceForm.form | 37 ++++- .../moo/info/ui/form/PowerSourceForm.java | 81 +++++++++- .../ui/form/PowerSourceLayoutDesignForm.form | 153 ++++++++++++++++++ .../ui/form/PowerSourceLayoutDesignForm.java | 129 +++++++++++++++ 5 files changed, 397 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form create mode 100644 src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java 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 0c6c3be..af91b27 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 @@ -278,10 +278,12 @@ public class OverviewForm { detailBuilder = new StringBuilder(); detailBuilder.append(powerSource.getName()); detailBuilder.append(" ").append(powerSource.getManufacturer()); + detailBuilder.append(" ").append(powerSource.getDeviceName()); if (!"unknown".equals(powerSource.getChemistry())) { detailBuilder.append(" ").append(powerSource.getChemistry()); } detailBuilder.append(" ").append(powerSource.getMaxCapacity()).append("/").append(powerSource.getDesignCapacity()); + detailBuilder.append("(").append(powerSource.getCapacityUnits()).append(")"); detailList.add(detailBuilder.toString()); } diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.form b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.form index 0f7b998..76d84a5 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.form +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.form @@ -15,12 +15,45 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.java index 2f96f5d..4f1f5f8 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceForm.java @@ -4,11 +4,15 @@ import cn.hutool.log.Log; import cn.hutool.log.LogFactory; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; +import com.luoboduner.moo.info.App; import lombok.Getter; +import oshi.hardware.PowerSource; import javax.swing.*; import javax.swing.border.TitledBorder; import java.awt.*; +import java.util.List; /** * NetworkForm @@ -19,6 +23,9 @@ import java.awt.*; @Getter public class PowerSourceForm { private JPanel mainPanel; + private JPanel powerBasePanel; + private JPanel powerInfoPanel; + private JTextPane textPane1; private static final Log logger = LogFactory.get(); @@ -34,8 +41,66 @@ public class PowerSourceForm { public static void init() { powerSourceForm = getInstance(); -// initUi(); -// initInfo(); + initUi(); + initInfo(); + } + + private static void initUi() { + + } + + private static void initInfo() { + List powerSources = App.si.getHardware().getPowerSources(); + JPanel powerBasePanel = getInstance().getPowerBasePanel(); + + powerBasePanel.setLayout(new GridLayoutManager(powerSources.size(), 1, new Insets(0, 0, 0, 0), -1, -1)); + + for (int i = 0; i < powerSources.size(); i++) { + PowerSource powerSource = powerSources.get(i); + + JPanel powerPanel = new JPanel(); + powerPanel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1)); + + JLabel powerNameLabel = new JLabel(); + StringBuilder powerNameBuilder = new StringBuilder(); + powerNameBuilder.append(powerSource.getName()); + powerNameBuilder.append(" ").append(powerSource.getManufacturer()); + powerNameBuilder.append(" ").append(powerSource.getDeviceName()); + powerNameBuilder.append(" ").append(powerSource.getChemistry()); + powerNameLabel.setText(powerNameBuilder.toString()); + powerPanel.add(powerNameLabel, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + + JProgressBar progressBar1 = new JProgressBar(); + progressBar1.setMaximum(100); + double remainingCapacityPercent = powerSource.getRemainingCapacityPercent(); + int remainingCapacityPercentInt = (int) (remainingCapacityPercent * 100); + progressBar1.setValue(remainingCapacityPercentInt); + progressBar1.setStringPainted(true); + progressBar1.setString(String.valueOf(remainingCapacityPercentInt)); + Dimension d = new Dimension(-1, 100); + progressBar1.setMinimumSize(d); + powerPanel.add(progressBar1, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + + JLabel capacityLabel = new JLabel(); + + StringBuilder capacityBuilder = new StringBuilder(); + capacityBuilder.append("Current ").append(powerSource.getCurrentCapacity()); + capacityBuilder.append(" / ").append("Max ").append(powerSource.getMaxCapacity()); + capacityBuilder.append(" / ").append("Design ").append(powerSource.getDesignCapacity()); + capacityBuilder.append(" (").append(powerSource.getCapacityUnits()).append(")"); + capacityLabel.setText(capacityBuilder.toString()); + powerPanel.add(capacityLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + + JLabel temperatureLabel = new JLabel(); + temperatureLabel.setText(String.valueOf(String.format("Temperature: %.1f°C", powerSource.getTemperature()))); + powerPanel.add(temperatureLabel, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + + final Spacer spacer2 = new Spacer(); + powerPanel.add(spacer2, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + + powerBasePanel.add(powerPanel, new GridConstraints(i, 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)); + } + } { @@ -59,8 +124,18 @@ public class PowerSourceForm { mainPanel.add(scrollPane1, 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, null, null, 0, false)); scrollPane1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(1, 1, new Insets(10, 10, 10, 10), -1, -1)); + panel1.setLayout(new GridLayoutManager(3, 1, new Insets(10, 10, 10, 10), -1, -1)); scrollPane1.setViewportView(panel1); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + powerBasePanel = new JPanel(); + powerBasePanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel1.add(powerBasePanel, 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)); + powerInfoPanel = new JPanel(); + powerInfoPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel1.add(powerInfoPanel, 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)); + textPane1 = new JTextPane(); + powerInfoPanel.add(textPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false)); } /** diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form new file mode 100644 index 0000000..c3e1c12 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form @@ -0,0 +1,153 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java new file mode 100644 index 0000000..710dcb6 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java @@ -0,0 +1,129 @@ +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.intellij.uiDesigner.core.Spacer; +import lombok.Getter; + +import javax.swing.*; +import javax.swing.border.TitledBorder; +import java.awt.*; + +/** + * NetworkForm + * + * @author RememBerBer + * @since 2021/11/21. + */ +@Getter +public class PowerSourceLayoutDesignForm { + private JPanel mainPanel; + private JProgressBar progressBar1; + private JLabel powerNameLabel; + private JPanel powerPanel; + private JLabel capacityLabel; + private JLabel temperatureLabel; + private JLabel powerCapacityLabel; + private JLabel temperatureLabel1; + private JLabel powerNameLabel1; + private JPanel panel1; + private JProgressBar progressBar2; + private JPanel powerBasePanel; + private JPanel powerInfoPanel; + private JTextPane textPane1; + + private static final Log logger = LogFactory.get(); + + private static PowerSourceLayoutDesignForm powerSourceForm; + + public static PowerSourceLayoutDesignForm getInstance() { + if (powerSourceForm == null) { + powerSourceForm = new PowerSourceLayoutDesignForm(); + } + return powerSourceForm; + } + + public static void init() { + powerSourceForm = getInstance(); + +// initUi(); +// initInfo(); + } + + { +// 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 JScrollPane scrollPane1 = new JScrollPane(); + mainPanel.add(scrollPane1, 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, null, null, 0, false)); + scrollPane1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); + final JPanel panel2 = new JPanel(); + panel2.setLayout(new GridLayoutManager(3, 1, new Insets(10, 10, 10, 10), -1, -1)); + scrollPane1.setViewportView(panel2); + final Spacer spacer1 = new Spacer(); + panel2.add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + powerBasePanel = new JPanel(); + powerBasePanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel2.add(powerBasePanel, 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)); + powerPanel = new JPanel(); + powerPanel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1)); + powerBasePanel.add(powerPanel, 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)); + powerNameLabel = new JLabel(); + powerNameLabel.setText("PowerName"); + powerPanel.add(powerNameLabel, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + progressBar1 = new JProgressBar(); + powerPanel.add(progressBar1, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + capacityLabel = new JLabel(); + capacityLabel.setText("PowerCapacity"); + powerPanel.add(capacityLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + temperatureLabel = new JLabel(); + temperatureLabel.setText("Temperature"); + powerPanel.add(temperatureLabel, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer2 = new Spacer(); + powerPanel.add(spacer2, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1)); + powerBasePanel.add(panel1, 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)); + powerNameLabel1 = new JLabel(); + powerNameLabel1.setText("PowerName"); + panel1.add(powerNameLabel1, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + progressBar2 = new JProgressBar(); + panel1.add(progressBar2, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + powerCapacityLabel = new JLabel(); + powerCapacityLabel.setText("PowerCapacity"); + panel1.add(powerCapacityLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + temperatureLabel1 = new JLabel(); + temperatureLabel1.setText("Temperature"); + panel1.add(temperatureLabel1, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + panel1.add(spacer3, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + powerInfoPanel = new JPanel(); + powerInfoPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); + panel2.add(powerInfoPanel, 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)); + textPane1 = new JTextPane(); + powerInfoPanel.add(textPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false)); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return mainPanel; + } + +}