Skip to content

Commit

Permalink
Einige Verbesserungen und die Möglichkeit, Wahlzeilen mehrfach zu def…
Browse files Browse the repository at this point in the history
…inieren. KonfliktRegeln werden nun auch in der Leistungs-/Prüfungsfach-Auswahl angewandt.
  • Loading branch information
heinrich26 committed Jan 28, 2024
1 parent b1d33f9 commit a33a375
Show file tree
Hide file tree
Showing 42 changed files with 518 additions and 548 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/kurswahlApp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

192 changes: 100 additions & 92 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/assets/drawables/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/drawables/home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 1 addition & 26 deletions app/assets/drawables/info_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/drawables/person.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/drawables/task_check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ plugins {
dependencies {
implementation project(':lib')

implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.16.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1'
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'com.github.lgooddatepicker:LGoodDatePicker:11.2.1'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/gui/AusgabeLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AusgabeLayout(fachData: FachData, wahlData: KurswahlData) : JPanel(GridBag
alignmentX = 0f
border = TitledBorder(RoundedBorder(8), R.getString("your_infos"))
}
feldPanel.add(JLabel("${R.getString("type_of_pk5")}: <b>${wahlData.pf5_typ.repr}</b>".wrapHtml()))
feldPanel.add(JLabel("${R.getString("type_of_pk5")}: <b>${wahlData.pf5Typ.repr}</b>".wrapHtml()))

// Wahlzeile
feldPanel.add(JLabel("${R.getString("wahlzeile")}: <b>${wahlData.wahlzeile}</b>".wrapHtml()))
Expand All @@ -157,7 +157,7 @@ class AusgabeLayout(fachData: FachData, wahlData: KurswahlData) : JPanel(GridBag
)

feldPanel.add(
JLabel("${R.getString("nationality")}: <b>${wahlData.staatsangehoerigkeit}</b>".wrapHtml())
JLabel("${R.getString("nationality")}: <b>${Locale(Locale.getDefault().language, wahlData.staatsangehoerigkeit).displayCountry}</b>".wrapHtml())
)

checkboxPanel.add(feldPanel)
Expand Down
46 changes: 1 addition & 45 deletions app/src/main/kotlin/gui/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@

package com.kurswahlApp.gui

import com.kurswahlApp.getResourceURL
import java.awt.*
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.geom.AffineTransform
import java.awt.geom.Path2D
import java.io.File
import java.net.URL
import javax.swing.ImageIcon
import javax.swing.JComboBox
import javax.swing.JComponent
import kotlin.system.measureNanoTime

/**
* Fügt den [Component] zu dem [Container] mit [GridBagLayout] hinzu
Expand Down Expand Up @@ -146,51 +142,11 @@ operator fun Dimension.component2() = height

fun Path2D.scale(sx: Double, sy: Double): Shape = createTransformedShape(AffineTransform.getScaleInstance(sx, sy))

fun <R> measureNanos(block: () -> R): R {
val result: R
println(measureNanoTime { result = block() })
return result
}

fun File.withExtension(ext: String): File = File(this.parentFile, "$nameWithoutExtension.$ext")

/**
* Öffnet eine Webseite im Browser
*/
fun openWebpage(url: URL): Boolean {
val desktop = if (Desktop.isDesktopSupported()) Desktop.getDesktop() else null
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(url.toURI())
return true
} catch (_: Exception) {
}
}
return false
}

fun Color.hexString() = "#${Integer.toHexString(rgb and 0x00ffffff)}"

fun img(src: String, alt: String? = null) =
if (alt != null) "<img src='${getResourceURL(src)}' alt='$alt'/>" else "<img src='${getResourceURL(src)}'/>"

fun img(src: String, width: Int, height: Int, alt: String? = null) =
if (alt != null)
"<img src='${getResourceURL(src)}' alt='$alt' width='$width' height='$height'/>"
else
"<img src='${getResourceURL(src)}' width='$width' height='$height'/>"

@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST", "UsePropertyAccessSyntax")
val <E> JComboBox<E>.selectedItem: E?
get() = this.getSelectedItem() as E?

