diff --git a/src/main/java/edu/project/components/WeatherCard.java b/src/main/java/edu/project/components/WeatherCard.java index f4d74ca..54cc5cd 100644 --- a/src/main/java/edu/project/components/WeatherCard.java +++ b/src/main/java/edu/project/components/WeatherCard.java @@ -20,6 +20,8 @@ public class WeatherCard extends JPanel { private JLabel valueLabel; public WeatherCard(String title, String unit) { + //// Set a custom property for the component's border style using FlatLaf + //// properties putClientProperty(FlatClientProperties.STYLE, "border: 6,4,6,4,shade(@background,10%),,16"); @@ -36,15 +38,18 @@ public WeatherCard(String title, String unit) { JLabel unitLabel = new JLabel(unit, SwingConstants.CENTER); unitLabel.setFont(new Font("Arial", Font.PLAIN, 14)); + // Define layout constraints for the GridBagLayout GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; - constraints.insets = new Insets(3, 3, 3, 3); + constraints.insets = new Insets(3, 3, 3, 3);// Padding around components add(titleLabel, constraints); + // Move to the next row and add the value label constraints.gridy++; add(valueLabel, constraints); + // Move to the next row and add the unit label constraints.gridy++; add(unitLabel, constraints); } @@ -53,12 +58,19 @@ public void setValue(String value) { valueLabel.setText(value); } + // Override the paintComponent method to customize the panel's appearance @Override protected void paintComponent(Graphics graphics) { + + // Cast the Graphics object to Graphics2D for better control over rendering Graphics2D graphics2d = (Graphics2D) graphics; + + // Enable anti-aliasing for smoother rendering graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2d.setColor(new Color(224, 224, 224)); graphics2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16); + + // Call the superclass method to ensure proper rendering of other components super.paintComponent(graphics); } } diff --git a/src/main/java/edu/project/components/WeatherInfo.java b/src/main/java/edu/project/components/WeatherInfo.java index 84eb8ec..44ec5ed 100644 --- a/src/main/java/edu/project/components/WeatherInfo.java +++ b/src/main/java/edu/project/components/WeatherInfo.java @@ -18,12 +18,17 @@ public class WeatherInfo extends JPanel { public WeatherInfo(Context context) { setLayout(new BorderLayout()); setOpaque(false); + + // Set an empty border around the panel with 8 pixels padding on each side setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); + // Create the left panel for date, time, sky condition, and feels like + // temperature JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS)); leftPanel.setOpaque(false); + // create and customize labels JLabel dateLabel = new JLabel("Saturday, May 4"); dateLabel.setFont(new Font(dateLabel.getFont().getName(), Font.BOLD, 18)); @@ -44,10 +49,12 @@ public WeatherInfo(Context context) { leftPanel.add(skyLabel); leftPanel.add(feelsLikeLabel); + // Create the right panel for location, temperature, and high/low temperatures JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS)); rightPanel.setOpaque(false); + // create and customize labels JLabel locationLabel = new JLabel("Quiling Sur"); locationLabel.setFont(new Font(locationLabel.getFont().getName(), Font.BOLD, 18)); @@ -64,6 +71,7 @@ public WeatherInfo(Context context) { add(leftPanel, BorderLayout.WEST); add(rightPanel, BorderLayout.EAST); + // Add a listener for current weather data updates context.store.addWeatherCurrentDataListener(data -> { // leftpanel SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE, MMMM d"); // Example format: "Saturday, May 4" @@ -83,6 +91,7 @@ public WeatherInfo(Context context) { }); + // Add a listener for 5-day weather forecast data updates context.store.addWeatherForecast5DataListener(data -> { // Get the weather description String description = data.list.get(0).weather.get(0).description;