Mercurial Hosting > junotu
changeset 118:290101988622
Functional checkbox options, and saving options to a card
author | Fox |
---|---|
date | Fri, 24 Nov 2023 23:20:29 +0100 |
parents | 652027516bd6 |
children | e11d32e296d2 |
files | src/junotu/Card.java src/junotu/Main.java src/junotu/TabEdit.java src/junotu/TabOptions.java |
diffstat | 4 files changed, 51 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/Card.java Sun Oct 15 09:26:24 2023 +0200 +++ b/src/junotu/Card.java Fri Nov 24 23:20:29 2023 +0100 @@ -18,6 +18,8 @@ public static final String TAG_SAVED = TAG_CORE_PREFIX+"timestamp_saved"; public static final String TAG_LAST_EDIT = TAG_CORE_PREFIX+"timestamp_last_edit"; + public static final String TAG_OPTIONS = TAG_CORE_PREFIX+"options"; + public static final String TAG_BOARD = TAG_CORE_PREFIX+"board"; public static final String TAG_BOARD_COLUMNS = TAG_CORE_PREFIX+"board_columns"; public static final String TAG_BOARD_COLUMN = TAG_CORE_PREFIX+"board_column"; @@ -35,6 +37,7 @@ public static final String VALUE_BOARD_COLUMN_CARD_ONLY = "only"; public static final String HIDE_TAGS[] = { + TAG_OPTIONS, TAG_BOARD_COLUMN, TAG_CALENDAR_BOARD, TAG_CALENDAR_BOARD_COLUMN,
--- a/src/junotu/Main.java Sun Oct 15 09:26:24 2023 +0200 +++ b/src/junotu/Main.java Fri Nov 24 23:20:29 2023 +0100 @@ -3,6 +3,10 @@ import java.lang.RuntimeException; import java.io.IOException; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.WildcardQuery; +import org.apache.lucene.index.Term; + import javax.swing.SwingUtilities; import java.awt.Desktop; import java.awt.Toolkit; @@ -12,6 +16,7 @@ import java.net.URI; import junotu.Database; +import junotu.Card; import junotu.Window; import junotu.Window.Tab; @@ -21,6 +26,8 @@ public static final int MAX_WINDOWS = 8; public static Database database; + public static Card options; + private static boolean optionsNew; public static Window[] windows = new Window[MAX_WINDOWS]; public static Desktop desktop; @@ -29,7 +36,21 @@ database = new Database(); desktop = Desktop.getDesktop(); - //database.databaseResaveAll(); + { + 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]; + } + } SwingUtilities.invokeLater( new Runnable() { @@ -68,6 +89,11 @@ } if( openWindowCount == 0 ) { System.out.print( "No windows open, closing program..\n" ); + if( optionsNew ) { + database.cardAdd( options ); + } else { + database.cardUpdate( options, false ); + } database.databaseCommit(); System.exit(0); }
--- a/src/junotu/TabEdit.java Sun Oct 15 09:26:24 2023 +0200 +++ b/src/junotu/TabEdit.java Fri Nov 24 23:20:29 2023 +0100 @@ -326,8 +326,9 @@ { tags.removeAll(); TagWidget newWidget; + boolean hideInternal = !Main.options.optionGetBool( Card.TAG_OPTION_PREFIX+"show_internal_tags", false ); for( String tag : card.tagNames() ) { - if( tag.startsWith("_") ) { + if( tag.startsWith("_") && hideInternal ) { continue; } for( Object value : card.tagValues( tag ) ) {
--- a/src/junotu/TabOptions.java Sun Oct 15 09:26:24 2023 +0200 +++ b/src/junotu/TabOptions.java Fri Nov 24 23:20:29 2023 +0100 @@ -20,7 +20,6 @@ import junotu.Main; import junotu.Window.TabInterface; import junotu.OptionTree; -import junotu.Card; public class TabOptions extends JPanel implements ActionListener, TabInterface { @@ -85,6 +84,7 @@ private static class OptionCheckbox extends Option { OptionTree.OptionCheckbox option; + JCheckBox checkbox; public OptionCheckbox( TabOptions events_, OptionTree.OptionCheckbox option_ ) { @@ -92,7 +92,10 @@ events = events_; option = option_; - JCheckBox checkbox = new JCheckBox( option.brief, option.default_value ); + checkbox = new JCheckBox( + option.brief, + Main.options.optionGetBool( option.tag, option.default_value ) + ); this.add(checkbox); @@ -185,11 +188,11 @@ } - public Card card; public Vector<OptionTree.OptionFolder> path = new Vector<OptionTree.OptionFolder>(); JPanel pathBox; Box optionList; + JButton apply; public TabOptions() { @@ -197,7 +200,7 @@ pathBox = new JPanel(); optionList = Box.createVerticalBox(); JScrollPane scroll = new JScrollPane(optionList); - JButton apply = new JButton("Apply"); + apply = new JButton("Apply"); pathBox.setLayout( new FlowLayout( FlowLayout.LEFT ) ); @@ -205,6 +208,8 @@ add( scroll, BorderLayout.CENTER ); add( apply, BorderLayout.SOUTH ); + apply.addActionListener(this); + path.add( OPTION_TREE.root ); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); @@ -270,13 +275,22 @@ } } - if( source instanceof OptionFolder ) { + if( source == apply ) { + /* TODO: Save options card. */ + } else if( source instanceof OptionFolder ) { OptionFolder clicked = (OptionFolder)source; path.add( clicked.option ); generate(); } else if( source instanceof OptionAction ) { OptionAction clicked = (OptionAction)source; clicked.option.onClick(); + } else if( source instanceof OptionCheckbox ) { + OptionCheckbox clicked = (OptionCheckbox)source; + Main.options.optionSetBool( clicked.option.tag, clicked.checkbox.isSelected() ); + System.out.print( + (clicked.checkbox.isSelected() ? "Checked" : "Unchecked")+ + " '"+clicked.option.tag+"'.\n" + ); } }