Mercurial Hosting > junotu
changeset 111:b93c6236c6cb
TabOptions: Minor progress
author | Fox |
---|---|
date | Thu, 15 Jun 2023 00:53:55 +0200 |
parents | 487ba392d38a |
children | 9bf9fd26bb33 |
files | src/junotu/Card.java src/junotu/Main.java src/junotu/OptionTree.java src/junotu/TabOptions.java |
diffstat | 4 files changed, 120 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/Card.java Thu Jun 15 00:09:23 2023 +0200 +++ b/src/junotu/Card.java Thu Jun 15 00:53:55 2023 +0200 @@ -9,7 +9,7 @@ import java.util.HashSet; public class Card { - + public static final String TAG_CORE_PREFIX = "_junotu_"; public static final String TAG_IDENTIFIER = TAG_CORE_PREFIX+"identifier"; public static final String TAG_TITLE = TAG_CORE_PREFIX+"title"; @@ -17,31 +17,33 @@ public static final String TAG_SEARCH = TAG_CORE_PREFIX+"search"; 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_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"; public static final String TAG_BOARD_COLUMN_CARDS = TAG_CORE_PREFIX+"board_column_cards"; public static final String TAG_BOARD_COLUMN_CARD = TAG_CORE_PREFIX+"board_column_card"; - + public static final String TAG_CALENDAR_BOARD = TAG_CORE_PREFIX+"calendar_board"; public static final String TAG_CALENDAR_BOARD_COLUMN = TAG_CORE_PREFIX+"calendar_board_column"; public static final String TAG_CALENDAR_BOARD_COLUMN_DATE = TAG_CORE_PREFIX+"calendar_board_column_date"; public static final String TAG_CALENDAR_BOARD_COLUMN_CARDS = TAG_CORE_PREFIX+"calendar_board_column_cards"; public static final String TAG_CALENDAR_BOARD_OPTION_ONLY_FILLED = TAG_CORE_PREFIX+"calendar_board_hide_empty_days"; - + + public static final String TAG_OPTION_PREFIX = TAG_CORE_PREFIX+"option_"; + public static final String VALUE_BOARD_COLUMN_CARD_ONLY = "only"; - + public static final String HIDE_TAGS[] = { TAG_BOARD_COLUMN, TAG_CALENDAR_BOARD, TAG_CALENDAR_BOARD_COLUMN, }; - + public static final String HIDE_TAG_VALUES[] = { TAG_BOARD_COLUMN_CARD, VALUE_BOARD_COLUMN_CARD_ONLY, }; - + public static final SortedMap< String, Class<?> > STRICT_TAG_TYPES; static { STRICT_TAG_TYPES = new TreeMap< String, Class<?> >(); @@ -49,67 +51,67 @@ STRICT_TAG_TYPES.put( Card.TAG_SAVED, Long.class ); STRICT_TAG_TYPES.put( Card.TAG_LAST_EDIT, Long.class ); } - + public SortedMap< String, Set<Object> > tags = new TreeMap< String, Set<Object> >(); - + public Card() {} - + public Long identifierGet() { return this.<Long>tagGetAs( TAG_IDENTIFIER ); } - + public String titleGet() { return tagGetAsOr( TAG_TITLE, "" ); } - + public void titleSet( String title ) { tagValueSetOnly( TAG_TITLE, title ); } - + public String contentGet() { return tagGetAsOr( TAG_CONTENT, "" ); } - + public void contentSet( String content ) { tagValueSetOnly( TAG_CONTENT, content ); } - + /** Return all set tags. */ public Set<String> tagNames() { return tags.keySet(); } - + public Set<Object> tagValues( String tag ) { return tags.get( tag ); } - + public void tagRemove( String tag ) { tags.remove( tag ); } - + public void tagValueSetOnly( String tag, Object value ) { Set<Object> values = new HashSet<Object>(); values.add( value ); tags.put( tag, values ); } - + /** Adds a value to a tag, if it doesn't contain equal value yet. Returns true if the value is new. */ public boolean tagValueAdd( String tag, Object value ) { Set<Object> values = new HashSet<Object>(); values.add( value ); - + values = tags.putIfAbsent( tag, values ); - + if( values == null ) { /* Means that key is new to the map, and was added just now. */ return true; @@ -117,46 +119,46 @@ return values.add( value ); } } - + public void tagValueRemove( String tag, Object value ) { Set<Object> values = tags.get( tag ); - + if( values == null ) { return; } - + values.remove( value ); - + if( values.size() == 0 ) { tagRemove( tag ); } - + } - + public void tagValueReplace( String tag, Object previous, Object value ) { Set<Object> values = tags.get( tag ); - + if( values == null ) { throw new RuntimeException("Can't replace value of a tag if the tag doesn't exist."); } - + values.remove( previous ); values.add( value ); - + } - + /** Returns first T value of a tag, or null. */ @SuppressWarnings("unchecked") public <T> T tagGetAs( String tag ) { final Set<Object> values = tagValues( tag ); - + if( values == null ) { return null; } - + Object current; while( ( current = values.iterator().next() ) != null ) { try { @@ -167,21 +169,21 @@ } return null; } - + public <T> T tagGetAsOr( String tag, T or ) { T value = tagGetAs( tag ); return value != null ? value : or; } - + public boolean tagHas( String tag ) { return tags.containsKey(tag); } - + public boolean isBoard() { return tags.containsKey(TAG_BOARD); } - + }
--- a/src/junotu/Main.java Thu Jun 15 00:09:23 2023 +0200 +++ b/src/junotu/Main.java Thu Jun 15 00:53:55 2023 +0200 @@ -17,7 +17,7 @@ public class Main { - public static final String PROGRAM_NAME = "Junotu"; + public static final String PROGRAM_NAME = "JUnotu"; public static final int MAX_WINDOWS = 8; public static Database database;
--- a/src/junotu/OptionTree.java Thu Jun 15 00:09:23 2023 +0200 +++ b/src/junotu/OptionTree.java Thu Jun 15 00:53:55 2023 +0200 @@ -3,18 +3,18 @@ import java.util.ArrayList; public class OptionTree { - + public static class Option<T> { - + public String tag; public String brief; public String hint; public T default_value; - + public Option() { } - + public Option( String tag_, String brief_, String hint_, T default_ ) { tag = tag_; @@ -22,12 +22,12 @@ hint = hint_; default_value = default_; } - + } - + public static class OptionFolder extends Option<Void> { public ArrayList<Option<?>> options = new ArrayList<Option<?>>(); - + public OptionFolder( String brief_, String hint_ ) { brief = brief_; @@ -39,14 +39,30 @@ options.add(option); return option; } - + + } + + public static class OptionCategory extends Option<Void> { + + public OptionCategory( String title, String hint_ ) + { + brief = title; + hint = hint_; + } + } - - public static class OptionCategory extends Option<Void> {} - - public static class OptionCheckbox extends Option<Boolean> {} + + public static class OptionCheckbox extends Option<Boolean> { + + public OptionCheckbox( String tag_, String brief_, String hint_, Boolean default_ ) + { + super( tag_, brief_, hint_, default_ ); + } + + } + public static class OptionSlider extends Option<Float> { - + public float minimum = 0.0f; public float maximum = 1.0f; @@ -63,7 +79,7 @@ } public static class OptionNumberCounter extends Option<Integer> { - + public int minimum = 0; public int maximum = 10; public int step = 1; @@ -80,18 +96,26 @@ } } - + public static class OptionString extends Option<String> {} public static class OptionAction extends Option<Void> { + + public OptionAction( String brief_, String hint_ ) + { + brief = brief_; + hint = hint_; + } + void onClick() {} + } - + public OptionFolder root = new OptionFolder( "root", "Root of the options." ); - + public <T extends Option> T add( T option ) { return root.<T>add(option); } - + }
--- a/src/junotu/TabOptions.java Thu Jun 15 00:09:23 2023 +0200 +++ b/src/junotu/TabOptions.java Thu Jun 15 00:53:55 2023 +0200 @@ -15,8 +15,10 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import junotu.Main; import junotu.Window.TabInterface; import junotu.OptionTree; +import junotu.Card; public class TabOptions extends JPanel implements ActionListener, TabInterface { @@ -43,15 +45,15 @@ setLayout( new BoxLayout( this, BoxLayout.X_AXIS ) ); events = events_; folder = folder_; - + JButton button = new JButton( folder.brief ); - + this.add(button); - + if( folder.hint.length() > 0 ) { button.setToolTipText( folder.hint ); } - + button.addActionListener(this); } } @@ -65,12 +67,17 @@ static public final OptionTree OPTION_TREE; static { OPTION_TREE = new OptionTree(); - OPTION_TREE.root = new OptionTree.OptionFolder( "JUnotu", "JUnotu options." ); - + OPTION_TREE.root = new OptionTree.OptionFolder( Main.PROGRAM_NAME, Main.PROGRAM_NAME+" options." ); + OptionTree.OptionFolder f1 = OPTION_TREE.add( new OptionTree.OptionFolder( "1", "Folder one." ) ); OptionTree.OptionFolder f2 = OPTION_TREE.add( new OptionTree.OptionFolder( "2", "Folder two." ) ); OptionTree.OptionFolder f3 = OPTION_TREE.add( new OptionTree.OptionFolder( "3", "Folder three." ) ); - + OptionTree.OptionFolder developer = OPTION_TREE.add( new OptionTree.OptionFolder( + "Development / Internal", + "Development-related options. Be careful, those options were not designed with safety or intutiveness in mind. "+ + "Misusing them could corrupt your card database." + ) ); + f1.add( new OptionTree.OptionFolder( "1.1", "Folder one one." ) ); f1.add( new OptionTree.OptionFolder( "1.2", "Folder one two." ) ); f1.add( new OptionTree.OptionFolder( "1.3", "Folder one three." ) ); @@ -82,6 +89,23 @@ f3.add( new OptionTree.OptionFolder( "3.1", "Folder three one." ) ); f3.add( new OptionTree.OptionFolder( "3.2", "Folder three two." ) ); f3.add( new OptionTree.OptionFolder( "3.3", "Folder three three." ) ); + + developer.add( new OptionTree.OptionCheckbox( + Card.TAG_OPTION_PREFIX+"show_internal_tags", + "Show 'internal' tags.", + "Show tags prefixed with '_', which are normally hidden.", + false + ) ); + + developer.add( new OptionTree.OptionCategory( "Actions", "" ) ); + + developer.add( new OptionTree.OptionAction( + "Resave all cards", + "Go over the whole card database, load each card and save each card. "+ + "Does not update user edit timestamp, meaning card ordering should not change on the search page. "+ + "This might be a useful thing to run after changing "+Main.PROGRAM_NAME+" version (updating or downgrading)." + ) ); + } public Card card; @@ -97,15 +121,15 @@ optionList = Box.createVerticalBox(); JScrollPane scroll = new JScrollPane(optionList); JButton apply = new JButton("Apply"); - + pathBox.setLayout( new FlowLayout( FlowLayout.LEFT ) ); - + add( pathBox, BorderLayout.NORTH ); add( scroll, BorderLayout.CENTER ); add( apply, BorderLayout.SOUTH ); - + path.add( OPTION_TREE.root ); - + scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); } @@ -135,6 +159,9 @@ pathBox.add( button ); button.setActionCommand( ACTION_PATH_BUTTON ); button.addActionListener(this); + if( path.get(i).hint.length() > 0 ) { + button.setToolTipText( path.get(i).hint ); + } } pathBox.add( Box.createHorizontalGlue() );