changeset 11:587b69a38915

Editing cards
author Fox
date Fri, 08 Apr 2022 13:13:31 +0200
parents 66d3fdffc3d2
children b4fd74d0680d
files src/junotu/CardWidget.java src/junotu/Database.java src/junotu/Main.java src/junotu/TabEdit.java src/junotu/TabSimpleSearch.java
diffstat 5 files changed, 43 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/CardWidget.java	Fri Apr 08 12:27:07 2022 +0200
+++ b/src/junotu/CardWidget.java	Fri Apr 08 13:13:31 2022 +0200
@@ -4,6 +4,8 @@
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import javax.swing.BorderFactory;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 
 import javax.swing.JPanel;
 
@@ -12,7 +14,9 @@
 import javax.swing.JLabel;
 import javax.swing.JTextArea;
 
+import junotu.Main;
 import junotu.Database.Card;
+import junotu.Window;
 
 public class CardWidget extends JPanel {
 
@@ -52,6 +56,24 @@
 	constraints.fill = GridBagConstraints.BOTH;
 	constraints.weighty = 0.5;
 	this.add( content, constraints );
+
+	MouseAdapter mouseListener = new MouseAdapter()
+	    {
+		@Override
+		public void mouseClicked( MouseEvent e )
+		{
+		    switch( e.getButton() )
+			{
+			case MouseEvent.BUTTON1: {
+			    Main.actionCardEdit( (Window)getTopLevelAncestor(), identifier );
+			}
+			}
+				      
+		}
+	    };
+	
+	this.addMouseListener( mouseListener );
+	content.addMouseListener( mouseListener );
 	
     }
 }
--- a/src/junotu/Database.java	Fri Apr 08 12:27:07 2022 +0200
+++ b/src/junotu/Database.java	Fri Apr 08 13:13:31 2022 +0200
@@ -165,6 +165,7 @@
 
 	luceneWriter.deleteDocuments( query );
 	luceneWriter.addDocument( cardToDocument( card ) );
+	System.out.print("Updated card with identifier "+Long.toString(card.identifier)+": '"+card.title+"'\n");
 	searcherRefresh();
 	//luceneWriter.commit();
 	
--- a/src/junotu/Main.java	Fri Apr 08 12:27:07 2022 +0200
+++ b/src/junotu/Main.java	Fri Apr 08 13:13:31 2022 +0200
@@ -66,19 +66,23 @@
 	return null;
     }
 
-    public static void actionCardCreate()
+    public static void actionCardCreate( Window window )
     {
-	Window active = windowGetActive();
-	active.tabSwitch( Tab.EDIT );
-	active.tabEdit.cardCreate();
+	//window = windowGetActive();
+	window.tabSwitch( Tab.EDIT );
+	window.tabEdit.cardCreate();
     }
 
-    public static void actionCardEdit( long identifier ) throws Exception
+    public static void actionCardEdit( Window window, long identifier )
     {
-	Window active = windowGetActive();
-	Card card = database.cardGetByIdentifier( identifier );
-	active.tabSwitch( Tab.EDIT );
-	active.tabEdit.cardEdit( card );
+	//window = windowGetActive();
+	try {
+	    Card card = database.cardGetByIdentifier( identifier );
+	    window.tabSwitch( Tab.EDIT );
+	    window.tabEdit.cardEdit( card );
+	} catch( Exception e ) {
+	    throw new RuntimeException(e);
+	}
     }
     
 }
--- a/src/junotu/TabEdit.java	Fri Apr 08 12:27:07 2022 +0200
+++ b/src/junotu/TabEdit.java	Fri Apr 08 13:13:31 2022 +0200
@@ -145,8 +145,9 @@
     
     private void buttonClickedBack()
     {
-	Main.windowGetActive().tabSwitch( Tab.SEARCH );
+	Window window = (Window)this.getTopLevelAncestor();
 	clearWidgets();
+        window.tabSwitch( Tab.SEARCH );
     }
     
     private void buttonClickedSave()
@@ -168,9 +169,10 @@
 	    
 	}
 
-        Main.windowGetActive().tabSearch.search();
-	Main.windowGetActive().tabSwitch( Tab.SEARCH );
+	Window window = (Window)this.getTopLevelAncestor();
+        window.tabSearch.search();
 	clearWidgets();
+	window.tabSwitch( Tab.SEARCH );
     }
     
 }
--- a/src/junotu/TabSimpleSearch.java	Fri Apr 08 12:27:07 2022 +0200
+++ b/src/junotu/TabSimpleSearch.java	Fri Apr 08 13:13:31 2022 +0200
@@ -136,7 +136,8 @@
     
     private void buttonClickedCreate()
     {
-	Main.actionCardCreate();
+	Window window = (Window)this.getTopLevelAncestor();
+	Main.actionCardCreate( window );
     }
     
 }