summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/CDControl.java
blob: b881b000a149df7c166a6487849bb244b39d71c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.DialogReceiver;
import NET.worlds.console.PolledDialog;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Window;

public class CDControl extends PolledDialog {
   private Label display;
   private Button stopButton = new Button("[]");
   private Button pauseButton = new Button("||");
   private Button playButton = new Button(">");
   private Button prevButton = new Button("|<<");
   private Button nextButton = new Button(">>|");
   private Panel top = new Panel();
   private Panel bottom = new Panel();
   private Checkbox cdBox = new Checkbox(Console.message("Autoplay-CD"), CDAudio.useAutoCDFlag);
   private Checkbox midiBox = new Checkbox(Console.message("Autoplay-MIDI"), CDAudio.useMidiFlag);
   private String time;
   private static Font font = new Font(Console.message("MenuFont"), 0, 12);

   public CDControl(Window parent, DialogReceiver receiver) {
      super(parent, receiver, Console.message("Music"), false);
      this.display = new Label(this.time = CDAudio.get().getTimeReadout());
      this.setAlignment(1);
      this.ready();
   }

   @Override
   protected void build() {
      this.setLayout(new GridLayout(2, 1));
      this.top.setLayout(new FlowLayout());
      this.top.add(this.display);
      this.top.add(this.stopButton);
      this.top.add(this.pauseButton);
      this.top.add(this.playButton);
      this.top.add(this.prevButton);
      this.top.add(this.nextButton);
      this.bottom.setLayout(new GridLayout(2, 1));
      this.cdBox.setFont(font);
      this.midiBox.setFont(font);
      this.bottom.add(this.cdBox);
      this.bottom.add(this.midiBox);
      this.add(this.top);
      this.add(this.bottom);
   }

   @Override
   protected void activeCallback() {
      String tmp = CDAudio.get().getTimeReadout();
      if (!tmp.equals(this.time)) {
         this.display.setText(this.time = tmp);
      }
   }

   @Override
   public boolean action(java.awt.Event event, Object what) {
      Object target = event.target;
      if (target == this.stopButton) {
         CDAudio.get().stop();
      } else if (target == this.pauseButton) {
         CDAudio.get().pause();
      } else if (target == this.playButton) {
         CDAudio.get().play();
      } else if (target == this.prevButton) {
         CDAudio.get().prev();
      } else if (target == this.nextButton) {
         CDAudio.get().next();
      } else if (target == this.cdBox) {
         CDAudio.get().useAutoCD(this.cdBox.getState());
      } else {
         if (target != this.midiBox) {
            return false;
         }

         CDAudio.get().setMidiFlag(this.midiBox.getState());
      }

      return true;
   }
}