-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFreeItem.java
More file actions
100 lines (96 loc) · 3.18 KB
/
FreeItem.java
File metadata and controls
100 lines (96 loc) · 3.18 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
package RouteMapMaker;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
public class FreeItem implements Cloneable{//路線図上に自由挿入できるアイテムを保持するクラス。テキストと画像をサポート
public static final int TEXT = 0;
public static final int IMAGE = 1;
private IntegerProperty type = new SimpleIntegerProperty();
private Image image;
private String text;//IMAGEなら画像の名前、TEXTなら文字列を格納する
private DoubleProperty[] params;
private DoubleBinding[] dragArea = new DoubleBinding[4];//ドラッグ有効エリアを定義する。
private Color color = Color.BLACK;
private String font;//フォントファミリ名
//<dragArea>0:左上X,1:左上Y,2:右下X,3:右下Y
/*
* IMAGE:image,{左上X,左上Y,描画幅,描画高さ,回転}
* TEXT:Color,text,{X,Y,文字サイズ,lineWidth,回転,文字style,strokeOrFill(0:Fill,1:Stroke),縦書き横書き(0:横)},FontName
*/
public FreeItem(int type){//一度タイプを設定したら変更できない仕様
this.type.set(type);
if(this.type.get() == TEXT){
params = new DoubleProperty[8];
for(int i = 0; i < 8; i++){
params[i] = new SimpleDoubleProperty(0.0);
}
}else if(this.type.get() == IMAGE){
params = new DoubleProperty[5];
for(int i = 0; i < 5; i++){
params[i] = new SimpleDoubleProperty(0.0);
}
//以下、dragAreaのBinding処理
dragArea[0] = Bindings.add(0.0, params[0]);//そのまんま代入するていうのができないので0加算でごまかす
dragArea[1] = Bindings.add(0.0, params[1]);
dragArea[2] = (DoubleBinding) Bindings.add(params[0], params[2]);
dragArea[3] = (DoubleBinding) Bindings.add(params[1], params[3]);
}else{
throw new IllegalArgumentException("typeがTEXTでもIMAGEでもありません!");
}
}
public int getType(){
return this.type.get();
}
public DoubleProperty[] getParams(){
return this.params;
}
public void setImage(Image image){
this.image = image;
}
public Image getImage(){
return this.image;
}
public void setText(String text){
this.text = text;
}
public String getText(){
return this.text;
}
public void setColor(Color c){
this.color = c;
}
public Color getColor(){
return this.color;
}
public void setFontName(String n){
this.font = n;
}
public String getFontName(){
return this.font;
}
public DoubleBinding[] getDragArea(){
return this.dragArea;
}
@Override
public FreeItem clone(){
FreeItem f = null;
try {
f = (FreeItem) super.clone();
f.type = new SimpleIntegerProperty(this.getType());
//imageはそのまま参照させる。
f.params = new DoubleProperty[this.getParams().length];
for(int i = 0; i < this.getParams().length; i++){
f.params[i] = new SimpleDoubleProperty(this.getParams()[i].get());
}
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return f;
}
}