|
|
@@ -18,7 +18,6 @@ import java.awt.GridBagLayout;
|
|
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
import java.awt.Insets;
|
|
|
-import java.util.List;
|
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JTextPane;
|
|
|
@@ -29,7 +28,7 @@ import javax.swing.JFormattedTextField;
|
|
|
import java.awt.Dimension;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
-@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE)
|
|
|
public class StepPanel extends JPanel implements AutoGrowPanel.ChildComponent {
|
|
|
ForwardingObservableListener<Step> listener = new ForwardingObservableListener<>();
|
|
|
ObservableListener<JTextPane, Step> intructionListener;
|
|
|
@@ -39,7 +38,7 @@ public class StepPanel extends JPanel implements AutoGrowPanel.ChildComponent {
|
|
|
@Getter(AccessLevel.PACKAGE) JTextPane txtpnInstructions;
|
|
|
@Getter(AccessLevel.PACKAGE) AutoGrowPanel<IngredientPanel, Ingredient> panelIngredients;
|
|
|
|
|
|
- public StepPanel(final Step step) {
|
|
|
+ public StepPanel() {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
@@ -82,7 +81,6 @@ public class StepPanel extends JPanel implements AutoGrowPanel.ChildComponent {
|
|
|
gbc_panelDuration.gridy = 0;
|
|
|
panelLeft.add(panelDuration, gbc_panelDuration);
|
|
|
|
|
|
- final List<Ingredient> ingredients = step.getIngredients();
|
|
|
panelIngredients = new AutoGrowPanel<>(Ingredient::new, IngredientPanel::new);
|
|
|
GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
|
|
|
gbc_panelIngredients.gridwidth = 3;
|
|
|
@@ -105,21 +103,25 @@ public class StepPanel extends JPanel implements AutoGrowPanel.ChildComponent {
|
|
|
durationListener = ObservableController.from(panelDuration.txtTime,
|
|
|
Step::getDuration, Step::setDuration);
|
|
|
|
|
|
+ setListPosition(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public StepPanel(final Step step) {
|
|
|
+ this();
|
|
|
+ setModel(step);
|
|
|
+ }
|
|
|
+
|
|
|
+ void setModel(final Step step) {
|
|
|
panelIngredients.setModel(step.getIngredients(), added -> {
|
|
|
listener.setObserved(step, step.getIngredients());
|
|
|
if (!added) {
|
|
|
ObserverDispatch.notifySubscribers(step);
|
|
|
}
|
|
|
});
|
|
|
- listener.setObserved(step, ingredients);
|
|
|
+ listener.setObserved(step, step.getIngredients());
|
|
|
intructionListener.setObserved(step);
|
|
|
durationListener.setObserved(step);
|
|
|
}
|
|
|
-
|
|
|
- public StepPanel(int zeroIndex, Step step) {
|
|
|
- this(step);
|
|
|
- setListPosition(zeroIndex);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void removeNotify() {
|