-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLine.java
More file actions
170 lines (163 loc) · 5.12 KB
/
Line.java
File metadata and controls
170 lines (163 loc) · 5.12 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
package RouteMapMaker;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.paint.Color;
public class Line {//路線の情報を保持するクラス。
public static final int REGULAR = 0;
public static final int ITALIC = 1;
public static final int BOLD = 2;
public static final int ITALIC_BOLD = 3;
//この数字の値,並びは各所で利用されているので変更は要注意
public static final int RIGHT = 0;
public static final int LEFT = 1;
public static final int TOP = 2;
public static final int BOTTOM = 3;
public static final int CENTER = 4;
class Connection {
Station station;
BooleanProperty curve;
Connection(Station s, boolean c) {
station = s;
curve = new SimpleBooleanProperty(c);
}
Connection(Station s) {
station = s;
curve = new SimpleBooleanProperty(false);
}
};
private ObservableList<Connection> connections; //<駅,曲線接続> で駅同士の接続を保持.
private ObservableList<Train> trains;//運転系統を保持する。
private StringProperty lineName = new SimpleStringProperty();//路線名
private BooleanProperty tategaki = new SimpleBooleanProperty(true);//縦書きか横書きか。trueなら縦書き
private IntegerProperty nameStyle = new SimpleIntegerProperty(REGULAR);
private IntegerProperty nameSize = new SimpleIntegerProperty(15);
private IntegerProperty nameLocation = new SimpleIntegerProperty(BOTTOM);
private ColorWrapper nameColor = new ColorWrapper(Color.BLACK);
private IntegerProperty NameX = new SimpleIntegerProperty(0);
private IntegerProperty NameY = new SimpleIntegerProperty(0);
public Line(String name){//コンストラクタ
connections = FXCollections.observableArrayList();
trains = FXCollections.observableArrayList();
setName(name);
//始点と終点は確保しておく
addStation(new Station(name + "始点"));
addStation(new Station(name + "終点"));
}
public String getName(){
return lineName.get();
}
public StringProperty getNameProperty(){
return this.lineName;
}
public void setName(String name){
this.lineName.set(name);
}
// ここで得られるListは編集可能ではないので注意
public ObservableList<Station> getStations(){
ObservableList<Station> staList = FXCollections.observableArrayList();
connections.forEach(c -> staList.add(c.station));
return staList;
}
public void setStations(ObservableList<Station> st){
connections.clear();
st.forEach(s -> connections.add(new Connection(s)));
}
public Connection insertStation(int idx, Station sta) {
Connection c = new Connection(sta);
connections.add(idx, c);
return c;
}
public Connection addStation(Station sta) {
Connection c = new Connection(sta);
connections.add(c);
return c;
}
public Connection removeStation(int idx) {
return connections.remove(idx);
}
public ObservableList<Connection> getConnections() {
return connections;
}
public boolean isTategaki(){
return tategaki.get();
}
public BooleanProperty getTategakiProperty(){
return this.tategaki;
}
public void setTategaki(boolean t){
this.tategaki.set(t);
}
public void setNameStyle(int i){
this.nameStyle.set(i);
}
public IntegerProperty getNameStyleProperty(){
return this.nameStyle;
}
public int getNameStyle(){
return this.nameStyle.get();
}
public int getNameSize(){
return this.nameSize.get();
}
public IntegerProperty getNameSizeProperty(){
return this.nameSize;
}
public void setNameSize(int i){
if(i <= 0) throw new IllegalArgumentException("lineのNameSizeは0以下にできません");//0以下は許容しません。
this.nameSize.set(i);
}
public int getNameLocation(){
return this.nameLocation.get();
}
public IntegerProperty getNameLocationProperty(){
return this.nameLocation;
}
public void setNameLocation(int i){
this.nameLocation.set(i);
}
public Color getNameColor(){
return this.nameColor.get();
}
public ColorWrapper getNameColorProperty(){
return this.nameColor;
}
public void setNameColor(Color c){
this.nameColor.set(c);
}
public void setNameX(int i){
this.NameX.set(i);
}
public void setNameY(int i){
this.NameY.set(i);
}
public IntegerProperty getNameXProperty(){
return this.NameX;
}
public IntegerProperty getNameYProperty(){
return this.NameY;
}
public int[] getNameZure(){
int[] ia = {NameX.get(), NameY.get()};
return ia;
}
public ObservableList<Train> getTrains(){
return trains;
}
public void setTrains(ObservableList<Train> t){
trains = t;
}
public boolean isCurvable(int idx) {
return idx>1 && connections.size()-idx>1 && //端条件
connections.get(idx-1).station.isSet() && connections.get(idx).station.isSet() && //固定条件
!connections.get(idx-1).curve.get() && !connections.get(idx+1).curve.get(); //連続条件
}
public boolean getCurveConnection(int idx) {
return connections.get(idx).curve.get();
}
}