|
@@ -35,52 +35,52 @@ public class CreateTemplatePopUp extends JDialog {
|
|
* Template HolonObject
|
|
* Template HolonObject
|
|
*/
|
|
*/
|
|
private HolonObject template;
|
|
private HolonObject template;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* HolonElementList
|
|
* HolonElementList
|
|
*/
|
|
*/
|
|
DefaultListModel<String> listModel;
|
|
DefaultListModel<String> listModel;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* HolonElement List
|
|
* HolonElement List
|
|
*/
|
|
*/
|
|
JList<String> list;
|
|
JList<String> list;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Category the Template should be inserted into
|
|
* Category the Template should be inserted into
|
|
*/
|
|
*/
|
|
private String category;
|
|
private String category;
|
|
-
|
|
|
|
- //Template Attributes
|
|
|
|
-
|
|
|
|
- //PopUp Parts
|
|
|
|
|
|
+
|
|
|
|
+ // Template Attributes
|
|
|
|
+
|
|
|
|
+ // PopUp Parts
|
|
private Control controller;
|
|
private Control controller;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Category Selection
|
|
* Category Selection
|
|
*/
|
|
*/
|
|
Choice choice;
|
|
Choice choice;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* name textfield
|
|
* name textfield
|
|
*/
|
|
*/
|
|
private JTextField textField_name;
|
|
private JTextField textField_name;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* textField for path
|
|
* textField for path
|
|
*/
|
|
*/
|
|
private JTextField textField_imagePath;
|
|
private JTextField textField_imagePath;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Image Preview
|
|
* Image Preview
|
|
*/
|
|
*/
|
|
JLabel lblImagePreview;
|
|
JLabel lblImagePreview;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* parent Frame
|
|
* parent Frame
|
|
*/
|
|
*/
|
|
JFrame parent;
|
|
JFrame parent;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Create the dialog.
|
|
* Create the dialog.
|
|
*
|
|
*
|
|
@@ -94,6 +94,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
*/
|
|
*/
|
|
public CreateTemplatePopUp(HolonObject obj, Model model,
|
|
public CreateTemplatePopUp(HolonObject obj, Model model,
|
|
JFrame parentFrame, Control controller) {
|
|
JFrame parentFrame, Control controller) {
|
|
|
|
+ setResizable(false);
|
|
/*
|
|
/*
|
|
* use Category Controller an stuff lul
|
|
* use Category Controller an stuff lul
|
|
*/
|
|
*/
|
|
@@ -111,7 +112,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
setBounds(100, 100, 476, 344);
|
|
setBounds(100, 100, 476, 344);
|
|
setLocationRelativeTo(parentFrame);
|
|
setLocationRelativeTo(parentFrame);
|
|
getContentPane().setLayout(new BorderLayout());
|
|
getContentPane().setLayout(new BorderLayout());
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Content Panel
|
|
* Content Panel
|
|
*/
|
|
*/
|
|
@@ -119,38 +120,39 @@ public class CreateTemplatePopUp extends JDialog {
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
contentPanel.setLayout(null);
|
|
contentPanel.setLayout(null);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Category Label
|
|
* Category Label
|
|
*/
|
|
*/
|
|
JLabel lblCategory = new JLabel("Category:");
|
|
JLabel lblCategory = new JLabel("Category:");
|
|
lblCategory.setBounds(12, 13, 68, 22);
|
|
lblCategory.setBounds(12, 13, 68, 22);
|
|
contentPanel.add(lblCategory);
|
|
contentPanel.add(lblCategory);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Category Choice
|
|
* Category Choice
|
|
*/
|
|
*/
|
|
choice = new Choice();
|
|
choice = new Choice();
|
|
choice.setBounds(86, 13, 172, 22);
|
|
choice.setBounds(86, 13, 172, 22);
|
|
contentPanel.add(choice);
|
|
contentPanel.add(choice);
|
|
- //add categories
|
|
|
|
- if(model.getCategories().size()==0)//if no categorie exist: create new Template Category
|
|
|
|
|
|
+ // add categories
|
|
|
|
+ if (model.getCategories().size() == 0)// if no categorie exist: create
|
|
|
|
+ // new Template Category
|
|
try {
|
|
try {
|
|
this.controller.addCategory("Template");
|
|
this.controller.addCategory("Template");
|
|
} catch (IOException e1) {
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
e1.printStackTrace();
|
|
}
|
|
}
|
|
- //add Categories to the choice
|
|
|
|
- for(Category c: model.getCategories())
|
|
|
|
|
|
+ // add Categories to the choice
|
|
|
|
+ for (Category c : model.getCategories())
|
|
choice.add(c.getName());
|
|
choice.add(c.getName());
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Name Label
|
|
* Name Label
|
|
*/
|
|
*/
|
|
JLabel lblName = new JLabel("Name:");
|
|
JLabel lblName = new JLabel("Name:");
|
|
lblName.setBounds(12, 48, 56, 16);
|
|
lblName.setBounds(12, 48, 56, 16);
|
|
contentPanel.add(lblName);
|
|
contentPanel.add(lblName);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Name Textfield
|
|
* Name Textfield
|
|
*/
|
|
*/
|
|
@@ -159,14 +161,14 @@ public class CreateTemplatePopUp extends JDialog {
|
|
contentPanel.add(textField_name);
|
|
contentPanel.add(textField_name);
|
|
textField_name.setColumns(10);
|
|
textField_name.setColumns(10);
|
|
textField_name.setText(template.getName());
|
|
textField_name.setText(template.getName());
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Image Path Lable
|
|
* Image Path Lable
|
|
*/
|
|
*/
|
|
JLabel lblImage = new JLabel("Image:");
|
|
JLabel lblImage = new JLabel("Image:");
|
|
lblImage.setBounds(12, 89, 56, 16);
|
|
lblImage.setBounds(12, 89, 56, 16);
|
|
contentPanel.add(lblImage);
|
|
contentPanel.add(lblImage);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Image Path Text Field
|
|
* Image Path Text Field
|
|
*/
|
|
*/
|
|
@@ -175,86 +177,87 @@ public class CreateTemplatePopUp extends JDialog {
|
|
contentPanel.add(textField_imagePath);
|
|
contentPanel.add(textField_imagePath);
|
|
textField_imagePath.setColumns(10);
|
|
textField_imagePath.setColumns(10);
|
|
textField_imagePath.setText(template.getImage());
|
|
textField_imagePath.setText(template.getImage());
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Browse Image Button
|
|
* Browse Image Button
|
|
*/
|
|
*/
|
|
JButton btnBrowseImage = new JButton("BrowseImage");
|
|
JButton btnBrowseImage = new JButton("BrowseImage");
|
|
btnBrowseImage.setBounds(268, 85, 117, 25);
|
|
btnBrowseImage.setBounds(268, 85, 117, 25);
|
|
contentPanel.add(btnBrowseImage);
|
|
contentPanel.add(btnBrowseImage);
|
|
- btnBrowseImage.addActionListener(actionevent->{
|
|
|
|
|
|
+ btnBrowseImage.addActionListener(actionevent -> {
|
|
fileChooser();
|
|
fileChooser();
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Image Preview
|
|
* Image Preview
|
|
*/
|
|
*/
|
|
lblImagePreview = new JLabel("Image Preview");
|
|
lblImagePreview = new JLabel("Image Preview");
|
|
- lblImagePreview.setIcon(new ImageIcon(Util.loadImage(this, template.getImage(),62,62)));
|
|
|
|
|
|
+ lblImagePreview.setIcon(new ImageIcon(Util.loadImage(this,
|
|
|
|
+ template.getImage(), 62, 62)));
|
|
lblImagePreview.setBounds(298, 13, 62, 62);
|
|
lblImagePreview.setBounds(298, 13, 62, 62);
|
|
contentPanel.add(lblImagePreview);
|
|
contentPanel.add(lblImagePreview);
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Holon Element List
|
|
* Holon Element List
|
|
*/
|
|
*/
|
|
listModel = new DefaultListModel<String>();
|
|
listModel = new DefaultListModel<String>();
|
|
- list = new JList<String>(listModel);
|
|
|
|
- list.setBounds(12, 118, 221, 166);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Add Elements to List
|
|
* Add Elements to List
|
|
*/
|
|
*/
|
|
- for(HolonElement he:template.getElements())
|
|
|
|
- listModel.addElement(he.getEleName()+": "+he.getOverallEnergy()+"U");
|
|
|
|
-
|
|
|
|
|
|
+ for (HolonElement he : template.getElements())
|
|
|
|
+ listModel.addElement(he.getAmount() + " * " + he.getEleName()
|
|
|
|
+ + ": " + he.getOverallEnergy() + "U");
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Add ScrollPane to List
|
|
* Add ScrollPane to List
|
|
*/
|
|
*/
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
- scrollPane.setBounds(10, 114, 236, 150);
|
|
|
|
- scrollPane.setViewportView(list);
|
|
|
|
|
|
+ scrollPane.setBounds(22, 118, 236, 150);
|
|
contentPanel.add(scrollPane);
|
|
contentPanel.add(scrollPane);
|
|
-
|
|
|
|
|
|
+ list = new JList<String>(listModel);
|
|
|
|
+ scrollPane.setViewportView(list);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Delete Element Button
|
|
* Delete Element Button
|
|
*/
|
|
*/
|
|
JButton btnDeleteElement = new JButton("Delete Element");
|
|
JButton btnDeleteElement = new JButton("Delete Element");
|
|
- btnDeleteElement.setBounds(268, 199, 140, 25);
|
|
|
|
|
|
+ btnDeleteElement.setBounds(268, 228, 140, 25);
|
|
contentPanel.add(btnDeleteElement);
|
|
contentPanel.add(btnDeleteElement);
|
|
- btnDeleteElement.addActionListener(e->removeElement());
|
|
|
|
-
|
|
|
|
|
|
+ btnDeleteElement.addActionListener(e -> removeElement());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Edit Element Button
|
|
* Edit Element Button
|
|
*/
|
|
*/
|
|
JButton btnEditElement = new JButton("Edit Element");
|
|
JButton btnEditElement = new JButton("Edit Element");
|
|
- btnEditElement.setBounds(268, 161, 140, 25);
|
|
|
|
|
|
+ btnEditElement.setBounds(268, 190, 140, 25);
|
|
contentPanel.add(btnEditElement);
|
|
contentPanel.add(btnEditElement);
|
|
- btnEditElement.addActionListener(e->editElement());
|
|
|
|
-
|
|
|
|
|
|
+ btnEditElement.addActionListener(e -> editElement());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Add Element Button
|
|
* Add Element Button
|
|
*/
|
|
*/
|
|
JButton btnAddElement = new JButton("Add Element");
|
|
JButton btnAddElement = new JButton("Add Element");
|
|
- btnAddElement.setBounds(268, 123, 140, 25);
|
|
|
|
|
|
+ btnAddElement.setBounds(268, 152, 140, 25);
|
|
contentPanel.add(btnAddElement);
|
|
contentPanel.add(btnAddElement);
|
|
- btnAddElement.addActionListener(e->addElement());
|
|
|
|
-
|
|
|
|
|
|
+ btnAddElement.addActionListener(e -> addElement());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Cancel Button
|
|
* Cancel Button
|
|
*/
|
|
*/
|
|
JButton btnCancel = new JButton("Cancel");
|
|
JButton btnCancel = new JButton("Cancel");
|
|
- btnCancel.setBounds(372, 257, 74, 25);
|
|
|
|
|
|
+ btnCancel.setBounds(384, 277, 74, 25);
|
|
contentPanel.add(btnCancel);
|
|
contentPanel.add(btnCancel);
|
|
btnCancel.addActionListener(e -> dispose());
|
|
btnCancel.addActionListener(e -> dispose());
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Add Template Button
|
|
* Add Template Button
|
|
*/
|
|
*/
|
|
JButton btnAddTemplate = new JButton("Add Template");
|
|
JButton btnAddTemplate = new JButton("Add Template");
|
|
- btnAddTemplate.setBounds(257, 257, 113, 25);
|
|
|
|
|
|
+ btnAddTemplate.setBounds(75, 271, 113, 25);
|
|
contentPanel.add(btnAddTemplate);
|
|
contentPanel.add(btnAddTemplate);
|
|
- btnAddTemplate.addActionListener(e->createTemplate());
|
|
|
|
-
|
|
|
|
|
|
+ btnAddTemplate.addActionListener(e -> createTemplate());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Title
|
|
* Title
|
|
*/
|
|
*/
|
|
@@ -267,70 +270,80 @@ public class CreateTemplatePopUp extends JDialog {
|
|
*/
|
|
*/
|
|
private void fileChooser() {
|
|
private void fileChooser() {
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
- FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
|
|
|
|
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
|
|
|
+ "png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
fileChooser.setFileFilter(filter);
|
|
fileChooser.setFileFilter(filter);
|
|
int returnValue = fileChooser.showOpenDialog(null);
|
|
int returnValue = fileChooser.showOpenDialog(null);
|
|
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
File selectedFile = fileChooser.getSelectedFile();
|
|
File selectedFile = fileChooser.getSelectedFile();
|
|
String filePath = selectedFile.getAbsolutePath();
|
|
String filePath = selectedFile.getAbsolutePath();
|
|
textField_imagePath.setText(filePath);
|
|
textField_imagePath.setText(filePath);
|
|
- ImageIcon icon = new ImageIcon(Util.loadImage(this, filePath, 62, 62, Image.SCALE_SMOOTH));
|
|
|
|
|
|
+ ImageIcon icon = new ImageIcon(Util.loadImage(this, filePath, 62,
|
|
|
|
+ 62, Image.SCALE_SMOOTH));
|
|
lblImagePreview.setIcon(icon);
|
|
lblImagePreview.setIcon(icon);
|
|
} else {
|
|
} else {
|
|
System.out.println("Failed to Load");
|
|
System.out.println("Failed to Load");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* create the template and add it to the category
|
|
* create the template and add it to the category
|
|
*/
|
|
*/
|
|
- private void createTemplate(){
|
|
|
|
|
|
+ private void createTemplate() {
|
|
try {
|
|
try {
|
|
template.setName(textField_name.getText());
|
|
template.setName(textField_name.getText());
|
|
template.setImage(textField_imagePath.getText());
|
|
template.setImage(textField_imagePath.getText());
|
|
- template.getElements().forEach(ele -> ele.setSaving(new Pair<String, String>(choice.getSelectedItem(), template.getName())));
|
|
|
|
- controller.addObject(controller.searchCategory(choice.getItem(choice.getSelectedIndex())), template.getName(), template.getElements(), template.getImage());
|
|
|
|
|
|
+ template.getElements().forEach(
|
|
|
|
+ ele -> ele.setSaving(new Pair<String, String>(choice
|
|
|
|
+ .getSelectedItem(), template.getName())));
|
|
|
|
+ controller.addObject(controller.searchCategory(choice
|
|
|
|
+ .getItem(choice.getSelectedIndex())), template.getName(),
|
|
|
|
+ template.getElements(), template.getImage());
|
|
this.dispose();
|
|
this.dispose();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- System.out.println("Could not create Template: Category not found!");
|
|
|
|
|
|
+ System.out
|
|
|
|
+ .println("Could not create Template: Category not found!");
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Add an Holon Element to the template
|
|
* Add an Holon Element to the template
|
|
*/
|
|
*/
|
|
- private void addElement(){
|
|
|
|
|
|
+ private void addElement() {
|
|
AddElementPopUp popUp = new AddElementPopUp(parent);
|
|
AddElementPopUp popUp = new AddElementPopUp(parent);
|
|
popUp.setActualCps(template);
|
|
popUp.setActualCps(template);
|
|
popUp.setVisible(true);
|
|
popUp.setVisible(true);
|
|
HolonElement he = popUp.getElement();
|
|
HolonElement he = popUp.getElement();
|
|
- if(he!=null){
|
|
|
|
- listModel.addElement(he.getEleName()+": "+he.getOverallEnergy()+"U");
|
|
|
|
|
|
+ if (he != null) {
|
|
|
|
+ listModel.addElement(he.getAmount() + " * " + he.getEleName()
|
|
|
|
+ + ": " + he.getOverallEnergy() + "U");
|
|
template.addElement(he);
|
|
template.addElement(he);
|
|
he.setSaving(new Pair<>(category, textField_name.getText()));
|
|
he.setSaving(new Pair<>(category, textField_name.getText()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Removes the Selected Element from the template
|
|
* Removes the Selected Element from the template
|
|
*/
|
|
*/
|
|
- private void removeElement(){
|
|
|
|
- int index = list.getSelectedIndex();
|
|
|
|
- if(index == -1)return;
|
|
|
|
- template.deleteElement(index);
|
|
|
|
- listModel.remove(index);
|
|
|
|
|
|
+ private void removeElement() {
|
|
|
|
+ int index = list.getSelectedIndex();
|
|
|
|
+ if (index == -1)
|
|
|
|
+ return;
|
|
|
|
+ template.deleteElement(index);
|
|
|
|
+ listModel.remove(index);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Edits the selected HolonElement
|
|
* Edits the selected HolonElement
|
|
*/
|
|
*/
|
|
- private void editElement(){
|
|
|
|
|
|
+ private void editElement() {
|
|
int index = list.getSelectedIndex();
|
|
int index = list.getSelectedIndex();
|
|
- if(index == -1)return;
|
|
|
|
- System.out.println("Edit "+template.getElements().get(index).toString());
|
|
|
|
|
|
+ if (index == -1)
|
|
|
|
+ return;
|
|
|
|
+ System.out.println("Edit "
|
|
|
|
+ + template.getElements().get(index).toString());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|