-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into geila/update-weather-info
- Loading branch information
Showing
10 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,58 @@ | ||
package edu.project.components; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.RenderingHints; | ||
|
||
import javax.swing.Box; | ||
import javax.swing.BoxLayout; | ||
import javax.swing.JPanel; | ||
|
||
import com.formdev.flatlaf.FlatClientProperties; | ||
|
||
import edu.project.Context; | ||
import java.awt.BorderLayout; | ||
|
||
import edu.project.components.weathercards.WeatherGroup; | ||
|
||
public class WeatherIsland extends JPanel { | ||
public WeatherIsland(Context context) { | ||
putClientProperty(FlatClientProperties.STYLE, | ||
"background: tint(@background,50%); border: 16,16,16,16,shade(@background,10%),,16"); | ||
"background: tint(@background,50%); border: 8,8,8,8,shade(@background,10%),,16"); | ||
setOpaque(false); | ||
|
||
setLayout(new BorderLayout()); | ||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); | ||
|
||
WeatherInfo weatherInfo = new WeatherInfo(context); | ||
add(weatherInfo, BorderLayout.CENTER); | ||
|
||
// Maximize Width and Minimize Height | ||
weatherInfo.setMaximumSize( | ||
new Dimension( | ||
weatherInfo.getMaximumSize().width, | ||
weatherInfo.getPreferredSize().height)); | ||
|
||
add(weatherInfo); | ||
|
||
add(Box.createVerticalStrut(8)); | ||
|
||
WeatherGroup weatherGroup = new WeatherGroup(); | ||
|
||
// Maximize Width and Minimize Height | ||
weatherGroup.setMaximumSize( | ||
new Dimension( | ||
weatherGroup.getMaximumSize().width, | ||
weatherGroup.getPreferredSize().height)); | ||
|
||
add(weatherGroup); | ||
|
||
} | ||
|
||
@Override | ||
protected void paintComponent(Graphics graphics) { | ||
Graphics2D graphics2d = (Graphics2D) graphics; | ||
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | ||
graphics2d.setColor(getBackground()); | ||
graphics2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16 + 12, 16 + 12); | ||
graphics2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16); | ||
super.paintComponent(graphics2d); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/edu/project/components/weathercards/WeatherCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package edu.project.components.weathercards; | ||
|
||
import com.formdev.flatlaf.FlatClientProperties; | ||
|
||
import java.awt.Color; | ||
import java.awt.Font; | ||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.GridBagConstraints; | ||
import java.awt.GridBagLayout; | ||
import java.awt.Insets; | ||
import java.awt.RenderingHints; | ||
|
||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.SwingConstants; | ||
|
||
public abstract class WeatherCard extends JPanel { | ||
public WeatherCard(String title, String value, 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.setFont(new Font("Arial", Font.BOLD, 32)); | ||
|
||
JLabel unitLabel = new JLabel(unit, SwingConstants.CENTER); | ||
unitLabel.setFont(new Font("Arial", Font.PLAIN, 14)); | ||
|
||
GridBagConstraints constraints = new GridBagConstraints(); | ||
constraints.gridx = 0; | ||
constraints.gridy = 0; | ||
constraints.insets = new Insets(3, 3, 3, 3); | ||
add(titleLabel, constraints); | ||
|
||
constraints.gridy++; | ||
add(valueLabel, constraints); | ||
|
||
constraints.gridy++; | ||
add(unitLabel, constraints); | ||
} | ||
|
||
@Override | ||
protected void paintComponent(Graphics graphics) { | ||
Graphics2D graphics2d = (Graphics2D) graphics; | ||
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | ||
graphics2d.setColor(Color.LIGHT_GRAY); | ||
graphics2d.fillRoundRect(0, 0, getWidth(), getHeight(), 16, 16); | ||
super.paintComponent(graphics); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/edu/project/components/weathercards/WeatherGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package edu.project.components.weathercards; | ||
|
||
import java.awt.GridLayout; | ||
|
||
import javax.swing.JPanel; | ||
|
||
public class WeatherGroup extends JPanel { | ||
public WeatherGroup() { | ||
setOpaque(false); | ||
setLayout(new GridLayout(1, 4, 8, 0)); | ||
add(new WeatherWindCard("16")); | ||
add(new WeatherHumidityCard("50")); | ||
add(new WeatherRainRateCard("0")); | ||
add(new WeatherUVCard("5")); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/project/components/weathercards/WeatherHumidityCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package edu.project.components.weathercards; | ||
|
||
public class WeatherHumidityCard extends WeatherCard { | ||
public WeatherHumidityCard(String value) { | ||
super("Humidity", value, "%"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/project/components/weathercards/WeatherRainRateCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package edu.project.components.weathercards; | ||
|
||
public class WeatherRainRateCard extends WeatherCard { | ||
public WeatherRainRateCard(String value) { | ||
super("Rain Rate", value, "in/h"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/project/components/weathercards/WeatherUVCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package edu.project.components.weathercards; | ||
|
||
public class WeatherUVCard extends WeatherCard { | ||
public WeatherUVCard(String value) { | ||
super("UV Index", value, "Moderate"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/project/components/weathercards/WeatherWindCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package edu.project.components.weathercards; | ||
|
||
public class WeatherWindCard extends WeatherCard { | ||
public WeatherWindCard(String value) { | ||
super("Wind", value, "mph"); | ||
} | ||
} |