mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -04:00
refactoring of SingleValueDialog separators, see #637
This commit is contained in:
parent
92f44c6523
commit
f7a37fc1e8
@ -140,8 +140,8 @@ public enum IntFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IsSeparator getSeparators(int bits) {
|
public boolean isSeparatorInFrontOf(int bits, int bit) {
|
||||||
return bit -> bit % 4 == 0;
|
return bit % 4 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,8 +231,8 @@ public enum IntFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IsSeparator getSeparators(int bits) {
|
public boolean isSeparatorInFrontOf(int bits, int bit) {
|
||||||
return bit -> bit % 4 == 0;
|
return bit % 4 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,8 +301,8 @@ public enum IntFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IsSeparator getSeparators(int bits) {
|
public boolean isSeparatorInFrontOf(int bits, int bit) {
|
||||||
return bit -> bit % 3 == 0;
|
return bit % 3 == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,8 +465,8 @@ public enum IntFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IsSeparator getSeparators(int bits) {
|
public boolean isSeparatorInFrontOf(int bits, int bit) {
|
||||||
return bit -> bit == fixedPoint;
|
return bit == fixedPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,14 +549,14 @@ public enum IntFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IsSeparator getSeparators(int bits) {
|
public boolean isSeparatorInFrontOf(int bits, int bit) {
|
||||||
switch (bits) {
|
switch (bits) {
|
||||||
case 32:
|
case 32:
|
||||||
return bit -> bit == 31 || bit == 23;
|
return bit == 31 || bit == 23;
|
||||||
case 64:
|
case 64:
|
||||||
return bit -> bit == 63 || bit == 52;
|
return bit == 63 || bit == 52;
|
||||||
default:
|
default:
|
||||||
return HEX_FORMATTER.getSeparators(bits);
|
return HEX_FORMATTER.isSeparatorInFrontOf(bits, bit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,27 +55,14 @@ public interface ValueFormatter {
|
|||||||
*/
|
*/
|
||||||
long dragValue(long initial, int bits, double inc);
|
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.
|
|
||||||
*
|
|
||||||
* @param bits the number of bits used
|
|
||||||
* @return the IsSeparator instance
|
|
||||||
*/
|
|
||||||
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.
|
* Returns true if there should be a separator in front of the given bit.
|
||||||
*
|
*
|
||||||
|
* @param bits the number of bits in the value to format
|
||||||
* @param bit the bit in question
|
* @param bit the bit in question
|
||||||
* @return true if there should be a separator in front of the given bit.
|
* @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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,9 +244,9 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSeparators() {
|
private void updateSeparators() {
|
||||||
ValueFormatter.IsSeparator s = valueFormatter.getSeparators(editValue.getBits());
|
int bits = editValue.getBits();
|
||||||
for (int i = 1; i < checkBoxes.length; i++) {
|
for (int i = 1; i < checkBoxes.length; i++) {
|
||||||
if (s.isSeparatorInFrontOf(i))
|
if (valueFormatter.isSeparatorInFrontOf(bits, i))
|
||||||
checkBoxes[i].setBorder(SEPARATOR);
|
checkBoxes[i].setBorder(SEPARATOR);
|
||||||
else
|
else
|
||||||
checkBoxes[i].setBorder(null);
|
checkBoxes[i].setBorder(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user