From 45ae3e99a85fc60578ab9c49c3544d7607a3dc44 Mon Sep 17 00:00:00 2001 From: Daniel Gredler Date: Sat, 7 Jul 2018 22:24:16 -0400 Subject: [PATCH] Channel Code: use same terminology as used by other symbologies ("preferred") --- .../java/uk/org/okapibarcode/MakeBarcode.java | 2 +- .../org/okapibarcode/backend/ChannelCode.java | 34 +++++++++++++------ .../java/uk/org/okapibarcode/gui/OkapiUI.java | 2 +- .../channelcode/basic-3-channels.properties | 2 +- .../channelcode/basic-4-channels.properties | 2 +- .../channelcode/basic-5-channels.properties | 2 +- .../channelcode/basic-6-channels.properties | 2 +- .../channelcode/basic-7-channels.properties | 2 +- .../channelcode/basic-8-channels.properties | 2 +- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/uk/org/okapibarcode/MakeBarcode.java b/src/main/java/uk/org/okapibarcode/MakeBarcode.java index d664b259..acd18854 100644 --- a/src/main/java/uk/org/okapibarcode/MakeBarcode.java +++ b/src/main/java/uk/org/okapibarcode/MakeBarcode.java @@ -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; diff --git a/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java b/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java index fca8d32c..cdfd7050 100644 --- a/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java +++ b/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java @@ -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. + *

Implements Channel Code according to ANSI/AIM BC12-1998. + * + *

Channel Code encodes whole integer values between 0 and 7,742,862. * * @author Robin Stuart */ 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 @@ -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); diff --git a/src/main/java/uk/org/okapibarcode/gui/OkapiUI.java b/src/main/java/uk/org/okapibarcode/gui/OkapiUI.java index 1bfe93ed..4023d8c4 100644 --- a/src/main/java/uk/org/okapibarcode/gui/OkapiUI.java +++ b/src/main/java/uk/org/okapibarcode/gui/OkapiUI.java @@ -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); diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels.properties index 6ab4e438..41204b9c 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=3 +preferredNumberOfChannels=3 content=26 LOG diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels.properties index 18626f1a..25228b63 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=4 +preferredNumberOfChannels=4 content=292 LOG diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels.properties index 07ffc9f1..a2aac1b6 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=5 +preferredNumberOfChannels=5 content=3493 LOG diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels.properties index dd10bd57..78d4bbc0 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=6 +preferredNumberOfChannels=6 content=44072 LOG diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels.properties index 0413c920..4c5296d9 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=7 +preferredNumberOfChannels=7 content=576688 LOG diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-8-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-8-channels.properties index 1505c18c..ecdb7f37 100644 --- a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-8-channels.properties +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-8-channels.properties @@ -1,6 +1,6 @@ PROPERTIES -numberOfChannels=8 +preferredNumberOfChannels=8 content=7742862 LOG