|
@@ -2,22 +2,31 @@ package ui.view;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.FlowLayout;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JDialog;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
+import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.swing.JTextField;
|
|
|
import javax.swing.JComboBox;
|
|
|
import javax.swing.DefaultComboBoxModel;
|
|
|
|
|
|
+import classes.HolonElement;
|
|
|
+
|
|
|
+import java.awt.event.ActionListener;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+
|
|
|
public class AddElementPopUp extends JDialog {
|
|
|
|
|
|
private final JPanel contentPanel = new JPanel();
|
|
|
- private JTextField textField;
|
|
|
- private JTextField textField_1;
|
|
|
- private JTextField textField_2;
|
|
|
+ private JTextField elementName;
|
|
|
+ private JTextField providedEnergy;
|
|
|
+ private JTextField amount;
|
|
|
+ private HolonElement hl;
|
|
|
|
|
|
/**
|
|
|
* Launch the application.
|
|
@@ -36,6 +45,8 @@ public class AddElementPopUp extends JDialog {
|
|
|
* Create the dialog.
|
|
|
*/
|
|
|
public AddElementPopUp() {
|
|
|
+ super((java.awt.Frame) null, true);
|
|
|
+ setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
|
|
|
setBounds(100, 100, 300, 190);
|
|
|
getContentPane().setLayout(new BorderLayout());
|
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
@@ -55,31 +66,52 @@ public class AddElementPopUp extends JDialog {
|
|
|
lblAmount.setBounds(10, 84, 46, 14);
|
|
|
contentPanel.add(lblAmount);
|
|
|
|
|
|
- textField = new JTextField();
|
|
|
- textField.setBounds(140, 8, 110, 20);
|
|
|
- contentPanel.add(textField);
|
|
|
- textField.setColumns(10);
|
|
|
+ elementName = new JTextField();
|
|
|
+ elementName.setBounds(140, 8, 110, 20);
|
|
|
+ contentPanel.add(elementName);
|
|
|
+ elementName.setColumns(10);
|
|
|
|
|
|
- JComboBox comboBox = new JComboBox();
|
|
|
- comboBox.setModel(new DefaultComboBoxModel(new String[] {"+", "-"}));
|
|
|
- comboBox.setBounds(100, 46, 33, 20);
|
|
|
- contentPanel.add(comboBox);
|
|
|
+ final JComboBox sign = new JComboBox();
|
|
|
+ sign.setModel(new DefaultComboBoxModel(new String[] {"+", "-"}));
|
|
|
+ sign.setBounds(100, 46, 33, 20);
|
|
|
+ contentPanel.add(sign);
|
|
|
|
|
|
- textField_1 = new JTextField();
|
|
|
- textField_1.setBounds(140, 46, 110, 20);
|
|
|
- contentPanel.add(textField_1);
|
|
|
- textField_1.setColumns(10);
|
|
|
+ providedEnergy = new JTextField();
|
|
|
+ providedEnergy.setBounds(140, 46, 110, 20);
|
|
|
+ contentPanel.add(providedEnergy);
|
|
|
+ providedEnergy.setColumns(10);
|
|
|
+ providedEnergy.setText("0");
|
|
|
|
|
|
- textField_2 = new JTextField();
|
|
|
- textField_2.setBounds(140, 81, 110, 20);
|
|
|
- contentPanel.add(textField_2);
|
|
|
- textField_2.setColumns(10);
|
|
|
+ amount = new JTextField();
|
|
|
+ amount.setBounds(140, 81, 110, 20);
|
|
|
+ contentPanel.add(amount);
|
|
|
+ amount.setColumns(10);
|
|
|
+ amount.setText("0");
|
|
|
{
|
|
|
JPanel buttonPane = new JPanel();
|
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
|
{
|
|
|
JButton okButton = new JButton("OK");
|
|
|
+ okButton.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent arg0) {
|
|
|
+ if(elementName.getText().length() != 0){
|
|
|
+ try{
|
|
|
+ float energy = Float.parseFloat(providedEnergy.getText().toString());
|
|
|
+ int elementAmount = Integer.parseInt(amount.getText().toString());
|
|
|
+ if(sign.getSelectedItem().toString().equals("-")){
|
|
|
+ energy = energy * -1;
|
|
|
+ }
|
|
|
+ hl = new HolonElement(elementName.getText().toString(), energy, elementAmount);
|
|
|
+ dispose();
|
|
|
+ } catch(NumberFormatException e){
|
|
|
+ JOptionPane.showMessageDialog(new JFrame(),"Please enter numbers in the Fields amount and providedEnergy");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ JOptionPane.showMessageDialog(new JFrame(), "Please enter a Name");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
okButton.setActionCommand("OK");
|
|
|
buttonPane.add(okButton);
|
|
|
getRootPane().setDefaultButton(okButton);
|
|
@@ -91,4 +123,8 @@ public class AddElementPopUp extends JDialog {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public HolonElement getElement(){
|
|
|
+ return hl;
|
|
|
+ }
|
|
|
}
|