فهرست منبع

NewPopUp integriert, aber es fehlt noch viel

tolatesry 7 سال پیش
والد
کامیت
4c246a6f47
2فایلهای تغییر یافته به همراه57 افزوده شده و 12 حذف شده
  1. 7 6
      src/ui/view/GUI.java
  2. 50 6
      src/ui/view/NewPopUp.java

+ 7 - 6
src/ui/view/GUI.java

@@ -14,6 +14,7 @@ import ui.controller.Control;
 import ui.controller.SimulationManager;
 import ui.controller.UpdateController;
 import ui.model.Model;
+import ui.view.NewPopUp.NewItem;
 
 import javax.swing.*;
 import javax.swing.border.LineBorder;
@@ -1974,25 +1975,25 @@ public class GUI implements CategoryListener {
 		mItemNew.addActionListener(actionEvent -> {
 			System.out.println("New..");
 			showHint(true);
+			new NewPopUp(controller, frmCyberPhysical);
+			//jDialog1.setModal(true);
 		});
 		btnAddPopUp.addSeparator();
 		btnAddPopUp.add(mItemCategory);
 		mItemCategory.addActionListener(actionEvent -> {
-			System.out.println("Category");
-			lblHint.setText("Category");
+			new NewPopUp(controller,NewItem.Category, frmCyberPhysical);
 		});
 		btnAddPopUp.add(mItemObject);
 		mItemObject.addActionListener(actionEvent -> {
-			System.out.println("Object");
-			showHint(false);
+			new NewPopUp(controller,NewItem.Object, frmCyberPhysical);
 		});
 		btnAddPopUp.add(mItemSwitch);
 		mItemSwitch.addActionListener(actionEvent -> {
-			System.out.println("Switch");
+			new NewPopUp(controller,NewItem.Switch, frmCyberPhysical);
 		});
 		btnAddPopUp.add(mItemBattery);
 		mItemBattery.addActionListener(actionEvent -> {
-			System.out.println("Battery");
+			new NewPopUp(controller,NewItem.Battery, frmCyberPhysical);
 		});
 		btnAdd.addActionListener(actionEvent -> {
 			btnAddPopUp.show(btnAdd, 0, 0);

+ 50 - 6
src/ui/view/NewPopUp.java

@@ -10,10 +10,13 @@ import java.awt.GridLayout;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
+import ui.controller.Control;
+
 
 
 public class NewPopUp extends JDialog{
@@ -40,16 +43,15 @@ public class NewPopUp extends JDialog{
 	
 	
 	public static void main(String[] args) {
-		NewPopUp dialog = new NewPopUp();
+		NewPopUp dialog = new NewPopUp(null, null);
 		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 
 	}
 	
-	NewPopUp(){
-		super((JDialog)null, "Create a..");
+	NewPopUp(Control controller, JFrame parentFrame){
+		super((JFrame)parentFrame, "Create a..");
 		setVisible(true);
 		JPanel contentPanel = new JPanel();
-		
 		contentPanel.setLayout(new BorderLayout());
 		contentPanel.add(makeTopPanel(), BorderLayout.PAGE_START);
 		JPanel cards = new JPanel(new CardLayout());
@@ -68,13 +70,55 @@ public class NewPopUp extends JDialog{
 		});
 		saveButton.addActionListener(actionEvent -> {
 			System.out.println(choosenOption);
-			
+			if(choosenOption == NewItem.Category)
+			{
+				try {
+					controller.addCategory(inputName.getText());
+				} catch (Exception e) {
+				}
+			}
 		});
 		
         contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
         
         add(contentPanel);	
-		setMinimumSize(new Dimension(200,200));
+		setMinimumSize(new Dimension(400,350));
+		pack();
+		setLocationRelativeTo(parentFrame);
+	}
+	NewPopUp(Control controller, NewItem aOption, JFrame parentFrame){
+		super((JFrame)parentFrame, "Create a " + aOption.name());
+		if(aOption == NewItem.None)
+			dispose();
+		setVisible(true);
+		JPanel contentPanel = new JPanel();
+		contentPanel.setLayout(new BorderLayout());
+		JPanel content;
+		switch(aOption)
+		{
+		case Battery:
+			content = makeBatteryPanel();
+			break;
+		case Category:
+			content = makeCategoryPanel();
+			break;
+		case Object:
+			content = makeObjectPanel();
+			break;
+		case Switch:
+			content = makeSwitchPanel();
+			break;
+		default:
+			content = new JPanel();
+			break;
+		}
+		choosenOption = aOption;
+		contentPanel.add(content, BorderLayout.CENTER);
+		contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
+		add(contentPanel);	
+		setMinimumSize(new Dimension(400,350));
+		pack();
+		setLocationRelativeTo(parentFrame);
 	}
 
 	private JPanel makeTopPanel() {