use of course_generator.settings.CgSettings in project Course_Generator by patrovite.
the class ImportPtsRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
CgImportPts data = null;
CgSettings settings = ((ImportPtsDataModel) table.getModel()).getSettings();
setIcon(null);
data = (CgImportPts) value;
// Depending of the column number return the rendered label
switch(column) {
// return b;
case // Selection
0:
// -- Set the value
if (data.getSel())
setText("X");
else
setText("");
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(Color.WHITE);
return this;
case // Line
1:
// -- Set the value
setText(data.getLineString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(Color.WHITE);
return this;
case // Distance
2:
setText(data.getDistString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else {
double dist = data.getDist();
if (dist <= settings.DistNear)
setBackground(Color.GREEN);
else if (dist <= settings.DistFar)
setBackground(Color.ORANGE);
else
setBackground(Color.RED);
}
return this;
case // Latitude
3:
// -- Set the value
setText(data.getLatitudeString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 242, 193));
return this;
case // Longitude
4:
// -- Set the value
setText(data.getLongitudeString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 242, 193));
return this;
case // Elevation
5:
setText(data.getElevationString(settings.Unit, false));
setHorizontalAlignment(CENTER);
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(Color.WHITE);
return this;
case // Tags
6:
int tag = data.getTag();
// -- Count the number of active tag
int cmpt = 0;
int i = 1;
while (i < 65536) {
if ((tag & i) != 0)
cmpt++;
i = i * 2;
}
// X position in the resulting image
int x = 0;
if (cmpt > 0) {
// -- Prepare the resulting image
BufferedImage combined = new BufferedImage(18 * cmpt, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = combined.getGraphics();
// Higher point
if ((tag & CgConst.TAG_HIGH_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/high_point.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Lower point
if ((tag & CgConst.TAG_LOW_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/low_point.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Station
if ((tag & CgConst.TAG_EAT_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/eat.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Drink
if ((tag & CgConst.TAG_WATER_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/drink.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Mark
if ((tag & CgConst.TAG_MARK) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/flag.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Roadbook
if ((tag & CgConst.TAG_ROADBOOK) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/roadbook.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Photo
if ((tag & CgConst.TAG_COOL_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/photo.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Note
if ((tag & CgConst.TAG_NOTE) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/note.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Info
if ((tag & CgConst.TAG_INFO) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/info.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
setIcon(new ImageIcon(combined));
} else
// No image
setIcon(null);
// -- Set the value
setText("");
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Name
7:
// -- Set the value
setText(data.getName());
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Comment
8:
// -- Set the value
setText(data.getComment());
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
}
return this;
}
use of course_generator.settings.CgSettings in project Course_Generator by patrovite.
the class ResumeRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
CgResume data = (CgResume) value;
Double val = 0.0;
String str;
CgSettings settings = ((ResumeModel) table.getModel()).getSettings();
setIcon(null);
// Depending of the column number return the rendered label
switch(column) {
case // N°
0:
val = data.getNum();
// -- Display the value
setText(String.format("%1.0f ", val));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Name
1:
str = data.getName();
// -- Display the value
setText(str);
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Line
2:
val = data.getLine();
// -- Display the value
setText(String.format("%1.0f ", val));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Elevation
3:
setText(data.getElevationString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Positive climb
4:
setText(data.getClimbPString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Negative climb
5:
setText(data.getClimbMString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Distance
6:
setText(data.getDistString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Time
7:
setText(data.getTimeString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Hour
8:
setText(data.getHourString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // dt Time
9:
setText(data.getdTime_f_String());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Time limit
10:
setText(data.getTimeLimitString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Station Time
11:
setText(data.getStationTimeString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // dt Distance
12:
setText(data.getdDistString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // dt positive climb
13:
setText(data.getdClimbPString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // dt negative climb
14:
setText(data.getdClimbMString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Ascend speed
15:
setText(data.getSpeedPString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Descend speed
16:
setText(data.getSpeedMString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Average ascend slope
17:
setText(data.getAvgSlopePString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Average descend slope
18:
setText(data.getAvgSlopeMString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Average speed
19:
setText(data.getAvgSpeedString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Comment
20:
str = data.getComment();
// -- Display the value
// TODO Delete /n
setText(str);
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
}
return this;
}
use of course_generator.settings.CgSettings in project Course_Generator by patrovite.
the class TrackDataRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
CgData data = null;
CgSettings settings = ((TrackDataModel) table.getModel()).getSettings();
setIcon(null);
// Depending of the column number return the rendered label
switch(column) {
case // Num
0:
data = (CgData) value;
Double num = data.getNum();
// -- Set the value
setText(String.format("%1.0f ", num));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Latitude
1:
data = (CgData) value;
Double lat = data.getLatitude();
// -- Set the value
setText(String.format("%1.7f", lat));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 242, 193));
return this;
case // Longitude
2:
data = (CgData) value;
Double lon = data.getLongitude();
// -- Set the value
setText(String.format("%1.7f", lon));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 242, 193));
return this;
case // Elevation
3:
data = (CgData) value;
Double slope = data.getSlope();
setText(data.getElevationString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the icon next to the elevation value
if (slope > 1.0) {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/up_elev.png")));
} else if (slope < -1.0) {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/down_elev.png")));
} else
setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/same_level_elev.png")));
// -- Set the color of the background. Color depend of the slope
// value
float tmpslope = slope.floatValue();
Color c = Color.WHITE;
if (tmpslope > 2.0f) {
if (tmpslope > 50.0f)
tmpslope = 50.0f;
float vsl = 18.0f * tmpslope / 50.0f;
c = Color.getHSBColor((18.0f - vsl) / 100.0f, 1f, 1f);
} else if (tmpslope < -2.0f) {
tmpslope = -tmpslope;
if (tmpslope > 50.0f)
tmpslope = 50.0f;
/*
float vsl = 18f * tmpslope / 50.0f;
c = Color.getHSBColor((48f + vsl) / 100.0f, 1f, 1f);
*/
float vsl = 40f * tmpslope / 50.0f;
c = Color.getHSBColor(0.35f, 1f, (100f - vsl) / 100f);
} else
c = Color.WHITE;
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(c);
return this;
case // Tags
4:
data = (CgData) value;
int tag = data.getTag();
// -- Count the number of active tag
int cmpt = 0;
int i = 1;
while (i < 65536) {
if ((tag & i) != 0)
cmpt++;
i = i * 2;
}
// X position in the resulting image
int x = 0;
if (cmpt > 0) {
// -- Prepare the resulting image
BufferedImage combined = new BufferedImage(18 * cmpt, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = combined.getGraphics();
// Higher point
if ((tag & CgConst.TAG_HIGH_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/high_point.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Lower point
if ((tag & CgConst.TAG_LOW_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/low_point.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Station
if ((tag & CgConst.TAG_EAT_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/eat.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Drink
if ((tag & CgConst.TAG_WATER_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/drink.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Mark
if ((tag & CgConst.TAG_MARK) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/flag.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Roadbook
if ((tag & CgConst.TAG_ROADBOOK) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/roadbook.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Photo
if ((tag & CgConst.TAG_COOL_PT) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/photo.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Note
if ((tag & CgConst.TAG_NOTE) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/note.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
// Info
if ((tag & CgConst.TAG_INFO) != 0) {
ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/info.png"));
g.drawImage(image.getImage(), x, 0, null);
x += 18;
}
setIcon(new ImageIcon(combined));
} else
// No image
setIcon(null);
// -- Set the value
setText("");
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Distance
5:
data = (CgData) value;
setText(data.getDistString(settings.Unit, false));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Total distance
6:
data = (CgData) value;
Double total = data.getTotal(settings.Unit);
// -- Set the value
setText(String.format("%1.3f", total / 1000.0));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(221, 255, 155));
return this;
case // Difficulty
7:
data = (CgData) value;
Double diff = data.getDiff();
// -- Set the value
setText(String.format("%1.0f ", diff));
setHorizontalAlignment(CENTER);
// -- Set the background color
Color clDiff = Color.WHITE;
if ((diff <= CgConst.DIFF_VERYEASY) && (diff > CgConst.DIFF_EASY)) {
// Color.WHITE; //--
clDiff = CgConst.CL_DIFF_VERYEASY;
// paint in white
} else if ((diff <= CgConst.DIFF_EASY) && (diff > CgConst.DIFF_AVERAGE)) {
// new Color(170, 212, 0);
clDiff = CgConst.CL_DIFF_EASY;
// //-- Paint in green
} else if ((diff <= CgConst.DIFF_AVERAGE) && (diff > CgConst.DIFF_HARD)) {
// new Color(85, 153,
clDiff = CgConst.CL_DIFF_AVERAGE;
// 255); //-- Paint in
// blue
} else if ((diff <= CgConst.DIFF_HARD) && (diff > CgConst.DIFF_VERYHARD)) {
// new Color(255, 0, 0); //--
clDiff = CgConst.CL_DIFF_HARD;
// Paint in red
} else if (diff <= CgConst.DIFF_VERYHARD) {
// new Color(77, 77, 77);
clDiff = CgConst.CL_DIFF_VERYHARD;
// //-- Paint in gray
}
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(clDiff);
return this;
case // Coeff
8:
data = (CgData) value;
Double coeff = data.getCoeff();
// -- Set the value
setText(String.format("%1.1f ", coeff));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Recovery
9:
data = (CgData) value;
Double recup = data.getRecovery();
// -- Set the value
if (recup != 0) {
DecimalFormat myFormatter = new DecimalFormat("0.#");
String output = myFormatter.format(recup);
setText(output + " ");
} else
setText("");
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Time
10:
data = (CgData) value;
// -- Set the value
setText(data.getTimeString());
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Time limit
11:
data = (CgData) value;
int timelimit = data.getTimeLimit();
int time1 = data.getTime();
// -- Set the value
setText(data.getTimeLimitString(true));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else {
if ((timelimit != 0) && (time1 > timelimit))
setBackground(Color.PINK);
else
setBackground(Color.WHITE);
}
return this;
case // Hour
12:
TrackData track = (TrackData) value;
DateTime hour = track.data.get(row).getHour();
// -- Set the value
setText(hour.toString("E HH:mm:ss "));
setHorizontalAlignment(CENTER);
// -- Set the background color
// Color.LightGreen;
Color clHour = new Color(221, 255, 155);
int ts_val = hour.getSecondOfDay();
int ts_start = track.StartNightTime.getSecondOfDay();
int ts_end = track.EndNightTime.getSecondOfDay();
if ((track.bNightCoeff) && ((ts_val > ts_start) || (ts_val < ts_end)))
// 95,158,160); //CadetBlue;
clHour = new Color(0, 128, 255);
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(clHour);
return this;
case // Station time
13:
data = (CgData) value;
// -- Set the value
setText(data.getStationString(true));
setHorizontalAlignment(CENTER);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Name
14:
data = (CgData) value;
// -- Set the value
setText(data.getName());
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
case // Comment
15:
data = (CgData) value;
// -- Set the value
setText(data.getComment());
setHorizontalAlignment(LEFT);
// -- Set the background
if (isSelected)
setBackground(CgConst.CL_LINE_SELECTION);
else
setBackground(new Color(255, 255, 255));
return this;
}
return this;
}
Aggregations