forked from IF-LK-2020/stundenplan
Uhrzeiten eingefügt und rotes Highliting des aktuellen Tages und der Aktuellen Stunde hinzugefügt.
Zum Testen muss die Systemzeit ggf. geändert werden.
This commit is contained in:
parent
d2a920b9fc
commit
073a25335f
|
@ -1,5 +1,6 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Stundenplan implements SelectionListener {
|
||||
|
@ -9,7 +10,7 @@ public class Stundenplan implements SelectionListener {
|
|||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws ParseException {
|
||||
// Setzen des "Look & Feel" des Programms
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
@ -29,7 +30,7 @@ public class Stundenplan implements SelectionListener {
|
|||
/**
|
||||
* Konstruktor des Hauptprogramms
|
||||
*/
|
||||
public Stundenplan() {
|
||||
public Stundenplan() throws ParseException {
|
||||
// Erstellen des GUIs
|
||||
gui = new StundenplanGUI();
|
||||
|
||||
|
@ -81,7 +82,7 @@ public class Stundenplan implements SelectionListener {
|
|||
// Neue Daten aus der Datenbank abfragen.
|
||||
// Hier gefakte Daten, die Struktur der Datenbank ist nicht vorgegeben.
|
||||
//dbc.executeStatement("SELECT 0,'Q2','405',kuerzel,0,0,'Informatik',-16711936 FROM lehrer WHERE kuerzel = '" + pNewValue + "'");
|
||||
dbc.executeStatement("SELECT blocknummer, raum, name, wochentag, kuerzel, Fach FROM Stunden JOIN klassen ON Stunden.klassen_id = klassen.id JOIN unterrichtet ON unterrichtet.Stundenid = Stunden.id WHERE kuerzel = \""+pNewValue+"\"");
|
||||
dbc.executeStatement("SELECT blocknummer, raum, name, wochentag, kuerzel, Fach, stundenbeginn, stundendende FROM Stunden JOIN klassen ON Stunden.klassen_id = klassen.id JOIN unterrichtet ON unterrichtet.Stundenid = Stunden.id JOIN tagesblocks ON blocknr = blocknummer WHERE kuerzel = \""+pNewValue+"\"");
|
||||
QueryResult r = dbc.getCurrentQueryResult();
|
||||
// Falls es ein Ergebnis gibt ...
|
||||
if (r != null) {
|
||||
|
@ -89,14 +90,13 @@ public class Stundenplan implements SelectionListener {
|
|||
|
||||
// Neue Stunden in die GUI schreiben
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
System.out.println("a");
|
||||
int wochentag = getWochentag(r,i);
|
||||
gui.addLesson(
|
||||
|
||||
wochentag, // Spalte im Plan (0=Montag, ... ,4=Freitag)
|
||||
Integer.parseInt(data[i][0])-1, // Zeile im Plan (0=1. Stunde, ... ,9=10. Stunde)
|
||||
data[i][5], // Titel
|
||||
"Raum " + data[i][1], // Untertitel
|
||||
"Raum " + data[i][1] + " | " + data[i][6] + " - " + data[i][7], // Untertitel
|
||||
data[i][4], // Beschreibungstext
|
||||
data[i][3], // Fußzeile
|
||||
new Color(colors(data,i)) // Farbe (Objekt der Klasse Color)
|
||||
|
@ -109,14 +109,13 @@ public class Stundenplan implements SelectionListener {
|
|||
}
|
||||
}
|
||||
if (pList == "Klasse"){
|
||||
dbc.executeStatement("SELECT blocknummer, raum, name, wochentag, kuerzel, Fach FROM Stunden JOIN klassen ON Stunden.klassen_id = klassen.id JOIN unterrichtet ON unterrichtet.Stundenid = Stunden.id WHERE name = \""+pNewValue+"\"");
|
||||
dbc.executeStatement("SELECT blocknummer, raum, name, wochentag, kuerzel, Fach, stundenbeginn, stundendende FROM Stunden JOIN klassen ON Stunden.klassen_id = klassen.id JOIN unterrichtet ON unterrichtet.Stundenid = Stunden.id JOIN tagesblocks ON blocknr = blocknummer WHERE name = \""+pNewValue+"\"");
|
||||
QueryResult r = dbc.getCurrentQueryResult();
|
||||
if (r != null) {
|
||||
String[][] data = r.getData();
|
||||
|
||||
// Neue Stunden in die GUI schreiben
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
System.out.println(Arrays.toString(r.getData()[i]));
|
||||
int wochentag = getWochentag(r,i);
|
||||
gui.addLesson(
|
||||
|
||||
|
@ -124,7 +123,7 @@ public class Stundenplan implements SelectionListener {
|
|||
Integer.parseInt(data[i][0])-1, // Zeile im Plan (0=1. Stunde, ... ,9=10. Stunde)
|
||||
//Integer.parseInt(t.getData()[i][0])-1,
|
||||
data[i][5], // Titel
|
||||
"Raum " + data[i][1], // Untertitel
|
||||
"Raum " + data[i][1] + " | " + data[i][6] + " - " + data[i][7], // Untertitel
|
||||
data[i][4], // Beschreibungstext
|
||||
data[i][2], // Fußzeile
|
||||
new Color(colors(data,i)) // Farbe (Objekt der Klasse Color)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.SQLOutput;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* GUI für das Stundenplanprogramm.
|
||||
|
@ -216,10 +216,6 @@ public class StundenplanGUI extends JFrame implements ActionListener {
|
|||
jpPlan.setLayout(new GridBagLayout());
|
||||
jpPlan.add(new JPanel());
|
||||
|
||||
DatabaseConnector dbc = new DatabaseConnector("", 0, "stundenplan.db", "", "");
|
||||
dbc.executeStatement("SELECT datum FROM Tage");
|
||||
QueryResult r = dbc.getCurrentQueryResult();
|
||||
|
||||
//Datum
|
||||
GregorianCalendar [] tage = new GregorianCalendar[7];
|
||||
GregorianCalendar g = new GregorianCalendar();
|
||||
|
@ -228,6 +224,8 @@ public class StundenplanGUI extends JFrame implements ActionListener {
|
|||
SimpleDateFormat datum = new SimpleDateFormat("dd.MM.yyyy");
|
||||
SimpleDateFormat tag = new SimpleDateFormat("dd");
|
||||
SimpleDateFormat wochentag = new SimpleDateFormat("EEEEEEEEEEEE");
|
||||
SimpleDateFormat uhrzeit = new SimpleDateFormat("HH:mm:ss");
|
||||
String heute = wochentag.format(d);
|
||||
System.out.println("current Date: " + datum.format(d));
|
||||
System.out.println("current Day: " + wochentag.format(d));
|
||||
/*
|
||||
|
@ -246,15 +244,36 @@ public class StundenplanGUI extends JFrame implements ActionListener {
|
|||
c.fill = GridBagConstraints.NONE;
|
||||
c.weightx = 0.5;
|
||||
c.weighty = 0.2;
|
||||
jpPlan.add(makeLabel("Montag "/*+r.getData()[0][0]*/, fHeader), c);
|
||||
Color color = new Color(0xf24e5e);
|
||||
JLabel mo = makeLabel("Montag ", fHeader);
|
||||
if(heute.equals("Montag")) {
|
||||
mo.setForeground(color);
|
||||
}
|
||||
jpPlan.add(mo, c);
|
||||
c.gridx++;
|
||||
jpPlan.add(makeLabel("Dienstag "/*+r.getData()[1][0]*/, fHeader), c);
|
||||
JLabel di = makeLabel("Dienstag ", fHeader);
|
||||
if(heute.equals("Dienstag")) {
|
||||
di.setForeground(color);
|
||||
}
|
||||
jpPlan.add(di, c);
|
||||
c.gridx++;
|
||||
jpPlan.add(makeLabel("Mittwoch "/*+r.getData()[2][0]*/, fHeader), c);
|
||||
JLabel mi = makeLabel("Mittwoch ", fHeader);
|
||||
if(heute.equals("Mittwoch")) {
|
||||
mi.setForeground(color);
|
||||
}
|
||||
jpPlan.add(mi, c);
|
||||
c.gridx++;
|
||||
jpPlan.add(makeLabel("Donnerstag "/*+r.getData()[3][0]*/, fHeader), c);
|
||||
JLabel don = makeLabel("Donnerstag ", fHeader);
|
||||
if(heute.equals("Donnerstag")) {
|
||||
don.setForeground(color);
|
||||
}
|
||||
jpPlan.add(don, c);
|
||||
c.gridx++;
|
||||
jpPlan.add(makeLabel("Freitag "/*+r.getData()[4][0]*/, fHeader), c);
|
||||
JLabel fr = makeLabel("Freitag ", fHeader);
|
||||
if(heute.equals("Freitag")) {
|
||||
fr.setForeground(color);
|
||||
}
|
||||
jpPlan.add(fr, c);
|
||||
|
||||
// Überschriften für die Zeilen (Stunden)
|
||||
c = new GridBagConstraints();
|
||||
|
@ -262,9 +281,30 @@ public class StundenplanGUI extends JFrame implements ActionListener {
|
|||
c.fill = GridBagConstraints.NONE;
|
||||
c.weightx = 0.2;
|
||||
c.weighty = 0.5;
|
||||
// Code um den Tag und die Aktuelle Stunde rot hervorzuheben
|
||||
String[][] blocks = getTagesblocks();
|
||||
|
||||
GregorianCalendar beginn = new GregorianCalendar();
|
||||
GregorianCalendar ende = new GregorianCalendar();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
beginn.set(beginn.HOUR_OF_DAY,Integer.parseInt(blocks[i][1].substring(0,2)));
|
||||
beginn.set(beginn.MINUTE,Integer.parseInt(blocks[i][1].substring(3,5)));
|
||||
|
||||
ende.set(beginn.HOUR_OF_DAY,Integer.parseInt(blocks[i][2].substring(0,2)));
|
||||
ende.set(beginn.MINUTE,Integer.parseInt(blocks[i][2].substring(3,5)));
|
||||
|
||||
c.gridy = i + 1;
|
||||
jpPlan.add(makeLabel((i + 1) + ". Stunde", fHeader), c);
|
||||
|
||||
if(g.after(beginn) && g.before(ende)) {
|
||||
JLabel current = makeLabel((i + 1) + ". Stunde", fHeader);
|
||||
current.setForeground(color);
|
||||
jpPlan.add(current, c);
|
||||
} else {
|
||||
jpPlan.add(makeLabel((i + 1) + ". Stunde", fHeader), c);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,6 +317,19 @@ public class StundenplanGUI extends JFrame implements ActionListener {
|
|||
return makeLabel(pLabel, fText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Tabelle Tagesblocks aus
|
||||
* @return
|
||||
*/
|
||||
private String[][] getTagesblocks(){
|
||||
DatabaseConnector dbc = new DatabaseConnector("", 0, "stundenplan.db", "", "");
|
||||
dbc.executeStatement("SELECT * FROM tagesblocks");
|
||||
QueryResult r = dbc.getCurrentQueryResult();
|
||||
System.out.println(r);
|
||||
if(r == null) return new String[0][0];
|
||||
return r.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt ein Text-Label mit der angegebenen Schrift und dem Text.
|
||||
* @param pLabel
|
||||
|
|
Loading…
Reference in New Issue