Browse Source

canvas variablen in model

Kevin Trometer 7 years ago
parent
commit
2e983116ab

BIN
res/Images/Thumbs.db


BIN
res/Images/questionmark.png


+ 19 - 0
src/ui/controller/CanvasController.java

@@ -310,4 +310,23 @@ public class CanvasController {
 		}
 
 	}
+	
+	/**
+	 * Set the Background Image;
+	 * 
+	 * @param imagePath
+	 *            Image Path
+	 * @param mode
+	 *            Image Mode
+	 * @param width
+	 *            Image custom width
+	 * @param height
+	 *            Image custom height
+	 */
+	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
+		model.setCanvasImagePath(imagePath);
+		model.setCanvasImageMode(mode);
+		model.setCanvasImageWidth(width);
+		model.setCanvasImageHeight(height);
+	}
 }

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

@@ -873,5 +873,20 @@ public class Control {
 	public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
 		return holonCanvasController.getActiveElements(arrayList);
 	}
+	/**
+	 * Set the Background Image;
+	 * 
+	 * @param imagePath
+	 *            Image Path
+	 * @param mode
+	 *            Image Mode
+	 * @param width
+	 *            Image custom width
+	 * @param height
+	 *            Image custom height
+	 */
+	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
+	canvasController.setBackgroundImage(imagePath, mode, width, height);
+	}
 
 }

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

@@ -35,9 +35,15 @@ import ui.view.DefaulTable;
  */
 public class Model {
 
-	// Global Variables
+	// Canvas Attributes
+	private String imgPath = "";
+	private int backgroundMode = 0;
+	private int backgroundWidth = 0;
+	private int backgroundHeight = 0;
 	private int canvasX = 1000;
 	private int canvasY = 1000;
+
+	// Global Variables
 	private static int sCALE = 50; // Picture Scale
 	private static int sCALEdIV2 = sCALE / 2;
 	private static int holonBodysCALE = 100; // Picture Scale
@@ -806,4 +812,79 @@ public class Model {
 		return switches;
 	}
 
+	/**
+	 * Returns the Path for the background Image of the Canvas.
+	 * 
+	 * @return imgPath the Path
+	 */
+	public String getCanvasImagePath() {
+		return imgPath;
+	}
+
+	/**
+	 * Returns the mode for the background Image of the Canvas.
+	 * 
+	 * 0 take size of the Image 1 stretch the Image 2 Custom Image size
+	 * 
+	 * @return backgroundMode the mode
+	 */
+	public int getCanvasImageMode() {
+		return backgroundMode;
+	}
+
+	/**
+	 * Returns the Custom width of the background Image of the Canvas.
+	 * 
+	 * @return backgroundWidth the Width
+	 */
+	public int getCanvasImageWidth() {
+		return backgroundWidth;
+	}
+	
+	/**
+	 * Returns the Custom height of the background Image of the Canvas.
+	 * 
+	 * @return backgroundHeight the height
+	 */
+	public int getCanvasImageHeight() {
+		return backgroundHeight;
+	}
+	
+	/**
+	 * Set the Path for the background Image of the Canvas.
+	 * 
+	 * @param paththe Path
+	 */
+	public void setCanvasImagePath(String path) {
+		imgPath = path;
+	}
+
+	/**
+	 * Set the mode for the background Image of the Canvas.
+	 * 
+	 * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
+	 * 
+	 * @param backgroundMode the mode
+	 */
+	public void setCanvasImageMode(int mode) {
+		backgroundMode = mode;
+	}
+
+	/**
+	 * Set the Custom width of the background Image of the Canvas.
+	 * 
+	 * @param width the Width
+	 */
+	public void setCanvasImageWidth(int width) {
+		backgroundWidth = width;
+	}
+	
+	/**
+	 * Set the Custom height of the background Image of the Canvas.
+	 * 
+	 * @param height the height
+	 */
+	public void setCanvasImageHeight(int height) {
+		backgroundHeight = height;
+	}
 }

+ 5 - 3
src/ui/view/BackgroundPopUp.java

