This method is used by the text tool to add typed characters to displayed text selections.
(char c)
| 159 | /** This method is used by the text tool to add typed |
| 160 | characters to displayed text selections. */ |
| 161 | public void addChar(char c) { |
| 162 | if (imp==null) return; |
| 163 | if (!(c>=' ' || c=='\b' || c=='\n')) return; |
| 164 | int cline = 0; |
| 165 | if (firstChar) { |
| 166 | theText[cline] = new String(""); |
| 167 | for (int i=1; i<MAX_LINES; i++) |
| 168 | theText[i] = null; |
| 169 | } else { |
| 170 | for (int i=0; i<theText.length && theText[i] != null; i++) |
| 171 | cline = i; //add the character to the last line |
| 172 | } |
| 173 | if ((int)c=='\b') { |
| 174 | // backspace |
| 175 | if (theText[cline].length()>0) |
| 176 | theText[cline] = theText[cline].substring(0, theText[cline].length()-1); |
| 177 | else if (cline>0) { |
| 178 | theText[cline] = null; |
| 179 | cline--; |
| 180 | } |
| 181 | if (angle!=0.0) |
| 182 | imp.draw(); |
| 183 | else |
| 184 | imp.draw(clipX, clipY, clipWidth, clipHeight); |
| 185 | firstChar = false; |
| 186 | return; |
| 187 | } else if ((int)c=='\n') { |
| 188 | // newline |
| 189 | if (cline<(MAX_LINES-1)) cline++; |
| 190 | theText[cline] = ""; |
| 191 | updateBounds(); |
| 192 | updateText(); |
| 193 | } else { |
| 194 | char[] chr = {c}; |
| 195 | theText[cline] += new String(chr); |
| 196 | updateBounds(); |
| 197 | updateText(); |
| 198 | firstChar = false; |
| 199 | return; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | Font getScaledFont() { |
| 204 | if (font==null) |
no test coverage detected