Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
Closing #6
  • Loading branch information
manuel3108 committed Nov 2, 2017
1 parent 0b2048f commit 84dbd66
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 76 deletions.
107 changes: 49 additions & 58 deletions Plugin Gleisbelegung/src/com/gleisbelegung/plugin/Fenster.java
Expand Up @@ -48,15 +48,13 @@ public class Fenster extends Plugin_Gleisbelegung {
private ScrollBar scrollBarHeight; //Scroll-Balken um die Tabelle bewegen zu können
private Label firstLabel; //neues Label oben links mit Bahnhofs-Namen

private ArrayList<ArrayList<LabelContainer>> grid; //Speichert alle LabelContainer die die Tabell an sich darstellen
public ArrayList<LabelContainer> labelTime; //Speichert alle LabelContainer die eine Zeit anzeigen
private ArrayList<LabelContainer> labelPlatform; //Speichert alle LabelContainer die Bahnsteigsnamen enthalten
private ArrayList<Gleis> gleise;

//Erzeugt alle Listen und erzeugt die LabelContainer mit Informationen, welche vorher von der @VErbindungs-Klasse bereitgestellt werden
public Fenster() throws Exception {
grid = new ArrayList<>();
labelTime = new ArrayList<>();
labelPlatform = new ArrayList<>();
gleise = new ArrayList<>();

Date dNow = new Date(currentGameTime);
SimpleDateFormat ft = new SimpleDateFormat("HH:mm:ss");
Expand Down Expand Up @@ -253,6 +251,7 @@ public Fenster() throws Exception {

//prepare Grid
int progressCounter = 0;
erstelleGleise();

for (int i = 0; i < settingsVorschau; i++) {
labelTime.add(i, new LabelContainer(i, -1, labelTime));
Expand All @@ -271,18 +270,21 @@ public Fenster() throws Exception {
}

for (int i = 0; i < bahnsteige.length; i++) {
labelPlatform.add(i, new LabelContainer(i,-2, labelTime));
labelPlatform.get(i).updateLabel(bahnsteige[i]);
labelPlatform.get(i).getLabel().setStyle("-fx-text-fill: #fff; -fx-border-color: #505050; -fx-border-width: 0 1 5 0");
LabelContainer lc = new LabelContainer(i,-2, labelTime);
lc.updateLabel(bahnsteige[i]);
lc.getLabel().setStyle("-fx-text-fill: #fff; -fx-border-color: #505050; -fx-border-width: 0 1 5 0");

int temp = i;
Platform.runLater(() -> gpPlatform.add(labelPlatform.get(temp).getLabel(), temp, 0));
Platform.runLater(() -> gpPlatform.add(lc.getLabel(), temp, 0));

int tempCounter = progressCounter;
Platform.runLater(() -> progressHint.setText("Fortschritt: " + getPercentage(tempCounter, countAllLabelContainers) + "%"));
progressCounter++;

gleise.get(i).setGleisLabel(lc);
}

ArrayList<ArrayList<LabelContainer>> grid = new ArrayList<>();
for (int i = 0; i < settingsVorschau; i++) { //x
grid.add(i, new ArrayList<>());

Expand All @@ -299,6 +301,7 @@ public Fenster() throws Exception {

progressCounter++;
}

try {
Thread.sleep(50);
} catch (InterruptedException e) {
Expand All @@ -307,6 +310,16 @@ public Fenster() throws Exception {
labelIndexCounter = i;
}

//Bereite Gleise vor
for (int i = 0; i < grid.get(0).size(); i++) {
ArrayList<LabelContainer> t = new ArrayList<>();
for (ArrayList<LabelContainer> tempGrid : grid) {
t.add(tempGrid.get(i));
}
gleise.get(i).setSpalte(t);
}

grid.clear();

Platform.runLater(() -> progressHint.setText("Öffne Ansicht..."));
}
Expand Down Expand Up @@ -516,8 +529,8 @@ private void drawTrain(Zug z) throws Exception{
abfahrt = ankunft + 4*1000*60;
}

for (int k = 0; k < grid.size(); k++) {
LabelContainer lc = grid.get(k).get(j);
for (int k = 0; k < settingsVorschau; k++) {
LabelContainer lc = gleise.get(j).getSpalte().get(k);
if(ankunft <= lc.getTime() && abfahrt >= lc.getTime() - 1000*60){
z.getFahrplan(i).addDrawnTo(lc);

Expand All @@ -538,8 +551,8 @@ private void drawTrain(Zug z) throws Exception{
abfahrt = ankunft + 4*1000*60;
}

for (int k = 0; k < grid.size(); k++) {
LabelContainer lc = grid.get(k).get(j);
for (int k = 0; k < settingsVorschau; k++) {
LabelContainer lc = gleise.get(j).getSpalte().get(k);
if(ankunft <= lc.getTime() && abfahrt >= lc.getTime() - 1000*60){
z.getFahrplan(i).addDrawnTo(lc);

Expand Down Expand Up @@ -670,13 +683,15 @@ public void refreshGrid() throws Exception{
for (int i = 0; i < bahnsteige.length; i++) {
Platform.runLater(() -> {
gp.getChildren().remove(0);
//grid.remove()
});
}
Platform.runLater(() -> {
gpTime.getChildren().remove(0);
labelTime.remove(0);
grid.remove(0);

for(Gleis g : gleise){
g.getSpalte().remove(0);
}
});


Expand All @@ -686,28 +701,28 @@ public void refreshGrid() throws Exception{
LabelContainer lc = new LabelContainer(labelIndexCounter-1,-1, labelTime);
lc.updateLabel(ft.format(dNow));
Platform.runLater(() -> {
//lc.getLabel().setStyle(lc.getLabel().getStyle() + "-fx-border-width: 0 5 1 0; -fx-border-color: #505050");
gpTime.add(lc.getLabel(), 0, labelIndexCounter+1);
labelTime.add(labelTime.size(), lc);
});

ArrayList<LabelContainer> labelContainer = new ArrayList<>();
Platform.runLater(() -> {
try{
for(int i = 0; i < bahnsteige.length; i++){
for(int i = 0; i < gleise.size(); i++){
labelContainer.add(new LabelContainer(labelIndexCounter,i, labelTime));

gp.add(labelContainer.get(i).getLabel(), i+1, labelIndexCounter+1);
labelContainer.get(i).updateLabel("", currentGameTime + settingsVorschau*1000*60 - 2000);

if(bahnsteigeSichtbar[i]){
if(gleise.get(i).isSichtbar()){
labelContainer.get(i).getLabel().setPrefWidth(settingsGridWidth);
} else{
labelContainer.get(i).getLabel().setMaxWidth(0);
labelContainer.get(i).getLabel().setPrefWidth(0);
labelContainer.get(i).getLabel().setMinWidth(0);
}
//labelContainer.get(i).updateLabel();

if(gleise.get(i).getHebeHervor()) labelContainer.get(i).setHervorhebungDurchGleis(true);

}
} catch(Exception e){
Expand All @@ -717,7 +732,9 @@ public void refreshGrid() throws Exception{


Platform.runLater(() -> {
grid.add(labelContainer);
for(int i = 0; i < gleise.size(); i++){
gleise.get(i).getSpalte().add(labelContainer.get(i));
}
});

labelIndexCounter++;
Expand Down Expand Up @@ -858,7 +875,7 @@ private void settings() throws Exception {
cb[i].setTranslateX(tempX);
cb[i].setTranslateY(tempY);
cb[i].setFont(Font.font(18));
cb[i].setSelected(bahnsteigeSichtbar[i]);
cb[i].setSelected(this.gleise.get(i).isSichtbar());

if ((i + 1) % 3 == 0) {
stageHeight += 30;
Expand Down Expand Up @@ -917,10 +934,10 @@ private void settings() throws Exception {
} else{
for (int i = 0; i < cb.length; i++) {
if (cb[i].isSelected()) {
bahnsteigeSichtbar[i] = true;
this.gleise.get(i).setSichtbar(true);
showPlatform(i, true);
} else {
bahnsteigeSichtbar[i] = false;
this.gleise.get(i).setSichtbar(false);
showPlatform(i, false);
}
}
Expand Down Expand Up @@ -987,13 +1004,8 @@ private void writeSettings() throws Exception{

//Hier werden die geänderten Einstellungen auf die Gui angewendet
private void updateSettings() throws Exception{
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid.get(i).size(); j++) {
LabelContainer lc = grid.get(i).get(j);
lc.getLabel().setFont(Font.font(settingsFontSize-5));
lc.getLabel().setMaxWidth(settingsGridWidth);
lc.getLabel().setMinWidth(settingsGridWidth);
}
for(Gleis g : gleise){
g.setLabelContainerToWith(settingsGridWidth);
}

for (int i = 0; i < labelTime.size(); i++) {
Expand All @@ -1003,13 +1015,6 @@ private void updateSettings() throws Exception{
lc.getLabel().setMinWidth(settingsGridWidth);
}

for (int i = 0; i < labelPlatform.size(); i++) {
LabelContainer lc = labelPlatform.get(i);
lc.getLabel().setFont(Font.font(settingsFontSize-5));
lc.getLabel().setMaxWidth(settingsGridWidth);
lc.getLabel().setMinWidth(settingsGridWidth);
}

pluginName.setFont(Font.font(settingsFontSize));
simZeit.setFont(Font.font(settingsFontSize));
einstellungen.setFont(Font.font(settingsFontSize));
Expand All @@ -1023,29 +1028,9 @@ private void updateSettings() throws Exception{
//Ist ein Bahnsteig sichtbar oder nicht. Hier wird das esetzt
private void showPlatform(int index, boolean visible) throws Exception{
if(visible){
for (int i = 0; i < grid.size(); i++) {
Label l = grid.get(i).get(index).getLabel();
l.setMinWidth(settingsGridWidth);
l.setMaxWidth(settingsGridWidth);
}
labelPlatform.get(index).getLabel().setMaxWidth(settingsGridWidth);
labelPlatform.get(index).getLabel().setMinWidth(settingsGridWidth);
gleise.get(index).setLabelContainerToWith(settingsGridWidth);
} else{
for (int i = 0; i < grid.size(); i++) {
final int temp = i;
Platform.runLater(() -> {
Label l = grid.get(temp).get(index).getLabel();
l.setMaxWidth(0);
l.setPrefWidth(0);
l.setMinWidth(0);
});
}

Platform.runLater(() -> {
labelPlatform.get(index).getLabel().setMaxWidth(0);
labelPlatform.get(index).getLabel().setMinWidth(0);
labelPlatform.get(index).getLabel().setPrefWidth(0);
});
gleise.get(index).setLabelContainerToWith(0);
}
}

Expand All @@ -1056,4 +1041,10 @@ public void clearOldData(){
gpPlatform.getChildren().clear();
gp.getChildren().clear();
}

public void erstelleGleise(){
for (int i = 0; i < bahnsteige.length; i++) {
gleise.add(new Gleis(bahnsteige[i]));
}
}
}
86 changes: 86 additions & 0 deletions Plugin Gleisbelegung/src/com/gleisbelegung/plugin/Gleis.java
@@ -0,0 +1,86 @@
package com.gleisbelegung.plugin;

import javafx.application.Platform;
import java.util.ArrayList;

public class Gleis extends Plugin_Gleisbelegung {
private ArrayList<LabelContainer> spalte;
private LabelContainer gleisLabel;
private String gleisName;
private boolean sichtbar;
private boolean hervorgehoben;

public Gleis(String gleisName){
this.gleisName = gleisName;
this.sichtbar = true;

hervorgehoben = false;
}

public ArrayList<LabelContainer> getSpalte() {
return spalte;
}
public void setSpalte(ArrayList<LabelContainer> spalte) {
this.spalte = spalte;
}

public String getGleisName() {
return gleisName;
}
public void setGleisName(String gleisName) {
this.gleisName = gleisName;
}

public boolean isSichtbar() {
return sichtbar;
}
public void setSichtbar(boolean sichtbar) {
this.sichtbar = sichtbar;
}

public LabelContainer getGleisLabel() {
return gleisLabel;
}
public void setGleisLabel(LabelContainer gleisLabel) {
gleisLabel.getLabel().setOnMouseClicked(e -> hebeHervor());

this.gleisLabel = gleisLabel;
}

public void setLabelContainerToWith(int width){
for(LabelContainer lc : spalte){
Platform.runLater(() -> {
lc.getLabel().setMaxWidth(width);
lc.getLabel().setPrefWidth(width);
lc.getLabel().setMinWidth(width);
});
}

gleisLabel.getLabel().setMaxWidth(width);
gleisLabel.getLabel().setPrefWidth(width);
gleisLabel.getLabel().setMinWidth(width);
}

private void hebeHervor(){
if(hervorgehoben) {
gleisLabel.getLabel().setStyle(gleisLabel.getLabel().getStyle() + "; -fx-background-color: #303030");
for(LabelContainer lc : spalte){
lc.setHervorhebungDurchGleis(false);
}

hervorgehoben = false;
}
else {
gleisLabel.getLabel().setStyle(gleisLabel.getLabel().getStyle() + "; -fx-background-color: #181818");

for(LabelContainer lc : spalte){
lc.setHervorhebungDurchGleis(true);
}

hervorgehoben = true;
}
}
public boolean getHebeHervor(){
return hervorgehoben;
}
}
Expand Up @@ -26,13 +26,15 @@ public class LabelContainer extends Plugin_Gleisbelegung{
private long time = -1; //Die Zeit die in der jeweiligen Zeile die richtige ist.
private int bahnsteig; //int der mit dem Bahnsteig-Namen aus der @Main-Klasse einen Bahnsteigsnamen darstellt
private ArrayList<LabelContainer> labelTime; //Übergabe von labelTime aus der @Fenster-Klasse
private boolean hervorhebungDurchGleis;

//Speichert alle übergebenen Daten
public LabelContainer(int labelIndex, int bahnsteig, ArrayList<LabelContainer> labelTime) throws Exception{
this.labelTime = labelTime;
this.bahnsteig = bahnsteig;
this.labelIndex = labelIndex;
trains = new ArrayList<>();
hervorhebungDurchGleis = false;

l = new Label();
l.setFont(Font.font(settingsFontSize-5));
Expand Down Expand Up @@ -113,7 +115,9 @@ public void updateLabel() throws Exception{
Platform.runLater(() -> {
l.setText("");
l.setTooltip(null);
if (labelIndex % 2 == 0) {
if(hervorhebungDurchGleis){
l.setStyle("-fx-text-fill: #fff; " + prepareBorder() + "; -fx-background-color: #181818");
} else if (labelIndex % 2 == 0) {
l.setStyle("-fx-text-fill: #fff; " + prepareBorder());
} else {
l.setStyle("-fx-background-color: #292929; -fx-text-fill: #fff; " + prepareBorder());
Expand Down Expand Up @@ -142,9 +146,9 @@ public void updateLabel() throws Exception{
l.setTooltip(new Tooltip(temp));
l.setStyle("-fx-text-fill: #fff; " + prepareBorder() + "-fx-background-color: red;");

if (bahnsteigeSichtbar[bahnsteig]) {
/*if (bahnsteigeSichtbar[bahnsteig]) {
playColisonSound();
}
}*/
}
});
}
Expand Down Expand Up @@ -359,4 +363,13 @@ public void highlight() throws Exception{
};
new Thread(r).start();
}

public void setHervorhebungDurchGleis(boolean hervorhebungDurchGleis) {
this.hervorhebungDurchGleis = hervorhebungDurchGleis;
try {
updateLabel();
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 84dbd66

Please sign in to comment.