Some code optimization
This commit is contained in:
parent
c33eb7c897
commit
6b2314c302
|
@ -105,24 +105,26 @@ 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));
|
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();
|
JLabel temperatureLabel = new JLabel();
|
||||||
temperatureLabel.setText(String.format("Temperature: %.1f°C", powerSource.getTemperature()));
|
temperatureLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
|
temperatureLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
|
||||||
|
|
||||||
|
StringBuilder powerTextBuilder = new StringBuilder();
|
||||||
|
if (powerSource.isCharging()) {
|
||||||
|
temperatureLabel.setIcon(new FlatSVGIcon("icons/Charging.svg"));
|
||||||
|
powerTextBuilder.append("Charging");
|
||||||
|
} else {
|
||||||
|
temperatureLabel.setIcon(new FlatSVGIcon("icons/indicator_light.svg"));
|
||||||
|
powerTextBuilder.append("Remaining Time: " + formatTimeRemaining(powerSource.getTimeRemainingEstimated()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// powerTextBuilder.append(String.format(" / Temperature: %.1f°C", powerSource.getTemperature()));
|
||||||
|
temperatureLabel.setText(powerTextBuilder.toString());
|
||||||
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));
|
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();
|
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));
|
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();
|
JLabel label1 = new JLabel();
|
||||||
label1.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
||||||
label1.setHorizontalTextPosition(SwingConstants.RIGHT);
|
|
||||||
|
|
||||||
if (powerSource.isCharging()) {
|
|
||||||
label1.setIcon(new FlatSVGIcon("icons/Charging.svg"));
|
|
||||||
label1.setText("Charging");
|
|
||||||
} else {
|
|
||||||
label1.setIcon(new FlatSVGIcon("icons/indicator_light.svg"));
|
|
||||||
label1.setText("Remaining Time: " + formatTimeRemaining(powerSource.getTimeRemainingEstimated()));
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
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();
|
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));
|
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));
|
||||||
|
@ -149,6 +151,7 @@ public class PowerSourceForm {
|
||||||
powerInfoBuilder.append("<br/><b>Power Usage Rate: </b>").append(powerSource.getPowerUsageRate());
|
powerInfoBuilder.append("<br/><b>Power Usage Rate: </b>").append(powerSource.getPowerUsageRate());
|
||||||
powerInfoBuilder.append("<br/><b>Voltage: </b>").append(powerSource.getVoltage());
|
powerInfoBuilder.append("<br/><b>Voltage: </b>").append(powerSource.getVoltage());
|
||||||
powerInfoBuilder.append("<br/><b>Amperage: </b>").append(powerSource.getAmperage());
|
powerInfoBuilder.append("<br/><b>Amperage: </b>").append(powerSource.getAmperage());
|
||||||
|
powerInfoBuilder.append("<br/><b>Temperature: </b>").append(String.format("%.1f°C", powerSource.getTemperature()));
|
||||||
powerInfoBuilder.append("<br/><b>Power OnLine: </b>").append(powerSource.isPowerOnLine());
|
powerInfoBuilder.append("<br/><b>Power OnLine: </b>").append(powerSource.isPowerOnLine());
|
||||||
powerInfoBuilder.append("<br/><b>Charging: </b>").append(powerSource.isCharging());
|
powerInfoBuilder.append("<br/><b>Charging: </b>").append(powerSource.isCharging());
|
||||||
powerInfoBuilder.append("<br/><b>Discharging: </b>").append(powerSource.isDischarging());
|
powerInfoBuilder.append("<br/><b>Discharging: </b>").append(powerSource.isDischarging());
|
||||||
|
|
Loading…
Reference in New Issue