From 6ca16d07e60aa1a9efdbf4a583f240579df7848e Mon Sep 17 00:00:00 2001 From: bancika Date: Sun, 4 Mar 2012 15:09:12 +0000 Subject: [PATCH] Application breaks when resistance is set to 0 ohms --- .../org/diylc/core/measures/Resistance.java | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Resistance.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Resistance.java index 52b18737..3d2f8716 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Resistance.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Resistance.java @@ -32,36 +32,56 @@ public class Resistance extends AbstractMeasure { public Color[] getColorCode(ResistorColorCode resistorColorCode) { Color[] bands; - double base = getValue() * getUnit().getFactor(); - int multiplier = 0; - while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) { - multiplier += 1; - base /= 10; - } - while (base < (resistorColorCode == ResistorColorCode._4_BAND ? 10 : 100)) { - multiplier -= 1; - base *= 10; - } - if (multiplier > 6 || multiplier < -2) { - // Out of range. - return new Color[] {}; - } - switch (resistorColorCode) { - case _4_BAND: - bands = new Color[3]; - bands[0] = COLOR_DIGITS[(int) (base / 10)]; - bands[1] = COLOR_DIGITS[(int) (base % 10)]; - bands[2] = COLOR_MULTIPLIER[multiplier + 2]; - break; - case _5_BAND: - bands = new Color[4]; - bands[0] = COLOR_DIGITS[(int) (base / 100)]; - bands[1] = COLOR_DIGITS[(int) (base / 10 % 10)]; - bands[2] = COLOR_DIGITS[(int) (base % 10)]; - bands[3] = COLOR_MULTIPLIER[multiplier + 2]; - break; - default: - bands = new Color[] {}; + if (getValue() == 0) { + switch (resistorColorCode) { + case _4_BAND: + bands = new Color[3]; + bands[0] = COLOR_DIGITS[0]; + bands[1] = COLOR_DIGITS[0]; + bands[2] = COLOR_MULTIPLIER[2]; + break; + case _5_BAND: + bands = new Color[4]; + bands[0] = COLOR_DIGITS[0]; + bands[1] = COLOR_DIGITS[0]; + bands[2] = COLOR_DIGITS[0]; + bands[3] = COLOR_MULTIPLIER[2]; + break; + default: + bands = new Color[] {}; + } + } else { + double base = getValue() * getUnit().getFactor(); + int multiplier = 0; + while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) { + multiplier += 1; + base /= 10; + } + while (base < (resistorColorCode == ResistorColorCode._4_BAND ? 10 : 100)) { + multiplier -= 1; + base *= 10; + } + if (multiplier > 6 || multiplier < -2) { + // Out of range. + return new Color[] {}; + } + switch (resistorColorCode) { + case _4_BAND: + bands = new Color[3]; + bands[0] = COLOR_DIGITS[(int) (base / 10)]; + bands[1] = COLOR_DIGITS[(int) (base % 10)]; + bands[2] = COLOR_MULTIPLIER[multiplier + 2]; + break; + case _5_BAND: + bands = new Color[4]; + bands[0] = COLOR_DIGITS[(int) (base / 100)]; + bands[1] = COLOR_DIGITS[(int) (base / 10 % 10)]; + bands[2] = COLOR_DIGITS[(int) (base % 10)]; + bands[3] = COLOR_MULTIPLIER[multiplier + 2]; + break; + default: + bands = new Color[] {}; + } } return bands; }