comparison src/main/java/christie/textEditor/TextFrame.java @ 267:1ac366f96815

remake for CommandPattern
author ichikitakahiro <e165713@ie.u-ryukyu.ac.jp>
date Wed, 29 Jan 2020 18:50:14 +0900
parents 824d75bafe67
children 1f42a0903440
comparison
equal deleted inserted replaced
266:345de1b14ea5 267:1ac366f96815
24 24
25 private String inserted_string; 25 private String inserted_string;
26 26
27 private int sendLoc = 0; 27 private int sendLoc = 0;
28 28
29 private int endLoc = 0;
30
29 private boolean canWrite = true; 31 private boolean canWrite = true;
32
33 private boolean dFrag = false;
34 // 文字列削除でtrue,されなければfalse
30 35
31 StyleContext sc = new StyleContext(); 36 StyleContext sc = new StyleContext();
32 37
33 public TextFrame() { 38 public TextFrame() {
34 this("新規テキスト"); 39 this("新規テキスト");
96 101
97 public void changeToFalseSend(){ 102 public void changeToFalseSend(){
98 send = false; 103 send = false;
99 } 104 }
100 105
106 public void protectToExcessiveInsert(){canWrite = false;}
107
108 public boolean deleteFrag(){return dFrag;}
109
110 public void changeToFalseDeleteFrag(){dFrag = false;};
111
101 public int returnOffset(){ 112 public int returnOffset(){
102 return sendLoc; 113 return sendLoc;
103 } 114 }
104 115
105 public void prohibitDL(){canWrite = false;}
106
107 public String returnString(){return inserted_string;} 116 public String returnString(){return inserted_string;}
108 117
118 public int returnEndOffset(){return endLoc;}
119
120 public void delete(int pos, int ePos) {
121 if (pos == ePos) {
122 textArea.replaceRange("", pos, pos + 1);
123 } else {
124 textArea.replaceRange("", pos, pos + 1);
125 }
126 }
109 public class MyDocumentListener implements DocumentListener { 127 public class MyDocumentListener implements DocumentListener {
110 public void insertUpdate(DocumentEvent e) { 128 public void insertUpdate(DocumentEvent e) {
111 if(canWrite == true) { 129 if(canWrite == true) {
112 Document doc = e.getDocument(); 130 Document doc = e.getDocument();
113 loc = e.getOffset(); 131 loc = e.getOffset();
114 sendLoc = loc; 132 sendLoc = loc;
115
116 try { 133 try {
117 inserted_string = doc.getText(loc, 1); 134 inserted_string = doc.getText(loc, 1);
118 System.out.println("string = " + doc.getText(loc, 1)); 135 System.out.println("string = " + doc.getText(loc, 1));
119 } catch (BadLocationException e1) { 136 } catch (BadLocationException e1) {
120 e1.printStackTrace(); 137 e1.printStackTrace();
125 142
126 } 143 }
127 144
128 @Override 145 @Override
129 public void removeUpdate(DocumentEvent e) { 146 public void removeUpdate(DocumentEvent e) {
130 Document doc = e.getDocument(); 147 if(canWrite == true) {
131 int loc = e.getOffset(); 148 Document doc = e.getDocument();
132 int e_length = e.getLength(); 149 sendLoc = e.getOffset();
133 int del_loc_end = loc + e_length - 1; 150 int e_length = e.getLength();
134 if (e_length == 1) { 151 endLoc = sendLoc + e_length;
135 System.out.println("delete " + loc); 152 if (e_length == 1) {
136 } else { 153 System.out.println("delete " + sendLoc);
137 System.out.println("delete " + loc + " to " + del_loc_end); 154 } else {
155 System.out.println("delete " + sendLoc + " to " + endLoc);
156 }
157 dFrag = true;
138 } 158 }
139 159 canWrite = true;
140 } 160 }
141 161
142 @Override 162 @Override
143 public void changedUpdate(DocumentEvent e) { 163 public void changedUpdate(DocumentEvent e) {
144 } 164 }