Skip to content
Binary file added bin/leaderboard.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/zacharyfox/rmonitor/entities/Competitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ private void messageUpdate(CompInfo message)
this.setLastName(message.getLastName());
this.setClassId(message.getClassId());

if (!"".equals(message.getNationality())) {
if (message.getNationality() != null && !message.getNationality().isEmpty()) {
this.setNationality(message.getNationality());
}

if (!"".equals(message.getAddInfo())) {
if (message.getAddInfo() != null && !message.getAddInfo().isEmpty()) {
this.setAddData(message.getAddInfo());
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/com/zacharyfox/rmonitor/entities/Race.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

//import com.zacharyfox.rmonitor.leaderboard.LeaderBoardTableModel;
import com.zacharyfox.rmonitor.message.ClassInfo;
import com.zacharyfox.rmonitor.message.CompInfo;
import com.zacharyfox.rmonitor.message.Heartbeat;
import com.zacharyfox.rmonitor.message.InitRecord;
import com.zacharyfox.rmonitor.message.LapInfo;
import com.zacharyfox.rmonitor.message.PassingInfo;
import com.zacharyfox.rmonitor.message.QualInfo;
Expand All @@ -20,6 +22,7 @@ public class Race
private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

private int competitorsVersion = 0;
private int resetCount = 0;
private Duration elapsedTime = new Duration();
private String flagStatus = "";
private int id = 0;
Expand All @@ -28,7 +31,7 @@ public class Race
private String name = "";
private Duration scheduledTime = new Duration();
private Duration timeOfDay = new Duration();
private Duration timeToGo = new Duration();
private Duration timeToGo = new Duration((float)0.001);
private Float trackLength = (float) 0.0;
private String trackName = "";

Expand Down Expand Up @@ -131,6 +134,16 @@ public void update(RMonitorMessage message)
RaceClass.update((ClassInfo) message);
} else if (message.getClass() == PassingInfo.class) {
Competitor.updateOrCreate(message);
} else if (message.getClass() == InitRecord.class) {
/* remove all rows from table */
setResetCount();
/* then remove competitors */
Competitor.reset();

setName("-");
setId(0);
setTrackName("-");
setLapsToGo(0);
} else {
System.out.println(message);
}
Expand Down Expand Up @@ -166,7 +179,7 @@ private void messageUpdate(RunInfo message)
name = "";
scheduledTime = new Duration();
timeOfDay = new Duration();
timeToGo = new Duration();
timeToGo = new Duration((float)0.001);
trackLength = (float) 0.0;
trackName = "";

Expand All @@ -193,6 +206,12 @@ private void setCompetitorsVersion()
this.competitorsVersion = this.competitorsVersion + 1;
changeSupport.firePropertyChange("competitorsVersion", this.competitorsVersion - 1, this.competitorsVersion);
}

private void setResetCount()
{
this.resetCount = this.resetCount + 1;
changeSupport.firePropertyChange("resetCount", this.resetCount - 1, this.resetCount);
}

private void setElapsedTime(Duration elapsedTime)
{
Expand Down
39 changes: 38 additions & 1 deletion src/com/zacharyfox/rmonitor/leaderboard/LeaderBoard.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.zacharyfox.rmonitor.leaderboard;

import java.awt.EventQueue;
import java.awt.Font;
import java.util.Enumeration;

import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource;

import com.zacharyfox.rmonitor.leaderboard.frames.ConnectFrame;
import com.zacharyfox.rmonitor.leaderboard.frames.MainFrame;
Expand All @@ -11,9 +16,41 @@ public class LeaderBoard
{
/**
* Launch the application.
* @throws UnsupportedLookAndFeelException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
*/
public static void main(String[] args)
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
{
float scale=1f;
UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

for (UIManager.LookAndFeelInfo info : looks) {

//if you want to change LaF to a spesific LaF,such as "GTK"
//put here a if statement like:
//if(info.getClassName().contains("GTK"))
UIManager.setLookAndFeel(info.getClassName());

UIDefaults defaults = UIManager.getDefaults();
Enumeration<Object> newKeys = defaults.keys();

while (newKeys.hasMoreElements()) {
Object obj = newKeys.nextElement();
Object current = UIManager.get(obj);
if (current instanceof FontUIResource) {
FontUIResource resource = (FontUIResource) current;
defaults.put(obj, new FontUIResource(resource.deriveFont(resource.getSize2D()*scale)));
// System.out.printf("%50s : %s\n", obj, UIManager.get(obj));
} else if (current instanceof Font) {
Font resource = (Font) current;
defaults.put(obj, resource.deriveFont(resource.getSize2D()*scale));
// System.out.printf("%50s : %s\n", obj, UIManager.get(obj));
}
}
}

try {
System.setProperty("apple.awt.fullscreenhidecursor","true");
System.setProperty("apple.laf.useScreenMenuBar", "true");
Expand Down
4 changes: 2 additions & 2 deletions src/com/zacharyfox/rmonitor/leaderboard/LeaderBoardTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ private void initColumns()
Integer smallColumnSize = 40;
Integer timeColumnSize = 100;

Integer[] smallColumns = {0, 1 , 2, 3, 5};
Integer[] timeColumns = {6, 7, 8, 9};
Integer[] smallColumns = {0, 1 , 2, 3, 7};
Integer[] timeColumns = {8, 9, 10, 11};

for (Integer column : smallColumns) {
this.getColumnModel().getColumn(column).setPreferredWidth(smallColumnSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,43 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
{
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
Duration fastestLap = Competitor.getFastestLap();
String columnName = table.getColumnName(column);
Boolean isLastTime = false;
Boolean isBestTime = false;
int numberColumnNumber = 2;
// TODO: This breaks if you reorder columns!!! Need to figure out how to do this with rowSorter and getModel
Duration competitorBestLap = Competitor.getInstance((String) table.getValueAt(row, 2)).getBestLap();
Competitor competitor;

if (column == 8 && value.equals(fastestLap)) {
for(int i=0;i<table.getColumnCount();i++) {
if(((String)table.getColumnName(i)).compareTo("#") == 0) {
numberColumnNumber = i;
}
}
try {
competitor = Competitor.getInstance((String) table.getValueAt(row, numberColumnNumber));
}
catch (Exception eee) {
return c;
}

if(competitor == null) {
return c;
}
Duration competitorBestLap = competitor.getBestLap();

if(columnName.compareTo("Last Time") == 0){
isLastTime = true;
}
if(columnName.compareTo("Best Time") == 0){
isBestTime = true;
}
if (isBestTime && value.equals(fastestLap)) {
c.setBackground(new Color(150, 0, 150));
c.setForeground(new Color(255, 255, 255));
} else if (column == 7 && value.equals(fastestLap)) {
} else if (isLastTime && value.equals(fastestLap)) {
c.setBackground(new Color(150, 0, 150));
c.setForeground(new Color(255, 255, 255));
} else if (column == 7 && value.equals(competitorBestLap)) {
} else if (isLastTime && value.equals(competitorBestLap)) {
c.setBackground(new Color(0, 150, 0));
c.setForeground(new Color(255, 255, 255));
} else {
Expand Down
18 changes: 15 additions & 3 deletions src/com/zacharyfox/rmonitor/leaderboard/LeaderBoardTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class LeaderBoardTableModel extends AbstractTableModel
{
private String[] columnNames = new String[] {
"Pos", "PIC", "#", "Class", "Name", "Laps", "Total Time", "Last Time", "Best Time", "Avg. Time"
"Pos", "PIC", "#", "Class", "Name", "Nat", "Add", "Laps", "Total Time", "Last Time", "Best Time", "Avg. Time"
};

private ArrayList<Object[]> data = new ArrayList<Object[]>();
Expand All @@ -20,7 +20,7 @@ public class LeaderBoardTableModel extends AbstractTableModel
public LeaderBoardTableModel()
{
super();
data.add(new Object[]{"", "", "", "", "", "", "", "", "", ""});
data.add(new Object[]{"", "", "", "", "", "", "", "", "", "", "", ""});
}

@Override
Expand Down Expand Up @@ -74,12 +74,24 @@ public void updateData()
data = rows;
fireTableDataChanged();
}

public void removeAllRows() {
int count = getRowCount();

fireTableRowsDeleted(0,count-1);

ArrayList<Object[]> rows = new ArrayList<Object[]>();
for (@SuppressWarnings("unused") Competitor competitor : Competitor.getInstances().values()) {
rows.add(new Object[]{"", "", "", "", "", "", "", "", "", "", "", ""});
}
data = rows;
}

private Object[] getRow(Competitor competitor)
{
return new Object[] {
competitor.getPosition(), competitor.getPositionInClass(), competitor.getRegNumber(), RaceClass.getClassName(competitor.getClassId()),
competitor.getFirstName() + " " + competitor.getLastName(), competitor.getLapsComplete(),
competitor.getFirstName() + " " + competitor.getLastName(), competitor.getNationality(), competitor.getAddData(), competitor.getLapsComplete(),
competitor.getTotalTime(), competitor.getLastLap(), competitor.getBestLap(), competitor.getAvgLap(), ""
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.zacharyfox.rmonitor.leaderboard.frames;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

Expand All @@ -22,6 +25,7 @@ private ConnectFrame(MainFrame mainFrame)
{
getContentPane().setLayout(new MigLayout("", "[][grow]", "[][][]"));


ipLabel = new JLabel("Scoreboard IP:");
ipLabel.setHorizontalAlignment(SwingConstants.RIGHT);
getContentPane().add(ipLabel, "cell 0 0,alignx trailing");
Expand Down
Loading