Parcourir la source

Adds a checkbox to the view menu which turns of the supply bars

Andreas T. Meyer-Berg il y a 7 ans
Parent
commit
af28ae96cc

+ 8 - 0
src/ui/controller/Control.java

@@ -970,4 +970,12 @@ public class Control {
         globalController.setShowConsoleLog(showConsoleLog);
     }
 
+    /**
+     * Sets show
+     * @param showSupplyBars wether the bars should be shown
+     */
+	public void setShowSupplyBars(boolean showSupplyBars) {
+		globalController.setShowSupplyBars(showSupplyBars);
+	}
+
 }

+ 8 - 0
src/ui/controller/GlobalController.java

@@ -164,4 +164,12 @@ public class GlobalController {
 	public void setShowConsoleLog(boolean showConsoleLog) {
 		model.setShowConsoleLog(showConsoleLog);
 	}
+	
+	/**
+	 * sets showSupplyBars
+	 * @param showSupplyBars
+	 */
+	public void setShowSupplyBars(boolean showSupplyBars) {
+		model.setShowSupplyBars(showSupplyBars);
+	}
 }

+ 16 - 1
src/ui/model/Model.java

@@ -67,7 +67,8 @@ public class Model {
     private boolean showConsoleLog = true;
     // whether the console log of the program should be displayed
     private boolean useFlexibleDevices = true;
-
+    // whether the supplyBars should be shown or not
+    private boolean showSupplyBars = true;
     /*
      * Array of all categories in the model. It is set by default with the
      * categories ENERGY, BUILDINGS and COMPONENTS
@@ -906,6 +907,20 @@ public class Model {
     }
 
     /**
+	 * @return true if SupplyBars should be shown
+	 */
+	public boolean getShowSupplyBars() {
+		return showSupplyBars;
+	}
+
+	/**
+	 * @param showSupplyBars true if the SupplyBars should be shown
+	 */
+	public void setShowSupplyBars(boolean showSupplyBars) {
+		this.showSupplyBars = showSupplyBars;
+	}
+
+	/**
      * Initialize the Gson with wanted parameters
      */
     private void initGson() {

+ 11 - 0
src/ui/view/GUI.java

@@ -46,6 +46,7 @@ public class GUI implements CategoryListener {
     private final JMenu mnHelp = new JMenu("Help");
     private final JCheckBox consoleLogCheckBox = new JCheckBox("Show program console log");
     private final JCheckBox useFlexibleDevicesCheckBox = new JCheckBox("Automatically use flexible devices");
+    private final JCheckBox showSupplyBarsCheckBox = new JCheckBox("Show supply bars.");
     private final JMenuItem mntmOpen = new JMenuItem("Open");
     private final JMenuItem mntmNew = new JMenuItem("New");
     private final JMenuItem mntmSave = new JMenuItem("Save");
@@ -687,6 +688,16 @@ public class GUI implements CategoryListener {
         mnNewMenuView.add(mntmCanvasSize);
         mnNewMenuView.add(mntmSplitView);
 
+        /*
+         * Adds Checkbox to turn supply bars on/off
+         */
+        mnNewMenuView.add(showSupplyBarsCheckBox);
+        showSupplyBarsCheckBox.setSelected(true);
+        showSupplyBarsCheckBox.addActionListener(arg0 -> {
+        controller.setShowSupplyBars(showSupplyBarsCheckBox.isSelected());
+        canvas.repaint();      
+        });
+        
         // Split View
         mntmSplitView.addActionListener(actionEvent -> {
             if (splitPaneCanvasConsole.getLeftComponent() instanceof JSplitPane) {

+ 2 - 2
src/ui/view/MyCanvas.java

@@ -477,9 +477,9 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 					controller.getScale(), controller.getScale(), null);
 
 			/**
-			 * draw and fill the supply Bar //TODO: work in Progress
+			 * draw and fill the supply Bar
 			 */
-			if (cps instanceof HolonObject) {
+			if (model.getShowSupplyBars() && cps instanceof HolonObject) {
 				HolonObject hl = (HolonObject) cps;
 				if (hl != null
 						&& (hl.getState() == HolonObject.NOT_SUPPLIED || hl