Skip to content

Commit

Permalink
Gui input checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-patane committed Apr 10, 2020
1 parent 905e280 commit fa70e1e
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 277 deletions.
11 changes: 5 additions & 6 deletions src/main/java/qubo/InputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inet.ipaddr.IPAddressSeqRange;
import inet.ipaddr.IPAddressString;
import utils.FileUtils;
import utils.InvalidRangeException;
import utils.IpList;
import utils.PortList;

Expand Down Expand Up @@ -84,8 +85,7 @@ private void help(Options options){
System.exit(-1);
}

public InputData(String[] command)
{
public InputData(String[] command) throws InvalidRangeException,NumberFormatException {
Options options = buildOptions();
CommandLineParser parser = new DefaultParser();
String ipStart = "",ipEnd = "";
Expand Down Expand Up @@ -114,8 +114,7 @@ public InputData(String[] command)
}
catch (NullPointerException | IndexOutOfBoundsException e)
{
System.out.println("Invalid IP range.");
System.exit(1);
throw new InvalidRangeException();
}

try
Expand All @@ -128,7 +127,7 @@ public InputData(String[] command)

portrange = new PortList(cmd.getOptionValue("ports"));
ping = !cmd.hasOption("noping");
} catch (ParseException e)
} catch (ParseException e)
{
help(options); //help contiene system.exit
}
Expand Down Expand Up @@ -167,7 +166,7 @@ public IpList getIpList() {
public PortList getPortrange() {
return portrange;
}
public int getThreads() {
public int getThreads() throws NumberFormatException{
return Integer.parseInt(cmd.getOptionValue("th"));
}
public int getTimeout() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/qubo/QuboInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void run()

}

private void checkServersExecutor() throws InterruptedException {
private void checkServersExecutor() throws InterruptedException,NumberFormatException {
ExecutorService checkService = Executors.newFixedThreadPool(inputData.getThreads());
Log.logln("Checking Servers...");

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/qubo/gui/Confirm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package qubo.gui;

import javax.swing.*;

public class Confirm {
public static boolean requestConfirm(String text){
return JOptionPane.showConfirmDialog(null, text) == 0;
}
}
38 changes: 0 additions & 38 deletions src/main/java/qubo/gui/CreditsForm.form

This file was deleted.

161 changes: 0 additions & 161 deletions src/main/java/qubo/gui/CreditsForm.java

This file was deleted.

9 changes: 8 additions & 1 deletion src/main/java/qubo/gui/InstanceRunnable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package qubo.gui;

import qubo.QuboInstance;
import utils.InvalidRangeException;
import utils.Log;

class InstanceRunnable implements Runnable {
Expand All @@ -20,7 +21,13 @@ public InstanceRunnable(QuboInstance quboInstance, MainWindow window){ //window

@Override
public void run() {
quboInstance.run();
try{
quboInstance.run();
}
catch (NumberFormatException e){
if(Confirm.requestConfirm("Check input and relaunch program, would you like to see an example configuration?"))
window.exampleConf();
}
window.idle();
Log.logln("Stopped");
}
Expand Down
Loading

0 comments on commit fa70e1e

Please sign in to comment.