StatisticGraphPanel.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package ui.view;
  2. import javax.swing.JPanel;
  3. import classes.TrackedDataSet;
  4. import ui.controller.Control;
  5. import ui.model.Model;
  6. import javax.swing.JLabel;
  7. import javax.swing.BoxLayout;
  8. import javax.swing.JButton;
  9. import javax.swing.SwingConstants;
  10. import java.awt.BorderLayout;
  11. import javax.swing.border.LineBorder;
  12. import java.awt.Color;
  13. public class StatisticGraphPanel extends JPanel {
  14. private static final long serialVersionUID = 1L;
  15. // Model/Controller
  16. private Model model;
  17. private Control controller;
  18. // Components
  19. private StatisticGraph sGraph;
  20. private final JLabel graphNameLabel;
  21. private final JLabel maximumLabel = new JLabel("0");
  22. private JPanel topPanel = new JPanel();
  23. private JButton closeButton = new JButton("X");
  24. // Variables
  25. String graphName;
  26. private final JPanel Legendpanel = new JPanel();
  27. /**
  28. * Constructor.
  29. *
  30. * @param mod
  31. * the Model
  32. * @param cont
  33. * the Controller
  34. */
  35. public StatisticGraphPanel(Model mod, Control cont, String name) {
  36. super();
  37. setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
  38. this.model = mod;
  39. this.controller = cont;
  40. this.sGraph = new StatisticGraph(mod, cont);
  41. this.graphName = name;
  42. setLayout(new BorderLayout(0, 0));
  43. //********** add everything **********//
  44. // Statistic Graph
  45. this.add(sGraph);
  46. // Graph Name and Close Button
  47. graphNameLabel = new JLabel(graphName);
  48. topPanel.add(graphNameLabel);
  49. topPanel.add(closeButton);
  50. topPanel.setBorder(null);
  51. this.add(topPanel, BorderLayout.NORTH);
  52. // Y Maximum
  53. maximumLabel.setVerticalAlignment(SwingConstants.TOP);
  54. this.add(maximumLabel, BorderLayout.WEST);
  55. // Legend Panel
  56. add(Legendpanel, BorderLayout.SOUTH);
  57. }
  58. /**
  59. * Adds the Set to the Graph.
  60. *
  61. * @param set
  62. */
  63. public void addObjec(TrackedDataSet set) {
  64. sGraph.addObject(set);
  65. }
  66. /**
  67. * Repaint the Graph.
  68. *
  69. * public void repaint() { sGraph.repaint(); }
  70. */
  71. /**
  72. * Set the Maximum Label
  73. *
  74. * @param max
  75. */
  76. public void setMaximumLabel(int max) {
  77. maximumLabel.setText(Integer.toString(max));
  78. }
  79. }