-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.java
More file actions
1820 lines (1420 loc) · 56.9 KB
/
dev.java
File metadata and controls
1820 lines (1420 loc) · 56.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package Backend;
import java.util.HashMap;
import java.util.Map;
public class Document{
//this class is to work as the hub for the spell check system creating the linked list from the workspace text.
//It transforms the data types into our word object so that the words can be analyzed by the spell check.
// first creating instance variables
public String text; // variable to hold last checked text instance in document
public LinkedList wordBuffer = new LinkedList(); //linked list to hold our word object list (for the entire document)
//create an instance of Doc error
Doc_Error doc_error = new Doc_Error();
Doc_Analysis doc_analysis;
//constructor
public Document(String text){
this.text = text;
populateLinkedList(text);
//doc_analysis = new Doc_Analysis(wordBuffer);
System.out.println("document created");
//create doc analysis object
this.doc_analysis = new Doc_Analysis(wordBuffer);
this.doc_error = new Doc_Error();
}
public void populateLinkedList(String text) {
//check to see if the string is empty
if(text.equals("")){
//do nothing
return;
}
String[] wordsWithDelimiters = text.split("\\s+");
//check to see if the linked list is empty
int i = 0;
Word_Object current = wordBuffer.getHead();
while (current != null) {
//check that i is in range of the wordsWithDelimiters
if(i >= wordsWithDelimiters.length - 1){
//remove the word
wordBuffer.removeWord(current);
//move to the next word
current = current.getNext_node();
}else if(current.getWord().equals(wordsWithDelimiters[i])){
//do nothing
i++;
}else{
String new_word = wordsWithDelimiters[i];
//take off the punctuation if any
if(new_word.endsWith(".") || new_word.endsWith(",") || new_word.endsWith(";") || new_word.endsWith(":") || new_word.endsWith("!") || new_word.endsWith("?") || new_word.endsWith("\"") || new_word.endsWith("\'")){
new_word = new_word.substring(0, new_word.length() - 1);
}
//create a new word object
Word_Object new_word_obj = new Word_Object(wordsWithDelimiters[i]);
//replace the word object in the linked list
wordBuffer.replaceWord(current, new_word_obj);
//increment i
i++;
//call the capital function
mark_capitals(new_word_obj);
}
if(current.getNext_node() != null){
current = current.getNext_node();
}else{
break;
}
}
//now we need to add the rest of the words to the linked list
while(i < wordsWithDelimiters.length){
//create a new word object
Word_Object new_word = new Word_Object(wordsWithDelimiters[i]);
//add the word object to the linked list
wordBuffer.add(new_word);
//increment i
i++;
//call the capital function
mark_capitals(new_word);
}
}
public void mark_capitals(Word_Object word){
//set the word_objects capital array
String this_word = word.getWord();
//get the length of the word
int length = this_word.length();
//create an array to hold the capitals
int[] capitals = new int[length];
//loop through the word
for(int i = 0; i < length; i++){
//check to see if the char is a capital
if(Character.isUpperCase(this_word.charAt(i))){
capitals[i] = 1;
}else{
capitals[i] = 0;
}
}
//set the capital array
word.setCapital_at(capitals);
//FROM THE CAPITAL ARRAY SE THE MARKERS
word.set_capital_markets();
}
public void run_spell_check() {
Word_Object current = wordBuffer.getHead();
while (current != null) {
if (current.isModified()) {
// Run spell check on this word
doc_error.checkWords(current);
doc_error.checkDoubleWord(current);
doc_error.checkCapitals(current);
current.setModified(false); // Reset the modified flag after checking
}
current = current.getNext_node();
}
//let us update the doc analysis
update_doc_analysis();
}
public Word_Object check_single_word(Word_Object word){
//create a word object
//check the word
doc_error.checkWords(word);
//return the word object
return word;
}
public Word_Object get_word_in_linked_list(int index){
//call calculate indicies (linked list was just updated by calling function)
wordBuffer.calculate_indicies();
//get the word object at the index
Word_Object word = (Word_Object) wordBuffer.get_word_at_index(index);
//return the word object
return word;
}
public void update_doc_analysis(){
System.out.println("updating doc analysis");
//check to see if doc_analysis is null
if(doc_analysis == null){
//create a new doc analysis object and assign it to instance variable
doc_analysis = new Doc_Analysis(wordBuffer);
}
//update the document analysis
doc_analysis.update(wordBuffer);
//get the values from doc analysis and print them
int char_count = doc_analysis.get_char_count();
int word_count = doc_analysis.get_word_count();
int line_count = doc_analysis.get_line_count();
System.out.println("char count: " + char_count);
System.out.println("word count: " + word_count);
System.out.println("line count: " + line_count);
}
public int[] get_doc_analysis(int num_lines){
//get the char count
int char_count = doc_analysis.get_char_count();
//get the word count
int word_count = doc_analysis.get_word_count();
//get the line count
int line_count = num_lines;
//add them to an array
int[] analysis = {char_count, word_count, line_count};
return analysis;
}
public int[] get_doc_error_values(){
//get the misspelt words
int misspelt_words = doc_error.getCurrent_misspelt_words();
int Corrected_misspelt_words = doc_error.getCorrected_misspelt_words();
int Current_double_words = doc_error.getCurrent_double_words();
int Corrected_double_words = doc_error.getCorrected_double_words();
int Current_capital_errors = doc_error.getCurrent_capital_errors();
int Corrected_capital_errors = doc_error.getCorrected_capital_errors();
//add them to an array
int[] errors = {misspelt_words, Corrected_misspelt_words, Current_double_words, Corrected_double_words, Current_capital_errors, Corrected_capital_errors};
//return the array
return errors;
}
public Doc_Error get_doc_error(){
return doc_error;
}
public void add_to_user_dict(String word){
//call the add to user dict function in doc error
doc_error.addToUserDict(word);
}
public void decrease_current_misspelt_words(){
//call the down count misspelt function in doc error
doc_error.downCountMisspelt();
}
public void decrease_current_double_words(){
//call the down count double word function in doc error
doc_error.downCountDoubleWord();
}
public void decrease_current_capital_errors(){
//call the down count capital function in doc error
doc_error.downCountCapital();
}
}
package Backend;
public class Word_Object{
private Word_Object prev_node;
private Word_Object next_node;
private String word;
private boolean needs_first_capital;
private boolean needs_lower_but_first;
private boolean needs_lower;
private boolean end_with_period;
private boolean is_real_word;
private boolean needs_capital;
private boolean needs_period;
private boolean is_double_word_after;
private boolean is_double_word_before;
private String suggestion_1;
private String suggestion_2;
private String suggestion_3;
private int start_index;
private int end_index;
private int spaces_after;
private int spaces_before;
private int[] is_capital_at;
private boolean ends_with_punctuation;
private boolean is_first_word;
public Word_Object(String word) {
// Initialization logic
//set is_real_word to false
this.is_real_word = false;
this.word = word;
this.end_with_period = false;
this.needs_capital = false;
this.needs_period = false;
this.is_double_word_after = false;
this.is_double_word_before = false;
this.suggestion_1 = "";
this.suggestion_2 = "";
this.suggestion_3 = "";
this.start_index = 0;
this.end_index = 0;
this.spaces_after = 0;
this.spaces_before = 0;
this.is_capital_at = null;
this.ends_with_punctuation = false;
this.is_first_word = false;
this.needs_first_capital = false;
this.needs_lower_but_first = false;
this.needs_lower = false;
}
private boolean modified = true;
public boolean isNeeds_first_capital() {
return needs_first_capital;
}
public void setNeeds_first_capital(boolean needs_first_capital) {
this.needs_first_capital = needs_first_capital;
}
public boolean isNeeds_lower_but_first() {
return needs_lower_but_first;
}
public void setNeeds_lower_but_first(boolean needs_lower_but_first) {
this.needs_lower_but_first = needs_lower_but_first;
}
public boolean isNeeds_lower() {
return needs_lower;
}
public void setNeeds_lower(boolean needs_lower) {
this.needs_lower = needs_lower;
}
public boolean isModified() {
return modified;
}
public void setModified(boolean modified) {
this.modified = modified;
}
public void Word_Object_full(String word, boolean start_with_capital, boolean end_with_period, boolean is_real_word, boolean needs_capital, boolean needs_period, boolean is_double_word_after, boolean is_double_word_before, String suggestion_1, String suggestion_2, String suggestion_3) {
this.word = word;
this.end_with_period = end_with_period;
this.is_real_word = is_real_word;
this.needs_capital = needs_capital;
this.needs_period = needs_period;
this.is_double_word_after = is_double_word_after;
this.is_double_word_before = is_double_word_before;
this.suggestion_1 = suggestion_1;
this.suggestion_2 = suggestion_2;
this.suggestion_3 = suggestion_3;
}
public void setStart_index(int start_index) {
this.start_index = start_index;
}
public void setEnd_index(int end_index) {
this.end_index = end_index;
}
public int getStart_index() {
return start_index;
}
public int getEnd_index() {
return end_index;
}
public Word_Object getPrev_node() {
return prev_node;
}
public void setPrev_node(Word_Object prev_node) {
this.prev_node = prev_node;
}
public Word_Object getNext_node() {
return next_node;
}
public void setNext_node(Word_Object next_node) {
this.next_node = next_node;
}
public String getWord() {
return word;
}
public void setEndsWithPunctuation(boolean endsWithPunctuation) {
this.ends_with_punctuation = endsWithPunctuation;
}
public boolean getEndsWithPunctuation() {
return ends_with_punctuation;
}
public void setIs_first_word(boolean is_first_word) {
this.is_first_word = is_first_word;
}
public boolean isIs_first_word() {
return is_first_word;
}
public void setWord(String word) {
this.word = word;
this.is_capital_at = new int[word.length()];
//loop through each char assign 1 if capital, 0 if not
for(int i = 0; i < word.length(); i++){
if(Character.isUpperCase(word.charAt(i))){
this.is_capital_at[i] = 1;
}
else{
this.is_capital_at[i] = 0;
}
}
}
public void replace_word(String word){
//replace the word and adjust indicies after the word
int old_length = this.word.length();
int new_length = word.length();
this.word = word;
//adjust the indicies of the word
this.end_index = this.start_index + new_length - 1;
for(int i = 0; i < word.length(); i++){
if(Character.isUpperCase(word.charAt(i))){
this.is_capital_at[i] = 1;
}
else{
this.is_capital_at[i] = 0;
}
}
//adjust the indicies of the next word
Word_Object current = this.next_node;
while(current != null){
current.setStart_index(current.getStart_index() - old_length + new_length);
current.setEnd_index(current.getEnd_index() - old_length + new_length);
current = current.getNext_node();
}
//mark the last and first words as modified
if(this.next_node != null){
this.next_node.setModified(true);
}
if(this.prev_node != null){
this.prev_node.setModified(true);
}
}
public void setCapital_at(int[] capital_at) {
this.is_capital_at = capital_at;
}
public void set_capital_markets(){
//check that if the previous word ends with a period, then this word needs a capital
if(this.prev_node != null){
if(this.prev_node.isEnd_with_period()){
//check if the fist char is a capital
if(Character.isUpperCase(this.word.charAt(0))){
//do nothing
}
else{
//set the needs capital to true
this.needs_first_capital = true;
}
//check to see if any other characters are capitals
for(int i = 1; i < this.word.length(); i++){
if(Character.isUpperCase(this.word.charAt(i))){
//set the needs lower but first to true
this.needs_lower_but_first = true;
this.needs_first_capital = false;
}
}
}
//check to see if any letters are capitals
for(int i = 0; i < this.word.length(); i++){
if(Character.isUpperCase(this.word.charAt(i))){
//set the needs lower to true
this.needs_lower = true;
break;
}
}
}else{
//first word so it needs a capital at the start
if(Character.isUpperCase(this.word.charAt(0))){
//do nothing
}
else{
//set the needs capital to true
this.needs_first_capital = true;
}
//check to see if any other characters are capitals
for(int i = 1; i < this.word.length(); i++){
if(Character.isUpperCase(this.word.charAt(i))){
//set the needs lower but first to true
this.needs_lower_but_first = true;
this.needs_first_capital = false;
}
}
}
//check to see if any letters are capitals
for(int i = 0; i < this.word.length(); i++){
if(Character.isUpperCase(this.word.charAt(i))){
//set the needs lower to true
this.needs_lower = true;
break;
}
}
}
public boolean isEnd_with_period() {
return end_with_period;
}
public void setEnd_with_period(boolean end_with_period) {
this.end_with_period = end_with_period;
}
public boolean isIs_real_word() {
return is_real_word;
}
public void setIs_real_word(boolean is_real_word) {
this.is_real_word = is_real_word;
}
public boolean isNeeds_capital() {
return needs_capital;
}
public void setNeeds_capital(boolean needs_capital) {
this.needs_capital = needs_capital;
}
public boolean isNeeds_period() {
return needs_period;
}
public void setNeeds_period(boolean needs_period) {
this.needs_period = needs_period;
}
public void setSpaces_after(int spaces_after) {
this.spaces_after = spaces_after;
}
public void setSpaces_before(int spaces_before) {
this.spaces_before = spaces_before;
}
public int getSpaces_after() {
return spaces_after;
}
public int getSpaces_before() {
return spaces_before;
}
public boolean isIs_double_word_after() {
return is_double_word_after;
}
public void setIs_double_word_after(boolean is_double_word_after) {
this.is_double_word_after = is_double_word_after;
}
public boolean isIs_double_word_before() {
return is_double_word_before;
}
public void setIs_double_word_before(boolean is_double_word_before) {
this.is_double_word_before = is_double_word_before;
}
public void setSuggestions(String[] suggestions) {
this.suggestion_1 = suggestions.length > 0 ? suggestions[0] : "";
this.suggestion_2 = suggestions.length > 1 ? suggestions[1] : "";
this.suggestion_3 = suggestions.length > 2 ? suggestions[2] : "";
}
public String[] getSuggestions(){
String[] items = new String[3];
items[0] = this.suggestion_1;
items[1] = this.suggestion_2;
items[2] = this.suggestion_3;
return items;
}
public int[] getIs_capital_at() {
return is_capital_at;
}
public boolean hasNext(){
if(this.next_node == null){
return false;
}
else{
return true;
}
}
}
package Backend;
public class LinkedList {
private Word_Object head; // Head of the list
private Word_Object tail; // Tail of the list
public LinkedList() {
head = null;
tail = null;
}
// Add a new node to the end of the list
public void add(Word_Object newNode) {
if (head == null) {
head = newNode;
tail = newNode;
newNode.setNext_node(null);
} else {
tail.setNext_node(newNode);
newNode.setPrev_node(tail);
tail = newNode;
}
}
// Add a new node to the beginning of the list
public void addFirst(Word_Object newNode) {
if (head == null) {
head = newNode;
tail = newNode;
newNode.setNext_node(null);
} else {
newNode.setNext_node(head);
head.setPrev_node(newNode);
head = newNode;
}
}
// get the head of the list
public Word_Object getHead() {
return head;
}
// get the tail of the list
public Word_Object getTail() {
return tail;
}
public int get_length() {
int length = 0;
Word_Object curr = head;
while (curr != null) {
length++;
curr = curr.getNext_node();
}
return length;
}
public void calculate_indicies() {
// We will populate the index values for each word object.
// Get the head of the linked list
Word_Object curr = head;
// Set the start index to 0
int index = 0;
// Loop through the linked list
while (curr != null) {
// Set the start index
curr.setStart_index(index);
// Get the word
String word = curr.getWord();
// Get the length of the word
int word_length = word.length();
// Add the word length to the index
index += word_length;
// Set the end index
curr.setEnd_index(index);
// Increment the index by 1 for space, by 2 for period and space
if (curr.isEnd_with_period()) {
index += 2;
} else {
index += 1;
}
// Move to the next node
curr = curr.getNext_node();
}
}
public void removeWord(Word_Object word) {
if (word.getPrev_node() != null) {
word.getPrev_node().setNext_node(word.getNext_node());
} else {
head = word.getNext_node();
}
if (word.getNext_node() != null) {
word.getNext_node().setPrev_node(word.getPrev_node());
} else {
tail = word.getPrev_node();
}
}
public Word_Object get_word_at_index(int index){
System.out.println("get word at index: " + index);
//get the head of the linked list
Word_Object curr = head;
System.out.println("index: " + index);
System.out.println("start index: " + curr.getWord());
//loop through the linked list
while(curr != null){
//check to see if the index is in the range of the word
if(index >= curr.getStart_index() && index <= curr.getEnd_index()){
return curr;
}
//increment the index
curr = curr.getNext_node();
}
//if we get here, we did not find the word
return null;
}
public Word_Object getWordAtCaretPosition(int caretPosition) {
Word_Object current = head;
while (current != null) {
if (caretPosition >= current.getStart_index() && caretPosition <= current.getEnd_index()) {
return current;
}
current = current.getNext_node();
}
return null; // No word found at this caret position
}
public void updateWordAtCaretPosition(int caretPosition, Word_Object newWord) {
Word_Object wordToUpdate = getWordAtCaretPosition(caretPosition);
if (wordToUpdate != null) {
// Replace the existing word
replaceWord(wordToUpdate, newWord);
} else {
// New word to add
add(newWord); // This may need to be more sophisticated depending on how you handle new words
}
}
public void replaceWord(Word_Object oldWord, Word_Object newWord) {
newWord.setNext_node(oldWord.getNext_node());
newWord.setPrev_node(oldWord.getPrev_node());
if (oldWord.getPrev_node() != null) {
oldWord.getPrev_node().setNext_node(newWord);
} else {
head = newWord;
}
if (oldWord.getNext_node() != null) {
oldWord.getNext_node().setPrev_node(newWord);
} else {
tail = newWord;
}
}
// Add other methods as needed, such as remove, find, etc.
}package spellapp.spellcheck;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.TextArea;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Popup;
import javafx.stage.Stage;
import javafx.scene.Scene;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.util.Duration;
import Backend.Document;
import Backend.Word_Object;
import javafx.stage.FileChooser;
import javafx.application.Platform;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import org.fxmisc.richtext.StyleClassedTextArea;
import Backend.Doc_Error;
public class MainSceneController {
@FXML
private Pane textAreaContainer;
private StyleClassedTextArea textArea = new StyleClassedTextArea();
@FXML
private Label mainLabel;
//Create a document object
Document document;
private ContextMenu contextMenu = new ContextMenu();
private ContextMenu spellingContextMenu = new ContextMenu();
private ContextMenu undoContextMenu = new ContextMenu();
private int currentCaretPosition = 0;
public void setTextAreaContent(String content) {
textArea.replaceText(content); // Replaces the entire text content
textArea.setOnMouseClicked(event -> {
if (contextMenu.isShowing()) {
contextMenu.hide();
}
// Additional logic for handling text click, if any
});
System.out.println("setting text area content" + content);
System.out.println("text area content: " + textArea.getText());
// Initialize and populate the document as before
init_document(textArea); // Ensure init_document is compatible with InlineCssTextArea
document.populateLinkedList(content);
document.run_spell_check();
}
//this function starts at the first click, and automatically updates the encironment every 10 seconds
public void startRepeatedTask() {
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(10), event -> {
Platform.runLater(() -> {
try {
//get text area content
String textContent = textArea.getText();
//populate the linked list
document.populateLinkedList(textContent);
//run the document spell check on the newly updated linked list
document.run_spell_check();
int[] docAnalysisVals = get_doc_analysis();
update_doc_analysis_values(docAnalysisVals);
//get the doc error values
int[] docErrorVals = get_doc_error();
//populate the doc error values on the front end
update_doc_error_values(docErrorVals);
//run the highlight misspelled words function
highlightErrors();
} catch (Exception e) {
System.err.println("Error during repeated task: " + e.getMessage());
// Handle or log the exception appropriately
}
});
}));
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
}
//init the document object from the text area
public void init_document(StyleClassedTextArea textArea_in){
// Create a new document object
this.document = new Document(textArea.getText());
}
public void setDocument(Document document) {
// Populate the document object
document.populateLinkedList(textArea.getText());
// Set the document object
this.document = document;
}
@FXML
private void handleSaveButton(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save File");
File file = fileChooser.showSaveDialog(new Stage());
if (file != null) {
saveSystem(file, textArea.getText());
}
}
private void saveSystem(File file, String text) {
try (PrintWriter printWriter = new PrintWriter(file)) {
printWriter.write(text);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@FXML
void openHelp(ActionEvent event) {
try {
// Load the Help.fxml file
FXMLLoader loader = new FXMLLoader(getClass().getResource("Help.fxml"));
Parent root = loader.load();
// Create a new popup
javafx.stage.Popup popup = new Popup();
popup.getContent().add(root);
// Set the owner stage
Stage ownerStage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
popup.show(ownerStage);
} catch (IOException e) {
e.printStackTrace();
}
}
//gets the text from the document (depricated (I think))
public String[] parse_text(){
//get the text from the text area
String text = textArea.getText();
//split the text into an array of words
String[] words = text.split("\\s+");
//delete double spaces
//return the array of words
return words;
}
@FXML
public void exit(ActionEvent event) {
try {
// Load the Help.fxml file
FXMLLoader loader = new FXMLLoader(getClass().getResource("Exit.fxml"));
Parent root = loader.load();
// Create a new popup
javafx.stage.Popup popup = new Popup();
popup.getContent().add(root);
// Set the owner stage
Stage ownerStage = (Stage) ((javafx.scene.Node) event.getSource()).getScene().getWindow();
popup.show(ownerStage);
} catch (IOException e) {
e.printStackTrace();