|
@@ -35,6 +35,7 @@ import javax.swing.SwingConstants;
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
|
|
+import classes.CpsObject;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import ui.controller.Control;
|
|
@@ -55,13 +56,14 @@ public class AddObjectPopUp extends JDialog {
|
|
|
private String filePath = " ";
|
|
|
private String givenCategory;
|
|
|
private JLabel lblImagePreview;
|
|
|
+ private CpsObject toEdit;
|
|
|
|
|
|
/**
|
|
|
* Launch the application.
|
|
|
*/
|
|
|
public static void main(String[] args) {
|
|
|
try {
|
|
|
- AddObjectPopUp dialog = new AddObjectPopUp();
|
|
|
+ AddObjectPopUp dialog = new AddObjectPopUp(false, null, null);
|
|
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
dialog.setVisible(true);
|
|
|
} catch (Exception e) {
|
|
@@ -72,7 +74,8 @@ public class AddObjectPopUp extends JDialog {
|
|
|
/**
|
|
|
* Create the dialog.
|
|
|
*/
|
|
|
- public AddObjectPopUp() {
|
|
|
+ public AddObjectPopUp(boolean edit, CpsObject obj, String cat) {
|
|
|
+ toEdit = obj;
|
|
|
this.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
|
.getScaledInstance(30, 30, Image.SCALE_SMOOTH));
|
|
|
setBounds(100, 100, 450, 342);
|
|
@@ -108,6 +111,9 @@ public class AddObjectPopUp extends JDialog {
|
|
|
objectName.setBackground(Color.WHITE);
|
|
|
}
|
|
|
});
|
|
|
+ if (edit) {
|
|
|
+ objectName.setText(obj.getName());
|
|
|
+ }
|
|
|
objectName.setBounds(98, 18, 172, 20);
|
|
|
contentPanel.add(objectName);
|
|
|
objectName.setColumns(10);
|
|
@@ -143,6 +149,15 @@ public class AddObjectPopUp extends JDialog {
|
|
|
sourcePath.setBackground(Color.WHITE);
|
|
|
}
|
|
|
});
|
|
|
+ if (edit) {
|
|
|
+ sourcePath.setText(obj.getImage());
|
|
|
+ if (sourcePath.getText().startsWith("/Images/")) {
|
|
|
+ sourcePath
|
|
|
+ .setText(System.getProperty("user.home") + "/praktikum-holons/res/" + sourcePath.getText());
|
|
|
+ }
|
|
|
+ filePath = sourcePath.getText();
|
|
|
+ selectedFile = new File(sourcePath.getText());
|
|
|
+ }
|
|
|
sourcePath.setBounds(148, 77, 271, 20);
|
|
|
contentPanel.add(sourcePath);
|
|
|
sourcePath.setColumns(10);
|
|
@@ -178,6 +193,11 @@ public class AddObjectPopUp extends JDialog {
|
|
|
scrollPane.setViewportView(list);
|
|
|
}
|
|
|
}
|
|
|
+ if (edit) {
|
|
|
+ for (HolonElement e : ((HolonObject) obj).getElements()) {
|
|
|
+ addElement(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
{
|
|
|
JButton btnNewButton = new JButton("Delete Element");
|
|
|
btnNewButton.addActionListener(new ActionListener() {
|
|
@@ -197,7 +217,6 @@ public class AddObjectPopUp extends JDialog {
|
|
|
lblImagePreview.setBounds(295, 3, 50, 50);
|
|
|
contentPanel.add(lblImagePreview);
|
|
|
}
|
|
|
-
|
|
|
{
|
|
|
JPanel buttonPane = new JPanel();
|
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
@@ -214,16 +233,23 @@ public class AddObjectPopUp extends JDialog {
|
|
|
// HolonObject(objectName.getText());
|
|
|
// theObject.setElements(hElements);
|
|
|
// theObject.setImage(imagePath);
|
|
|
- controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
|
|
|
- hElements, imagePath);
|
|
|
+ if (edit) {
|
|
|
+ controller.delObjectCategory(givenCategory, toEdit.getName());
|
|
|
+ controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
|
|
|
+ hElements, imagePath);
|
|
|
+ } else {
|
|
|
+ controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
|
|
|
+ hElements, imagePath);
|
|
|
+ }
|
|
|
// controller.addObjectCategory(controller.searchCategory(givenCategory),
|
|
|
// theObject);
|
|
|
//
|
|
|
// System.out.println(theObject.getImage());
|
|
|
System.out.println(givenCategory);
|
|
|
dispose();
|
|
|
- } else
|
|
|
+ } else {
|
|
|
sourcePath.setBackground(new Color(255, 50, 50));
|
|
|
+ }
|
|
|
} else {
|
|
|
objectName.setBackground(new Color(255, 50, 50));
|
|
|
if (!sourcePath.getText().equals(filePath))
|
|
@@ -279,11 +305,10 @@ public class AddObjectPopUp extends JDialog {
|
|
|
try {
|
|
|
File source = new File(filePath);
|
|
|
File dest = new File(System.getProperty("user.home") + "/HolonGUI/Images/");
|
|
|
-
|
|
|
- dest.mkdirs();
|
|
|
- dest = new File(dest, selectedFile.getName());
|
|
|
- imagePath = "" + dest;
|
|
|
-
|
|
|
+ dest.mkdirs();
|
|
|
+ dest = new File(dest, selectedFile.getName());
|
|
|
+ imagePath = "" + dest;
|
|
|
+
|
|
|
inStream = new FileInputStream(source);
|
|
|
outStream = new FileOutputStream(dest);
|
|
|
byte[] buffer = new byte[1024];
|
|
@@ -303,6 +328,10 @@ public class AddObjectPopUp extends JDialog {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void editInformation(HolonObject obj) {
|
|
|
+ objectName.setText(obj.getName());
|
|
|
+ }
|
|
|
+
|
|
|
public static String getJarContainingFolder(Class aclass) throws Exception {
|
|
|
CodeSource codeSource = aclass.getProtectionDomain().getCodeSource();
|
|
|
|