-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainURManager.java
More file actions
373 lines (365 loc) · 12.1 KB
/
MainURManager.java
File metadata and controls
373 lines (365 loc) · 12.1 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package RouteMapMaker;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.property.DoubleProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
//main画面でundo/redoをサポートするため独自命令に対応するクラス。
public class MainURManager extends URElements {
public static MainURManager urManager = new MainURManager();
private ObservableList<canUR> MainCommandList = FXCollections.observableArrayList();
public void push(ObservableList<Line.Connection> staList, int staIndex, Line.Connection removedCon,
ObservableList<Train> trains, ArrayList<Integer[]> removeList, ObservableList<TrainStop> stopValue){//DELETE_LINE
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
Station_Delete sd = new Station_Delete();
sd.staList = staList;
sd.staIndex = staIndex;
sd.removedCon = removedCon;
sd.trains = trains;
sd.removeList = removeList;
sd.stopValue = stopValue;
MainCommandList.add(sd);
undoable.set(true);
redoable.set(false);
}
public void push(ObservableList<Station> staList,Station oldSta,Station newSta,int staIndex,
ObservableList<Train> trains,ArrayList<Integer[]> setList,ObservableList<TrainStop> stopValue){//Deconnect
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
Station_Deconnect sd = new Station_Deconnect(staList,oldSta,newSta,staIndex, trains, setList, stopValue);
MainCommandList.add(sd);
undoable.set(true);
redoable.set(false);
}
public void push(ObservableList<MvSta> movingStList){//moveStations
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
moveStations ms = new moveStations(movingStList);
MainCommandList.add(ms);
undoable.set(true);
redoable.set(false);
}
public void push(Train train, StopMark oldMark, StopMark newMark){
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
setTrainMark tm = new setTrainMark(train,oldMark,newMark);
MainCommandList.add(tm);
undoable.set(true);
redoable.set(false);
}
public void push(TrainStop stop, StopMark oldMark, StopMark newMark){
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
setStopMark sm = new setStopMark(stop,oldMark,newMark);
MainCommandList.add(sm);
undoable.set(true);
redoable.set(false);
}
public void push(Train train, DoubleArrayWrapper oldArray, DoubleArrayWrapper newArray){
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
setLineDashes sl = new setLineDashes(train, oldArray, newArray);
MainCommandList.add(sl);
undoable.set(true);
redoable.set(false);
}
public void push(ObservableList<DoubleProperty> props, ObservableList<Double> oldVals, ObservableList<Double> newVals,
double[] oldSize, double[] newSize, UIController uic){
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
transform tf = new transform(props, oldVals, newVals, oldSize, newSize,uic);
MainCommandList.add(tf);
undoable.set(true);
redoable.set(false);
}
public void push(List<Line.Connection> connections, List<TrainStop> stops,
Station prevSta, Station replacing, boolean fixed){
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
IntegrateSta is = new IntegrateSta(connections, stops, prevSta, replacing, fixed);
MainCommandList.add(is);
undoable.set(true);
redoable.set(false);
}
public void push(Background prev, Background replaced, Background target) {
undoTypeStack.push(Type.SUBCLASS);
undoIndexStack.push(MainCommandList.size());
redoTypeStack.clear();
redoIndexStack.clear();
SetBackground sbg = new SetBackground(prev, replaced, target);
MainCommandList.add(sbg);
undoable.set(true);
redoable.set(false);
}
@Override
public void undo(){
super.undo();
if(type == URElements.Type.SUBCLASS){
MainCommandList.get(index).undo();
}
}
@Override
public void redo(){
super.redo();
if(type == URElements.Type.SUBCLASS){
MainCommandList.get(index).redo();
}
}
interface canUR{//各命令を保持する内部クラス群はすべてコレを実装する。
void undo();
void redo();
}
//以下、各命令を保持する内部クラス群
public class Station_Delete implements canUR{
ObservableList<Line.Connection> staList;
int staIndex;
Line.Connection removedCon;
ObservableList<Train> trains;
ArrayList<Integer[]> removeList;
ObservableList<TrainStop> stopValue;
@Override
public void undo() {
staList.add(staIndex, removedCon);//接続自体の復元
//一緒に削除された停車駅の復元
for(int i = 0; i < removeList.size(); i++){
Integer[] removeIndex = removeList.get(i);
trains.get(removeIndex[0]).getStops().add(removeIndex[1], stopValue.get(i));
}
}
@Override
public void redo() {
// TODO Auto-generated method stub
staList.remove(staIndex);//駅自体の削除
//停車駅の削除
for(int i = 0; i < removeList.size(); i++){
Integer[] removeIndex = removeList.get(i);
trains.get(removeIndex[0].intValue()).getStops().remove(removeIndex[1].intValue());
}
}
}
public class Station_Deconnect implements canUR{
ObservableList<Station> staList;
Station oldSta;//置き換え前の駅
Station newSta;//接続を切った後の新駅
int staIndex;//line.stationsの方の置き換えるindex
ObservableList<Train> trains;
ArrayList<Integer[]> setList;//{系統番号,停車駅番号}
ObservableList<TrainStop> stopValue;//偶数はold,奇数はnewにする
Station_Deconnect(ObservableList<Station> staList,Station oldSta,Station newSta,int staIndex,
ObservableList<Train> trains,ArrayList<Integer[]> setList,ObservableList<TrainStop> stopValue){
this.staList = staList;
this.oldSta = oldSta;
this.newSta = newSta;
this.staIndex = staIndex;
this.trains = trains;
this.setList = setList;
this.stopValue = stopValue;
}
@Override
public void undo() {
// TODO Auto-generated method stub
staList.set(staIndex, oldSta);
for(int i = 0; i < setList.size(); i++){
Integer[] setIndex = setList.get(i);
trains.get(setIndex[0].intValue()).getStops().set(setIndex[1].intValue(), stopValue.get(i * 2));
}
}
@Override
public void redo() {
// TODO Auto-generated method stub
staList.set(staIndex, newSta);
for(int i = 0; i < setList.size(); i++){
Integer[] setIndex = setList.get(i);
trains.get(setIndex[0].intValue()).getStops().set(setIndex[1].intValue(), stopValue.get(i * 2 + 1));
}
}
}
public class moveStations implements canUR{
//MvStaオブジェクトをそのまま使うと外部から変更された時にヤバイので全て値をコピーして使います。
ObservableList<Station> station = FXCollections.observableArrayList();
ObservableList<Boolean> isSet = FXCollections.observableArrayList();//変更前の状態(変更後は必ずtrueなので)
ObservableList<Double> startX = FXCollections.observableArrayList();
ObservableList<Double> startY = FXCollections.observableArrayList();
ObservableList<Double> afterX = FXCollections.observableArrayList();
ObservableList<Double> afterY = FXCollections.observableArrayList();
moveStations(ObservableList<MvSta> movingStList){
for(MvSta ms: movingStList){
station.add(ms.sta);
isSet.add(ms.isSet);
startX.add(ms.start[0]);
startY.add(ms.start[1]);
afterX.add(ms.sta.getPoint()[0]);
afterY.add(ms.sta.getPoint()[1]);
}
}
@Override
public void undo() {
// TODO Auto-generated method stub
for(int i = 0; i < station.size(); i++){
if(isSet.get(i)) station.get(i).setPoint(startX.get(i), startY.get(i));
if(! isSet.get(i)) station.get(i).setInterPoint(startX.get(i), startY.get(i));
}
}
@Override
public void redo() {
// TODO Auto-generated method stub
for(int i = 0; i < station.size(); i++){
station.get(i).setPoint(afterX.get(i), afterY.get(i));
}
}
}
public class setTrainMark implements canUR{
Train train;
StopMark oldMark;
StopMark newMark;
setTrainMark(Train train, StopMark oldMark, StopMark newMark){
this.train = train;
this.oldMark = oldMark;
this.newMark = newMark;
}
@Override
public void undo() {
// TODO Auto-generated method stub
train.setMark(oldMark);
}
@Override
public void redo() {
// TODO Auto-generated method stub
train.setMark(newMark);
}
}
public class setStopMark implements canUR{
TrainStop stop;
StopMark oldMark;
StopMark newMark;
setStopMark(TrainStop stop, StopMark oldMark, StopMark newMark){
this.stop = stop;
this.oldMark = oldMark;
this.newMark = newMark;
}
@Override
public void undo() {
// TODO Auto-generated method stub
stop.setMark(oldMark);
}
@Override
public void redo() {
// TODO Auto-generated method stub
stop.setMark(newMark);
}
}
public class setLineDashes implements canUR{
Train train;
DoubleArrayWrapper oldArray;
DoubleArrayWrapper newArray;
setLineDashes(Train train, DoubleArrayWrapper oldArray, DoubleArrayWrapper newArray){
this.train = train;
this.oldArray = oldArray;
this.newArray = newArray;
}
@Override
public void undo() {
// TODO Auto-generated method stub
train.setLineDash(oldArray);
}
@Override
public void redo() {
// TODO Auto-generated method stub
train.setLineDash(newArray);
}
}
public class transform implements canUR{
ObservableList<DoubleProperty> props = FXCollections.observableArrayList();
ObservableList<Double> oldVals = FXCollections.observableArrayList();
ObservableList<Double> newVals = FXCollections.observableArrayList();
double[] oldSize;
double[] newSize;
UIController uic;
transform(ObservableList<DoubleProperty> props, ObservableList<Double> oldVals, ObservableList<Double> newVals,
double[] oldSize, double[] newSize, UIController uic){
this.props = props;
this.oldVals = oldVals;
this.newVals = newVals;
this.oldSize = oldSize;
this.newSize = newSize;
this.uic = uic;
}
@Override
public void undo() {
// TODO Auto-generated method stub
for(int i = 0; i < props.size(); i++){
props.get(i).set(oldVals.get(i));
}
uic.canvasOriginal = oldSize;
}
@Override
public void redo() {
// TODO Auto-generated method stub
for(int i = 0; i < props.size(); i++){
props.get(i).set(newVals.get(i));
}
uic.canvasOriginal = newSize;
}
}
public class IntegrateSta implements canUR{
List<Line.Connection> connections; //置き換える駅のConnectionの配列
List<TrainStop> stops; //置き換える駅を含んだTrainStopの配列
Station prevSta;//置き換え前
Station replacing;//置き換え後
boolean fixed;//以前座標固定点だったか否か
IntegrateSta(List<Line.Connection> con, List<TrainStop> stops,
Station prevSta, Station replacing, boolean fixed){
this.connections = con;
this.stops = stops;
this.prevSta = prevSta;
this.replacing = replacing;
this.fixed = fixed;
}
@Override
public void undo() {
connections.forEach(c -> c.station = prevSta);
stops.forEach(s -> s.setSta(prevSta));
if(!fixed) replacing.erasePoint();//座標非固定点ならば非固定にする。
}
@Override
public void redo() {
// TODO Auto-generated method stub
if(!fixed) replacing.setPoint(replacing.getInterPoint()[0], replacing.getInterPoint()[1]);
connections.forEach(c -> c.station = replacing);
stops.forEach(s -> s.setSta(replacing));
}
}
public class SetBackground implements canUR {
Background prevBg, replacedBg, target;
SetBackground(Background prev, Background replaced, Background target) {
this.prevBg = prev;
this.replacedBg = replaced;
this.target = target;
}
@Override
public void undo() {
target.copyParams(prevBg);
}
@Override
public void redo() {
target.copyParams(replacedBg);
}
}
}