|
@@ -40,8 +40,14 @@ import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import ui.controller.Control;
|
|
|
|
|
|
+/**
|
|
|
+ * Popup for adding a Holon Object to a Category.
|
|
|
+ *
|
|
|
+ * @author Gruppe14
|
|
|
+ */
|
|
|
public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
private final JPanel contentPanel = new JPanel();
|
|
|
private AddElementPopUp addElement;
|
|
|
private JTextField objectName;
|
|
@@ -62,6 +68,9 @@ public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
/**
|
|
|
* Launch the application.
|
|
|
+ *
|
|
|
+ * @param args
|
|
|
+ * standard
|
|
|
*/
|
|
|
public static void main(String[] args) {
|
|
|
try {
|
|
@@ -75,6 +84,13 @@ public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
/**
|
|
|
* Create the dialog.
|
|
|
+ *
|
|
|
+ * @param edit
|
|
|
+ * true if edit
|
|
|
+ * @param obj
|
|
|
+ * the object
|
|
|
+ * @param cat
|
|
|
+ * the categorie
|
|
|
*/
|
|
|
public AddObjectPopUp(boolean edit, AbstractCpsObject obj, String cat) {
|
|
|
toEdit = obj;
|
|
@@ -168,8 +184,8 @@ public class AddObjectPopUp extends JDialog {
|
|
|
sourcePath.setText(filePath);
|
|
|
ImageIcon icon = new ImageIcon(
|
|
|
new ImageIcon(filePath).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
|
|
|
- if(icon != null)
|
|
|
- lblImagePreview.setIcon(icon);
|
|
|
+ if (icon != null)
|
|
|
+ lblImagePreview.setIcon(icon);
|
|
|
}
|
|
|
sourcePath.setBounds(148, 77, 271, 20);
|
|
|
contentPanel.add(sourcePath);
|
|
@@ -199,11 +215,11 @@ public class AddObjectPopUp extends JDialog {
|
|
|
{
|
|
|
|
|
|
listModel = new DefaultListModel();
|
|
|
- HolonElement hel = new HolonElement("Test", 100, 5);
|
|
|
- String name = hel.getEleName();
|
|
|
+
|
|
|
/*
|
|
|
- * for (int i = 0; i < 11; i++) { hel.setEleName(name + i);
|
|
|
- * addElement(hel); }
|
|
|
+ * HolonElement hel = new HolonElement("Test", 100, 5); String
|
|
|
+ * name = hel.getEleName(); for (int i = 0; i < 11; i++) {
|
|
|
+ * hel.setEleName(name + i); addElement(hel); }
|
|
|
*/
|
|
|
list = new JList(listModel);
|
|
|
scrollPane.setViewportView(list);
|
|
@@ -228,7 +244,7 @@ public class AddObjectPopUp extends JDialog {
|
|
|
btnNewButton.setBounds(270, 182, 142, 27);
|
|
|
contentPanel.add(btnNewButton);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
{
|
|
|
JPanel buttonPane = new JPanel();
|
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
@@ -241,8 +257,8 @@ public class AddObjectPopUp extends JDialog {
|
|
|
if (objectName.getText().length() > 0) {
|
|
|
if (sourcePath.getText().equals(filePath)) {
|
|
|
imagePath = filePath;
|
|
|
- if(imageChanged)
|
|
|
- copieFile();
|
|
|
+ if (imageChanged)
|
|
|
+ copieFile();
|
|
|
imageChanged = false;
|
|
|
// theObject = new
|
|
|
// HolonObject(objectName.getText());
|
|
@@ -290,19 +306,28 @@ public class AddObjectPopUp extends JDialog {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * adds a Holon Element.
|
|
|
+ *
|
|
|
+ * @param hl
|
|
|
+ * the HolonElement
|
|
|
+ */
|
|
|
public void addElement(HolonElement hl) {
|
|
|
hElements.add(hl);
|
|
|
listModel.addElement(hl.getAmount() + "x: " + hl.getEleName() + " " + hl.getEnergy() + "U");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Choose the file.
|
|
|
+ */
|
|
|
protected void fileChooser() {
|
|
|
// TODO Auto-generated method stub
|
|
|
- JFileChooser FileChooser = new JFileChooser();
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
|
|
|
- FileChooser.setFileFilter(filter);
|
|
|
- int returnValue = FileChooser.showOpenDialog(null);
|
|
|
+ fileChooser.setFileFilter(filter);
|
|
|
+ int returnValue = fileChooser.showOpenDialog(null);
|
|
|
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
|
|
- selectedFile = FileChooser.getSelectedFile();
|
|
|
+ selectedFile = fileChooser.getSelectedFile();
|
|
|
filePath = selectedFile.getAbsolutePath();
|
|
|
sourcePath.setText(filePath);
|
|
|
ImageIcon icon = new ImageIcon(
|
|
@@ -315,6 +340,9 @@ public class AddObjectPopUp extends JDialog {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Copies the File.
|
|
|
+ */
|
|
|
protected void copieFile() {
|
|
|
InputStream inStream = null;
|
|
|
OutputStream outStream = null;
|
|
@@ -339,15 +367,30 @@ public class AddObjectPopUp extends JDialog {
|
|
|
if (outStream != null)
|
|
|
outStream.close();
|
|
|
System.out.println("File Copied..");
|
|
|
- } catch (IOException e1) {
|
|
|
- e1.printStackTrace();
|
|
|
+ } catch (IOException eex) {
|
|
|
+ eex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Edit the Information.
|
|
|
+ *
|
|
|
+ * @param obj
|
|
|
+ * the CpsObject
|
|
|
+ */
|
|
|
public void editInformation(HolonObject obj) {
|
|
|
objectName.setText(obj.getName());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get Jar Containing Folder.
|
|
|
+ *
|
|
|
+ * @param aclass
|
|
|
+ * aClass
|
|
|
+ * @return String
|
|
|
+ * @throws Exception
|
|
|
+ * Exception
|
|
|
+ */
|
|
|
public static String getJarContainingFolder(Class aclass) throws Exception {
|
|
|
CodeSource codeSource = aclass.getProtectionDomain().getCodeSource();
|
|
|
|
|
@@ -364,14 +407,29 @@ public class AddObjectPopUp extends JDialog {
|
|
|
return jarFile.getParentFile().getAbsolutePath();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Return the Object.
|
|
|
+ *
|
|
|
+ * @return the CpsObject
|
|
|
+ */
|
|
|
public HolonObject getObject() {
|
|
|
return theObject;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the Controller.
|
|
|
+ *
|
|
|
+ * @param controller the controller
|
|
|
+ */
|
|
|
public void setController(Control controller) {
|
|
|
this.controller = controller;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set the Category.
|
|
|
+ *
|
|
|
+ * @param cat the Category
|
|
|
+ */
|
|
|
public void setCategory(String cat) {
|
|
|
givenCategory = cat;
|
|
|
}
|