Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
geilala committed May 30, 2024
1 parent 92517b5 commit d4212e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/edu/project/components/WeatherCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
}
Expand All @@ -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);
}
}
9 changes: 9 additions & 0 deletions src/main/java/edu/project/components/WeatherInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand All @@ -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"
Expand All @@ -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;
Expand Down

0 comments on commit d4212e6

Please sign in to comment.