annotate src/remoteeditor/editors/RemoteEditor.java @ 142:75034fcaa1f1

*** empty log message ***
author pin
date Tue, 05 Feb 2008 19:46:29 +0900 (2008-02-05)
parents 347ebb50ff05
children 7218ba447b7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
1 package remoteeditor.editors;
cf13bdba762b Initial revision
pin
parents:
diff changeset
2
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
3 import java.io.IOException;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
4 import java.net.InetAddress;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
5 import java.net.InetSocketAddress;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
6 import java.net.NetworkInterface;
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
7 import java.net.SocketException;
85
18ae3b9fe57a *** empty log message ***
pin
parents: 65
diff changeset
8 import java.nio.CharBuffer;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
9 import java.nio.channels.SocketChannel;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
10 import java.util.Enumeration;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
11 import java.util.LinkedList;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
12 import java.util.List;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
13
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
14 import org.eclipse.jface.text.BadLocationException;
cf13bdba762b Initial revision
pin
parents:
diff changeset
15 import org.eclipse.jface.text.IDocument;
cf13bdba762b Initial revision
pin
parents:
diff changeset
16 import org.eclipse.jface.text.ITextListener;
cf13bdba762b Initial revision
pin
parents:
diff changeset
17 import org.eclipse.jface.text.TextEvent;
cf13bdba762b Initial revision
pin
parents:
diff changeset
18 import org.eclipse.jface.text.source.ISourceViewer;
cf13bdba762b Initial revision
pin
parents:
diff changeset
19 import org.eclipse.swt.widgets.Composite;
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
20 import org.eclipse.swt.widgets.Display;
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
21 import org.eclipse.swt.widgets.Shell;
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
22 import org.eclipse.ui.IWorkbench;
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
23 import org.eclipse.ui.PlatformUI;
1
c5c8358a14f3 add sample package
yabiku
parents: 0
diff changeset
24 import org.eclipse.ui.editors.text.TextEditor;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
25
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
26 import remoteeditor.command.REPCommand;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
27 import remoteeditor.command.REPCommandEvent;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
28 import remoteeditor.command.REPCommandListener;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
29 import remoteeditor.network.REP;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
30 import remoteeditor.network.REPPacketReceive;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
31 import remoteeditor.network.REPPacketSend;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
32 import remoteeditor.network.RSocketEvent;
cf13bdba762b Initial revision
pin
parents:
diff changeset
33 import remoteeditor.network.RSocketListener;
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
34 import remoteeditor.ui.REPSelectWindow;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
35 import sample.merge.Translate;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
36
cf13bdba762b Initial revision
pin
parents:
diff changeset
37
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
38 public class RemoteEditor extends TextEditor implements ITextListener, REPCommandListener{
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
39
cf13bdba762b Initial revision
pin
parents:
diff changeset
40 private ISourceViewer viewer;
cf13bdba762b Initial revision
pin
parents:
diff changeset
41 private IDocument document;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
42
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
43 REPPacketReceive repreceive;
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
44 REPPacketSend repsend;
56
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
45
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
46 List <REPCommand> userCmdList = new LinkedList<REPCommand>();
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
47 List <REPCommand> tokenCmdList = new LinkedList<REPCommand>();
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
48 Translate trans = new Translate(userCmdList, tokenCmdList);
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
49
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
50 //Translate trans = new Translate();
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
51
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
52
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
53 int numberOfLinesOld;
26
b5493a5932ac *** empty log message ***
pin
parents: 25
diff changeset
54 int offset_con;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
55 private SocketChannel sc;
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
56 private int myeid = 0;
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
57 private int myseq = 0;
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
58 private int mysid = 0;
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
59 private String filename = "afro";
39
188f09aff2be *** empty log message ***
pin
parents: 38
diff changeset
60 protected boolean lock;
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
61 private String myHostAndPort;
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
62
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
63
56
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
64 //private Translate translate;
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
65
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
66 public RemoteEditor() {
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
67 super();
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
68 //filename = this.getEditorInput().getName();
36
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
69
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
70 }
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
71
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
72 public void createPartControl(Composite parent) {
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
73 super.createPartControl(parent);
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
74 viewer = getSourceViewer();
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
75 viewer.addTextListener(this);
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
76 document = viewer.getDocument();
18badb26ba0e *** empty log message ***
pin
parents: 35
diff changeset
77 filename = this.getEditorInput().getName();
138
7353ff5ddbb1 *** empty log message ***
pin
parents: 137
diff changeset
78 numberOfLinesOld = document.getNumberOfLines();
103
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
79
61
e6806b2195d3 *** empty log message ***
pin
parents: 56
diff changeset
80 int port = 8766;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
81 String host = "localhost";
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
82 InetSocketAddress addr = new InetSocketAddress(host, port);
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
83 try {
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
84 sc = SocketChannel.open();
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
85 sc.configureBlocking(true);
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
86 sc.connect(addr);
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
87 while(!sc.finishConnect()){
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
88 System.out.println("afro");
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
89 }
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
90 }catch (IOException e) {
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
91 e.printStackTrace();
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
92 }
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
93 getSocketString(sc);
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
94 repreceive = new REPPacketReceive(sc);
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
95 repsend = new REPPacketSend(sc);
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
96
62
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
97 // IWorkbench workbench = PlatformUI.getWorkbench();
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
98 // Display display = workbench.getDisplay();
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
99 // REPSelectWindow selectwindow = new REPSelectWindow(display);
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
100 // selectwindow.initWindow();
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
101 // selectwindow.setName(this.getEditorInput().getName());
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
102 // selectwindow.setChannel(sc);
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
103 // selectwindow.open();
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
104
62
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
105 //REPCommand temp = repreceive.unpack();
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
106 //myeid = temp.eid; mysid = temp.sid;
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
107 repreceive.addCommandListener(this);
62
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
108 //repsend.send(new REPCommand(REP.REPCMD_READ, mysid, myeid, myseq, 0, 0, ""));
86
f8c001e00f9c *** empty log message ***
pin
parents: 85
diff changeset
109 //joinPart();
103
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
110 if(document.getLength() < 1){
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
111 joinPart();
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
112 }else {
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
113 putPart();
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
114 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
115 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
116
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
117 private void getSocketString(SocketChannel sc2) {
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
118 String socketString = sc2.socket().getLocalSocketAddress().toString();
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
119 System.out.println(socketString);
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
120 String[] str = socketString.split("/");
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
121 //String String str2;
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
122 for(String str2: str){
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
123 this.myHostAndPort = str2;
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
124 }
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
125 //this.myHostAndPort = socketString;
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
126 }
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
127
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
128 public void dispose() {
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
129 //rep.dispose();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
130 super.dispose();
cf13bdba762b Initial revision
pin
parents:
diff changeset
131 }
cf13bdba762b Initial revision
pin
parents:
diff changeset
132 public void textChanged(TextEvent event) {
140
347ebb50ff05 *** empty log message ***
pin
parents: 139
diff changeset
133 if(lock) {
347ebb50ff05 *** empty log message ***
pin
parents: 139
diff changeset
134 numberOfLinesOld = document.getNumberOfLines();
347ebb50ff05 *** empty log message ***
pin
parents: 139
diff changeset
135 return;
347ebb50ff05 *** empty log message ***
pin
parents: 139
diff changeset
136 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
137 String replacedText = event.getReplacedText();
cf13bdba762b Initial revision
pin
parents:
diff changeset
138 String inputText = event.getText();
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
139
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
140 //ページ先頭からの文字数による座標(改行を含む)
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
141 int textOffset = event.getOffset();
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
142
cf13bdba762b Initial revision
pin
parents:
diff changeset
143 System.out.println("replace = " + replacedText);
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
144 System.out.println("input = " + inputText + " : " + inputText.length());
1
c5c8358a14f3 add sample package
yabiku
parents: 0
diff changeset
145
12
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
146 int line = 0;
26
b5493a5932ac *** empty log message ***
pin
parents: 25
diff changeset
147 int offset = 0;
12
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
148 int length = 0;
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
149 int cmd = 0;
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
150 int numberOfLinesNew = 0;
12
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
151 String lineText = null;
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
152 try {
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
153 line = document.getNumberOfLines(0, textOffset); // lineno を取得してます。
12
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
154 offset = document.getLineOffset(line-1);
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
155 length = document.getLineLength(line-1);
4e88130303cc *** empty log message ***
pin
parents: 11
diff changeset
156 lineText = document.get(offset, length);
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
157 numberOfLinesNew = document.getNumberOfLines();
11
b3cff9bd2cbc *** empty log message ***
pin
parents: 2
diff changeset
158 } catch (BadLocationException e1) {
b3cff9bd2cbc *** empty log message ***
pin
parents: 2
diff changeset
159 e1.printStackTrace();
b3cff9bd2cbc *** empty log message ***
pin
parents: 2
diff changeset
160 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
161 if(numberOfLinesNew > numberOfLinesOld){
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
162 //insert, delete, replace 行数で判断
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
163 cmd = REP.REPCMD_INSERT;
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
164 try {
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
165 sendInsert(line);
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
166 createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line);
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
167 } catch (BadLocationException e) {
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
168 e.printStackTrace();
112
65ba9545fa49 *** empty log message ***
pin
parents: 111
diff changeset
169 }
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
170
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
171 }else if(numberOfLinesNew == numberOfLinesOld){
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
172 cmd = REP.REPCMD_REPLACE;
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
173 try {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
174 sendReplace(line);
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
175 createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line);
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
176 } catch (BadLocationException e) {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
177 e.printStackTrace();
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
178 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
179 }else {
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
180 cmd = REP.REPCMD_DELETE;
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
181 try {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
182 sendDelete(line);
142
75034fcaa1f1 *** empty log message ***
pin
parents: 140
diff changeset
183 createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line);
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
184 } catch (BadLocationException e) {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
185 e.printStackTrace();
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
186 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
187 }
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
188 //rep.sendCmd(cmd, line, length, lineText);
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
189 // if(!lock){
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
190 // REPCommand usercmd = new REPCommand(cmd, mysid, myeid, myseq, line, lineText.length(), lineText);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
191 // repsend.send(usercmd);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
192 // //translate.addUserList(usercmd);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
193 // trans.addUserList(usercmd);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
194 // //System.out.println("User List" + userCmdList.toString());
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
195 // //System.out.println("Token List" + tokenCmdList.toString());
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
196 // }else{ }
139
4cff3c065460 *** empty log message ***
pin
parents: 138
diff changeset
197 //numberOfLinesOld = numberOfLinesNew;
4cff3c065460 *** empty log message ***
pin
parents: 138
diff changeset
198 numberOfLinesOld = document.getNumberOfLines();
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
199 }
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
200
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
201 private void createUndoCommand(int cmd, int offset, String replacedText, String inputText, int line) {
134
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
202 int undoCmd = 0;
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
203 String undoString = null;
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
204 REPCommand undoCommand;
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
205 REPPacketSend send = new REPPacketSend(sc);
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
206
131
61f82e84937a *** empty log message ***
pin
parents: 129
diff changeset
207 if(cmd == REP.REPCMD_INSERT){
132
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
208 undoCmd = REP.REPCMD_DELETE;
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
209 undoString = "";
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
210
132
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
211 }else if(cmd == REP.REPCMD_REPLACE){
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
212 undoCmd = REP.REPCMD_REPLACE;
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
213 String lineText = null;
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
214 try {
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
215 int lineOffset = document.getLineOffset(line-1);
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
216 int length = document.getLineLength(line-1);
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
217 lineText = document.get(lineOffset, length);
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
218 } catch (BadLocationException e) {
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
219 e.printStackTrace();
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
220 }
136
5b6afb5641ac *** empty log message ***
pin
parents: 135
diff changeset
221 StringBuffer sb = new StringBuffer(lineText);
5b6afb5641ac *** empty log message ***
pin
parents: 135
diff changeset
222 sb.delete(offset, offset + inputText.length());
138
7353ff5ddbb1 *** empty log message ***
pin
parents: 137
diff changeset
223 //undoString = sb.toString();
137
debb9b2eca2d *** empty log message ***
pin
parents: 136
diff changeset
224 if(replacedText != null){
debb9b2eca2d *** empty log message ***
pin
parents: 136
diff changeset
225 sb.insert(offset, replacedText);
debb9b2eca2d *** empty log message ***
pin
parents: 136
diff changeset
226 }
debb9b2eca2d *** empty log message ***
pin
parents: 136
diff changeset
227 undoString = sb.toString();
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
228 //sb.insert(offset, inputText);
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
229 //if(replacedText == null){
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
230 // sb.delete(offset, inputText.length());
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
231 //}else {
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
232 //sb.replace(offset, inputText.length(), replacedText);
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
233 //}
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
234 //undoString = sb.toString();
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
235
132
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
236 }else if(cmd == REP.REPCMD_DELETE){
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
237 undoCmd = REP.REPCMD_INSERT;
9ee013fde4d8 *** empty log message ***
pin
parents: 131
diff changeset
238 undoString = replacedText;
131
61f82e84937a *** empty log message ***
pin
parents: 129
diff changeset
239 }
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
240
134
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
241 undoCommand = new REPCommand(undoCmd, mysid, 0, -1, line, undoString.length(), undoString);
1e033a92b69a *** empty log message ***
pin
parents: 132
diff changeset
242 send.send(undoCommand);
131
61f82e84937a *** empty log message ***
pin
parents: 129
diff changeset
243 }
61f82e84937a *** empty log message ***
pin
parents: 129
diff changeset
244
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
245 private void sendDelete(int line) throws BadLocationException {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
246 if(!lock){
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
247 int offset = document.getLineOffset(line-1);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
248 int length = document.getLineLength(line-1);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
249 String lineText = document.get(offset, length);
129
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
250 REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText);
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
251 repsend.send(usercmd);
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
252
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
253 offset = document.getLineOffset(line);
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
254 length = document.getLineLength(line);
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
255 lineText = document.get(offset, length);
e4c21b87223a *** empty log message ***
pin
parents: 127
diff changeset
256 usercmd = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, myseq, line, lineText.length(), lineText);
127
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
257 repsend.send(usercmd);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
258 }
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
259 }
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
260
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
261 private void sendReplace(int line) throws BadLocationException {
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
262 if(!lock){
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
263 int offset = document.getLineOffset(line-1);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
264 int length = document.getLineLength(line-1);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
265 String lineText = document.get(offset, length);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
266 REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
267 repsend.send(usercmd);
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
268 }
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
269 }
6f174e2b7503 *** empty log message ***
pin
parents: 121
diff changeset
270
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
271 private void sendInsert(int line) throws BadLocationException {
120
fa4085c9f2ad *** empty log message ***
pin
parents: 119
diff changeset
272 if(!lock){
121
166759021e78 *** empty log message ***
pin
parents: 120
diff changeset
273 int offset = document.getLineOffset(line-1);
166759021e78 *** empty log message ***
pin
parents: 120
diff changeset
274 int length = document.getLineLength(line-1);
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
275 String lineText = document.get(offset, length);
119
a78e0429bee2 *** empty log message ***
pin
parents: 118
diff changeset
276 REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText);
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
277 repsend.send(usercmd);
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
278
121
166759021e78 *** empty log message ***
pin
parents: 120
diff changeset
279 offset = document.getLineOffset(line);
166759021e78 *** empty log message ***
pin
parents: 120
diff changeset
280 length = document.getLineLength(line);
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
281 lineText = document.get(offset, length);
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
282 usercmd = new REPCommand(REP.REPCMD_INSERT, mysid, myeid, myseq, line, lineText.length(), lineText);
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
283 repsend.send(usercmd);
120
fa4085c9f2ad *** empty log message ***
pin
parents: 119
diff changeset
284 }
118
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
285 }
ad836eeae5bd *** empty log message ***
pin
parents: 117
diff changeset
286
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
287 private void changeText(int kindOfCmd, int lineNo, int LineLength, String text) throws Exception{
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
288 System.out.println("Replace Text : " + text);
52
ec0bdbd7a8cf *** empty log message ***
pin
parents: 51
diff changeset
289 final int offset = document.getLineOffset(lineNo-1);
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
290 final String changedText = text;
43
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
291
52
ec0bdbd7a8cf *** empty log message ***
pin
parents: 51
diff changeset
292 final int replaceLength = document.getLineLength(lineNo-1);
43
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
293
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
294 viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
43
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
295
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
296 public void run() {
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
297 try {
39
188f09aff2be *** empty log message ***
pin
parents: 38
diff changeset
298 lock = true;
40
3368e6c94f11 *** empty log message ***
pin
parents: 39
diff changeset
299 //document.replace(offset, replaceLength, changedText);
50
301c2dd245a2 *** empty log message ***
pin
parents: 49
diff changeset
300 document.replace(offset, replaceLength, changedText);
39
188f09aff2be *** empty log message ***
pin
parents: 38
diff changeset
301 lock = false;
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
302 } catch (BadLocationException e) {
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
303 e.printStackTrace();
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
304 }
18
e87cae12907e *** empty log message ***
pin
parents: 17
diff changeset
305 }
21
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
306 });
8b58e6bb09c1 *** empty log message ***
pin
parents: 19
diff changeset
307 }
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
308 /*
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
309 // public void packetReceived(final RSocketEvent evt) {
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
310 // final int lineNo = evt.getLineNo();
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
311 // final int Linelength = evt.getLength();
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
312 // final String text = evt.getText();
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
313 // try {
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
314 // changeText(evt.getCmd(), lineNo, Linelength, text);
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
315 // } catch (Exception e) {
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
316 // e.printStackTrace();
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
317 // }
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
318 // }*/
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
319
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
320 public void joinPart(){
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
321 //String string = "test.txt";
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
322 repsend.send(new REPCommand(REP.SMCMD_JOIN, 0, 0, 0, 0, 0, myHostAndPort));
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
323 }
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
324
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
325 public void putPart(){
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
326 if(this.getEditorInput() != null) filename = this.getEditorInput().getName();
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
327 repsend.send(new REPCommand(REP.SMCMD_PUT, mysid, myeid, myseq, 0, filename.length(), filename));
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
328 }
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
329
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
330
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
331 public void selectPart(){
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
332 repsend.send(new REPCommand(REP.SMCMD_SELECT, mysid, myeid, myseq, 0, 0, ""));
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
333 }
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
334
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
335 public void CommandReceived(REPCommandEvent event) {
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
336 REPCommand receivedCommand = event.getCommand();
56
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
337 if(receivedCommand.eid == myeid){
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
338 System.out.println("my REP Command.");
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
339 }else{
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
340 tokenCmdList.add(receivedCommand);
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
341 }
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
342 //System.out.println("received command : " + receivedCommand.toString());
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
343 commandManager(receivedCommand);
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
344 }
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
345
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
346 private void commandManager(REPCommand command) {
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
347 switch(command.cmd){
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
348 case REP.SMCMD_JOIN_ACK:
92
a21881284668 *** empty log message ***
pin
parents: 89
diff changeset
349 mysid = command.sid;
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
350 myeid = command.eid;
56
679491395f8f *** empty log message ***
pin
parents: 55
diff changeset
351 trans.myeid = myeid;
103
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
352 REPCommand sendCommand = new REPCommand(REP.REPCMD_READ, mysid, myeid, 0, 0, 0, "");
dca742322984 *** empty log message ***
pin
parents: 93
diff changeset
353 repsend.send(sendCommand);
89
2d9d35298631 *** empty log message ***
pin
parents: 88
diff changeset
354 //putPart();
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
355 break;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
356 case REP.SMCMD_PUT_ACK:
87
267536d02275 *** empty log message ***
pin
parents: 86
diff changeset
357 mysid = command.sid;
267536d02275 *** empty log message ***
pin
parents: 86
diff changeset
358 myeid = command.eid;
62
99bcbd897f94 *** empty log message ***
pin
parents: 61
diff changeset
359 //selectPart();
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
360 break;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
361 case REP.SMCMD_SELECT_ACK:
63
023c20cd07ef *** empty log message ***
pin
parents: 62
diff changeset
362 mysid = command.sid;
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
363 break;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
364 case REP.REPCMD_INSERT:
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
365 try {
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
366 if(command.eid == myeid) break; //mergerを導入する時に消す
48
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
367 textInsert(command.lineno, command.len, command.string);
37
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
368 } catch (Exception e) {
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
369 e.printStackTrace();
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
370 }
7f346cf2a07b *** empty log message ***
pin
parents: 36
diff changeset
371 break;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
372 case REP.REPCMD_REPLACE:
43
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
373 try {
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
374 if(command.eid == myeid) break;//mergerを導入する時に消す
135
cdcd9fcd5dbf *** empty log message ***
pin
parents: 134
diff changeset
375 if(command.seq > 0) repsend.send(command);
43
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
376 changeText(command.cmd, command.lineno, command.len, command.string);
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
377 } catch (Exception e1) {
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
378 e1.printStackTrace();
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
379 }
94d2232a1d7d *** empty log message ***
pin
parents: 42
diff changeset
380 break;
64
403272ec470c *** empty log message ***
pin
parents: 63
diff changeset
381 case REP.REPCMD_DELETE:
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
382 try {
117
a441426fe48a *** empty log message ***
pin
parents: 112
diff changeset
383 if(command.eid == myeid) break;//mergerを導入する時に消す
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
384 textDelete(command.lineno, command.len, command.string);
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
385 } catch (BadLocationException e1) {
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
386 e1.printStackTrace();
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
387 }
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
388 break;
38
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
389 case REP.REPCMD_READ:
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
390 try {
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
391 receiveReadCMD(command.eid);
38
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
392 } catch (BadLocationException e) {
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
393 e.printStackTrace();
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
394 }
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
395 break;
106
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
396 case REP.REPCMD_READ_ACK:
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
397 try {
107
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
398 if(command.sid == mysid && command.eid == myeid){
106
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
399 read(command);
107
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
400 }else{
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
401 repsend.send(command);
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
402 }
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
403
106
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
404 } catch (BadLocationException e) {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
405 e.printStackTrace();
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
406 }
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
407 break;
38
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
408 }
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
409 }
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
410
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
411
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
412
106
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
413 private void read(REPCommand command) throws BadLocationException {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
414 final int offset = document.getLineOffset(command.lineno);
107
823a45f843a9 *** empty log message ***
pin
parents: 106
diff changeset
415 final String string = command.string;
106
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
416
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
417 viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
418 public void run() {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
419 try {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
420 lock = true;
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
421 //document.replace(offset, replaceLength, changedText);
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
422 document.replace(offset, 0, string);
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
423 lock = false;
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
424 } catch (BadLocationException e) {
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
425 e.printStackTrace();
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
426 }
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
427 }
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
428 });
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
429 }
8a3880cd858b *** empty log message ***
pin
parents: 103
diff changeset
430
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
431 private void textDelete(int lineNo, int len, String string) throws BadLocationException {
54
520bf354a2ac *** empty log message ***
pin
parents: 53
diff changeset
432 final int offset = document.getLineOffset(lineNo);
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
433 //final String changedText = string;
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
434
54
520bf354a2ac *** empty log message ***
pin
parents: 53
diff changeset
435 final int replaceLength = document.getLineLength(lineNo);
53
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
436
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
437 viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
438 public void run() {
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
439 try {
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
440 lock = true;
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
441 //document.replace(offset, replaceLength, changedText);
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
442 document.replace(offset, replaceLength, "");
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
443 lock = false;
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
444 } catch (BadLocationException e) {
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
445 e.printStackTrace();
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
446 }
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
447 }
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
448 });
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
449 }
2f6190300fdb *** empty log message ***
pin
parents: 52
diff changeset
450
48
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
451 private void textInsert(int lineNo, int j, String text) throws BadLocationException {
49
cd196794b07f *** empty log message ***
pin
parents: 48
diff changeset
452 final int offset = document.getLineOffset(lineNo);
48
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
453 final String changedText = text;
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
454
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
455 //final int replaceLength = document.getLineLength(lineNo);
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
456
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
457 viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
458 public void run() {
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
459 try {
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
460 lock = true;
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
461 //document.replace(offset, replaceLength, changedText);
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
462 document.replace(offset, 0, changedText);
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
463 lock = false;
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
464 } catch (BadLocationException e) {
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
465 e.printStackTrace();
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
466 }
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
467 }
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
468 });
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
469 }
039451639710 *** empty log message ***
pin
parents: 47
diff changeset
470
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
471 private void receiveReadCMD(int desteid) throws BadLocationException {
38
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
472 for(int i = 0; i < document.getNumberOfLines(); i++){
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
473 int offset = document.getLineOffset(i);
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
474 int length = document.getLineLength(i);
99dc7f13ed80 *** empty log message ***
pin
parents: 37
diff changeset
475 String text = document.get(offset, length);
65
b1710c49c883 *** empty log message ***
pin
parents: 64
diff changeset
476 repsend.send(new REPCommand(REP.REPCMD_READ_ACK, mysid, desteid, myseq, i, text.length(), text));
35
0c5701885b09 *** empty log message ***
pin
parents: 34
diff changeset
477 }
34
7d80c9318695 *** empty log message ***
pin
parents: 28
diff changeset
478 }
0
cf13bdba762b Initial revision
pin
parents:
diff changeset
479 }