changeset 119:e11d32e296d2

Cleaned-up option card code a bit, and functional 'save' and 'discard' buttons in TabOptions
author Fox
date Sat, 25 Nov 2023 11:40:14 +0100
parents 290101988622
children 6a78c671a7cf
files src/junotu/Main.java src/junotu/TabOptions.java src/junotu/Window.java
diffstat 3 files changed, 63 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/Main.java	Fri Nov 24 23:20:29 2023 +0100
+++ b/src/junotu/Main.java	Sat Nov 25 11:40:14 2023 +0100
@@ -35,22 +35,7 @@
 	{
 		database = new Database();
 		desktop = Desktop.getDesktop();
-		
-		{
-			Query query = new WildcardQuery( new Term(Card.TAG_OPTIONS, "*") );
-			Card cards[] = database.searchCustom( query, 1, false ).cards;
-			
-			optionsNew = cards.length == 0;
-			
-			if( optionsNew ) {
-				options = new Card();
-				options.titleSet( PROGRAM_NAME+" Options" );
-				options.contentSet( "Internal card that stores all "+PROGRAM_NAME+" settings." );
-				options.tagValueSetOnly( Card.TAG_OPTIONS, null );
-			} else {
-				options = cards[0];
-			}
-		}
+		optionsReload();
 		
 		SwingUtilities.invokeLater(
 			new Runnable() {
@@ -89,11 +74,7 @@
 		}
 		if( openWindowCount == 0 ) {
 			System.out.print( "No windows open, closing program..\n" );
-			if( optionsNew ) {
-				database.cardAdd( options );
-			} else {
-				database.cardUpdate( options, false );
-			}
+			optionsSave();
 			database.databaseCommit();
 			System.exit(0);
 		}
@@ -109,6 +90,32 @@
 		return null;
 	}
 	
+	public static void optionsReload()
+	{
+		Query query = new WildcardQuery( new Term(Card.TAG_OPTIONS, "*") );
+		Card cards[] = database.searchCustom( query, 1, false ).cards;
+		
+		optionsNew = cards.length == 0;
+		
+		if( optionsNew ) {
+			options = new Card();
+			options.titleSet( PROGRAM_NAME+" Options" );
+			options.contentSet( "Internal card that stores all "+PROGRAM_NAME+" settings." );
+			options.tagValueSetOnly( Card.TAG_OPTIONS, null );
+		} else {
+			options = cards[0];
+		}
+	}
+	
+	public static void optionsSave()
+	{
+		if( optionsNew ) {
+			database.cardAdd( options );
+		} else {
+			database.cardUpdate( options, false );
+		}
+	}
+	
 	public static void refreshSearches()
 	{
 		for( int i = 0; i < windows.length; i++ ) {
--- a/src/junotu/TabOptions.java	Fri Nov 24 23:20:29 2023 +0100
+++ b/src/junotu/TabOptions.java	Sat Nov 25 11:40:14 2023 +0100
@@ -192,7 +192,8 @@
 	
 	JPanel pathBox;
 	Box optionList;
-	JButton apply;
+	JButton save;
+	JButton discard;
 	
 	public TabOptions()
 	{
@@ -200,15 +201,25 @@
 		pathBox = new JPanel();
 		optionList = Box.createVerticalBox();
 		JScrollPane scroll = new JScrollPane(optionList);
-		apply = new JButton("Apply");
+		JPanel bottomBox = new JPanel();
+		save = new JButton("Save");
+		discard = new JButton("Discard");
 		
 		pathBox.setLayout( new FlowLayout( FlowLayout.LEFT ) );
+		bottomBox.setLayout( new BorderLayout() );
 		
 		add( pathBox, BorderLayout.NORTH );
 		add( scroll, BorderLayout.CENTER );
-		add( apply, BorderLayout.SOUTH );
+		add( bottomBox, BorderLayout.SOUTH );
+		
+		bottomBox.add( save, BorderLayout.CENTER );
+		bottomBox.add( discard, BorderLayout.EAST );
 		
-		apply.addActionListener(this);
+		save.addActionListener(this);
+		discard.addActionListener(this);
+		
+		save.setToolTipText( "Save option changes to disk." );
+		discard.setToolTipText( "Discard pending option changes, reload save options from disk." );
 		
 		path.add( OPTION_TREE.root );
 		
@@ -275,8 +286,11 @@
 			}
 		}
 		
-		if( source == apply ) {
-			/* TODO: Save options card. */
+		if( source == save ) {
+			Main.optionsSave();
+		} else if( source == discard ) {
+			Main.optionsReload();
+			generate();
 		} else if( source instanceof OptionFolder ) {
 			OptionFolder clicked = (OptionFolder)source;
 			path.add( clicked.option );
--- a/src/junotu/Window.java	Fri Nov 24 23:20:29 2023 +0100
+++ b/src/junotu/Window.java	Sat Nov 25 11:40:14 2023 +0100
@@ -65,14 +65,21 @@
 	
 	public Window( Tab tab )
 	{
-	
+		
 		panelsCreate();
 		tabSwitch( tab );
-	
+		
 		this.setSize(512, 384);
 		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		
+		if( tab == Tab.OPTIONS ) {
+			/* TODO: Make the window a popup or similar. ('Transient' on X).
+			         Practically, I want it to be a floating window
+			         in my window manager. */
+		}
+		
 		this.setVisible(true);
-	
+		
 	}
 	
 	@Override
@@ -120,16 +127,16 @@
 	
 	private void panelsCreate()
 	{
-	
+		
 		tabsLayout = new CardLayout();
 		tabs = new JPanel( tabsLayout );
-	
+		
 		tabSearch = new TabSimpleSearch();
 		tabEdit = new TabEdit();
 		tabBoard = new TabBoard();
 		tabCalendarBoard = new TabCalendarBoard();
 		tabOptions = new TabOptions();
-	
+		
 		this.add(tabs);
 		tabs.add(tabSearch);
 		tabs.add(tabEdit);
@@ -141,14 +148,14 @@
 		tabsLayout.addLayoutComponent( tabBoard,         TAB_NAMES[Tab.BOARD.ordinal()] );
 		tabsLayout.addLayoutComponent( tabCalendarBoard, TAB_NAMES[Tab.CALENDAR_BOARD.ordinal()] );
 		tabsLayout.addLayoutComponent( tabOptions,       TAB_NAMES[Tab.OPTIONS.ordinal()] );
-	
+		
 		tabs.registerKeyboardAction(
 			this,
 			KEY_ACTION_NEW_WINDOW,
 			KeyStroke.getKeyStroke( KeyEvent.VK_F2, 0 ),
 			JPanel.WHEN_IN_FOCUSED_WINDOW
 		);
-	
+		
 	}
 	
 }