|
@@ -32,37 +32,46 @@ public class CreateTemplatePopUp extends JDialog {
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Original Object to be templated
|
|
|
|
|
|
+ * Template HolonObject
|
|
*/
|
|
*/
|
|
- private HolonObject originalObject;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Category the Template should be inserted into
|
|
|
|
- */
|
|
|
|
- private String givenCategory;
|
|
|
|
-
|
|
|
|
- //Template Attributes
|
|
|
|
|
|
+ private HolonObject template;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * name of the HolonObjectTemplate
|
|
|
|
|
|
+ * HolonElementList
|
|
*/
|
|
*/
|
|
- private String name;
|
|
|
|
|
|
+ DefaultListModel<String> listModel;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * path to the originalImage
|
|
|
|
|
|
+ * HolonElement List
|
|
*/
|
|
*/
|
|
- private String imagePath;
|
|
|
|
|
|
+ JList<String> list;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * HolonElements of the template
|
|
|
|
|
|
+ * Category the Template should be inserted into
|
|
*/
|
|
*/
|
|
- private ArrayList<HolonElement> elements;
|
|
|
|
|
|
+ private String category;
|
|
|
|
+
|
|
|
|
+ //Template Attributes
|
|
|
|
|
|
//PopUp Parts
|
|
//PopUp Parts
|
|
private Control controller;
|
|
private Control controller;
|
|
|
|
+ /**
|
|
|
|
+ * name textfield
|
|
|
|
+ */
|
|
private JTextField textField_name;
|
|
private JTextField textField_name;
|
|
|
|
+ /**
|
|
|
|
+ * textField for path
|
|
|
|
+ */
|
|
private JTextField textField_imagePath;
|
|
private JTextField textField_imagePath;
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Image Preview
|
|
|
|
+ */
|
|
|
|
+ JLabel lblImagePreview;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * parent Frame
|
|
|
|
+ */
|
|
|
|
+ JFrame parent;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Create the dialog.
|
|
* Create the dialog.
|
|
@@ -76,7 +85,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
* the categorie
|
|
* the categorie
|
|
*/
|
|
*/
|
|
public CreateTemplatePopUp(HolonObject obj, Model model,
|
|
public CreateTemplatePopUp(HolonObject obj, Model model,
|
|
- JFrame parentFrame) {
|
|
|
|
|
|
+ JFrame parentFrame, Control controller) {
|
|
/*
|
|
/*
|
|
* use Category Controller an stuff lul
|
|
* use Category Controller an stuff lul
|
|
*/
|
|
*/
|
|
@@ -84,9 +93,9 @@ public class CreateTemplatePopUp extends JDialog {
|
|
/*
|
|
/*
|
|
* initialize Data
|
|
* initialize Data
|
|
*/
|
|
*/
|
|
- originalObject = obj;
|
|
|
|
- name = obj.getName();
|
|
|
|
-
|
|
|
|
|
|
+ template = new HolonObject(obj);
|
|
|
|
+ this.parent = parentFrame;
|
|
|
|
+ this.controller = controller;
|
|
/*
|
|
/*
|
|
* create Frame and GUI
|
|
* create Frame and GUI
|
|
*/
|
|
*/
|
|
@@ -114,9 +123,16 @@ public class CreateTemplatePopUp extends JDialog {
|
|
* Category Choice
|
|
* Category Choice
|
|
*/
|
|
*/
|
|
Choice choice = new Choice();
|
|
Choice choice = new Choice();
|
|
- choice.setBounds(86, 13, 172, 36);
|
|
|
|
|
|
+ choice.setBounds(86, 13, 172, 22);
|
|
contentPanel.add(choice);
|
|
contentPanel.add(choice);
|
|
//add categories
|
|
//add categories
|
|
|
|
+ if(model.getCategories().size()==0)//if no categorie exist: create new Template Category
|
|
|
|
+ try {
|
|
|
|
+ this.controller.addCategory("Template");
|
|
|
|
+ } catch (IOException e1) {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ //add Categories to the choice
|
|
for(Category c: model.getCategories())
|
|
for(Category c: model.getCategories())
|
|
choice.add(c.getName());
|
|
choice.add(c.getName());
|
|
|
|
|
|
@@ -134,7 +150,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
textField_name.setBounds(86, 48, 172, 22);
|
|
textField_name.setBounds(86, 48, 172, 22);
|
|
contentPanel.add(textField_name);
|
|
contentPanel.add(textField_name);
|
|
textField_name.setColumns(10);
|
|
textField_name.setColumns(10);
|
|
- textField_name.setText(obj.getName());
|
|
|
|
|
|
+ textField_name.setText(template.getName());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Image Path Lable
|
|
* Image Path Lable
|
|
@@ -150,7 +166,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
textField_imagePath.setBounds(86, 86, 172, 22);
|
|
textField_imagePath.setBounds(86, 86, 172, 22);
|
|
contentPanel.add(textField_imagePath);
|
|
contentPanel.add(textField_imagePath);
|
|
textField_imagePath.setColumns(10);
|
|
textField_imagePath.setColumns(10);
|
|
- textField_imagePath.setText(obj.getImage());
|
|
|
|
|
|
+ textField_imagePath.setText(template.getImage());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Browse Image Button
|
|
* Browse Image Button
|
|
@@ -158,21 +174,38 @@ public class CreateTemplatePopUp extends JDialog {
|
|
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->{
|
|
|
|
+ fileChooser();
|
|
|
|
+ });
|
|
|
|
|
|
/**
|
|
/**
|
|
* Image Preview
|
|
* Image Preview
|
|
*/
|
|
*/
|
|
- JLabel lblNewLabel = new JLabel("Image Preview");
|
|
|
|
- lblNewLabel.setIcon(new ImageIcon(Util.loadImage(this, obj.getImage(),62,62)));
|
|
|
|
- lblNewLabel.setBounds(298, 13, 62, 62);
|
|
|
|
- contentPanel.add(lblNewLabel);
|
|
|
|
|
|
+ lblImagePreview = new JLabel("Image Preview");
|
|
|
|
+ lblImagePreview.setIcon(new ImageIcon(Util.loadImage(this, template.getImage(),62,62)));
|
|
|
|
+ lblImagePreview.setBounds(298, 13, 62, 62);
|
|
|
|
+ contentPanel.add(lblImagePreview);
|
|
|
|
|
|
/**
|
|
/**
|
|
* Holon Element List
|
|
* Holon Element List
|
|
*/
|
|
*/
|
|
- JList list = new JList(((HolonObject)obj).getElements().toArray());
|
|
|
|
|
|
+ listModel = new DefaultListModel<String>();
|
|
|
|
+ list = new JList<String>(listModel);
|
|
list.setBounds(12, 118, 221, 166);
|
|
list.setBounds(12, 118, 221, 166);
|
|
contentPanel.add(list);
|
|
contentPanel.add(list);
|
|
|
|
+ /**
|
|
|
|
+ * Add Elements to List
|
|
|
|
+ */
|
|
|
|
+ for(HolonElement he:template.getElements())
|
|
|
|
+ listModel.addElement(he.getEleName()+": "+he.getOverallEnergy()+"U");
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Add ScrollPane to List
|
|
|
|
+ */
|
|
|
|
+ JScrollPane scrollPane = new JScrollPane();
|
|
|
|
+ scrollPane.setBounds(10, 114, 236, 150);
|
|
|
|
+ scrollPane.setViewportView(list);
|
|
|
|
+ contentPanel.add(scrollPane);
|
|
|
|
|
|
/**
|
|
/**
|
|
* Delete Element Button
|
|
* Delete Element Button
|
|
@@ -180,6 +213,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
JButton btnDeleteElement = new JButton("Delete Element");
|
|
JButton btnDeleteElement = new JButton("Delete Element");
|
|
btnDeleteElement.setBounds(245, 199, 140, 25);
|
|
btnDeleteElement.setBounds(245, 199, 140, 25);
|
|
contentPanel.add(btnDeleteElement);
|
|
contentPanel.add(btnDeleteElement);
|
|
|
|
+ btnDeleteElement.addActionListener(e->removeElement());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Edit Element Button
|
|
* Edit Element Button
|
|
@@ -187,6 +221,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
JButton btnEditElement = new JButton("Edit Element");
|
|
JButton btnEditElement = new JButton("Edit Element");
|
|
btnEditElement.setBounds(245, 161, 140, 25);
|
|
btnEditElement.setBounds(245, 161, 140, 25);
|
|
contentPanel.add(btnEditElement);
|
|
contentPanel.add(btnEditElement);
|
|
|
|
+ btnEditElement.addActionListener(e->editElement());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Add Element Button
|
|
* Add Element Button
|
|
@@ -194,6 +229,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
JButton btnAddElement = new JButton("Add Element");
|
|
JButton btnAddElement = new JButton("Add Element");
|
|
btnAddElement.setBounds(245, 123, 140, 25);
|
|
btnAddElement.setBounds(245, 123, 140, 25);
|
|
contentPanel.add(btnAddElement);
|
|
contentPanel.add(btnAddElement);
|
|
|
|
+ btnAddElement.addActionListener(e->addElement());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Cancel Button
|
|
* Cancel Button
|
|
@@ -209,6 +245,7 @@ public class CreateTemplatePopUp extends JDialog {
|
|
JButton btnAddTemplate = new JButton("Add Template");
|
|
JButton btnAddTemplate = new JButton("Add Template");
|
|
btnAddTemplate.setBounds(235, 257, 113, 25);
|
|
btnAddTemplate.setBounds(235, 257, 113, 25);
|
|
contentPanel.add(btnAddTemplate);
|
|
contentPanel.add(btnAddTemplate);
|
|
|
|
+ btnAddTemplate.addActionListener(e->createTemplate());
|
|
|
|
|
|
/**
|
|
/**
|
|
* Title
|
|
* Title
|
|
@@ -218,12 +255,51 @@ public class CreateTemplatePopUp extends JDialog {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Sets the Controller.
|
|
|
|
- *
|
|
|
|
- * @param controller
|
|
|
|
- * the controller
|
|
|
|
|
|
+ * Choose the file.
|
|
*/
|
|
*/
|
|
- public void setController(Control controller) {
|
|
|
|
- this.controller = controller;
|
|
|
|
|
|
+ private void fileChooser() {
|
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
|
+ FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
|
|
+ fileChooser.setFileFilter(filter);
|
|
|
|
+ int returnValue = fileChooser.showOpenDialog(null);
|
|
|
|
+ if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
|
|
+ File selectedFile = fileChooser.getSelectedFile();
|
|
|
|
+ String filePath = selectedFile.getAbsolutePath();
|
|
|
|
+ textField_imagePath.setText(filePath);
|
|
|
|
+ ImageIcon icon = new ImageIcon(Util.loadImage(this, filePath, 62, 62, Image.SCALE_SMOOTH));
|
|
|
|
+ lblImagePreview.setIcon(icon);
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println("Failed to Load");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void createTemplate(){
|
|
|
|
+ System.out.println("Create "+category+" "+template.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void addElement(){
|
|
|
|
+ AddElementPopUp popUp = new AddElementPopUp(parent);
|
|
|
|
+ popUp.setActualCps(template);
|
|
|
|
+ popUp.setVisible(true);
|
|
|
|
+ HolonElement he = popUp.getElement();
|
|
|
|
+ if(he!=null){
|
|
|
|
+ listModel.addElement(he.getEleName()+": "+he.getOverallEnergy()+"U");
|
|
|
|
+ template.addElement(he);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void removeElement(){
|
|
|
|
+ int index = list.getSelectedIndex();
|
|
|
|
+ if(index == -1)return;
|
|
|
|
+ template.deleteElement(index);
|
|
|
|
+ listModel.remove(index);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void editElement(){
|
|
|
|
+ int index = list.getSelectedIndex();
|
|
|
|
+ if(index == -1)return;
|
|
|
|
+ System.out.println("Edit "+template.getElements().get(index).toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|