Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7df3b68
Commit
HarpreetPadda Nov 12, 2020
c89e6fc
Merge remote-tracking branch 'remotes/origin/Jaishil' into HarpreetPadda
HarpreetPadda Nov 12, 2020
c56163a
Merge remote-tracking branch 'remotes/origin/Victor' into HarpreetPadda
HarpreetPadda Nov 12, 2020
111dfe2
Merge remote-tracking branch 'remotes/origin/Victor' into HarpreetPadda
HarpreetPadda Nov 12, 2020
880c9b6
kmve
HarpreetPadda Nov 12, 2020
7fc426b
Merge remote-tracking branch 'remotes/origin/Foad' into HarpreetPadda
HarpreetPadda Nov 12, 2020
fd9f944
commit
HarpreetPadda Nov 13, 2020
ea7c912
did it work
HarpreetPadda Nov 13, 2020
be69703
tooltip added
Victor-Peraza Nov 30, 2020
3d55aa1
update
HarpreetPadda Nov 30, 2020
025e89e
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Har…
HarpreetPadda Nov 30, 2020
702ed70
Added a combo box to store recent cities
Victor-Peraza Nov 30, 2020
baa8b22
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Victor
Victor-Peraza Nov 30, 2020
5b14e0e
Added static map, placement needs work
foadolfat Nov 30, 2020
d319e51
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Victor
Victor-Peraza Nov 30, 2020
6b7b676
background image and map
Victor-Peraza Nov 30, 2020
2a00a40
jar file relative path
Victor-Peraza Nov 30, 2020
2fbc17c
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Har…
HarpreetPadda Nov 30, 2020
ad6d08b
background image now shows before action and remains after
foadolfat Nov 30, 2020
3bcc78f
Static map now updates with new searches
foadolfat Nov 30, 2020
aff3afb
Removed lat/lon text box functionality, added address searching.
foadolfat Nov 30, 2020
7e6a6b5
Added icons, removed input class
foadolfat Nov 30, 2020
cfdf3af
implemented additional getters in forcast and today, added dates and …
foadolfat Dec 1, 2020
761b885
GUI redesign
Victor-Peraza Dec 1, 2020
420a48d
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Victor
Victor-Peraza Dec 1, 2020
dc9fe91
hi
HarpreetPadda Dec 1, 2020
68e6e89
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Har…
HarpreetPadda Dec 1, 2020
5fc903a
implemented victor's ui and foad's changes
foadolfat Dec 1, 2020
e39fcb0
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Har…
HarpreetPadda Dec 1, 2020
0834c9d
added pictures for background
foadolfat Dec 1, 2020
3303046
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Victor
Victor-Peraza Dec 1, 2020
32ee76b
Merge branch 'Foad' of https://github.com/niccsus/theWeather into Har…
HarpreetPadda Dec 1, 2020
ccc898e
GUI Redesign
Victor-Peraza Dec 1, 2020
b0334d1
the pictures
HarpreetPadda Dec 1, 2020
dc1b64c
Merge branch 'Victor' of https://github.com/niccsus/theWeather into H…
HarpreetPadda Dec 1, 2020
9640f57
here
HarpreetPadda Dec 1, 2020
040733c
background now changes based on weather.
foadolfat Dec 1, 2020
8a0f4c7
Day of week and weather icon added to all forecast days.
foadolfat Dec 1, 2020
dd05dba
Fixed the overlapping text bug. App now displays everything properly.
foadolfat Dec 2, 2020
23890a7
added weather map overlay on top of google maps. Fixed misc.xml. inco…
foadolfat Dec 3, 2020
415cc31
Added Zoom buttons for map.
foadolfat Dec 4, 2020
8505214
Turned Fetch Singleton to meet project requirement.
foadolfat Dec 4, 2020
b5a58e9
Introduced a better interface than the previous one.
foadolfat Dec 4, 2020
796d495
Zoom out now goes all the way out to World Map.
foadolfat Dec 4, 2020
65e07f3
Removed test comments and print statements.
foadolfat Dec 4, 2020
a76bc64
removed input.java since it was unused
foadolfat Dec 4, 2020
d181977
here is the saved names
HarpreetPadda Dec 6, 2020
3484740
here
HarpreetPadda Dec 6, 2020
8bad8d6
here you guys go
HarpreetPadda Dec 6, 2020
0a0d5b1
Fixed double save in combo box
foadolfat Dec 7, 2020
253e79d
mergd with victor
foadolfat Dec 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
//Make sure the path on your machine is correct
"java.project.referencedLibraries": [
"lib/**/*.jar",
"c:\\Users\\Foad_Olfat\\Downloads\\json-20201115.jar"
"weather/json-20201115.jar"
]
}
Binary file added weather/.DS_Store
Binary file not shown.
Binary file added weather/json-20201115.jar
Binary file not shown.
Binary file added weather/picture/Zoom_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/Zoom_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/cloud.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/rain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/snow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weather/picture/thunder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions weather/src/BufferedImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


public interface BufferedImage {

}
120 changes: 89 additions & 31 deletions weather/src/Fetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,112 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import org.json.JSONArray;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import org.json.JSONObject;
import java.net.URI;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.net.URL;

