Skip to content
Snippets Groups Projects
Commit 2d2b32ac authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist: Committed by Denis Zhidkikh
Browse files

Harrastustaulukko toimimaan Harrastus-luokan tietojen perusteella

parent 3bc7618f
No related branches found
No related tags found
No related merge requests found
1|1|Pitsin nypläys|1950|19
1|1|Pitsin nypläys|1950|18
2|1|Pitsin nypläys|1929|8
3|1|Pitsin nypläys|1972|23
4|1|Pitsin nypläys|1975|48
4|1|Pitsin nypläys|1975|23
5|2|Pitsin nypläys|1900|27
6|2|Pitsin nypläys|1943|18
7|3|Pitsin nypläys|1990|8
......
......@@ -19,10 +19,7 @@ import fi.jyu.mit.fxgui.TextAreaOutputStream;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import kerho.Harrastus;
......@@ -95,8 +92,8 @@ public class KerhoGUIController implements Initializable {
@FXML private void handleUusiJasen() {
uusiJasen();
}
@FXML private void handleMuokkaaJasen() {
muokkaa(kentta);
}
......@@ -140,6 +137,7 @@ public class KerhoGUIController implements Initializable {
private Kerho kerho;
private TextField[] edits;
private int kentta = 0;
private static Harrastus apuharrastus = new Harrastus();
/**
* Tekee tarvittavat muut alustukset, nyt vaihdetaan GridPanen tilalle
......@@ -160,6 +158,22 @@ public class KerhoGUIController implements Initializable {
edit.focusedProperty().addListener((a,o,n) -> kentta = getFieldId(edit,kentta));
}
// alustetaan harrastustaulukon otsikot
int eka = apuharrastus.ekaKentta();
int lkm = apuharrastus.getKenttia();
String[] headings = new String[lkm-eka];
for (int i=0, k=eka; k<lkm; i++, k++) headings[i] = apuharrastus.getKysymys(k);
tableHarrastukset.initTable(headings);
tableHarrastukset.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableHarrastukset.setEditable(false);
tableHarrastukset.setPlaceholder(new Label("Ei vielä harrastuksia"));
// Tämä on vielä huono, ei automaattisesti muutu jos kenttiä muutetaan.
tableHarrastukset.setColumnSortOrderNumber(1);
tableHarrastukset.setColumnSortOrderNumber(2);
tableHarrastukset.setColumnWidth(1, 60);
tableHarrastukset.setColumnWidth(2, 60);
tableHarrastukset.setEditable(false);
tableHarrastukset.setOnMouseClicked( e -> { if ( e.getClickCount() > 1 ) muokkaaHarrastusta(); } );
tableHarrastukset.setOnKeyPressed( e -> {if ( e.getCode() == KeyCode.F2 ) muokkaaHarrastusta();});
......@@ -267,11 +281,13 @@ public class KerhoGUIController implements Initializable {
private void naytaHarrastus(Harrastus har) {
String[] rivi = har.toString().split("\\|");
tableHarrastukset.add(har, rivi[2], rivi[3], rivi[4]); // TODO: KORJAAA
int kenttia = har.getKenttia();
String[] rivi = new String[kenttia-har.ekaKentta()];
for (int i=0, k=har.ekaKentta(); k < kenttia; i++, k++)
rivi[i] = har.anna(k);
tableHarrastukset.add(har,rivi);
}
/**
* Hakee jäsenten tiedot listaan. Jos jnr==0, aktivoidaan nykyjäsen
......
package kanta.test;
// Generated by ComTest BEGIN
import static org.junit.Assert.*;
import org.junit.*;
import kerho.Harrastus;
import kanta.*;
// Generated by ComTest END
/**
* Test class made by ComTest
* @version 2024.04.02 00:27:50 // Generated by ComTest
*
*/
@SuppressWarnings({ "PMD" })
public class TietueTest {
// Generated by ComTest BEGIN
/** testGetKenttia17 */
@Test
public void testGetKenttia17() { // Tietue: 17
Harrastus har = new Harrastus();
assertEquals("From: Tietue line: 20", 5, har.getKenttia());
} // Generated by ComTest END
// Generated by ComTest BEGIN
/** testEkaKentta29 */
@Test
public void testEkaKentta29() { // Tietue: 29
Harrastus har = new Harrastus();
assertEquals("From: Tietue line: 31", 2, har.ekaKentta());
} // Generated by ComTest END
// Generated by ComTest BEGIN
/** testGetKysymys41 */
@Test
public void testGetKysymys41() { // Tietue: 41
Harrastus har = new Harrastus();
assertEquals("From: Tietue line: 43", "ala", har.getKysymys(2));
} // Generated by ComTest END
// Generated by ComTest BEGIN
/** testAnna53 */
@Test
public void testAnna53() { // Tietue: 53
Harrastus har = new Harrastus();
har.parse(" 2 | 10 | Kalastus | 1949 | 22 t ");
assertEquals("From: Tietue line: 56", "2", har.anna(0));
assertEquals("From: Tietue line: 57", "10", har.anna(1));
assertEquals("From: Tietue line: 58", "Kalastus", har.anna(2));
assertEquals("From: Tietue line: 59", "1949", har.anna(3));
assertEquals("From: Tietue line: 60", "22", har.anna(4));
} // Generated by ComTest END
// Generated by ComTest BEGIN
/** testAseta73 */
@Test
public void testAseta73() { // Tietue: 73
Harrastus har = new Harrastus();
assertEquals("From: Tietue line: 75", "aloitusvuosi: Ei kokonaisluku (kissa)", har.aseta(3,"kissa"));
assertEquals("From: Tietue line: 76", null, har.aseta(3,"1940"));
assertEquals("From: Tietue line: 77", "h/vko: Ei kokonaisluku (kissa)", har.aseta(4,"kissa"));
assertEquals("From: Tietue line: 78", null, har.aseta(4,"20"));
} // Generated by ComTest END
// Generated by ComTest BEGIN
/**
* testClone89
* @throws CloneNotSupportedException when error
*/
@Test
public void testClone89() throws CloneNotSupportedException { // Tietue: 89
Harrastus har = new Harrastus();
har.parse(" 2 | 10 | Kalastus | 1949 | 22 t ");
Object kopio = har.clone();
assertEquals("From: Tietue line: 94", har.toString(), kopio.toString());
har.parse(" 1 | 11 | Uinti | 1949 | 22 t ");
assertEquals("From: Tietue line: 96", false, kopio.toString().equals(har.toString()));
assertEquals("From: Tietue line: 97", true, kopio instanceof Harrastus);
} // Generated by ComTest END
// Generated by ComTest BEGIN
/** testToString107 */
@Test
public void testToString107() { // Tietue: 107
Harrastus harrastus = new Harrastus();
harrastus.parse(" 2 | 10 | Kalastus | 1949 | 22 t ");
{ String _l_=harrastus.toString(),_r_="2\\|10\\|Kalastus\\|1949\\|22.*"; if ( !_l_.matches(_r_) ) fail("From: Tietue line: 110" + " does not match: ["+ _l_ + "] != [" + _r_ + "]");};
} // Generated by ComTest END
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
kanta.test.HetuTarkistusTest.class,
kanta.test.TietueTest.class,
kerho.test.JasenTest.class,
kerho.test.JasenetTest.class,
kerho.test.HarrastusTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment