Added jfreechart dependency and rudimentary implementation.
This commit is contained in:
16
pom.xml
16
pom.xml
@@ -22,12 +22,16 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20190722</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jfree</groupId>
|
||||
<artifactId>jfreechart</artifactId>
|
||||
<version>1.5.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20190722</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -27,7 +27,7 @@ public final class MainFrame extends JFrame implements Themeable {
|
||||
private MainFrame() {
|
||||
this.setTitle("Firewall Dashboard");
|
||||
this.setJMenuBar(MenuBar.getMenuBar());
|
||||
this.setPanel(Panel.ConnectToServerPanel);
|
||||
this.setPanel(Panel.MonitoringPanel);
|
||||
this.setSize(1400, 700);
|
||||
this.setMinimumSize(new Dimension(700, 500));
|
||||
this.setLocation(100, 100);
|
||||
@@ -44,6 +44,7 @@ public final class MainFrame extends JFrame implements Themeable {
|
||||
|
||||
private void setPanel(JPanel panel) {
|
||||
this.getContentPane().removeAll();
|
||||
|
||||
this.getContentPane().setLayout(new GridBagLayout());
|
||||
|
||||
// Status Panel
|
||||
@@ -64,6 +65,7 @@ public final class MainFrame extends JFrame implements Themeable {
|
||||
mainConstraints.weighty = 0.1;
|
||||
this.getContentPane().add(panel, mainConstraints);
|
||||
|
||||
this.getContentPane().update(this.getGraphics());
|
||||
this.update(this.getGraphics());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package gui.src.panels.ConnectionsLineChart;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.block.BlockBorder;
|
||||
import org.jfree.chart.plot.PlotOrientation;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
||||
import org.jfree.chart.title.TextTitle;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
import org.jfree.data.xy.XYSeries;
|
||||
import org.jfree.data.xy.XYSeriesCollection;
|
||||
|
||||
public class ConnectionsLineChartPanel extends JPanel {
|
||||
private static ConnectionsLineChartPanel instance;
|
||||
|
||||
private ConnectionsLineChartPanel() {
|
||||
XYDataset dataset = createDataset();
|
||||
JFreeChart chart = createChart(dataset);
|
||||
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
chartPanel.setBackground(Color.white);
|
||||
add(chartPanel);
|
||||
}
|
||||
|
||||
public static ConnectionsLineChartPanel getInstance() {
|
||||
if (null == instance) {
|
||||
instance = new ConnectionsLineChartPanel();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private XYDataset createDataset() {
|
||||
|
||||
var series = new XYSeries("2016");
|
||||
series.add(18, 15);
|
||||
series.add(20, 20);
|
||||
series.add(25, 40);
|
||||
series.add(30, 70);
|
||||
|
||||
var dataset = new XYSeriesCollection();
|
||||
dataset.addSeries(series);
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
private JFreeChart createChart(XYDataset dataset) {
|
||||
|
||||
JFreeChart chart = ChartFactory.createXYLineChart(
|
||||
"Average salary per age",
|
||||
"Age",
|
||||
"Salary (€)",
|
||||
dataset,
|
||||
PlotOrientation.VERTICAL,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
XYPlot plot = chart.getXYPlot();
|
||||
|
||||
var renderer = new XYLineAndShapeRenderer();
|
||||
renderer.setSeriesPaint(0, Color.RED);
|
||||
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
|
||||
|
||||
plot.setRenderer(renderer);
|
||||
plot.setBackgroundPaint(Color.white);
|
||||
|
||||
plot.setRangeGridlinesVisible(true);
|
||||
plot.setRangeGridlinePaint(Color.BLACK);
|
||||
|
||||
plot.setDomainGridlinesVisible(true);
|
||||
plot.setDomainGridlinePaint(Color.BLACK);
|
||||
|
||||
chart.getLegend().setFrame(BlockBorder.NONE);
|
||||
|
||||
chart.setTitle(new TextTitle("Zugriffe",
|
||||
new Font("Serif", java.awt.Font.BOLD, 18)
|
||||
)
|
||||
);
|
||||
|
||||
return chart;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,25 @@
|
||||
|
||||
package gui.src.panels;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import gui.src.panels.ConnectionsLineChart.ConnectionsLineChartPanel;
|
||||
|
||||
public final class MonitoringPanel extends JPanel {
|
||||
|
||||
private static MonitoringPanel instance;
|
||||
|
||||
private MonitoringPanel() {
|
||||
GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
this.add(ConnectionsLineChartPanel.getInstance(), gridBagConstraints);
|
||||
|
||||
this.setPreferredSize(new Dimension(900,600));
|
||||
}
|
||||
|
||||
public static MonitoringPanel getInstance() {
|
||||
|
||||
@@ -21,23 +21,15 @@ public final class Main {
|
||||
private static final String className = "Main";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ControllerToViewQueue.getInstance();
|
||||
MessageLogger.printMessage(className, "ControllerToViewQueue was created.");
|
||||
ViewToControllerQueue.getInstance();
|
||||
MessageLogger.printMessage(className, "ViewToControllerQueue was created.");
|
||||
|
||||
View view = new ViewThread();
|
||||
MessageLogger.printMessage(className, "View was created.");
|
||||
view.start();
|
||||
MessageLogger.printMessage(className, "View was started.");
|
||||
|
||||
|
||||
ModelRepresentation model = new ModelRepresentation();
|
||||
MessageLogger.printMessage(className, "Model was created.");
|
||||
|
||||
Controller controller = new ControllerThread(view, model);
|
||||
MessageLogger.printMessage(className, "Controller was created.");
|
||||
controller.start();
|
||||
MessageLogger.printMessage(className, "Controller was started.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user