瀏覽代碼

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

Teh-Hai Julian Zheng 8 年之前
父節點
當前提交
3d93592bea
共有 4 個文件被更改,包括 49 次插入19 次删除
  1. 21 8
      src/ui/view/AlgorithmMenu.java
  2. 1 0
      src/ui/view/FlexSubData.java
  3. 24 10
      src/ui/view/GUI.java
  4. 3 1
      src/ui/view/StatisticPanel.java

+ 21 - 8
src/ui/view/AlgorithmMenu.java

@@ -14,9 +14,11 @@ import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.tools.JavaCompiler;
 import javax.tools.ToolProvider;
 
+import api.CpsAlgorithm;
 import ui.controller.Control;
 import ui.model.Model;
 
@@ -129,7 +131,8 @@ public class AlgorithmMenu extends JMenu {
 	}
 
 	public void setAlgorithm(File file, String name) {
-		boolean missinConsole = false;
+		boolean missingCompiler = false;
+		boolean instantiationError = false;
 		try {
 			BufferedReader br = new BufferedReader(new FileReader(file.getPath()));
 			String line = br.readLine();
@@ -155,7 +158,7 @@ public class AlgorithmMenu extends JMenu {
 			JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
 
 			if (ToolProvider.getSystemJavaCompiler() == null) {
-				missinConsole = true;
+				missingCompiler = true;
 			}
 
 			compiler.run(null, null, null, file.getPath());
@@ -163,6 +166,7 @@ public class AlgorithmMenu extends JMenu {
 			// Load and instantiate compiled class.
 			URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
 
+			instantiationError = true;
 			Class<?> cls;
 			if (packageName.isEmpty()) {
 				cls = Class.forName(name, true, classLoader);
@@ -171,14 +175,23 @@ public class AlgorithmMenu extends JMenu {
 			}
 
 			Object t = cls.newInstance();
-
-			controller.setAlgorithm(t);
-
+			if (t instanceof CpsAlgorithm) {
+				controller.setAlgorithm(t);
+			} else {
+				JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
+						JOptionPane.ERROR_MESSAGE);
+				noneItem.doClick();
+			}
 		} catch (Exception e) {
-			if (missinConsole) {
-				controller.addTextToConsole("missing Compiiler! Please install JDK");
+			if (missingCompiler) {
+				JOptionPane.showMessageDialog(null, "Missing Compiiler! Please install JDK!", "Error!",
+						JOptionPane.ERROR_MESSAGE);
+			} else if (instantiationError) {
+				JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
+						JOptionPane.ERROR_MESSAGE);
+				noneItem.doClick();
 			} else {
-				controller.addTextToConsole(e.toString());
+				JOptionPane.showMessageDialog(null, e.toString(), "Error!", JOptionPane.ERROR_MESSAGE);
 			}
 		}
 	}

+ 1 - 0
src/ui/view/FlexSubData.java

@@ -89,6 +89,7 @@ public class FlexSubData extends JSplitPane {
 			listener.revalidate();
 			btnShowObjects.setText(HIDE);
 		}
+		super.repaint();
 	}
 	
 	public void hideAction(){

+ 24 - 10
src/ui/view/GUI.java

@@ -17,6 +17,7 @@ import java.awt.event.ComponentEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -384,7 +385,7 @@ public class GUI<E> implements CategoryListener {
 
 		String cntrlADown = "controlA";
 		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
-		actionMap.put(cntrlADown, new AbstractAction() {
+		AbstractAction controlA = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -416,7 +417,8 @@ public class GUI<E> implements CategoryListener {
 				}
 
 			}
-		});
+		};
+		actionMap.put(cntrlADown, controlA);
 
 		String delDown = "delete";
 		inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
@@ -523,7 +525,7 @@ public class GUI<E> implements CategoryListener {
 
 		String cntrlCDown = "controlC";
 		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
-		actionMap.put(cntrlCDown, new AbstractAction() {
+		AbstractAction controlC = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -546,11 +548,12 @@ public class GUI<E> implements CategoryListener {
 					}
 				}
 			}
-		});
+		};
+		actionMap.put(cntrlCDown, controlC);
 
 		String cntrlVDown = "controlV";
 		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
-		actionMap.put(cntrlVDown, new AbstractAction() {
+		AbstractAction controlV = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -584,12 +587,12 @@ public class GUI<E> implements CategoryListener {
 				}
 				canvas.repaint();
 			}
-		});
+		};
+		actionMap.put(cntrlVDown, controlV);
 
 		String cntrlXDown = "controlX";
 		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
-		actionMap.put(cntrlXDown, new AbstractAction() {
-
+		AbstractAction controlX = new AbstractAction() {
 			private static final long serialVersionUID = 1L;
 
 			@Override
@@ -612,7 +615,8 @@ public class GUI<E> implements CategoryListener {
 					canvas.repaint();
 				}
 			}
-		});
+		};
+		actionMap.put(cntrlXDown, controlX);
 
 		frmCyberPhysical.setJMenuBar(menuBar);
 
@@ -1313,7 +1317,17 @@ public class GUI<E> implements CategoryListener {
 		 *****************************/
 
 		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
-
+		/****************
+		 * Tree Stuff
+		 ****************/
+		
+		//Override Key Actions
+		inputMap = tree.getInputMap();
+		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
+		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
+		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
+		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
+		
 		TreeCellRenderer customRenderer = new TreeCellRenderer() {
 			@Override
 			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,

+ 3 - 1
src/ui/view/StatisticPanel.java

@@ -180,6 +180,7 @@ public class StatisticPanel extends JSplitPane implements GraphListener {
 		graphScrollPane.setViewportView(graphPanel);
 		
 		JSplitPane splitPane = new JSplitPane();
+		splitPane.setResizeWeight(0.5);
 		splitPane.setBorder(null);
 		splitPane.setPreferredSize(new Dimension(0, 0));
 		splitPane.setMinimumSize(new Dimension(0, 0));
@@ -693,10 +694,11 @@ public class StatisticPanel extends JSplitPane implements GraphListener {
 		colorPanel.setBackground(Color.WHITE);
 		colorPanel.setBounds(10, 164, 59, 38);
 		editPanel.add(colorPanel);
+		
 
 		btnAdd.setBounds(10, 213, 59, 23);
 		editPanel.add(btnAdd);
-		splitPane.setDividerLocation(220);
+		splitPane.setDividerLocation(0.5);
 		
 		//============================= WINDOWBUILDER COMPONENTS END =================//