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 76d84a5..95104fa 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 @@ -36,20 +36,20 @@ - + - + - - - + - + + + 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 cf9ac5f..55270b7 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 @@ -2,6 +2,7 @@ package com.luoboduner.moo.info.ui.form; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; +import com.formdev.flatlaf.extras.FlatSVGIcon; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; @@ -25,7 +26,7 @@ public class PowerSourceForm { private JPanel mainPanel; private JPanel powerBasePanel; private JPanel powerInfoPanel; - private JTextPane textPane1; + private JTextPane powerInfoTextPane; private static final Log logger = LogFactory.get(); @@ -51,15 +52,21 @@ public class PowerSourceForm { private static void initInfo() { List powerSources = App.si.getHardware().getPowerSources(); - JPanel powerBasePanel = getInstance().getPowerBasePanel(); + PowerSourceForm powerSourceForm = getInstance(); + JPanel powerBasePanel = powerSourceForm.getPowerBasePanel(); powerBasePanel.setLayout(new GridLayoutManager(powerSources.size(), 1, new Insets(0, 0, 0, 0), -1, -1)); + StringBuilder powerSourceInfoTextBuilder = new StringBuilder(); for (int i = 0; i < powerSources.size(); i++) { + PowerSource powerSource = powerSources.get(i); + powerSourceInfoTextBuilder.append(powerSource.toString()); + powerSourceInfoTextBuilder.append("\n"); + JPanel powerPanel = new JPanel(); - powerPanel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 10, 10, 10), -1, -1)); + powerPanel.setLayout(new GridLayoutManager(3, 4, new Insets(10, 10, 10, 10), -1, -1)); JLabel powerNameLabel = new JLabel(); StringBuilder powerNameBuilder = new StringBuilder(); @@ -68,7 +75,7 @@ public class PowerSourceForm { 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)); + powerPanel.add(powerNameLabel, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); JProgressBar progressBar1 = new JProgressBar(); progressBar1.setMaximum(100); @@ -76,10 +83,10 @@ public class PowerSourceForm { int remainingCapacityPercentInt = (int) (remainingCapacityPercent * 100); progressBar1.setValue(remainingCapacityPercentInt); progressBar1.setStringPainted(true); - progressBar1.setString(String.valueOf(remainingCapacityPercentInt)); + progressBar1.setString(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)); + powerPanel.add(progressBar1, new GridConstraints(1, 0, 1, 4, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); JLabel capacityLabel = new JLabel(); @@ -92,20 +99,30 @@ public class PowerSourceForm { 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(); - double powerUsageRate = powerSource.getPowerUsageRate(); - double amperage = powerSource.getAmperage(); - double voltage = powerSource.getVoltage(); - boolean charging = powerSource.isCharging(); - int cycleCount = powerSource.getCycleCount(); 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)); + powerPanel.add(temperatureLabel, new GridConstraints(2, 3, 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)); + powerPanel.add(spacer2, new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + + JLabel label1 = new JLabel(); + if (powerSource.isCharging()) { + label1.setHorizontalAlignment(SwingConstants.RIGHT); + label1.setHorizontalTextPosition(SwingConstants.RIGHT); + label1.setIcon(new FlatSVGIcon("icons/Charging.svg")); + label1.setText("Charging"); + } + + powerPanel.add(label1, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + powerPanel.add(spacer3, new GridConstraints(0, 2, 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)); } + // info textPane + powerSourceForm.getPowerInfoTextPane().setText(powerSourceInfoTextBuilder.toString()); + } { @@ -137,10 +154,11 @@ public class PowerSourceForm { 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)); + powerInfoPanel.setLayout(new GridLayoutManager(1, 1, new Insets(10, 10, 10, 10), -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)); + powerInfoTextPane = new JTextPane(); + powerInfoTextPane.setEditable(false); + powerInfoPanel.add(powerInfoTextPane, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, 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 index c3e1c12..9565e5f 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.form @@ -34,7 +34,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -64,19 +64,34 @@ + + + + + + + + + + + + + + + + + + + + - + - - - - - @@ -134,13 +149,15 @@ - + - + + + 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 index 710dcb6..13909e2 100644 --- a/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java +++ b/src/main/java/com/luoboduner/moo/info/ui/form/PowerSourceLayoutDesignForm.java @@ -32,7 +32,7 @@ public class PowerSourceLayoutDesignForm { private JProgressBar progressBar2; private JPanel powerBasePanel; private JPanel powerInfoPanel; - private JTextPane textPane1; + private JTextPane powerInfoTextPane; private static final Log logger = LogFactory.get(); @@ -81,21 +81,28 @@ public class PowerSourceLayoutDesignForm { 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)); + powerPanel.setLayout(new GridLayoutManager(3, 4, 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)); + powerPanel.add(powerNameLabel, new GridConstraints(0, 0, 1, 1, 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)); + powerPanel.add(progressBar1, new GridConstraints(1, 0, 1, 4, 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)); + final Spacer spacer2 = new Spacer(); + powerPanel.add(spacer2, new GridConstraints(2, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + label1.setHorizontalAlignment(11); + label1.setHorizontalTextPosition(11); + label1.setText("Label"); + powerPanel.add(label1, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + powerPanel.add(spacer3, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, 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)); + powerPanel.add(temperatureLabel, new GridConstraints(2, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, 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)); @@ -110,13 +117,14 @@ public class PowerSourceLayoutDesignForm { 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)); + final Spacer spacer4 = new Spacer(); + panel1.add(spacer4, 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)); + powerInfoTextPane = new JTextPane(); + powerInfoTextPane.setEditable(false); + powerInfoPanel.add(powerInfoTextPane, 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)); } /**