Browse Source

change background image for uppernodes

Kevin Trometer 7 years ago
parent
commit
b0eacd7b9d

+ 59 - 0
src/classes/CpsUpperNode.java

@@ -9,6 +9,11 @@ public class CpsUpperNode extends AbstractCpsObject {
 	private ArrayList<CpsEdge> nodeEdges;
 	private ArrayList<CpsEdge> oldEdges;
 	private HashMap<Integer, Integer> nodesIdx;
+	// Background Image
+	private String imgPath = "";
+	private int backgroundMode = 0;
+	private int backgroundWidth = 0;
+	private int backgroundHeight = 0;
 
 	public CpsUpperNode(String nodeName) {
 		super(nodeName);
@@ -124,4 +129,58 @@ public class CpsUpperNode extends AbstractCpsObject {
 		return result;
 	}
 
+	/**
+	 * 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;
+	}
+
+	/**
+	 * Get the Background Image Path.
+	 * 
+	 * @return imgPath Path of the Image
+	 */
+	public String getImagePath() {
+		return imgPath;
+	}
+
+	/**
+	 * Get the Background mode.
+	 * 
+	 * @return mode the mode
+	 */
+	public int getBackgroundMode() {
+		return backgroundMode;
+	}
+	
+	/**
+	 * Get the Background image Width.
+	 * 
+	 * @return mode the width of the Image
+	 */
+	public int getImageWidht() {
+		return backgroundWidth;
+	}
+	
+	/**
+	 * Get the Background image Height.
+	 * 
+	 * @return mode the mode
+	 */
+	public int getImageHeight() {
+		return backgroundHeight;
+	}
 }

+ 1 - 1
src/ui/view/BackgroundPopUp.java

@@ -166,7 +166,7 @@ public class BackgroundPopUp extends JDialog {
 					canvas.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()), Integer.parseInt(imageHeight.getText()));
 					canvas.repaint();
 				} else if (uNode != null) {
-
+					uNode.setBackgroundImage(path, mode, Integer.parseInt(imageWidth.getText()), Integer.parseInt(imageHeight.getText()));
 				}
 				dispose();
 			}

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

@@ -685,9 +685,20 @@ public class GUI<E> implements CategoryListener {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				BackgroundPopUp backgroundDialog = new BackgroundPopUp(canvas, null);
-				backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-				backgroundDialog.setVisible(true);
+				if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+						.getComponent(0) instanceof MyCanvas) {
+					BackgroundPopUp backgroundDialog = new BackgroundPopUp(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);
+					backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+					backgroundDialog.setVisible(true);
+					uNodeCanvas.repaint();
+				}
 			}
 		});
 

+ 17 - 12
src/ui/view/UpperNodeCanvas.java

@@ -113,11 +113,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	private Position unPos;
 	private ArrayList<Position> savePos;
 
-	// Background Image
-	private String imgPath = "";
-	private int backgroundMode = 0;
-	private int backgroundWidth = 0;
-	private int backgroundHeight = 0;
+	
 
 	/**
 	 * Constructor.
@@ -418,9 +414,21 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		g2.setRenderingHints(rh);
 
 		// Paint the Background
-		if (!imgPath.isEmpty()) {
-			img = new ImageIcon(imgPath).getImage();
-			g2.drawImage(img, borderPos, 0, model.getCanvasX(), model.getCanvasY(), null);
+		if (!upperNode.getImagePath().isEmpty()) {
+			img = new ImageIcon(upperNode.getImagePath()).getImage();
+			switch (upperNode.getBackgroundMode()) {
+			case BackgroundPopUp.IMAGE_PIXELS:
+				g2.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
+				break;
+			case BackgroundPopUp.STRETCHED:
+				g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(), null);
+				break;
+			case BackgroundPopUp.CUSTOM:
+				g2.drawImage(img, 0, 0, upperNode.getImageWidht(), upperNode.getImageHeight(), null);
+				break;
+			default:
+				break;
+			}
 		}
 
 		// Left Border
@@ -1459,10 +1467,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 *            Image custom height
 	 */
 	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
-		imgPath = imagePath;
-		backgroundMode = mode;
-		backgroundWidth = width;
-		backgroundHeight = height;
+		upperNode.setBackgroundImage(imagePath, mode, width, height);
 	}
 
 }