package org.leumasjaffe.recipe.view.summary; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTextArea; import javax.swing.JTextField; import org.jdesktop.swingx.VerticalLayout; import org.leumasjaffe.recipe.model.Element; import org.leumasjaffe.recipe.model.RecipeCard; import org.leumasjaffe.recipe.view.CollatedDurationPanel; import org.leumasjaffe.recipe.view.ImagePanel; import lombok.AccessLevel; import lombok.experimental.FieldDefaults; import java.awt.Font; @SuppressWarnings("serial") @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true) public class SummaryPanel extends JPanel { public SummaryPanel(final RecipeCard card) { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0, 0, 0}; gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JPanel panelHeader = new JPanel(); GridBagConstraints gbc_panelHeader = new GridBagConstraints(); gbc_panelHeader.gridwidth = 2; gbc_panelHeader.insets = new Insets(0, 0, 5, 0); gbc_panelHeader.fill = GridBagConstraints.BOTH; gbc_panelHeader.gridx = 0; gbc_panelHeader.gridy = 0; add(panelHeader, gbc_panelHeader); GridBagLayout gbl_panelHeader = new GridBagLayout(); gbl_panelHeader.columnWidths = new int[]{0, 0}; gbl_panelHeader.rowHeights = new int[]{0, 0, 0}; gbl_panelHeader.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panelHeader.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; panelHeader.setLayout(gbl_panelHeader); JTextField txtTitle = new JTextField(); txtTitle.setText(card.getTitle()); GridBagConstraints gbc_txtTitle = new GridBagConstraints(); gbc_txtTitle.insets = new Insets(0, 0, 0, 5); gbc_txtTitle.fill = GridBagConstraints.HORIZONTAL; gbc_txtTitle.gridx = 0; gbc_txtTitle.gridy = 0; panelHeader.add(txtTitle, gbc_txtTitle); txtTitle.setColumns(10); CollatedDurationPanel panelDuration = new CollatedDurationPanel(card.getCollatedDuration()); GridBagConstraints gbc_panelDuration = new GridBagConstraints(); gbc_panelDuration.gridx = 0; gbc_panelDuration.gridy = 1; panelHeader.add(panelDuration, gbc_panelDuration); JPanel panelIngredients = new JPanel(); GridBagConstraints gbc_panelIngredients = new GridBagConstraints(); gbc_panelIngredients.insets = new Insets(0, 0, 5, 5); gbc_panelIngredients.fill = GridBagConstraints.BOTH; gbc_panelIngredients.gridx = 0; gbc_panelIngredients.gridy = 1; add(panelIngredients, gbc_panelIngredients); panelIngredients.setLayout(new VerticalLayout()); JPanel panel = new JPanel(); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 5, 0); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 1; gbc_panel.gridy = 1; add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0, 0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); JPanel panelPhoto = new ImagePanel(); GridBagConstraints gbc_panelPhoto = new GridBagConstraints(); gbc_panelPhoto.insets = new Insets(0, 0, 5, 0); gbc_panelPhoto.gridx = 0; gbc_panelPhoto.gridy = 0; panel.add(panelPhoto, gbc_panelPhoto); JTextArea txaDesription = new JTextArea(5, 20); txaDesription.setFont(new Font("Verdana", Font.PLAIN, 10)); txaDesription.setWrapStyleWord(true); txaDesription.setLineWrap(true); txaDesription.setText(card.getDescription()); GridBagConstraints gbc_txaDesription = new GridBagConstraints(); gbc_txaDesription.insets = new Insets(0, 0, 5, 0); gbc_txaDesription.fill = GridBagConstraints.BOTH; gbc_txaDesription.gridx = 0; gbc_txaDesription.gridy = 1; panel.add(txaDesription, gbc_txaDesription); for (final Element element : card.getElements()) { panelIngredients.add(new ElementPanel(element)); panelIngredients.add(new JSeparator()); } } }