package ru.nsu.ccfit.bogush.view;

import ru.nsu.ccfit.bogush.CarFactoryModel;
import ru.nsu.ccfit.bogush.factory.Supplier;
import ru.nsu.ccfit.bogush.factory.store.CarDealer;

import javax.swing.*;

public class ControlPanel extends JPanel {
	public LabeledSliderWithTextField enginePeriod;
	public LabeledSliderWithTextField bodyPeriod;
	public LabeledSliderWithTextField accessoriesPeriod;
	public LabeledSliderWithTextField dealersPeriod;
	private JPanel panel;

	private static final String ENGINE_PERIOD_LABEL_TEXT = "Engine Supplier Period";
	private static final String BODY_PERIOD_LABEL_TEXT = "Body Supplier Period";
	private static final String ACCESSORIES_PERIOD_LABEL_TEXT = "Accessories Supplier Period";
	private static final String DEALERS_PERIOD_LABEL_TEXT = "Dealers Supplier Period";
	private static final int MIN_PERIOD = 0;

	private static final int MAX_PERIOD = 10000;
	private static final int INITIAL_PERIOD = 1;
	private static final int INTERVAL = 1;

	private CarFactoryModel model;

	public ControlPanel(CarFactoryModel model) {
		this.model = model;
	}

	private void createUIComponents() {
		enginePeriod = new LabeledSliderWithTextField(ENGINE_PERIOD_LABEL_TEXT, MIN_PERIOD, MAX_PERIOD, INTERVAL);
		bodyPeriod = new LabeledSliderWithTextField(BODY_PERIOD_LABEL_TEXT, MIN_PERIOD, MAX_PERIOD, INTERVAL);
		accessoriesPeriod = new LabeledSliderWithTextField(ACCESSORIES_PERIOD_LABEL_TEXT, MIN_PERIOD, MAX_PERIOD, INTERVAL);
		dealersPeriod = new LabeledSliderWithTextField(DEALERS_PERIOD_LABEL_TEXT, MIN_PERIOD, MAX_PERIOD, INTERVAL);

		enginePeriod.setValue(INITIAL_PERIOD);
		bodyPeriod.setValue(INITIAL_PERIOD);
		accessoriesPeriod.setValue(INITIAL_PERIOD);
		dealersPeriod.setValue(INITIAL_PERIOD);

		enginePeriod.addListener(value -> model.getEngineSupplier().setPeriod(value));

		bodyPeriod.addListener(value -> model.getBodySupplier().setPeriod(value));

		accessoriesPeriod.addListener(value -> {
			for (Supplier supplier: model.getAccessorySuppliers())
				supplier.setPeriod(value);
		});

		dealersPeriod.addListener(value -> {
			for (CarDealer dealer: model.getDealers()) {
				dealer.setPeriod(value);
			}
		});
	}
}

@@ -120,60 +120,8 @@
 ier;
-%0Aimport ru.nsu.ccfit.bogush.factory.store.CarDealer;
 %0A%0Aim
@@ -876,17 +876,17 @@
 ERIOD = 
-1
+0
 ;%0A%09priva
@@ -1517,32 +1517,39 @@
 enginePeriod.set
+TextAnd
 Value(INITIAL_PE
@@ -1563,32 +1563,39 @@
 %09%09bodyPeriod.set
+TextAnd
 Value(INITIAL_PE
@@ -1616,32 +1616,39 @@
 soriesPeriod.set
+TextAnd
 Value(INITIAL_PE
@@ -1673,16 +1673,23 @@
 riod.set
+TextAnd
 Value(IN
@@ -2049,44 +2049,280 @@
 %0A%09%09%09
-for (CarDealer dealer: model.getDeal
+model.getStore().setPeriod(value);%0A%09%09%7D);%0A%0A%09%09model.getStore().setPeriod(dealersPeriod.getValue());%0A%09%09model.getBodySupplier().setPeriod(bodyPeriod.getValue());%0A%09%09model.getEngineSupplier().setPeriod(enginePeriod.getValue());%0A%09%09for (Supplier supplier: model.getAccessorySuppli
 ers(
@@ -2329,21 +2329,22 @@
 )) %7B%0A%09%09%09
-%09deal
+suppli
 er.setPe
@@ -2352,26 +2352,37 @@
 iod(
-v
+enginePeriod.getV
 alue
+()
 );%0A%09%09
-%09%7D%0A%09%09%7D);
+%7D
 %0A%09%7D%0A

Change initial period to 0 Initialize model with initial periods