formating and font color part 1
started work on formating and font color *added a textflow instead of the textarea
This commit is contained in:
@ -8,20 +8,17 @@ import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.eclipsesource.json.Json;
|
||||
import com.eclipsesource.json.JsonObject;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
@SuppressWarnings("unused") //TODO
|
||||
public class apiQuery{
|
||||
|
||||
public apiQuery(MainWindowController m, DBController db){
|
||||
@ -32,8 +29,9 @@ public class apiQuery{
|
||||
private MainWindowController mainWindowController;
|
||||
private DBController dbController;
|
||||
private Image im;
|
||||
private int fontSize = 20;
|
||||
private String fontFamily = "System";
|
||||
private String[] responseString = new String[20];
|
||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||
|
||||
void startQuery(String titel, String streamUrl){
|
||||
URL url = null;
|
||||
@ -44,6 +42,11 @@ public class apiQuery{
|
||||
String retdata = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
String fontFamily = mainWindowController.fontFamily;
|
||||
int fontSize = (int) Math.round(mainWindowController.size);
|
||||
|
||||
responseText.removeAll(responseText);
|
||||
nameText.removeAll(nameText);
|
||||
|
||||
try {
|
||||
|
||||
@ -69,158 +72,93 @@ public class apiQuery{
|
||||
is = url.openStream();
|
||||
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
|
||||
// lesen der Daten aus dem Antwort Stream
|
||||
// read data from response Stream
|
||||
while ((retdata = br.readLine()) != null) {
|
||||
//retdata in json object parsen und anschließend das json Objekt "zerschneiden"
|
||||
//cut the json response into separate strings
|
||||
System.out.println(retdata);
|
||||
JsonObject object = Json.parse(retdata).asObject();
|
||||
String titelV = object.getString("Title", "");
|
||||
String yearV = object.getString("Year", "");
|
||||
String ratedV = object.getString("Rated", "");
|
||||
String releasedV = object.getString("Released", "");
|
||||
String runtimeV = object.getString("Runtime", "");
|
||||
String genreV = object.getString("Genre", "");
|
||||
String directorV = object.getString("Director", "");
|
||||
String writerV = object.getString("Writer", "");
|
||||
String actorsV = object.getString("Actors", "");
|
||||
String plotV = object.getString("Plot", "");
|
||||
String languageV = object.getString("Language", "");
|
||||
String countryV = object.getString("Country", "");
|
||||
String awardsV = object.getString("Awards", "");
|
||||
|
||||
String metascoreV = object.getString("Metascore", "");
|
||||
String imdbRatingV = object.getString("imdbRating", "");
|
||||
String imdbVotesV = object.getString("imdbVotes", "");
|
||||
String imdbIDV = object.getString("imdbID", "");
|
||||
String typeV = object.getString("Type", "");
|
||||
|
||||
String posterURL = object.getString("Poster", "");
|
||||
String response = object.getString("Response", "");
|
||||
responseString[0] = object.getString("Title", "");
|
||||
responseString[1] = object.getString("Year", "");
|
||||
responseString[2] = object.getString("Rated", "");
|
||||
responseString[3] = object.getString("Released", "");
|
||||
responseString[4] = object.getString("Runtime", "");
|
||||
responseString[5] = object.getString("Genre", "");
|
||||
responseString[6] = object.getString("Director", "");
|
||||
responseString[7] = object.getString("Writer", "");
|
||||
responseString[8] = object.getString("Actors", "");
|
||||
responseString[9] = object.getString("Plot", "");
|
||||
responseString[10] = object.getString("Language", "");
|
||||
responseString[11] = object.getString("Country", "");
|
||||
responseString[12] = object.getString("Awards", "");
|
||||
responseString[13] = object.getString("Metascore", "");
|
||||
responseString[14] = object.getString("imdbRating", "");
|
||||
responseString[15] = object.getString("Type", "");
|
||||
responseString[16] = object.getString("imdbVotes", "");
|
||||
responseString[17] = object.getString("imdbID", "");
|
||||
responseString[18] = object.getString("Poster", "");
|
||||
responseString[19] = object.getString("Response", "");
|
||||
|
||||
dbController.addCache( streamUrl, titelV, yearV, ratedV, releasedV, runtimeV, genreV, directorV, writerV, actorsV, plotV, languageV, countryV,
|
||||
awardsV, metascoreV, imdbRatingV, imdbVotesV, imdbIDV, typeV, posterURL, response);
|
||||
//adding strings to the cache
|
||||
dbController.addCache( streamUrl, responseString[0], responseString[1],responseString[2], responseString[3], responseString[4], responseString[5],
|
||||
responseString[6], responseString[7], responseString[8], responseString[9], responseString[10],responseString[11], responseString[12],
|
||||
responseString[13], responseString[14], responseString[15], responseString[16], responseString[17], responseString[18],
|
||||
responseString[19]);
|
||||
dbController.setCached(streamUrl);
|
||||
|
||||
|
||||
// Text titelR = new Text (object.getString("Title", "")+"\n");
|
||||
// titelR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text yearR = new Text (object.getString("Year", "")+"\n");
|
||||
// yearR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text ratedR = new Text (object.getString("Rated", "")+"\n");
|
||||
// ratedR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text releasedR = new Text (object.getString("Released", "")+"\n");
|
||||
// releasedR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text runtimeR = new Text (object.getString("Runtime", "")+"\n");
|
||||
// runtimeR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text genreR = new Text (object.getString("Genre", ""));
|
||||
// genreR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text directorR = new Text (object.getString("Director", "")+"\n");
|
||||
// directorR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text writerR = new Text (object.getString("Writer", "")+"\n");
|
||||
// writerR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text actorsR = new Text (object.getString("Actors", "")+"\n");
|
||||
// actorsR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text plotR = new Text (object.getString("Plot", "")+"\n");
|
||||
// plotR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text languageR = new Text (object.getString("Language", "")+"\n");
|
||||
// languageR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text countryR = new Text (object.getString("Country", "")+"\n");
|
||||
// countryR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text awardsR = new Text (object.getString("Awards", "")+"\n");
|
||||
// awardsR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text metascoreR = new Text (object.getString("Metascore", "")+"\n");
|
||||
// metascoreR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text imdbRatingR = new Text (object.getString("imdbRating", "")+"\n");
|
||||
// imdbRatingR.setFont(Font.font (fontFamily, fontSize));
|
||||
// @SuppressWarnings("unused")
|
||||
// Text imdbVotesR = new Text (object.getString("imdbVotes", "")+"\n");
|
||||
// imdbVotesR.setFont(Font.font (fontFamily, fontSize));
|
||||
// @SuppressWarnings("unused")
|
||||
// Text imdbIDR = new Text (object.getString("imdbID", "")+"\n");
|
||||
// imdbIDR.setFont(Font.font (fontFamily, fontSize));
|
||||
// Text typeR = new Text (object.getString("Type", "")+"\n");
|
||||
// typeR.setFont(Font.font (fontFamily, fontSize));
|
||||
for(int i=0; i<20; i++){
|
||||
Text text = new Text(responseString[i]+"\n");
|
||||
responseText.add(text);
|
||||
responseText.get(i).setFont(Font.font(fontFamily, fontSize));
|
||||
}
|
||||
|
||||
|
||||
if(response.equals("False")){
|
||||
mainWindowController.ta1.appendText(mainWindowController.noFilmFound);
|
||||
//if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
|
||||
if(responseString[19].equals("False")){
|
||||
mainWindowController.textFlow.getChildren().add(new Text(mainWindowController.noFilmFound));
|
||||
im = new Image("recources/icons/close_black_2048x2048.png");
|
||||
mainWindowController.image1.setImage(im);
|
||||
}else{
|
||||
//ausgabe des Textes in ta1 in jeweils neuer Zeile
|
||||
mainWindowController.ta1.appendText(mainWindowController.title+": "+titelV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.year+": "+ yearV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.rating+": "+ratedV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.publishedOn+": "+releasedV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.duration+": "+runtimeV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.genre+": "+genreV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.director+": "+directorV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.writer+": "+writerV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.actors+": "+actorsV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.plot+": "+plotV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.language+": "+languageV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.country+": "+countryV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.awards+": "+awardsV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.metascore+": "+metascoreV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.imdbRating+": "+imdbRatingV+"\n");
|
||||
mainWindowController.ta1.appendText(mainWindowController.type+": "+typeV+"\n");
|
||||
//
|
||||
nameText.add(0, new Text(mainWindowController.title+": "));
|
||||
nameText.add(1, new Text(mainWindowController.year+": "));
|
||||
nameText.add(2, new Text(mainWindowController.rating+": "));
|
||||
nameText.add(3, new Text(mainWindowController.publishedOn+": "));
|
||||
nameText.add(4, new Text(mainWindowController.duration+": "));
|
||||
nameText.add(5, new Text(mainWindowController.genre+": "));
|
||||
nameText.add(6, new Text(mainWindowController.director+": "));
|
||||
nameText.add(7, new Text(mainWindowController.writer+": "));
|
||||
nameText.add(8, new Text(mainWindowController.actors+": "));
|
||||
nameText.add(9, new Text(mainWindowController.plot+": "));
|
||||
nameText.add(10, new Text(mainWindowController.language+": "));
|
||||
nameText.add(11, new Text(mainWindowController.country+": "));
|
||||
nameText.add(12, new Text(mainWindowController.awards+": "));
|
||||
nameText.add(13, new Text(mainWindowController.metascore+": "));
|
||||
nameText.add(14, new Text(mainWindowController.imdbRating+": "));
|
||||
nameText.add(15, new Text(mainWindowController.type+": "));
|
||||
|
||||
|
||||
for(int i=0; i<nameText.size(); i++){
|
||||
nameText.get(i).setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
}
|
||||
|
||||
// mainWindowController.ta1.setVisible(false);
|
||||
mainWindowController.textFlow.getChildren().remove(0, mainWindowController.textFlow.getChildren().size());
|
||||
|
||||
// Text title = new Text(15, 20, mainWindowController.title+": ");
|
||||
// title.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text year = new Text(15, 20, mainWindowController.year+": ");
|
||||
// year.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text rating = new Text(15, 20, mainWindowController.rating+": ");
|
||||
// rating.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text publishedOn = new Text(15, 20, mainWindowController.publishedOn+": ");
|
||||
// publishedOn.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text duration = new Text(15, 20, mainWindowController.duration+": ");
|
||||
// duration.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text genre = new Text(15, 20, mainWindowController.genre+": ");
|
||||
// genre.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text director = new Text(15, 20, mainWindowController.director+": ");
|
||||
// director.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text writer = new Text(15, 20, mainWindowController.writer+": ");
|
||||
// writer.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text actors = new Text(15, 20, mainWindowController.actors+": ");
|
||||
// actors.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text plot = new Text(15, 20, mainWindowController.plot+": ");
|
||||
// plot.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text language = new Text(15, 20, mainWindowController.language+": ");
|
||||
// language.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text country = new Text(15, 20, mainWindowController.country+": ");
|
||||
// country.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text awards = new Text(15, 20, mainWindowController.awards+": ");
|
||||
// awards.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text metascore = new Text(15, 20, mainWindowController.metascore+": ");
|
||||
// metascore.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text imdbRating = new Text(15, 20, mainWindowController.imdbRating+": ");
|
||||
// imdbRating.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
// Text type = new Text(15, 20, mainWindowController.type+": ");
|
||||
// type.setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
||||
//
|
||||
// mainWindowController.textFlow.getChildren().remove(0, mainWindowController.textFlow.getChildren().size());
|
||||
//
|
||||
// ObservableList<Node> list = mainWindowController.textFlow.getChildren();
|
||||
//
|
||||
// list.addAll(title,titelR,year,yearR,rating,ratedR,
|
||||
// publishedOn,releasedR,duration,runtimeR,genre,genreR,director,directorR,writer,writerR,
|
||||
// actors,actorsR,plot,plotR,language,languageR,country,countryR,awards,awardsR,metascore,
|
||||
// metascoreR,imdbRating,imdbRatingR,type,typeR);
|
||||
//
|
||||
|
||||
if(posterURL.equals("N/A")){
|
||||
for(int i=0;i<nameText.size(); i++){
|
||||
mainWindowController.textFlow.getChildren().addAll(nameText.get(i),responseText.get(i));
|
||||
}
|
||||
|
||||
//if there is no poster
|
||||
if(responseString[18].equals("N/A")){
|
||||
im = new Image("recources/icons/close_black_2048x2048.png");
|
||||
}else{
|
||||
im = new Image(posterURL);
|
||||
im = new Image(responseString[18]);
|
||||
}
|
||||
mainWindowController.image1.setImage(im);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
mainWindowController.ta1.setText(e.toString());
|
||||
mainWindowController.textFlow.getChildren().add(new Text(e.toString()));
|
||||
System.out.println(e);
|
||||
} finally {
|
||||
//closes datainputStream, InputStream,Scanner if not already done
|
||||
|
Reference in New Issue
Block a user