public class SchulklasseGUI {
private Display display;
private Shell shell;
private Schulklasse schulklasse;
private Color color;
private void createDisplay() {
this.display = new Display();
}
private void createShell() {
this.shell = new Shell();
this.shell.setText("Schulklasse anzeigen");
this.shell.setSize(300, 500);
this.shell.setBackground(getColor());
this.shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
this.shell.setLayout(new GridLayout(4, false));
}
public void sleep() {
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
color.dispose();
}
public void open(Schule schule) {
createDisplay();
createShell();
getColor();
for (int i = 0; i < schule.schulklassen.size(); i++) {
createLabel(" Schulklasse: ");
createLabel(schule.getSchulklasse(i).getName());
Schulklasse schulklasse = schule.getSchulklasse(i);
this.schulklasse = schulklasse;
createLabel(" maximale Klassengröße: ");
createLabel(getmaxKlassenanzahl(i, schule));
createSchuelerTabelle();
createFaecherTabelle();
this.shell.open();
}
}
private Color getColor(){
this.color = new Color (this.display, 255,255,255);
return this.color;
}
private void createLabel(String text) {
Label label = new Label(this.shell, SWT.BORDER);
label.setText(text);
label.setLayoutData(new GridData());
}
private String getmaxKlassenanzahl(int i, Schule schule) {
int maxKlassenanzahl = schule.getSchulklasse(i).getSchuelerzahl();
String maxKlassenanzahlString = "" + maxKlassenanzahl;
return maxKlassenanzahlString;
}
private Table createSchuelerTabelle() {
final Table table = new Table(this.shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER
| SWT.FULL_SELECTION);
final TableColumn col1 = new TableColumn(table, SWT.LEFT);
GridData griddata = new GridData();
griddata.horizontalAlignment = SWT.FILL;
griddata.verticalAlignment = SWT.FILL;
griddata.horizontalSpan = 2;
table.setLayoutData(griddata);
col1.setText("Schüler");
col1.setWidth(80);
table.setHeaderVisible(true);
table.setLinesVisible(true);
for (int i = 0; i < schulklasse.getSchuelerzahl(); i++) {
if (schulklasse.schueler[i] != null) {
final TableItem item1 = new TableItem(table, 0);
item1.setText(new String[] { schulklasse.schueler[i].getVorname() + " "
+ schulklasse.schueler[i].getName() });
}
}
return table;
}
private Table createFaecherTabelle() {
final Table table = new Table(this.shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER
| SWT.FULL_SELECTION);
final TableColumn col1 = new TableColumn(table, SWT.LEFT);
GridData griddata = new GridData();
griddata.horizontalAlignment = SWT.FILL;
griddata.verticalAlignment = SWT.FILL;
griddata.horizontalSpan = 2;
table.setLayoutData(griddata);
col1.setText("Fächer");
col1.setWidth(80);
table.setHeaderVisible(true);
table.setLinesVisible(true);
for (int i = 0; i < schulklasse.faecher.size(); i++) {
if (schulklasse.faecher.get(i) != null) {
final TableItem item1 = new TableItem(table, 0);
item1.setText(new String[] { schulklasse.faecher.get(i).getName()});
}
}
return table;
}
}