44import com .xwintop .xJavaFxTool .view .debugTools .SwitchHostsToolView ;
55import javafx .concurrent .Task ;
66import javafx .event .ActionEvent ;
7+ import javafx .event .EventHandler ;
78import javafx .fxml .FXML ;
89import javafx .scene .control .TreeItem ;
10+ import javafx .scene .input .KeyCode ;
11+ import javafx .scene .input .KeyCodeCombination ;
12+ import javafx .scene .input .KeyCombination ;
13+ import javafx .scene .input .KeyEvent ;
914import lombok .Getter ;
1015import lombok .Setter ;
1116import lombok .extern .slf4j .Slf4j ;
12- import org .fxmisc .richtext .CodeArea ;
1317import org .fxmisc .richtext .LineNumberFactory ;
1418import org .fxmisc .richtext .model .StyleSpans ;
1519import org .fxmisc .richtext .model .StyleSpansBuilder ;
@@ -46,6 +50,7 @@ public class SwitchHostsToolController extends SwitchHostsToolView {
4650 @ Override
4751 public void initialize (URL location , ResourceBundle resources ) {
4852 try {
53+ executor = Executors .newSingleThreadExecutor ();
4954 initView ();
5055 initEvent ();
5156 initService ();
@@ -55,41 +60,48 @@ public void initialize(URL location, ResourceBundle resources) {
5560 }
5661
5762 private void initView () {
58- executor = Executors .newSingleThreadExecutor ();
59- hostTextArea = new CodeArea ();
63+ hostTextArea .getStylesheets ().add (getClass ().getClassLoader ().getResource ("css/debugTools/hosts-keywords.css" ).toExternalForm ());
6064 hostTextArea .setParagraphGraphicFactory (LineNumberFactory .get (hostTextArea ));
6165 hostTextArea .richChanges ()
6266 .filter (ch -> !ch .getInserted ().equals (ch .getRemoved ())) // XXX
6367 .successionEnds (Duration .ofMillis (500 ))
6468 .supplyTask (this ::computeHighlightingAsync )
6569 .awaitLatest (hostTextArea .richChanges ())
6670 .filterMap (t -> {
67- if (t .isSuccess ()) {
71+ if (t .isSuccess ()) {
6872 return Optional .of (t .get ());
6973 } else {
7074 t .getFailure ().printStackTrace ();
7175 return Optional .empty ();
7276 }
7377 })
7478 .subscribe (this ::applyHighlighting );
79+ hostTextArea .setOnKeyPressed (new EventHandler <KeyEvent >() {
80+ @ Override
81+ public void handle (KeyEvent event ) {
82+ if (new KeyCodeCombination (KeyCode .S , KeyCombination .CONTROL_DOWN ).match (event )) {
83+ switchHostsToolService .editAction ();
84+ }
7585
86+ }
87+ });
7688 TreeItem <String > treeItem = new TreeItem <String >("Hosts" );
7789 treeItem .setExpanded (true );
7890 hostFileTreeView .setRoot (treeItem );
79- TreeItem <String > commonHostTreeItem = new TreeItem <String >("公共Host" );
91+ // TreeItem<String> commonHostTreeItem = new TreeItem<String>("公共Host");
8092 TreeItem <String > systemHostTreeItem = new TreeItem <String >("系统当前Host" );
81- TreeItem <String > localHostTreeItem = new TreeItem <String >("本地方案" );
82- localHostTreeItem .setExpanded (true );
83- TreeItem <String > localHostTreeItem1 = new TreeItem <String >("方案一" );
84- TreeItem <String > localHostTreeItem2 = new TreeItem <String >("方案二" );
85- localHostTreeItem .getChildren ().add (localHostTreeItem1 );
86- localHostTreeItem .getChildren ().add (localHostTreeItem2 );
87- TreeItem <String > webTreeItem = new TreeItem <String >("在线方案" );
88- webTreeItem .setExpanded (true );
89- treeItem .getChildren ().add (commonHostTreeItem );
93+ // TreeItem<String> localHostTreeItem = new TreeItem<String>("本地方案");
94+ // localHostTreeItem.setExpanded(true);
95+ // TreeItem<String> localHostTreeItem1 = new TreeItem<String>("方案一");
96+ // TreeItem<String> localHostTreeItem2 = new TreeItem<String>("方案二");
97+ // localHostTreeItem.getChildren().add(localHostTreeItem1);
98+ // localHostTreeItem.getChildren().add(localHostTreeItem2);
99+ // TreeItem<String> webTreeItem = new TreeItem<String>("在线方案");
100+ // webTreeItem.setExpanded(true);
101+ // treeItem.getChildren().add(commonHostTreeItem);
90102 treeItem .getChildren ().add (systemHostTreeItem );
91- treeItem .getChildren ().add (localHostTreeItem );
92- treeItem .getChildren ().add (webTreeItem );
103+ // treeItem.getChildren().add(localHostTreeItem);
104+ // treeItem.getChildren().add(webTreeItem);
93105 }
94106
95107 private void initEvent () {
@@ -138,11 +150,12 @@ private static StyleSpans<Collection<String>> computeHighlighting(String text) {
138150 int lastKwEnd = 0 ;
139151 StyleSpansBuilder <Collection <String >> spansBuilder
140152 = new StyleSpansBuilder <>();
141- while (matcher .find ()) {
153+ while (matcher .find ()) {
142154 String styleClass =
143155 matcher .group ("KEYWORD" ) != null ? "keyword" :
144156 matcher .group ("COMMENT" ) != null ? "comment" :
145- null ; /* never happens */ assert styleClass != null ;
157+ null ; /* never happens */
158+ assert styleClass != null ;
146159 spansBuilder .add (Collections .emptyList (), matcher .start () - lastKwEnd );
147160 spansBuilder .add (Collections .singleton (styleClass ), matcher .end () - matcher .start ());
148161 lastKwEnd = matcher .end ();
0 commit comments