Commits (2)
......@@ -19,8 +19,8 @@ public class SetPreset implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Builder builder = new Builder();
Server server = sender.getServer();
Builder builder = new Builder(server);
Player player = server.getPlayer(sender.getName());
if (player != null) {
Location location = player.getLocation();
......@@ -31,11 +31,11 @@ public class SetPreset implements CommandExecutor {
Runnable t = () -> {
DataHolder.foundation.setLocation(location);
DataHolder.generateSimpleData(Integer.parseInt(args[0]));
builder.setFoundation(server, location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
builder.setFoundation(location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
for (Structure structure : DataHolder.foundation.getChildren()) {
Building building = (Building) structure;
sender.sendMessage("bau" + building.toString());
builder.fillQube(server, building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
builder.fillQube(building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
}
};
t.run();
......
......@@ -2,9 +2,13 @@ package de._82grfl1bif.KPI_Visualizer.commands;
import de._82grfl1bif.KPI_Visualizer.data.DataHolder;
import de._82grfl1bif.KPI_Visualizer.data.JsonParser;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.Rectangle;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.Row;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.SquarifiedTreemapLayout;
import de._82grfl1bif.KPI_Visualizer.structures.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
......@@ -13,56 +17,75 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Map;
import java.util.logging.Level;
public class generateLayout implements CommandExecutor {
Builder builder = new Builder();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 2){
if (args.length < 2) {
sender.sendMessage("please type or select the needed Arguments with tab.");
return false;
}
sender.sendMessage("generating Layout");
sender.sendMessage("generating SimpleSquareLayout");
Server server = sender.getServer();
Builder builder = new Builder(server);
Player player = server.getPlayer(sender.getName());
JsonParser jsonParser = new JsonParser();
if (!jsonParser.evalJson(args[0])){
if (!jsonParser.evalJson(args[0])) {
sender.sendMessage("failed to parse Json");
return false;
}
if(player != null) {
if (player != null) { //check if Player exists for getting Start coordinates.
Location location = player.getLocation();
if (args[1].equals("SquarifiedTreemap")) { //check 2. Argument whether to use SquarifiedTreemap or SimpleSquare Layout.
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
SquarifiedTreemapLayout squarifiedTreemapLayout = new SquarifiedTreemapLayout();
squarifiedTreemapLayout.generateLayout(DataHolder.foundation, new Rectangle(DataHolder.foundation.getArea(), Math.sqrt(DataHolder.foundation.getArea()), new Point(0, 0)));
builder.setFoundation(location,(int)Math.round(Math.sqrt(DataHolder.foundation.getArea())),(int)Math.round(Math.sqrt(DataHolder.foundation.getArea())), Material.COBBLESTONE);
for (Row row : squarifiedTreemapLayout.getRows()) {
for (Map.Entry<Rectangle, Structure> entry : row.getRectangles().entrySet()) {
Rectangle r = entry.getKey();
Structure s = entry.getValue();
if(s.getClass() == Foundation.class){
builder.setFoundation(location.clone().add(r.getOrigin().x,s.getDepth(),r.getOrigin().y),(int)(r.getWidth()),(int)(r.getHeight()),s.getMaterial());
}else{
builder.fillQube(location.clone().add(r.getOrigin().x,s.getDepth()+100,r.getOrigin().y),(int)(r.getWidth()),((Building)s).getHeight(),(int)(r.getHeight()),s.getMaterial());
}
if(r.getHeight() >= 5 && r.getWidth() >= 5){
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
//DataHolder.ComplexData();
DataHolder.foundation.setLocation(location);
DataHolder.foundation.organizeFoundation();
DataHolder.foundation.correctAllLocations(location);
builder.setFoundation(server, DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
setAllChildren(server, DataHolder.foundation);
}
};
t.run();
return true;
}else{
}else{
Bukkit.getLogger().log(Level.SEVERE,"the rectangle is too small");
}
}
}
}
};
t.run();
return true;
} else {
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
DataHolder.foundation.setLocation(location);
DataHolder.foundation.organizeFoundation();
DataHolder.foundation.correctAllLocations(location);
builder.setFoundation(DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
builder.setAllChildren(DataHolder.foundation);
}
};
t.run();
return true;
}
} else {
Bukkit.getLogger().log(Level.SEVERE, "Kein Spieler gefunden.");
return false;
}
}
private void setAllChildren(Server server, Foundation foundation) {
for (Structure s : foundation.getChildren()) {
if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
builder.setFoundation(server, s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
setAllChildren(server, (Foundation) s);
} else {//TODO must be revisited to draw rectangular Buildings
builder.buildBuilding(server, s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(), s.getMaterial());
}
}
}
}
......@@ -7,9 +7,10 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.logging.Level;
public class JsonParser {
......@@ -35,8 +36,16 @@ public class JsonParser {
}
JSONArray entities = (JSONArray) jsonObject.get("entities");
ArrayList<Klasse> entitiesList = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd kk:mm:ss Z");
for (int i=0; i < entities.size(); i++) {
JSONObject object = (JSONObject) entities.get(i);
JSONArray commits = (JSONArray) ((JSONObject) entities.get(i)).get("commits");
ArrayList<LocalDateTime> dates = new ArrayList<>();
for (Object o: commits){
Object date = ((JSONObject) o).get("date");
LocalDateTime time = LocalDateTime.parse(date.toString(),formatter);
dates.add(time);
}
Klasse currentKlasse = new Klasse(
Integer.parseInt(object.get("entity_id").toString()),
object.get("name").toString(),
......@@ -45,8 +54,10 @@ public class JsonParser {
Integer.parseInt(object.get("loc").toString()),
((JSONArray) object.get("commits")).size(),
((JSONArray) object.get("functions")).size(),
((JSONArray) object.get("variables")).size());
entitiesList.add(currentKlasse);
((JSONArray) object.get("variables")).size(),
Math.round(Float.parseFloat(object.get("complexity").toString())),
dates);
if(currentKlasse.depth != -1)entitiesList.add(currentKlasse);
}
entitiesList.sort(new DepthComparator());
DataHolder.generateTreeFromKlassenList(entitiesList);
......
package de._82grfl1bif.KPI_Visualizer.data;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class Klasse {
public String name;
public String path;
public int qloc;
public static int qlocMin = Integer.MAX_VALUE;
public static int qlocMax;
public int loc;
public static int locMin= Integer.MAX_VALUE;
public static int locMax;
public int commits;
public static int commitsMin= Integer.MAX_VALUE;
public static int commitsMax;
public int depth;
public static int depthMax;
public int complexity;
public static int complexityMax;
public static int complexityMin= Integer.MAX_VALUE;
public final int id;
public int functions;
public static int functionsMin= Integer.MAX_VALUE;
public static int functionsMax;
public int variables;
public static int variablesMin= Integer.MAX_VALUE;
public static int variablesMax;
public Duration bearbeiteteZeit;
public static Duration bearbeiteteZeitMin;
public static Duration bearbeiteteZeitMax;
public Duration zeitSeitLetzterBearbeitung;
public static Duration zeitSeitLetzterBearbeitungMin;
public static Duration zeitSeitLetzterBearbeitungMax;
public Duration zeitSeitErstemCommit;
public static Duration zeitSeitErstemCommitMin;
public static Duration zeitSeitErstemCommitMax;
ArrayList<LocalDateTime> commitTimes;
public Klasse(int id, String name, String path, int qloc, int loc, int commits, int functions, int variables){
public Klasse(int id, String name, String path, int qloc, int loc, int commits, int functions, int variables,int complexity, ArrayList<LocalDateTime> commitTimes){
this.id = id;
this.commits = commits;
commitsMax = Math.max(commitsMax,commits);
commitsMin = Math.min(commitsMin,commits);
this.depth = getDepthOfPath(path);
depthMax = Math.max(depthMax,depth);
this.loc = loc;
locMax = Math.max(locMax,loc);
locMin = Math.min(locMin,loc);
this.qloc = qloc;
qlocMax = Math.max(qlocMax,qloc);
qlocMin = Math.min(qlocMin,qloc);
this.functions = functions;
functionsMax = Math.max(functionsMax,functions);
functionsMin = Math.min(functionsMin,functions);
this.variables = variables;
variablesMax = Math.max(variablesMax,variables);
variablesMin = Math.min(variablesMin,variables);
this.complexity = complexity;
complexityMax = Math.max(complexityMax,complexity);
complexityMin = Math.min(complexityMin,complexity);
this.name = name;
this.path = path;
this.commitTimes = commitTimes;
this.bearbeiteteZeit = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(commitTimes.size()-1), commitTimes.get(0));
if (bearbeiteteZeit != null) {
if(bearbeiteteZeitMax == null)bearbeiteteZeitMax = Duration.ofMillis(Long.MIN_VALUE);
if(bearbeiteteZeitMin == null)bearbeiteteZeitMin = Duration.ofMillis((Long.MAX_VALUE));
bearbeiteteZeitMax = (bearbeiteteZeitMax.toMillis() >= bearbeiteteZeit.toMillis()) ? bearbeiteteZeitMax:bearbeiteteZeit;
bearbeiteteZeitMin = (bearbeiteteZeitMin.toMillis() <= bearbeiteteZeit.toMillis()) ? bearbeiteteZeitMin:bearbeiteteZeit;
}
this.zeitSeitLetzterBearbeitung = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(0),LocalDateTime.now());
if (zeitSeitLetzterBearbeitung != null) {
if(zeitSeitLetzterBearbeitungMax == null)zeitSeitLetzterBearbeitungMax = Duration.ofMillis(Long.MIN_VALUE);
if(zeitSeitLetzterBearbeitungMin == null)zeitSeitLetzterBearbeitungMin = Duration.ofMillis(Long.MAX_VALUE);
zeitSeitLetzterBearbeitungMax = (zeitSeitLetzterBearbeitungMax.toMillis() >= zeitSeitLetzterBearbeitung.toMillis()) ? zeitSeitLetzterBearbeitungMax:zeitSeitLetzterBearbeitung;
zeitSeitLetzterBearbeitungMin = (zeitSeitLetzterBearbeitungMin.toMillis() <= zeitSeitLetzterBearbeitung.toMillis()) ? zeitSeitLetzterBearbeitungMin:zeitSeitLetzterBearbeitung;
}
this.zeitSeitErstemCommit = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(commitTimes.size()-1),LocalDateTime.now());
if (zeitSeitErstemCommit != null) {
if(zeitSeitErstemCommitMax == null)zeitSeitErstemCommitMax = Duration.ofMillis(Long.MIN_VALUE);
if(zeitSeitErstemCommitMin == null)zeitSeitErstemCommitMin = Duration.ofMillis(Long.MAX_VALUE);
zeitSeitErstemCommitMax = (zeitSeitErstemCommitMax.toMillis() >= zeitSeitErstemCommit.toMillis()) ? zeitSeitErstemCommitMax:zeitSeitErstemCommit;
zeitSeitErstemCommitMin = (zeitSeitErstemCommitMin.toMillis() <= zeitSeitErstemCommit.toMillis()) ? zeitSeitErstemCommitMin:zeitSeitErstemCommit;
}
}
private int getDepthOfPath(String path){
......
package de._82grfl1bif.KPI_Visualizer.data;
package de._82grfl1bif.KPI_Visualizer.helpers;
import de._82grfl1bif.KPI_Visualizer.data.JsonParser;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.ArrayList;
public class Quadrat extends Shape{
public class Quadrat extends Shape {
private Boolean belegt;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import java.awt.*;
import java.util.ArrayList;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import java.awt.Point;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Quadrat;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import javax.management.AttributeNotFoundException;
......@@ -7,8 +9,7 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
@SuppressWarnings("ALL")
public class Layout {
public class SimpleSquareLayout {
private final ArrayList<Structure> structures;
private final ArrayList<Quadrat> layout = new ArrayList<>();
......@@ -19,7 +20,7 @@ public class Layout {
private int size = 0;
public Layout(ArrayList<Structure> structures){
public SimpleSquareLayout(ArrayList<Structure> structures){
this.structures = structures;//ordered biggest first.
}
......@@ -77,9 +78,9 @@ public class Layout {
layout.add(new Quadrat(new Point(q.bottomLeftCorner.y,q.bottomLeftCorner.x),new Point(q.topRightCorner.y,q.topRightCorner.x))); // gespiegeltes Quadrat
layout.add(new Quadrat(new Point(q.bottomLeftCorner.x,q.bottomLeftCorner.x),structure.getWidth().x)); // Oberes rechtes Quadrat
if((this.size-(2*structure.getWidth().x)) > 0){ //falls Abstand zwischen den Quadraten ist.
Rectangle rTop = new Rectangle(structure.getWidth().x,(this.size-2*structure.getWidth().x),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle rTop = new de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle(structure.getWidth().x,(this.size-2*structure.getWidth().x),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
layout.addAll(rTop.splitToQuads(rTop));
Rectangle rRight = new Rectangle((this.size-2*structure.getWidth().x),structure.getWidth().x,new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle rRight = new Rectangle((this.size-2*structure.getWidth().x),structure.getWidth().x,new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
layout.addAll(rRight.splitToQuads(rRight));
}
}
......
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Rectangle{
private double area;
private double width;
private double height;
private Point origin;
public void setHeight(double height) {
this.height = height;
this.width = area/height;
}
public void setWidth(double width) {
this.width = width;
this.height = area/width;
}
public double getArea() {
return area;
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
public Point getOrigin() {
return origin;
}
public void setOrigin(Point origin) {
this.origin = origin;
}
public Rectangle(double area,double width,Point origin){
this.area = area;
this.origin = origin;
setWidth(width);
}
public double getSideRelation(){
return Math.max(width/height,height/width);
}
public boolean checkSideRelation(double side){
return !(getSideRelation() < Math.max((area/side)/side,side/(area/side)));// false if the Relation gets worse.
}
}
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
public class Row {
double broad;
boolean horizontal;
public HashMap<Rectangle, Structure> getRectangles() {
return rectangles;
}
HashMap<Rectangle, Structure> rectangles;
Rectangle space;
public Row(Rectangle space) {
this.space = space;
this.rectangles = new HashMap<>();
this.broad = 0;
this.horizontal = (space.getWidth() >= space.getHeight());
}
private double getSideRelation() {
double currentMax = 0;
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
currentMax = Math.max(r.getSideRelation(), currentMax);
}
return currentMax;
}
public void addRectangle(double area, Structure structure) {
double currentArea = getCurrentArea() + area;
if (horizontal) {
this.broad = currentArea / space.getHeight(); //calculating the new broad
int currentHeight = this.space.getOrigin().y; //new temp for height of origins
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
r.setWidth(this.broad);//setting new width&Height for all existing rectangles
r.setOrigin(new Point(this.space.getOrigin().x, currentHeight));//setting new origins for all existing rectangles
currentHeight += (int) Math.round(r.getHeight());//for next origin
}
rectangles.put((new Rectangle(area, this.broad, new Point(this.space.getOrigin().x, currentHeight))), structure);//add new Rectangle
} else {
this.broad = currentArea / space.getWidth(); //calculating the new broad
int currentWidth = this.space.getOrigin().x; //new temp for width of origins
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
r.setHeight(this.broad);//setting new width&Height for all existing rectangles
r.setOrigin(new Point(currentWidth, space.getOrigin().y));//setting new origins for all existing rectangles
currentWidth += (int) Math.round(r.getHeight());//for next origin
}
rectangles.put(new Rectangle(area, area / this.broad, new Point(currentWidth, space.getOrigin().y)), structure);
}
}
private double getCurrentArea() {
double currentArea = 0;
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
currentArea += r.getArea();
}
return currentArea;
}
public boolean checkInsert(double area) {
if (!rectangles.isEmpty()) {
double currentArea = getCurrentArea() + area;
double broadTemp = horizontal ? currentArea / space.getHeight() : currentArea / space.getWidth();
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
if (!r.checkSideRelation(broadTemp))
return false;//returns false if one of the existing rectangles gets worse
}
return !(new Rectangle(area, broad, new Point(0, 0)).getSideRelation() > getSideRelation()); //returns false if the inserted rectangle is worse, than any other before
}else {
return true;
}
}
public Rectangle getLeftover() {
Point origin;
double width;
if (horizontal) {
origin = new Point(space.getOrigin().x + (int)(broad), space.getOrigin().y);
width = space.getWidth() - getWidth();
} else {
origin = new Point(space.getOrigin().x, space.getOrigin().y + (int)(broad));
width = getWidth();
}
return new Rectangle(this.space.getArea() - getCurrentArea(), width, origin);
}
public double getWidth() {
if (horizontal) {
return this.broad;
} else {
return this.space.getWidth();
}
}
public double getHeight() {
if (horizontal) {
return this.space.getHeight();
} else {
return this.broad;
}
}
public boolean isFull(){
return (Math.round(this.space.getArea()) <= Math.round(this.getCurrentArea()));
}
}
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Foundation;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SquarifiedTreemapLayout {
private ArrayList<Row> rows = new ArrayList<>();
public ArrayList<Row> getRows() {
return rows;
}
public SquarifiedTreemapLayout() {
this.rows = new ArrayList<>();
}
public void generateLayout(Foundation foundation, Rectangle bounds) {
rows.addAll(generateSubLayout(foundation, bounds));
ArrayList<Foundation> foundations = new ArrayList<>();
foundations.add(foundation);
do {
ArrayList<Row> tempRows = new ArrayList<>();
rows.stream().filter(r -> r.rectangles.containsValue(foundations.get(foundations.size()-1))).forEach(row ->
tempRows.addAll(generateSubLayout(foundations.get(foundations.size()-1), new Rectangle(foundations.get(foundations.size()-1).getArea(), row.getWidth(), row.space.getOrigin()))));
rows.addAll(tempRows);//letztes element bearbeitet und ein subLayout dafür angelegt.
ArrayList<Foundation> tempFoundations = new ArrayList<>();
for (Structure s : foundations.get(foundations.size() - 1).getChildren()) {
if (s.getClass() == Foundation.class) {
tempFoundations.add((Foundation) s);
}
}
foundations.remove(foundations.size()-1);
foundations.addAll(tempFoundations);//alle Kinder(nur Foundations) des letzten Elements in die Liste geschrieben und das Element entfernt.
} while (!foundations.isEmpty());
}
private ArrayList<Row> generateSubLayout(Foundation foundation, Rectangle rectangle) {
ArrayList<Row> result = new ArrayList<>();
result.add(new Row(rectangle));
for (Structure s : foundation.getChildren()) {
if (!result.get(result.size() - 1).checkInsert(s.getArea())) {//wenn einfügen in die bestehende Reihe das Seitenverhältnis verschlechtern würde.
Row tempRow = new Row(result.get(result.size() - 1).getLeftover());//erzeige neue Reihe mit dem Rest des alten spaces als space.
result.add(tempRow);//füge die neue Reihe ans Ende der Sammlung ein.
}
result.get(result.size() - 1).addRectangle(s.getArea(), s);//füge das Kind in die letzte Reihe ein, die in der Liste ist.
}
return result;
}
}
......@@ -2,7 +2,7 @@ package de._82grfl1bif.KPI_Visualizer;
import de._82grfl1bif.KPI_Visualizer.commands.SetPreset;
import de._82grfl1bif.KPI_Visualizer.commands.generateLayout;
import de._82grfl1bif.KPI_Visualizer.data.FileInputTabCompleter;
import de._82grfl1bif.KPI_Visualizer.helpers.FileInputTabCompleter;
import org.bukkit.plugin.java.JavaPlugin;
public final class main extends JavaPlugin {
......
......@@ -7,33 +7,37 @@ import java.awt.Point;
public class Building extends Structure{
private final int height;
public Klasse klasse = null;
@Deprecated
public Building(int width, int height, Material material){ //Buildings are Square -> no depth
this.width.x = width;
this.width.y = width;
this.height = height;
this.material = material;
if(this.width.x < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
if(this.width.x < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
public Building(Point width, int height, Material material){ //Buildings are Square -> no depth
public Building(Point width/*and depth for complex algorithms*/, int height, Material material){
this.width = width;
this.height = height;
this.material = material;
if(this.width.x < 3 || this.width.y < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
public Building(Material material, Klasse klasse, String name){ //Buildings are Square -> no depth
this.klasse = klasse;
this.material = material;
this.width = new Point(5,5); //TODO: make this work with treemap and square
this.width = new Point((int)Math.round((klasse.variables+5)),(int)Math.round((klasse.variables+5))); //TODO: make this work with treemap and square
this.area = klasse.variables*25;
this.name = name;
this.height = klasse.commits; // con be changed to likings TODO: find out which fits best.
if(this.width.x < 3 || this.width.y < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
this.height = klasse.functions;
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
......
package de._82grfl1bif.KPI_Visualizer.structures;
import de._82grfl1bif.KPI_Visualizer.data.Klasse;
import de._82grfl1bif.KPI_Visualizer.helpers.Layout;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.SimpleSquareLayout;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
......@@ -16,7 +16,7 @@ import java.util.Random;
public class Foundation extends Structure {
private ArrayList<Structure> children = new ArrayList<>();
private Layout layout;
private SimpleSquareLayout simpleSquareLayout;
public Foundation(int depth, Material material) { //Foundations are uniform Height
this.width.x = 0;
......@@ -47,7 +47,7 @@ public class Foundation extends Structure {
if (isFoundation) {
result = new Foundation(this.depth + 1, nextMaterial(), name);
} else {
result = new Building(Material.LIME_CONCRETE, klasse, name);
result = new Building(nextMaterial(), klasse, name);
}
this.children.add(result);
return result;
......@@ -143,19 +143,10 @@ public class Foundation extends Structure {
return null;
}
public Structure findByName(String findName) {
if (this.name.equals(findName)) {
return this;
} else {
for (Structure s : this.children) {
if (s.getClass() == Foundation.class) {
if ((((Foundation) s).findByName(findName)) != null) {
return s;
}
}
}
}
return null;
@Override
public double getArea(){
if(area == 0)setAllAreas();
return area;
}
private static class DepthComparator implements Comparator<Foundation> {
......@@ -188,13 +179,13 @@ public class Foundation extends Structure {
} else { //normal Call and recursion
this.children.sort(new WidthComparator());
Collections.reverse(this.children); //Widest Building or Foundation first
this.layout = new Layout(this.children);
this.layout.createLayout();
this.width.x = layout.getSize();
this.simpleSquareLayout = new SimpleSquareLayout(this.children);
this.simpleSquareLayout.createLayout();
this.width.x = simpleSquareLayout.getSize();
}
}
private ArrayList<Foundation> collectAllFoundations() { //called on the base Foundation
public ArrayList<Foundation> collectAllFoundations() { //called on the base Foundation
ArrayList<Foundation> fCollection = new ArrayList<>();
fCollection.add(this);
int currentDepth = this.depth;
......@@ -211,6 +202,18 @@ public class Foundation extends Structure {
return fCollection;
}
public ArrayList<Building> collectAllBuildings() { //called on the base Foundation
ArrayList<Building> buildings = new ArrayList<>();
for (Structure s: children) {
if (s.getClass() == Foundation.class){
buildings.addAll(((Foundation) s).collectAllBuildings());
}else{
buildings.add((Building) s);
}
}
return buildings;
}
private ArrayList<Foundation> getNextDepth() {
ArrayList<Foundation> result = new ArrayList<>();
for (Structure s : this.children) {
......@@ -229,7 +232,7 @@ public class Foundation extends Structure {
public void correctAllLocations(Location location) {
for (Structure s : this.children) {
try {
Point temp = this.layout.getCoordinateOf(s);
Point temp = this.simpleSquareLayout.getCoordinateOf(s);
s.setLocation(location.clone().add(temp.x, 0, temp.y));
if (s.getClass() == Foundation.class) {
Foundation f = (Foundation) s;
......@@ -240,4 +243,17 @@ public class Foundation extends Structure {
}
}
}
private double setAllAreas(){
double myArea = 0;
for (Structure s: children) {
if(s.getClass() == Foundation.class){
myArea += ((Foundation) s).setAllAreas();
}else{
myArea += s.getArea();
}
}
this.area = myArea;
return myArea;
}
}
......@@ -15,6 +15,11 @@ public abstract class Structure{
protected Location location;
protected int depth;
protected String name;
protected double area;
public double getArea() {
return area;
}
public Material getMaterial() {
return material;
......