refactoring of SingleValueDialog separators, see #637

This commit is contained in:
hneemann 2021-02-04 18:22:31 +01:00
parent 92f44c6523
commit f7a37fc1e8
3 changed files with 20 additions and 33 deletions

View File

@ -140,8 +140,8 @@ public enum IntFormat {
}
@Override
public IsSeparator getSeparators(int bits) {
return bit -> bit % 4 == 0;
public boolean isSeparatorInFrontOf(int bits, int bit) {
return bit % 4 == 0;
}
}
@ -231,8 +231,8 @@ public enum IntFormat {
}
@Override
public IsSeparator getSeparators(int bits) {
return bit -> bit % 4 == 0;
public boolean isSeparatorInFrontOf(int bits, int bit) {
return bit % 4 == 0;
}
}
@ -301,8 +301,8 @@ public enum IntFormat {
}
@Override
public IsSeparator getSeparators(int bits) {
return bit -> bit % 3 == 0;
public boolean isSeparatorInFrontOf(int bits, int bit) {
return bit % 3 == 0;
}
}
@ -465,8 +465,8 @@ public enum IntFormat {
}
@Override
public IsSeparator getSeparators(int bits) {
return bit -> bit == fixedPoint;
public boolean isSeparatorInFrontOf(int bits, int bit) {
return bit == fixedPoint;
}
}
@ -549,14 +549,14 @@ public enum IntFormat {
}
@Override
public IsSeparator getSeparators(int bits) {
public boolean isSeparatorInFrontOf(int bits, int bit) {
switch (bits) {
case 32:
return bit -> bit == 31 || bit == 23;
return bit == 31 || bit == 23;
case 64:
return bit -> bit == 63 || bit == 52;
return bit == 63 || bit == 52;
default:
return HEX_FORMATTER.getSeparators(bits);
return HEX_FORMATTER.isSeparatorInFrontOf(bits, bit);
}
}
}

View File

@ -56,26 +56,13 @@ public interface ValueFormatter {
long dragValue(long initial, int bits, double inc);
/**
* Returns the {@link IsSeparator} interface to place separators in the {@link de.neemann.digital.gui.components.SingleValueDialog}
* Defaults to no separator at all.
* Returns true if there should be a separator in front of the given bit.
*
* @param bits the number of bits used
* @return the IsSeparator instance
* @param bits the number of bits in the value to format
* @param bit the bit in question
* @return true if there should be a separator in front of the given bit.
*/
default IsSeparator getSeparators(int bits) {
return bit -> false;
}
/**
* Interface to define separators
*/
interface IsSeparator {
/**
* Returns true if there should be a separator in front of the given bit.
*
* @param bit the bit in question
* @return true if there should be a separator in front of the given bit.
*/
boolean isSeparatorInFrontOf(int bit);
default boolean isSeparatorInFrontOf(int bits, int bit) {
return false;
}
}

View File

@ -244,9 +244,9 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
}
private void updateSeparators() {
ValueFormatter.IsSeparator s = valueFormatter.getSeparators(editValue.getBits());
int bits = editValue.getBits();
for (int i = 1; i < checkBoxes.length; i++) {
if (s.isSeparatorInFrontOf(i))
if (valueFormatter.isSeparatorInFrontOf(bits, i))
checkBoxes[i].setBorder(SEPARATOR);
else
checkBoxes[i].setBorder(null);