|
@@ -5,6 +5,7 @@ import java.awt.Dimension;
|
|
|
import java.awt.Window;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
+import java.io.File;
|
|
|
import java.util.Collection;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
@@ -19,8 +20,8 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
|
|
|
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
|
|
|
|
|
|
+import javax.swing.JFileChooser;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JLabel;
|
|
@@ -32,6 +33,7 @@ import javax.swing.JComboBox;
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.event.DocumentEvent;
|
|
|
import javax.swing.event.DocumentListener;
|
|
|
+import javax.swing.filechooser.FileFilter;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
public class ConnectionCreationPanel extends JScrollPane {
|
|
@@ -135,9 +137,7 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
private void initializePanel() {
|
|
|
disconnectedIndex = connection.getProtocol().getNumberOfRoles();
|
|
|
|
|
|
- availableProtocols = new LinkedList<Class<? extends Protocol>>();
|
|
|
- availableProtocols.add(MQTT_protocol.class);
|
|
|
- availableProtocols.add(SimpleProtocol.class);
|
|
|
+ availableProtocols = controller.getControllerImport().getProtocols();
|
|
|
|
|
|
setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
|
this.setPreferredSize(new Dimension(600, 170 + ports.length * 20));
|
|
@@ -273,8 +273,69 @@ public class ConnectionCreationPanel extends JScrollPane {
|
|
|
JButton btnImportLink = new JButton("Import Link Type");
|
|
|
btnImportLink.setBounds(290, 40, 155, 20);
|
|
|
content.add(btnImportLink);
|
|
|
- btnImportLink.addActionListener(a -> System.out
|
|
|
- .println("WARNING: No import yet"));
|
|
|
+ btnImportLink.addActionListener(a -> {
|
|
|
+ //Filechooser starting in the base directory
|
|
|
+ JFileChooser fc = new JFileChooser(new File(System.getProperty("user.dir")));
|
|
|
+ fc.setFileFilter(new FileFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getDescription() {
|
|
|
+ return "Java Files(.java, .class)";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean accept(File f) {
|
|
|
+ if(f == null)
|
|
|
+ return false;
|
|
|
+ else if(f.isDirectory())
|
|
|
+ return true;
|
|
|
+ String[] parts = f.getName().split("[.]");
|
|
|
+ if(parts.length<=1)
|
|
|
+ return false;
|
|
|
+ String ending = parts[parts.length-1].toLowerCase();
|
|
|
+ if(ending.equals("class"))
|
|
|
+ return true;
|
|
|
+ else if(ending.equals("java"))
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ int returnVal = fc.showOpenDialog(this);
|
|
|
+
|
|
|
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
|
+ File file = fc.getSelectedFile();
|
|
|
+ System.out.println("Opening: " + file.getName());
|
|
|
+ String[] parts = file.getName().split("[.]");
|
|
|
+ for(int i = 0; i<parts.length; i++)
|
|
|
+ System.out.println(i+" "+parts[i]);
|
|
|
+ if(parts.length <= 1)
|
|
|
+ return;
|
|
|
+ String ending = parts[parts.length-1].toLowerCase();
|
|
|
+ if(ending.equals("class")){
|
|
|
+ System.out.println("Java Class File - not implemented");
|
|
|
+ }
|
|
|
+ else if(ending.equals("java")){
|
|
|
+ System.out.println("Java File");
|
|
|
+ // Compile source file.
|
|
|
+ Class imported = controller.getControllerImport().importJavaClass(file);
|
|
|
+ if(imported==null){
|
|
|
+ System.out.println("Importing failed");
|
|
|
+ }else{
|
|
|
+ Class[] interfaces = imported.getInterfaces();
|
|
|
+ for(int i = 0; i<interfaces.length; i++){
|
|
|
+ if(interfaces[i] == Protocol.class)
|
|
|
+ System.out.println("YEAH PROTOCOL");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.out.println("invalid File Type");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("Open command cancelled by user.");
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
JButton btnCreate = new JButton("Verify and Create");
|
|
|
btnCreate.setBounds(121, 103, 206, 25);
|