package org.leumasjaffe.recipe.view; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JPanel; import org.leumasjaffe.recipe.model.Duration; import org.leumasjaffe.recipe.view.formatter.DurationFormatter; @SuppressWarnings("serial") public class DurationPanel extends JPanel { JFormattedTextField txtTime; /** * @wbp.parser.constructor */ public DurationPanel(String name) { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE}; setLayout(gridBagLayout); JLabel lblName = new JLabel(name + ": "); GridBagConstraints gbc_lblName = new GridBagConstraints(); gbc_lblName.insets = new Insets(0, 0, 0, 5); gbc_lblName.gridx = 0; gbc_lblName.gridy = 0; add(lblName, gbc_lblName); txtTime = new JFormattedTextField(new DurationFormatter()); GridBagConstraints gbc_txtTime = new GridBagConstraints(); gbc_txtTime.gridx = 1; gbc_txtTime.gridy = 0; add(txtTime, gbc_txtTime); } public DurationPanel(String name, final Duration duration) { this(name); setModel(duration); } public void setModel(final Duration duration) { txtTime.setValue(duration); } public void setEditable(boolean b) { txtTime.setEditable(b); } }