8 * Sample Scoreboard Client Abstract Class, extends {@link ScoreboardClient}.
10 public class SampleScoreboardClient
extends ScoreboardClient
{
11 // used by printRow to print out all the problem statistics
12 private long numProblems
=0;
14 private String fileName
=null;
15 private Object printingLock
=new Object();
17 * SampleScoreboardClient constructor comment.
18 * @exception java.rmi.RemoteException The exception description.
20 public SampleScoreboardClient() throws java
.rmi
.RemoteException
{
24 * handleClientRefresh method comment.
26 public void handleClientRefresh() {}
28 * Each time a new run is submitted to a PC<SUP>2</SUP> Server
29 * this method is called passing run information and files to this
32 * Note: one can extract the files from {@link RunInfoAndFiles} using
33 * {@link RunInfoAndFiles#writeUserFile(int,String)}
36 public void handleNewRun(RunInfoAndFiles run
) {}
38 * Each time a run is judged this method will be invoked with
39 * the run and judgement info.
42 public void handleRunJudged(RunInfoAndFiles run
, boolean isSolved
, String judgement
) {
46 * Invoked when run is judged
48 * @param run pc2.ex.RunInfoAndFiles
50 public void handleRunStatusUpdated(RunInfoAndFiles run
) {}
52 * Indicates when contest settings have changed
54 public void handleSettingsUpdated() {
58 * When a judge un checks out (returns a run without judging) this is invoked
60 * @see RunInfoAndFiles
61 * @param run pc2.ex.RunInfoAndFiles
63 public void handleUNCheckedOutRun(RunInfoAndFiles run
) {}
65 * Starts the application.
66 * @param args java.lang.String[]
68 public static void main(String
[] args
) {
69 SampleScoreboardClient sc
= null;
71 sc
= new SampleScoreboardClient();
72 } catch (Exception e
){
73 PC2Log
.message("error in new SampleClient()",e
);
76 // This sets the debug level for the log according to pc2v8.ini
77 if (new PC2ini().containsKey("client.debugLevel")) {
78 String temp
=PC2ini
.getKey("client.debugLevel");
80 int value
=new Integer(temp
).intValue();
81 PC2Log
.setDebugLevel(value
);
82 } catch (NumberFormatException nfe
) {
87 if (args
!= null && args
.length
> 0) {
90 String loginId
= "board1";
91 // siteId of 0 means any site
94 if (! sc
.loginToPC2("127.0.0.1", pc2
.PC2Constants
.DEFAULT_PC2_PORT
, 0, loginId
, loginId
))
96 PC2Log
.message("Could not login as "+loginId
);
97 JFrame frame
= new JFrame("Invisible JFrame... ooh");
98 JOptionPane
.showMessageDialog
101 "Could not login as "+loginId
,
103 JOptionPane
.INFORMATION_MESSAGE
108 } catch (Exception exc
) {
109 PC2Log
.message("Exception ",exc
);
113 // print scoreboard at start
115 String sentinel
= "stopboard";
116 PC2Log
.message("Create file named '"+sentinel
+"' to exit client.");
117 Thread loopy
= new Thread ();
122 // PC2Log.message("remaining "+(max-count));
125 java
.io
.File f
= new java
.io
.File(sentinel
);
129 System
.out
.println("found "+sentinel
+", exiting ");
135 } catch (Exception ex
) {
136 PC2Log
.message("Funny bugger aren't you ",ex
);
141 PC2Log
.message("Logged out.");
146 * Insert the method's description here.
147 * Creation date: (8/14/2002 3:29:52 PM)
148 * @param os java.io.PrintWriter
150 private void printHeader(PrintWriter os
) {
152 os
=new PrintWriter(System
.out
,true);
154 os
.println("<html>");
155 os
.println("<head><title>"+this.getClass().getName()+"</title><head>");
156 os
.println("<body>");
157 os
.println("<table>");
159 os
.print("<th><strong><u>Rank</u></strong></th>");
160 os
.print("<th><strong><u>Name</u></strong></th>");
161 os
.print("<th><strong><u>Solved</u></strong></th>");
162 os
.print("<th><strong><u>Score</u></strong></th>");
163 // now all per problem stuff
164 String alphabet
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
165 for(int j
=0;j
< numProblems
;j
++) {
166 os
.print("<th> <u><strong>"+alphabet
.charAt(j
% 26)+"</u></strong> </th>");
172 * Insert the method's description here.
173 * Creation date: (8/20/02 5:53:33 PM)
175 private void printHTML() {
177 synchronized (printingLock
) {
178 PC2Log
.message("print scoreboard begin");
179 ClientScoreData
[] sd
= null;
180 ProblemScoreData psd
= null;
181 PrintWriter pout
= null;
182 if (fileName
!= null) {
183 pout
= new PrintWriter(new FileOutputStream(fileName
), true);
185 pout
= new PrintWriter(System
.out
, true);
187 numProblems
= getNumProblems();
190 if (getNumTeamAccounts() > 0) {
194 PC2Log
.message("no standings ?!?");
196 for (int i
= 0; i
< sd
.length
; i
++) {
197 printRow(pout
, sd
[i
]);
200 PC2Log
.message("No teams defined");
203 PC2Log
.message("print scoreboard end");
205 } catch (Exception e
) {
206 PC2Log
.message("printHTML()", e
);
210 * Insert the method's description here.
211 * Creation date: (8/14/2002 3:29:52 PM)
212 * @param os java.io.PrintWriter
213 * @param csd pc2.ex.ClientScoreData
215 private void printRow(PrintWriter os
, ClientScoreData csd
) {
217 os
=new PrintWriter(System
.out
,true);
220 PC2Log
.message("printRow no ClientScoreData to print");
223 os
.print("<td>"+csd
.getRank()+"</td>");
224 os
.print("<td>"+csd
.getTeamName()+"</td>");
225 os
.print("<td>"+csd
.getNumberOfSolvedProblems()+"</td>");
226 os
.print("<td>"+csd
.getScore()+"</td>");
227 // now all per problem stuff
229 ProblemScoreData psd
=null;
230 for(int j
=1;j
<= numProblems
;j
++) {
231 psd
=csd
.getProblemScoreData(j
);
232 if (psd
.isSolved()) {
233 stats
=psd
.getAttempts()+"/"+psd
.getSolutionTime();
235 stats
=psd
.getAttempts()+"/--";
237 os
.print("<td>"+stats
+"</td>");
244 * Insert the method's description here.
245 * Creation date: (8/14/2002 3:29:52 PM)
246 * @param os java.io.PrintWriter
248 private void printTrailer(PrintWriter os
) {
250 os
=new PrintWriter(System
.out
,true);
252 os
.println("</table>");
253 os
.println("</body>");
254 os
.println("</html>");