Przeglądaj źródła

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

Teh-Hai Julian Zheng 7 lat temu
rodzic
commit
71b6ded489
3 zmienionych plików z 150 dodań i 92 usunięć
  1. 85 82
      src/ui/view/GUI.java
  2. 31 5
      src/ui/view/MyCanvas.java
  3. 34 5
      src/ui/view/UpperNodeCanvas.java

+ 85 - 82
src/ui/view/GUI.java

@@ -111,9 +111,10 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmOpen = new JMenuItem("Open");
 	private final JMenuItem mntmNew = new JMenuItem("New");
 	private final JMenuItem mntmSave = new JMenuItem("Save");
-	private final JMenuItem aboutUs = new JMenuItem("About Us");
-	private final JMenuItem canvasSize = new JMenuItem("View Size");
-	private final JMenuItem background = new JMenuItem("Background Image");
+	private final JMenuItem mntmAboutUs = new JMenuItem("About Us");
+	private final JMenuItem mntmCanvasSize = new JMenuItem("View Size");
+	private final JMenuItem mntmBackground = new JMenuItem("Background Image");
+	private final JMenuItem mntmSplitView = new JMenuItem("Split View");
 	private final JSplitPane splitPane = new JSplitPane();
 	private final JSplitPane splitPane1 = new JSplitPane();
 	private final JSplitPane splitPaneCanvasConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
@@ -123,15 +124,12 @@ public class GUI<E> implements CategoryListener {
 	// private final JScrollPane holonSP = new JScrollPane();
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.TOP);
-	private final JButton splitButton = new JButton("Split View Test");
 	private JSplitPane tempSplit;
 	private boolean initSplit = true;
 
 	private JPopupMenu popmenuEdit = new JPopupMenu();
 	private JMenuItem editItem = new JMenuItem("Edit Object");
 	private String catOfObjToBeEdited;
-	private final JScrollPane statTab = new JScrollPane();
-
 	private FlexiblePane flexPane;
 	private StatPanel2 statSplitPane;
 	private JScrollPane statScrollPane;
