source: src/main/java/genius/gui/progress/MultiPartyTournamentProgressUI.java@ 346

Last change on this file since 346 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package genius.gui.progress;
2
3import java.awt.BorderLayout;
4import java.awt.Panel;
5
6import javax.swing.JLabel;
7import javax.swing.JPanel;
8import javax.swing.JProgressBar;
9import javax.swing.JScrollPane;
10import javax.swing.JTable;
11
12import genius.core.events.NegotiationEvent;
13import genius.core.events.TournamentEndedEvent;
14import genius.core.events.TournamentSessionStartedEvent;
15import genius.core.listener.Listener;
16
17@SuppressWarnings("serial")
18public class MultiPartyTournamentProgressUI extends Panel implements Listener<NegotiationEvent> {
19
20 Progress progress = new Progress();
21
22 DataKeyTableModel model;
23
24 /**
25 * @param m
26 * the {@link DataKeyTableModel} that holds the table to be
27 * logged.
28 */
29 public MultiPartyTournamentProgressUI(DataKeyTableModel m) {
30 model = m;
31 setLayout(new BorderLayout());
32
33 add(progress, BorderLayout.NORTH);
34
35 // table must be inside scrollpane, otherwise the headers do not show.
36 JTable resultsTable = new JTable(model);
37 resultsTable.setShowGrid(true); // no effect?
38 resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
39 JScrollPane tableScrollPane = new JScrollPane(resultsTable);
40
41 add(tableScrollPane, BorderLayout.CENTER);
42 }
43
44 /***************
45 * implements Listener
46 *********************/
47
48 // we only listen to update the progress bar. The model updates itself.
49 @Override
50 public void notifyChange(NegotiationEvent e) {
51 if (e instanceof TournamentEndedEvent) {
52 progress.finish();
53 } else if (e instanceof TournamentSessionStartedEvent) {
54 TournamentSessionStartedEvent e1 = (TournamentSessionStartedEvent) e;
55 progress.update(e1.getCurrentSession(), e1.getTotalSessions());
56 }
57
58 }
59}
60
61/**
62 * progress panel, shows progress bar and text n/N
63 *
64 */
65@SuppressWarnings("serial")
66class Progress extends JPanel {
67 private final int SCALE = 1000000;
68 private JProgressBar progressbar = new JProgressBar(0, SCALE);
69 private JLabel label = new JLabel("starting tournament");
70
71 public Progress() {
72 setLayout(new BorderLayout());
73 add(label, BorderLayout.EAST);
74 add(progressbar, BorderLayout.CENTER);
75 }
76
77 /**
78 * Shows progress bar when n of total have been started. We are still
79 * working on the nth, even if it equals the total. Therefore the progress
80 * bar never will go exactly to 100%
81 *
82 * @param n
83 * @param total
84 */
85 public void update(int n, int total) {
86 progressbar.setValue(Math.min(SCALE - 1, (int) (SCALE * n / (total + 1))));
87 label.setText("" + n + "/" + total);
88 }
89
90 /**
91 * Set progress bar to 100% of total.
92 *
93 * @param total
94 */
95 public void finish() {
96 progressbar.setValue(SCALE);
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.