summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/EditMusicDialog.java
blob: a5720b0c38cbd94da5e745fb1d371b1ba8aabc89 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.console.DialogReceiver;
import NET.worlds.console.FileSysDialog;
import NET.worlds.console.PolledDialog;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;

class EditMusicDialog extends PolledDialog implements DialogReceiver {
   private TextField nameField = new TextField(20);
   private TextField trackField = new TextField(3);
   private TextField midiField = new TextField(30);
   private Button browseButton = new Button(Console.message("Browse"));
   private Checkbox loopBox = new Checkbox(Console.message("Loop-cont"));
   private Button okButton = new Button(Console.message("OK"));
   private Button cancelButton = new Button(Console.message("Cancel"));
   private MusicManagerDialog parent;
   private MusicTrack music;
   private String oldName;
   private String path;
   private static Font font = new Font(Console.message("MenuFont"), 0, 12);
   private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);

   public EditMusicDialog(MusicManagerDialog parent, MusicTrack music) {
      super(parent, parent, music == null ? Console.message("Add-Music") : Console.message("Edit-Music"), true);
      this.parent = parent;
      this.music = music;
      if (music != null) {
         this.oldName = music.getName();
      }

      this.path = parent.getManager().getFileName().toLowerCase().replace('/', '\\');
      this.path = this.path.substring(0, this.path.lastIndexOf(92) + 1);
      this.ready();
   }

   @Override
   protected void build() {
      GridBagLayout gbag = new GridBagLayout();
      this.setLayout(gbag);
      GridBagConstraints c = new GridBagConstraints();
      c.fill = 0;
      c.anchor = 13;
      this.add(gbag, new Label(Console.message("Name"), 2), c);
      c.gridwidth = 0;
      c.anchor = 17;
      this.nameField.setFont(font);
      this.trackField.setFont(font);
      this.midiField.setFont(font);
      this.browseButton.setFont(bfont);
      this.loopBox.setFont(font);
      this.add(gbag, this.nameField, c);
      c.gridwidth = 1;
      c.anchor = 13;
      Label vt = new Label(Console.message("Virtual-track"), 2);
      vt.setFont(font);
      this.add(gbag, vt, c);
      c.gridwidth = 0;
      c.anchor = 17;
      this.add(gbag, this.trackField, c);
      c.gridwidth = 1;
      c.anchor = 13;
      Label am = new Label(Console.message("Alternate-MIDI"), 2);
      am.setFont(font);
      this.add(gbag, am, c);
      c.fill = 2;
      c.weightx = 1.0;
      c.anchor = 17;
      this.add(gbag, this.midiField, c);
      c.fill = 0;
      c.weightx = 0.0;
      c.gridwidth = 0;
      this.add(gbag, this.browseButton, c);
      this.add(gbag, this.loopBox, c);
      c.fill = 0;
      c.anchor = 10;
      Panel p = new Panel();
      this.okButton.setFont(bfont);
      this.cancelButton.setFont(bfont);
      p.add(this.okButton);
      p.add(this.cancelButton);
      this.add(gbag, p, c);
      if (this.music != null) {
         this.nameField.setText(this.music.getName());
         this.trackField.setText("" + this.music.getVirtTrackNumber());
         this.midiField.setText(this.music.getMIDIFileName());
         this.loopBox.setState(this.music.getLooping());
      }
   }

   @Override
   public boolean action(java.awt.Event event, Object what) {
      Object target = event.target;
      if (target == this.okButton && this.nameField.getText().trim().length() != 0) {
         return this.done(true);
      } else if (target == this.cancelButton) {
         return this.done(false);
      } else {
         if (target == this.browseButton) {
            this.dialogDisable(true);
            new FileSysDialog(
               Console.getFrame(),
               this,
               Console.message("Browse-MIDI"),
               0,
               "MIDI Files|*.mid;*.midi|All Files|*.*",
               this.path + this.midiField.getText(),
               false
            );
         }

         return false;
      }
   }

   @Override
   public synchronized void dialogDone(Object who, boolean confirmed) {
      this.dialogDisable(false);
      if (confirmed && who instanceof FileSysDialog) {
         String name = ((FileSysDialog)who).fileName().toLowerCase();
         if (name.startsWith(this.path)) {
            this.midiField.setText(name.substring(this.path.length()));
         }
      }
   }

   public boolean isEditor() {
      return this.music != null;
   }

   public MusicTrack getMusicTrack() {
      String name = this.nameField.getText().trim();
      int track = 0;

      try {
         track = Integer.parseInt(this.trackField.getText());
      } catch (NumberFormatException var5) {
      }

      String midi = this.midiField.getText().trim();
      boolean loop = this.loopBox.getState();
      if (this.music == null) {
         return new MusicTrack(name, track, midi, loop);
      } else {
         this.music.setName(name);
         if (track != -1) {
            this.music.setVirtTrackNumber(track);
         }

         this.music.setMIDIFileName(midi);
         this.music.setLooping(loop);
         return this.music;
      }
   }

   public String getOldName() {
      return this.oldName;
   }
}