|
|
@@ -5,14 +5,11 @@ import java.awt.GridBagLayout;
|
|
|
import javax.swing.JTextField;
|
|
|
import java.awt.GridBagConstraints;
|
|
|
import java.awt.Insets;
|
|
|
-import java.text.NumberFormat;
|
|
|
-import java.util.Locale;
|
|
|
-
|
|
|
-import javax.swing.text.NumberFormatter;
|
|
|
|
|
|
import org.leumasjaffe.observer.ObservableListener;
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
import org.leumasjaffe.recipe.model.Ingredient;
|
|
|
+import org.leumasjaffe.recipe.view.formatter.AmountFormatter;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
import lombok.Getter;
|
|
|
@@ -29,14 +26,13 @@ public class IngredientPreparationPanel extends JPanel {
|
|
|
ObservableListener<IngredientPreparationPanel, Ingredient> listener;
|
|
|
@Getter(AccessLevel.PACKAGE) JTextField txtName;
|
|
|
@Getter(AccessLevel.PACKAGE) JFormattedTextField txtAmount;
|
|
|
- @Getter(AccessLevel.PACKAGE) JTextField txtUnit;
|
|
|
@Getter(AccessLevel.PACKAGE) JTextField txtPreparation;
|
|
|
|
|
|
- public IngredientPreparationPanel(final Ingredient ingredient) {
|
|
|
+ public IngredientPreparationPanel() {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
- gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
|
|
+ gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
- gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
|
+ gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
|
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
|
|
|
|
@@ -48,7 +44,7 @@ public class IngredientPreparationPanel extends JPanel {
|
|
|
gbc_label.gridy = 0;
|
|
|
add(label, gbc_label);
|
|
|
|
|
|
- txtName = new JTextField(ingredient.getName());
|
|
|
+ txtName = new JTextField();
|
|
|
txtName.setEditable(false);
|
|
|
txtName.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
GridBagConstraints gbc_txtName = new GridBagConstraints();
|
|
|
@@ -59,12 +55,8 @@ public class IngredientPreparationPanel extends JPanel {
|
|
|
add(txtName, gbc_txtName);
|
|
|
txtName.setColumns(10);
|
|
|
|
|
|
- NumberFormatter fmtDone = new NumberFormatter(NumberFormat.getNumberInstance(Locale.getDefault()));
|
|
|
- fmtDone.setMinimum(0.0);
|
|
|
- fmtDone.setCommitsOnValidEdit(true);
|
|
|
- txtAmount = new JFormattedTextField(fmtDone);
|
|
|
+ txtAmount = new JFormattedTextField(new AmountFormatter());
|
|
|
txtAmount.setEditable(false);
|
|
|
- txtAmount.setValue(ingredient.getAmount().getValue());
|
|
|
txtAmount.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
GridBagConstraints gbc_txtAmount = new GridBagConstraints();
|
|
|
gbc_txtAmount.fill = GridBagConstraints.HORIZONTAL;
|
|
|
@@ -72,37 +64,32 @@ public class IngredientPreparationPanel extends JPanel {
|
|
|
gbc_txtAmount.gridx = 2;
|
|
|
gbc_txtAmount.gridy = 0;
|
|
|
add(txtAmount, gbc_txtAmount);
|
|
|
- txtAmount.setColumns(4);
|
|
|
+ txtAmount.setColumns(11);
|
|
|
|
|
|
- txtUnit = new JTextField(ingredient.getAmount().unitName());
|
|
|
- txtUnit.setEditable(false);
|
|
|
- txtUnit.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
- GridBagConstraints gbc_txtUnit = new GridBagConstraints();
|
|
|
- gbc_txtUnit.insets = new Insets(0, 0, 0, 5);
|
|
|
- gbc_txtUnit.anchor = GridBagConstraints.ABOVE_BASELINE;
|
|
|
- gbc_txtUnit.fill = GridBagConstraints.HORIZONTAL;
|
|
|
- gbc_txtUnit.gridx = 3;
|
|
|
- gbc_txtUnit.gridy = 0;
|
|
|
- add(txtUnit, gbc_txtUnit);
|
|
|
- txtUnit.setColumns(6);
|
|
|
-
|
|
|
- txtPreparation = new JTextField(ingredient.getPreparation());
|
|
|
+ txtPreparation = new JTextField();
|
|
|
txtPreparation.setEditable(false);
|
|
|
txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
|
|
|
GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
|
|
|
gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
|
|
|
gbc_txtPreparation.fill = GridBagConstraints.HORIZONTAL;
|
|
|
- gbc_txtPreparation.gridx = 4;
|
|
|
+ gbc_txtPreparation.gridx = 3;
|
|
|
gbc_txtPreparation.gridy = 0;
|
|
|
add(txtPreparation, gbc_txtPreparation);
|
|
|
txtPreparation.setColumns(10);
|
|
|
|
|
|
- listener = new ObservableListener<>(this, (c, t) -> {
|
|
|
- txtName.setText(t.getName());
|
|
|
- txtAmount.setValue(t.getAmount().getValue());
|
|
|
- txtUnit.setText(t.getAmount().unitName());
|
|
|
- txtPreparation.setText(t.getPreparation());
|
|
|
+ listener = new ObservableListener<>(this, (c, v) -> {
|
|
|
+ c.txtName.setText(v.getName());
|
|
|
+ c.txtAmount.setValue(v.getAmount());
|
|
|
+ c.txtPreparation.setText(v.getPreparation());
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
+ public IngredientPreparationPanel(final Ingredient ingredient) {
|
|
|
+ this();
|
|
|
+ setModel(ingredient);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setModel(final Ingredient ingredient) {
|
|
|
listener.setObserved(ingredient);
|
|
|
}
|
|
|
|