@@ -431,23 +429,26 @@ public class GUI<E> implements CategoryListener {
 							controller.delObjUpperNode(cps, uNC.upperNode);
 							// Remove UpperNodeTab if UpperNode deleted
 							if (cps instanceof CpsUpperNode) {
+								boolean splitView = false;
 								for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-									if (tabbedPane.getComponentAt(i) != null
-											&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
-													.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+									if (tabbedPane.getComponentAt(i) == null) {
+										splitView = true;
+									} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
+											.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
 										((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
 										break;
 									}
 								}
 								// If SplitView is on and the view on
 								// tabbedPane2 is the deleted upperNode
-								if (tabbedPane2.getTabCount() > 0
-										&& ((JScrollPane) tabbedPane2.getSelectedComponent()).getViewport()
-												.getComponent(0) instanceof UpperNodeCanvas
-										&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
-												.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
-									((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
-											.removeTabs();
+								try {
+									if (splitView
+											&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+													.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+										((ButtonTabComponent) tabbedPane
+												.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
+									}
+								} catch (Exception e2) {
 								}
 							}
 						}
@@ -465,23 +466,25 @@ public class GUI<E> implements CategoryListener {
 						controller.delCanvasObject(cps, save);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
+							boolean splitView = false;
 							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-								if (tabbedPane.getComponentAt(i) != null
-										&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-												.getComponent(0)).upperNode.getId() == cps.getId()) {
+								if (tabbedPane.getComponentAt(i) == null) {
+									splitView = true;
+								} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+										.getComponent(0)).upperNode.getId() == cps.getId()) {
 									((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
 									break;
 								}
 							}
 							// If SplitView is on and the view on
 							// tabbedPane2 is the deleted upperNode
-							if (tabbedPane2.getTabCount() > 0
-									&& ((JScrollPane) tabbedPane2.getSelectedComponent()).getViewport()
-											.getComponent(0) instanceof UpperNodeCanvas
-									&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
-											.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
-								((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
-										.removeTabs();
+							try {
+								if (splitView && ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+										.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+									((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
+											.removeTabs();
+								}
+							} catch (Exception e2) {
 							}
 						}
 					}
@@ -697,8 +700,8 @@ public class GUI<E> implements CategoryListener {
 
 		menuBar.add(mnNewMenuView);
 
-		mnNewMenuView.add(canvasSize);
-		canvasSize.addActionListener(new ActionListener() {
+		mnNewMenuView.add(mntmCanvasSize);
+		mntmCanvasSize.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				JPanel myPanel = new JPanel();
@@ -739,10 +742,53 @@ public class GUI<E> implements CategoryListener {
 			}
 		});
 
-		mnNewMenuView.add(canvasSize);
+		mnNewMenuView.add(mntmCanvasSize);
+		mnNewMenuView.add(mntmSplitView);
+		
+		// Split View
+				mntmSplitView.addActionListener(new ActionListener() {
+					@Override
+					public void actionPerformed(ActionEvent e) {
+						if (splitPaneCanvasConsole.getLeftComponent() instanceof JSplitPane) {
+							initSplit = true;
+							Component tempC = tabbedPane2.getSelectedComponent();
+							tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
+							tabbedPane2.removeAll();
+							splitPaneCanvasConsole.setLeftComponent(tabbedPane);
+						} else {
+							for (int i = 0; i < tabbedPane.getTabCount(); i++) {
+								tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
+								if (i >= 4) {
+									// tabbedPane2.setTabComponentAt(tabbedPane.getTabCount()
+									// - 1,
+									// new ButtonTabComponent(tabbedPane, tabbedPane2));
+								}
+							}
+							if (tabbedPane.getSelectedComponent() == statScrollPane) {
+								tabbedPane.setComponentAt(0, null);
+								tabbedPane2.setComponentAt(0, canvasSP);
+								tabbedPane2.setSelectedIndex(0);
+							} else {
+								tabbedPane.setComponentAt(1, null);
+								tabbedPane2.setComponentAt(1, statScrollPane);
+								tabbedPane2.setSelectedIndex(1);
+							}
+							tempSplit = new JSplitPane();
+							tempSplit.setBorder(null);
+							tempSplit.setRightComponent(tabbedPane2);
+							tempSplit.setLeftComponent(tabbedPane);
+							tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
+							tempSplit.setResizeWeight(0.9);
+							splitPaneCanvasConsole.setLeftComponent(tempSplit);
+							initSplit = false;
+						}
+						contentPane.updateUI();
+					}
 
-		mnNewMenuView.add(background);
-		background.addActionListener(new ActionListener() {
+				});
+		mnNewMenuView.add(mntmBackground);
+		
+		mntmBackground.addActionListener(new ActionListener() {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
@@ -787,57 +833,14 @@ public class GUI<E> implements CategoryListener {
 		splitPane_1.setLeftComponent(lblHolonBodySize);
 
 		mnAlgorithm.add(simMenu);
-		
+
 		menuBar.add(mnAlgorithm);
-		
+
 		menuBar.add(mnHelp);
 
-		mnHelp.add(aboutUs);
+		mnHelp.add(mntmAboutUs);
 
-		// Testing
-		menuBar.add(splitButton);
-		// Split View
-		splitButton.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				if (splitPaneCanvasConsole
-						.getLeftComponent() instanceof JSplitPane) {
-					initSplit = true;
-					Component tempC = tabbedPane2.getSelectedComponent();
-					tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
-					tabbedPane2.removeAll();
-					splitPaneCanvasConsole.setLeftComponent(tabbedPane);
-				} else {
-					for (int i = 0; i < tabbedPane.getTabCount(); i++) {
-						tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
-						if (i >= 4) {
-							// tabbedPane2.setTabComponentAt(tabbedPane.getTabCount()
-							// - 1,
-							// new ButtonTabComponent(tabbedPane, tabbedPane2));
-						}
-					}
-					if (tabbedPane.getSelectedComponent() == statScrollPane) {
-						tabbedPane.setComponentAt(0, null);
-						tabbedPane2.setComponentAt(0, canvasSP);
-						tabbedPane2.setSelectedIndex(0);
-					} else {
-						tabbedPane.setComponentAt(1, null);
-						tabbedPane2.setComponentAt(1, statScrollPane);
-						tabbedPane2.setSelectedIndex(1);
-					}
-					tempSplit = new JSplitPane();
-					tempSplit.setBorder(null);
-					tempSplit.setRightComponent(tabbedPane2);
-					tempSplit.setLeftComponent(tabbedPane);
-					tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
-					tempSplit.setResizeWeight(0.9);
-					splitPaneCanvasConsole.setLeftComponent(tempSplit);
-					initSplit = false;
-				}
-				contentPane.updateUI();
-			}
-
-		});
+		
 
 		tabbedPane.addChangeListener(new ChangeListener() {
 
@@ -1530,7 +1533,7 @@ public class GUI<E> implements CategoryListener {
 		 * Pop up - About Us with some important information about the
 		 * developers, source and programming stuff
 		 */
-		aboutUs.addMouseListener(new MouseAdapter() {
+		mntmAboutUs.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
 				aboutUsPopUp = new AboutUsPopUp();
@@ -2118,9 +2121,9 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenuOptions.setText(tempArray[9]);
 		mntmResetCategory.setText(tempArray[10]);
 		mnNewMenuView.setText(tempArray[11]);
-		canvasSize.setText(tempArray[12]);
+		mntmCanvasSize.setText(tempArray[12]);
 		mnHelp.setText(tempArray[13]);
-		aboutUs.setText(tempArray[14]);
+		mntmAboutUs.setText(tempArray[14]);
 		mntmEditEdges.setText(tempArray[15]);
 		mnLanguage.setText(tempArray[16]);
 		canvas.updateLanguages();
@@ -2247,7 +2250,7 @@ public class GUI<E> implements CategoryListener {
 
 			JScrollPane sp = new JScrollPane(unc);
 			sp.setBorder(null);
-			//Selected tabbed Pane = tabbedPane or tabbedPane2
+			// Selected tabbed Pane = tabbedPane or tabbedPane2
 			if (tabTemp == tabbedPane) {
 				tabbedPane.add(temp.getName(), sp);
 				tabbedPane.setSelectedComponent(sp);

+ 31 - 5
src/ui/view/MyCanvas.java

@@ -27,6 +27,7 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
 import javax.swing.JTabbedPane;
 
 import com.google.gson.JsonParseException;
@@ -343,15 +344,40 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					controller.removeTrackingObj(cps);
 					// Remove UpperNodeTab if UpperNode deleted
 					if (cps instanceof CpsUpperNode) {
-						JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
+						boolean splitView = false;
+						JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
+						JTabbedPane tabbedPane;
+						JTabbedPane tabbedPane2;
+						// if SplitView is activated
+						if (tempSplit.getLeftComponent() instanceof JTabbedPane
+								&& tempSplit.getRightComponent() instanceof JTabbedPane) {
+							splitView = true;
+							tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+							tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
+						} else {
+							tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+							tabbedPane2 = null;
+						}
+						//Look if the uppernode is open in a Tab
 						for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-							if (tabbedPane.getComponentAt(i) != null
-									&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-											.getComponent(0)).upperNode.getId() == cps.getId()) {
+							if (tabbedPane.getComponentAt(i) == null) {
+							} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+									.getComponent(0)).upperNode.getId() == cps.getId()) {
 								((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
 								break;
 							}
 						}
+						// If SplitView is on and the view on
+						// tabbedPane2 is the deleted upperNode
+						try {
+							if (tabbedPane2 != null
+									&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+											.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+								((ButtonTabComponent) tabbedPane
+										.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
+							}
+						} catch (Exception e2) {
+						}
 					}
 					toolTip = false;
 				}
@@ -1112,7 +1138,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 *            boolean for conecction
 	 * @param object
 	 *            boolean for objects
-	 * @param nodeOfnode 
+	 * @param nodeOfnode
 	 */
 	public void setShowedInformation(boolean connection, boolean object, boolean border, boolean nodeOfnode) {
 		showedInformation[0] = connection;

+ 34 - 5
src/ui/view/UpperNodeCanvas.java

@@ -27,6 +27,7 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
 import javax.swing.JTabbedPane;
 
 import com.google.gson.JsonParseException;
@@ -358,14 +359,41 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						controller.removeTrackingObj(cps);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
-							JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
+							boolean splitView = false;
+							JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
+							JTabbedPane tabbedPane;
+							JTabbedPane tabbedPane2;
+							// if SplitView is activated
+							if (tempSplit.getLeftComponent() instanceof JTabbedPane
+									&& tempSplit.getRightComponent() instanceof JTabbedPane) {
+								splitView = true;
+								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+								tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
+							} else {
+								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+								tabbedPane2 = null;
+							}
+							//Look if the uppernode is open in a Tab
 							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-								if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+								if (tabbedPane.getComponentAt(i) == null) {
+								} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 										.getComponent(0)).upperNode.getId() == cps.getId()) {
-									tabbedPane.remove(i);
-									i = tabbedPane.getTabCount();
+									((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
+									break;
 								}
 							}
+							// If SplitView is on and the view on
+							// tabbedPane2 is the deleted upperNode
+							try {
+								if (tabbedPane2 != null
+										&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+												.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+									((ButtonTabComponent) tabbedPane
+											.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
+								}
+							} catch (Exception e2) {
+							}
+
 						}
 					}
 				}
@@ -680,7 +708,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 							if (ed.getState()) {
 								g2.setColor(Color.GREEN);
 								if (ed.getCapacity() != -1) {
-									g2.setStroke(new BasicStroke(Math.min(((ed.getFlow() / ed.getCapacity() * 3) + 1), 4)));
+									g2.setStroke(
+											new BasicStroke(Math.min(((ed.getFlow() / ed.getCapacity() * 3) + 1), 4)));
 								}
 							} else {
 								g2.setColor(Color.RED);