Changeset 363


Ignore:
Timestamp:
Apr 10, 2012, 5:17:01 PM (5 years ago)
Author:
tim.te.beek@…
Message:

Do not allow user to select other option directly
When other option is selected and document is null or empty, return ',' instead from getCharacter
NonEmptySingleCharacterFilter? was not needed anymore

Location:
branches/alttableimport-model-rewrite/src/main/java/nl/nbic/brs/alttableimport/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alttableimport-model-rewrite/src/main/java/nl/nbic/brs/alttableimport/models/DelimiterModel.java

    r362 r363  
    1212import javax.swing.event.ChangeEvent;
    1313import javax.swing.event.ChangeListener;
    14 import javax.swing.text.BadLocationException;
    1514
    1615import lombok.AccessLevel;
     
    2726        DelimiterButtonModel    spaceButtonModel                = new DelimiterButtonModel(' ');
    2827
    29         SingleCharacterDocument otherDocument                   = new SingleCharacterDocument(new NonEmptySingleCharacterFilter());
     28        SingleCharacterDocument otherDocument                   = new SingleCharacterDocument();
    3029        // A cheeky override so we can call getDelimiter on any delimiter group selection
    3130        ButtonModel                             otherButtonModel                = new DelimiterButtonModel('\0') {
     
    4342                spaceButtonModel.setGroup(delimiterButtonGroup);
    4443                otherButtonModel.setGroup(delimiterButtonGroup);
     44                otherButtonModel.setEnabled(false);
    4545
    4646                // Make comma the default delimiter
     
    100100        }
    101101
    102         public Character getCharacter() {
     102        public char getCharacter() {
    103103                DelimiterButtonModel selection = (DelimiterButtonModel) delimiterButtonGroup.getSelection();
    104                 return selection.getDelimiter();
     104                Character delimiter = selection.getDelimiter();
     105                // Prevent NPE in converting from Character to char when otherButtonModel is selected and otherDocument is empty
     106                return delimiter == null ? ',' : delimiter;
    105107        }
    106108
     
    139141        }
    140142
    141         /**
    142          * Do not allow null or empty text to pass through this filter.
    143          */
    144         class NonEmptySingleCharacterFilter extends SingleCharacterFilter {
    145                 @Override
    146                 public void retainLast(final FilterBypass fb, final String text) throws BadLocationException {
    147                         // In this case text removal should not yet trigger anything: But do we really need this anymore?
    148                         if (text != null && !text.isEmpty())
    149                                 super.retainLast(fb, text);
    150                 }
    151         }
    152 
    153143        public static class DelimiterButtonModel extends ToggleButtonModel {
    154144                @Getter
  • branches/alttableimport-model-rewrite/src/main/java/nl/nbic/brs/alttableimport/models/SingleCharacterDocument.java

    r358 r363  
    99public class SingleCharacterDocument extends PlainDocument {
    1010        public SingleCharacterDocument() {
    11                 this(new SingleCharacterFilter());
    12         }
    13 
    14         public SingleCharacterDocument(final DocumentFilter filter) {
    15                 setDocumentFilter(filter);
     11                setDocumentFilter(new SingleCharacterFilter());
    1612        }
    1713
Note: See TracChangeset for help on using the changeset viewer.