mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
Delete src directory
This commit is contained in:
1 parent
e501a99559
commit
7396be94c9
43 files changed
-7836
No files matched your search
@@ -1,257 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Almanac extends Thread {
|
||||
Utilities utl = new Utilities();
|
||||
String today;
|
||||
String tomorrow;
|
||||
String todaySunrise;
|
||||
String todaySunset;
|
||||
String tomorrowSunrise;
|
||||
String tomorrowSunset;
|
||||
String todayLow;
|
||||
String todayHigh;
|
||||
String tomorrowHigh;
|
||||
String tomorrowLow;
|
||||
String normalPrecip;
|
||||
String getDay(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String day = JSONResponse.getJSONArray("dayOfWeek").getString(dayNum);
|
||||
|
||||
String[] dayNames = {" SUNDAY ", " MONDAY ", " TUESDAY ", "WEDNESDAY", "THURSDAY ", " FRIDAY ", "SATURDAY "};
|
||||
return switch (day) {
|
||||
case "Sunday" -> dayNames[0];
|
||||
case "Monday" -> dayNames[1];
|
||||
case "Tuesday" -> dayNames[2];
|
||||
case "Wednesday" -> dayNames[3];
|
||||
case "Thursday" -> dayNames[4];
|
||||
case "Friday" -> dayNames[5];
|
||||
case "Saturday" -> dayNames[6];
|
||||
default -> " ";
|
||||
};
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getSunrise(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray("sunriseTimeLocal").getString(dayNum);
|
||||
|
||||
int hour = Integer.parseInt(time.substring(11, 13));
|
||||
int dispHour = hour > 12 ? hour - 12 : hour;
|
||||
String minutes = time.substring(14, 16);
|
||||
String part = hour < 12 ? " AM" : " PM";
|
||||
|
||||
return utl.rjust(dispHour + ":" + minutes + part, 8, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getSunset(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray("sunsetTimeLocal").getString(dayNum);
|
||||
|
||||
int hour = Integer.parseInt(time.substring(11, 13));
|
||||
int dispHour = hour > 12 ? hour - 12 : hour;
|
||||
String minutes = time.substring(14, 16);
|
||||
String part = hour < 12 ? " AM" : " PM";
|
||||
|
||||
return utl.rjust(dispHour + ":" + minutes + part, 8, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getMonth(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "error";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
String getDayDate(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "error";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
String getTempMax(String icaoCode, String key, int dayNum, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
int temp = JSONResponse.getJSONArray("temperatureAverageMax").getInt(dayNum);
|
||||
|
||||
return utl.rjust(temp + " \\F", 6, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getTempMin(String icaoCode, String key, int dayNum, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
int temp = JSONResponse.getJSONArray("temperatureAverageMin").getInt(dayNum);
|
||||
|
||||
return utl.rjust(temp + " \\F", 6, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getPrecip(String icaoCode, String key, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
String[] monthNames = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
float precip = JSONResponse.getJSONArray("precipitationAverage").getFloat(0);
|
||||
|
||||
String precipString = utl.rjust(precip + " IN", 8, " ");
|
||||
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 23, " ");
|
||||
|
||||
return utl.ljust(cmonth + precipString, 31, " ") + " ";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
String mainIcao = Main.mainIcao;
|
||||
String key = Main.key;
|
||||
String todayMonth = Main.todayMonth;
|
||||
String todayDay = Main.todayDay;
|
||||
Main.almanac.today = getDay(mainIcao, key, 0);
|
||||
Main.almanac.tomorrow = getDay(mainIcao, key, 1);
|
||||
Main.almanac.todaySunrise = getSunrise(mainIcao, key, 0);
|
||||
Main.almanac.todaySunset = getSunset(mainIcao, key, 0);
|
||||
Main.almanac.tomorrowSunrise = getSunrise(mainIcao, key, 1);
|
||||
Main.almanac.tomorrowSunset = getSunset(mainIcao, key, 1);
|
||||
Main.almanac.todayHigh = getTempMax(mainIcao, key, 0, todayMonth, todayDay);
|
||||
Main.almanac.todayLow = getTempMin(mainIcao, key, 0, todayMonth, todayDay);
|
||||
Main.almanac.tomorrowHigh = getTempMax(mainIcao, key, 1, todayMonth, todayDay);
|
||||
Main.almanac.tomorrowLow = getTempMin(mainIcao, key, 1, todayMonth, todayDay);
|
||||
Main.almanac.normalPrecip = getPrecip(mainIcao, key, todayMonth, todayDay);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import javazoom.jl.player.Player;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AudioManager extends Thread {
|
||||
private Player player;
|
||||
private List<File> playlist;
|
||||
private volatile boolean finished;
|
||||
|
||||
public AudioManager(String folder) {
|
||||
this.player = null;
|
||||
this.finished = true;
|
||||
|
||||
File musicFolder = new File(folder);
|
||||
|
||||
if (!musicFolder.exists() || !musicFolder.isDirectory()) {
|
||||
System.err.println("\"" + folder + "\" folder not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.playlist = Arrays.asList(musicFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".mp3")));
|
||||
|
||||
for (int i = 0; i < this.playlist.size(); i++) {
|
||||
//System.out.println(getSong(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<File> getPlayList() {
|
||||
return this.playlist;
|
||||
}
|
||||
|
||||
public File getSong(int index) {
|
||||
return this.playlist.get(index);
|
||||
}
|
||||
|
||||
private void playSong(File file) {
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
player = new Player(fis);
|
||||
player.play();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error playing file " + file.getName() + ": " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.finished = true;
|
||||
if (player != null) {
|
||||
player.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void startPlayList() {
|
||||
finished = false;
|
||||
while (!this.finished && playlist != null && !playlist.isEmpty()) {
|
||||
for (int i = 0; i < this.playlist.size(); i++) {
|
||||
if (this.finished) {
|
||||
break;
|
||||
|
||||
}
|
||||
//System.out.println("Playing " + this.playlist.get(i));
|
||||
playSong(this.playlist.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.close();
|
||||
}
|
||||
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
startPlayList();
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
public class Bulletin extends Thread {
|
||||
static Utilities utl = new Utilities();
|
||||
ArrayList<String> bulletinText = new ArrayList<>();
|
||||
//String color;
|
||||
//boolean severe;
|
||||
//boolean crawl;
|
||||
|
||||
public ArrayList<String> getBulletin(String key, String lat, String lon) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
|
||||
JSONObject responseObject = new JSONObject(Response.body());
|
||||
|
||||
for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) {
|
||||
String headline = responseObject.getJSONArray("alerts").getJSONObject(i).getString("eventDescription");
|
||||
|
||||
String detailKey = responseObject.getJSONArray("alerts").getJSONObject(i).getString("detailKey");
|
||||
if (utl.isScroll(headline)) {
|
||||
return eachAlert(detailKey, key);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
|
||||
return words;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> eachAlert(String detailKey, String key) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/alerts/detail?alertId=" + detailKey + "&format=json&language=en-US&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
|
||||
JSONObject ResponseObj = new JSONObject(Response.body());
|
||||
|
||||
String headline = ResponseObj.getJSONObject("alertDetail").getString("eventDescription");
|
||||
|
||||
String alert = ResponseObj.getJSONObject("alertDetail").getJSONArray("texts").getJSONObject(0).getString("description").toUpperCase();
|
||||
|
||||
words.clear();
|
||||
|
||||
words.addAll(Arrays.asList(alert.replace("\n\n", " *newline* ").split("\\s+")));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ArrayList<String> finalWords = new ArrayList<>();
|
||||
|
||||
finalWords.add(headline);
|
||||
|
||||
for (int i = 0; i <= words.size()-1; i++) {
|
||||
if (words.get(i).equals("*newline*")) {
|
||||
if (!sb.isEmpty()) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
int wordlength = words.get(i).length();
|
||||
if (wordlength > 32) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(words.get(i));
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
} else {
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(words.get(i));
|
||||
} else {
|
||||
i--;
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
return finalWords;
|
||||
} catch (Exception e) {
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String key = Main.key;
|
||||
String mainLat = Main.mainLat;
|
||||
String mainLon = Main.mainLon;
|
||||
Main.bulletin.bulletinText = getBulletin(key, mainLat, mainLon);
|
||||
//System.out.println(Main.bulletin.bulletinText);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.joml.*;
|
||||
|
||||
public class Camera {
|
||||
private Matrix4f projectionMatrix, viewMatrix;
|
||||
Vector2f position;
|
||||
|
||||
public Camera(Vector2f position) {
|
||||
this.position = position;
|
||||
this.projectionMatrix = new Matrix4f();
|
||||
this.viewMatrix = new Matrix4f();
|
||||
adjustProjection();
|
||||
}
|
||||
|
||||
public void adjustProjection() {
|
||||
projectionMatrix.identity();
|
||||
projectionMatrix.ortho(0.0f, 720.0f, 480.0f, 0.0f, 0.0f, 100.0f);
|
||||
}
|
||||
|
||||
public Matrix4f getViewMatrix() {
|
||||
Vector3f cameraFront = new Vector3f(0.0f, 0.0f, -1.0f);
|
||||
Vector3f cameraUp = new Vector3f(0.0f, 1.0f, 0.0f);
|
||||
this.viewMatrix.identity();
|
||||
viewMatrix = viewMatrix.lookAt(new Vector3f(position.x, position.y, 20.0f),
|
||||
cameraFront.add(position.x, position.y, 0.0f),
|
||||
cameraUp);
|
||||
return this.viewMatrix;
|
||||
}
|
||||
|
||||
public Matrix4f getProjectionMatrix() {
|
||||
return this.projectionMatrix;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
public abstract class Component {
|
||||
|
||||
public GameObject gameObject = null;
|
||||
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
}
|
||||
@@ -1,338 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
//import java.text.DecimalFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
public class CurrentConditions extends Thread {
|
||||
String locName;
|
||||
String condition;
|
||||
String temperature;
|
||||
String feelsLike;
|
||||
String humidity;
|
||||
String dewPoint;
|
||||
String pressure;
|
||||
String wind;
|
||||
String gusts;
|
||||
String visibility;
|
||||
String ceiling;
|
||||
String precip;
|
||||
static Utilities utl = new Utilities();
|
||||
|
||||
static String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);}
|
||||
static String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
return JSONResponse.getString("wxPhraseLong").toUpperCase();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
static String getTemperature(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String temp = utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
|
||||
|
||||
return "TEMP: " + temp + "\\F";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getFeelsLike(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int feelTemp = JSONResponse.getInt("temperatureFeelsLike");
|
||||
int temp = JSONResponse.getInt("temperature");
|
||||
if (temp == feelTemp) {
|
||||
return " ";
|
||||
} else {
|
||||
if (feelTemp > 65) {
|
||||
return "HEAT INDEX:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
|
||||
} else {
|
||||
return "WIND CHILL:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getHumidity(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String humid = utl.rjust(Integer.toString(JSONResponse.getInt("relativeHumidity")), 3, " ");
|
||||
|
||||
return "HUMIDITY: " + humid + "%";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getDewPoint(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String dewpt = utl.rjust(Integer.toString(JSONResponse.getInt("temperatureDewPoint")), 3, " ");
|
||||
|
||||
return "DEWPOINT:" + dewpt + "\\F";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getPressure(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
//DecimalFormat df = new DecimalFormat("#.##");
|
||||
float pres = JSONResponse.getFloat("pressureAltimeter");
|
||||
String fpres = String.format("%.2f", pres);
|
||||
|
||||
int presCode = JSONResponse.getInt("pressureTendencyCode");
|
||||
String fpresCode = "";
|
||||
if (presCode == 0) {
|
||||
fpresCode = "IN.";
|
||||
} else if (presCode == 1 || presCode == 3) {
|
||||
fpresCode = "R";
|
||||
} else if (presCode == 2 || presCode == 4) {
|
||||
fpresCode = "F";
|
||||
}
|
||||
|
||||
return "BAROMETRIC PRESSURE: " + fpres + " " + fpresCode;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getWind(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int windDir = JSONResponse.getInt("windDirection");
|
||||
int windSpeed = JSONResponse.getInt("windSpeed");
|
||||
|
||||
if (windSpeed == 0) {
|
||||
return "WIND: CALM ";
|
||||
} else {
|
||||
return "WIND: " + utl.degToThreeLetter(windDir) + utl.rjust(Integer.toString(windSpeed), 3, " ") + " MPH";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getGusts(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String gus;
|
||||
gus = JSONResponse.isNull("windGust") ? " " : "GUSTS TO " + utl.rjust(Integer.toString(JSONResponse.getInt("windGust")), 3, " ");
|
||||
|
||||
return gus;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getVisiblity(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String visib = utl.rjust(Integer.toString(JSONResponse.getInt("visibility")) + " MI.", 7, " ");
|
||||
|
||||
return "VISIB: " + visib;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getCeiling(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String ceil = JSONResponse.isNull("cloudCeiling") ? "UNLIMITED" : utl.rjust(JSONResponse.getInt("cloudCeiling") + " FT.", 9, " ");
|
||||
|
||||
return "CEILING:" + ceil;//three length
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getPrecip(String key, String lat, String lon) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v1/geocode/" + lat + "/" + lon + "/observations/current.json?language=en-US&units=e&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
LocalDate cdate = LocalDate.now();
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
try {
|
||||
JSONObject obsObject = JSONResponse.getJSONObject("observation");
|
||||
JSONObject impObj = obsObject.getJSONObject("imperial");
|
||||
String fprecip = String.format("%.2f", impObj.getFloat("precip_mtd"));
|
||||
String prec = utl.rjust(fprecip + " IN", 8, " ");
|
||||
|
||||
return cmonth.name().toUpperCase() + " PRECIPITATION:" + prec;
|
||||
} catch (Exception e) {
|
||||
return " ";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
String mainLocName = Main.mainLocName.getText();
|
||||
String key = Main.key;
|
||||
String mainIcao = Main.mainIcao;
|
||||
String mainLat = Main.mainLat;
|
||||
String mainLon = Main.mainLon;
|
||||
Main.currentConditions.locName = getLocName(mainLocName);
|
||||
Main.currentConditions.condition = getCondition(mainIcao, key);
|
||||
Main.currentConditions.temperature = getTemperature(mainIcao, key);
|
||||
Main.currentConditions.feelsLike = getFeelsLike(mainIcao, key);
|
||||
Main.currentConditions.humidity = getHumidity(mainIcao, key);
|
||||
Main.currentConditions.dewPoint = getDewPoint(mainIcao, key);
|
||||
Main.currentConditions.pressure = getPressure(mainIcao, key);
|
||||
Main.currentConditions.wind = getWind(mainIcao, key);
|
||||
Main.currentConditions.gusts = getGusts(mainIcao, key);
|
||||
Main.currentConditions.visibility = getVisiblity(mainIcao, key);
|
||||
Main.currentConditions.ceiling = getCeiling(mainIcao, key);
|
||||
Main.currentConditions.precip = getPrecip(key, mainLat, mainLon);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
public class DataRunner extends Thread {
|
||||
public void run() {
|
||||
//System.out.println("Data collection");
|
||||
Main.currentConditions = new CurrentConditions();
|
||||
Main.hourlyObservations = new HourlyObservations();
|
||||
Main.regionalConditions = new RegionalConditions();
|
||||
Main.localForecast = new LocalForecast();
|
||||
Main.almanac = new Almanac();
|
||||
Main.regionalForecast = new RegionalForecast();
|
||||
Main.extendedForecast = new ExtendedForecast();
|
||||
Main.outlook = new Outlook();
|
||||
Main.travelForecast = new TravelForecast();
|
||||
Main.bulletin = new Bulletin();
|
||||
|
||||
Main.currentConditions.start();
|
||||
Main.hourlyObservations.start();
|
||||
Main.regionalConditions.start();
|
||||
Main.localForecast.start();
|
||||
Main.almanac.start();
|
||||
Main.regionalForecast.start();
|
||||
Main.extendedForecast.start();
|
||||
Main.outlook.start();
|
||||
Main.travelForecast.start();
|
||||
Main.bulletin.start();
|
||||
|
||||
try {
|
||||
Main.currentConditions.join();
|
||||
Main.hourlyObservations.join();
|
||||
Main.regionalConditions.join();
|
||||
Main.localForecast.join();
|
||||
Main.almanac.join();
|
||||
Main.regionalForecast.join();
|
||||
Main.extendedForecast.join();
|
||||
Main.outlook.join();
|
||||
Main.travelForecast.join();
|
||||
Main.bulletin.join();
|
||||
LoadingScreen.dataFinish = true;
|
||||
SlidesRunner.collectingData = false;
|
||||
//ystem.out.println("data finished, destroying thread");
|
||||
//wr.join();
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
public class ExtendedForecast extends Thread {
|
||||
String dayOne;
|
||||
String dayTwo;
|
||||
String dayThree;
|
||||
ArrayList<String> conditionOne;
|
||||
ArrayList<String> conditionTwo;
|
||||
ArrayList<String> conditionThree;
|
||||
String lowOne;
|
||||
String lowTwo;
|
||||
String lowThree;
|
||||
String highOne;
|
||||
String highTwo;
|
||||
String highThree;
|
||||
Utilities utl = new Utilities();
|
||||
String getDayName(String icaoCode, String key, int day) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
//JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
//JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
//int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : 0;
|
||||
|
||||
return utl.ljust(new JSONObject(ResponseBody).getJSONArray("dayOfWeek").getString(day + 2).toUpperCase(), 10, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
ArrayList<String> getCondition(String icaoCode, String key, int day) {
|
||||
ArrayList<String> values = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
values.add(" ");
|
||||
values.add(" ");
|
||||
return values;
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
|
||||
int ex = day*2;
|
||||
|
||||
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 0));
|
||||
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 1));
|
||||
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
values.add(" ");
|
||||
values.add(" ");
|
||||
return values;
|
||||
}
|
||||
}
|
||||
String getLow(String icaoCode, String key, int day) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
|
||||
int ex = day*2;
|
||||
|
||||
return "LO:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump + 1)), 4, " ") + " ";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getHigh(String icaoCode, String key, int day) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
|
||||
int ex = day*2;
|
||||
|
||||
return "HI:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump)), 4, " ") + " ";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
String key = Main.key;
|
||||
String mainIcao = Main.mainIcao;
|
||||
Main.extendedForecast.dayOne = getDayName(mainIcao, key, 0);
|
||||
Main.extendedForecast.dayTwo = getDayName(mainIcao, key, 1);
|
||||
Main.extendedForecast.dayThree = getDayName(mainIcao, key, 2);
|
||||
Main.extendedForecast.conditionOne = getCondition(mainIcao, key, 0);
|
||||
Main.extendedForecast.conditionTwo = getCondition(mainIcao, key, 1);
|
||||
Main.extendedForecast.conditionThree = getCondition(mainIcao, key, 2);
|
||||
Main.extendedForecast.lowOne = getLow(mainIcao, key, 0);
|
||||
Main.extendedForecast.lowTwo = getLow(mainIcao, key, 1);
|
||||
Main.extendedForecast.lowThree = getLow(mainIcao, key, 2);
|
||||
Main.extendedForecast.highOne = getHigh(mainIcao, key, 0);
|
||||
Main.extendedForecast.highTwo = getHigh(mainIcao, key, 1);
|
||||
Main.extendedForecast.highThree = getHigh(mainIcao, key, 2);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GameObject {
|
||||
private String name;
|
||||
private List<Component> components;
|
||||
public Transform transform;
|
||||
private int zIndex;
|
||||
private boolean visible = true;
|
||||
|
||||
public GameObject(String name) {
|
||||
this.name = name;
|
||||
this.components = new ArrayList<>();
|
||||
this.transform = new Transform();
|
||||
this.zIndex = 0;
|
||||
this.visible = true;
|
||||
}
|
||||
|
||||
public GameObject(String name, Transform transform, int zIndex) {
|
||||
this.name = name;
|
||||
this.zIndex = zIndex;
|
||||
this.components = new ArrayList<>();
|
||||
this.transform = transform;
|
||||
this.visible = true;
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(Class<T> componentClass) {
|
||||
for (Component c : components) {
|
||||
if (componentClass.isAssignableFrom(c.getClass())) {
|
||||
try {
|
||||
return componentClass.cast(c);
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
assert false : "Error casting component";
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends Component> void removeComponent(Class<T> componentClass) {
|
||||
for (int i = 0; i < components.size(); i++) {
|
||||
Component c = components.get(i);
|
||||
if (componentClass.isAssignableFrom(c.getClass())) {
|
||||
components.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addComponent(Component c) {
|
||||
this.components.add(c);
|
||||
c.gameObject = this;
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
for (int i = 0; i < components.size(); i++) {
|
||||
components.get(i).update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
for (int i = 0; i <components.size(); i++) {
|
||||
components.get(i).start();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
public int zIndex() {
|
||||
return this.zIndex;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HourlyObservations extends Thread {
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> temperature = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
ArrayList<String> wind = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
String getLocName(String displayName) {
|
||||
return utl.ljust(displayName, 14, " ").substring(0, 14);
|
||||
}
|
||||
String getTemperature(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
return utl.getCondition(JSONResponse.getInt("iconCodeExtend"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
String getWind(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int windDir = JSONResponse.getInt("windDirection");
|
||||
int windSpeed = JSONResponse.getInt("windSpeed");
|
||||
|
||||
return utl.formatWind(windSpeed, windDir, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
ArrayList<String> nearNames = new ArrayList<>();
|
||||
nearNames.addAll(Main.nearNames);
|
||||
ArrayList<String> nearIcaos = new ArrayList<>();;
|
||||
nearIcaos.addAll(Main.nearIcaos);
|
||||
String key = Main.key;
|
||||
for (int i = 0; i < nearIcaos.size(); i++) {
|
||||
Main.hourlyObservations.locName.add(getLocName(nearNames.get(i)));
|
||||
Main.hourlyObservations.temperature.add(getTemperature(nearIcaos.get(i), key));
|
||||
Main.hourlyObservations.condition.add(getCondition(nearIcaos.get(i), key));
|
||||
Main.hourlyObservations.wind.add(getWind(nearIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
public class KeyListener {
|
||||
private static KeyListener instance;
|
||||
private boolean keyPressed[] = new boolean[350];
|
||||
|
||||
private KeyListener() {
|
||||
|
||||
}
|
||||
|
||||
public static KeyListener get() {
|
||||
if (KeyListener.instance == null) {
|
||||
KeyListener.instance = new KeyListener();
|
||||
}
|
||||
|
||||
return KeyListener.instance;
|
||||
}
|
||||
|
||||
public static void keyCallback(long window, int key, int scancode, int action, int mods) {
|
||||
if (key >= 0 && key <= 350) {
|
||||
if (action == GLFW_PRESS) {
|
||||
get().keyPressed[key] = true;
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
get().keyPressed[key] = false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static boolean isKeyPressed(int keyCode) {
|
||||
if (keyCode >= 0 && keyCode <= 350) {
|
||||
return get().keyPressed[keyCode];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import components.SpriteRenderer;
|
||||
import components.Spritesheet;
|
||||
import util.AssetPool;
|
||||
import util.Utilities;
|
||||
|
||||
public class LoadingScreen extends Scene {
|
||||
Vector4f color1 = new Vector4f(82.0f/255.0f, 80.0f/255.0f, 80.0f/255.0f, 1.0f); //gray
|
||||
Vector4f color2 = new Vector4f(11.0f/255.0f, 104.0f/255.0f, 6.0f/255.0f, 1.0f); //green
|
||||
Vector4f color3 = new Vector4f(61.0f/255.0f, 0.0f/255.0f, 109.0f/255.0f, 1.0f); //purple
|
||||
Vector4f color4 = new Vector4f(104.0f/255.0f, 0.0f/255.0f, 8.0f/255.0f, 1.0f); //red
|
||||
Vector4f color5 = new Vector4f(4.0f/255.0f, 92.0f/255.0f, 82.0f/255.0f, 1.0f); //cyan
|
||||
Vector4f color6 = new Vector4f(46.0f/255.0f, 2.0f/255.0f, 120.0f/255.0f, 1.0f); //blue BG
|
||||
Vector4f color7 = new Vector4f(124.0f/255.0f, 104.0f/255.0f, 6.0f/255.0f, 1.0f); //gold
|
||||
Vector4f color8 = new Vector4f(3.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); //black
|
||||
Vector4f color9 = new Vector4f(106.0f/255.0f, 80.0f/255.0f, 57.0f/255.0f, 1.0f); //brown
|
||||
Vector4f color10 = new Vector4f(116.0f/255.0f, 133.0f/255.0f, 22.0f/255.0f, 1.0f); //yellow
|
||||
Vector4f color11 = new Vector4f(60.0f/255.0f, 0.0f/255.0f, 109.0f/255.0f, 1.0f); //purple (again?)
|
||||
Vector4f color12 = new Vector4f(132.0f/255.0f, 81.0f/255.0f, 74.0f/255.0f, 1.0f); //peach
|
||||
Vector4f color13 = new Vector4f(83.0f/255.0f, 77.0f/255.0f, 1.0f/255.0f, 1.0f); //hazel
|
||||
Vector4f color14 = new Vector4f(9.0f/255.0f, 121.0f/255.0f, 172.0f/255.0f, 1.0f); //light blue
|
||||
Vector4f color15 = new Vector4f(160.0f/255.0f, 78.0f/255.0f, 14.0f/255.0f, 1.0f); //orange
|
||||
Vector4f color16 = new Vector4f(188.0f/255.0f, 190.0f/255.0f, 189.0f/255.0f, 1.0f); //white
|
||||
Vector4f greenScreen = new Vector4f(0.0f/255.0f, 255.0f/255.0f, 0.0f/255.0f, 1.0f);
|
||||
|
||||
Utilities utl = new Utilities();
|
||||
Spritesheet sprites;
|
||||
boolean dataInit = false;
|
||||
static boolean dataFinish = false;
|
||||
|
||||
public LoadingScreen() {
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
System.out.println("start loading screen");
|
||||
|
||||
loadResources();
|
||||
this.camera = new Camera(new Vector2f(0, 0));
|
||||
|
||||
sprites = AssetPool.getSpritesheet("/resources/images/charMap.png");
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
GameObject[] lsPool = new GameObject[256];
|
||||
|
||||
for (int i = 0; i < lsPool.length; i++) {
|
||||
lsPool[i] = new GameObject("ccPool" + i, new Transform(new Vector2f()), 0);
|
||||
lsPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
|
||||
}
|
||||
|
||||
lines.add("LOADING DATA...");
|
||||
lines.add(" ");
|
||||
lines.add("MADE WITH JAVA, LWJGL, OPENGL,");
|
||||
lines.add("AND JLAYER BY JAVAZOOM");
|
||||
lines.add("BROUGHT TO YOU BY");
|
||||
lines.add("JOE MOLINELLI");
|
||||
lines.add("AND MIST WEATHER MEDIA");
|
||||
|
||||
int textX = 81;
|
||||
int textY = 44;
|
||||
int poolIdx = 0;
|
||||
for (int row = 0; row < lines.size(); row++) {
|
||||
int lineHeight = 40;
|
||||
String line = lines.get(row);
|
||||
for (int i = 0; i < line.length(); i ++) {
|
||||
if (poolIdx >= lsPool.length) break;
|
||||
|
||||
char c = line.charAt(i);
|
||||
|
||||
GameObject go = lsPool[poolIdx++];
|
||||
go.transform.position.set(textX, textY);
|
||||
go.transform.scale.set(18, 32);
|
||||
|
||||
SpriteRenderer sr = go.getComponent(SpriteRenderer.class);
|
||||
sr.setSprite(sprites.getSprite(utl.getMainChar(c)));
|
||||
|
||||
this.addGameObjectToScene(go);
|
||||
|
||||
if (i % 2 != 0) textX++;
|
||||
textX += 17;
|
||||
}
|
||||
|
||||
textX = 81;
|
||||
textY += lineHeight;
|
||||
}
|
||||
}
|
||||
private void loadResources() {
|
||||
AssetPool.getShader("/resources/shaders/default.glsl");
|
||||
AssetPool.addSpritesheet("/resources/images/charMap.png", new Spritesheet(AssetPool.getTexture("/resources/images/charMap.png"),32, 32, 128, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
if (!dataInit) {
|
||||
dataInit = true;
|
||||
DataRunner data = new DataRunner();
|
||||
data.start();
|
||||
}
|
||||
|
||||
for (GameObject go : this.gameObjects) {
|
||||
go.update(dt);
|
||||
}
|
||||
|
||||
this.renderer.render();
|
||||
if (dataFinish) {
|
||||
Window.finishInit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LocalForecast extends Thread {
|
||||
ArrayList<String> bulletin = new ArrayList<>();
|
||||
ArrayList<String> forecastOne = new ArrayList<>();
|
||||
ArrayList<String> forecastTwo = new ArrayList<>();
|
||||
ArrayList<String> forecastThree = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
ArrayList<String> getForecast(String icaoCode, String key, int forecastId) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
words.add("NO REPORT");
|
||||
return words;
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : 0;
|
||||
String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", JSONResponse.getJSONArray("dayOfWeek").getString(bump)).toUpperCase() +
|
||||
"..." +
|
||||
dpData.getJSONArray("narrative").getString(forecastId + bump).toUpperCase();
|
||||
String[] splitwords = fullText.split("\\s+");
|
||||
|
||||
words.addAll(Arrays.asList(splitwords));
|
||||
|
||||
return words;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("NO REPORT");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<String> getBulletin(String key, String lat, String lon) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
words.add("NOBULLETIN");
|
||||
return words;
|
||||
}
|
||||
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONArray alertData = JSONResponse.getJSONArray("alerts");
|
||||
StringBuilder fullText = new StringBuilder();
|
||||
|
||||
fullText.setLength(0);
|
||||
|
||||
for (int i = 0; i < alertData.length(); i++) {
|
||||
if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) {
|
||||
if (!fullText.isEmpty()) {fullText.append(" *NEWLINE* ");}
|
||||
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
words.clear();
|
||||
|
||||
if (!fullText.isEmpty()) {
|
||||
String[] splitwords = fullText.toString().split("\\s+");
|
||||
|
||||
words.addAll(Arrays.asList(splitwords));
|
||||
} else {
|
||||
words.add("NOBULLETIN");
|
||||
}
|
||||
|
||||
return words;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("NOBULLETIN");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
String mainIcao = Main.mainIcao;
|
||||
String key = Main.key;
|
||||
String mainLat = Main.mainLat;
|
||||
String mainLon = Main.mainLon;
|
||||
Main.localForecast.bulletin = getBulletin(key, mainLat, mainLon);
|
||||
Main.localForecast.forecastOne = getForecast(mainIcao, key, 0);
|
||||
Main.localForecast.forecastTwo = getForecast(mainIcao, key, 1);
|
||||
Main.localForecast.forecastThree = getForecast(mainIcao, key, 2);
|
||||
}
|
||||
}
|
||||
@@ -1,883 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Scanner;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class Main {
|
||||
static String selectedFlavor;
|
||||
static ArrayList<String> ldlList = new ArrayList<>(Arrays.asList("cityname", "condition", "temperature", "humidity", "pressure", "wind", "visibility", "precip"));
|
||||
static boolean settingsErrorThrown = false;
|
||||
static ArrayList<String> settingsErrorReasons = new ArrayList<>();
|
||||
static String popupErrors = "";
|
||||
static boolean loopSlides = false;
|
||||
static boolean greenScreen = false;
|
||||
static String key;
|
||||
static String mainIcao;
|
||||
static String mainLon;
|
||||
static String mainLat;
|
||||
static String todayMonth;
|
||||
static String todayDay;
|
||||
static int simWidth;
|
||||
static int simHeight;
|
||||
static boolean fullscreen = false;
|
||||
// static String mainName;
|
||||
static DataRunner dr;
|
||||
static CurrentConditions currentConditions;
|
||||
static HourlyObservations hourlyObservations;
|
||||
static RegionalConditions regionalConditions;
|
||||
static LocalForecast localForecast;
|
||||
static Almanac almanac;
|
||||
static RegionalForecast regionalForecast;
|
||||
static ExtendedForecast extendedForecast;
|
||||
static Outlook outlook;
|
||||
static TravelForecast travelForecast;
|
||||
static Bulletin bulletin;
|
||||
|
||||
static ArrayList<String> nearNames = new ArrayList<>();
|
||||
static ArrayList<String> nearIcaos = new ArrayList<>();
|
||||
static ArrayList<String> regConNames = new ArrayList<>();
|
||||
static ArrayList<String> regConIcaos = new ArrayList<>();
|
||||
static ArrayList<String> regForNames = new ArrayList<>();
|
||||
static ArrayList<String> regForIcaos = new ArrayList<>();
|
||||
static JFrame settingsWindow;
|
||||
|
||||
static String adCrawl;
|
||||
|
||||
static String jarFolder = "";
|
||||
|
||||
static JTextField mainLocName;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//stuff to add:
|
||||
//no report mode
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.4.0");
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
if (userDir != null && !userDir.isEmpty()) {
|
||||
jarFolder = userDir;
|
||||
} else {
|
||||
// Definitive filesystem fallback if the OS environment fails to report
|
||||
jarFolder = new File(".").getAbsolutePath();
|
||||
}
|
||||
|
||||
settingsWindow = new JFrame("WeatherSTAR 3000 Settings");
|
||||
settingsWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
settingsWindow.setSize(540, 350);
|
||||
settingsWindow.setLocationRelativeTo(null);
|
||||
settingsWindow.setResizable(false);
|
||||
|
||||
ImageIcon sfIcon = new ImageIcon(Main.class.getResource("/resources/images/icon.png"));
|
||||
settingsWindow.setIconImage(sfIcon.getImage());
|
||||
|
||||
JPanel settingsFrame = new JPanel();
|
||||
settingsFrame.setPreferredSize(new Dimension(540, 840));
|
||||
settingsFrame.setLayout(new FlowLayout(FlowLayout.LEADING));
|
||||
|
||||
// read
|
||||
File loadDataFile = new File(jarFolder + File.separator + "loadData.txt");
|
||||
ArrayList<String> loadDataLines = new ArrayList<>();
|
||||
|
||||
// info
|
||||
settingsFrame.add(new JLabel("***Maximum location name length: 14 characters, 19 for Regional Con***"));// 19
|
||||
// if
|
||||
// regional
|
||||
// conditions
|
||||
|
||||
// api key
|
||||
settingsFrame.add(new JLabel("api,weather.com IBM api key"));
|
||||
JTextField apiKeyText = new JTextField(20);
|
||||
settingsFrame.add(apiKeyText);
|
||||
|
||||
// main location
|
||||
settingsFrame.add(new JLabel("Main Location ICAO Code and Name"));
|
||||
JTextField mainLocIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(mainLocIcaoCode);
|
||||
mainLocName = new JTextField(14);
|
||||
settingsFrame.add(mainLocName);
|
||||
|
||||
// spacer
|
||||
JPanel firstSpacer = new JPanel();
|
||||
firstSpacer.setPreferredSize(new Dimension(480, 10));
|
||||
settingsFrame.add(firstSpacer);
|
||||
|
||||
// nearby locations
|
||||
settingsFrame.add(new JLabel("Nearby Location One ICAO Code and Name"));
|
||||
JTextField nearLocOneIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocOneIcaoCode);
|
||||
JTextField nearLocOneName = new JTextField(14);
|
||||
settingsFrame.add(nearLocOneName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Two ICAO Code and Name"));
|
||||
JTextField nearLocTwoIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocTwoIcaoCode);
|
||||
JTextField nearLocTwoName = new JTextField(14);
|
||||
settingsFrame.add(nearLocTwoName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Three ICAO Code and Name"));
|
||||
JTextField nearLocThreeIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocThreeIcaoCode);
|
||||
JTextField nearLocThreeName = new JTextField(14);
|
||||
settingsFrame.add(nearLocThreeName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Four ICAO Code and Name"));
|
||||
JTextField nearLocFourIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocFourIcaoCode);
|
||||
JTextField nearLocFourName = new JTextField(14);
|
||||
settingsFrame.add(nearLocFourName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Five ICAO Code and Name"));
|
||||
JTextField nearLocFiveIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocFiveIcaoCode);
|
||||
JTextField nearLocFiveName = new JTextField(14);
|
||||
settingsFrame.add(nearLocFiveName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Six ICAO Code and Name"));
|
||||
JTextField nearLocSixIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocSixIcaoCode);
|
||||
JTextField nearLocSixName = new JTextField(14);
|
||||
settingsFrame.add(nearLocSixName);
|
||||
|
||||
settingsFrame.add(new JLabel("Nearby Location Seven ICAO Code and Name"));
|
||||
JTextField nearLocSevenIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(nearLocSevenIcaoCode);
|
||||
JTextField nearLocSevenName = new JTextField(14);
|
||||
settingsFrame.add(nearLocSevenName);
|
||||
|
||||
// spacer
|
||||
JPanel secondSpacer = new JPanel();
|
||||
secondSpacer.setPreferredSize(new Dimension(480, 10));
|
||||
settingsFrame.add(secondSpacer);
|
||||
|
||||
// nearby locations
|
||||
settingsFrame.add(new JLabel("Regional Conditions One ICAO Code and Name"));
|
||||
JTextField regConOneIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConOneIcaoCode);
|
||||
JTextField regConOneName = new JTextField(14);
|
||||
settingsFrame.add(regConOneName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Two ICAO Code and Name"));
|
||||
JTextField regConTwoIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConTwoIcaoCode);
|
||||
JTextField regConTwoName = new JTextField(14);
|
||||
settingsFrame.add(regConTwoName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Three ICAO Code and Name"));
|
||||
JTextField regConThreeIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConThreeIcaoCode);
|
||||
JTextField regConThreeName = new JTextField(14);
|
||||
settingsFrame.add(regConThreeName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Four ICAO Code and Name"));
|
||||
JTextField regConFourIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConFourIcaoCode);
|
||||
JTextField regConFourName = new JTextField(14);
|
||||
settingsFrame.add(regConFourName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Five ICAO Code and Name"));
|
||||
JTextField regConFiveIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConFiveIcaoCode);
|
||||
JTextField regConFiveName = new JTextField(14);
|
||||
settingsFrame.add(regConFiveName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Six ICAO Code and Name"));
|
||||
JTextField regConSixIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConSixIcaoCode);
|
||||
JTextField regConSixName = new JTextField(14);
|
||||
settingsFrame.add(regConSixName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Conditions Seven ICAO Code and Name"));
|
||||
JTextField regConSevenIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regConSevenIcaoCode);
|
||||
JTextField regConSevenName = new JTextField(14);
|
||||
settingsFrame.add(regConSevenName);
|
||||
|
||||
// spacer
|
||||
JPanel thirdSpacer = new JPanel();
|
||||
thirdSpacer.setPreferredSize(new Dimension(480, 10));
|
||||
settingsFrame.add(thirdSpacer);
|
||||
|
||||
// nearby locations
|
||||
settingsFrame.add(new JLabel("Regional Forecast One ICAO Code and Name"));
|
||||
JTextField regForOneIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForOneIcaoCode);
|
||||
JTextField regForOneName = new JTextField(14);
|
||||
settingsFrame.add(regForOneName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Two ICAO Code and Name"));
|
||||
JTextField regForTwoIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForTwoIcaoCode);
|
||||
JTextField regForTwoName = new JTextField(14);
|
||||
settingsFrame.add(regForTwoName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Three ICAO Code and Name"));
|
||||
JTextField regForThreeIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForThreeIcaoCode);
|
||||
JTextField regForThreeName = new JTextField(14);
|
||||
settingsFrame.add(regForThreeName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Four ICAO Code and Name"));
|
||||
JTextField regForFourIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForFourIcaoCode);
|
||||
JTextField regForFourName = new JTextField(14);
|
||||
settingsFrame.add(regForFourName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Five ICAO Code and Name"));
|
||||
JTextField regForFiveIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForFiveIcaoCode);
|
||||
JTextField regForFiveName = new JTextField(14);
|
||||
settingsFrame.add(regForFiveName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Six ICAO Code and Name"));
|
||||
JTextField regForSixIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForSixIcaoCode);
|
||||
JTextField regForSixName = new JTextField(14);
|
||||
settingsFrame.add(regForSixName);
|
||||
|
||||
settingsFrame.add(new JLabel("Regional Forecast Seven ICAO Code and Name"));
|
||||
JTextField regForSevenIcaoCode = new JTextField(4);
|
||||
settingsFrame.add(regForSevenIcaoCode);
|
||||
JTextField regForSevenName = new JTextField(14);
|
||||
settingsFrame.add(regForSevenName);
|
||||
|
||||
JPanel aSpacer = new JPanel();
|
||||
aSpacer.setPreferredSize(new Dimension(500, 10));
|
||||
settingsFrame.add(aSpacer);
|
||||
|
||||
settingsFrame.add(new JLabel("Ad crawl message"));
|
||||
JTextField adCrawlInput = new JTextField(32);
|
||||
settingsFrame.add(adCrawlInput);
|
||||
|
||||
// spacer
|
||||
JPanel fourthSpacer = new JPanel();
|
||||
fourthSpacer.setPreferredSize(new Dimension(500, 10));
|
||||
settingsFrame.add(fourthSpacer);
|
||||
|
||||
settingsFrame.add(new JLabel("Width"));
|
||||
JTextField widthField = new JTextField(3);
|
||||
settingsFrame.add(widthField);
|
||||
widthField.setText("720");
|
||||
settingsFrame.add(new JLabel("Height"));
|
||||
JTextField heightField = new JTextField(3);
|
||||
heightField.setText("480");
|
||||
settingsFrame.add(heightField);
|
||||
|
||||
settingsFrame.add(new JLabel("Flavor"));
|
||||
String[] flavorOptions = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"};
|
||||
JComboBox flavorDropdown = new JComboBox(flavorOptions);
|
||||
flavorDropdown.setSelectedIndex(0);
|
||||
settingsFrame.add(flavorDropdown);
|
||||
|
||||
settingsFrame.add(new JLabel("LDL Options"));
|
||||
String[] ldlOptions = {"Observations", "Ad Crawl", "Both"};
|
||||
JComboBox ldlDropdown = new JComboBox(ldlOptions);
|
||||
ldlDropdown.setSelectedIndex(0);
|
||||
settingsFrame.add(ldlDropdown);
|
||||
|
||||
JPanel fifthSpacer = new JPanel();
|
||||
fifthSpacer.setPreferredSize(new Dimension(500, 10));
|
||||
settingsFrame.add(fifthSpacer);
|
||||
|
||||
JCheckBox loopCheck = new JCheckBox("Loop");
|
||||
settingsFrame.add(loopCheck);
|
||||
|
||||
JCheckBox gsCheck = new JCheckBox("Green Screen");
|
||||
settingsFrame.add(gsCheck);
|
||||
|
||||
JCheckBox fsCheck = new JCheckBox("Fullscreen");
|
||||
settingsFrame.add(fsCheck);
|
||||
|
||||
JPanel sixthSpacer = new JPanel();
|
||||
sixthSpacer.setPreferredSize(new Dimension(500, 10));
|
||||
settingsFrame.add(sixthSpacer);
|
||||
|
||||
JButton doneButton = new JButton("Run");
|
||||
settingsFrame.add(doneButton);
|
||||
|
||||
JButton saveButton = new JButton("Save Config");
|
||||
settingsFrame.add(saveButton);
|
||||
|
||||
JButton loadButton = new JButton("Load Config");
|
||||
settingsFrame.add(loadButton);
|
||||
|
||||
try (Scanner myReader = new Scanner(loadDataFile)) {
|
||||
while (myReader.hasNextLine()) {
|
||||
loadDataLines.add(myReader.nextLine());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
JOptionPane.showMessageDialog(settingsFrame, "Unable to read previous data.");
|
||||
}
|
||||
apiKeyText.setText(loadDataLines.get(0));
|
||||
mainLocIcaoCode.setText(loadDataLines.get(1));
|
||||
mainLocName.setText(loadDataLines.get(2));
|
||||
nearLocOneIcaoCode.setText(loadDataLines.get(3));
|
||||
nearLocOneName.setText(loadDataLines.get(4));
|
||||
nearLocTwoIcaoCode.setText(loadDataLines.get(5));
|
||||
nearLocTwoName.setText(loadDataLines.get(6));
|
||||
nearLocThreeIcaoCode.setText(loadDataLines.get(7));
|
||||
nearLocThreeName.setText(loadDataLines.get(8));
|
||||
nearLocFourIcaoCode.setText(loadDataLines.get(9));
|
||||
nearLocFourName.setText(loadDataLines.get(10));
|
||||
nearLocFiveIcaoCode.setText(loadDataLines.get(11));
|
||||
nearLocFiveName.setText(loadDataLines.get(12));
|
||||
nearLocSixIcaoCode.setText(loadDataLines.get(13));
|
||||
nearLocSixName.setText(loadDataLines.get(14));
|
||||
nearLocSevenIcaoCode.setText(loadDataLines.get(15));
|
||||
nearLocSevenName.setText(loadDataLines.get(16));
|
||||
regConOneIcaoCode.setText(loadDataLines.get(17));
|
||||
regConOneName.setText(loadDataLines.get(18));
|
||||
regConTwoIcaoCode.setText(loadDataLines.get(19));
|
||||
regConTwoName.setText(loadDataLines.get(20));
|
||||
regConThreeIcaoCode.setText(loadDataLines.get(21));
|
||||
regConThreeName.setText(loadDataLines.get(22));
|
||||
regConFourIcaoCode.setText(loadDataLines.get(23));
|
||||
regConFourName.setText(loadDataLines.get(24));
|
||||
regConFiveIcaoCode.setText(loadDataLines.get(25));
|
||||
regConFiveName.setText(loadDataLines.get(26));
|
||||
regConSixIcaoCode.setText(loadDataLines.get(27));
|
||||
regConSixName.setText(loadDataLines.get(28));
|
||||
regConSevenIcaoCode.setText(loadDataLines.get(29));
|
||||
regConSevenName.setText(loadDataLines.get(30));
|
||||
regForOneIcaoCode.setText(loadDataLines.get(31));
|
||||
regForOneName.setText(loadDataLines.get(32));
|
||||
regForTwoIcaoCode.setText(loadDataLines.get(33));
|
||||
regForTwoName.setText(loadDataLines.get(34));
|
||||
regForThreeIcaoCode.setText(loadDataLines.get(35));
|
||||
regForThreeName.setText(loadDataLines.get(36));
|
||||
regForFourIcaoCode.setText(loadDataLines.get(37));
|
||||
regForFourName.setText(loadDataLines.get(38));
|
||||
regForFiveIcaoCode.setText(loadDataLines.get(39));
|
||||
regForFiveName.setText(loadDataLines.get(40));
|
||||
regForSixIcaoCode.setText(loadDataLines.get(41));
|
||||
regForSixName.setText(loadDataLines.get(42));
|
||||
regForSevenIcaoCode.setText(loadDataLines.get(43));
|
||||
regForSevenName.setText(loadDataLines.get(44));
|
||||
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setDialogTitle("Select a directory to save you config");
|
||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
|
||||
int result = chooser.showOpenDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFolder = chooser.getSelectedFile();
|
||||
|
||||
String fileName = JOptionPane.showInputDialog(null, "Name the config file?");
|
||||
|
||||
// 3. Create the JSON content
|
||||
String jsonContent = String.format(
|
||||
"{\"starSettings\": {"
|
||||
|
||||
+ "\"api_key\": \"" + apiKeyText.getText() + "\","
|
||||
+ "\"mainLocation\": {"
|
||||
+ "\"icaoCode\": \"" + mainLocIcaoCode.getText() + "\","
|
||||
+ "\"locName\": \"" + mainLocName.getText() + "\","
|
||||
+ "},"
|
||||
+ "\"nearbyLocations\": ["
|
||||
+ "{\"icaoCode\": \"" + nearLocOneIcaoCode.getText() + "\", \"locName\": \"" + nearLocOneName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocTwoIcaoCode.getText() + "\", \"locName\": \"" + nearLocTwoName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocThreeIcaoCode.getText() + "\", \"locName\": \"" + nearLocThreeName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocFourIcaoCode.getText() + "\", \"locName\": \"" + nearLocFourName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocFiveIcaoCode.getText() + "\", \"locName\": \"" + nearLocFiveName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocSixIcaoCode.getText() + "\", \"locName\": \"" + nearLocSixName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + nearLocSevenIcaoCode.getText() + "\", \"locName\": \"" + nearLocSevenName.getText() + "\"},"
|
||||
+ "],"
|
||||
+ "\"regionalForecastLocations\": ["
|
||||
+ "{\"icaoCode\": \"" + regForOneIcaoCode.getText() + "\", \"locName\": \"" + regForOneName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForTwoIcaoCode.getText() + "\", \"locName\": \"" + regForTwoName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForThreeIcaoCode.getText() + "\", \"locName\": \"" + regForThreeName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForFourIcaoCode.getText() + "\", \"locName\": \"" + regForFourName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForFiveIcaoCode.getText() + "\", \"locName\": \"" + regForFiveName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForSixIcaoCode.getText() + "\", \"locName\": \"" + regForSixName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regForSevenIcaoCode.getText() + "\", \"locName\": \"" + regForSevenName.getText() + "\"},"
|
||||
+ "],"
|
||||
+ "\"regionalConditionsLocations\": ["
|
||||
+ "{\"icaoCode\": \"" + regConOneIcaoCode.getText() + "\", \"locName\": \"" + regConOneName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConTwoIcaoCode.getText() + "\", \"locName\": \"" + regConTwoName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConThreeIcaoCode.getText() + "\", \"locName\": \"" + regConThreeName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConFourIcaoCode.getText() + "\", \"locName\": \"" + regConFourName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConFiveIcaoCode.getText() + "\", \"locName\": \"" + regConFiveName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConSixIcaoCode.getText() + "\", \"locName\": \"" + regConSixName.getText() + "\"},"
|
||||
+ "{\"icaoCode\": \"" + regConSevenIcaoCode.getText() + "\", \"locName\": \"" + regConSevenName.getText() + "\"},"
|
||||
+ "],"
|
||||
+ "}}"
|
||||
);
|
||||
|
||||
// 4. Save to the folder
|
||||
if (fileName != null && !fileName.trim().isEmpty()) {
|
||||
if (!fileName.endsWith(".json")) fileName += ".json";
|
||||
} else {
|
||||
fileName = "myConfig.json";
|
||||
}
|
||||
File fileToSave = new File(selectedFolder, fileName);
|
||||
try (FileWriter writer = new FileWriter(fileToSave)) {
|
||||
writer.write(jsonContent);
|
||||
JOptionPane.showMessageDialog(null, "Saved to: " + fileToSave.getAbsolutePath());
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
JOptionPane.showMessageDialog(settingsFrame, "Error saving config file.");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
loadButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser openFile = new JFileChooser();
|
||||
int returnval = openFile.showOpenDialog(null);
|
||||
File loadedFile = openFile.getSelectedFile();
|
||||
Path filePath;
|
||||
String absFilePath;
|
||||
String loadedExtension;
|
||||
if (returnval == JFileChooser.APPROVE_OPTION) {
|
||||
filePath = Paths.get(loadedFile.getAbsolutePath());
|
||||
absFilePath = loadedFile.getAbsolutePath();
|
||||
try {
|
||||
loadedExtension = Files.probeContentType(filePath);
|
||||
} catch (IOException ex) {
|
||||
loadedExtension = "error";
|
||||
}
|
||||
if (!loadedExtension.equals("application/json")) {
|
||||
JOptionPane.showMessageDialog(settingsFrame, "Please choose a json file.");
|
||||
} else {
|
||||
StringBuilder jsonText = new StringBuilder();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(absFilePath));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
jsonText.append(line).append("\n");
|
||||
}
|
||||
br.close();
|
||||
JSONObject settingsObj = new JSONObject(jsonText.toString()).getJSONObject("starSettings");
|
||||
// api key
|
||||
apiKeyText.setText(settingsObj.getString("api_key"));
|
||||
|
||||
// main location
|
||||
mainLocIcaoCode.setText(settingsObj.getJSONObject("mainLocation").getString("icaoCode"));
|
||||
mainLocName.setText(settingsObj.getJSONObject("mainLocation").getString("locName"));
|
||||
|
||||
// nearby cities
|
||||
nearLocOneIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(0).getString("icaoCode"));
|
||||
nearLocOneName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(0).getString("locName"));
|
||||
nearLocTwoIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(1).getString("icaoCode"));
|
||||
nearLocTwoName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(1).getString("locName"));
|
||||
nearLocThreeIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(2).getString("icaoCode"));
|
||||
nearLocThreeName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(2).getString("locName"));
|
||||
nearLocFourIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(3).getString("icaoCode"));
|
||||
nearLocFourName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(3).getString("locName"));
|
||||
nearLocFiveIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(4).getString("icaoCode"));
|
||||
nearLocFiveName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(4).getString("locName"));
|
||||
nearLocSixIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(5).getString("icaoCode"));
|
||||
nearLocSixName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(5).getString("locName"));
|
||||
nearLocSevenIcaoCode.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(6).getString("icaoCode"));
|
||||
nearLocSevenName.setText(
|
||||
settingsObj.getJSONArray("nearbyLocations").getJSONObject(6).getString("locName"));
|
||||
|
||||
// regional conditions
|
||||
regConOneIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(0).getString("icaoCode"));
|
||||
regConOneName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(0).getString("locName"));
|
||||
regConTwoIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(1).getString("icaoCode"));
|
||||
regConTwoName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(1).getString("locName"));
|
||||
regConThreeIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(2).getString("icaoCode"));
|
||||
regConThreeName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(2).getString("locName"));
|
||||
regConFourIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(3).getString("icaoCode"));
|
||||
regConFourName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(3).getString("locName"));
|
||||
regConFiveIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(4).getString("icaoCode"));
|
||||
regConFiveName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(4).getString("locName"));
|
||||
regConSixIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(5).getString("icaoCode"));
|
||||
regConSixName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(5).getString("locName"));
|
||||
regConSevenIcaoCode.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(6).getString("icaoCode"));
|
||||
regConSevenName.setText(settingsObj.getJSONArray("regionalConditionsLocations")
|
||||
.getJSONObject(6).getString("locName"));
|
||||
|
||||
// regional forecast
|
||||
regForOneIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(0).getString("icaoCode"));
|
||||
regForOneName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(0)
|
||||
.getString("locName"));
|
||||
regForTwoIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(1).getString("icaoCode"));
|
||||
regForTwoName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(1)
|
||||
.getString("locName"));
|
||||
regForThreeIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(2).getString("icaoCode"));
|
||||
regForThreeName.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(2).getString("locName"));
|
||||
regForFourIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(3).getString("icaoCode"));
|
||||
regForFourName.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(3).getString("locName"));
|
||||
regForFiveIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(4).getString("icaoCode"));
|
||||
regForFiveName.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(4).getString("locName"));
|
||||
regForSixIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(5).getString("icaoCode"));
|
||||
regForSixName.setText(settingsObj.getJSONArray("regionalForecastLocations").getJSONObject(5)
|
||||
.getString("locName"));
|
||||
regForSevenIcaoCode.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(6).getString("icaoCode"));
|
||||
regForSevenName.setText(settingsObj.getJSONArray("regionalForecastLocations")
|
||||
.getJSONObject(6).getString("locName"));
|
||||
|
||||
// after all of that, change the base config json that loads on start
|
||||
String dataFilePath = jarFolder + File.separator + "loadData.txt";
|
||||
String content = apiKeyText.getText() + "\n" + mainLocIcaoCode.getText() + "\n"
|
||||
+ mainLocName.getText() + "\n" + nearLocOneIcaoCode.getText() + "\n"
|
||||
+ nearLocOneName.getText() + "\n" + nearLocTwoIcaoCode.getText() + "\n"
|
||||
+ nearLocTwoName.getText() + "\n" + nearLocThreeIcaoCode.getText() + "\n"
|
||||
+ nearLocThreeName.getText() + "\n" + nearLocFourIcaoCode.getText() + "\n"
|
||||
+ nearLocFourName.getText() + "\n" + nearLocFiveIcaoCode.getText() + "\n"
|
||||
+ nearLocFiveName.getText() + "\n" + nearLocSixIcaoCode.getText() + "\n"
|
||||
+ nearLocSixName.getText() + "\n" + nearLocSevenIcaoCode.getText() + "\n"
|
||||
+ nearLocSevenName.getText() + "\n" + regConOneIcaoCode.getText() + "\n"
|
||||
+ regConOneName.getText() + "\n" + regConTwoIcaoCode.getText() + "\n"
|
||||
+ regConTwoName.getText() + "\n" + regConThreeIcaoCode.getText() + "\n"
|
||||
+ regConThreeName.getText() + "\n" + regConFourIcaoCode.getText() + "\n"
|
||||
+ regConFourName.getText() + "\n" + regConFiveIcaoCode.getText() + "\n"
|
||||
+ regConFiveName.getText() + "\n" + regConSixIcaoCode.getText() + "\n"
|
||||
+ regConSixName.getText() + "\n" + regConSevenIcaoCode.getText() + "\n"
|
||||
+ regConSevenName.getText() + "\n" + regForOneIcaoCode.getText() + "\n"
|
||||
+ regForOneName.getText() + "\n" + regForTwoIcaoCode.getText() + "\n"
|
||||
+ regForTwoName.getText() + "\n" + regForThreeIcaoCode.getText() + "\n"
|
||||
+ regForThreeName.getText() + "\n" + regForFourIcaoCode.getText() + "\n"
|
||||
+ regForFourName.getText() + "\n" + regForFiveIcaoCode.getText() + "\n"
|
||||
+ regForFiveName.getText() + "\n" + regForSixIcaoCode.getText() + "\n"
|
||||
+ regForSixName.getText() + "\n" + regForSevenIcaoCode.getText() + "\n"
|
||||
+ regForSevenName.getText() + "\n";
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dataFilePath))) {
|
||||
writer.write(content);
|
||||
writer.close();
|
||||
} catch (IOException y) {
|
||||
y.printStackTrace();
|
||||
JOptionPane.showMessageDialog(settingsFrame,
|
||||
"Error saving loaded config data to program. Config will not load on next startup.");
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
JOptionPane.showMessageDialog(settingsFrame,
|
||||
"Unable to read loaded configuration file, please choose a valid file.");
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
doneButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loopSlides = loopCheck.isSelected();
|
||||
greenScreen = gsCheck.isSelected();
|
||||
fullscreen = fsCheck.isSelected();
|
||||
key = apiKeyText.getText();
|
||||
mainIcao = mainLocIcaoCode.getText();
|
||||
/*
|
||||
if (!checkIcaoCode(mainIcao, key).equals("noerror")) {
|
||||
settingsErrorThrown = true;
|
||||
settingsErrorReasons.add("\nMain Location Error: " + checkIcaoCode(mainIcao, key));
|
||||
}
|
||||
*/
|
||||
nearIcaos.add(nearLocOneIcaoCode.getText());
|
||||
nearIcaos.add(nearLocTwoIcaoCode.getText());
|
||||
nearIcaos.add(nearLocThreeIcaoCode.getText());
|
||||
nearIcaos.add(nearLocFourIcaoCode.getText());
|
||||
nearIcaos.add(nearLocFiveIcaoCode.getText());
|
||||
nearIcaos.add(nearLocSixIcaoCode.getText());
|
||||
nearIcaos.add(nearLocSevenIcaoCode.getText());
|
||||
|
||||
|
||||
nearNames.add(nearLocOneName.getText());
|
||||
nearNames.add(nearLocTwoName.getText());
|
||||
nearNames.add(nearLocThreeName.getText());
|
||||
nearNames.add(nearLocFourName.getText());
|
||||
nearNames.add(nearLocFiveName.getText());
|
||||
nearNames.add(nearLocSixName.getText());
|
||||
nearNames.add(nearLocSevenName.getText());
|
||||
/*
|
||||
for (int i = 0; i < nearIcaos.size(); i++) {
|
||||
if (!checkIcaoCode(nearIcaos.get(i), key).equals("noerror")) {
|
||||
settingsErrorThrown = true;
|
||||
settingsErrorReasons
|
||||
.add("\nNear Location " + i + " Error: " + checkIcaoCode(nearIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
*/
|
||||
regConIcaos.add(regConOneIcaoCode.getText());
|
||||
regConIcaos.add(regConTwoIcaoCode.getText());
|
||||
regConIcaos.add(regConThreeIcaoCode.getText());
|
||||
regConIcaos.add(regConFourIcaoCode.getText());
|
||||
regConIcaos.add(regConFiveIcaoCode.getText());
|
||||
regConIcaos.add(regConSixIcaoCode.getText());
|
||||
regConIcaos.add(regConSevenIcaoCode.getText());
|
||||
|
||||
regConNames.add(regConOneName.getText());
|
||||
regConNames.add(regConTwoName.getText());
|
||||
regConNames.add(regConThreeName.getText());
|
||||
regConNames.add(regConFourName.getText());
|
||||
regConNames.add(regConFiveName.getText());
|
||||
regConNames.add(regConSixName.getText());
|
||||
regConNames.add(regConSevenName.getText());
|
||||
/*
|
||||
for (int i = 0; i < regConIcaos.size(); i++) {
|
||||
if (!checkIcaoCode(regConIcaos.get(i), key).equals("noerror")) {
|
||||
settingsErrorThrown = true;
|
||||
settingsErrorReasons.add(
|
||||
"\nRegional Conditions Loc " + i + " Error: " + checkIcaoCode(regConIcaos.get(i), key));
|
||||
}
|
||||
}*/
|
||||
|
||||
regForIcaos.add(regForOneIcaoCode.getText());
|
||||
regForIcaos.add(regForTwoIcaoCode.getText());
|
||||
regForIcaos.add(regForThreeIcaoCode.getText());
|
||||
regForIcaos.add(regForFourIcaoCode.getText());
|
||||
regForIcaos.add(regForFiveIcaoCode.getText());
|
||||
regForIcaos.add(regForSixIcaoCode.getText());
|
||||
regForIcaos.add(regForSevenIcaoCode.getText());
|
||||
|
||||
regForNames.add(regForOneName.getText());
|
||||
regForNames.add(regForTwoName.getText());
|
||||
regForNames.add(regForThreeName.getText());
|
||||
regForNames.add(regForFourName.getText());
|
||||
regForNames.add(regForFiveName.getText());
|
||||
regForNames.add(regForSixName.getText());
|
||||
regForNames.add(regForSevenName.getText());
|
||||
|
||||
adCrawl = adCrawlInput.getText();
|
||||
/*
|
||||
for (int i = 0; i < regForIcaos.size(); i++) {
|
||||
if (!checkIcaoCode(regForIcaos.get(i), key).equals("noerror")) {
|
||||
settingsErrorThrown = true;
|
||||
settingsErrorReasons
|
||||
.add("\nRegional Forecast Loc " + i + " Error: " + checkIcaoCode(regForIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
*/
|
||||
WindowRunner wr = new WindowRunner();
|
||||
//dr = new DataRunner();
|
||||
/*currentConditions = new CurrentConditions();
|
||||
hourlyObservations = new HourlyObservations();
|
||||
regionalConditions = new RegionalConditions();
|
||||
localForecast = new LocalForecast();
|
||||
almanac = new Almanac();
|
||||
regionalForecast = new RegionalForecast();
|
||||
extendedForecast = new ExtendedForecast();*/
|
||||
|
||||
/*if (settingsErrorThrown) {
|
||||
for (int i = 0; i < settingsErrorReasons.size(); i++) {
|
||||
popupErrors = popupErrors + settingsErrorReasons.get(i);
|
||||
}
|
||||
JOptionPane.showMessageDialog(settingsFrame, "The following errors have occured: " + popupErrors);
|
||||
mainLat = "error";
|
||||
mainLon = "error";
|
||||
|
||||
todayMonth = "error";
|
||||
todayDay = "error";
|
||||
*///} else {
|
||||
// after checking for icao code and key errors, get data
|
||||
|
||||
//}
|
||||
|
||||
String ldltype = (String) ldlDropdown.getSelectedItem();
|
||||
switch (ldltype) {
|
||||
case "Observations":
|
||||
SlidesRunner.ccType = "obs";
|
||||
break;
|
||||
case "Ad Crawl":
|
||||
SlidesRunner.ccType = "crawl";
|
||||
break;
|
||||
case "Both":
|
||||
SlidesRunner.ccType = "both";
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid LDL Option");
|
||||
break;
|
||||
}
|
||||
|
||||
selectedFlavor = (String) flavorDropdown.getSelectedItem();
|
||||
|
||||
simWidth = Integer.parseInt(widthField.getText());
|
||||
simHeight = Integer.parseInt(heightField.getText());
|
||||
|
||||
mainLat = icaoToLat(mainIcao, key);
|
||||
mainLon = icaoToLon(mainIcao, key);
|
||||
|
||||
almanac = new Almanac();
|
||||
todayMonth = almanac.getMonth(mainIcao, key);
|
||||
todayDay = almanac.getDayDate(mainIcao, key);
|
||||
|
||||
|
||||
/*currentConditions.start();
|
||||
hourlyObservations.start();
|
||||
regionalConditions.start();
|
||||
localForecast.start();
|
||||
almanac.start();
|
||||
regionalForecast.start();
|
||||
extendedForecast.start();
|
||||
|
||||
try {
|
||||
currentConditions.join();
|
||||
hourlyObservations.join();
|
||||
regionalConditions.join();
|
||||
localForecast.join();
|
||||
almanac.join();
|
||||
regionalForecast.join();
|
||||
extendedForecast.join();
|
||||
//wr.join();
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
//dr.run();
|
||||
wr.start();
|
||||
// flavor manager
|
||||
|
||||
|
||||
// after all data, checks, and flavor management
|
||||
/*
|
||||
settingsWindow.setVisible(false);
|
||||
|
||||
//BlueWindow blueWindow = new BlueWindow();
|
||||
//LDLRunner lr = new LDLRunner();
|
||||
//lr.start();
|
||||
//BlueRunner br = new BlueRunner();
|
||||
//br.start();
|
||||
*/
|
||||
|
||||
//settingsWindow.setVisible(false);
|
||||
//Window window = Window.get();
|
||||
//window.runWindow();
|
||||
|
||||
settingsErrorThrown = false;
|
||||
settingsErrorReasons.clear();
|
||||
popupErrors = "";
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane settingsScrollFrame = new JScrollPane(settingsFrame);
|
||||
settingsScrollFrame.getVerticalScrollBar().setUnitIncrement(16);
|
||||
|
||||
settingsScrollFrame.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
settingsScrollFrame.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
settingsWindow.add(settingsScrollFrame);
|
||||
settingsWindow.setVisible(true);
|
||||
}
|
||||
|
||||
static String checkIcaoCode(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
if (Response.statusCode() == 401) {
|
||||
return "API Key error";
|
||||
} else {
|
||||
return "Invalid ICAO Code";
|
||||
}
|
||||
}
|
||||
|
||||
return "noerror";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Server Error";
|
||||
}
|
||||
}
|
||||
|
||||
static String icaoToLat(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject locationObject = JSONResponse.getJSONObject("location");
|
||||
|
||||
return Float.toString(locationObject.getFloat("latitude"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Server Error";
|
||||
}
|
||||
}
|
||||
|
||||
static String icaoToLon(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject locationObject = JSONResponse.getJSONObject("location");
|
||||
|
||||
return Float.toString(locationObject.getFloat("longitude"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Server Error";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
public class MouseListener {
|
||||
private static MouseListener instance;
|
||||
private double scrollX, scrollY;
|
||||
private double xPos, yPos, lastX, lastY;
|
||||
private boolean mouseButtonPressed[] = new boolean[3];
|
||||
private boolean isDragging;
|
||||
|
||||
private MouseListener() {
|
||||
this.scrollX = 0.0;
|
||||
this.scrollY = 0.0;
|
||||
this.xPos = 0.0;
|
||||
this.yPos = 9.0;
|
||||
this.lastX = 0.0;
|
||||
this.lastY = 0.0;
|
||||
|
||||
}
|
||||
|
||||
public static MouseListener get() {
|
||||
if (MouseListener.instance == null) {
|
||||
MouseListener.instance = new MouseListener();
|
||||
}
|
||||
|
||||
return MouseListener.instance;
|
||||
}
|
||||
|
||||
public static void mousePosCallback(long window, double xpos, double ypos) {
|
||||
get().lastX = get().xPos;
|
||||
get().lastY = get().yPos;
|
||||
get().xPos = xpos;
|
||||
get().yPos = ypos;
|
||||
get().isDragging = get().mouseButtonPressed[0] || get().mouseButtonPressed[1] || get().mouseButtonPressed[2];
|
||||
}
|
||||
|
||||
public static void mouseButtonCallback(long window, int button, int action, int mods) {
|
||||
if (action == GLFW_PRESS) {
|
||||
if (button < get().mouseButtonPressed.length) {
|
||||
get().mouseButtonPressed[button] = true;
|
||||
}
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
if (button < get().mouseButtonPressed.length) {
|
||||
get().mouseButtonPressed[button] = false;
|
||||
get().isDragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void mouseScrollCallback(long window, double xOffset, double yOffset) {
|
||||
get().scrollX = xOffset;
|
||||
get().scrollY = yOffset;
|
||||
}
|
||||
|
||||
public static void endFrame() {
|
||||
get().scrollX = 0;
|
||||
get().scrollY = 0;
|
||||
get().lastX = get().xPos;
|
||||
get().lastY = get().yPos;
|
||||
}
|
||||
|
||||
public static float getX() {
|
||||
return (float)get().xPos;
|
||||
}
|
||||
|
||||
public static float getY() {
|
||||
return (float)get().yPos;
|
||||
}
|
||||
|
||||
public static float getDx() {
|
||||
return (float)(get().lastX - get().xPos);
|
||||
}
|
||||
|
||||
public static float getDy() {
|
||||
return (float)(get().lastY - get().yPos);
|
||||
}
|
||||
|
||||
public static float getScrollX() {
|
||||
return (float)get().scrollX;
|
||||
}
|
||||
|
||||
public static float getScrollY() {
|
||||
return (float)get().scrollY;
|
||||
}
|
||||
|
||||
public static boolean isDragging() {
|
||||
return get().isDragging;
|
||||
}
|
||||
|
||||
public static boolean mouseButtonDown(int button) {
|
||||
if (button < get().mouseButtonPressed.length) {
|
||||
return get().mouseButtonPressed[button];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
//import java.net.URI;
|
||||
//import java.net.http.HttpClient;
|
||||
//import java.net.http.HttpRequest;
|
||||
//import java.net.http.HttpResponse;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
//import org.json.JSONObject;
|
||||
|
||||
public class Outlook extends Thread {
|
||||
static Utilities utl = new Utilities();
|
||||
String month;
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
String getMonth() {
|
||||
LocalDate cdate = LocalDate.now();
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
return cmonth.name().toUpperCase();
|
||||
}
|
||||
ArrayList<String> getOutlook() {
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
outlook.add("NO");
|
||||
outlook.add("REPORT");
|
||||
return outlook;
|
||||
}
|
||||
public void run() {
|
||||
Main.outlook.month = getMonth();
|
||||
Main.outlook.outlook = getOutlook();
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegionalConditions extends Thread {
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> temperature = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
String getLocName(String displayName){
|
||||
return utl.ljust(displayName, 19, " ").substring(0, 19);
|
||||
}
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
return utl.getCondition(JSONResponse.getInt("iconCodeExtend"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
String getTemperature(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
ArrayList<String> regConNames = new ArrayList<>();
|
||||
regConNames.addAll(Main.regConNames);
|
||||
ArrayList<String> regConIcaos = new ArrayList<>();
|
||||
regConIcaos.addAll(Main.regConIcaos);
|
||||
String key = Main.key;
|
||||
for (int i = 0; i < regConIcaos.size(); i++) {
|
||||
Main.regionalConditions.locName.add(getLocName(regConNames.get(i)));
|
||||
Main.regionalConditions.temperature.add(getTemperature(regConIcaos.get(i), key));
|
||||
Main.regionalConditions.condition.add(getCondition(regConIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegionalForecast extends Thread {
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
ArrayList<String> low = new ArrayList<>();
|
||||
ArrayList<String> high = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
String getLocName(String displayName){
|
||||
return utl.ljust(displayName, 14, " ").substring(0, 14);
|
||||
}
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
|
||||
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
String getLow(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
|
||||
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getHigh(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
|
||||
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
ArrayList<String> regForNames = new ArrayList<>();
|
||||
regForNames.addAll(Main.regForNames);
|
||||
ArrayList<String> regForIcaos = new ArrayList<>();
|
||||
regForIcaos.addAll(Main.regForIcaos);
|
||||
String key = Main.key;
|
||||
for (int i = 0; i < regForIcaos.size(); i++) {
|
||||
Main.regionalForecast.locName.add(getLocName(regForNames.get(i)));
|
||||
Main.regionalForecast.condition.add(getCondition(regForIcaos.get(i), key));
|
||||
Main.regionalForecast.low.add(getLow(regForIcaos.get(i), key));
|
||||
Main.regionalForecast.high.add(getHigh(regForIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import renderer.Renderer;
|
||||
|
||||
public abstract class Scene {
|
||||
protected Renderer renderer = new Renderer();
|
||||
protected Camera camera;
|
||||
private boolean isRunning = false;
|
||||
protected List<GameObject> gameObjects = new ArrayList<>();
|
||||
|
||||
public Scene() {
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
public void start() {
|
||||
for (GameObject go : gameObjects) {
|
||||
go.start();
|
||||
this.renderer.add(go);
|
||||
}
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public void addGameObjectToScene(GameObject go) {
|
||||
if (!isRunning) {
|
||||
gameObjects.add(go);
|
||||
} else {
|
||||
gameObjects.add(go);
|
||||
go.start();
|
||||
this.renderer.add(go);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
|
||||
public Camera camera() {
|
||||
return this.camera;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,44 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.joml.Vector2f;
|
||||
|
||||
public class Transform {
|
||||
|
||||
public Vector2f position;
|
||||
public Vector2f scale;
|
||||
|
||||
public Transform() {
|
||||
init(new Vector2f(), new Vector2f());
|
||||
}
|
||||
|
||||
public Transform(Vector2f position) {
|
||||
init(position, new Vector2f());
|
||||
}
|
||||
|
||||
public Transform(Vector2f position, Vector2f scale) {
|
||||
init(position, scale);
|
||||
}
|
||||
|
||||
public void init(Vector2f position, Vector2f scale) {
|
||||
this.position = position;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public Transform copy() {
|
||||
return new Transform(new Vector2f(this.position), new Vector2f(this.scale));
|
||||
}
|
||||
|
||||
public void copy(Transform to) {
|
||||
to.position.set(this.position);
|
||||
to.scale.set(this.scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (!(o instanceof Transform)) return false;
|
||||
|
||||
Transform t = (Transform)o;
|
||||
return t.position.equals(this.position) && t.scale.equals(this.scale);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
public class TravelForecast extends Thread {
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
ArrayList<String> low = new ArrayList<>();
|
||||
ArrayList<String> high = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
ArrayList<String> tForNames = new ArrayList<>(Arrays.asList("ATLANTA", "BISMARCK", "BOISE", "BOSTON", "BUFFALO", "CHICAGO", "CINCINNATI", "DALLAS", "DENVER", "DETROIT", "KANSAS CITY", "LOS ANGELES", "MINNEAPOLIS", "NASHVILLE", "NEW ORLEANS", "NEW YORK CITY", "PHOENIX", "PORTLAND", "RALEIGH", "RAPID CITY", "SACRAMENTO", "SALT LAKE CITY", "TAMPA", "WASHINGTON, DC"));
|
||||
ArrayList<String> tForIcaos = new ArrayList<>(Arrays.asList("KATL", "KBIS", "KBOI", "KBOS", "KBUF", "KORD", "KCVG", "KDAL", "KDEN", "KDTW", "KMCI", "KLAX", "KMSP", "KDNA", "KMSY", "KLGA", "KPHX", "KPDX", "KRDU", "KRAP", "KSMF", "KSLC", "KTPA", "KDCA"));
|
||||
|
||||
String getLocName(String displayName){
|
||||
return utl.ljust(displayName, 14, " ").substring(0, 14);
|
||||
}
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
|
||||
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
String getLow(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
|
||||
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
String getHigh(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
|
||||
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
String key = Main.key;
|
||||
for (int i = 0; i < tForIcaos.size(); i++) {
|
||||
Main.travelForecast.locName.add(getLocName(tForNames.get(i)));
|
||||
Main.travelForecast.condition.add(getCondition(tForIcaos.get(i), key));
|
||||
Main.travelForecast.low.add(getLow(tForIcaos.get(i), key));
|
||||
Main.travelForecast.high.add(getHigh(tForIcaos.get(i), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.lwjgl.system.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import static org.lwjgl.glfw.Callbacks.*;
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.system.MemoryStack.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
import static org.lwjgl.opengl.GL30.glGenFramebuffers;
|
||||
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
||||
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
|
||||
import renderer.FrameBuffer;
|
||||
|
||||
public class Window {
|
||||
static int secFrameCount;
|
||||
static int fourSecFrameCount;
|
||||
static int slidesSecFrameCount;
|
||||
static int crawlSecFrameCount;
|
||||
static int bTimerSecFrameCount;
|
||||
static int bSlideSecFrameCount;
|
||||
|
||||
int width, height;
|
||||
String title;
|
||||
|
||||
private FrameBuffer framebuffer;
|
||||
|
||||
private static long glfwWindow;
|
||||
|
||||
public float r, g, b, a;
|
||||
|
||||
private static boolean fullscreen;
|
||||
|
||||
private static Window window;
|
||||
|
||||
private static Scene currentScene;
|
||||
|
||||
private Window(int width, int height, boolean fullscreen) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.title = "WeatherSTAR 3000";
|
||||
this.fullscreen = fullscreen;
|
||||
r = 0.0f;
|
||||
g = 0.0f;
|
||||
b = 0.0f;
|
||||
a = 1.0f;
|
||||
}
|
||||
public static Window get() {
|
||||
if (Window.window == null) {
|
||||
Window.window = new Window(Main.simWidth, Main.simHeight, Main.fullscreen);
|
||||
}
|
||||
|
||||
return Window.window;
|
||||
}
|
||||
public static long getGLFWWindow() {
|
||||
return glfwWindow;
|
||||
}
|
||||
|
||||
public static Scene getScene() {
|
||||
return get().currentScene;
|
||||
}
|
||||
|
||||
public void runWindow() {
|
||||
System.out.println("LWJGL" + Version.getVersion());
|
||||
|
||||
init();
|
||||
loop();
|
||||
|
||||
glfwFreeCallbacks(glfwWindow);
|
||||
glfwDestroyWindow(glfwWindow);
|
||||
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(null).free();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
GLFWErrorCallback.createPrint(System.err).set();
|
||||
|
||||
//glfwInitHint(GLFW.GLFW_PLATFORM, GLFW.GLFW_PLATFORM_WAYLAND);
|
||||
|
||||
if (!glfwInit()) {
|
||||
throw new IllegalStateException("Unable to initialize GLFW");
|
||||
}
|
||||
|
||||
glfwDefaultWindowHints();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
|
||||
|
||||
PointerBuffer monitors = glfwGetMonitors();
|
||||
|
||||
if (!monitors.equals(NULL)) {
|
||||
for (int i = 0; i < monitors.limit(); i++) {
|
||||
long monitorHandle = monitors.get(i);
|
||||
// Get the human-readable name of the monitor
|
||||
String monitorName = glfwGetMonitorName(monitorHandle);
|
||||
|
||||
System.out.println("Monitor " + i + ": " + monitorName);
|
||||
}
|
||||
} else {
|
||||
System.err.println("No monitors found!");
|
||||
}
|
||||
|
||||
if (this.fullscreen) {
|
||||
glfwWindow = glfwCreateWindow(vidMode.width(), vidMode.height(), "WeatherSTAR 3000", GLFW.glfwGetPrimaryMonitor(), NULL);
|
||||
} else {
|
||||
glfwWindow = glfwCreateWindow(this.width, this.height, "WeatherSTAR 3000", NULL, NULL);
|
||||
}
|
||||
|
||||
if (glfwWindow == NULL) {
|
||||
throw new IllegalStateException("Failed to create GLFW window");
|
||||
}
|
||||
|
||||
glfwSetFramebufferSizeCallback(glfwWindow, (windowHandle, newWidth, newHeight) -> {
|
||||
this.width = newWidth;
|
||||
this.height = newHeight;
|
||||
glViewport(0, 0, newWidth, newHeight);
|
||||
});
|
||||
|
||||
glfwSetKeyCallback(glfwWindow, KeyListener::keyCallback);
|
||||
|
||||
glfwMakeContextCurrent(glfwWindow);
|
||||
|
||||
glfwSwapInterval(1);
|
||||
|
||||
GL.createCapabilities();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glfwShowWindow(glfwWindow);
|
||||
|
||||
//this.framebuffer = new FrameBuffer(this.width, this.height);
|
||||
|
||||
currentScene = new LoadingScreen();
|
||||
currentScene.init();
|
||||
currentScene.start();
|
||||
}
|
||||
|
||||
public void loop() {
|
||||
float beginTime = (float)glfwGetTime();
|
||||
float endTime;
|
||||
float dt = 0.0f;
|
||||
secFrameCount = 0;
|
||||
|
||||
System.out.println("start window");
|
||||
|
||||
while(!glfwWindowShouldClose(glfwWindow)) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(r, g, b, a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (KeyListener.isKeyPressed(GLFW_KEY_ESCAPE)) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (dt >= 0) {
|
||||
currentScene.update(dt);
|
||||
}
|
||||
|
||||
glfwSwapBuffers(glfwWindow);
|
||||
|
||||
endTime = (float)glfwGetTime();
|
||||
|
||||
if (SlidesRunner.slidesStarted) {
|
||||
secFrameCount++;
|
||||
fourSecFrameCount++;
|
||||
slidesSecFrameCount++;
|
||||
if (!SlidesRunner.bulletinActive) {
|
||||
bTimerSecFrameCount++;
|
||||
}
|
||||
|
||||
if (SlidesRunner.adCrawlActive) {
|
||||
crawlSecFrameCount++;
|
||||
}
|
||||
}
|
||||
|
||||
dt = endTime - beginTime;
|
||||
//System.out.println(1.0f/dt + " fps");
|
||||
beginTime = endTime;
|
||||
}
|
||||
|
||||
if (SlidesRunner.audioManager != null) {
|
||||
SlidesRunner.audioManager.close();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
static void finishInit() {
|
||||
currentScene = new SlidesRunner();
|
||||
currentScene.init();
|
||||
currentScene.start();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
public class WindowRunner extends Thread {
|
||||
public void run() {
|
||||
Main.settingsWindow.setVisible(false);
|
||||
Window window = Window.get();
|
||||
window.runWindow();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user