Skip to content

Commit af7cc19

Browse files
committed
Implemented UI for switch displayed mood dimension
1 parent 8ad547c commit af7cc19

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/java/plotmas/PlotControlsLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected void drawGraphs() {
4545
this.plotGraph = PlotGraph.getPlotListener().visualizeGraph(COMPRESS_GRAPH);
4646

4747
// create and visualize mood graph
48-
MoodGraph.getMoodListener().createGraph();
48+
MoodGraph.getMoodListener().createData();
4949
this.moodGraph = MoodGraph.getMoodListener().visualizeGraph();
5050

5151
this.isDraw = true;

src/java/plotmas/graph/MoodGraph.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package plotmas.graph;
22

3+
import java.awt.BorderLayout;
34
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
56
import java.util.Iterator;
@@ -12,6 +13,7 @@
1213
import org.jfree.chart.ChartFactory;
1314
import org.jfree.chart.ChartPanel;
1415
import org.jfree.chart.JFreeChart;
16+
import org.jfree.chart.plot.CategoryPlot;
1517
import org.jfree.chart.plot.PlotOrientation;
1618
import org.jfree.data.category.DefaultCategoryDataset;
1719
import org.jfree.ui.RefineryUtilities;
@@ -35,6 +37,7 @@ public class MoodGraph extends JFrame {
3537

3638
private DefaultCategoryDataset moodData = null;
3739
private String selectedMoodDimension = null;
40+
private JFreeChart chart = null;
3841

3942
public static MoodGraph getMoodListener() {
4043
if (MoodGraph.moodListener==null) {
@@ -55,7 +58,7 @@ public MoodGraph(String title) {
5558
this.selectedMoodDimension = MOOD_DIMS[0];
5659
}
5760

58-
public void createGraph() {
61+
public void createData() {
5962
this.deleteGraphData();
6063

6164
Long startTime = PlotAwareAg.moodMapper.latestStartTime();
@@ -74,6 +77,21 @@ public void createGraph() {
7477
}
7578
}
7679

80+
private void createChart(DefaultCategoryDataset data) {
81+
String title = "Mood Development Over Time";
82+
if (data.getRowCount() == 0)
83+
title = "No mood points have been reported to MoodGraph";
84+
85+
JFreeChart lineChart = ChartFactory.createLineChart(
86+
title,
87+
"plot time in ms", this.selectedMoodDimension,
88+
data,
89+
PlotOrientation.VERTICAL,
90+
true,true,false);
91+
92+
this.chart = lineChart;
93+
}
94+
7795
public void deleteGraphData() {
7896
this.moodData.clear();
7997
}
@@ -83,11 +101,10 @@ public JFrame visualizeGraph() {
83101
}
84102

85103
public JFrame visualizeGraph(DefaultCategoryDataset data) {
86-
JFreeChart lineChart = createChart(data);
87-
88-
ChartPanel chartPanel = new ChartPanel(lineChart);
104+
// create line chart
105+
this.createChart(data);
106+
ChartPanel chartPanel = new ChartPanel(this.chart);
89107
chartPanel.setPreferredSize(new java.awt.Dimension( 560 , 367 ));
90-
this.setContentPane(chartPanel);
91108

92109
// create dropdown to select modd dimension
93110
JComboBox<String> moodDimensionList = new JComboBox<>(MOOD_DIMS);
@@ -99,12 +116,18 @@ public void actionPerformed(ActionEvent event) {
99116
String selectedDimension = (String) combo.getSelectedItem();
100117

101118
MoodGraph.getMoodListener().selectedMoodDimension = selectedDimension;
102-
MoodGraph.getMoodListener().setContentPane(new ChartPanel(MoodGraph.getMoodListener().createChart(data)));
103-
MoodGraph.getMoodListener().pack();
119+
MoodGraph.getMoodListener().createData();
120+
121+
((CategoryPlot) MoodGraph.getMoodListener().chart.getPlot()).getRangeAxis().setLabel(
122+
MoodGraph.getMoodListener().selectedMoodDimension
123+
);
124+
125+
MoodGraph.getMoodListener().repaint();
104126
}
105127
});
106128

107-
this.add(moodDimensionList);
129+
this.add(chartPanel, BorderLayout.CENTER);
130+
this.add(moodDimensionList, BorderLayout.SOUTH);
108131

109132
this.addWindowListener(new java.awt.event.WindowAdapter() {
110133
@Override
@@ -121,20 +144,6 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
121144
return this;
122145
}
123146

124-
private JFreeChart createChart(DefaultCategoryDataset data) {
125-
String title = this.selectedMoodDimension + " development over time";
126-
if (data.getRowCount() == 0)
127-
title = "No mood points have been reported to MoodGraph";
128-
129-
JFreeChart lineChart = ChartFactory.createLineChart(
130-
title,
131-
"plot time in ms", this.selectedMoodDimension,
132-
data,
133-
PlotOrientation.VERTICAL,
134-
true,true,false);
135-
136-
return lineChart;
137-
}
138147

139148
private void addMoodPoint(Double value, Long time, String agName) {
140149
this.moodData.addValue(value, agName, time);

0 commit comments

Comments
 (0)