DurationPanel.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package org.leumasjaffe.recipe.view;
  2. import java.awt.GridBagConstraints;
  3. import java.awt.GridBagLayout;
  4. import java.awt.Insets;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import org.leumasjaffe.recipe.model.Duration;
  8. @SuppressWarnings("serial")
  9. public class DurationPanel extends JPanel {
  10. private JLabel lblTime;
  11. public DurationPanel(String name) {
  12. GridBagLayout gridBagLayout = new GridBagLayout();
  13. gridBagLayout.columnWidths = new int[]{0, 0, 0};
  14. gridBagLayout.rowHeights = new int[]{0, 0};
  15. gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
  16. gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
  17. setLayout(gridBagLayout);
  18. JLabel lblName = new JLabel(name + ": ");
  19. GridBagConstraints gbc_lblName = new GridBagConstraints();
  20. gbc_lblName.insets = new Insets(0, 0, 0, 5);
  21. gbc_lblName.gridx = 0;
  22. gbc_lblName.gridy = 0;
  23. add(lblName, gbc_lblName);
  24. lblTime = new JLabel();
  25. GridBagConstraints gbc_lblTime = new GridBagConstraints();
  26. gbc_lblTime.gridx = 1;
  27. gbc_lblTime.gridy = 0;
  28. add(lblTime, gbc_lblTime);
  29. }
  30. public DurationPanel(String name, Duration duration) {
  31. this(name);
  32. setModel(duration);
  33. }
  34. public void setModel(final Duration duration) {
  35. lblTime.setText(duration.toString());
  36. }
  37. }