Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#472 number fields have now configurable alternative symbols #475

Merged
merged 6 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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