Skip to content
Permalink
Browse files
refactored index file loading + refactored RefreshListener
  • Loading branch information
Philipp Dargel committed Nov 28, 2018
1 parent 836a03a commit 83c8aed706c5c7d2679b9880846a8e5bc4158f9e
Showing 80 changed files with 3,342 additions and 3,357 deletions.
@@ -8,4 +8,5 @@
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
</configuration>

19 pom.xml
@@ -15,6 +15,7 @@
<project.build.mainClass>oc.OnlineCodex</project.build.mainClass>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jackson.version>2.9.0</jackson.version>
</properties>

<scm>
@@ -30,6 +31,11 @@
</issueManagement>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -55,6 +61,19 @@
<artifactId>github-api</artifactId>
<version>1.94</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
@@ -8,6 +8,9 @@
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;

import static oc.RefreshListener.Priority.ANZAHL_PANEL;
import static oc.RefreshListener.addRefreshListener;

public class AnzahlPanel extends OptionsVater implements KeyListener {

private int minModelle;
@@ -137,12 +140,7 @@ public void init(int ID, int lX, int lY, String name, int minModelle, int maxMod
this.panel.setLocation(lX, lY);
tModelle.addKeyListener(this);

new RefreshListener((byte) 1, ID) {
@Override
public void refresh() {
control();
}
};
addRefreshListener(ANZAHL_PANEL, ID, this::control);
}

public void produceButtons() {
@@ -1,5 +1,9 @@
package oc;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@@ -18,6 +22,7 @@
import java.io.*;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;

public abstract class BuildaHQ implements BuildaSTK { // stellt die ganzen Methoden und globalen Variablen bereit. Komplett static
@@ -519,35 +524,6 @@ public static Document loadXMLFile(String path, boolean bereinigen) {
return doc;
}

public static HashMap<String, Integer> loadindexFile(InputStream is) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains(";")) {
// LOGGER.info(line);
String[] sL = line.split(";");
sL[0] = sL[0].replaceAll(" ", "");
sL[0] = sL[0].replaceAll("-", "");
sL[0] = sL[0].toLowerCase();

if (map.containsKey((String) sL[0]) && Integer.parseInt(sL[1]) != map.get(sL[0])) {
LOGGER.error("Doppelter Key mit verschiedenen Werten: " + sL[0] + " - " + Integer.parseInt(sL[1]) + " Vorhanden als: " + sL[0] + " - " + map.get(sL[0]));
} else {
map.put(sL[0], Integer.parseInt(sL[1]));
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
LOGGER.error("", e);
} catch (IOException e) {
// TODO Auto-generated catch block
LOGGER.error("", e);
}

return map;
}

public static void bereinigeXML(Document doc) {
bereinigeElement(doc.getDocumentElement());
@@ -5,6 +5,9 @@
import java.text.NumberFormat;
import java.util.Vector;

import static oc.RefreshListener.Priority.ONLINE_CODEX;
import static oc.RefreshListener.addRefreshListener;


public abstract class BuildaPanel implements BuildaSTK { // Die Vaterklasse für alle anderen OC-Klassen, da jede oC Klasse ein weißes JPanel brauch^^

@@ -13,14 +16,10 @@ public abstract class BuildaPanel implements BuildaSTK { // Die Vaterklasse fü
public static JTextField budget = new JTextField();
public final JLabel kostenLabel = new JLabel();
public Vector<BuildaVater> myBuilderz = new Vector<BuildaVater>();
public RefreshListener refreshListener = new RefreshListener((byte) 15) {
public void refresh() {
refreshAction();
}
};
protected JPanel panel = new JPanel(null, false); // kein LayoutManager für ALLE Panels, aber doubleBuffered

public BuildaPanel() {
addRefreshListener(ONLINE_CODEX, this::refreshAction);
panel.setBackground(Color.WHITE);
}

@@ -12,6 +12,9 @@
import java.awt.event.ItemListener;
import java.util.Vector;

import static oc.RefreshListener.Priority.BUILDA_VATER;
import static oc.RefreshListener.addRefreshListener;

public class BuildaTextArea extends BuildaPanel implements ActionListener, ItemListener, BuildaSTK {

private static final Logger LOGGER = LoggerFactory.getLogger(BuildaTextArea.class);
@@ -142,11 +145,7 @@ TitledBorder.BELOW_TOP, new Font("Viner Hand ITC",
panel.add(fehlerLabel);

armeelistenFormatAnpassen(true);
new RefreshListener((byte) 13) {
public void refresh() {
textAreaRefresh();
}
};
addRefreshListener(BUILDA_VATER, this::textAreaRefresh);
}
}

@@ -1,5 +1,6 @@
package oc;

import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
@@ -11,10 +12,9 @@
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Set;
import java.util.Vector;
import java.util.*;

import static oc.utils.ResourceUtils.sanitzeKey;

public abstract class BuildaVater extends BuildaPanel implements ActionListener, ItemListener, BuildaSTK {

@@ -50,8 +50,8 @@ public abstract class BuildaVater extends BuildaPanel implements ActionListener,
public Formation formation;
public boolean fcountBool = false; // Im Falle einer Subformation mit nur einer Auswahl, kann die Auswahl mehrmals gewählt werden und zählt mehrfach.
public int fcount = 1; // so
public HashMap<String, Integer> pointValues = new HashMap<String, Integer>();
public HashMap<String, Integer> CP = new HashMap<String, Integer>();
private final Map<String, Integer> pointValues;
public Map<String, Integer> CP = new HashMap<String, Integer>();
protected BuildaTextArea buildatextArea;
protected boolean nurBeiLeerenBuilderTrue = false;
protected int cnt = 0;
@@ -151,9 +151,9 @@ public void actionPerformed(ActionEvent event) {

};

public BuildaVater() {
public BuildaVater(Map<String, Integer> pointValues) {
this.pointValues = ImmutableMap.copyOf(pointValues);
panel.setBackground(Color.WHITE);
//panel.setBounds(0, 0, 3500, CHOOSER_Y + 100);
}

public String getText() {
@@ -691,6 +691,14 @@ public void fillChooserSpace() {

}

public int getPts(String key) {
return Optional.ofNullable(pointValues.get(sanitzeKey(key)))
.orElseGet(() -> {
LOGGER.error("could not determine points for key {}", key);
return 0;
});
}

public void refreshAction() {
super.refreshAction();
if (formation != null) {
@@ -710,17 +718,4 @@ public void clearCombo() {
public void refreshSupplements() {

}

public void appendPointList(HashMap<String, Integer> appendList) {

Set<String> pointset = appendList.keySet();
Object[] pointArray = pointset.toArray();
for (int i = 0; i < pointArray.length; i++) {
if (pointValues.containsKey(pointArray[i]) && appendList.get(pointArray[i]) != pointValues.get(pointArray[i])) {
LOGGER.error("Doppelter Key mit verschiedenen Werten: " + pointArray[i] + " - " + appendList.get(pointArray[i]) + " Vorhanden als: " + pointArray[i] + " - " + pointValues.get(pointArray[i]));
} else {
pointValues.put((String) pointArray[i], appendList.get(pointArray[i]));
}
}
}
}
@@ -11,6 +11,9 @@
import java.util.HashMap;
import java.util.Vector;

import static oc.RefreshListener.Priority.CHOOSER;
import static oc.RefreshListener.addRefreshListener;

public class Chooser extends BuildaPanel implements ActionListener, BuildaSTK {

private static final Logger LOGGER = LoggerFactory.getLogger(Chooser.class);
@@ -86,12 +89,7 @@ public Chooser(BuildaVater bv, int lX, int lY, String reflectionKennung, Object[
cloneButton.repaint();
panel.repaint();

new RefreshListener((byte) 9) {
@Override
public void refresh() {
sizeSetzen();
}
};
addRefreshListener(CHOOSER, this::sizeSetzen);
}

public int getKategorie() {
@@ -12,6 +12,9 @@
import java.awt.event.ActionListener;
import java.util.Vector;

import static oc.RefreshListener.Priority.CHOOSER_GRUPPE;
import static oc.RefreshListener.addRefreshListener;

public class ChooserGruppe extends BuildaPanel {

private static final Logger LOGGER = LoggerFactory.getLogger(ChooserGruppe.class);
@@ -64,14 +67,11 @@ public ChooserGruppe(BuildaVater bv, String reflectionKennung, int lX, int lY, i
adden(c);
überschriftLabelSetzen();

new RefreshListener((byte) 11) {
public void refresh() {
chooserLocationCheck();
überschriftLabelSetzen();
panel.repaint(); // damit es keine überlappenden Einträge beim Eintrags-Wechsel gibt, wenn beide genau gleichgroß sind. Also wichtig!!

}
};
addRefreshListener(CHOOSER_GRUPPE, () -> {
chooserLocationCheck();
überschriftLabelSetzen();
panel.repaint(); // damit es keine überlappenden Einträge beim Eintrags-Wechsel gibt, wenn beide genau gleichgroß sind. Also wichtig!!
});

BuildaHQ.registerNewChooserGruppe(this, kategorie);
}

0 comments on commit 83c8aed

Please sign in to comment.