Browse Source

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

# Conflicts:
#	bin/ui/controller/Control$command.class
#	bin/ui/controller/Control.class
Teh-Hai Julian Zheng 8 years ago
parent
commit
4d8c7ef3c8

BIN
bin/ui/view/AddObjectPopUp.class


BIN
bin/ui/view/GUI$1.class


BIN
bin/ui/view/GUI$2.class


BIN
bin/ui/view/GUI$3.class


BIN
bin/ui/view/GUI$4.class


BIN
bin/ui/view/GUI$5.class


BIN
bin/ui/view/GUI$6.class


BIN
bin/ui/view/GUI.class


BIN
bin/ui/view/MyCanvas.class


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

@@ -8,6 +8,7 @@ import java.util.LinkedList;
 
 import classes.Category;
 import classes.CpsObject;
+import classes.HolonObject;
 import Interfaces.CategoryListener;
 import ui.model.Model;
 import ui.view.GUI;
@@ -43,6 +44,10 @@ public class Control {
 	public void addNewObject(Category cat, String name, String objType) {
 		categoryController.addNewHolonObject(cat, name, objType);
 	}
+	
+	public void addNewObject(Category cat, HolonObject object) {
+		categoryController.addObject(cat, object);
+	}
 
 	public void addNewTransformer(Category cat, String name, String objType) {
 		categoryController.addNewHolonTransformer(cat, name, objType);

+ 47 - 18
src/ui/view/AddObjectPopUp.java

@@ -23,23 +23,30 @@ import javax.swing.JList;
 import javax.swing.JOptionPane;
 import javax.swing.SwingConstants;
 
+import classes.Category;
 import classes.HolonElement;
+import classes.HolonObject;
 
 import javax.swing.JScrollBar;
 import javax.swing.ScrollPaneConstants;
 
+import ui.controller.Control;
+
 public class AddObjectPopUp extends JDialog {
 
 	private final JPanel contentPanel = new JPanel();
 	private AddElementPopUp addElement;
-	private JTextField textField;
-	private JTextField textField_1;
+	private JTextField objectName;
+	private JTextField sourcePath;
 	private ArrayList<HolonElement> hElements;
 	private DefaultListModel listModel;
 	private JList list;
-
+	private String imagePath;
+	private HolonObject theObject;
+	private Control controller;
 	private File selectedFile = null;
 	private String filePath = " ";
+	private String givenCategory;
 
 	/**
 	 * Launch the application.
@@ -72,10 +79,10 @@ public class AddObjectPopUp extends JDialog {
 			contentPanel.add(lblName);
 		}
 		{
-			textField = new JTextField();
-			textField.setBounds(135, 8, 86, 20);
-			contentPanel.add(textField);
-			textField.setColumns(10);
+			objectName = new JTextField();
+			objectName.setBounds(135, 8, 86, 20);
+			contentPanel.add(objectName);
+			objectName.setColumns(10);
 		}
 		{
 			JButton btnBrowseImage = new JButton("Browse Image");
@@ -89,10 +96,10 @@ public class AddObjectPopUp extends JDialog {
 
 		}
 		{
-			textField_1 = new JTextField();
-			textField_1.setBounds(135, 51, 271, 20);
-			contentPanel.add(textField_1);
-			textField_1.setColumns(10);
+			sourcePath = new JTextField();
+			sourcePath.setBounds(135, 51, 271, 20);
+			contentPanel.add(sourcePath);
+			sourcePath.setColumns(10);
 		}
 		{
 			JButton btnAddDefaultElement = new JButton("Add Default Element");
@@ -148,11 +155,22 @@ public class AddObjectPopUp extends JDialog {
 				JButton okButton = new JButton("OK");
 				okButton.addMouseListener(new MouseAdapter() {
 					public void mouseClicked(MouseEvent e) {
-						if (!textField_1.getText().equals(filePath)) {
-							Component frame = null;
-							JOptionPane.showMessageDialog(frame, "No image selected!");
-						} else {
+						Component frame = null;
+						if (!sourcePath.getText().equals(filePath)) {
+							//JOptionPane.showMessageDialog(frame, "No image selected!");
+						}
+						if(objectName.getText().length() == 0){
+							JOptionPane.showMessageDialog(frame, "please enter a name");
+						}
+						else {
 							copieFile();
+							theObject = new HolonObject(objectName.getText());
+							theObject.setElements(hElements);
+							theObject.setImage(imagePath);
+							controller.addNewObject(controller.searchCategory(givenCategory), theObject);
+							System.out.println(theObject.getImage());
+							System.out.println(givenCategory);
+							dispose();
 						}
 					}
 				});
@@ -182,7 +200,7 @@ public class AddObjectPopUp extends JDialog {
 		if (returnValue == JFileChooser.APPROVE_OPTION) {
 			selectedFile = FileChooser.getSelectedFile();
 			filePath = selectedFile.getAbsolutePath();
-			textField_1.setText(filePath);
+			sourcePath.setText(filePath);
 		} else {
 			System.out.println("Failed to Load");
 		}
@@ -194,10 +212,10 @@ public class AddObjectPopUp extends JDialog {
 		OutputStream outStream = null;
 		try {
 			File source = new File(filePath);
-			File dest = new File(System.getProperty("user.dir") + "/res/Images/", selectedFile.getName());
+			File dest = new File(System.getProperty("user.dir") + "/bin/Images/", selectedFile.getName());
+			imagePath = "/Images/" + selectedFile.getName() ;
 			inStream = new FileInputStream(source);
 			outStream = new FileOutputStream(dest);
-
 			byte[] buffer = new byte[1024];
 
 			int length;
@@ -214,4 +232,15 @@ public class AddObjectPopUp extends JDialog {
 			e1.printStackTrace();
 		}
 	}
+	
+	public HolonObject getObject(){
+		return theObject;
+	}
+	
+	public void setController(Control controller){
+		this.controller = controller;
+	}
+	public void setCategory(String cat){
+		givenCategory = cat;
+	}
 }

+ 27 - 10
src/ui/view/GUI.java

@@ -27,6 +27,7 @@ import javax.swing.table.DefaultTableModel;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Cursor;
+import java.awt.Dimension;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.Toolkit;
@@ -51,6 +52,9 @@ import Interfaces.CategoryListener;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.awt.event.ActionEvent;
 
 public class GUI implements CategoryListener {
@@ -147,9 +151,16 @@ public class GUI implements CategoryListener {
 		splitPane.setRightComponent(splitPane_1);
 		splitPane.setDividerLocation(200);
 		splitPane_1.setDividerLocation(500);
+		
 		canvas.setBackground(Color.WHITE);
+		canvas.setPreferredSize(new Dimension(10000, 10000));
+		JScrollPane canvasSP = new JScrollPane(canvas);
+		canvasSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
+		canvasSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 
-		tabbedPane.addTab("Modeling", null, canvas, null);
+		tabbedPane.addTab("Modeling", null, canvasSP, null);
+
+		
 		tabbedPane.addTab("Simulation", null, scrollPane_2, null);
 		dtrpnHereWillBe.setText("Here will be the Simulation");
 
@@ -291,6 +302,19 @@ public class GUI implements CategoryListener {
 						controller.addNewCategory(catName);
 					}
 					break;
+				
+				case "Object":
+					if (selectedNode == null) {
+						JOptionPane.showMessageDialog(new JFrame(),
+								"Please select a Category first before adding " + selectedOption + ".");
+					}
+					if (selectedNode.getLevel() == 1) {
+						addObjectPopUP = new AddObjectPopUp();
+						addObjectPopUP.setVisible(true);
+						addObjectPopUP.setController(controller);
+						addObjectPopUP.setCategory(selectedNode.toString());
+					}
+					break;
 
 				default:
 					addObjectAction(selectedOption, selectedNode);
@@ -373,24 +397,17 @@ public class GUI implements CategoryListener {
 			if (selectedNode.getLevel() == 1) {
 				String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
 				Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
-				if (objname.equals("show")) {
-					addObjectPopUP = new AddObjectPopUp();
-					addObjectPopUP.setVisible(true);
-				}
 
 				if (objname.length() != 0) {
 					switch (objType) {
 
-					case "Object":
-						controller.addNewObject(cat, objname, objType);
-
-						break;
-
 					case "Switch":
 						controller.addNewSwitch(cat, objname, objType);
+						break;
 
 					case "Transformer":
 						controller.addNewTransformer(cat, objname, objType);
+						break;
 					}
 				}
 			} else {

+ 7 - 1
src/ui/view/MyCanvas.java

@@ -3,6 +3,7 @@ package ui.view;
 import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Container;
+import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
@@ -183,7 +184,12 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
 			tempCps = null;
 		}
-		
+		if(y+GlobalVariables.SCALE>this.getHeight()){
+			this.setPreferredSize(new Dimension(this.getWidth(), y+GlobalVariables.SCALE));
+		}
+		if(x+GlobalVariables.SCALE>this.getHeight()){
+			this.setPreferredSize(new Dimension(x+GlobalVariables.SCALE,this.getHeight() ));
+		}
 		// Rechtsklick Liste
 		if (e.getButton() == e.BUTTON3) {
 			if (e.getButton() == e.BUTTON3 && tempCps != null) {