Ver Fonte

Split View fortschritt

Kevin Trometer há 7 anos atrás
pai
commit
9ce5770883
1 ficheiros alterados com 51 adições e 6 exclusões
  1. 51 6
      src/ui/view/GUI.java

+ 51 - 6
src/ui/view/GUI.java

@@ -122,6 +122,8 @@ public class GUI<E> implements CategoryListener {
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.TOP);
 	private final JButton splitButton = new JButton("Split View");
+	private JSplitPane tempSplit;
+	private boolean initSplit = true;
 
 	private final JPanel panelTapped_SimMenu = new JPanel();
 	private JPopupMenu popmenuEdit = new JPopupMenu();
@@ -755,12 +757,13 @@ public class GUI<E> implements CategoryListener {
 
 		// Testing
 		menuBar.add(splitButton);
-		//Split View
+		// Split View
 		splitButton.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				if (panelTapped_SimMenu
 						.getComponent(panelTapped_SimMenu.getComponentCount() - 1) instanceof JSplitPane) {
+					initSplit = true;
 					Component tempC = tabbedPane2.getSelectedComponent();
 					tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
 					tabbedPane2.removeAll();
@@ -772,28 +775,70 @@ public class GUI<E> implements CategoryListener {
 						tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
 					}
 					if (tabbedPane.getSelectedComponent() == statScrollPane) {
-						tabbedPane.setComponentAt(0,null);
+						tabbedPane.setComponentAt(0, null);
 						tabbedPane2.setComponentAt(0, canvasSP);
 						tabbedPane2.setSelectedIndex(0);
 					} else {
-						tabbedPane.setComponentAt(1,null);
+						tabbedPane.setComponentAt(1, null);
 						tabbedPane2.setComponentAt(1, statScrollPane);
 						tabbedPane2.setSelectedIndex(1);
 					}
-					JSplitPane tempSplit = new JSplitPane();
+					tempSplit = new JSplitPane();
 					tempSplit.setBorder(null);
 					tempSplit.setRightComponent(tabbedPane2);
 					tempSplit.setLeftComponent(tabbedPane);
-					tempSplit.setDividerLocation(tabbedPane.getWidth()/2);
+					tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
 					tempSplit.setResizeWeight(0.9);
 					panelTapped_SimMenu.remove(tabbedPane);
 					panelTapped_SimMenu.add(tempSplit);
+					initSplit = false;
 				}
 				contentPane.updateUI();
 			}
 
 		});
 
+		tabbedPane.addChangeListener(new ChangeListener() {
+
+			@Override
+			public void stateChanged(ChangeEvent e) {
+				if (tabbedPane.getSelectedComponent() == null) {
+					Component tempC = tabbedPane2.getSelectedComponent();
+					tabbedPane2.setComponentAt(tabbedPane.getSelectedIndex(), null);
+					tabbedPane.setComponentAt(tabbedPane.getSelectedIndex(), tempC);
+					tempC = tabbedPane.getComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()));
+					tabbedPane.setComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()), null);
+					tabbedPane2.setComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()), tempC);
+					tabbedPane2.setSelectedIndex((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()));
+					contentPane.updateUI();
+				}
+			}
+		});
+
+		tabbedPane2.addChangeListener(new ChangeListener() {
+
+			@Override
+			public void stateChanged(ChangeEvent e) {
+				if (tabbedPane2.getSelectedComponent() == null && !initSplit) {
+					Component tempC = tabbedPane.getComponentAt(tabbedPane2.getSelectedIndex());
+					tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), null);
+					tabbedPane2.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
+					for (int i = 0; i < tabbedPane.getTabCount(); i++) {
+						if (tabbedPane2.getComponentAt(i) != null && tabbedPane2.getComponentAt(i) != tempC) {
+							tempC = tabbedPane2.getComponentAt(i);
+							tabbedPane2.setComponentAt(i, null);
+							tabbedPane.setComponentAt(i, tempC);
+							break;
+						}
+					}
+					if (tabbedPane.getSelectedIndex() == tabbedPane2.getSelectedIndex()) {
+						tabbedPane.setSelectedIndex((tabbedPane2.getSelectedIndex() + 1) % tabbedPane.getTabCount());
+					}
+					contentPane.updateUI();
+				}
+			}
+		});
+
 		mnNewMenuOptions.add(mnLanguage);
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
@@ -1799,7 +1844,7 @@ public class GUI<E> implements CategoryListener {
 		splitPane1.setDividerLocation(500);
 		splitPaneCanvasConsole.setDividerLocation(550);
 		splitPaneCanvasConsole.setResizeWeight(0.9);
-		
+
 		splitPane.setLeftComponent(scrollPane1);
 		splitPaneCanvasConsole.setLeftComponent(panelTapped_SimMenu);
 		tabbedPane.addTab("View", canvasSP);