return (Manners2009) solutionBusiness.getSolution();
}
public void resetPanel() {
removeAll();
Manners2009 manners2009 = getManners2009();
gridLayout.setColumns((int) Math.ceil(Math.sqrt(manners2009.getTableList().size())));
Map<Table, JPanel> tablePanelMap = new HashMap<Table, JPanel>(manners2009.getTableList().size());
Map<Seat, SeatPanel> seatPanelMap = new HashMap<Seat, SeatPanel>(manners2009.getSeatList().size());
for (Table table : manners2009.getTableList()) {
// Formula: 4(columns - 1) = tableSize
int edgeLength = (int) Math.ceil(((double) (table.getSeatList().size() + 4)) / 4.0);
JPanel tablePanel = new JPanel(new GridLayout(0, edgeLength));
tablePanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(5, 5, 5, 5),
BorderFactory.createTitledBorder("Table " + table.getTableIndex())
));
add(tablePanel);
tablePanelMap.put(table, tablePanel);
for (int y = 0; y < edgeLength; y++) {
for (int x = 0; x < edgeLength; x++) {
int index;
if (y == 0) {
index = x;
} else if (x == (edgeLength - 1)) {
index = (edgeLength - 1) + y;
} else if (y == (edgeLength - 1)) {
index = 2 * (edgeLength - 1) + (edgeLength - 1 - x);
} else if (x == 0) {
index = 3 * (edgeLength - 1) + (edgeLength - 1 - y);
} else {
index = Integer.MAX_VALUE;
}
if (index < table.getSeatList().size()) {
Seat seat = table.getSeatList().get(index);
SeatPanel seatPanel = new SeatPanel(seat);
tablePanel.add(seatPanel);
seatPanelMap.put(seat, seatPanel);
} else {
tablePanel.add(new JPanel());
}
}
}
}
if (manners2009.isInitialized()) {
for (SeatDesignation seatDesignation : manners2009.getSeatDesignationList()) {
SeatPanel seatPanel = seatPanelMap.get(seatDesignation.getSeat());
seatPanel.addSeatDesignation(seatDesignation);
}
}
}