summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Property.java
blob: 31b797ae0c12c9df7c9c7e9797ab96cf1caf3cab (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
package NET.worlds.scape;

import NET.worlds.console.Main;

public class Property {
   protected Properties owner;
   public static final int BOOL_TYPE = 0;
   public static final int INT_TYPE = 1;
   public static final int FLOAT_TYPE = 2;
   public static final int STRING_TYPE = 3;
   public static final int COLOR_TYPE = 4;
   public static final int ENUM_TYPE = 5;
   public static final int FLOAT_ARRAY_TYPE = 6;
   public static final int POINT2_TYPE = 7;
   public static final int POINT3_TYPE = 8;
   public static final int TRANSFORM_TYPE = 9;
   public static final int URL_TYPE = 10;
   protected int index;
   protected String name;
   protected int propertyType = 3;
   protected PropEditor editor;
   public boolean helpExists = false;
   protected boolean canSetNull = false;

   public Property(Properties owner, int index, String name) {
      this.owner = owner;
      this.index = index;
      this.name = name;
   }

   public Property(Properties owner, int index, String name, boolean haveHelp) {
      this.owner = owner;
      this.index = index;
      this.name = name;
      this.helpExists = haveHelp;
   }

   Property setEditor(PropEditor editor) {
      this.editor = editor;
      return this;
   }

   public PropEditor getEditor() {
      return this.editor;
   }

   public Property allowSetNull() {
      this.canSetNull = true;
      return this;
   }

   public boolean canSetNull() {
      return this.canSetNull;
   }

   public String getName() {
      return this.name;
   }

   public int getIndex() {
      return this.index;
   }

   public Properties getOwner() {
      return this.owner;
   }

   public Object get() {
      return this.operate(1, null);
   }

   public Object set(Object obj) {
      return this.operate(2, obj);
   }

   @Override
   public boolean equals(Object obj) {
      return obj instanceof Property && ((Property)obj).owner == this.owner && ((Property)obj).index == this.index;
   }

   @Override
   public int hashCode() {
      return this.owner.hashCode() ^ this.index;
   }

   protected Object operate(int func, Object value) {
      return Main.isMainThread() ? this.safeOperate(func, value) : new CallbackPropertyOperator(this, func, value).getValue();
   }

   Object safeOperate(int func, Object value) {
      try {
         Object ret = this.owner.properties(this.index, 0, func, value);
         if (func > 1 && func < 5 && this.owner instanceof SuperRoot) {
            ((SuperRoot)this.owner).markEdited();
         }

         return ret;
      } catch (NoSuchPropertyException var4) {
         assert false;

         return null;
      }
   }

   @Override
   public String toString() {
      return this.getName();
   }

   public void setPropertyType(int type) {
      this.propertyType = type;
   }

   public String getPropertyType() {
      String retVal;
      switch (this.propertyType) {
         case 0:
            retVal = "Boolean";
            break;
         case 1:
            retVal = "Integer";
            break;
         case 2:
            retVal = "Float";
            break;
         case 3:
            retVal = "String";
            break;
         case 4:
            retVal = "Color";
            break;
         case 5:
            retVal = "Enumeration";
            break;
         case 6:
            retVal = "Float Array";
            break;
         case 7:
            retVal = "2D Point";
            break;
         case 8:
            retVal = "3D Point";
            break;
         case 9:
            retVal = "Transform";
            break;
         default:
            retVal = "URL";
      }

      return retVal;
   }
}