|
@@ -1,11 +1,12 @@
|
|
|
package ui.view;
|
|
|
|
|
|
import classes.AbstractCpsObject;
|
|
|
+import classes.HolonBattery;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.Pair;
|
|
|
import ui.controller.Control;
|
|
|
-
|
|
|
+import java.lang.NumberFormatException;
|
|
|
import javax.swing.*;
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
@@ -42,21 +43,21 @@ public class AddObjectPopUp extends JDialog {
|
|
|
private boolean editState;
|
|
|
private boolean imageChanged = false;
|
|
|
|
|
|
-// /**
|
|
|
-// * Launch the application.
|
|
|
-// *
|
|
|
-// * @param args
|
|
|
-// * standard
|
|
|
-// */
|
|
|
-// public static void main(String[] args) {
|
|
|
-// try {
|
|
|
-// AddObjectPopUp dialog = new AddObjectPopUp(false, null, null);
|
|
|
-// dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
-// dialog.setVisible(true);
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * Launch the application.
|
|
|
+ *
|
|
|
+ * @param args
|
|
|
+ * standard
|
|
|
+ */
|
|
|
+ public static void main(String[] args) {
|
|
|
+ try {
|
|
|
+ AddObjectPopUp dialog = new AddObjectPopUp(false,new HolonBattery("jo") , "hei", null);
|
|
|
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
+ dialog.setVisible(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Create the dialog.
|
|
@@ -69,6 +70,11 @@ public class AddObjectPopUp extends JDialog {
|
|
|
* the categorie
|
|
|
*/
|
|
|
AddObjectPopUp(boolean edit, AbstractCpsObject obj, String cat, JFrame parentFrame) {
|
|
|
+ if(obj instanceof HolonBattery)
|
|
|
+ {
|
|
|
+ BatteryPopUp(edit, obj, cat, parentFrame);
|
|
|
+ return;
|
|
|
+ }
|
|
|
toEdit = obj;
|
|
|
editState = edit;
|
|
|
this.setIconImage(Util.loadImage(this, "/Images/Dummy_House.png",30,30));
|
|
@@ -275,7 +281,118 @@ public class AddObjectPopUp extends JDialog {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ protected void BatteryPopUp(boolean edit, AbstractCpsObject obj, String cat, JFrame parentFrame) {
|
|
|
+ //TODO: Click mich <3
|
|
|
+ HolonBattery editBat = (HolonBattery) obj;
|
|
|
+ //Window Settings
|
|
|
+ this.setIconImage(Util.loadImage(this, "/Images/battery.png",30,30));
|
|
|
+ this.setTitle("Edit Battery");
|
|
|
+ setBounds(0, 0, 285, 290);
|
|
|
+ setLocationRelativeTo(parentFrame);
|
|
|
+
|
|
|
+ //Labels, TextFiels, Buttons
|
|
|
+ JPanel myPanel = new JPanel();
|
|
|
+ myPanel.setLayout(null);
|
|
|
+ int beginBoxX = 140, beginLabelX = 30;
|
|
|
+ int beginColumAtY = 20, newColumY = 40;
|
|
|
+ JLabel batteryNameLabel = new JLabel("Name:");
|
|
|
+ JTextField batteryNameBox = new JTextField(10);
|
|
|
+ batteryNameBox.setText(editBat.getName());
|
|
|
+ JLabel batteryInRateLabel = new JLabel("In ratio:");
|
|
|
+ JTextField batteryInRateBox = new JTextField(10);
|
|
|
+ batteryInRateBox.setText(Float.toString(editBat.getInRatio()));
|
|
|
+ JLabel batteryOutRateLabel = new JLabel("Out ratio:");
|
|
|
+ JTextField batteryOutRateBox = new JTextField(10);
|
|
|
+ batteryOutRateBox.setText(Float.toString(editBat.getOutRatio()));
|
|
|
+ JLabel batteryCapasityLabel = new JLabel("Capasity:");
|
|
|
+ JTextField batteryCapasityBox = new JTextField(10);
|
|
|
+ batteryCapasityBox.setText(Float.toString(editBat.getCapasity()));
|
|
|
+ JLabel batterySOCLabel = new JLabel("State of charge:");
|
|
|
+ JTextField batterySOCBox = new JTextField(10);
|
|
|
+ batterySOCBox.setText(Float.toString(editBat.getStateOfCharge()));
|
|
|
+
|
|
|
+
|
|
|
+ batteryNameLabel.setBounds(beginLabelX, beginColumAtY, 200, 20);
|
|
|
+ batteryNameBox.setBounds(beginBoxX, beginColumAtY, 100, 20);
|
|
|
+ myPanel.add(batteryNameLabel);
|
|
|
+ myPanel.add(batteryNameBox);
|
|
|
+ beginColumAtY += newColumY;
|
|
|
+
|
|
|
+ batteryInRateLabel.setBounds(beginLabelX, beginColumAtY, 200, 20);
|
|
|
+ batteryInRateBox.setBounds(beginBoxX, beginColumAtY, 100, 20);
|
|
|
+ myPanel.add(batteryInRateLabel);
|
|
|
+ myPanel.add(batteryInRateBox);
|
|
|
+ beginColumAtY += newColumY;
|
|
|
+
|
|
|
+ batteryOutRateLabel.setBounds(beginLabelX, beginColumAtY, 200, 20);
|
|
|
+ batteryOutRateBox.setBounds(beginBoxX, beginColumAtY, 100, 20);
|
|
|
+ myPanel.add(batteryOutRateLabel);
|
|
|
+ myPanel.add(batteryOutRateBox);
|
|
|
+ beginColumAtY += newColumY;
|
|
|
+
|
|
|
+ batteryCapasityLabel.setBounds(beginLabelX, beginColumAtY, 200, 20);
|
|
|
+ batteryCapasityBox.setBounds(beginBoxX, beginColumAtY, 100, 20);
|
|
|
+ myPanel.add(batteryCapasityLabel);
|
|
|
+ myPanel.add(batteryCapasityBox);
|
|
|
+ beginColumAtY += newColumY;
|
|
|
+
|
|
|
+ batterySOCLabel.setBounds(beginLabelX, beginColumAtY, 200, 20);
|
|
|
+ batterySOCBox.setBounds(beginBoxX, beginColumAtY, 100, 20);
|
|
|
+ myPanel.add(batterySOCLabel);
|
|
|
+ myPanel.add(batterySOCBox);
|
|
|
+
|
|
|
+ //Save , Cancel
|
|
|
+ JPanel bottomPanel = new JPanel();
|
|
|
+ bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
|
+
|
|
|
+ JButton saveButton = new JButton("Save");
|
|
|
+ bottomPanel.add(saveButton);
|
|
|
+
|
|
|
+ saveButton.addActionListener(e -> {
|
|
|
+ //SaveButten Event:
|
|
|
+ if(batteryNameBox.getText().isEmpty()){ //Check for valid name
|
|
|
+ JOptionPane.showMessageDialog(getContentPane(), "Name is empty." , "Wrong input" , JOptionPane.WARNING_MESSAGE);
|
|
|
+ }else{
|
|
|
+ editBat.setName(batteryNameBox.getText());
|
|
|
+ try{//Check for floats inputs
|
|
|
+ float changedInRatio = Float.valueOf(batteryInRateBox.getText());
|
|
|
+ float changedOutRatio = Float.valueOf(batteryOutRateBox.getText());
|
|
|
+ float changedCapasity = Float.valueOf(batteryCapasityBox.getText());
|
|
|
+ float changedSOC = Float.valueOf(batterySOCBox.getText());
|
|
|
+ //Saving:
|
|
|
+ editBat.setInRatio(changedInRatio);
|
|
|
+ editBat.setOutRatio(changedOutRatio);
|
|
|
+ editBat.setCapasity(changedCapasity);
|
|
|
+ editBat.setStateOfCharge(changedSOC);
|
|
|
+ try {
|
|
|
+ controller.saveCategory();
|
|
|
+ controller.notifyAll();
|
|
|
+ } catch (Exception e1) { //Controller Exceptions
|
|
|
+ }
|
|
|
+ dispose();
|
|
|
+ }catch(NumberFormatException FloatException){
|
|
|
+ String wrong= FloatException.getMessage();
|
|
|
+ String message;
|
|
|
+ if(wrong.startsWith("empty")){
|
|
|
+ message = "A field is empty.";
|
|
|
+ }else{
|
|
|
+ message = wrong.substring(18) + " is not a valid Number.";
|
|
|
+ }
|
|
|
+ JOptionPane.showMessageDialog(getContentPane(), message, "Wrong input" , JOptionPane.WARNING_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ JButton cancelButton = new JButton("Cancel");
|
|
|
+ bottomPanel.add(cancelButton);
|
|
|
+ cancelButton.addActionListener(e -> dispose());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getContentPane().setLayout(new BorderLayout());
|
|
|
+ getContentPane().add(myPanel, BorderLayout.CENTER);
|
|
|
+ getContentPane().add(bottomPanel, BorderLayout.SOUTH);
|
|
|
+ }
|
|
|
// /**
|
|
|
// * Get Jar Containing Folder.
|
|
|
// *
|