-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUIController.java
More file actions
3755 lines (3701 loc) · 170 KB
/
UIController.java
File metadata and controls
3755 lines (3701 loc) · 170 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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package RouteMapMaker;
import java.awt.Desktop;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javafx.application.Platform;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Slider;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.util.Pair;
import javax.imageio.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class UIController implements Initializable{
final double EPSILON = 0.00001;//doubleでの比較用。double変数は==で比較しちゃだめです!
private ObservableList<String> rnList = FXCollections.observableArrayList();
private ObservableList<String> tStaListOb = FXCollections.observableArrayList();
private ObservableList<String> snList = FXCollections.observableArrayList();
private ObservableList<String> trList = FXCollections.observableArrayList();
private ObservableList<StopMark> markList = FXCollections.observableArrayList();//駅ごと
private ObservableList<StopMark> trainMarkList = FXCollections.observableArrayList();//経路ごと
private ObservableList<Line> lineList;
private Line line; //現在選択中の路線?(RouteTableのlistenerでセットされている)
private Station movingSt;
private ObservableList<MvSta> movingStList = FXCollections.observableArrayList();
private FreeItem movingItem = null;
private GraphicsContext gc;
private double y_largest = 0;
private double x_largest = 0;
private ToggleGroup esGroup;//どちらの編集モードかのToggleGroup
private final double pointRadius = 3;//駅の点の半径
final double canvasMargin = 200;
private final double version = 9;//セーブファイルのバージョン。セーブファイルに完全な互換性がなくなった時に変更する。
private final double ReleaseVersion = 16;//リリースバージョン。ユーザーへの案内用
private File dataFile;
private Stage mainStage;//この画面のstage。MODALにするのに使ったり
private Background background = new Background();
private double zoom = 1.0;//canvas上での表示倍率。mapDrawのみに適用する。
protected double[] canvasOriginal = new double[2];//mapDrawで1倍の時のcanvasのサイズを記録しておく。
private StringProperty stationFontFamily = new SimpleStringProperty("system");//駅名に使用するフォントファミリ名
private ObservableList<StopMark> customMarks = FXCollections.observableArrayList();//カスタム停車駅マークを保持するクラス。
private ObservableList<FreeItem> freeItems = FXCollections.observableArrayList();//自由挿入テキスト、画像を保持するクラス。
private Configuration config = new Configuration();
private Stage configStage;
private boolean configWindowOpened = false;//環境設定ウィンドウが既に開かれているかどうか
private FreeItemsController fic;
private Stage fiStage;
private boolean fiWindowOpened = false;//freeItemウィンドウが既に開かれているかどうか
private MainURManager urManager = MainURManager.urManager;
private ObservableList<DoubleArrayWrapper> lineDashes = FXCollections.observableArrayList();//ライン点線パターンを記憶。
private Stage changeAllStage;
private boolean changeAllWindowOpened = false;
private boolean shortCutKeyPressed = false;//コマンドorCtrlキーが押されてるか否か
private boolean isLoading = false; //読み込み処理でUIのlistenerが反応するため,それの処理
@FXML AnchorPane leftPane;
@FXML AnchorPane rightPane;
@FXML Button RouteDelete;
@FXML Button RouteAdd;
@FXML Button RouteLoad;
@FXML Button setBgImage;
@FXML Button staRemoveRestr;
@FXML Button staDeConnect;
@FXML Button StationDelete;
@FXML Button StationAdd;
@FXML Button stationFont;
@FXML Button tStaEdit;
@FXML Button TrainAdd;
@FXML Button TrainDelete;
@FXML Button TrainCopy;
@FXML Button TT_UP;
@FXML Button TT_DOWN;
@FXML Button RRT_UP;
@FXML Button RRT_DOWN;
@FXML Canvas canvas;
@FXML CheckBox showBackInLE;
@FXML CheckBox staCurveConnection;
@FXML CheckBox staNameNoShow;
@FXML ColorPicker bgColor_CP;
@FXML ColorPicker re_line_CP;
@FXML ColorPicker re_mark_CP;
@FXML ColorPicker RouteColor;
@FXML ComboBox<StopMark> re_mark_CB;
@FXML ComboBox<StopMark> re_staMark_CB;
@FXML ComboBox<DoubleArrayWrapper> re_linePattern_CB;
@FXML ComboBox<String> re_staPStyle_CB;
@FXML ComboBox<String> RouteStyle;
@FXML ComboBox<String> staStyle;
@FXML Label bgImageLabel;
@FXML Label currentFont;
@FXML Label mouseLocation;
@FXML ListView<String> RouteTable;
@FXML ListView<String> StationList;
@FXML ListView<String> TrainTable;
@FXML ListView<String> tStaList;
@FXML ListView<String> R_RouteTable;
@FXML MenuBar menubar;
@FXML MenuItem mb_new;
@FXML MenuItem mb_open;
@FXML MenuItem mb_save;
@FXML MenuItem mb_saveAs;
@FXML MenuItem mb_exportImage;
@FXML MenuItem mb_about;
@FXML MenuItem mb_goWiki;
@FXML MenuItem mb_checkUpdate;
@FXML MenuItem mb_config;
@FXML MenuItem mb_changeAll;
@FXML MenuItem mb_editCustomMark;
@FXML MenuItem mb_setCustomMark;
@FXML MenuItem mb_freeItem;
@FXML MenuItem mb_lineDashes;
@FXML MenuItem mb_transform;
@FXML MenuItem mb_undo;
@FXML MenuItem mb_redo;
@FXML MenuItem mb_R;
@FXML MenuItem mb_T;
@FXML ToggleButton leftEditButton;
@FXML ToggleButton rightEditButton;
@FXML ToggleButton re_staPShift_TB;
@FXML ToggleButton lineTop;
@FXML ToggleButton lineBottom;
@FXML ToggleButton lineRight;
@FXML ToggleButton lineLeft;
@FXML ToggleButton lineCenter;
@FXML ToggleButton lineYoko;
@FXML ToggleButton lineTate;
@FXML ToggleGroup lineTextMuki;
@FXML ToggleGroup lineTextLocation;
@FXML ToggleButton staTop;
@FXML ToggleButton staBottom;
@FXML ToggleButton staRight;
@FXML ToggleButton staLeft;
@FXML ToggleButton staCenter;
@FXML ToggleButton staYoko;
@FXML ToggleButton staTate;
@FXML ToggleButton staObeyLine;
@FXML ToggleGroup staTextMuki;
@FXML ToggleGroup staTextLocation;
@FXML Rectangle draggedRect;
@FXML ScrollPane canvasPane;
@FXML Slider ZoomSlider;
@FXML Spinner<Integer> bgImageOpacity;
@FXML Spinner<Integer> bgImageSize;
@FXML Spinner<Integer> bgImageX;
@FXML Spinner<Integer> bgImageY;
@FXML Spinner<Integer> re_line_SP;
@FXML Spinner<Integer> re_lineC_SP;
@FXML Spinner<Integer> re_mark_SP;
@FXML Spinner<Integer> re_lineSA_SP;
@FXML Spinner<Integer> re_lineSB_SP;
@FXML Spinner<Integer> re_staPSize_SP;
@FXML Spinner<Integer> RouteSize;
@FXML Spinner<Integer> R_nameX;
@FXML Spinner<Integer> R_nameY;
@FXML Spinner<Integer> re_staPX_SP;
@FXML Spinner<Integer> re_staPY_SP;
@FXML Spinner<Integer> re_staLAX_SP;
@FXML Spinner<Integer> re_staLAY_SP;
@FXML Spinner<Integer> staSize;
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
lineList = FXCollections.observableArrayList();
RouteTable.setItems(rnList);
RouteTable.setEditable(true);
RouteTable.setCellFactory(TextFieldListCell.forListView());
lineList.add(new Line("路線1"));
newLinePointSet(lineList.get(0));
rnList.add(lineList.get(0).getName());
StationList.setCellFactory(TextFieldListCell.forListView());
gc = canvas.getGraphicsContext2D();
gc.save();
(new Thread(){
@Override
public void run(){
checkUpdate(true);
}
}).start();
config.read();
Runtime.getRuntime().addShutdownHook(new Thread(() -> config.save()));
//起動時ダイアログの表示
if(! config.getNoAlert()){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setHeaderText("路線図メーカー使用上の注意・お願い");
Text text = new Text("本ソフトウェアの使用にあたり以下の3つをお願いしています。\n"
+ "1.不具合によるデータの破損などに十分注意してください。\n"
+ "2.随時アップデートを配信しますのでアップデートを確認し、インストールしてください。\n"
+ "3.不具合を発見した時は開発者へバグ報告をしてください。(Twitter @himeshi_hob にお願いします。)\n\n"
+ "開発者の情報、ライセンスなどはHelp→Aboutを参照してください。");
CheckBox box = new CheckBox("次からこのダイアログを表示しない");
VBox vbox = new VBox(10.0,text,box);
alert.getDialogPane().setContent(vbox);
alert.showAndWait();
config.setNoAlert(box.isSelected());
}
selectSomething(true);
lineDraw();
line = lineList.get(0);
RouteAdd.setOnAction((ActionEvent) ->{
createNewLine(null);
lineDraw();
});
RouteDelete.setOnAction((ActionEvent) ->{
int index = RouteTable.getSelectionModel().getSelectedIndex();
if(index != -1){
urManager.push(lineList, URElements.ArrayCommands.REMOVE, index, lineList.get(index));
lineList.remove(index);
rnList.clear();
for(int i=0; i < lineList.size(); i++){
rnList.add(lineList.get(i).getName());
}
lineDraw();
}
});
RouteLoad.setOnAction((ActionEvent) ->{
// 駅名が書かれたファイルを選択
FileChooser fc = new FileChooser();
FileChooser.ExtensionFilter txt = new FileChooser.ExtensionFilter("テキストファイル(*.txt)", "*.txt");
fc.setTitle("ファイルを開く");
fc.getExtensionFilters().add(txt);
File selectedFile = fc.showOpenDialog(null);
ArrayList<String> staNames = new ArrayList<String>();
try{
if(fc.getSelectedExtensionFilter() == txt){
BufferedReader br = new BufferedReader(new FileReader(selectedFile));
String line = br.readLine();
while(line != null) {
staNames.add(line);
line = br.readLine();
}
br.close();
createNewLine(staNames);
lineDraw();
}
}catch(IOException e){
Alert alert = new Alert(AlertType.ERROR,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("エラーが発生しました。ファイルを読み込めません。");
alert.showAndWait();
}catch(Exception e){
e.printStackTrace();
Alert alert = new Alert(AlertType.ERROR,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("エラーが発生しました。\n"
+ "以下のエラーメッセージを@himeshi_hobにお知らせください。\n" + e.getLocalizedMessage());
alert.showAndWait();
}
});
//駅名文字列の向きに関するトグルボタンの設定(路線単位)
lineTextLocation.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle,
Toggle new_toggle) ->{
int RouteIndex = RouteTable.getSelectionModel().getSelectedIndex();
if(RouteIndex == -1){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("路線を選択してください。");
alert.showAndWait();
return;
}
Toggle[] tlToggle = {lineRight, lineLeft, lineTop, lineBottom, lineCenter};
int newT = Arrays.asList(tlToggle).indexOf(new_toggle);
int oldT = Arrays.asList(tlToggle).indexOf(old_toggle);
if(newT == -1 && oldT != -1) {
//トグルの選択が解除されたことによるlisterの呼び出し.再選択
lineTextLocation.selectToggle(old_toggle);
}else if(lineList.get(RouteIndex).getNameLocation() == oldT && oldT != newT){
//手動で操作されたことによるlistenerの呼び出し
urManager.push(lineList.get(RouteIndex).getNameLocationProperty(), oldT, newT);
lineList.get(RouteIndex).setNameLocation(newT);
}
lineDraw();
});
lineTextMuki.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle,
Toggle new_toggle) ->{
int RouteIndex = RouteTable.getSelectionModel().getSelectedIndex();
if(RouteIndex == -1){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("路線を選択してください。");
alert.showAndWait();
return;
}
if(new_toggle==null && old_toggle!=null) {
//トグルの選択が解除されたことによるlisterの呼び出し.再選択
lineTextMuki.selectToggle(old_toggle);
} else if(old_toggle != null && old_toggle != new_toggle
&& lineList.get(RouteIndex).isTategaki() == (old_toggle==lineTate)) {
//手動で操作されたことによるlistenerの呼び出し
boolean nt = (new_toggle==lineTate);
urManager.push(lineList.get(RouteIndex).getTategakiProperty(), nt);
lineList.get(RouteIndex).setTategaki(nt);
}
lineDraw();
});
RouteTable.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends String> ov,
String old_val, String new_val) -> {
//路線が選択された時の処理
int index = RouteTable.getSelectionModel().getSelectedIndex();
if(index == -1) {
//index-1は何も選択されてないことを示すので処理しない。
return;
}
line = lineList.get(index);
StationList.setItems(snList);
snList.clear();
line.getStations().stream().forEach(s -> snList.add(s.getName())); //駅名リストの更新
StationList.getSelectionModel().selectLast();
StationList.setEditable(true);
//トグルの選択と駅名表示位置設定
Toggle[] tlToggle = {lineRight, lineLeft, lineTop, lineBottom, lineCenter};
lineTextLocation.selectToggle(tlToggle[line.getNameLocation()]);
lineTextMuki.selectToggle(line.isTategaki() ? lineTate : lineYoko);
RouteSize.getValueFactory().setValue(lineList.get(index).getNameSize());//サイズ設定
RouteStyle.getSelectionModel().select(lineList.get(index).getNameStyle());//style設定
RouteColor.setValue(lineList.get(index).getNameColor());//色設定
});
RouteTable.setOnEditCommit(new EventHandler<ListView.EditEvent<String>>(){
@Override
public void handle(ListView.EditEvent<String> t){
if(! t.getNewValue().equals("")){
if(! t.getNewValue().equals(lineList.get(t.getIndex()).getName())){
urManager.push(lineList.get(t.getIndex()).getNameProperty(), lineList.get(t.getIndex()).getName(),
t.getNewValue());
lineList.get(t.getIndex()).setName(t.getNewValue());
}
}
rnList.clear();
for(int i=0; i < lineList.size(); i++){
rnList.add(lineList.get(i).getName());
}
RouteTable.getSelectionModel().select(t.getIndex());
}
});
RouteColor.setOnAction((ActionEvent) -> {
int index = RouteTable.getSelectionModel().getSelectedIndex();
if(index != -1){
urManager.push(lineList.get(index).getNameColorProperty(), lineList.get(index).getNameColor(),
RouteColor.getValue());
lineList.get(index).setNameColor(RouteColor.getValue());
lineDraw();
}
});
RouteSize.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1,Integer.MAX_VALUE,15,1));
RouteSize.getEditor().addEventHandler(KeyEvent.KEY_PRESSED, new IntegerSpinnerEventHandler(RouteSize));
RouteSize.valueProperty().addListener((obs, oldVal, newVal) -> {
int index = RouteTable.getSelectionModel().getSelectedIndex();
if(index != -1){
if(oldVal.intValue() == lineList.get(index).getNameSize())
urManager.push(lineList.get(index).getNameSizeProperty(), oldVal, newVal);
lineList.get(index).setNameSize(RouteSize.getValue());
lineDraw();
}
});
ObservableList<String> RouteStyle_Options = FXCollections.observableArrayList("Regular", "Italic", "Bold", "BoldItalic");
RouteStyle.setItems(RouteStyle_Options);
RouteStyle.valueProperty().addListener((obs, oldVal, newVal) -> {
int index = RouteTable.getSelectionModel().getSelectedIndex();
if(index != -1){
if(oldVal != null){
if((oldVal.equals("Regular") && lineList.get(index).getNameStyle() == Line.REGULAR) ||
(oldVal.equals("Italic") && lineList.get(index).getNameStyle() == Line.ITALIC) ||
(oldVal.equals("Bold") && lineList.get(index).getNameStyle() == Line.BOLD) ||
(oldVal.equals("BoldItalic") && lineList.get(index).getNameStyle() == Line.ITALIC_BOLD))
urManager.push(lineList.get(index).getNameStyleProperty(), lineList.get(index).getNameStyle(),
RouteStyle.getSelectionModel().getSelectedIndex());
}
lineList.get(index).setNameStyle(RouteStyle.getSelectionModel().getSelectedIndex());
lineDraw();
}
});
stationFont.setOnAction((ActionEvent) ->{//フォントを設定。これは全路線共通です。
String oldVal = stationFontFamily.get();
stationFontFamily.set(selectFontFamily(stationFontFamily.get()));
if(! stationFontFamily.get().equals(oldVal)) urManager.push(stationFontFamily, oldVal, stationFontFamily.get());
currentFont.setText(stationFontFamily.get());
currentFont.setFont(Font.font(stationFontFamily.get()));
lineDraw();
});
StationAdd.setOnAction((ActionEvent) ->{
int index = StationList.getSelectionModel().getSelectedIndex();
if(index == 0){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("駅は2番目以降に挿入してください。");
alert.showAndWait();
}
else if(line.getCurveConnection(index) && line.isCurvable(index)) {
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("曲線区間に駅を挿入することはできません.");
alert.showAndWait();
}
else{
int staNum = 0;
while(true){
String d = staNum + "駅";
if(findStaByName(d)!=null){
staNum++;
}else{
break;
}
}
Line.Connection newCon = line.insertStation(index, new Station(staNum + "駅"));
urManager.push(line.getConnections(), URElements.ArrayCommands.ADD, index, newCon);
//固定座標ではないが参照座標を登録する。
double[] p = detectCoordinate(index, RouteTable.getSelectionModel().getSelectedIndex());
line.getStations().get(index).setInterPoint(p[0], p[1]);
snList.clear();
for(int i=0; i < line.getStations().size(); i++){
snList.add(line.getStations().get(i).getName());
}
StationList.getSelectionModel().select(index + 1);
lineDraw();
}
});
StationDelete.setOnAction((ActionEvent) ->{
int index = StationList.getSelectionModel().getSelectedIndex();
if(index == 0 || index == line.getStations().size() - 1){
//削除は受け付けない
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("始点と終点は削除できません。");
alert.showAndWait();
}else if(index != -1){
//選択されたlineで削除対象駅が路線に追加されているかを検査する
ArrayList<Integer[]> remove_Candidates = new ArrayList<Integer[]>();//{経路番号,停車場番号}
ObservableList<TrainStop> removedStops = FXCollections.observableArrayList();
Station removeCandidate = line.getStations().get(index);
for(int i = 0; i < line.getTrains().size(); i++){
for(int h = 0; h < line.getTrains().get(i).getStops().size(); h++){
if(line.getTrains().get(i).getStops().get(h).getSta() == removeCandidate){
Integer[] id = {i,h};
remove_Candidates.add(id);
}
}
}
if(remove_Candidates.size() > 0){
StringBuilder names = new StringBuilder();
for(Integer[] id: remove_Candidates){
names.append(line.getTrains().get(id[0]).getName()+" ");//空白で区切る
}
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setContentText("運転経路"+names.toString()+"に削除対象駅が含まれています。削除してよろしいですか?");
Optional<ButtonType> result = alert.showAndWait();
if(result.get() == ButtonType.OK){
for(Integer[] id: remove_Candidates){
TrainStop removedTrainStop = line.getTrains().get(id[0]).getStops().remove(id[1].intValue());
removedStops.add(removedTrainStop);
}
}
}
Line.Connection removedCon = line.removeStation(index);
urManager.push(line.getConnections(), index, removedCon, line.getTrains(), remove_Candidates, removedStops);
snList.clear();
for(int i=0; i < line.getStations().size(); i++){
snList.add(line.getStations().get(i).getName());
}
StationList.getSelectionModel().select(index);
lineDraw();
}
});
StationList.setOnEditCommit(new EventHandler<ListView.EditEvent<String>>(){
@Override
public void handle(ListView.EditEvent<String> t){
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
String prev = lineList.get(indexR).getStations().get(indexS).getName();//変更前の駅名
StationList.getItems().set(t.getIndex(), t.getNewValue());
String str = StationList.getSelectionModel().getSelectedItem();//変更しようとしてる駅名
//途中駅でも接続することにしました。
if(str.equals("")){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("駅名は空にはできません。\n"
+ "中継点を設定するときは駅名大きさパラメーターを-1にしてください。");
alert.showAndWait();
}else if(!str.equals(prev)){
//同名の駅による置き換えを試みる
if(stationConnect(indexS, indexR, str)==1) {
//同名の駅は存在しない。駅名を書き換えるだけ。
lineList.get(indexR).getStations().get(indexS).setName(str);
urManager.push(lineList.get(indexR).getStations().get(indexS).getNameProperty(), prev, str);
}
}
snList.clear();
for(int i=0; i < line.getStations().size(); i++){
snList.add(line.getStations().get(i).getName());
}
StationList.getSelectionModel().select(indexS);
lineDraw();
}
});
staObeyLine.setSelected(true);
staObeyLine.setOnAction((ActionEvent)->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR == -1 || indexS == -1) {
return;
}
Station s = lineList.get(indexR).getStations().get(indexS);
if((s.getTextLocation()==Station.TEXT_UNSET)==staObeyLine.isSelected()) {
//状態更新不要
return;
}
int newLocation = staObeyLine.isSelected() ? Station.TEXT_UNSET : Station.TEXT_LEFT;
urManager.push(s.getTextLocationProperty(), s.getTextLocation(), newLocation);
s.setTextLocation(newLocation);
//位置指定トグルの有効/無効を切り替える
Toggle[] stlToggles = {staLeft, staRight, staBottom, staTop, staCenter, staTate, staYoko};
boolean obeyLine = newLocation==Station.TEXT_UNSET;
Arrays.asList(stlToggles).forEach(t -> ((javafx.scene.Node)t).setDisable(obeyLine));
if(!obeyLine) {
staTextLocation.selectToggle(stlToggles[s.getTextLocation()-Station.TEXT_LEFT]);
}
lineDraw();
});
staTextLocation.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle,
Toggle new_toggle) ->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
Toggle[] stlToggles = {staLeft, staRight, staBottom, staTop, staCenter};
int oldT = Arrays.asList(stlToggles).indexOf(old_toggle);
int newT = Arrays.asList(stlToggles).indexOf(new_toggle);
if(indexR == -1 || indexS == -1 || oldT == -1) {
return;
}
if(newT == -1) {
//トグルの選択が解除されたことによるlisterの呼び出し.再選択
staTextLocation.selectToggle(old_toggle);
} else {
oldT += Station.TEXT_LEFT;
newT += Station.TEXT_LEFT;
Station sta = lineList.get(indexR).getStations().get(indexS);
if(oldT == sta.getTextLocation()) {
urManager.push(sta.getTextLocationProperty(), oldT, newT);
sta.setTextLocation(newT);
}
}
lineDraw();
});
staTextMuki.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle,
Toggle new_toggle) ->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR == -1 || indexS == -1 || old_toggle==null) {
return;
}
Station s = lineList.get(indexR).getStations().get(indexS);
if(new_toggle==null) {
//トグルの選択が解除されたことによるlisterの呼び出し.再選択
staTextMuki.selectToggle(old_toggle);
} else if(old_toggle != new_toggle && s.isTategaki() == (old_toggle==staTate)) {
//手動で操作されたことによるlistenerの呼び出し
boolean nt = (new_toggle==staTate);
urManager.push(s.getTategakiProperty(), nt);
s.setTategaki(nt);
}
lineDraw();
});
staSize.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(-1,Integer.MAX_VALUE,0,1));
staSize.getEditor().addEventHandler(KeyEvent.KEY_PRESSED, new IntegerSpinnerEventHandler(staSize));
staSize.valueProperty().addListener((obs, oldVal, newVal) -> {
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR != -1 && indexS != -1){
if(lineList.get(indexR).getStations().get(indexS).getNameSize() == oldVal.intValue())
urManager.push(lineList.get(indexR).getStations().get(indexS).getNameSizeProperty(), oldVal, newVal);
lineList.get(indexR).getStations().get(indexS).setNameSize(staSize.getValue());
lineDraw();
}
});
ObservableList<String> staStyle_Options = FXCollections.observableArrayList("Regular", "Italic", "Bold",
"BoldItalic", "路線準拠");
staStyle.setItems(staStyle_Options);
staStyle.valueProperty().addListener((obs, oldVal, newVal) -> {
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR != -1 && indexS != -1){
if(lineList.get(indexR).getStations().get(indexS).getNameStyle() == staStyle_Options.indexOf(oldVal))
urManager.push(lineList.get(indexR).getStations().get(indexS).getNameStyleProperty(),
staStyle_Options.indexOf(oldVal), staStyle_Options.indexOf(newVal));
lineList.get(indexR).getStations().get(indexS).setNameStyle(staStyle.getSelectionModel().getSelectedIndex());
lineDraw();
}
});
staCurveConnection.setOnAction((ActionEvent)->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
BooleanProperty cp = lineList.get(indexR).getConnections().get(indexS).curve;
cp.set(staCurveConnection.isSelected());
urManager.push(cp, cp.get());
lineDraw();
});
staNameNoShow.setOnAction((ActionEvent)->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR == -1 || indexS == -1) { return; }
Station sta = lineList.get(indexR).getStations().get(indexS);
if(staNameNoShow.isSelected()) {
urManager.push(sta.getNameSizeProperty(), sta.getNameSize(), -1);
sta.setNameSize(-1);
} else {
urManager.push(sta.getNameSizeProperty(), -1, 0);
sta.setNameSize(0);
staSize.getValueFactory().setValue(0);
}
staSize.setDisable(staNameNoShow.isSelected());
lineDraw();
});
staRemoveRestr.setOnAction((ActionEvent)->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR != -1 && indexS != -1){
if(indexS == 0 || indexS == lineList.get(indexR).getStations().size() - 1){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("始点または終点の座標固定を解除することはできません");
alert.showAndWait();
}else if(detectConnectedLine(lineList.get(indexR).getStations().get(indexS)).size() > 1){
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("複数路線に所属する駅の座標固定を解除することはできません。\n"
+ "「駅の接続解除」ボタンで駅の接続を解除できます。");
alert.showAndWait();
}else{
lineList.get(indexR).getStations().get(indexS).erasePoint();
urManager.push(lineList.get(indexR).getStations().get(indexS).getPointSetProperty(), false);
lineDraw();
}
}
});
staDeConnect.setOnAction((ActionEvent)->{
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR != -1 && indexS != -1){
if(detectConnectedLine(lineList.get(indexR).getStations().get(indexS)).size() < 2){
//この場合は接続を解除する意味がないのでなにもしない。
Alert alert = new Alert(AlertType.WARNING,"",ButtonType.CLOSE);
alert.getDialogPane().setContentText("指定された駅は他の路線と接続していません。");
alert.showAndWait();
}else{
Station oldSta = lineList.get(indexR).getStations().get(indexS);
Station newSta = new Station("新-" + oldSta.getName());
//以下初期設定。clone使いたいけどshiftCoorでトラブりそうなのでやめる
newSta.setPoint(oldSta.getPoint()[0] + 50, oldSta.getPoint()[1] + 50);
newSta.setConnection(oldSta.getConnection());
newSta.setTextLocation(oldSta.getTextLocation());
newSta.setNameSize(oldSta.getNameSize());
newSta.setNameStyle(oldSta.getNameStyle());
//描画位置設定は引き継がないことにする
lineList.get(indexR).getConnections().get(indexS).station = newSta;
lineDraw();
snList.clear();
for(int i=0; i < lineList.get(indexR).getStations().size(); i++){
snList.add(lineList.get(indexR).getStations().get(i).getName());
}
//交点駅が登録されている運転経路も新駅にチェンジ
ArrayList<Integer[]> setList = new ArrayList<Integer[]>();
ObservableList<TrainStop> stopValue = FXCollections.observableArrayList();
for(int k = 0; k < lineList.get(indexR).getTrains().size(); k++){
Train train = lineList.get(indexR).getTrains().get(k);
for(int i = 0; i < train.getStops().size(); i++){
if(train.getStops().get(i).getSta() == oldSta){
TrainStop newStop = new TrainStop(newSta);
Integer[] id = {k,i};
setList.add(id);
stopValue.add(train.getStops().get(i));
stopValue.add(newStop);
train.getStops().set(i, newStop);
}
}
}
urManager.push(lineList.get(indexR).getStations(), oldSta, newSta, indexS, lineList.get(indexR).getTrains(),
setList, stopValue);
//運転経路編集ウィンドウで変更を反映させる
int indexRR = R_RouteTable.getSelectionModel().getSelectedIndex();
int indexT = TrainTable.getSelectionModel().getSelectedIndex();
if(indexRR != -1 && indexT != -1){
tStaListOb.clear();
for(TrainStop ts: lineList.get(indexRR).getTrains().get(indexT).getStops()){
tStaListOb.add(ts.getSta().getName());
}
}
}
}
});
StationList.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends String> ov,
String old_val, String new_val) -> {
int indexR = RouteTable.getSelectionModel().getSelectedIndex();
int indexS = StationList.getSelectionModel().getSelectedIndex();
if(indexR == -1 || indexS == -1){
return;
}
Station s = lineList.get(indexR).getStations().get(indexS);
staSize.getValueFactory().setValue(s.getNameSize());
staSize.setDisable(s.getNameSize()==-1);
staNameNoShow.setSelected(s.getNameSize()==-1);
staStyle.getSelectionModel().select(s.getNameStyle());
staCurveConnection.setDisable(!lineList.get(indexR).isCurvable(indexS));
staCurveConnection.setSelected(lineList.get(indexR).getCurveConnection(indexS));
Toggle[] stlToggles = {staLeft, staRight, staBottom, staTop, staCenter};
//位置指定トグルの有効/無効を切り替える
boolean obeyLine = s.getTextLocation()==Station.TEXT_UNSET;
staObeyLine.setSelected(obeyLine);
Arrays.asList(stlToggles).forEach(t -> ((javafx.scene.Node)t).setDisable(obeyLine));
((javafx.scene.Node)staTate).setDisable(obeyLine);
((javafx.scene.Node)staYoko).setDisable(obeyLine);
staTextMuki.selectToggle(s.isTategaki() ? staTate : staYoko);
if(!obeyLine) {
staTextLocation.selectToggle(stlToggles[s.getTextLocation()-Station.TEXT_LEFT]);
}
//選択中の駅を赤点で表示する
if(movingStList.size() < 2) {
movingStList.clear();
movingStList.add(new MvSta(s));
lineDraw();
}
});
showBackInLE.setOnAction((ActionEvent) -> {
lineDraw();
});
bgColor_CP.setValue(background.color);
bgColor_CP.setOnAction((ActionEvent) ->{
// undo stackにpushする必要があるか?
if(!bgColor_CP.getValue().equals(background.color) || background.image!=null) {
Background prev_bg = background.clone();
background.color = bgColor_CP.getValue();
background.image = null;
updateBackgroundComponents();
urManager.push(prev_bg, background.clone(), background);
}
lineDraw();
});
setBgImage.setOnAction((ActionEvent) -> {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("画像ファイルを選択してください。");
fileChooser.getExtensionFilters().add(new ExtensionFilter("Image Files(jpg,png,gif,bmp)",
"*.png", "*.jpg", "*.jpeg", "*.gif","*.bmp", "*.PNG", "*.JPG", "*.JPEG", "*.GIF","*.BMP"));
File imageFile = fileChooser.showOpenDialog(null);
if(imageFile == null) { return; } //画像が選択されなかった
try {
Image im = new Image(new BufferedInputStream(new FileInputStream(imageFile)));
if(im.isError()) { //イメージのロード中にエラーが検出されたことを示す。
Alert alert = new Alert(AlertType.ERROR,"画像の読み込みエラー",ButtonType.CLOSE);
alert.getDialogPane().setContentText("画像の読み込みでエラーが発生しました。画像ファイルでない可能性があります。");
alert.showAndWait();
return;
}
Background prev_bg = background.clone();
background.image = im;
urManager.push(prev_bg, background.clone(), background);
updateBackgroundComponents();
lineDraw();
} catch (Exception e) {
e.printStackTrace();
Alert alert = new Alert(AlertType.ERROR,"ファイルのエラー",ButtonType.CLOSE);
alert.getDialogPane().setContentText("選択されたファイルを開くことができませんでした。");
alert.showAndWait();
}
});
bgImageX.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(Integer.MIN_VALUE,Integer.MAX_VALUE,0));
bgImageY.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(Integer.MIN_VALUE,Integer.MAX_VALUE,0));
bgImageSize.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1,1000,100));
bgImageOpacity.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0,100,0));
Spinner[] bgSpinners = {bgImageX, bgImageY, bgImageSize, bgImageOpacity};
for(Spinner<Integer> spinner: bgSpinners) {
// SpinnerEventHandlerの登録
spinner.getEditor().addEventHandler(KeyEvent.KEY_PRESSED, new IntegerSpinnerEventHandler(spinner));
// Listenerの登録.newValの設定先以外は共通
spinner.valueProperty().addListener((obs, oldVal, newVal) -> {
if(isLoading) { return; }
Background prev_bg = background.clone();
if(spinner==bgImageX) {background.x = newVal;}
else if(spinner==bgImageY) {background.y = newVal;}
else if(spinner==bgImageSize) {background.zoomRatio = newVal;}
else if(spinner==bgImageOpacity) {background.opacity = newVal;}
urManager.push(prev_bg, background.clone(), background);
lineDraw();
});
}
double[] startCoor = new double[2];//ドラッグスタート時の座標を記録する。station座標(zoomを考慮).
draggedRect.setVisible(false);
canvas.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>(){//canvas上でマウスが押された時
@Override
public void handle(MouseEvent e){
startCoor[0] = e.getX()/zoom;
startCoor[1] = e.getY()/zoom;
if(esGroup.getSelectedToggle() == rightEditButton){
movingSt = searchStation(startCoor[0], startCoor[1]);
if(movingSt == null){
draggedRect.setVisible(true);
draggedRect.setX(e.getX());
draggedRect.setY(e.getY());
draggedRect.setWidth(0);
draggedRect.setHeight(0);
movingStList.clear();
}else{
startCoor[0] = movingSt.getPointUS()[0];//駅移動時の開始座標は開始時のマウス座標ではなく駅座標にする。
startCoor[1] = movingSt.getPointUS()[1];
boolean contain = movingStList.stream().filter(ms -> ms.sta==movingSt).count()>0;
if(contain && shortCutKeyPressed){//movingStListから選択されたものを削除する
//ConcurrentModificationExceptionを回避するためにIteratorを使う
Iterator<MvSta> iter = movingStList.iterator();
while(iter.hasNext()){
MvSta ms = iter.next();
if(ms.sta == movingSt) iter.remove();
}
}
if(! contain){
if(! shortCutKeyPressed) movingStList.clear();
movingStList.add(new MvSta(movingSt));
}
for(MvSta ms: movingStList){//start座標の更新
ms.start[0] = ms.sta.getPointUS()[0];
ms.start[1] = ms.sta.getPointUS()[1];
}
draggedRect.setVisible(false);
}
lineDraw();
}else{//leftEditbuttonが選択されている状態
}
}
});
canvas.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>(){//canvas上でマウスがドラッグされた時
@Override
public void handle(MouseEvent e){
if(esGroup.getSelectedToggle() == rightEditButton){
if(e.getButton()!=MouseButton.PRIMARY) {
return;
}
final double[] cc = {e.getX()/zoom, e.getY()/zoom}; //zoomを考慮した現在のマウス座標
if(movingSt != null){//特定の駅が選択されている時
//movingSt.setPoint(e.getX(), e.getY());
for(MvSta ms: movingStList){
ms.sta.setPoint(ms.start[0] + cc[0] - startCoor[0], ms.start[1] + cc[1] - startCoor[1]);
}
//領域の自動拡大
if(canvas.getWidth() - e.getX() < canvasMargin) canvas.setWidth(e.getX() + canvasMargin);
if(canvas.getHeight() - e.getY() < canvasMargin) canvas.setHeight(e.getY() + canvasMargin);
lineDraw();
}else{//特定の駅が選択されているわけではないとき
if(e.getX() - startCoor[0]*zoom <= 0){//符号の反転が必要
draggedRect.setX(e.getX());
draggedRect.setWidth(startCoor[0]*zoom - e.getX());
}else{//反転必要なし
draggedRect.setWidth(e.getX() - startCoor[0]*zoom);
}
if(e.getY() - startCoor[1]*zoom <= 0){
draggedRect.setY(e.getY());
draggedRect.setHeight(startCoor[1]*zoom - e.getY());
}else{
draggedRect.setHeight(e.getY() - startCoor[1]*zoom);
}
}
}else{//leftEditbuttonが選択されている状態
}
}
});
canvas.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>(){//canvas上でマウスが離された時
@Override
public void handle(MouseEvent e){
if(esGroup.getSelectedToggle() == rightEditButton){
final double[] cc = {e.getX()/zoom, e.getY()/zoom}; //zoomを考慮した現在のマウス座標
if(movingSt != null){//特定の駅が選択されている時
if(e.getButton()!=MouseButton.PRIMARY) {
return;
}
double[] gridedPos = getGridedPoint(cc[0], cc[1]);
double mouseX = gridedPos[0];
double mouseY = gridedPos[1];
for(MvSta ms: movingStList){
ms.sta.setPoint(ms.start[0] + mouseX - startCoor[0], ms.start[1] + mouseY - startCoor[1]);
}
//マウスが全く動いてないかつ全てがもともと座標固定駅だった場合はpushしてはならない
boolean shouldBePushed = false;
for(MvSta ms: movingStList){
//完全にイコールにするとすごく小さな値で差がついてしまう
if(! ms.isSet || Math.abs(ms.start[0] - ms.sta.getPoint()[0]) > 0.5 ||
Math.abs(ms.start[1] - ms.sta.getPoint()[1]) > 0.5){
shouldBePushed = true;
break;
}
}
if(shouldBePushed){
urManager.push(movingStList);
System.out.println("mouseReleased - pushed!");
}
//canvasのサイズを調整する。
x_largest = 0;
y_largest = 0;