Fix Android Studio warnings in EngineServer module

This commit is contained in:
Peter Osterlund 2019-06-15 02:08:42 +02:00
parent 0ca5a1092d
commit eabe60e65f
3 changed files with 16 additions and 55 deletions

View File

@ -33,7 +33,7 @@ public class EngineServer implements ErrorHandler {
private PortListener[] portListeners; private PortListener[] portListeners;
private MainWindow window; private MainWindow window;
public EngineServer(int numEngines) { private EngineServer(int numEngines) {
configs = new EngineConfig[numEngines]; configs = new EngineConfig[numEngines];
portListeners = new PortListener[numEngines]; portListeners = new PortListener[numEngines];
for (int i = 0; i < numEngines; i++) { for (int i = 0; i < numEngines; i++) {
@ -110,7 +110,7 @@ public class EngineServer implements ErrorHandler {
} }
private static void usage() { private static void usage() {
System.out.printf("Usage: engineServer [-numengines value] [-nogui]\n"); System.out.println("Usage: engineServer [-numengines value] [-nogui]");
System.exit(2); System.exit(2);
} }

View File

@ -22,8 +22,6 @@ import java.awt.Container;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
@ -32,7 +30,6 @@ import java.io.File;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -48,7 +45,6 @@ public class MainWindow {
private JTextField[] port; private JTextField[] port;
private JTextField[] filename; private JTextField[] filename;
private JTextField[] arguments; private JTextField[] arguments;
private JButton[] browse;
private EngineServer server; private EngineServer server;
private EngineConfig[] configs; private EngineConfig[] configs;
@ -56,12 +52,7 @@ public class MainWindow {
public MainWindow(EngineServer server, EngineConfig[] configs) { public MainWindow(EngineServer server, EngineConfig[] configs) {
this.server = server; this.server = server;
this.configs = configs; this.configs = configs;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(this::initUI);
@Override
public void run() {
initUI();
}
});
} }
private void initUI() { private void initUI() {
@ -72,7 +63,6 @@ public class MainWindow {
port = new JTextField[numEngines]; port = new JTextField[numEngines];
filename = new JTextField[numEngines]; filename = new JTextField[numEngines];
arguments = new JTextField[numEngines]; arguments = new JTextField[numEngines];
browse = new JButton[numEngines];
Container pane = frame.getContentPane(); Container pane = frame.getContentPane();
frame.setTitle("Chess Engine Server"); frame.setTitle("Chess Engine Server");
@ -118,12 +108,7 @@ public class MainWindow {
constr.gridy = row; constr.gridy = row;
pane.add(enabled[r], constr); pane.add(enabled[r], constr);
enabled[r].setSelected(config.enabled); enabled[r].setSelected(config.enabled);
enabled[r].addActionListener(new ActionListener() { enabled[r].addActionListener(event -> enabledChanged(engineNo));
@Override
public void actionPerformed(ActionEvent event) {
enabledChanged(engineNo);
}
});
port[r] = new JTextField(); port[r] = new JTextField();
constr = new GridBagConstraints(); constr = new GridBagConstraints();
@ -134,12 +119,7 @@ public class MainWindow {
pane.add(port[r], constr); pane.add(port[r], constr);
port[r].setColumns(5); port[r].setColumns(5);
port[r].setText(Integer.toString(config.port)); port[r].setText(Integer.toString(config.port));
port[r].addActionListener(new ActionListener() { port[r].addActionListener(event -> portChanged(engineNo));
@Override
public void actionPerformed(ActionEvent event) {
portChanged(engineNo);
}
});
port[r].addFocusListener(new FocusAdapter() { port[r].addFocusListener(new FocusAdapter() {
@Override @Override
public void focusLost(FocusEvent event) { public void focusLost(FocusEvent event) {
@ -156,12 +136,7 @@ public class MainWindow {
pane.add(filename[r], constr); pane.add(filename[r], constr);
filename[r].setColumns(40); filename[r].setColumns(40);
filename[r].setText(config.filename); filename[r].setText(config.filename);
filename[r].addActionListener(new ActionListener() { filename[r].addActionListener(event -> filenameChanged(engineNo));
@Override
public void actionPerformed(ActionEvent event) {
filenameChanged(engineNo);
}
});
filename[r].addFocusListener(new FocusAdapter() { filename[r].addFocusListener(new FocusAdapter() {
@Override @Override
public void focusLost(FocusEvent event) { public void focusLost(FocusEvent event) {
@ -178,12 +153,7 @@ public class MainWindow {
pane.add(arguments[r], constr); pane.add(arguments[r], constr);
arguments[r].setColumns(40); arguments[r].setColumns(40);
arguments[r].setText(config.arguments); arguments[r].setText(config.arguments);
arguments[r].addActionListener(new ActionListener() { arguments[r].addActionListener(event -> argumentsChanged(engineNo));
@Override
public void actionPerformed(ActionEvent event) {
argumentsChanged(engineNo);
}
});
arguments[r].addFocusListener(new FocusAdapter() { arguments[r].addFocusListener(new FocusAdapter() {
@Override @Override
public void focusLost(FocusEvent event) { public void focusLost(FocusEvent event) {
@ -191,20 +161,15 @@ public class MainWindow {
} }
}); });
browse[r] = new JButton("Browse"); JButton browse = new JButton("Browse");
constr = new GridBagConstraints(); constr = new GridBagConstraints();
constr.anchor = GridBagConstraints.NORTH; constr.anchor = GridBagConstraints.NORTH;
constr.insets = inset; constr.insets = inset;
constr.gridx = 3; constr.gridx = 3;
constr.gridy = row; constr.gridy = row;
constr.gridheight = 2; constr.gridheight = 2;
pane.add(browse[r], constr); pane.add(browse, constr);
browse[r].addActionListener(new ActionListener() { browse.addActionListener(event -> browseFile(engineNo));
@Override
public void actionPerformed(ActionEvent event) {
browseFile(engineNo);
}
});
row += 2; row += 2;
} }
@ -268,16 +233,12 @@ public class MainWindow {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int lineLen = 100; int lineLen = 100;
while (message.length() > lineLen) { while (message.length() > lineLen) {
sb.append(message.substring(0, lineLen)); sb.append(message, 0, lineLen);
sb.append('\n'); sb.append('\n');
message = message.substring(lineLen); message = message.substring(lineLen);
} }
sb.append(message); sb.append(message);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(frame, sb.toString(), title,
@Override JOptionPane.ERROR_MESSAGE));
public void run() {
JOptionPane.showMessageDialog(frame, sb.toString(), title, JOptionPane.ERROR_MESSAGE);
}
});
} }
} }

View File

@ -90,11 +90,11 @@ public class PortListener {
Thread t1 = forwardIO(proc.getInputStream(), clientSocket.getOutputStream()); Thread t1 = forwardIO(proc.getInputStream(), clientSocket.getOutputStream());
Thread t2 = forwardIO(clientSocket.getInputStream(), proc.getOutputStream()); Thread t2 = forwardIO(clientSocket.getInputStream(), proc.getOutputStream());
try { try {
int exitCode = proc.waitFor(); /* int exitCode = */ proc.waitFor();
if (exitCode != 0) { // if (exitCode != 0) {
// errorHandler.reportError("Engine error", // errorHandler.reportError("Engine error",
// "Engine terminated with status " + exitCode); // "Engine terminated with status " + exitCode);
} // }
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
proc.getOutputStream().close(); proc.getOutputStream().close();
proc.destroyForcibly(); proc.destroyForcibly();