Disk panel first step, copy from oshi

This commit is contained in:
RememBerBer 2021-11-16 13:35:19 +08:00
parent afc41e9f8f
commit d3d6ca755b
3 changed files with 38 additions and 13 deletions

View File

@ -61,7 +61,7 @@ public class DiskForm {
OSFileStore store = fileStores.get(i); OSFileStore store = fileStores.get(i);
JPanel diskPanel = new JPanel(); JPanel diskPanel = new JPanel();
diskPanel.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 0), -1, -1)); diskPanel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 0, 10, 0), -1, -1));
JLabel title = new JLabel(); JLabel title = new JLabel();
StringBuilder titleBuilder = new StringBuilder(); StringBuilder titleBuilder = new StringBuilder();
titleBuilder.append(store.getName()); titleBuilder.append(store.getName());
@ -70,13 +70,13 @@ public class DiskForm {
titleBuilder.append(store.getLabel()); titleBuilder.append(store.getLabel());
} }
title.setText(titleBuilder.toString()); title.setText(titleBuilder.toString());
Font font = new Font(diskListPanel.getFont().getName(), Font.BOLD, diskListPanel.getFont().getSize()); Font font = new Font(diskListPanel.getFont().getName(), Font.BOLD, diskListPanel.getFont().getSize() + 2);
title.setFont(font); title.setFont(font);
diskPanel.add(title, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); diskPanel.add(title, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
JProgressBar spacePercent = new JProgressBar(); JProgressBar spacePercent = new JProgressBar();
diskPanel.add(spacePercent, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); diskPanel.add(spacePercent, 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 subTitle = new JLabel(); JLabel subTitle = new JLabel();
long usable = store.getUsableSpace(); long usable = store.getUsableSpace();
long total = store.getTotalSpace(); long total = store.getTotalSpace();
@ -84,9 +84,15 @@ public class DiskForm {
int usagePercent = (int) ((total - usable) * 100 / total); int usagePercent = (int) ((total - usable) * 100 / total);
spacePercent.setValue(usagePercent); spacePercent.setValue(usagePercent);
spacePercent.setToolTipText(usagePercent + "%"); spacePercent.setToolTipText(usagePercent + "%");
subTitle.setText("Available: " + DataSizeUtil.format(usable) + "/" + DataSizeUtil.format(total)); subTitle.setText("Used " + DataSizeUtil.format(total - usable) + "/" + DataSizeUtil.format(total));
diskPanel.add(subTitle, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); diskPanel.add(subTitle, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
JLabel available = new JLabel();
available.setText(DataSizeUtil.format(usable) + "/" + DataSizeUtil.format(total) + " Available");
diskPanel.add(available, 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 spacer1 = new Spacer();
diskPanel.add(spacer1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
diskListPanel.add(diskPanel, 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)); diskListPanel.add(diskPanel, 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));

View File

@ -29,7 +29,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="33985" binding="disk1Panel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="33985" binding="disk1Panel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="0" bottom="10" right="0"/> <margin top="10" left="0" bottom="10" right="0"/>
<constraints> <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"/> <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"/>
@ -39,7 +39,7 @@
<children> <children>
<component id="7b3f6" class="javax.swing.JLabel" binding="disk1Label1"> <component id="7b3f6" class="javax.swing.JLabel" binding="disk1Label1">
<constraints> <constraints>
<grid row="0" column="0" 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="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Label"/> <text value="Label"/>
@ -47,7 +47,7 @@
</component> </component>
<component id="687e9" class="javax.swing.JProgressBar" binding="disk1ProgressBar"> <component id="687e9" class="javax.swing.JProgressBar" binding="disk1ProgressBar">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
</component> </component>
@ -59,6 +59,19 @@
<text value="Label"/> <text value="Label"/>
</properties> </properties>
</component> </component>
<component id="ed1e7" class="javax.swing.JLabel" binding="disk1Label3">
<constraints>
<grid row="2" column="2" 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="Label"/>
</properties>
</component>
<hspacer id="49f40">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children> </children>
</grid> </grid>
<grid id="1ad60" binding="disk2Panel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="1ad60" binding="disk2Panel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

View File

@ -33,6 +33,7 @@ public class DiskFormLayoutDesign {
private JLabel disk3Label1; private JLabel disk3Label1;
private JLabel disk3Label2; private JLabel disk3Label2;
private JPanel diskListPanel; private JPanel diskListPanel;
private JLabel disk1Label3;
private static final Log logger = LogFactory.get(); private static final Log logger = LogFactory.get();
@ -85,16 +86,21 @@ public class DiskFormLayoutDesign {
diskListPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 10, 0, 10), -1, -1)); diskListPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 10, 0, 10), -1, -1));
scrollPane1.setViewportView(diskListPanel); scrollPane1.setViewportView(diskListPanel);
disk1Panel = new JPanel(); disk1Panel = new JPanel();
disk1Panel.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 0), -1, -1)); disk1Panel.setLayout(new GridLayoutManager(3, 3, new Insets(10, 0, 10, 0), -1, -1));
diskListPanel.add(disk1Panel, 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)); diskListPanel.add(disk1Panel, 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));
disk1Label1 = new JLabel(); disk1Label1 = new JLabel();
disk1Label1.setText("Label"); disk1Label1.setText("Label");
disk1Panel.add(disk1Label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); disk1Panel.add(disk1Label1, new GridConstraints(0, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
disk1ProgressBar = new JProgressBar(); disk1ProgressBar = new JProgressBar();
disk1Panel.add(disk1ProgressBar, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); disk1Panel.add(disk1ProgressBar, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
disk1Label2 = new JLabel(); disk1Label2 = new JLabel();
disk1Label2.setText("Label"); disk1Label2.setText("Label");
disk1Panel.add(disk1Label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); disk1Panel.add(disk1Label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
disk1Label3 = new JLabel();
disk1Label3.setText("Label");
disk1Panel.add(disk1Label3, 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 spacer1 = new Spacer();
disk1Panel.add(spacer1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
disk2Panel = new JPanel(); disk2Panel = new JPanel();
disk2Panel.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 0), -1, -1)); disk2Panel.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 0), -1, -1));
diskListPanel.add(disk2Panel, 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)); diskListPanel.add(disk2Panel, 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));
@ -117,8 +123,8 @@ public class DiskFormLayoutDesign {
disk3Label2 = new JLabel(); disk3Label2 = new JLabel();
disk3Label2.setText("Label"); disk3Label2.setText("Label");
disk3Panel.add(disk3Label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); disk3Panel.add(disk3Label2, 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 spacer1 = new Spacer(); final Spacer spacer2 = new Spacer();
diskListPanel.add(spacer1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); diskListPanel.add(spacer2, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
} }
/** /**