Skip to content
Snippets Groups Projects
Commit c66438ce authored by joalhelk's avatar joalhelk
Browse files

temperature panel and linechart structure

parent a928da30
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import javax.swing.*;
import com.joelhelkala.watcherGui.User.User;
import com.joelhelkala.watcherGui.frames.panels.LineChartPanel;
import com.joelhelkala.watcherGui.frames.panels.ProgressBarCirclePanel;
import com.joelhelkala.watcherGui.frames.panels.TemperaturePanel;
public class WelcomePage {
......@@ -38,12 +39,12 @@ public class WelcomePage {
cardPanel.setBounds(leftPanelWidth, topPanelHeight, width-leftPanelWidth, cardPanelHeight);
cardPanel.setLayout(null);
JPanel card1 = new JPanel();
JPanel card1 = new TemperaturePanel();
card1.setBackground(lightgray);
card1.setBounds(15, 10, cardWidth, cardPanelHeight-20);
cardPanel.add(card1);
JPanel card2 = new ProgressBarCirclePanel().makeUI();
JPanel card2 = new ProgressBarCirclePanel().makeUI("Humidity");
card2.setBackground(lightgray);
card2.setBounds(cardWidth+30, 10, cardWidth, cardPanelHeight-20);
cardPanel.add(card2);
......@@ -58,7 +59,7 @@ public class WelcomePage {
chartPanel.setBounds(leftPanelWidth, topPanelHeight+cardPanelHeight, width-leftPanelWidth, cardPanelHeight);
chartPanel.setLayout(null);
JPanel chart = new LineChartPanel("Temperature").getPanel();
JPanel chart = new LineChartPanel("Temperature");
chart.setBackground(darkwhite);
chart.setBounds(15, 10, width - leftPanelWidth - 30, cardPanelHeight - 20);
chartPanel.add(chart);
......
......@@ -12,9 +12,7 @@ import org.jfree.data.category.DefaultCategoryDataset;
import java.awt.BorderLayout;
import java.time.LocalDateTime;
public class LineChartPanel {
private JPanel panel;
public class LineChartPanel extends JPanel {
// Constructor
public LineChartPanel(String chartTitle) {
......@@ -25,14 +23,9 @@ public class LineChartPanel {
ChartPanel chartPanel = new ChartPanel( lineChart );
chartPanel.setPreferredSize( new Dimension( 560 , 367 ) );
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(chartPanel, BorderLayout.CENTER);
panel.validate();
}
public JPanel getPanel() {
return panel;
this.setLayout(new BorderLayout());
this.add(chartPanel, BorderLayout.CENTER);
this.validate();
}
// Mockup dataset
......
......@@ -2,12 +2,16 @@ package com.joelhelkala.watcherGui.frames.panels;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.plaf.basic.BasicProgressBarUI;
import org.jfree.chart.ChartColor;
import javafx.scene.paint.Color;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
......@@ -63,14 +67,14 @@ public class ProgressBarCirclePanel extends BasicProgressBarUI {
}
// Returns the panel which contains the circle progressbar
public JPanel makeUI() {
public JPanel makeUI(String title) {
JProgressBar progress = new JProgressBar();
// use JProgressBar#setUI(...) method
progress.setUI(new ProgressBarCirclePanel());
progress.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
progress.setStringPainted(true);
progress.setFont(progress.getFont().deriveFont(24f));
progress.setForeground(ChartColor.ORANGE);
progress.setForeground(ChartColor.LIGHT_BLUE);
// Timer for animation
(new Timer(50, e -> {
......@@ -79,7 +83,11 @@ public class ProgressBarCirclePanel extends BasicProgressBarUI {
})).start();
JPanel p = new JPanel();
JLabel label = new JLabel(title);
label.setForeground(java.awt.Color.white);
label.setHorizontalAlignment(SwingConstants.CENTER);
p.setLayout(new BorderLayout());
p.add(label, BorderLayout.NORTH);
p.add(progress, BorderLayout.CENTER);
return p;
}
......
package com.joelhelkala.watcherGui.frames.panels;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Font;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TemperaturePanel extends JPanel {
public TemperaturePanel() {
this.setLayout(new BorderLayout());
JLabel day = new JLabel(getDay());
day.setForeground(java.awt.Color.white);
day.setHorizontalAlignment(SwingConstants.CENTER);
this.add(day, BorderLayout.NORTH);
Character degree = 0xB0;
String temperature = "-17" + degree;
JLabel temp = new JLabel(temperature);
temp.setForeground(java.awt.Color.white);
temp.setHorizontalAlignment(SwingConstants.CENTER);
temp.setFont(new Font(null, Font.BOLD, 40));
this.add(temp, BorderLayout.CENTER);
}
private String getDay() {
Calendar cal = Calendar.getInstance();
Format f = new SimpleDateFormat("EEEE");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String date = f.format(new Date()) + " " + sdf.format(cal.getTime());
return date;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment