changeset 74:1d37914defe0

TabEdit: Fixed being able to add multiple tag buttons that represent the same internal tag-value
author Fox
date Sat, 07 Jan 2023 01:12:25 +0100
parents d1faf5db459c
children 85b392e8ba87
files src/junotu/Card.java src/junotu/TabEdit.java
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/junotu/Card.java	Sat Jan 07 00:58:11 2023 +0100
+++ b/src/junotu/Card.java	Sat Jan 07 01:12:25 2023 +0100
@@ -94,8 +94,8 @@
 	tags.put( tag, values );
     }
     
-    /** Adds a value to a tag, if it doesn't contain equal value yet. */
-    public void tagValueAdd( String tag, Object value )
+    /** 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 );
@@ -104,9 +104,9 @@
 	
 	if( values == null ) {
 	    /* Means that key is new to the map, and was added just now. */
-	    return;
+	    return true;
 	} else {
-	    values.add( value );
+	    return values.add( value );
 	}
     }
 
--- a/src/junotu/TabEdit.java	Sat Jan 07 00:58:11 2023 +0100
+++ b/src/junotu/TabEdit.java	Sat Jan 07 01:12:25 2023 +0100
@@ -358,12 +358,16 @@
 	    
 	} else { /* Adding new tag (value). */
 	    if( !newTag.equals("") ) {
-		TagWidget newWidget = new TagWidget( newTag, newValue );
-		card.tagValueAdd( newTag, newValue );
-		tags.add( newWidget, GUIToolbox.componentGetIndex( addTag )-1 );
-		newWidget.addActionListener(this);
-		newWidget.addMouseListener(this);
-		logTagChange( "", null, newTag, newValue );
+		/* Only add new tag button if the tag value is unique. */
+		if( card.tagValueAdd( newTag, newValue ) ) {
+		    TagWidget newWidget = new TagWidget( newTag, newValue );
+		    tags.add( newWidget, GUIToolbox.componentGetIndex( addTag )-1 );
+		    newWidget.addActionListener(this);
+		    newWidget.addMouseListener(this);
+		    logTagChange( "", null, newTag, newValue );
+		} else {
+		    logTagChange( "", null, "", null );
+		}
 	    } else {
 		logTagChange( "", null, "", null );
 	    }