Skip to content

Commit

Permalink
Integrate API to weather cards
Browse files Browse the repository at this point in the history
  • Loading branch information
daawaan4U committed May 29, 2024
1 parent f807fa7 commit 8d86895
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.project.components.weathercards;
package edu.project.components;

import com.formdev.flatlaf.FlatClientProperties;

Expand All @@ -15,22 +15,22 @@
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public abstract class WeatherCard extends JPanel {
public WeatherCard(String title, String value, String unit) {
public class WeatherCard extends JPanel {

private JLabel valueLabel;

public WeatherCard(String title, String unit) {
putClientProperty(FlatClientProperties.STYLE,
"border: 6,4,6,4,shade(@background,10%),,16");

setOpaque(false);

setLayout(new GridBagLayout());
// setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// setMaximumSize(new Dimension(100, 150));
// setPreferredSize(new Dimension(100, 150));

JLabel titleLabel = new JLabel(title, SwingConstants.CENTER);
titleLabel.setFont(new Font("Arial", Font.PLAIN, 14));

JLabel valueLabel = new JLabel(value, SwingConstants.CENTER);
valueLabel = new JLabel(" ", SwingConstants.CENTER);
valueLabel.setFont(new Font("Arial", Font.BOLD, 32));

JLabel unitLabel = new JLabel(unit, SwingConstants.CENTER);
Expand All @@ -49,6 +49,10 @@ public WeatherCard(String title, String value, String unit) {
add(unitLabel, constraints);
}

public void setValue(String value) {
valueLabel.setText(value);
}

@Override
protected void paintComponent(Graphics graphics) {
Graphics2D graphics2d = (Graphics2D) graphics;
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/edu/project/components/WeatherCardGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package edu.project.components;

import java.awt.GridLayout;

import javax.swing.JPanel;

import edu.project.Context;

public class WeatherCardGroup extends JPanel {
public WeatherCardGroup(Context context) {
setOpaque(false);
setLayout(new GridLayout(1, 4, 8, 0));

WeatherCard windCard = new WeatherCard("Wind", "m/s");
WeatherCard humidityCard = new WeatherCard("Humidity", "%");
WeatherCard rainRateCard = new WeatherCard("Rain Rate", "mm/h");
WeatherCard pressureCard = new WeatherCard("Cloud", "%");

add(windCard);
add(humidityCard);
add(rainRateCard);
add(pressureCard);

context.store.addWeatherCurrentDataListener(data -> {
windCard.setValue(String.format("%.1f", data.wind.speed));
humidityCard.setValue(String.format("%d", data.main.humidity));
rainRateCard.setValue(String.format("%.1f", data.rain != null ? data.rain.one_hour : 0));
pressureCard.setValue(String.format("%d", data.clouds.all));
});
}
}
4 changes: 1 addition & 3 deletions src/main/java/edu/project/components/WeatherIsland.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import edu.project.Context;

import edu.project.components.weathercards.WeatherGroup;

public class WeatherIsland extends JPanel {
public WeatherIsland(Context context) {
putClientProperty(FlatClientProperties.STYLE,
Expand All @@ -35,7 +33,7 @@ public WeatherIsland(Context context) {

add(Box.createVerticalStrut(8));

WeatherGroup weatherGroup = new WeatherGroup();
WeatherCardGroup weatherGroup = new WeatherCardGroup(context);

// Maximize Width and Minimize Height
weatherGroup.setMaximumSize(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8d86895

Please sign in to comment.