Feat: add static analytic of code

This commit is contained in:
Laurent Clouet
2024-06-03 14:02:30 +00:00
parent c966a1a032
commit 4bce6409e3
52 changed files with 249 additions and 316 deletions

View File

@@ -136,7 +136,6 @@ public class GuiSwing extends JFrame implements Gui {
private DownloadProgress downloadProgress;
private BufferedImage iconSprites;
private BufferedImage[] trayIconSprites;
@Getter @Setter private SettingsLoader settingsLoader;
@@ -183,7 +182,6 @@ public class GuiSwing extends JFrame implements Gui {
if (spriteSequenceUrl != null) {
try {
iconSprites = ImageIO.read(spriteSequenceUrl);
trayIconSprites = new BufferedImage[101 * 1]; // sprite sheet has 101 images in 1 column
setIconImage(extractImageFromSprite(-1)); // sprite 0 is standard Sheep It! icon
}
@@ -483,12 +481,10 @@ public class GuiSwing extends JFrame implements Gui {
setIconImage(img);
// if the app supports the system tray, update as well
if (sysTray != null && SystemTray.isSupported()) {
if (trayIcon != null) {
trayIcon.setImage(img);
trayIcon.setImageAutoSize(true); // use this method to ensure that icon is refreshed when on
// the tray
}
if (sysTray != null && SystemTray.isSupported() && trayIcon != null) {
trayIcon.setImage(img);
trayIcon.setImageAutoSize(true); // use this method to ensure that icon is refreshed when on
// the tray
}
}

View File

@@ -40,7 +40,6 @@ public class GuiTextOneLine implements Gui {
private String project;
private int rendered;
private int remaining;
private String creditsEarned;
private int sigIntCount = 0;
private DateFormat df;
@@ -62,7 +61,6 @@ public class GuiTextOneLine implements Gui {
downloadProgress = new DownloadProgress(this);
project = "";
rendered = 0;
remaining = 0;
creditsEarned = null;
status = "";
computeMethod = "";
@@ -162,7 +160,6 @@ public class GuiTextOneLine implements Gui {
}
@Override public void displayStats(Stats stats) {
remaining = stats.getRemainingFrame();
creditsEarned = String.valueOf(stats.getCreditsEarnedDuringSession());
updateLine();
}

View File

@@ -34,7 +34,6 @@ public class VersionParameterHandler<T> extends OptionHandler<T> {
}
@Override public int parseArguments(Parameters params) throws CmdLineException {
Configuration config = new Configuration(null, "", "");
System.out.println("Version: " + Configuration.jarVersion);
System.exit(0);
return 0;

View File

@@ -276,7 +276,7 @@ public class Worker {
try {
config.setMaxAllowedMemory(Utils.parseNumber(max_ram) / 1024); // internal value is in KiB
}
catch (java.lang.IllegalStateException e) {
catch (IllegalStateException e) {
System.err.println(
String.format("ERROR: The entered value of maximum memory (-memory parameter) doesn't seem to be a valid number [%s]", e.getMessage()));
return;

View File

@@ -62,8 +62,6 @@ import com.sheepit.client.Configuration.ComputeType;
import com.sheepit.client.hardware.cpu.CPU;
import com.sheepit.client.hardware.gpu.GPU;
import com.sheepit.client.hardware.gpu.GPUDevice;
import com.sheepit.client.hardware.gpu.GPULister;
import com.sheepit.client.hardware.gpu.nvidia.Nvidia;
import com.sheepit.client.network.Proxy;
import com.sheepit.client.os.OS;
import com.sheepit.client.standalone.GuiSwing;
@@ -632,25 +630,16 @@ public class Settings implements Activity {
class GpuChangeAction implements ActionListener {
@Override public void actionPerformed(ActionEvent e) {
int counter = 0;
for (JCheckBox box : useGPUs) {
if (!box.isSelected()) {
box.setSelected(false);
}
else {
GPULister gpu;
if (useGPUs.get(counter).getGPUDevice().getType().equals(Nvidia.TYPE)) {
gpu = new Nvidia();
}
}
// Simulate a radio button behavior with check buttons while only 1 GPU
// can be selected at a time
if (box.equals(e.getSource()) == false) {
box.setSelected(false);
}
counter++;
}
checkDisplaySaveButton();
}

View File

@@ -20,7 +20,6 @@
package com.sheepit.client.standalone.swing.activity;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
@@ -31,7 +30,6 @@ import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Objects;
@@ -46,8 +44,6 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import com.sheepit.client.Client;
import com.sheepit.client.Job;
@@ -370,10 +366,8 @@ public class Working implements Activity {
if (this.exitAfterFrame.getText().startsWith("Cancel")) {
Client client = parent.getClient();
if (client != null) {
if (client.isRunning()) {
queueSize++;
}
if (client != null && client.isRunning()) {
queueSize++;
}
exitAfterFrame.setText(String.format("Cancel exit (%s frame%s to go)", queueSize, (queueSize > 1 ? "s" : "")));
@@ -457,64 +451,6 @@ public class Working implements Activity {
}
private void alignPanel(Container parent, int rows, int cols, Spring width) {
SpringLayout layout;
try {
layout = (SpringLayout) parent.getLayout();
}
catch (ClassCastException exc) {
System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
return;
}
Spring x = Spring.constant(0);
for (int c = 0; c < cols; c++) {
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, width);
}
Spring y = Spring.constant(0);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, height);
}
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
private Spring getBestWidth(Container parent, int rows, int cols) {
Spring x = Spring.constant(0);
Spring width = Spring.constant(0);
for (int c = 0; c < cols; c++) {
for (int r = 0; r < rows; r++) {
width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
}
}
return width;
}
private SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}
private int getJobsQueueSize(Client client) {
return client.getUploadQueueSize() + (client.getRenderingJob() != null ? 1 : 0);
}