Skip to content

Commit

Permalink
Channel Code: use same terminology as used by other symbologies ("pre…
Browse files Browse the repository at this point in the history
…ferred")
  • Loading branch information
gredler committed Jul 8, 2018
1 parent 354fc5a commit 45ae3e9
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/uk/org/okapibarcode/MakeBarcode.java
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ public void process(Settings settings, String dataInput, String outputFileName)
case 140:
// Channel Code
ChannelCode channelCode = new ChannelCode();
channelCode.setNumberOfChannels(settings.getSymbolColumns());
channelCode.setPreferredNumberOfChannels(settings.getSymbolColumns());
channelCode.setHumanReadableLocation(hrtLocation);
channelCode.setContent(dataInput);
symbol = channelCode;
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/uk/org/okapibarcode/backend/ChannelCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,41 @@
package uk.org.okapibarcode.backend;

/**
* Implements Channel Code according to ANSI/AIM BC12-1998. Channel code encodes whole integer values
* between 0 and 7,742,862.
* <p>Implements Channel Code according to ANSI/AIM BC12-1998.
*
* <p>Channel Code encodes whole integer values between 0 and 7,742,862.
*
* @author <a href="mailto:rstuart114@gmail.com">Robin Stuart</a>
*/
public class ChannelCode extends Symbol {

private int preferredNumberOfChannels;

private int[] space = new int[11];
private int[] bar = new int[11];
private double currentValue;
private double targetValue;
private int requestedNumberOfChannels;

/**
* Sets the number of channels used to encode data. This setting will be ignored if the value to be
* encoded requires more channels.
* Sets the preferred number of channels used to encode data. This setting will be
* ignored if the value to be encoded requires more channels.
*
* @param channels number of channels (between 3 and 8, inclusive)
* @param channels the preferred number of channels (3 to 8, inclusive)
*/
public void setNumberOfChannels(int channels) {
if (channels >= 3 && channels <= 8) {
requestedNumberOfChannels = channels;
public void setPreferredNumberOfChannels(int channels) {
if (channels < 3 || channels > 8) {
throw new IllegalArgumentException("Invalid Channel Code number of channels: " + channels);
}
preferredNumberOfChannels = channels;
}

/**
* Returns the preferred number of channels used to encode data.
*
* @return the preferred number of channels used to encode data
*/
public int getPreferredNumberOfChannels() {
return preferredNumberOfChannels;
}

@Override
Expand All @@ -56,10 +68,10 @@ protected void encode() {
throw new OkapiException("Invalid characters in input");
}

if (requestedNumberOfChannels <= 2 || requestedNumberOfChannels > 8) {
if (preferredNumberOfChannels <= 2 || preferredNumberOfChannels > 8) {
channels = 3;
} else {
channels = requestedNumberOfChannels;
channels = preferredNumberOfChannels;
}

targetValue = Integer.parseInt(content);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/org/okapibarcode/gui/OkapiUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,7 @@ private Symbol getNewSymbol() throws OkapiException {
return auRedirect;
case CHANNEL_CODE:
ChannelCode channelCode = new ChannelCode();
channelCode.setNumberOfChannels(channelChannelsCombo.getSelectedIndex() + 2);
channelCode.setPreferredNumberOfChannels(channelChannelsCombo.getSelectedIndex() + 2);
channelCode.setHumanReadableLocation(hrtLoc);
channelCode.setContent(dataInput);
setUniversals(channelCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=3
preferredNumberOfChannels=3
content=26

LOG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=4
preferredNumberOfChannels=4
content=292

LOG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=5
preferredNumberOfChannels=5
content=3493

LOG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=6
preferredNumberOfChannels=6
content=44072

LOG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=7
preferredNumberOfChannels=7
content=576688

LOG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROPERTIES

numberOfChannels=8
preferredNumberOfChannels=8
content=7742862

LOG
Expand Down

0 comments on commit 45ae3e9

Please sign in to comment.