Parcourir la source

Console finished and can be used via controller

Kevin Trometer il y a 7 ans
Parent
commit
fe93c042da

+ 44 - 0
src/ui/controller/ConsoleController.java

@@ -0,0 +1,44 @@
+package ui.controller;
+
+import java.awt.Color;
+
+import ui.model.Model;
+import ui.view.Console;
+
+public class ConsoleController {
+
+	private Model MODEL;
+
+	public ConsoleController(Model model) {
+		this.MODEL = model;
+	}
+
+	/**
+	 * Getter for selected CpsObject
+	 *
+	 * @param text
+	 *            String the Text
+	 * @param color
+	 *            the color of the Text
+	 * @param p
+	 *            size of the Text
+	 * @param bold
+	 *            bold or not
+	 * @param italic
+	 *            italic or not
+	 * @param ln
+	 *            new line or not
+	 * 
+	 * @return selected CpsObject
+	 */
+	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
+		MODEL.getConsole().addText(text, color, p, bold, italic, nl);
+	}
+
+	/**
+	 * Clears the console
+	 */
+	public void clearConsole() {
+		MODEL.getConsole().clearConsole();
+	}
+}

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

@@ -1,5 +1,6 @@
 package ui.controller;
 
+import java.awt.Color;
 import java.awt.Point;
 import java.awt.event.ActionListener;
 import java.io.File;
@@ -24,6 +25,7 @@ public class Control {
 
 	private ActionListener actionListener;
 
+	private final ConsoleController consoleController;
 	private final MultiPurposeController multiPurposeController;
 	private final CategoryController categoryController;
 	private final ObjectController objectController;
@@ -48,6 +50,7 @@ public class Control {
 				multiPurposeController);
 		this.simulationManager = new SimulationManager(MODEL);
 		this.autoSaveController = new AutoSaveController(MODEL);
+		this.consoleController = new ConsoleController(MODEL);
 		autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		File dest = new File(autoPath);
 		dest.mkdirs();
@@ -289,4 +292,32 @@ public class Control {
 		return simulationManager;
 	}
 
+	/**
+	 * Getter for selected CpsObject
+	 *
+	 * @param text
+	 *            String the Text
+	 * @param color
+	 *            the color of the Text
+	 * @param p
+	 *            size of the Text
+	 * @param bold
+	 *            bold or not
+	 * @param italic
+	 *            italic or not
+	 * @param ln
+	 *            new line or not
+	 * 
+	 * @return selected CpsObject
+	 */
+	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
+		consoleController.addTextToConsole(text, color, p, bold, italic, nl);
+	}
+
+	/**
+	 * Clears the console
+	 */
+	public void clearConsole() {
+		consoleController.clearConsole();
+	}
 }

+ 10 - 0
src/ui/model/Model.java

@@ -13,6 +13,7 @@ import classes.CpsEdge;
 import classes.CpsObject;
 import classes.HolonElement;
 import ui.controller.*;
