-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNotifiableList.java
More file actions
55 lines (51 loc) · 1.4 KB
/
NotifiableList.java
File metadata and controls
55 lines (51 loc) · 1.4 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
package RouteMapMaker;
import javafx.beans.property.SimpleListProperty;
public class NotifiableList<E> extends SimpleListProperty<E> {//これを使うとURElementsへの通知を自動でやります。
/*
* Undoが反映されるメソッド:add(E e),add(int index, E element),set(int index, E element),remove(int index),remove(Object o)
*/
URElements ure;
public NotifiableList(URElements ure){
super();
this.ure = ure;
}
public NotifiableList(){
super();
}
public void setUR(URElements ure){
this.ure = ure;
}
@Override
public boolean add(E e){
ure.push(this, URElements.ArrayCommands.ADD, this.size(), e);
super.add(e);
return true;
}
@Override
public void add(int index, E e){
ure.push(this, URElements.ArrayCommands.ADD, index, e);
super.add(index, e);
}
@Override
public E set(int index, E e){
E prevItem = this.get(index);
ure.push(this, URElements.ArrayCommands.SET, index, prevItem, e);
return super.set(index, e);
}
@Override
public E remove(int index){
E removeItem = super.remove(index);
ure.push(this, URElements.ArrayCommands.REMOVE, index, removeItem);
return removeItem;
}
@Override
public boolean remove(Object o){
int index = super.indexOf(o);
if(index == -1){
return false;//見つからない場合は通知しない
}else{
ure.push(this, URElements.ArrayCommands.REMOVE, index, this.get(index));
return super.remove(o);
}
}
}