summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/EnumPropertyEditor.java
blob: 07a363addad4b6db0e5aa305fe56abc4de7d786a (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
package NET.worlds.scape;

import NET.worlds.console.PolledDialog;

public class EnumPropertyEditor extends PropEditor {
   private String[] choices;
   private int[] numbers;

   private EnumPropertyEditor(Property property, String[] names, int[] values) {
      super(property);

      assert names != null;

      assert values != null;

      int len = Math.max(names.length, values.length);

      assert len > 1;

      this.choices = new String[len];
      this.numbers = new int[len];

      for (int i = 0; i < len; i++) {
         if (i < names.length) {
            this.choices[i] = names[i];
         } else {
            this.choices[i] = names[names.length - 1] + i;
         }

         if (i < values.length) {
            this.numbers[i] = values[i];
         } else {
            this.numbers[i] = values[values.length - 1] + i - values.length;
         }
      }
   }

   @Override
   public PolledDialog edit(EditTile parent, String title) {
      return new EnumFieldEditorDialog(parent, title, this.property, this.choices, this.numbers);
   }

   public static Property make(Property property, String[] names, int[] values) {
      property.setPropertyType(5);
      return property.setEditor(new EnumPropertyEditor(property, names, values));
   }
}