-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_java_code_report.txt
More file actions
2436 lines (1830 loc) · 71 KB
/
Copy pathall_java_code_report.txt
File metadata and controls
2436 lines (1830 loc) · 71 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 com.projectwizard;
/**
* Classe de entrada alternativa para evitar problemas com o Java Module System (JPMS).
* Ao iniciar a aplicação por uma classe que não estende 'Application', o JavaFX
* permite que dependências não-modulares funcionem corretamente no Classpath.
*/
public class Launcher {
public static void main(String[] args) {
Main.main(args);
}
}
package com.projectwizard;
import com.projectwizard.view.MainWindow;
//import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import com.projectwizard.theme.ThemeManager;
import com.projectwizard.theme.ThemeType;
import com.projectwizard.view.sidebar.Sidebar;
import com.projectwizard.view.dashboard.DashboardView;
import com.projectwizard.service.PersistenceService;
import com.projectwizard.core.navigation.NavigationController;
import com.projectwizard.core.navigation.NavigationTarget;
import java.io.File;
public class App {
public void start(Stage stage) {
ThemeManager.apply(ThemeType.PRIMER_DARK);
MainWindow window = new MainWindow();
window.show(stage);
// Restaurar último projeto aberto (Estilo Navegador)
restoreLastProject();
Scene scene = stage.getScene();
if (scene != null) {
scene.getStylesheets().add(
getClass()
.getResource("/themes/projectwizard.css")
.toExternalForm()
);
}
}
private void restoreLastProject() {
PersistenceService persistence = new PersistenceService();
String lastPath = persistence.getLastProjectPath();
if (lastPath != null) {
File projectDir = new File(lastPath);
if (projectDir.exists() && projectDir.isDirectory()) {
NavigationController.getInstance()
.navigateWithProject(NavigationTarget.WORKSPACE, projectDir);
}
}
}
}
package com.projectwizard.view.openproject;
import java.io.File;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.Window;
import com.projectwizard.view.explorer.PackageExplorer;
import com.projectwizard.view.explorer.FileTreeCell;
import com.projectwizard.view.editor.EditorHost;
import com.projectwizard.view.editor.EditorSupport;
import com.projectwizard.service.git.GitService;
import com.projectwizard.core.navigation.NavigationController;
import com.projectwizard.core.navigation.NavigationTarget;
public class OpenProjectView extends BorderPane {
private final TextField pathField = new TextField();
private final Button browseButton = new Button("Browse...");
private final Button openButton = new Button("Open");
private final Button cancelButton = new Button("Cancel");
private File selectedDirectory;
private final PackageExplorer explorer = new PackageExplorer();
private final TextArea info = new TextArea();
private final EditorHost editorHost = new EditorHost();
private GitService gitService;
public OpenProjectView() {
setPadding(new Insets(20));
Label title = new Label("Open Project");
title.setStyle("-fx-font-size:26px;-fx-font-weight:bold;");
pathField.setPromptText("Choose a project folder...");
pathField.setEditable(false);
HBox pathBox = new HBox(10, pathField, browseButton);
HBox.setHgrow(pathField, Priority.ALWAYS);
info.setEditable(false);
info.setText("Choose a folder to continue.");
info.setWrapText(true);
VBox.setVgrow(info, Priority.ALWAYS);
openButton.setDisable(true);
browseButton.setOnAction(e -> handleBrowse());
openButton.setOnAction(e -> handleOpen());
cancelButton.setOnAction(e -> handleCancel());
HBox buttons = new HBox(10, openButton, cancelButton);
VBox center = new VBox(20, title, pathBox, info, buttons);
TabPane tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
tabPane.getTabs().addAll(
new Tab("📁 Explorer", explorer),
new Tab("📝 Editor", editorHost)
);
SplitPane split = new SplitPane();
split.getItems().addAll(tabPane, center);
split.setDividerPositions(0.40);
setCenter(split);
setupDoubleClickHandler();
}
private void handleBrowse() {
Window window = getScene().getWindow();
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Open Project Folder");
File dir = chooser.showDialog(window);
if (dir != null) {
selectedDirectory = dir;
gitService = new GitService(dir);
explorer.setCellFactory(v -> new FileTreeCell());
explorer.openProject(dir);
pathField.setText(dir.getAbsolutePath());
info.setText("Folder selected:\n\n" + dir.getAbsolutePath()
+ "\n\n" + gitService.getRepositoryInfo()
+ "\n\n💡 Double-click files to preview in tabs. Click Open to load workspace!");
openButton.setDisable(false);
}
}
private void handleOpen() {
if (selectedDirectory == null) {
showAlert("Error", "No folder selected!", Alert.AlertType.ERROR);
return;
}
try {
NavigationController.getInstance()
.navigateWithProject(NavigationTarget.WORKSPACE, selectedDirectory);
} catch (Exception e) {
showAlert("Error", "Failed: " + e.getMessage(), Alert.AlertType.ERROR);
}
}
private void handleCancel() {
pathField.clear();
selectedDirectory = null;
openButton.setDisable(true);
info.setText("Choose a folder to continue.");
explorer.setRoot(null);
editorHost.clear();
}
private void setupDoubleClickHandler() {
explorer.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
TreeItem<File> selected = explorer.getSelectionModel().getSelectedItem();
if (selected != null && selected.getValue() != null && selected.getValue().isFile()) {
File file = selected.getValue();
if (EditorSupport.isTextFile(file)) {
editorHost.openFile(file);
info.setText("📄 " + file.getName()
+ "\n📍 " + file.getAbsolutePath()
+ "\n📑 Tabs open: " + editorHost.getOpenTabCount());
}
}
}
});
}
private void showAlert(String title, String message, Alert.AlertType type) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}
package com.projectwizard.view.explorer;
import java.io.File;
import java.util.Arrays;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
/**
* Enhanced PackageExplorer with Lazy Loading and Smart Filtering
*
* Features:
* - Lazy loads folders on expand
* - Auto-filters build artifacts
* - Alphabetically sorted
* - Supports large projects
*/
public class PackageExplorer extends TreeView<File> {
private static final String[] FILTERED_NAMES = {
".git", ".gitignore", ".github", ".gitlab-ci.yml",
"target", "node_modules", ".idea", "build", ".gradle",
".vscode", ".DS_Store", "*.class", "dist", "out", "bin",
".settings", ".classpath", ".project", ".mvn", "pom.xml.bak"
};
public PackageExplorer() {
setShowRoot(true);
}
public void openProject(File rootFolder) {
if (rootFolder == null)
return;
TreeItem<File> root = create(rootFolder);
setRoot(root);
root.setExpanded(true);
}
private TreeItem<File> create(File file) {
TreeItem<File> item = new TreeItem<>(file);
if (file.isDirectory()) {
File[] files = listFilteredFiles(file);
if (files != null && files.length > 0) {
TreeItem<File> placeholder = new TreeItem<File>(null) {
@Override
public String toString() {
return "Loading...";
}
};
item.getChildren().add(placeholder);
item.expandedProperty().addListener((obs, oldVal, newVal) -> {
if (newVal && item.getChildren().size() == 1) {
TreeItem<File> ph = item.getChildren().get(0);
if (ph.getValue() == null) {
item.getChildren().clear();
loadChildren(item);
}
}
});
}
}
return item;
}
private void loadChildren(TreeItem<File> parent) {
File[] files = listFilteredFiles(parent.getValue());
if (files != null) {
for (File child : files) {
parent.getChildren().add(create(child));
}
}
}
private File[] listFilteredFiles(File directory) {
if (directory == null)
return null;
File[] files = directory.listFiles();
if (files == null)
return null;
File[] filtered = Arrays.stream(files)
.filter(f -> !shouldFilter(f.getName()))
.sorted()
.toArray(File[]::new);
return filtered.length > 0 ? filtered : null;
}
private boolean shouldFilter(String name) {
for (String filter : FILTERED_NAMES) {
if (filter.startsWith("*")) {
String ext = filter.substring(1);
if (name.endsWith(ext))
return true;
} else if (name.equals(filter) || name.startsWith(filter)) {
return true;
}
}
return false;
}
}
package com.projectwizard.view.explorer;
import java.io.File;
import javafx.geometry.Insets;
import javafx.scene.control.TreeCell;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2AL;
import org.kordamp.ikonli.material2.Material2MZ;
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;
import org.kordamp.ikonli.fontawesome5.FontAwesomeBrands;
/**
* FileTreeCell with Professional Icons and Syntax Highlighting Colors
*/
public class FileTreeCell extends TreeCell<File> {
@Override
protected void updateItem(File item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
String displayName = item.getName().isBlank()
? item.getAbsolutePath()
: item.getName();
FontIcon icon = getFileIcon(item);
String styleClass = getFileStyleClass(item);
icon.getStyleClass().add(styleClass);
icon.setIconSize(16);
Text nameText = new Text(displayName);
nameText.getStyleClass().add(styleClass);
HBox hbox = new HBox(8, icon, nameText);
hbox.setPadding(new Insets(2));
setGraphic(hbox);
setText(null);
}
}
private String getFileStyleClass(File file) {
if (file.isDirectory()) return "file-folder";
String name = file.getName().toLowerCase();
if (name.endsWith(".java")) return "file-java";
if (name.endsWith(".xml") || name.endsWith(".fxml")) return "file-xml";
if (name.endsWith(".md")) return "file-md";
if (name.endsWith(".sh") || name.endsWith(".bat")) return "file-sh";
if (name.endsWith(".js") || name.endsWith(".ts")) return "file-js";
if (name.endsWith(".css") || name.endsWith(".scss")) return "file-css";
if (name.endsWith(".json")) return "file-json";
return "file-default";
}
private FontIcon getFileIcon(File file) {
if (file.isDirectory()) {
String name = file.getName().toLowerCase();
if (name.equals("src")) return new FontIcon(Material2MZ.SOURCE);
if (name.equals("test")) return new FontIcon(Material2MZ.SCIENCE);
if (name.equals("resources")) return new FontIcon(Material2MZ.STORAGE);
if (name.equals("target") || name.equals("build")) return new FontIcon(Material2AL.BUILD);
if (name.equals(".git")) return new FontIcon(Material2AL.ACCOUNT_TREE);
return new FontIcon(Material2AL.FOLDER);
}
String name = file.getName().toLowerCase();
if (name.endsWith(".java")) return new FontIcon(FontAwesomeSolid.COFFEE);
if (name.endsWith(".xml") || name.endsWith(".fxml")) return new FontIcon(Material2AL.CODE);
if (name.endsWith(".md")) return new FontIcon(Material2AL.DESCRIPTION);
if (name.endsWith(".sh") || name.endsWith(".bat")) return new FontIcon(FontAwesomeSolid.TERMINAL);
if (name.endsWith(".js") || name.endsWith(".ts")) return new FontIcon(FontAwesomeBrands.JS);
if (name.endsWith(".css") || name.endsWith(".scss")) return new FontIcon(Material2MZ.PALETTE);
if (name.endsWith(".json")) return new FontIcon(Material2MZ.SETTINGS_ETHERNET);
if (name.startsWith(".")) return new FontIcon(Material2AL.LOCK);
return new FontIcon(Material2AL.INSERT_DRIVE_FILE);
}
}
package com.projectwizard.view.git;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
public class GitView extends BorderPane {
public GitView() {
Label label = new Label("Git");
label.setStyle(
"-fx-font-size:28px;" +
"-fx-font-weight:bold;"
);
setCenter(label);
BorderPane.setAlignment(label, Pos.CENTER);
}
}
package com.projectwizard.view;
import com.projectwizard.core.navigation.NavigationController;
import com.projectwizard.view.dashboard.DashboardView;
import javafx.scene.Node;
import javafx.scene.layout.BorderPane;
public class WorkspacePane extends BorderPane {
private static WorkspacePane instance;
public WorkspacePane() {
instance = this;
NavigationController.getInstance().setWorkspace(this);
showDashboard();
}
public static WorkspacePane getInstance() {
return instance;
}
public void setContent(Node node) {
setCenter(node);
}
public void showDashboard() {
setContent(new DashboardView());
}
}
package com.projectwizard.view.editor;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.FileChooser;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.projectwizard.core.ApplicationContext;
import com.projectwizard.service.PersistenceService;
public class EditorHost extends BorderPane {
private final TabPane tabPane = new TabPane();
private final PersistenceService persistence = new PersistenceService();
public EditorHost() {
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
setupToolBar();
setCenter(tabPane);
// Salvar estado quando abas mudam
tabPane.getTabs().addListener((javafx.collections.ListChangeListener.Change<? extends Tab> c) -> {
saveState();
});
}
private void saveState() {
List<String> paths = tabPane.getTabs().stream()
.filter(t -> t.getContent() instanceof EditorPane)
.map(t -> ((EditorPane) t.getContent()).getFile().getAbsolutePath())
.collect(Collectors.toList());
persistence.saveOpenFiles(paths);
}
public void restoreState() {
List<String> paths = persistence.getOpenFiles();
for (String path : paths) {
File file = new File(path);
if (file.exists() && file.isFile()) {
openFile(file);
}
}
}
private void setupToolBar() {
Button btnSave = new Button("💾 Save");
Button btnSaveAs = new Button("📂 Save As...");
btnSave.setOnAction(e -> handleSave());
btnSaveAs.setOnAction(e -> handleSaveAs());
setTop(new ToolBar(btnSave, btnSaveAs));
}
private void handleSave() {
Tab selected = tabPane.getSelectionModel().getSelectedItem();
if (selected != null && selected.getContent() instanceof EditorPane pane) {
try {
ApplicationContext.getInstance().getFileSystemService().saveFile(pane.getFile(), pane.getText());
} catch (Exception ex) {
ApplicationContext.getInstance().getDialogService().showError("Error", ex.getMessage());
}
}
}
private void handleSaveAs() {
Tab selected = tabPane.getSelectionModel().getSelectedItem();
if (selected != null && selected.getContent() instanceof EditorPane pane) {
FileChooser chooser = new FileChooser();
File file = chooser.showSaveDialog(getScene().getWindow());
if (file != null) {
try {
ApplicationContext.getInstance().getFileSystemService().saveFile(file, pane.getText());
selected.setText(file.getName());
} catch (Exception ex) {
ApplicationContext.getInstance().getDialogService().showError("Error", ex.getMessage());
}
}
}
}
// Sobrecarga para aceitar apenas o File (Lê o conteúdo automaticamente)
public void openFile(File file) {
try {
String content = Files.readString(file.toPath());
openFile(file, content);
} catch (Exception e) {
ApplicationContext.getInstance().getDialogService().showError("Read Error", e.getMessage());
}
}
public void openFile(File file, String content) {
// Verifica se o arquivo já está aberto para evitar duplicidade
for (Tab tab : tabPane.getTabs()) {
if (tab.getText().equals(file.getName())) {
tabPane.getSelectionModel().select(tab);
return;
}
}
Tab tab = new Tab(file.getName());
tab.setContent(new EditorPane(file, content));
tabPane.getTabs().add(tab);
tabPane.getSelectionModel().select(tab);
}
public void clear() {
tabPane.getTabs().clear();
}
public int getOpenTabCount() {
return tabPane.getTabs().size();
}
}
package com.projectwizard.view.editor;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
public final class EditorSupport {
private static final String[] TEXT_EXTENSIONS = {
".java", ".xml", ".json", ".properties", ".yml", ".yaml",
".md", ".txt", ".html", ".fxml", ".css", ".scss", ".sql", ".sh",
".gradle", ".kt", ".groovy", ".toml", ".ini", ".cfg", ".log",
".js", ".jsx", ".ts", ".tsx", ".py", ".pyw", ".bat", ".cmd"
};
private static final int MAX_PREVIEW_CHARS = 50_000;
private EditorSupport() {
}
public static boolean isTextFile(File file) {
if (file == null) {
return false;
}
String name = file.getName().toLowerCase();
for (String ext : TEXT_EXTENSIONS) {
if (name.endsWith(ext)) {
return true;
}
}
return false;
}
public static String readFileContent(File file) throws Exception {
if (!isTextFile(file)) {
return "[Binary file: " + file.getName() + "]";
}
String content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
if (content.length() > MAX_PREVIEW_CHARS) {
int remaining = content.length() - MAX_PREVIEW_CHARS;
content = content.substring(0, MAX_PREVIEW_CHARS)
+ "\n\n... [Truncated: " + remaining + " chars] ...";
}
return content;
}
public static String formatSize(long bytes) {
if (bytes <= 0) {
return "0 B";
}
final String[] units = {"B", "KB", "MB", "GB"};
int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
digitGroups = Math.min(digitGroups, units.length - 1);
return String.format("%.1f %s", bytes / Math.pow(1024, digitGroups), units[digitGroups]);
}
}
package com.projectwizard.view.editor;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import javafx.concurrent.Task;
import javafx.scene.layout.BorderPane;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import com.projectwizard.service.editor.JetBrainsSyntaxScanner;
/**
* EditorPane com Realce de Sintaxe Industrial.
*/
public class EditorPane extends BorderPane {
private static final long MAX_FILE_SIZE = 1024 * 1024; // 1MB
private final CodeArea codeArea = new CodeArea();
private final JetBrainsSyntaxScanner scanner = new JetBrainsSyntaxScanner();
private File currentFile;
public EditorPane(File file, String content) {
this.currentFile = file;
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
codeArea.replaceText(content);
if (file != null && file.length() > MAX_FILE_SIZE) {
System.err.println("[JDT] Arquivo muito grande para realce.");
setCenter(new VirtualizedScrollPane<>(codeArea));
return;
}
// Listener assíncrono para manter a UI fluida
codeArea.multiPlainChanges().subscribe(ignore -> runHighlightingAsync());
// Realce da linha atual
codeArea.setParagraphStyle(0, Collections.singleton("current-line"));
codeArea.caretPositionProperty().addListener((obs, oldPos, newPos) -> {
int oldLine = codeArea.offsetToPosition(oldPos, CodeArea.Bias.Forward).getMajor();
int newLine = codeArea.offsetToPosition(newPos, CodeArea.Bias.Forward).getMajor();
if (oldLine != newLine) {
codeArea.setParagraphStyle(oldLine, Collections.emptyList());
codeArea.setParagraphStyle(newLine, Collections.singleton("current-line"));
}
});
runHighlightingAsync();
setCenter(new VirtualizedScrollPane<>(codeArea));
}
private void runHighlightingAsync() {
String text = codeArea.getText();
Task<StyleSpans<Collection<String>>> highlightTask = new Task<>() {
@Override
protected StyleSpans<Collection<String>> call() {
return computeHighlighting(text);
}
};
highlightTask.setOnSucceeded(
e -> codeArea.setStyleSpans(0, highlightTask.getValue()));
Thread thread = new Thread(highlightTask);
thread.setDaemon(true);
thread.start();
}
private StyleSpans<Collection<String>> computeHighlighting(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder =
new StyleSpansBuilder<>();
final int[] lastKwEnd = { 0 };
String processableText = text.length() > 50000
? text.substring(0, 50000)
: text;
String fileName = currentFile != null ? currentFile.getName() : "Main.java";
scanner.tokenize(processableText, fileName, (type, start, end) -> {
int spacer = start - lastKwEnd[0];
if (spacer > 0) {
spansBuilder.add(Collections.singleton("token-default"), spacer);
}
spansBuilder.add(Collections.singleton(type), end - start);
lastKwEnd[0] = end;
});
int remaining = text.length() - lastKwEnd[0];
if (remaining > 0) {
spansBuilder.add(Collections.singleton("token-default"), remaining);
}
return spansBuilder.create();
}
public String getText() {
return codeArea.getText();
}
public File getFile() {
return currentFile;
}
}package com.projectwizard.view.about;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
public class AboutView extends BorderPane {
public AboutView() {
Label label = new Label("About Project Wizard");
label.setStyle(
"-fx-font-size:28px;" +
"-fx-font-weight:bold;"
);
setCenter(label);
BorderPane.setAlignment(label, Pos.CENTER);
}
}
package com.projectwizard.view.settings;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
public class SettingsView extends BorderPane {
public SettingsView() {
Label label = new Label("Settings");
label.setStyle(
"-fx-font-size:28px;" +
"-fx-font-weight:bold;"
);
setCenter(label);
BorderPane.setAlignment(label, Pos.CENTER);
}
}
package com.projectwizard.view.templates;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
public class TemplatesView extends BorderPane {
public TemplatesView() {
Label label = new Label("Templates");
label.setStyle(
"-fx-font-size:28px;" +
"-fx-font-weight:bold;"
);
setCenter(label);
BorderPane.setAlignment(label, Pos.CENTER);
}
}
package com.projectwizard.view.newproject;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class NewProjectView extends BorderPane {
public NewProjectView() {
setPadding(new Insets(20));
VBox left = new VBox(15);
left.getChildren().addAll(
createStep("① Project"),
createStep("② Language"),
createStep("③ Framework"),
createStep("④ Dependencies"),
createStep("⑤ Git"),
createStep("⑥ Summary")
);
left.setPrefWidth(220);
GridPane form = new GridPane();
form.setHgap(10);
form.setVgap(12);
Label title = new Label("Create New Project");
title.setStyle(
"-fx-font-size:26px;" +
"-fx-font-weight:bold;"
);
TextField projectName = new TextField();
TextField group = new TextField("com.example");
TextField artifact = new TextField();
ComboBox<String> language = new ComboBox<>();
language.getItems().addAll(
"Java",
"Kotlin",
"Groovy"
);
language.getSelectionModel().selectFirst();
ComboBox<String> build = new ComboBox<>();
build.getItems().addAll(
"Maven",
"Gradle"
);
build.getSelectionModel().selectFirst();
form.add(title,0,0,2,1);
form.add(new Label("Project Name"),0,1);
form.add(projectName,1,1);
form.add(new Label("Group"),0,2);
form.add(group,1,2);
form.add(new Label("Artifact"),0,3);
form.add(artifact,1,3);
form.add(new Label("Language"),0,4);
form.add(language,1,4);
form.add(new Label("Build Tool"),0,5);
form.add(build,1,5);
HBox buttons = new HBox(10);
Button back = new Button("◀ Back");
Button next = new Button("Next ▶");
Button finish = new Button("Finish");
buttons.getChildren().addAll(
back,
next,
finish
);
buttons.setAlignment(Pos.CENTER_RIGHT);
VBox center = new VBox(20);
center.getChildren().addAll(
form,
new Separator(),
buttons
);
setLeft(left);
setCenter(center);
}
private Label createStep(String text){
Label label = new Label(text);
label.setMaxWidth(Double.MAX_VALUE);
label.setStyle(
"-fx-font-size:15px;" +
"-fx-padding:8;"
);
return label;
}
}
package com.projectwizard.view;
import com.projectwizard.core.ApplicationContext;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MainWindow {
private final ApplicationContext context =
ApplicationContext.getInstance();
public void show(Stage stage) {
BorderPane root = new BorderPane();
MenuBar menuBar = new MenuBar();
Menu file = new Menu("File");
Menu help = new Menu("Help");
MenuItem exit = new MenuItem("Exit");
exit.setOnAction(e -> stage.close());
MenuItem about = new MenuItem("About");
about.setOnAction(e ->
context.getDialogService().showInformation(
"About",
context.getApplicationName()
+ "\nVersion "
+ context.getVersion()
)
);