TomTroppmann 2 years ago
parent
commit
62c4789e13

+ 86 - 0
pom.xml

@@ -0,0 +1,86 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>praktikum-holons</groupId>
+	<artifactId>praktikum-holons</artifactId>
+	<version>2.2.0</version>
+	<name>HOLEG</name>
+	<build>
+		<sourceDirectory>src</sourceDirectory>
+		<testSourceDirectory>tests</testSourceDirectory>
+		<resources>
+			<resource>
+				<directory>src</directory>
+				<excludes>
+					<exclude>**/*.java</exclude>
+				</excludes>
+			</resource>
+		</resources>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.1</version>
+				<configuration>
+					<release>16</release>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>3.2.0</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<mainClass>holeg.ui.view.main.Main</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+
+
+
+	<dependencies>
+		<dependency>
+			<groupId>com.google.code.gson</groupId>
+			<artifactId>gson</artifactId>
+			<version>2.8.9</version>
+		</dependency>
+		<dependency>
+			<groupId>org.junit.jupiter</groupId>
+			<artifactId>junit-jupiter-api</artifactId>
+			<version>5.7.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.junit.jupiter</groupId>
+			<artifactId>junit-jupiter-engine</artifactId>
+			<version>5.7.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-email</artifactId>
+			<version>1.5</version>
+		</dependency>
+		<dependency>
+			<groupId>org.wso2.orbit.org.apache.commons</groupId>
+			<artifactId>commons-compress</artifactId>
+			<version>1.18.0.wso2v1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.knowm.xchart</groupId>
+			<artifactId>xchart</artifactId>
+			<version>3.8.1</version>
+		</dependency>
+		<dependency>
+			<groupId>com.miglayout</groupId>
+			<artifactId>miglayout-swing</artifactId>
+			<version>5.0</version>
+		</dependency>
+
+	</dependencies>
+</project>

+ 1 - 2
src/holeg/addon/Randomizer.java

@@ -290,9 +290,8 @@ public class Randomizer implements AddOn {
 	
 	private void readCatalogFromJson(File file, List<HolonElementSketch> catalog) {
 		Gson gson = new Gson();
-		JsonParser parser = new JsonParser();
 		try {
-			JsonElement jsonTreeRoot = parser.parse(new FileReader(file));
+			JsonElement jsonTreeRoot = JsonParser.parseReader(new FileReader(file));
 			if(jsonTreeRoot.isJsonArray()) {
 				JsonArray jsonArray = jsonTreeRoot.getAsJsonArray();
 				jsonArray.forEach(jsonObject -> {

+ 12 - 14
src/holeg/ui/controller/CategoryController.java

@@ -33,7 +33,6 @@ public class CategoryController {
 	 */
 	public CategoryController(Control control) {
 		this.OnCategoryChanged = control.OnCategoryChanged;
-		initCategories();
 	}
 
 	/**
@@ -69,20 +68,16 @@ public class CategoryController {
 
 	
 	public Category createCategoryWithName(String categoryName) {
-		int i = 0;
-		while (findCategoryWithName(categoryName).isPresent()) {
-			if (categoryName.contains("_")) {
-				categoryName = (categoryName.substring(0, categoryName.indexOf('_')));				
-			}
-			
-			categoryName += "_" + i;
-			i++;
+		Optional<Category> category = findCategoryWithName(categoryName);
+		if(category.isEmpty()) {
+			Category cat = new Category(categoryName);
+			GuiSettings.getCategories().add(cat);	
+			OnCategoryChanged.broadcast();
+			return cat;			
+		}else {
+			return category.get();
 		}
 		
-		Category cat = new Category(categoryName);
-		GuiSettings.getCategories().add(cat);	
-		OnCategoryChanged.broadcast();
-		return cat;
 	}
 
 
@@ -96,7 +91,10 @@ public class CategoryController {
 		GuiSettings.getCategories().remove(c);
 		OnCategoryChanged.broadcast();
 	}
-	
+
+	public void clearCategories() {
+		GuiSettings.getCategories().clear();
+	}
 
 	/**
 	 * Add Object into a Category.

+ 2 - 4
src/holeg/ui/controller/ClipboardController.java

@@ -26,7 +26,6 @@ public class ClipboardController {
     private LoadController load;
     private CanvasController cvsC;
     private NodeController uppC;
-    private JsonParser parser;
     private Clipboard clipboard;
     private HashMap<Integer, Integer> objIDMap;
     private HashMap<Integer, Integer> eleIDMap;
@@ -43,7 +42,6 @@ public class ClipboardController {
         this.uppC = uppC;
         this.clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
         this.simManager = simManager;
-        parser = new JsonParser();
     }
 
     /**
@@ -110,8 +108,8 @@ public class ClipboardController {
 
             String str = (String) content.getTransferData(DataFlavor.stringFlavor);
 
-            if (parser.parse(str).isJsonObject())
-                json = (JsonObject) parser.parse(str);
+            if (JsonParser.parseString(str).isJsonObject())
+                json = (JsonObject) JsonParser.parseString(str);
             else
                 throw new JsonParseException("Unknown Clipboard Information");
 

+ 1 - 0
src/holeg/ui/controller/Control.java

@@ -142,6 +142,7 @@ public class Control {
 	 * init default category and objects.
 	 */
 	public void resetCategories() {
+		categoryController.clearCategories();
 		categoryController.initCategories();
 		saveCategory();
 

+ 2 - 4
src/holeg/ui/controller/LoadController.java

@@ -40,7 +40,6 @@ public class LoadController {
     private CategoryController cgC;
     private CanvasController cvsC;
     private NodeController uppC;
-    private JsonParser parser;
     private static HashMap<String,String> OldTypeNameReplacement = new HashMap<String, String>();
     
     static {
@@ -64,7 +63,6 @@ public class LoadController {
         this.cgC = cg;
         this.cvsC = cvs;
         this.uppC = uppC;
-        this.parser = new JsonParser();
     }
 
     /**
@@ -91,7 +89,7 @@ public class LoadController {
      * @return a list of the form [x, y, width, height]
      */
     ArrayList<Integer> readWindowDimensions(String path) throws FileNotFoundException {
-        JsonObject json = (JsonObject) parser.parse(new FileReader(path));
+        JsonObject json = (JsonObject) JsonParser.parseReader(new FileReader(path));
         ArrayList<Integer> dimensions = new ArrayList<>();
 
         List<String> keys = getKeys(json);
@@ -103,7 +101,7 @@ public class LoadController {
     }
 
     void readJson(String path) throws IOException {
-        JsonObject json = (JsonObject) parser.parse(new FileReader(path));
+        JsonObject json = (JsonObject) JsonParser.parseReader(new FileReader(path));
         // get all keys via stream
         List<String> keys = getKeys(json);
         List<String> edges = keys.stream().filter(key -> key.contains("EDGE"))

+ 0 - 50
src/holeg/ui/model/HolegModel.java

@@ -1,50 +0,0 @@
-package holeg.ui.model;
-
-import java.util.ArrayList;
-import java.util.stream.Stream;
-
-import holeg.model.Edge;
-import holeg.model.GroupNode;
-
-public class HolegModel {
-	
-	public enum FairnessModel{
-		/**
-		 * One Element of each HolonObject will be powered first, starting with the
-		 * smallest Demand. If ale HolonObjects have an active Element, the
-		 * simulation will try to fully supply as many HolonObjects as possible.
-		 */
-		MininumDemandFirst, 
-		/**
-		 * All HolonObjects will receive the same amount of energy.
-		 */
-		AllEqual
-	}
-    private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;    
-    private GroupNode canvas = new GroupNode("Canvas");
-    private ArrayList<Edge> edges = new ArrayList<>();
-
-    public FairnessModel getFairnessModel() {
-    	return fairnessModel;
-    }
-    public void setFairnessModel(FairnessModel fairnessModel) {
-    	this.fairnessModel = fairnessModel;
-    }
-    
-	public Stream<Edge> getEdges() {
-		return edges.stream();
-	}
-	public void addEdge(Edge edge) {
-		edges.add(edge);
-	}
-	public void removeEdge(Edge edge) {
-		edges.remove(edge);
-	}
-
-	public GroupNode getCanvas() {
-		return canvas;
-	}
-    
-    
-
-}

+ 10 - 5
src/holeg/ui/view/information/HolonInformationPanel.java

@@ -125,7 +125,7 @@ public class HolonInformationPanel extends JPanel {
 		supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
 		supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
 		supplyChart.updatePieSeries("No energy", noEnergyAmount);
-		panelHolonObject.updateToolTips();
+		updateToolTips(panelHolonObject);
 
 		// UPDATE PRIORITYS
 		holeg.ui.view.information.FilterableGroupNode.PriorityCounts priorityCounts = decoratedGroupNode
@@ -138,7 +138,7 @@ public class HolonInformationPanel extends JPanel {
 		boolean hasPriority = priorityCounts.essential + priorityCounts.high + priorityCounts.medium
 				+ priorityCounts.low > 0;
 		priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
-		panelPriority.updateToolTips();
+		updateToolTips(panelPriority);
 
 		// UPDATE PRODUCTION
 		float production = decoratedGroupNode.getProduction(stateFilter, priorityFilter);
@@ -148,7 +148,7 @@ public class HolonInformationPanel extends JPanel {
 		energyChart.updatePieSeries("Production", production);
 		energyChart.updatePieSeries("Consumption", consumption);
 		differenceEnergyLabelAmount.setText(FormatFloat.doubleFixedPlaces(1, difference));
-		panelEnergy.updateToolTips();
+		updateToolTips(panelEnergy);
 
 		// UPDATE FLEXIBILITIES
 		int inUse = 0;
@@ -188,7 +188,7 @@ public class HolonInformationPanel extends JPanel {
 		flexibilityChart.updatePieSeries("Unavailable", unavailable);
 		boolean hasFlex = offered + inUse + onCooldown + notOffered + unavailable > 0;
 		flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
-		panelFlexibility.updateToolTips();
+		updateToolTips(panelFlexibility);
 
 		// UPDATE ActiveInActive
 		int activeAmount = decoratedGroupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter);
@@ -196,12 +196,17 @@ public class HolonInformationPanel extends JPanel {
 				- activeAmount;
 		activeChart.updatePieSeries("Active", activeAmount);
 		activeChart.updatePieSeries("Inactive", inactiveAmounts);
-		panelActive.updateToolTips();
+		updateToolTips(panelActive);
 
 		this.revalidate();
 		this.repaint();
 	}
 
+	private void updateToolTips(XChartPanel<PieChart> chart) {
+		log.info("UpdatetoolTips");
+		
+	}
+
 	private Optional<FilterableGroupNode> multiSelectionToFilterableGroupNode() {
 		FilterableGroupNode temp = new FilterableGroupNode(new GroupNode("Temp"),
 				control.getModel().getCurrentIteration());