|
@@ -6,6 +6,7 @@ import classes.HolonObject;
|
|
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
import javax.swing.border.EmptyBorder;
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
+
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
import java.awt.event.KeyEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.awt.event.KeyListener;
|
|
import java.awt.event.KeyListener;
|
|
@@ -14,6 +15,7 @@ import java.awt.event.KeyListener;
|
|
* popup for adding an Holon Element to a holon Object.
|
|
* popup for adding an Holon Element to a holon Object.
|
|
*
|
|
*
|
|
* @author Gruppe14
|
|
* @author Gruppe14
|
|
|
|
+ * @author improved by A.T.M.-B. (Gruppe007)
|
|
*/
|
|
*/
|
|
public class AddElementPopUp extends JDialog {
|
|
public class AddElementPopUp extends JDialog {
|
|
|
|
|
|
@@ -21,38 +23,39 @@ public class AddElementPopUp extends JDialog {
|
|
* Serial.
|
|
* Serial.
|
|
*/
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
+ /* Data */
|
|
|
|
+ /** Holon Object the Element should be added to */
|
|
|
|
+ private AbstractCpsObject tempCps;
|
|
|
|
+ /** Holon Element that should be edited (if in edit Modus */
|
|
|
|
+ private HolonElement hl;
|
|
|
|
+
|
|
|
|
+ /* GUI */
|
|
|
|
+ /** Panel containing everything */
|
|
private final JPanel contentPanel = new JPanel();
|
|
private final JPanel contentPanel = new JPanel();
|
|
|
|
+ /** Textfield for entering a Name for the Element */
|
|
private JTextField elementName;
|
|
private JTextField elementName;
|
|
|
|
+ /** Textfield for the energy the Element consumes/produces */
|
|
private JTextField providedEnergy;
|
|
private JTextField providedEnergy;
|
|
|
|
+ /** Element is active if checked */
|
|
|
|
+ JCheckBox checkBoxActive;
|
|
|
|
+ /** Textfield to enter the amount of this Element */
|
|
private JTextField amount;
|
|
private JTextField amount;
|
|
- private HolonElement hl;
|
|
|
|
- private AbstractCpsObject tempCps;
|
|
|
|
-
|
|
|
|
- // /**
|
|
|
|
- // * Launch the application.
|
|
|
|
- // *
|
|
|
|
- // * @param args
|
|
|
|
- // * standard
|
|
|
|
- // */
|
|
|
|
- // public static void main(String[] args) {
|
|
|
|
- // try {
|
|
|
|
- //
|
|
|
|
- // AddElementPopUp dialog = new AddElementPopUp();
|
|
|
|
- // dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
|
- // dialog.setVisible(true);
|
|
|
|
- // } catch (Exception e) {
|
|
|
|
- // e.printStackTrace();
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
|
|
+ /** Textfield to enter the flexible Energy of the Element */
|
|
|
|
+ private JTextField flexibleEnergy;
|
|
|
|
+ /** Flexible if checkbox is checked */
|
|
|
|
+ JCheckBox checkboxFlexible;
|
|
|
|
+ /** Panel for the Graph */
|
|
|
|
+ JPanel panelGraph;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Create the dialog.
|
|
|
|
|
|
+ * Create the AddElementPopup Dialog
|
|
|
|
+ * @param parentFrame
|
|
*/
|
|
*/
|
|
AddElementPopUp(JFrame parentFrame) {
|
|
AddElementPopUp(JFrame parentFrame) {
|
|
super((java.awt.Frame) null, true);
|
|
super((java.awt.Frame) null, true);
|
|
this.setIconImage(Util.loadImage(this, "/Images/Dummy_House.png", 30, 30));
|
|
this.setIconImage(Util.loadImage(this, "/Images/Dummy_House.png", 30, 30));
|
|
setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
|
|
setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
|
|
- setBounds(100, 100, 400, 190);
|
|
|
|
|
|
+ setBounds(100, 100, 400, 515);
|
|
setLocationRelativeTo(parentFrame);
|
|
setLocationRelativeTo(parentFrame);
|
|
getContentPane().setLayout(new BorderLayout());
|
|
getContentPane().setLayout(new BorderLayout());
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
@@ -60,18 +63,8 @@ public class AddElementPopUp extends JDialog {
|
|
contentPanel.setLayout(null);
|
|
contentPanel.setLayout(null);
|
|
this.setTitle(Languages.getLanguage()[64]);
|
|
this.setTitle(Languages.getLanguage()[64]);
|
|
|
|
|
|
- JLabel lblElementName = new JLabel(Languages.getLanguage()[65]);
|
|
|
|
- lblElementName.setBounds(10, 11, 100, 14);
|
|
|
|
- contentPanel.add(lblElementName);
|
|
|
|
-
|
|
|
|
- JLabel lblProvidedEnergy = new JLabel(Languages.getLanguage()[66]);
|
|
|
|
- lblProvidedEnergy.setBounds(10, 49, 120, 14);
|
|
|
|
- contentPanel.add(lblProvidedEnergy);
|
|
|
|
-
|
|
|
|
- JLabel lblAmount = new JLabel(Languages.getLanguage()[67]);
|
|
|
|
- lblAmount.setBounds(10, 84, 100, 14);
|
|
|
|
- contentPanel.add(lblAmount);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /* Element Name Textfield and Label */
|
|
elementName = new JTextField();
|
|
elementName = new JTextField();
|
|
elementName.addKeyListener(new KeyListener() {
|
|
elementName.addKeyListener(new KeyListener() {
|
|
@Override
|
|
@Override
|
|
@@ -87,22 +80,62 @@ public class AddElementPopUp extends JDialog {
|
|
elementName.setBackground(Color.WHITE);
|
|
elementName.setBackground(Color.WHITE);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- elementName.setBounds(130, 8, 110, 20);
|
|
|
|
|
|
+
|
|
|
|
+ JLabel lblElementName = new JLabel(Languages.getLanguage()[65]);
|
|
|
|
+ lblElementName.setBounds(10, 10, 100, 20);
|
|
|
|
+ contentPanel.add(lblElementName);
|
|
|
|
+ elementName.setBounds(130, 10, 110, 20);
|
|
contentPanel.add(elementName);
|
|
contentPanel.add(elementName);
|
|
elementName.setColumns(10);
|
|
elementName.setColumns(10);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /* Add Provided Energy Label and Textfield */
|
|
|
|
+ JLabel lblProvidedEnergy = new JLabel(Languages.getLanguage()[66]);
|
|
|
|
+ lblProvidedEnergy.setBounds(10, 50, 120, 20);
|
|
|
|
+ contentPanel.add(lblProvidedEnergy);
|
|
|
|
+
|
|
providedEnergy = new JTextField();
|
|
providedEnergy = new JTextField();
|
|
- providedEnergy.setBounds(130, 46, 110, 20);
|
|
|
|
|
|
+ providedEnergy.setBounds(130, 50, 110, 20);
|
|
contentPanel.add(providedEnergy);
|
|
contentPanel.add(providedEnergy);
|
|
providedEnergy.setColumns(10);
|
|
providedEnergy.setColumns(10);
|
|
providedEnergy.setText("0");
|
|
providedEnergy.setText("0");
|
|
|
|
+
|
|
|
|
+ checkBoxActive = new JCheckBox("Active");
|
|
|
|
+ checkBoxActive.setSelected(true);
|
|
|
|
+ checkBoxActive.setBounds(250, 50, 115, 20);
|
|
|
|
+ contentPanel.add(checkBoxActive);
|
|
|
|
+
|
|
|
|
+ /* Add Flexible Energy Textfield and CheckBox */
|
|
|
|
+ JLabel lblFlexibleEnergy = new JLabel("Flexible Energy:");
|
|
|
|
+ lblFlexibleEnergy.setBounds(10, 90, 100, 20);
|
|
|
|
+ contentPanel.add(lblFlexibleEnergy);
|
|
|
|
+
|
|
|
|
+ flexibleEnergy = new JTextField();
|
|
|
|
+ flexibleEnergy.setText("0");
|
|
|
|
+ flexibleEnergy.setColumns(10);
|
|
|
|
+ flexibleEnergy.setBounds(130, 90, 110, 20);
|
|
|
|
+ contentPanel.add(flexibleEnergy);
|
|
|
|
+
|
|
|
|
+ checkboxFlexible = new JCheckBox("Flexible");
|
|
|
|
+ checkboxFlexible.setBounds(250, 90, 115, 20);
|
|
|
|
+ contentPanel.add(checkboxFlexible);
|
|
|
|
+
|
|
|
|
+ /* Add Amount Textfield and Checkbox */
|
|
|
|
+ JLabel lblAmount = new JLabel(Languages.getLanguage()[67]);
|
|
|
|
+ lblAmount.setBounds(10, 130, 100, 14);
|
|
|
|
+ contentPanel.add(lblAmount);
|
|
|
|
|
|
amount = new JTextField();
|
|
amount = new JTextField();
|
|
- amount.setBounds(130, 81, 110, 20);
|
|
|
|
|
|
+ amount.setBounds(130, 130, 110, 20);
|
|
contentPanel.add(amount);
|
|
contentPanel.add(amount);
|
|
amount.setColumns(10);
|
|
amount.setColumns(10);
|
|
amount.setText("1");
|
|
amount.setText("1");
|
|
|
|
+
|
|
|
|
+ /* Add Graph Panel */
|
|
|
|
+ panelGraph = new JPanel();
|
|
|
|
+ panelGraph.setBounds(12, 157, 358, 263);
|
|
|
|
+ contentPanel.add(panelGraph);
|
|
|
|
|
|
|
|
+ /* Add Buttons and Actions */
|
|
JPanel buttonPane = new JPanel();
|
|
JPanel buttonPane = new JPanel();
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
@@ -139,15 +172,28 @@ public class AddElementPopUp extends JDialog {
|
|
return hl;
|
|
return hl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * setElement that should be edited
|
|
|
|
+ * @param holonElement
|
|
|
|
+ */
|
|
public void setElement(HolonElement holonElement) {
|
|
public void setElement(HolonElement holonElement) {
|
|
- hl = new HolonElement(hl);
|
|
|
|
-
|
|
|
|
|
|
+ hl = holonElement;
|
|
|
|
+ elementName.setText(hl.getEleName());
|
|
|
|
+ amount.setText(""+hl.getAmount());
|
|
|
|
+ flexibleEnergy.setText(""+hl.getFlexibleEnergyAvailablePerElement());
|
|
|
|
+ checkboxFlexible.setSelected(hl.isFlexible());
|
|
|
|
+ providedEnergy.setText(""+hl.getEnergyPerElement());
|
|
|
|
+ checkBoxActive.setSelected(hl.isActive());
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Creates
|
|
|
|
+ */
|
|
private void okAction() {
|
|
private void okAction() {
|
|
boolean repeated = false;
|
|
boolean repeated = false;
|
|
for (HolonElement e : ((HolonObject) tempCps).getElements()) {
|
|
for (HolonElement e : ((HolonObject) tempCps).getElements()) {
|
|
- if (elementName.getText().equals(e.getEleName())) {
|
|
|
|
|
|
+ if (elementName.getText().equals(e.getEleName())&&(hl == null || hl.getId()!=e.getId())) {
|
|
repeated = true;
|
|
repeated = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -156,8 +202,16 @@ public class AddElementPopUp extends JDialog {
|
|
try {
|
|
try {
|
|
float energy = Float.parseFloat(providedEnergy.getText());
|
|
float energy = Float.parseFloat(providedEnergy.getText());
|
|
int elementAmount = Integer.parseInt(amount.getText());
|
|
int elementAmount = Integer.parseInt(amount.getText());
|
|
- hl = new HolonElement(elementName.getText(), elementAmount, energy);
|
|
|
|
-
|
|
|
|
|
|
+ if(hl == null){
|
|
|
|
+ hl = new HolonElement(elementName.getText(), elementAmount, energy);
|
|
|
|
+ } else {
|
|
|
|
+ hl.setEleName(elementName.getText());
|
|
|
|
+ hl.setAmount(elementAmount);
|
|
|
|
+ hl.setEnergyPerElement(energy);
|
|
|
|
+ }
|
|
|
|
+ hl.setActive(checkBoxActive.isSelected());
|
|
|
|
+ hl.setFlexible(checkboxFlexible.isSelected());
|
|
|
|
+ hl.setFlexibleEnergyAvailable(Float.parseFloat(flexibleEnergy.getText()));
|
|
dispose();
|
|
dispose();
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[68]);
|
|
JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[68]);
|