changeset 41:101ad0b0ab6f

TabColumns: Plus button now inserts new card
author Fox
date Sun, 30 Oct 2022 00:29:20 +0200
parents 979e9183aac8
children a5bc0a1f173c
files src/junotu/TabColumns.java
diffstat 1 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/TabColumns.java	Fri Oct 21 17:08:34 2022 +0200
+++ b/src/junotu/TabColumns.java	Sun Oct 30 00:29:20 2022 +0200
@@ -43,7 +43,7 @@
     final static int COLUMN_CONTENT_WIDTH = 256;
     final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16;
     
-    private class ColumnWidget extends JPanel {
+    private class ColumnWidget extends JPanel implements ActionListener {
 	JLabel title;
 	JTextField titleEdit;
 	Box cards;
@@ -90,6 +90,8 @@
 		    new Font( "Monospaced", Font.BOLD, 16 )
 		)
 	    );
+
+	    addCard.addActionListener(this);
 	    
 	}
 
@@ -111,6 +113,17 @@
 	    ColumnCardWidget cardWidget = new ColumnCardWidget( card );
 	    /* TODO: Check if works properly. */
 	    cards.add( cardWidget, at );
+	    cards.validate();
+	    this.validate(); /* Without this, first inserted card doesn't show up. */
+	}
+
+	public void actionPerformed( ActionEvent e )
+	{
+	    if( e.getSource() == addCard ) {
+		Card newCard = new Card();
+		newCard.titleSet("New card");
+		insertCard( newCard, -1 );
+	    }
 	}
     }
 
@@ -172,19 +185,8 @@
     {
 	title.setText("New board");
 	columns.removeAll();
-	Card testCard = new Card();
-	testCard.titleSet("Test card");
-	testCard.contentSet("Content.");
 	for( int i = 0; i < 5; i++ ) {
-	    ColumnWidget column = new ColumnWidget();
-	    column.titleSet("New column");
-
-	    for( int j = 0; j < i*3; j++ ) {
-		column.insertCard( testCard, -1 );
-	    }
-
-	    columns.add( Box.createHorizontalStrut(16) );
-	    columns.add(column);
+	    insertColumn();
 	}
     }
 
@@ -197,5 +199,13 @@
     {
 	
     }
+
+    public void insertColumn()
+    {
+	ColumnWidget column = new ColumnWidget();
+	column.titleSet("New column");
+	columns.add( Box.createHorizontalStrut(16) );
+	columns.add(column);
+    }
     
 }