Pārlūkot izejas kodu

First added old functionality

tolatesry 6 gadi atpakaļ
vecāks
revīzija
02582c2168

+ 9 - 0
src/ui/controller/CategoryController.java

@@ -222,6 +222,15 @@ public class CategoryController {
 		holonBat.setSav(cat.getName());
 		addObject(cat, holonBat);
 	}
+	
+	public void addNewHolonBattery(Category cat, HolonBattery holonBat, String image) {
+		holonBat.setImage(image);
+		holonBat.setSav(cat.getName());
+		addObject(cat, holonBat);
+	}
+	
+	
+	
 	/**
 	 * Removes an Object from a Category.
 	 * @param category Category

+ 6 - 1
src/ui/controller/Control.java

@@ -252,7 +252,12 @@ public class Control {
         categoryController.addNewHolonBattery(cat, obj, "/Images/battery.png");
         saveCategory();
     }
-
+    //TODO make good
+    public void addBattery(Category cat, HolonBattery holonbat) throws IOException {
+        categoryController.addNewHolonBattery(cat, holonbat, "/Images/battery.png");
+        saveCategory();
+    }
+    
     /**
      * delete a given Category.
      *

+ 1 - 48
src/ui/view/GUI.java

@@ -1973,10 +1973,7 @@ public class GUI implements CategoryListener {
 		//TODO: Add functionalyty
 		btnAddPopUp.add(mItemNew);
 		mItemNew.addActionListener(actionEvent -> {
-			System.out.println("New..");
-			showHint(true);
 			new NewPopUp(controller, frmCyberPhysical);
-			//jDialog1.setModal(true);
 		});
 		btnAddPopUp.addSeparator();
 		btnAddPopUp.add(mItemCategory);
@@ -1995,51 +1992,7 @@ public class GUI implements CategoryListener {
 		mItemBattery.addActionListener(actionEvent -> {
 			new NewPopUp(controller,Option.Battery, frmCyberPhysical);
 		});
-		btnAdd.addActionListener(actionEvent -> {
-			btnAddPopUp.show(btnAdd, 0, 0);
-			
-			//btnAddPopUp.
-			//JOptionPane.showMessageDialog(contentPane, "Work in Progress" , "Message" , JOptionPane.WARNING_MESSAGE);
-			/*
-			Object nodeInfo = tree.getLastSelectedPathComponent();
-			String selectedOption = comboBox.getSelectedItem().toString();
-			DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
-			try {
-
-				switch (selectedOption) {
-
-				case "Category":
-					String catName = JOptionPane.showInputDialog(
-							frmCyberPhysical, Languages.getLanguage()[56]);
-					if (catName.length() != 0) {
-						controller.addCategory(catName);
-					}
-					break;
-				case "Object":
-					if (selectedNode == null) {
-						JOptionPane.showMessageDialog(frmCyberPhysical,
-								Languages.getLanguage()[57] + selectedOption
-										+ ".");
-					}
-					if (selectedNode != null && selectedNode.getLevel() == 1) {
-						AbstractCpsObject tmp = new HolonObject("");
-						addObjectPopUP = new AddObjectPopUp(false, tmp, null,
-								frmCyberPhysical);
-						addObjectPopUP.setVisible(true);
-						addObjectPopUP.setController(controller);
-						addObjectPopUP.setCategory(selectedNode.toString());
-					}
-					break;
-
-				default:
-					addObjectAction(selectedOption, selectedNode);
-					break;
-				}
-			} catch (Exception e) {
-			}
-			tree.repaint();
-			*/
-		});
+		btnAdd.addActionListener(actionEvent -> btnAddPopUp.show(btnAdd, 0, 0));
 		toolBar.add(btnAdd);
 		/**
 		 * Help Menu Action Listeners

+ 55 - 20
src/ui/view/NewPopUp.java

@@ -2,10 +2,8 @@ package ui.view;
 
 import java.awt.BorderLayout;
 import java.awt.CardLayout;
-import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
-import java.awt.GridBagLayout;
 import java.awt.GridLayout;
 import java.io.IOException;
 
@@ -19,14 +17,12 @@ import javax.swing.JTextField;
 
 import classes.HolonBattery;
 import classes.HolonObject;
-import javafx.scene.paint.Color;
 import ui.controller.Control;
 
 
 
 public class NewPopUp extends JDialog{
 	//DefaultConstructor
-	
 	String[] optionStrings = { "","Category", "Object", "Battery", "Switch"};
 	public static enum Option {
 		None, Category, Object, Battery, Switch;
@@ -45,13 +41,11 @@ public class NewPopUp extends JDialog{
 	JComboBox<String> optionList = new JComboBox<String>(optionStrings);
 	JTextField inputName = new JTextField();
 	JButton saveButton = new JButton("Save");
+	//TODO
+	JTextField inputNameSwitch = new JTextField();
+	JComboBox<String> selectedCategorySwitch = new JComboBox<String>();
 	
 	
-	public static void main(String[] args) {
-		NewPopUp dialog = new NewPopUp(null, null);
-		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-
-	}
 	
 	NewPopUp(Control controller, JFrame parentFrame){
 		super((JFrame)parentFrame, "Create a..");
@@ -74,7 +68,7 @@ public class NewPopUp extends JDialog{
 		    cl.show(cards, actualOption.name());
 		    saveButton.setEnabled(actualOption != Option.None);  
 		    //TODO delete and make own iterface
-		    saveButton.setVisible(actualOption != Option.Object);	
+		    saveButton.setVisible(actualOption != Option.Object && actualOption != Option.Battery);	
 		});
 		
 		
@@ -82,7 +76,7 @@ public class NewPopUp extends JDialog{
         addSaveButtonLogik();
         add(contentPanel);
         saveButton.setEnabled(false);	
-		setMinimumSize(new Dimension(400,350));
+		setMinimumSize(new Dimension(400,50));
 		pack();
 		setLocationRelativeTo(parentFrame);
 	}
@@ -120,9 +114,9 @@ public class NewPopUp extends JDialog{
 		contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
 		addSaveButtonLogik(); 
 		//TODO delete and make own iterface
-	    if(aOption == Option.Object) saveButton.setVisible(false);
+	    if(aOption == Option.Object || aOption == Option.Battery) saveButton.setVisible(false);
 		add(contentPanel);	
-		setMinimumSize(new Dimension(400,350));
+		setMinimumSize(new Dimension(400,50));
 		pack();
 		setLocationRelativeTo(parentFrame);
 	}
@@ -191,8 +185,16 @@ public class NewPopUp extends JDialog{
 		return objectPanel;
 	}
 
-	private void makeOldBatteryPopUp(String string) {
-		
+	private void makeOldBatteryPopUp(String category) {
+		HolonBattery holonbat = new HolonBattery("newBattery");
+		try {
+			actualController.addBattery(actualController.searchCategory(category), holonbat);
+			AddObjectPopUp addObjectPopUP = new AddObjectPopUp(false,holonbat , "hei", null);
+			addObjectPopUP.setVisible(true);
+			addObjectPopUP.setController(actualController);
+			dispose();
+		} catch (IOException e) {
+		}
 	}
 
 	private JPanel makeNothingPanel() {
@@ -227,15 +229,39 @@ public class NewPopUp extends JDialog{
 	}
 	private JPanel makeSwitchPanel()
 	{
-		JPanel newCategory = new JPanel();
-		JLabel categoryName = new JLabel("Name:Switch");
+		JPanel objectPanel = new JPanel();
+		JLabel categoryText = new JLabel("In Category:");
+		objectPanel.add(categoryText);
+		selectedCategorySwitch = new JComboBox<String>(actualController.getCategoriesStrings());
+		objectPanel.add(selectedCategorySwitch);
 		
-		newCategory.add(categoryName);
-		return newCategory;
+		
+		JLabel switchName = new JLabel("Name:");
+		String initialText = "The name of the new switch";
+		
+		inputNameSwitch.setText(initialText);
+		inputNameSwitch.setBackground(java.awt.Color.LIGHT_GRAY);
+		inputNameSwitch.addFocusListener(new java.awt.event.FocusAdapter() {
+		    public void focusGained(java.awt.event.FocusEvent evt) {
+		       if (inputNameSwitch.getText().equals(initialText)) {
+		    	   inputNameSwitch.setText("");
+		    	   inputNameSwitch.setBackground(java.awt.Color.WHITE);
+		       }
+		    }
+		    public void focusLost (java.awt.event.FocusEvent evt) {
+			       if (inputNameSwitch.getText().equals("")) {
+			    	   inputNameSwitch.setText(initialText);
+			    	   inputNameSwitch.setBackground(java.awt.Color.LIGHT_GRAY);
+			       }
+			    }
+		});
+		inputNameSwitch.setColumns(20);
+		objectPanel.add(switchName);
+		objectPanel.add(inputNameSwitch);
+		return objectPanel;
 	}	
 	private void addSaveButtonLogik() {
 		saveButton.addActionListener(actionEvent -> {
-			System.out.println(actualOption);
 			if(actualOption == Option.Category)
 			{
 				try {
@@ -245,6 +271,15 @@ public class NewPopUp extends JDialog{
 				}
 				dispose();
 			}
+			else if (actualOption == Option.Switch)
+			{//TODO
+				try {
+					actualController.addSwitch(actualController.searchCategory(selectedCategorySwitch.getSelectedItem().toString()), inputNameSwitch.getText());
+				} catch (IOException e) {
+					System.err.println("IOException addSwitch");
+				}
+				dispose();
+			}
 		});
 	}
 }