|
@@ -11,6 +11,8 @@ import java.util.Locale;
|
|
|
import javax.swing.event.DocumentListener;
|
|
import javax.swing.event.DocumentListener;
|
|
|
import javax.swing.text.NumberFormatter;
|
|
import javax.swing.text.NumberFormatter;
|
|
|
|
|
|
|
|
|
|
+import org.leumasjaffe.observer.ObservableController;
|
|
|
|
|
+import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
|
|
|
|
|
import javax.swing.JFormattedTextField;
|
|
import javax.swing.JFormattedTextField;
|
|
@@ -19,10 +21,9 @@ import javax.swing.JLabel;
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
@SuppressWarnings("serial")
|
|
|
public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentListenable {
|
|
public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentListenable {
|
|
|
|
|
+ ObservableController<JTextField, Ingredient> controller;
|
|
|
private JTextField txtName;
|
|
private JTextField txtName;
|
|
|
- private JTextField txtUnit;
|
|
|
|
|
- private JTextField txtPreparation;
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public IngredientPanel(final Ingredient ingredient) {
|
|
public IngredientPanel(final Ingredient ingredient) {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
|
@@ -63,7 +64,7 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
|
|
|
add(txtAmount, gbc_txtAmount);
|
|
add(txtAmount, gbc_txtAmount);
|
|
|
txtAmount.setColumns(4);
|
|
txtAmount.setColumns(4);
|
|
|
|
|
|
|
|
- txtUnit = new JTextField(ingredient.getAmount().unitName());
|
|
|
|
|
|
|
+ JTextField txtUnit = new JTextField(ingredient.getAmount().unitName());
|
|
|
txtUnit.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
txtUnit.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
GridBagConstraints gbc_txtUnit = new GridBagConstraints();
|
|
GridBagConstraints gbc_txtUnit = new GridBagConstraints();
|
|
|
gbc_txtUnit.insets = new Insets(0, 0, 0, 5);
|
|
gbc_txtUnit.insets = new Insets(0, 0, 0, 5);
|
|
@@ -74,7 +75,7 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
|
|
|
add(txtUnit, gbc_txtUnit);
|
|
add(txtUnit, gbc_txtUnit);
|
|
|
txtUnit.setColumns(6);
|
|
txtUnit.setColumns(6);
|
|
|
|
|
|
|
|
- txtPreparation = new JTextField(ingredient.getPreparation());
|
|
|
|
|
|
|
+ JTextField txtPreparation = new JTextField(ingredient.getPreparation());
|
|
|
txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
|
|
GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
|
|
|
gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
|
|
gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
|
|
@@ -83,6 +84,13 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
|
|
|
gbc_txtPreparation.gridy = 0;
|
|
gbc_txtPreparation.gridy = 0;
|
|
|
add(txtPreparation, gbc_txtPreparation);
|
|
add(txtPreparation, gbc_txtPreparation);
|
|
|
txtPreparation.setColumns(10);
|
|
txtPreparation.setColumns(10);
|
|
|
|
|
+
|
|
|
|
|
+ // I technically don't need to listen here as of this change,
|
|
|
|
|
+ // but if I ever restore support for it, it will be convenient.
|
|
|
|
|
+ controller = new ObservableController<>(txtName,
|
|
|
|
|
+ Ingredient::getName, Ingredient::setName,
|
|
|
|
|
+ JTextField::setText);
|
|
|
|
|
+ controller.setObserved(ingredient);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -94,5 +102,11 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
|
|
|
public void removeDocumentListener(DocumentListener dl) {
|
|
public void removeDocumentListener(DocumentListener dl) {
|
|
|
this.txtName.getDocument().removeDocumentListener(dl);
|
|
this.txtName.getDocument().removeDocumentListener(dl);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void removeNotify() {
|
|
|
|
|
+ super.removeNotify();
|
|
|
|
|
+ ObserverDispatch.unsubscribeAll(controller);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|