Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
View
10 client/swing-spectator/src/main/java/spectator/PointsPerMinuteCalculator.java
@@ -7,7 +7,9 @@
private static final long ONE_MINUTE = 60000;
private static final long UPDATE_INTERVAL = 10000;
- private static final int SMOOTHING_FACTOR = 6;
+
+ private static final int MIN_SMOOTHING_FACTOR = 5;
+ private static final int MAX_SMOOTHING_FACTOR = 17;
private static class ScoreSnapshot {
@@ -39,12 +41,12 @@ public void scoresAfterRound(Scores scores, int roundNumber) {
}
private void createCheckpoint(ScoreSnapshot currentScores) {
- ScoreSnapshot referenceScores = previousScores.peek();
- if (referenceScores != null) {
+ if (previousScores.size() >= MIN_SMOOTHING_FACTOR) {
+ ScoreSnapshot referenceScores = previousScores.peek();
calculatePointsPerMinute(referenceScores, currentScores);
}
previousScores.add(currentScores);
- while (previousScores.size() > SMOOTHING_FACTOR) {
+ while (previousScores.size() > MAX_SMOOTHING_FACTOR) {
previousScores.poll();
}
}
View
60 client/swing-spectator/src/main/java/spectator/SpectatorApplication.java
@@ -26,6 +26,7 @@
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.TimeSeriesCollection;
+import javax.swing.JSplitPane;
public class SpectatorApplication {
@@ -42,6 +43,7 @@
private JLabel lblHistorie;
private ChartPanel chartPanel;
private TimeSeriesCollection pointsPerMinute;
+ private JSplitPane splitPane;
/**
* Create the application.
@@ -51,12 +53,31 @@ public SpectatorApplication() {
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
new IncrementProgressBar(progressBar, 1), 1, 1,
TimeUnit.SECONDS);
+ }
+
+ public void show() {
+ // GraphicsDevice defaultScreen =
+ // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ // if (defaultScreen.isFullScreenSupported()) {
+ // frmMxchen.setUndecorated(true);
+ // defaultScreen.setFullScreenWindow(frmMxchen);
+ // }
+ frmMxchen.setVisible(true);
+ }
+
+ /**
+ * Initialize the contents of the frame.
+ */
+ private void initialize() {
+ frmMxchen = new JFrame();
+ frmMxchen.setTitle("Mäxchen!");
+ frmMxchen.setSize(800, 600);
+ frmMxchen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rightColumn = new JPanel();
rightColumn.setBackground(SystemColor.window);
rightColumn.setBorder(null);
- frmMxchen.getContentPane().add(rightColumn, BorderLayout.EAST);
- rightColumn.setLayout(new MigLayout("", "[400px]", "[15px][][][]"));
+ rightColumn.setLayout(new MigLayout("", "[grow,fill]", "[15px][][][]"));
scoresTableHeader = new JLabel("Warte auf ersten Punktestand...");
scoresTableHeader.setFont(new Font("Arial", Font.BOLD, 18));
rightColumn.add(scoresTableHeader, "cell 0 0,alignx left,aligny top");
@@ -78,38 +99,19 @@ public SpectatorApplication() {
scrollPane.setOpaque(false);
rightColumn.add(scrollPane, "cell 0 1");
- lblHistorie = new JLabel("Historie");
+ lblHistorie = new JLabel("Punkte pro Minute");
+ lblHistorie.setFont(new Font("Arial", Font.BOLD, 18));
rightColumn.add(lblHistorie, "cell 0 2");
pointsPerMinute = new TimeSeriesCollection();
- JFreeChart chart = ChartFactory.createTimeSeriesChart("Punkte pro Minute", "", "", pointsPerMinute , true, false, false);
+ JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "",
+ pointsPerMinute, true, false, false);
chartPanel = new ChartPanel(chart);
rightColumn.add(chartPanel, "cell 0 3");
- }
-
- public void show() {
- // GraphicsDevice defaultScreen =
- // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- // if (defaultScreen.isFullScreenSupported()) {
- // frmMxchen.setUndecorated(true);
- // defaultScreen.setFullScreenWindow(frmMxchen);
- // }
- frmMxchen.setVisible(true);
- }
-
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmMxchen = new JFrame();
- frmMxchen.setTitle("Mäxchen!");
- frmMxchen.setSize(800, 600);
- frmMxchen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
leftColumn = new JPanel();
leftColumn.setBackground(Color.WHITE);
leftColumn.setBorder(null);
- frmMxchen.getContentPane().add(leftColumn, BorderLayout.CENTER);
leftColumn.setLayout(new MigLayout("", "[][grow,fill]",
"[][grow,fill][]"));
@@ -131,6 +133,12 @@ private void initialize() {
progressBar.setValue(10);
progressBar.setMaximum(10);
leftColumn.add(progressBar, "cell 1 2,growx,aligny top");
+
+ splitPane = new JSplitPane();
+ splitPane.setResizeWeight(1.0);
+ splitPane.setLeftComponent(leftColumn);
+ splitPane.setRightComponent(rightColumn);
+ frmMxchen.getContentPane().add(splitPane, BorderLayout.CENTER);
}
private TableModel createScoreModel(Scores scores) {
@@ -177,5 +185,5 @@ public void run() {
public TimeSeriesCollection getPointsPerMinute() {
return pointsPerMinute;
}
-
+
}

No commit comments for this range

Something went wrong with that request. Please try again.