Controls.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import java.io.*;
  2. import java.util.*;
  3. import java.awt.*;
  4. import javax.swing.*;
  5. import javax.swing.event.*;
  6. import java.awt.event.*;
  7. import javax.swing.ImageIcon;
  8. public class Controls extends JPanel implements Observer
  9. {
  10. private Model model;
  11. private playSlider playback;
  12. private JButton play;
  13. private JButton rewind;
  14. private JButton reset;
  15. private JButton clear;
  16. // Bob the Builder this shit
  17. public Controls(Model model)
  18. {
  19. // Hook up this observer so that it will be notified when the model
  20. // changes.
  21. this.model = model;
  22. this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  23. this.setPreferredSize(new Dimension(1280,75));
  24. this.setMinimumSize(new Dimension(320, 75));
  25. this.play = new JButton("Play");
  26. play.addActionListener(new ActionListener()
  27. {
  28. public void actionPerformed(ActionEvent e)
  29. {
  30. }
  31. });
  32. this.rewind = new JButton("Rewind");
  33. rewind.addActionListener(new ActionListener()
  34. {
  35. public void actionPerformed(ActionEvent e)
  36. {
  37. }
  38. });
  39. this.playback = new playSlider(0, 0, 0);
  40. playback.addChangeListener(new ChangeListener()
  41. {
  42. public void stateChanged(ChangeEvent e)
  43. {
  44. if (!playback.getSettingLen())
  45. {
  46. }
  47. }
  48. });
  49. this.playback.setPreferredSize(new Dimension(280, 75));
  50. this.reset = new JButton("End");
  51. reset.addActionListener(new ActionListener()
  52. {
  53. public void actionPerformed(ActionEvent e)
  54. {
  55. //playback.setValue(playback.getMaximum());
  56. }
  57. });
  58. this.clear = new JButton("Start");
  59. clear.addActionListener(new ActionListener()
  60. {
  61. public void actionPerformed(ActionEvent e)
  62. {
  63. //playback.setValue(playback.getMinimum());
  64. }
  65. });
  66. this.add(play);
  67. this.add(rewind);
  68. this.add(playback);
  69. this.add(clear);
  70. this.add(reset);
  71. model.addObserver(this);
  72. }
  73. public void update(Object observable)
  74. {
  75. int len = 0;
  76. if (len > 0)
  77. {
  78. playback.toggleSettingLen();
  79. playback.setMaximum(len);
  80. playback.toggleSettingLen();
  81. }
  82. revalidate();
  83. repaint();
  84. }
  85. }
  86. class playSlider extends JSlider
  87. {
  88. private boolean settingLen;
  89. public playSlider(int min, int max, int val)
  90. {
  91. super(min, max, val);
  92. this.settingLen = false;
  93. }
  94. public void toggleSettingLen()
  95. {
  96. this.settingLen = !settingLen;
  97. }
  98. public boolean getSettingLen()
  99. {
  100. return settingLen;
  101. }
  102. }