+import ui.view.Console;
 
 public class Model {
 
@@ -27,6 +28,7 @@ public class Model {
 	private CpsEdge selectedEdge;
 	private ArrayList<CpsObject> selectedObjects = new ArrayList<CpsObject>();
 	private ArrayList<CpsObject> clipboardObjects = new ArrayList<CpsObject>();
+	private Console console;
 
 	private int selectedID = 0;
 	// number of the current autosave
@@ -356,4 +358,12 @@ public class Model {
 	public ArrayList<CpsObject> getClipboradObjects(){
 		return clipboardObjects;
 	}
+	
+	public void setConsole(Console console){
+		this.console = console;
+	}
+	
+	public Console getConsole(){
+		return console;
+	}
 }

+ 21 - 7
src/ui/view/Console.java

@@ -39,30 +39,44 @@ public class Console extends JScrollPane {
 		panel.add(consoleText);
 		setViewportView(panel);
 	}
-	
+
 	/**
 	 * Getter for selected CpsObject
 	 *
-	 * @param text,
+	 * @param text
 	 *            String the Text
-	 * @param color,
+	 * @param color
 	 *            the color of the Text
-	 * @param p,
+	 * @param p
 	 *            size of the Text
+	 * @param bold
+	 *            bold or not
+	 * @param italic
+	 *            italic or not
+	 * @param ln
+	 *            new line or not
 	 * 
 	 * @return selected CpsObject
 	 */
-	public void addText(String text, Color color, int p, boolean bold) {
+	public void addText(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		StyleConstants.setForeground(style, color);
 		StyleConstants.setFontSize(style, p);
 		StyleConstants.setBold(style, bold);
+		StyleConstants.setItalic(style, italic);
 
 		try {
-			if (consoleText.getText().length() != 0) {
+			doc.insertString(doc.getLength(), text, style);
+			if (nl) {
 				doc.insertString(doc.getLength(), "\n", style);
 			}
-			doc.insertString(doc.getLength(), text, style);
 		} catch (BadLocationException e) {
 		}
 	}
+
+	/**
+	 * Clears the console
+	 */
+	public void clearConsole() {
+		consoleText.setText("");
+	}
 }

+ 3 - 18
src/ui/view/GUI.java

@@ -219,32 +219,17 @@ public class GUI<E> implements CategoryListener {
 		this.canvas = new MyCanvas(model, control);
 		this.unitGraph = new UnitGraph(model, control);
 		control.initListener(this);
+		controller.setCanvas(canvas);
+		model.setConsole(console);
 		initialize();
 		updateCategories(model.getCategories());
-		controller.setCanvas(canvas);
 	}
 
 	/**
 	 * Initialize the contents of the frame.
 	 */
 	@SuppressWarnings({ "serial", "unchecked" })
-	private void initialize() {
-		console.addText("Das ist ein blauer Text der größe 12", Color.BLUE, 12, false);
-		console.addText("Das ist ein roter Text der größe 16", Color.RED, 16, false);
-		console.addText("Das ist ein gelber Text der größe 20", Color.YELLOW, 20, true);
-		console.addText("Das ist ein blauer Text der größe 12", Color.BLUE, 12, false);
-		console.addText("Das ist ein roter Text der größe 16", Color.RED, 16, true);
-		console.addText("Das ist ein gelber Text der größe 20", Color.YELLOW, 20, false);
-		console.addText("Das ist ein blauer Text der größe 12", Color.BLUE, 12, true);
-		console.addText("Das ist ein roter Text der größe 16", Color.RED, 16, false);
-		console.addText("Das ist ein gelber Text der größe 20", Color.YELLOW, 20, false);
-		console.addText("Das ist ein blauer Text der größe 12", Color.BLUE, 12, false);
-		console.addText("Das ist ein roter Text der größe 16", Color.RED, 16, true);
-		console.addText("Das ist ein gelber Text der größe 20", Color.YELLOW, 20, true);
-		console.addText("Das ist ein blauer Text der größe 12", Color.BLUE, 12, false);
-		console.addText("Das ist ein roter Text der größe 16", Color.RED, 16, false);
-		console.addText("Das ist ein gelber Text der größe 20", Color.YELLOW, 20, false);
-		
+	private void initialize() {		
 		simulationSpeedField.setColumns(10);
 		frmCyberPhysical = new JFrame();
 		frmCyberPhysical.setTitle("Cyber Physical Systems Model");

+ 4 - 0
src/ui/view/MyCanvas.java

@@ -333,6 +333,10 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			cy = cps.getPosition().y;
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
+				controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
+				controller.addTextToConsole(""+cps.getName(), Color.BLUE, 12, true, false, false);
+				controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
+				controller.addTextToConsole(""+cps.getID(), Color.RED, 12, true, false, true);
 				dragging = true;
 				// If drawing an Edge (CTRL down)
 				if (tempCps.getClass() == HolonObject.class) {