|
@@ -2,10 +2,8 @@ package ui.view;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.CardLayout;
|
|
import java.awt.CardLayout;
|
|
-import java.awt.Component;
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.Dimension;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.FlowLayout;
|
|
-import java.awt.GridBagLayout;
|
|
|
|
import java.awt.GridLayout;
|
|
import java.awt.GridLayout;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
|
@@ -19,14 +17,12 @@ import javax.swing.JTextField;
|
|
|
|
|
|
import classes.HolonBattery;
|
|
import classes.HolonBattery;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
-import javafx.scene.paint.Color;
|
|
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NewPopUp extends JDialog{
|
|
public class NewPopUp extends JDialog{
|
|
//DefaultConstructor
|
|
//DefaultConstructor
|
|
-
|
|
|
|
String[] optionStrings = { "","Category", "Object", "Battery", "Switch"};
|
|
String[] optionStrings = { "","Category", "Object", "Battery", "Switch"};
|
|
public static enum Option {
|
|
public static enum Option {
|
|
None, Category, Object, Battery, Switch;
|
|
None, Category, Object, Battery, Switch;
|
|
@@ -45,13 +41,11 @@ public class NewPopUp extends JDialog{
|
|
JComboBox<String> optionList = new JComboBox<String>(optionStrings);
|
|
JComboBox<String> optionList = new JComboBox<String>(optionStrings);
|
|
JTextField inputName = new JTextField();
|
|
JTextField inputName = new JTextField();
|
|
JButton saveButton = new JButton("Save");
|
|
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){
|
|
NewPopUp(Control controller, JFrame parentFrame){
|
|
super((JFrame)parentFrame, "Create a..");
|
|
super((JFrame)parentFrame, "Create a..");
|
|
@@ -74,7 +68,7 @@ public class NewPopUp extends JDialog{
|
|
cl.show(cards, actualOption.name());
|
|
cl.show(cards, actualOption.name());
|
|
saveButton.setEnabled(actualOption != Option.None);
|
|
saveButton.setEnabled(actualOption != Option.None);
|
|
//TODO delete and make own iterface
|
|
//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();
|
|
addSaveButtonLogik();
|
|
add(contentPanel);
|
|
add(contentPanel);
|
|
saveButton.setEnabled(false);
|
|
saveButton.setEnabled(false);
|
|
- setMinimumSize(new Dimension(400,350));
|
|
|
|
|
|
+ setMinimumSize(new Dimension(400,50));
|
|
pack();
|
|
pack();
|
|
setLocationRelativeTo(parentFrame);
|
|
setLocationRelativeTo(parentFrame);
|
|
}
|
|
}
|
|
@@ -120,9 +114,9 @@ public class NewPopUp extends JDialog{
|
|
contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
|
|
contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
|
|
addSaveButtonLogik();
|
|
addSaveButtonLogik();
|
|
//TODO delete and make own iterface
|
|
//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);
|
|
add(contentPanel);
|
|
- setMinimumSize(new Dimension(400,350));
|
|
|
|
|
|
+ setMinimumSize(new Dimension(400,50));
|
|
pack();
|
|
pack();
|
|
setLocationRelativeTo(parentFrame);
|
|
setLocationRelativeTo(parentFrame);
|
|
}
|
|
}
|
|
@@ -191,8 +185,16 @@ public class NewPopUp extends JDialog{
|
|
return objectPanel;
|
|
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() {
|
|
private JPanel makeNothingPanel() {
|
|
@@ -227,15 +229,39 @@ public class NewPopUp extends JDialog{
|
|
}
|
|
}
|
|
private JPanel makeSwitchPanel()
|
|
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() {
|
|
private void addSaveButtonLogik() {
|
|
saveButton.addActionListener(actionEvent -> {
|
|
saveButton.addActionListener(actionEvent -> {
|
|
- System.out.println(actualOption);
|
|
|
|
if(actualOption == Option.Category)
|
|
if(actualOption == Option.Category)
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
@@ -245,6 +271,15 @@ public class NewPopUp extends JDialog{
|
|
}
|
|
}
|
|
dispose();
|
|
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();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|