Replaced all tabs with spaces

This commit is contained in:
Hanz727 2025-11-14 19:36:29 +01:00
commit ee0d2ce427
9 changed files with 247 additions and 247 deletions

View file

@ -31,27 +31,27 @@ import javafx.stage.Stage;
public class Main extends Application {
private static final Injector INJECTOR = createInjector(new MyModule());
private static final MyFXML FXML = new MyFXML(INJECTOR);
private static final Injector INJECTOR = createInjector(new MyModule());
private static final MyFXML FXML = new MyFXML(INJECTOR);
public static void main(String[] args) throws URISyntaxException, IOException {
launch();
}
public static void main(String[] args) throws URISyntaxException, IOException {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
@Override
public void start(Stage primaryStage) throws Exception {
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
if (!serverUtils.isServerAvailable()) {
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
System.err.println(msg);
return;
}
var serverUtils = INJECTOR.getInstance(ServerUtils.class);
if (!serverUtils.isServerAvailable()) {
var msg = "Server needs to be started before the client, but it does not seem to be available. Shutting down.";
System.err.println(msg);
return;
}
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var add = FXML.load(AddQuoteCtrl.class, "client", "scenes", "AddQuote.fxml");
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, add);
}
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, add);
}
}

View file

@ -29,68 +29,68 @@ import javafx.stage.Modality;
public class AddQuoteCtrl {
private final ServerUtils server;
private final MainCtrl mainCtrl;
private final ServerUtils server;
private final MainCtrl mainCtrl;
@FXML
private TextField firstName;
@FXML
private TextField firstName;
@FXML
private TextField lastName;
@FXML
private TextField lastName;
@FXML
private TextField quote;
@FXML
private TextField quote;
@Inject
public AddQuoteCtrl(ServerUtils server, MainCtrl mainCtrl) {
this.mainCtrl = mainCtrl;
this.server = server;
@Inject
public AddQuoteCtrl(ServerUtils server, MainCtrl mainCtrl) {
this.mainCtrl = mainCtrl;
this.server = server;
}
}
public void cancel() {
clearFields();
mainCtrl.showOverview();
}
public void cancel() {
clearFields();
mainCtrl.showOverview();
}
public void ok() {
try {
server.addQuote(getQuote());
} catch (WebApplicationException e) {
public void ok() {
try {
server.addQuote(getQuote());
} catch (WebApplicationException e) {
var alert = new Alert(Alert.AlertType.ERROR);
alert.initModality(Modality.APPLICATION_MODAL);
alert.setContentText(e.getMessage());
alert.showAndWait();
return;
}
var alert = new Alert(Alert.AlertType.ERROR);
alert.initModality(Modality.APPLICATION_MODAL);
alert.setContentText(e.getMessage());
alert.showAndWait();
return;
}
clearFields();
mainCtrl.showOverview();
}
clearFields();
mainCtrl.showOverview();
}
private Quote getQuote() {
var p = new Person(firstName.getText(), lastName.getText());
var q = quote.getText();
return new Quote(p, q);
}
private Quote getQuote() {
var p = new Person(firstName.getText(), lastName.getText());
var q = quote.getText();
return new Quote(p, q);
}
private void clearFields() {
firstName.clear();
lastName.clear();
quote.clear();
}
private void clearFields() {
firstName.clear();
lastName.clear();
quote.clear();
}
public void keyPressed(KeyEvent e) {
switch (e.getCode()) {
case ENTER:
ok();
break;
case ESCAPE:
cancel();
break;
default:
break;
}
}
public void keyPressed(KeyEvent e) {
switch (e.getCode()) {
case ENTER:
ok();
break;
case ESCAPE:
cancel();
break;
default:
break;
}
}
}

View file

@ -35,43 +35,43 @@ import jakarta.ws.rs.core.GenericType;
public class ServerUtils {
private static final String SERVER = "http://localhost:8080/";
private static final String SERVER = "http://localhost:8080/";
public void getQuotesTheHardWay() throws IOException, URISyntaxException {
var url = new URI("http://localhost:8080/api/quotes").toURL();
var is = url.openConnection().getInputStream();
var br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
public void getQuotesTheHardWay() throws IOException, URISyntaxException {
var url = new URI("http://localhost:8080/api/quotes").toURL();
var is = url.openConnection().getInputStream();
var br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
public List<Quote> getQuotes() {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.get(new GenericType<List<Quote>>() {});
}
public List<Quote> getQuotes() {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.get(new GenericType<List<Quote>>() {});
}
public Quote addQuote(Quote quote) {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
}
public Quote addQuote(Quote quote) {
return ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER).path("api/quotes") //
.request(APPLICATION_JSON) //
.post(Entity.entity(quote, APPLICATION_JSON), Quote.class);
}
public boolean isServerAvailable() {
try {
ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER) //
.request(APPLICATION_JSON) //
.get();
} catch (ProcessingException e) {
if (e.getCause() instanceof ConnectException) {
return false;
}
}
return true;
}
public boolean isServerAvailable() {
try {
ClientBuilder.newClient(new ClientConfig()) //
.target(SERVER) //
.request(APPLICATION_JSON) //
.get();
} catch (ProcessingException e) {
if (e.getCause() instanceof ConnectException) {
return false;
}
}
return true;
}
}