|
@@ -5,9 +5,20 @@ import java.awt.Color;
|
|
import java.awt.Component;
|
|
import java.awt.Component;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.Image;
|
|
import java.awt.Image;
|
|
-import java.awt.event.*;
|
|
|
|
-import java.awt.image.ImageProducer;
|
|
|
|
-import java.io.*;
|
|
|
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
|
+import java.awt.event.KeyEvent;
|
|
|
|
+import java.awt.event.KeyListener;
|
|
|
|
+import java.awt.event.MouseAdapter;
|
|
|
|
+import java.awt.event.MouseEvent;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
+import java.security.CodeSource;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import javax.swing.DefaultListModel;
|
|
import javax.swing.DefaultListModel;
|
|
@@ -15,25 +26,17 @@ import javax.swing.ImageIcon;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFileChooser;
|
|
|
|
+import javax.swing.JLabel;
|
|
|
|
+import javax.swing.JList;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JScrollPane;
|
|
-import javax.swing.ListModel;
|
|
|
|
-import javax.swing.ListSelectionModel;
|
|
|
|
-import javax.swing.border.EmptyBorder;
|
|
|
|
-import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
-import javax.swing.JLabel;
|
|
|
|
import javax.swing.JTextField;
|
|
import javax.swing.JTextField;
|
|
-import javax.swing.JList;
|
|
|
|
-import javax.swing.JOptionPane;
|
|
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingConstants;
|
|
|
|
+import javax.swing.border.EmptyBorder;
|
|
|
|
+import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
|
|
-import classes.Category;
|
|
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
-
|
|
|
|
-import javax.swing.JScrollBar;
|
|
|
|
-import javax.swing.ScrollPaneConstants;
|
|
|
|
-
|
|
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
|
|
|
|
public class AddObjectPopUp extends JDialog {
|
|
public class AddObjectPopUp extends JDialog {
|
|
@@ -211,10 +214,12 @@ public class AddObjectPopUp extends JDialog {
|
|
// HolonObject(objectName.getText());
|
|
// HolonObject(objectName.getText());
|
|
// theObject.setElements(hElements);
|
|
// theObject.setElements(hElements);
|
|
// theObject.setImage(imagePath);
|
|
// theObject.setImage(imagePath);
|
|
- controller.addObject(controller.searchCategory(givenCategory), objectName.getText(), hElements, imagePath);
|
|
|
|
-// controller.addObjectCategory(controller.searchCategory(givenCategory), theObject);
|
|
|
|
-//
|
|
|
|
-// System.out.println(theObject.getImage());
|
|
|
|
|
|
+ controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
|
|
|
|
+ hElements, imagePath);
|
|
|
|
+ // controller.addObjectCategory(controller.searchCategory(givenCategory),
|
|
|
|
+ // theObject);
|
|
|
|
+ //
|
|
|
|
+ // System.out.println(theObject.getImage());
|
|
System.out.println(givenCategory);
|
|
System.out.println(givenCategory);
|
|
dispose();
|
|
dispose();
|
|
} else
|
|
} else
|
|
@@ -259,7 +264,6 @@ public class AddObjectPopUp extends JDialog {
|
|
selectedFile = FileChooser.getSelectedFile();
|
|
selectedFile = FileChooser.getSelectedFile();
|
|
filePath = selectedFile.getAbsolutePath();
|
|
filePath = selectedFile.getAbsolutePath();
|
|
sourcePath.setText(filePath);
|
|
sourcePath.setText(filePath);
|
|
- // Image image = createImage((ImageProducer) selectedFile);
|
|
|
|
ImageIcon icon = new ImageIcon(
|
|
ImageIcon icon = new ImageIcon(
|
|
new ImageIcon(filePath).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
|
|
new ImageIcon(filePath).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
|
|
lblImagePreview.setIcon(icon);
|
|
lblImagePreview.setIcon(icon);
|
|
@@ -272,10 +276,23 @@ public class AddObjectPopUp extends JDialog {
|
|
protected void copieFile() {
|
|
protected void copieFile() {
|
|
InputStream inStream = null;
|
|
InputStream inStream = null;
|
|
OutputStream outStream = null;
|
|
OutputStream outStream = null;
|
|
|
|
+ String jarLocation = "";
|
|
try {
|
|
try {
|
|
File source = new File(filePath);
|
|
File source = new File(filePath);
|
|
- File dest = new File(System.getProperty("user.dir") + "/bin/Images/", selectedFile.getName());
|
|
|
|
- imagePath = "/Images/" + selectedFile.getName();
|
|
|
|
|
|
+ // File dest = new File(System.getProperty("user.dir") +
|
|
|
|
+ // "/bin/Images/", selectedFile.getName());
|
|
|
|
+ // imagePath = "/Images/" + selectedFile.getName();
|
|
|
|
+ try {
|
|
|
|
+ jarLocation = getJarContainingFolder(this.getClass());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ File dest = new File(jarLocation + "/HolonGUI/Images/");
|
|
|
|
+ dest.mkdirs();
|
|
|
|
+
|
|
|
|
+ dest = new File(dest, selectedFile.getName());
|
|
|
|
+ imagePath = jarLocation + "/HolonGUI/Images/" + selectedFile.getName();
|
|
inStream = new FileInputStream(source);
|
|
inStream = new FileInputStream(source);
|
|
outStream = new FileOutputStream(dest);
|
|
outStream = new FileOutputStream(dest);
|
|
byte[] buffer = new byte[1024];
|
|
byte[] buffer = new byte[1024];
|
|
@@ -295,6 +312,22 @@ public class AddObjectPopUp extends JDialog {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static String getJarContainingFolder(Class aclass) throws Exception {
|
|
|
|
+ CodeSource codeSource = aclass.getProtectionDomain().getCodeSource();
|
|
|
|
+
|
|
|
|
+ File jarFile;
|
|
|
|
+
|
|
|
|
+ if (codeSource.getLocation() != null) {
|
|
|
|
+ jarFile = new File(codeSource.getLocation().toURI());
|
|
|
|
+ } else {
|
|
|
|
+ String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath();
|
|
|
|
+ String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
|
|
|
|
+ jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
|
|
|
|
+ jarFile = new File(jarFilePath);
|
|
|
|
+ }
|
|
|
|
+ return jarFile.getParentFile().getAbsolutePath();
|
|
|
|
+ }
|
|
|
|
+
|
|
public HolonObject getObject() {
|
|
public HolonObject getObject() {
|
|
return theObject;
|
|
return theObject;
|
|
}
|
|
}
|