32
32
/**
33
33
* Panel used to set armor value for a single location. Optionally used for rear location as well,
34
34
* and can be used to set the armor type for units with patchwork armor.
35
- *
35
+ *
36
36
* @author Neoancient
37
37
*/
38
38
public class ArmorLocationView extends BuildView implements ChangeListener {
@@ -46,22 +46,22 @@ public void addListener(ArmorLocationListener l) {
46
46
public void removeListener (ArmorLocationListener l ) {
47
47
listeners .remove (l );
48
48
}
49
-
49
+
50
50
private final SpinnerNumberModel spnPointsModel = new SpinnerNumberModel (0 , 0 , null , 1 );
51
51
private final SpinnerNumberModel spnPointsRearModel = new SpinnerNumberModel (0 , 0 , null , 1 );
52
52
private final JSpinner spnPoints = new JSpinner (spnPointsModel );
53
53
private final JSpinner spnPointsRear = new JSpinner (spnPointsRearModel );
54
54
private final JLabel lblRear = new JLabel ();
55
55
private final JLabel lblMaxPoints = new JLabel ();
56
-
56
+
57
57
private final int location ;
58
58
private final String maxFormat ;
59
59
private Integer maxPoints ;
60
60
private boolean hasRear = false ;
61
-
61
+
62
62
ArmorLocationView (int location ) {
63
63
this .location = location ;
64
-
64
+
65
65
ResourceBundle resourceMap = ResourceBundle .getBundle ("megameklab.resources.Views" );
66
66
lblRear .setText (resourceMap .getString ("ArmorLocationView.lblRear.text" ));
67
67
maxFormat = resourceMap .getString ("ArmorLocationView.lblMax.format" );
@@ -80,12 +80,12 @@ public void removeListener(ArmorLocationListener l) {
80
80
add (spnPointsRear , gbc );
81
81
gbc .gridy ++;
82
82
gbc .weighty = 1.0 ;
83
- add (lblMaxPoints , gbc );
83
+ add (lblMaxPoints , gbc );
84
84
}
85
-
85
+
86
86
/**
87
87
* Changes the location name in the title and whether it has a rear armor location.
88
- *
88
+ *
89
89
* @param locName
90
90
* @param rear
91
91
*/
@@ -98,18 +98,18 @@ public void updateLocation(String locName, boolean rear) {
98
98
spnPointsRear .setValue (0 );
99
99
}
100
100
}
101
-
101
+
102
102
/**
103
103
* @return The index (LOC_* constant) of the location managed by this view.
104
104
*/
105
105
public int getLocationIndex () {
106
106
return location ;
107
107
}
108
-
108
+
109
109
/**
110
110
* Sets the maximum number of armor points that can be assigned to this location.
111
111
* A value of null indicates that there is no maximum.
112
- *
112
+ *
113
113
* @param max
114
114
*/
115
115
public void setMaxPoints (@ Nullable Integer max ) {
@@ -123,17 +123,17 @@ public void setMaxPoints(@Nullable Integer max) {
123
123
lblMaxPoints .setText (String .format (maxFormat , max ));
124
124
}
125
125
}
126
-
126
+
127
127
public void setMinimum (int minimum ) {
128
128
spnPointsModel .setMinimum (minimum );
129
129
if (getPoints () < minimum ) {
130
130
spnPointsModel .setValue (minimum );
131
131
}
132
132
}
133
-
133
+
134
134
/**
135
135
* Sets the number of points for this location. If the location has rear armor, this sets only the front.
136
- *
136
+ *
137
137
* @param points
138
138
*/
139
139
public void setPoints (int points ) {
@@ -148,7 +148,7 @@ public void setPoints(int points) {
148
148
}
149
149
spnPoints .addChangeListener (this );
150
150
}
151
-
151
+
152
152
/**
153
153
* @return The number of points of armor for this location (front).
154
154
*/
@@ -158,7 +158,7 @@ public int getPoints() {
158
158
159
159
/**
160
160
* Sets the number of points of armor for this location in the rear.
161
- *
161
+ *
162
162
* @param points
163
163
*/
164
164
public void setPointsRear (int points ) {
@@ -173,17 +173,22 @@ public void setPointsRear(int points) {
173
173
}
174
174
spnPointsRear .addChangeListener (this );
175
175
}
176
-
176
+
177
177
/**
178
178
* @return The number of points of rear armor in this location.
179
179
*/
180
180
public int getPointsRear () {
181
181
return spnPointsRearModel .getNumber ().intValue ();
182
182
}
183
-
183
+
184
184
@ Override
185
185
public void stateChanged (ChangeEvent e ) {
186
186
listeners .forEach (l -> l .armorPointsChanged (location , getPoints (), getPointsRear ()));
187
187
}
188
188
189
+ public void omniLock (boolean unlocked ) {
190
+ spnPoints .setEnabled (unlocked );
191
+ spnPointsRear .setEnabled (unlocked );
192
+ }
193
+
189
194
}
0 commit comments