package org.leumasjaffe.recipe.view; import javax.swing.JPanel; import org.jdesktop.swingx.VerticalLayout; import org.leumasjaffe.recipe.model.Preparation; import lombok.AccessLevel; import lombok.Getter; import lombok.experimental.FieldDefaults; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JLabel; import java.awt.Component; import javax.swing.Box; @SuppressWarnings("serial") @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true) public class PreparationPanel extends JPanel { @Getter(AccessLevel.PACKAGE) JLabel lblDuration; @Getter(AccessLevel.PACKAGE) JPanel panelIngredients; public PreparationPanel(Preparation step) { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JPanel panelLeft = new JPanel(); GridBagConstraints gbc_panelLeft = new GridBagConstraints(); gbc_panelLeft.insets = new Insets(0, 0, 0, 5); gbc_panelLeft.fill = GridBagConstraints.BOTH; gbc_panelLeft.gridx = 0; gbc_panelLeft.gridy = 0; add(panelLeft, gbc_panelLeft); GridBagLayout gbl_panelLeft = new GridBagLayout(); gbl_panelLeft.columnWidths = new int[]{0, 0, 0, 0}; gbl_panelLeft.rowHeights = new int[]{0, 0, 0}; gbl_panelLeft.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE}; gbl_panelLeft.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; panelLeft.setLayout(gbl_panelLeft); JLabel lblIndex = new JLabel("Prep"); GridBagConstraints gbc_lblIndex = new GridBagConstraints(); gbc_lblIndex.fill = GridBagConstraints.HORIZONTAL; gbc_lblIndex.insets = new Insets(0, 0, 5, 5); gbc_lblIndex.gridx = 0; gbc_lblIndex.gridy = 0; panelLeft.add(lblIndex, gbc_lblIndex); Component horizontalGlue = Box.createHorizontalGlue(); GridBagConstraints gbc_horizontalGlue = new GridBagConstraints(); gbc_horizontalGlue.insets = new Insets(0, 0, 5, 5); gbc_horizontalGlue.gridx = 1; gbc_horizontalGlue.gridy = 0; panelLeft.add(horizontalGlue, gbc_horizontalGlue); lblDuration = new JLabel("Requires: " + step.getDuration().toString()); GridBagConstraints gbc_lblDuration = new GridBagConstraints(); gbc_lblDuration.insets = new Insets(0, 0, 5, 0); gbc_lblDuration.gridx = 2; gbc_lblDuration.gridy = 0; panelLeft.add(lblDuration, gbc_lblDuration); panelIngredients = new JPanel(); panelIngredients.setLayout(new VerticalLayout(5)); GridBagConstraints gbc_panelIngredients = new GridBagConstraints(); gbc_panelIngredients.gridwidth = 3; gbc_panelIngredients.insets = new Insets(0, 0, 0, 5); gbc_panelIngredients.fill = GridBagConstraints.BOTH; gbc_panelIngredients.gridx = 0; gbc_panelIngredients.gridy = 1; panelLeft.add(panelIngredients, gbc_panelIngredients); step.getIngredientsAsStream().map(IngredientPreparationPanel::new).forEach(panelIngredients::add); } }