import java.awt.AlphaComposite;
import java.awt.Graphics;

public class Fetch {
private final String key = "843b5b1093b07ff0e1d9f681a3a3cb0c"; //API token
private final String google_key = "AIzaSyCVMgcmhkqfQKxbeUnJPGx6V5twYGMq-9k"; //google api token
private String query; //API URL
private String google_query; //google API URL
JSONObject json = new JSONObject(); //the JSON object that contains weather data
JSONObject google_json = new JSONObject(); //the JSON object that contains city co ordinates


public Fetch(){

private static Fetch instance = null;
private Fetch() {
// Exists only to defeat instantiation.
}
//constructor in case user inputs string
public Fetch(String city) {
//this.query = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=imperial&appid=" + key;
this.google_query = "https://maps.googleapis.com/maps/api/geocode/json?address="+ city + "&key=" + google_key;
Geolocator geolocator = new Geolocator(google_query);
//this.query = "https://api.openweathermap.org/data/2.5/weather?lat=" + geolocator.lat + "&lon=" + geolocator.lon + "&units=imperial&appid=" + key;
this.query = "https://api.openweathermap.org/data/2.5/onecall?lat="+ geolocator.lat + "&lon=" + geolocator.lon + "&units=imperial&appid=" + key;
set_json(query);


}
//constructor in case user inputs lat/lon
//WORK IN PROGRESS
public Fetch(String[] lat_lon){
//38.7521235,-121.2880059
this.query = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat_lon[0] + "&lon=" + lat_lon[1] + "&units=imperial&appid=" + key;
private final static String key = "843b5b1093b07ff0e1d9f681a3a3cb0c"; // API token
private final static String google_key = "AIzaSyCVMgcmhkqfQKxbeUnJPGx6V5twYGMq-9k"; // google api token
private static String query; // API URL
private static String google_query; // google API URL
private static String weather_map_query;
static JSONObject json = new JSONObject(); // the JSON object that contains weather data
JSONObject google_json = new JSONObject(); // the JSON object that contains city co ordinates
static ImageIcon map = new ImageIcon();
static String static_map_query;
static Geolocator geolocator;
static ImageIcon weather_map = new ImageIcon();
ImageIcon composite = new ImageIcon();
String view = "";

// constructor in case user inputs string
public static Fetch getInstance(String city, String view, int zoom) throws IOException {
if (instance == null) {
instance = new Fetch();
}
google_query = "https://maps.googleapis.com/maps/api/geocode/json?address=" + city + "&key=" + google_key;
geolocator = new Geolocator(google_query, zoom);
query = "https://api.openweathermap.org/data/2.5/onecall?lat=" + geolocator.lat + "&lon=" + geolocator.lon
+ "&units=imperial&appid=" + key;
set_json(query);
set_map(zoom, view);
return instance;
}

//creates JSON object based on user input
public void set_json(String query){
// creates JSON object based on user input
public static void set_json(String query) {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(query)).build();
this.json = new JSONObject(client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.join());
json = new JSONObject(
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(HttpResponse::body).join());
}

public static BufferedImage get_weather_map_img(BufferedImage image) {

BufferedImage tmpImg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) tmpImg.getGraphics();
g2d.setComposite(AlphaComposite.SrcOver.derive(1.0f));
// set the transparency level in range 0.0f - 1.0f
g2d.drawImage(image, 0, 0, null);
image = tmpImg;
return image;
}

public void get_composite() throws IOException {
// Assumed that these are non-null
BufferedImage bigIcon, smallIcon;
URL url = new URL(static_map_query);
URL url2 = new URL(weather_map_query);
bigIcon = ImageIO.read(url);
smallIcon = ImageIO.read(url2);
// Create a new image.
BufferedImage finalIcon = new BufferedImage(bigIcon.getWidth(), bigIcon.getHeight(),
BufferedImage.TYPE_INT_ARGB); // start transparent

// Get the graphics object. This is like the canvas you draw on.
Graphics g = finalIcon.getGraphics();

// Now we draw the images.
g.drawImage(bigIcon, 0, 0, null); // start at (0, 0)
g.drawImage(smallIcon, 0, 0, null); // start at (10, 10)

// Once we're done drawing on the Graphics object, we should
// call dispose() on it to free up memory.
g.dispose();

// Finally, convert to ImageIcon and apply.
composite = new ImageIcon(finalIcon);
}

public static void set_map(int zoom, String view) throws IOException {
static_map_query = "https://maps.googleapis.com/maps/api/staticmap?center=" + geolocator.lat + ","
+ geolocator.lon + "&zoom=" + zoom + "&size=256x256&maptype=hybrid&key=" + google_key;
URL url = new URL(static_map_query);
BufferedImage img = ImageIO.read(url);
map = new ImageIcon(img);

Geolocator.getTileNumber(geolocator.lon, geolocator.lat, zoom);
weather_map_query = "https://tile.openweathermap.org/map/" + view + "/" + zoom + "/" + Geolocator.x + "/"
+ Geolocator.y + ".png?appid=" + key;
URL url2 = new URL(weather_map_query);
BufferedImage img2 = ImageIO.read(url2);
weather_map = new ImageIcon(get_weather_map_img(img2));
}
}
Loading