I am using the Gagawa (https://code.google.com/archive/p/gagawa/) library to dynamically create an HTML table to display school courses on a weekly schedule. The problem is that, because I'm using rowspan to increase the size of a cell based on the course's duration, when I try to, for example add a course that meets on MWF, the typical layout for the row would be
<td>...content...</td> <td></td> <td>...content...</td> <td></td> <td>...content...</td>
But, if 2 courses overlap in time but are on different days, inserting the blank <td>
element is forced to the right, because <td>
for the other course already exists in the next column. See the attached screenshot for more clarification (I've drawn arrows on it in red to show what the correct layout should be; ANT210.101 should be on MWF, but I'm trying to insert a blank <td>
where the bottom half of the first ANT220.102 block it, so it gets put to the right of it).
I either need a way to dynamically detect whether or not to put in the blank <td>
or a way to make it to that instead of getting shifted right, it gets shifted down (maybe there's a way to do this in CSS?).
Below is my code to dynamically generate the HTML table:
public String generateHTMLScheduleTable(Schedule s){
Table scheduleTable=new Table();
scheduleTable.setCSSClass("scheduleTable");
Tr dayRow=new Tr();
Th time=new Th(); time.appendText("Time");
Th mon=new Th(); mon.appendText("Monday");
Th tue=new Th(); tue.appendText("Tuesday");
Th wed=new Th(); wed.appendText("Wednesday");
Th th=new Th(); th.appendText("Thursday");
Th fri=new Th(); th.appendText("Friday");
dayRow.appendChild(time, mon, tue, wed, th, fri);
TreeMap<Integer, String> colors=mapCoursesToColors(s);
String[] days={"m", "t", "w", "r", "f"};
for(int j=8; j<=22; j++){
int timeInt=j%12;
if(timeInt==0){
timeInt=12;
}
String timeHr="" + timeInt;
//System.out.println(timeHr);
String amPm;
if(j>11){
amPm="PM";
}
else{
amPm="AM";
}
for(int k=0; k<2; k++){
String timeMin="";
if(k==0){
timeMin="00";
}
else{
timeMin="30";
}
Tr currRow=new Tr();
Td currCell=new Td();
currCell.appendText(timeHr + ":" + timeMin + amPm);
currRow.appendChild(currCell);
for(int i=0; i<days.length; i++){
Td newCell=new Td();
for(Course c : s.getCourses()){
if((c.getTime().substring(0, c.getTime().indexOf(':')).equals(timeHr) || c.getTime().substring(0, c.getTime().indexOf(':')).equals("0" + timeHr)) && c.getTime().substring(0, c.getTime().indexOf('-')).contains(timeMin) && c.getTime().substring(0, c.getTime().indexOf('-')).contains(amPm)){
if(c.getDays().toLowerCase().contains(days[i])){
String currentColor=colors.get(c.getCRN());
String timeLastHalf=c.getTime().substring(c.getTime().indexOf('-')+1);
int startHr=Integer.parseInt(timeHr);
int endHr=Integer.parseInt(timeLastHalf.substring(0, timeLastHalf.indexOf(':')));
int numCells=endHr-startHr;
numCells=numCells*2;
if(!c.getTime().substring(0, c.getTime().indexOf('-')).contains("00")){
if(timeLastHalf.contains("00")){
numCells=numCells-1;
}
}
else{
if(!timeLastHalf.contains("00")){
numCells=numCells+1;
}
}
if(numCells<2){
numCells=2;
}
newCell.setBgcolor(currentColor);
newCell.setRowspan("" + numCells);
newCell.appendText(c.getTitle());
newCell.appendChild(new Br());
newCell.appendText(c.getCourseAndSection());
newCell.appendChild(new Br());
newCell.appendText(c.getTime());
Input submit=new Input();
submit.setType("submit");
submit.setCSSClass("btn");
submit.setName("" + c.getCRN());
submit.setValue("Remove");
Input moreInfo=new Input();
moreInfo.setType("submit");
moreInfo.setCSSClass("btn");
moreInfo.setName(c.getCRN() + "View");
moreInfo.setValue("More Info");
newCell.appendChild(new Br());
newCell.appendChild(submit);
newCell.appendChild(moreInfo);
}
}
}
currRow.appendChild(newCell);
}
scheduleTable.appendChild(currRow);
}
}
String html=scheduleTable.write();
System.out.println(html);
return html;
}