Browse Source

Fixes HolonElementTableCell staying in edit mode 4 2 long *finally*

Andreas T. Meyer-Berg 7 years ago
parent
commit
f3cc9afc6b
1 changed files with 25 additions and 1 deletions
  1. 25 1
      src/ui/view/GUI.java

+ 25 - 1
src/ui/view/GUI.java

@@ -17,6 +17,8 @@ import ui.model.Model;
 
 import javax.swing.*;
 import javax.swing.border.LineBorder;
+import javax.swing.event.AncestorEvent;
+import javax.swing.event.AncestorListener;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.JTableHeader;
@@ -1304,8 +1306,30 @@ public class GUI implements CategoryListener {
 				xBThis = e.getX();
 
 			}
+			
+			@Override
+			public void mouseExited(MouseEvent e) {
+				/**
+				 * Stop Editing, if mouse exits the Table
+				 */
+				JTable holElem = model.getTableHolonElement();
+				if(e.getX()<=0 || e.getX()>=holElem.getWidth() 
+						|| e.getY() <= 0 || e.getY()>= holElem.getHeight()){
+					CellEditor cellEditor = holElem.getCellEditor();
+					if (cellEditor != null) {
+					    if (cellEditor.getCellEditorValue() != null) {
+					    	/** TODO: Maybe try to save current Data */
+					        cellEditor.stopCellEditing();
+					    } else {
+					        cellEditor.cancelCellEditing();
+					    }
+					}
+				}
+				
+			}
+			
 		});
-
+		
 		/*
 		 * Triggered every time a change is made
 		 */