|
@@ -23,23 +23,30 @@ import javax.swing.JList;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.SwingConstants;
|
|
|
|
|
|
+import classes.Category;
|
|
|
import classes.HolonElement;
|
|
|
+import classes.HolonObject;
|
|
|
|
|
|
import javax.swing.JScrollBar;
|
|
|
import javax.swing.ScrollPaneConstants;
|
|
|
|
|
|
+import ui.controller.Control;
|
|
|
+
|
|
|
public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
private final JPanel contentPanel = new JPanel();
|
|
|
private AddElementPopUp addElement;
|
|
|
- private JTextField textField;
|
|
|
- private JTextField textField_1;
|
|
|
+ private JTextField objectName;
|
|
|
+ private JTextField sourcePath;
|
|
|
private ArrayList<HolonElement> hElements;
|
|
|
private DefaultListModel listModel;
|
|
|
private JList list;
|
|
|
-
|
|
|
+ private String imagePath;
|
|
|
+ private HolonObject theObject;
|
|
|
+ private Control controller;
|
|
|
private File selectedFile = null;
|
|
|
private String filePath = " ";
|
|
|
+ private String givenCategory;
|
|
|
|
|
|
/**
|
|
|
* Launch the application.
|
|
@@ -72,10 +79,10 @@ public class AddObjectPopUp extends JDialog {
|
|
|
contentPanel.add(lblName);
|
|
|
}
|
|
|
{
|
|
|
- textField = new JTextField();
|
|
|
- textField.setBounds(135, 8, 86, 20);
|
|
|
- contentPanel.add(textField);
|
|
|
- textField.setColumns(10);
|
|
|
+ objectName = new JTextField();
|
|
|
+ objectName.setBounds(135, 8, 86, 20);
|
|
|
+ contentPanel.add(objectName);
|
|
|
+ objectName.setColumns(10);
|
|
|
}
|
|
|
{
|
|
|
JButton btnBrowseImage = new JButton("Browse Image");
|
|
@@ -89,10 +96,10 @@ public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
}
|
|
|
{
|
|
|
- textField_1 = new JTextField();
|
|
|
- textField_1.setBounds(135, 51, 271, 20);
|
|
|
- contentPanel.add(textField_1);
|
|
|
- textField_1.setColumns(10);
|
|
|
+ sourcePath = new JTextField();
|
|
|
+ sourcePath.setBounds(135, 51, 271, 20);
|
|
|
+ contentPanel.add(sourcePath);
|
|
|
+ sourcePath.setColumns(10);
|
|
|
}
|
|
|
{
|
|
|
JButton btnAddDefaultElement = new JButton("Add Default Element");
|
|
@@ -148,11 +155,22 @@ public class AddObjectPopUp extends JDialog {
|
|
|
JButton okButton = new JButton("OK");
|
|
|
okButton.addMouseListener(new MouseAdapter() {
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
- if (!textField_1.getText().equals(filePath)) {
|
|
|
- Component frame = null;
|
|
|
- JOptionPane.showMessageDialog(frame, "No image selected!");
|
|
|
- } else {
|
|
|
+ Component frame = null;
|
|
|
+ if (!sourcePath.getText().equals(filePath)) {
|
|
|
+ //JOptionPane.showMessageDialog(frame, "No image selected!");
|
|
|
+ }
|
|
|
+ if(objectName.getText().length() == 0){
|
|
|
+ JOptionPane.showMessageDialog(frame, "please enter a name");
|
|
|
+ }
|
|
|
+ else {
|
|
|
copieFile();
|
|
|
+ theObject = new HolonObject(objectName.getText());
|
|
|
+ theObject.setElements(hElements);
|
|
|
+ theObject.setImage(imagePath);
|
|
|
+ controller.addNewObject(controller.searchCategory(givenCategory), theObject);
|
|
|
+ System.out.println(theObject.getImage());
|
|
|
+ System.out.println(givenCategory);
|
|
|
+ dispose();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -182,7 +200,7 @@ public class AddObjectPopUp extends JDialog {
|
|
|
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
|
selectedFile = FileChooser.getSelectedFile();
|
|
|
filePath = selectedFile.getAbsolutePath();
|
|
|
- textField_1.setText(filePath);
|
|
|
+ sourcePath.setText(filePath);
|
|
|
} else {
|
|
|
System.out.println("Failed to Load");
|
|
|
}
|
|
@@ -194,10 +212,10 @@ public class AddObjectPopUp extends JDialog {
|
|
|
OutputStream outStream = null;
|
|
|
try {
|
|
|
File source = new File(filePath);
|
|
|
- File dest = new File(System.getProperty("user.dir") + "/res/Images/", selectedFile.getName());
|
|
|
+ File dest = new File(System.getProperty("user.dir") + "/bin/Images/", selectedFile.getName());
|
|
|
+ imagePath = "/Images/" + selectedFile.getName() ;
|
|
|
inStream = new FileInputStream(source);
|
|
|
outStream = new FileOutputStream(dest);
|
|
|
-
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
int length;
|
|
@@ -214,4 +232,15 @@ public class AddObjectPopUp extends JDialog {
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public HolonObject getObject(){
|
|
|
+ return theObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setController(Control controller){
|
|
|
+ this.controller = controller;
|
|
|
+ }
|
|
|
+ public void setCategory(String cat){
|
|
|
+ givenCategory = cat;
|
|
|
+ }
|
|
|
}
|