Bulb default OFF color
This commit is contained in:
parent
3825c41bc4
commit
7ae8a35e0c
@ -6,6 +6,8 @@ import static java.lang.Math.round;
|
||||
|
||||
public class CONFIG {
|
||||
|
||||
public static final double BULB_VOLTAGE_MIN = 0.5;
|
||||
|
||||
public static final double VOLTAGE = 3.0;
|
||||
|
||||
public static final int RASTER = 200;
|
||||
|
||||
@ -26,7 +26,6 @@ public class Window extends JFrame {
|
||||
|
||||
final JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sidebar, circuitPanel);
|
||||
splitter.setDividerLocation(calcWidth(3));
|
||||
splitter.setResizeWeight(0.3);
|
||||
add(splitter);
|
||||
|
||||
pack();
|
||||
|
||||
@ -36,8 +36,8 @@ public class Circuit {
|
||||
return battery;
|
||||
}
|
||||
|
||||
public PartLight addLight(final String name, final int x, final int y, final Orientation orientation, final double maxVoltage) {
|
||||
final PartLight light = new PartLight(name, new Point(x, y), orientation, maxVoltage);
|
||||
public PartLight addLight(final String name, final int x, final int y, final Orientation orientation, final double minVoltage, final double maxVoltage) {
|
||||
final PartLight light = new PartLight(name, new Point(x, y), orientation, minVoltage, maxVoltage);
|
||||
partAdd(light);
|
||||
return light;
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ public class PartLightDto extends PartDto {
|
||||
|
||||
private JunctionDto minus;
|
||||
|
||||
private double minVoltage;
|
||||
|
||||
private double maxVoltage;
|
||||
|
||||
private boolean defect;
|
||||
@ -23,6 +25,7 @@ public class PartLightDto extends PartDto {
|
||||
this.plus = new JunctionDto(partLight.getPin1());
|
||||
this.minus = new JunctionDto(partLight.getPin0());
|
||||
this.defect = partLight.isDefect();
|
||||
this.minVoltage = partLight.getMinVoltage();
|
||||
this.maxVoltage = partLight.getMaxVoltage();
|
||||
}
|
||||
|
||||
|
||||
@ -31,33 +31,39 @@ public class PartLight extends PartOther {
|
||||
|
||||
private static final int BULB_RADIUS = (int) round(0.25 * RASTER);
|
||||
|
||||
public static final Color BULB_OFF_COLOR = Color.DARK_GRAY;
|
||||
|
||||
private final Junction pin0;
|
||||
|
||||
private final Junction pin1;
|
||||
|
||||
private final double minVoltage;
|
||||
|
||||
private final double maxVoltage;
|
||||
|
||||
private boolean defect = false;
|
||||
|
||||
private double voltage = 0;
|
||||
|
||||
private Color color;
|
||||
private Color color = BULB_OFF_COLOR;
|
||||
|
||||
public PartLight(final Point position) {
|
||||
this("Licht", position, Orientation.R0, VOLTAGE);
|
||||
this("Licht", position, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
}
|
||||
|
||||
public PartLight(final String name, final Point position, final Orientation orientation, final double maxVoltage) {
|
||||
public PartLight(final String name, final Point position, final Orientation orientation, final double minVoltage, final double maxVoltage) {
|
||||
super(name, position, orientation);
|
||||
this.minVoltage = minVoltage;
|
||||
this.maxVoltage = maxVoltage;
|
||||
pin0 = newJunction(this, "", JUNCTION_LEFT, HALF);
|
||||
pin1 = newJunction(this, "", JUNCTION_RIGHT, HALF);
|
||||
this.maxVoltage = maxVoltage;
|
||||
}
|
||||
|
||||
public PartLight(final PartLightDto dto) {
|
||||
super(dto);
|
||||
pin0 = newJunction(this, dto.getMinus(), JUNCTION_LEFT, HALF);
|
||||
pin1 = newJunction(this, dto.getPlus(), JUNCTION_RIGHT, HALF);
|
||||
minVoltage = dto.getMinVoltage();
|
||||
maxVoltage = dto.getMaxVoltage();
|
||||
defect = dto.isDefect();
|
||||
}
|
||||
@ -73,7 +79,7 @@ public class PartLight extends PartOther {
|
||||
} else {
|
||||
final int v = (int) round(voltage / maxVoltage * 255);
|
||||
if (v < 10) {
|
||||
color = Color.DARK_GRAY;
|
||||
color = BULB_OFF_COLOR;
|
||||
} else {
|
||||
color = new Color(v, v, 0);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import de.ph87.electro.circuit.Circuit;
|
||||
import de.ph87.electro.circuit.part.Orientation;
|
||||
import de.ph87.electro.circuit.part.impl.*;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static de.ph87.electro.CONFIG.VOLTAGE;
|
||||
|
||||
public class DemoAll {
|
||||
@ -13,7 +14,7 @@ public class DemoAll {
|
||||
|
||||
final PartBattery battery = circuit.addBattery("Batterie", 0, 0, Orientation.R2, VOLTAGE);
|
||||
final PartSwitch1x1 switcher = circuit.addSwitch1x1("Ausschalter", 2, 0, Orientation.R0, false);
|
||||
final PartLight light = circuit.addLight("Licht", 4, 0, Orientation.R0, VOLTAGE);
|
||||
final PartLight light = circuit.addLight("Licht", 4, 0, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 0, 2, Orientation.R0, false);
|
||||
final PartSwitchCross switcherX = circuit.addSwitchCross("Kreuzschalter", 2, 2, Orientation.R0, false);
|
||||
final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 4, 2, Orientation.R2, true);
|
||||
@ -35,8 +36,8 @@ public class DemoAll {
|
||||
final Circuit circuit = new Circuit();
|
||||
|
||||
final PartBattery battery = circuit.addBattery("Batterie", 2, 0, Orientation.R1, VOLTAGE);
|
||||
final PartLight light0 = circuit.addLight("Licht 0", 4, 2, Orientation.R1, VOLTAGE);
|
||||
final PartLight light1 = circuit.addLight("Licht 1", 0, 2, Orientation.R1, VOLTAGE);
|
||||
final PartLight light0 = circuit.addLight("Licht 0", 4, 2, Orientation.R1, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
final PartLight light1 = circuit.addLight("Licht 1", 0, 2, Orientation.R1, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
final PartSwitch1x2 switcher0 = circuit.addSwitch1x2("Wechselschalter 0", 2, 2, Orientation.R1, false);
|
||||
|
||||
circuit.connect(battery.getMinus(), light0.getPin0());
|
||||
|
||||
@ -6,6 +6,7 @@ import de.ph87.electro.circuit.part.impl.PartLight;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -17,7 +18,7 @@ public class BatteryLightTest {
|
||||
|
||||
private static final PartBattery battery = circuit.addBattery("Batterie", 1, 0, Orientation.R0, VOLTAGE);
|
||||
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
|
||||
@ -7,6 +7,7 @@ import de.ph87.electro.circuit.part.impl.PartSwitch1x1;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -20,7 +21,7 @@ public class BatterySwitcher1x1Test {
|
||||
|
||||
private static final PartSwitch1x1 switcher = circuit.addSwitch1x1("Ein-/Ausschalter", 0, 1, Orientation.R0, false);
|
||||
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
|
||||
@ -7,6 +7,7 @@ import de.ph87.electro.circuit.part.impl.PartSwitch1x2;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -20,9 +21,9 @@ public class BatterySwitcher1x2Test {
|
||||
|
||||
private static final PartSwitch1x2 switcher = circuit.addSwitch1x2("Wechselschalter", 0, 2, Orientation.R0, false);
|
||||
|
||||
private static final PartLight light0 = circuit.addLight("Licht 0", 1, 1, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light0 = circuit.addLight("Licht 0", 1, 1, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
private static final PartLight light1 = circuit.addLight("Licht 1", 1, 3, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light1 = circuit.addLight("Licht 1", 1, 3, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
|
||||
@ -7,6 +7,7 @@ import de.ph87.electro.circuit.part.impl.PartSwitch1x2;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -22,7 +23,7 @@ public class BatterySwitcher2x2Test {
|
||||
|
||||
private static final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 1, 1, Orientation.R0, false);
|
||||
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 0, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 1, 0, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
|
||||
@ -8,6 +8,7 @@ import de.ph87.electro.circuit.part.impl.PartSwitchCross;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@ -25,7 +26,7 @@ public class BatterySwitcherCrossTest {
|
||||
|
||||
private static final PartSwitch1x2 switcher1 = circuit.addSwitch1x2("Wechselschalter 1", 2, 1, Orientation.R0, false);
|
||||
|
||||
private static final PartLight light = circuit.addLight("Licht", 2, 0, Orientation.R0, VOLTAGE);
|
||||
private static final PartLight light = circuit.addLight("Licht", 2, 0, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
|
||||
@ -12,6 +12,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static de.ph87.electro.CONFIG.BULB_VOLTAGE_MIN;
|
||||
import static de.ph87.electro.CONFIG.VOLTAGE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ -21,7 +22,7 @@ class CircuitServiceTest {
|
||||
void serialization() throws IOException {
|
||||
final Circuit circuit = new Circuit();
|
||||
final PartBattery battery = circuit.addBattery("Batterie", 1, 0, Orientation.R1, VOLTAGE);
|
||||
final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, VOLTAGE);
|
||||
final PartLight light = circuit.addLight("Licht", 1, 1, Orientation.R0, BULB_VOLTAGE_MIN, VOLTAGE);
|
||||
circuit.connect(battery.getPlus(), light.getPin1());
|
||||
circuit.connect(light.getPin0(), battery.getMinus());
|
||||
check(circuit);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user