Skip to content

Commit

Permalink
#472 number fields have now configurable alternative symbols (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaadin-miki authored May 25, 2023
1 parent 536bfe9 commit a1a13ea
Show file tree
Hide file tree
Showing 15 changed files with 698 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.superfields.numbers.AbstractSuperFloatingPointField;

import java.util.Collections;
import java.util.Set;
import java.util.function.Consumer;

/**
Expand All @@ -20,6 +22,10 @@ public class AbstractSuperFloatingPointFieldBuilder implements ContentBuilder<Ab
public void buildContent(AbstractSuperFloatingPointField<?, ?> component, Consumer<Component[]> callback) {
final Checkbox integerPartOptional = new Checkbox("Make integer part optional?");
integerPartOptional.addValueChangeListener(event -> component.setIntegerPartOptional(event.getValue()));
callback.accept(new Component[]{integerPartOptional});

final Checkbox allowDecimalAlternatives = new Checkbox("Allow | and : as decimal separators?");
allowDecimalAlternatives.addValueChangeListener(event -> component.setDecimalSeparatorAlternatives(event.getValue() ? Set.of('|', ':') : Collections.emptySet()));

callback.accept(new Component[]{integerPartOptional, allowDecimalAlternatives});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.superfields.numbers.AbstractSuperNumberField;

import java.util.Collections;
import java.util.Set;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -45,6 +47,16 @@ public void buildContent(AbstractSuperNumberField<?, ?> component, Consumer<Comp
component.removeThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
}
);
callback.accept(new Component[]{autoselect, separatorHidden, prefix, suffix, alignRight});

final Checkbox allowGroupAlternative = new Checkbox("Allow _ as grouping alternative?");
allowGroupAlternative.addValueChangeListener(event -> component.setGroupingSeparatorAlternatives(event.getValue() ? Set.of('_') : Collections.emptySet()));

final Checkbox allowNegativeAlternative = new Checkbox("Allow ^ and # as a negative sign?");
allowNegativeAlternative.addValueChangeListener(event -> component.setNegativeSignAlternatives(event.getValue() ? Set.of('^', '#') : Collections.emptySet()));

final Checkbox disallowAlternatives = new Checkbox("Disallow typing ^ and space?");
disallowAlternatives.addValueChangeListener(event -> component.setKeyboardDisallowedAlternatives(event.getValue() ? Set.of('^', ' ') : Collections.emptySet()));

callback.accept(new Component[]{autoselect, separatorHidden, prefix, suffix, alignRight, allowGroupAlternative, allowNegativeAlternative, disallowAlternatives});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.vaadin.flow.function.SerializablePredicate;

import java.util.Locale;
import java.util.Set;

/**
* Base class for implementations of {@link AbstractSuperNumberField} that allow modifications to minimum and maximum number of fraction digits.
Expand Down Expand Up @@ -100,4 +101,15 @@ public final SELF withIntegerPartRequired() {
public final SELF withIntegerPartOptional() {
return this.withIntegerPartOptional(true);
}

@Override
public Set<Character> getDecimalSeparatorAlternatives() {
return super.getDecimalSeparatorAlternatives();
}

@Override
public void setDecimalSeparatorAlternatives(Set<Character> alternatives) {
super.setDecimalSeparatorAlternatives(alternatives);
}

}
Loading

0 comments on commit a1a13ea

Please sign in to comment.