/** Erstellt ein [ImageIcon] mit dem gegebenen [path] und einer optionalen [description]. */
fun createImageIcon(path: String, description: String? = null): ImageIcon? {
val imgURL: URL? = getResourceURL(path)
return if (imgURL != null) {
ImageIcon(imgURL, description)
} else {
System.err.println("Couldn't find file: $path")
null
}
}
5 changes: 4 additions & 1 deletion app/src/main/kotlin/gui/Fremdsprachen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Fremdsprachen(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
}
}

//#region Selection Components
private val fsJahr1: SpinnerNumberModel
private val fsJahr2: SpinnerNumberModel
private val fsJahr3: SpinnerNumberModel
Expand All @@ -55,6 +56,7 @@ class Fremdsprachen(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
private val wpf2: FachComboBox

private val klasse: JComboBox<String?>
//#endregion

init {
val container1 = JPanel(GridBagLayout())
Expand Down Expand Up @@ -228,7 +230,8 @@ class Fremdsprachen(wahlData: KurswahlData, fachData: FachData, notifier: (Boole

add(container1, row = 0, fill = GridBagConstraints.BOTH)
add(container2, row = 1, fill = GridBagConstraints.BOTH)
add(container3, row = 2, fill = GridBagConstraints.BOTH)

if (fachData.klassen.isNotEmpty()) add(container3, row = 2, fill = GridBagConstraints.BOTH)
add(Box.createHorizontalStrut(200), row = 0, column = 0)
}

Expand Down
24 changes: 19 additions & 5 deletions app/src/main/kotlin/gui/GrundkursWahl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
}
}
}

checkAndNotify()
})

label.addComponentListener(object : ComponentAdapter() {
Expand Down Expand Up @@ -200,6 +202,8 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
invalidRows++
label.foreground = Consts.COLOR_ERROR
}

checkAndNotify()
}

add(
Expand Down Expand Up @@ -239,6 +243,13 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
fun count(): Int = toWahlmoeglichkeit()?.n ?: 0
}

private fun checkAndNotify(invalidate: Boolean = false) {
notifier.invoke((invalidRows == 0) and checkData())
if (invalidate) {
regelLabelArray.forEach { invalidate() }
}
}

private fun checkData(): Boolean {
val data = close()
data.lock()
Expand Down Expand Up @@ -335,17 +346,12 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole

private val checkboxPanel = ScrollablePanel(GridBagLayout()).apply { setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT) }

private val checkButton = JButton("Überprüfen")

private val regelPanel = ScrollablePanel(null)

init {
add(anzahlLabel, row = 1)
add(anzahlInfoLabel, row = 1, column = 0, columnspan = 3)

checkButton.addActionListener { notifier.invoke((invalidRows == 0) and checkData()) }
add(checkButton, row = 1, column = 2, anchor = GridBagConstraints.EAST)

buildCheckboxes()

val scrollPane =
Expand Down Expand Up @@ -405,7 +411,9 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
/**
* Erstellt Checkboxen mit Labels und versteckt jene, die der Schüler nicht wählen kann
*/
@Suppress("ConvertArgumentToSet")
private fun buildCheckboxes() {
wahlData.lock()
// fremdsprachen & wpfs holen
val fs = wahlData.fremdsprachen.map(Pair<Fach, *>::first)

Expand Down Expand Up @@ -438,6 +446,10 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
var af = Int.MIN_VALUE
var offset = 1

val versteckte = fachData.regeln.filterIsInstance<KonfliktRegel>().mapNotNull {
it.wildcardMembers.takeIf { m -> m.any { f -> f in wahlData.pfs } }
}.flatten().minus(wahlData.pfs)

for ((i, fach) in fachData.faecher.withIndex()) {
/* TODO Umsetzen:
VO-GO Berlin - § 20 Kurse und Kursfolgen, Nr.2
Expand All @@ -446,6 +458,7 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
worden sein müssen. (Schlussfolgerung aus Satz 1, da nicht definiert, wvl.
Wochenstunden eine neue Fremdsprache in Sek II hätte) */
if (!fach.isKurs
|| fach in versteckte
|| fach.isFremdsprache && fach !in fs
|| !fach.checkKlasse(wahlData.klasse)
|| (!fach.isGk && fach !in wahlData.lks)
Expand Down Expand Up @@ -480,6 +493,7 @@ class GrundkursWahl(wahlData: KurswahlData, fachData: FachData, notifier: (Boole
weightx = 1.0
)
}
wahlData.unlock()
}

/**
Expand Down
Loading

0 comments on commit a33a375

Please sign in to comment.