@@ -11,6 +11,8 @@ import javax.swing.JButton;
 import org.eclipse.wb.swing.FocusTraversalOnArray;
 
 import classes.CpsUpperNode;
+import ui.controller.Control;
+import ui.model.Model;
 
 import java.awt.Component;
 import java.awt.event.ActionEvent;
@@ -71,13 +73,13 @@ public class BackgroundPopUp extends JDialog {
 
 	JFileChooser fileChooser;
 
-	public BackgroundPopUp(MyCanvas canvas, CpsUpperNode uNode) {
+	public BackgroundPopUp(Model model, Control controller, MyCanvas canvas, CpsUpperNode uNode) {
 		super((java.awt.Frame) null, true);
 		getContentPane().setBackground(Color.WHITE);
 		this.setTitle("Set View Background");
 		// Show background Image
 		if (canvas != null) {
-			path = canvas.getBackgroundPath();
+			path = model.getCanvasImagePath();
 		} else if (uNode != null) {
 			path = uNode.getImagePath();
 		}
@@ -196,7 +198,7 @@ public class BackgroundPopUp extends JDialog {
 						if (imageChanged) {
 							copieImage();
 						}
-						canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()),
+						controller.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()),
 								Integer.parseInt(imageHeight.getText()));
 						canvas.repaint();
 					} else if (uNode != null) {

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

@@ -687,14 +687,14 @@ public class GUI<E> implements CategoryListener {
 			public void actionPerformed(ActionEvent e) {
 				if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
 						.getComponent(0) instanceof MyCanvas) {
-					BackgroundPopUp backgroundDialog = new BackgroundPopUp(canvas, null);
+					BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller, canvas, null);
 					backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 					backgroundDialog.setVisible(true);
 				} else if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
 						.getComponent(0) instanceof UpperNodeCanvas) {
 					UpperNodeCanvas uNodeCanvas = (UpperNodeCanvas)(((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
 							.getComponent(0));
-					BackgroundPopUp backgroundDialog = new BackgroundPopUp(null, uNodeCanvas.upperNode);
+					BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller,null, uNodeCanvas.upperNode);
 					backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 					backgroundDialog.setVisible(true);
 					uNodeCanvas.repaint();

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

@@ -103,12 +103,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	private int animDelay = 1000 / animFPS; // animation Delay
 	private int animSteps = animDuration / animDelay; // animation Steps;
 
-	// Background Image
-	private String imgPath = "";
-	private int backgroundMode = 0;
-	private int backgroundWidth = 0;
-	private int backgroundHeight = 0;
-
 	// contains the value of the Capacity for new created Edges
 
 	/**
@@ -403,9 +397,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		g2.setRenderingHints(rh);
 
 		// Paint the Background
-		if (!imgPath.isEmpty()) {
-			img = new ImageIcon(imgPath).getImage();
-			switch (backgroundMode) {
+		if (!model.getCanvasImagePath().isEmpty()) {
+			img = new ImageIcon(model.getCanvasImagePath()).getImage();
+			switch (model.getCanvasImageMode()) {
 			case BackgroundPopUp.IMAGE_PIXELS:
 				g2.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
 				break;
@@ -413,7 +407,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(), null);
 				break;
 			case BackgroundPopUp.CUSTOM:
-				g2.drawImage(img, 0, 0, backgroundWidth, backgroundHeight, null);
+				g2.drawImage(img, 0, 0, model.getCanvasImageWidth(), model.getCanvasImageHeight(), null);
 				break;
 			default:
 				break;
@@ -1136,27 +1130,4 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	public boolean[] getShowedInformation() {
 		return showedInformation;
 	}
-
-	/**
-	 * Set the Background Image;
-	 * 
-	 * @param imagePath
-	 *            Image Path
-	 * @param mode
-	 *            Image Mode
-	 * @param width
-	 *            Image custom width
-	 * @param height
-	 *            Image custom height
-	 */
-	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
-		imgPath = imagePath;
-		backgroundMode = mode;
-		backgroundWidth = width;
-		backgroundHeight = height;
-	}
-	
-	public String getBackgroundPath(){
-		return imgPath;
-	}
 }