2023年6月6日18:09:32
parent
d3c2ef1400
commit
3cc20a868a
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.resource.ClassPathResource;
|
||||||
import cn.hutool.core.io.resource.Resource;
|
import cn.hutool.core.io.resource.Resource;
|
||||||
import com.zhangmeng.tools.components.RecursiveFileList;
|
import com.zhangmeng.tools.components.RecursiveFileList;
|
||||||
import com.zhangmeng.tools.languages.ProcessGO;
|
import com.zhangmeng.tools.languages.ProcessGO;
|
||||||
|
import com.zhangmeng.tools.languages.ProcessHtml;
|
||||||
import com.zhangmeng.tools.languages.ProcessJava;
|
import com.zhangmeng.tools.languages.ProcessJava;
|
||||||
import com.zhangmeng.tools.utils.AlertUtils;
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
|
@ -13,6 +14,7 @@ import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.Event;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
|
@ -78,7 +80,7 @@ public class FileEditController {
|
||||||
|
|
||||||
private final SimpleIntegerProperty text_size = new SimpleIntegerProperty(15);
|
private final SimpleIntegerProperty text_size = new SimpleIntegerProperty(15);
|
||||||
private final SimpleIntegerProperty icon_size = new SimpleIntegerProperty(15);
|
private final SimpleIntegerProperty icon_size = new SimpleIntegerProperty(15);
|
||||||
private static final Map<Integer,Tab> map = new HashMap<>();
|
private static final Map<Path, Tab> map = new HashMap<>();
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
@ -91,17 +93,6 @@ public class FileEditController {
|
||||||
splitPane.getItems().add(1, tabPane);
|
splitPane.getItems().add(1, tabPane);
|
||||||
splitPane.setDividerPosition(0, 0.20);
|
splitPane.setDividerPosition(0, 0.20);
|
||||||
splitPane.setDividerPosition(1, 0.80);
|
splitPane.setDividerPosition(1, 0.80);
|
||||||
|
|
||||||
tabPane.getTabs().addListener(new ListChangeListener<Tab>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(Change<? extends Tab> c) {
|
|
||||||
if (c.next()){
|
|
||||||
if (c.wasRemoved()){
|
|
||||||
filePaths_list.remove(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
@ -237,8 +228,11 @@ public class FileEditController {
|
||||||
Path path = file.toPath();
|
Path path = file.toPath();
|
||||||
if (filePaths_list.contains(path)) {//size -1 ,szie -2
|
if (filePaths_list.contains(path)) {//size -1 ,szie -2
|
||||||
//切换到一打开的tab
|
//切换到一打开的tab
|
||||||
int i = filePaths_list.indexOf(path);
|
Tab tab = map.get(path);
|
||||||
tabPane.getSelectionModel().select(i);
|
if (!tabPane.getTabs().contains(tab)){
|
||||||
|
tabPane.getTabs().add(tab);
|
||||||
|
}
|
||||||
|
tabPane.getSelectionModel().select(tab);
|
||||||
} else {
|
} else {
|
||||||
CodeArea codeArea = new CodeArea();
|
CodeArea codeArea = new CodeArea();
|
||||||
URL resource = this.getClass().getClassLoader().getResource("css/code.css");
|
URL resource = this.getClass().getClassLoader().getResource("css/code.css");
|
||||||
|
|
@ -267,14 +261,19 @@ public class FileEditController {
|
||||||
});
|
});
|
||||||
codeArea.replaceText(0, 0, file_content);
|
codeArea.replaceText(0, 0, file_content);
|
||||||
Tab tab = new Tab(file.getName());
|
Tab tab = new Tab(file.getName());
|
||||||
|
|
||||||
|
tab.setOnCloseRequest(new EventHandler<Event>() {
|
||||||
|
@Override
|
||||||
|
public void handle(Event event) {
|
||||||
|
// log.info("tabtab.setOnCloseRequest:--->" + tab.getText());
|
||||||
|
tabPane.getTabs().remove(tab);
|
||||||
|
}
|
||||||
|
});
|
||||||
tab.setContent(new VirtualizedScrollPane<>(codeArea));
|
tab.setContent(new VirtualizedScrollPane<>(codeArea));
|
||||||
filePaths_list.add(path);
|
filePaths_list.add(path);
|
||||||
int i = index.get();
|
tabPane.getTabs().add( tab);
|
||||||
map.put(i,tab);
|
|
||||||
tabPane.getTabs().add(i,tab);
|
|
||||||
tabPane.getSelectionModel().select(tab);
|
tabPane.getSelectionModel().select(tab);
|
||||||
i ++;
|
map.put(path,tab);
|
||||||
index.set(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,6 +344,9 @@ public class FileEditController {
|
||||||
if (extension.equals("go")) {
|
if (extension.equals("go")) {
|
||||||
type = Type.GO;
|
type = Type.GO;
|
||||||
}
|
}
|
||||||
|
if (extension.equals("html")) {
|
||||||
|
type = Type.HTML;
|
||||||
|
}
|
||||||
|
|
||||||
open_file(file, type);
|
open_file(file, type);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -357,6 +359,9 @@ public class FileEditController {
|
||||||
if (type.equals(Type.GO)) {
|
if (type.equals(Type.GO)) {
|
||||||
matcher = ProcessGO.PATTERN.matcher(text);
|
matcher = ProcessGO.PATTERN.matcher(text);
|
||||||
}
|
}
|
||||||
|
if (type.equals(Type.HTML)) {
|
||||||
|
matcher = ProcessHtml.PATTERN.matcher(text);
|
||||||
|
}
|
||||||
int lastKwEnd = 0;
|
int lastKwEnd = 0;
|
||||||
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
|
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
package com.zhangmeng.tools.languages;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 芊芊墨客
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2023-06-01 11:01
|
||||||
|
*/
|
||||||
|
public class ProcessHtml {
|
||||||
|
|
||||||
|
public static final String[] KEYWORDS = new String[] {
|
||||||
|
"<!DOCTYPE html>", "<html>", "<head>", "</head>", "<body>",
|
||||||
|
"</body>", "</html>", "<p>", "<br>",
|
||||||
|
"<title>", "</title>", "style", "<img",
|
||||||
|
"<h1>", "</h1>", "<h3>", ">",
|
||||||
|
"<h2>", "</h2>", "</h3>", "<hr>",
|
||||||
|
"<a", "</a>", "<table","<div","<div>","</div>","<span","<span>","</span>",
|
||||||
|
"<ul>", "</ul>", "<dl>", "</dl>", "<dd>","</dl>"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final String[] KEYWORDS2 = new String[] {
|
||||||
|
"href", "name", "style", "finally", "id", "src",
|
||||||
|
"return"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final String KEYWORD_PATTERN = "\\b(" + String.join("|", KEYWORDS) + ")\\b";
|
||||||
|
public static final String KEYWORD_PATTERN2 = "\\b(" + String.join("|", KEYWORDS2) + ")\\b";
|
||||||
|
public static final String PAREN_PATTERN = "\\(|\\)";
|
||||||
|
public static final String BRACE_PATTERN = "\\{|\\}";
|
||||||
|
public static final String BRACKET_PATTERN = "\\[|\\]";
|
||||||
|
public static final String SEMICOLON_PATTERN = "\\;";
|
||||||
|
public static final String STRING_PATTERN = "\"([^\"\\\\]|\\\\.)*\"";
|
||||||
|
public static final String COMMENT_PATTERN = "//[^\n]*" + "|" + "/\\*(.|\\R)*?\\*/";
|
||||||
|
public static final String ANNOTATION_PATTERN = "@[a-zA-Z]+";
|
||||||
|
public static final String PARAMS_PATTERN = "\\\\b([a-zA-Z]+)\\\\s*=\\\\s*([a-zA-Z0-9]+)\\\\b";
|
||||||
|
public static final String METHOD_PATTERN = "\\w+\\((\\w+,\\s*)*\\w*\\)";
|
||||||
|
|
||||||
|
public static final Pattern PATTERN = Pattern.compile(
|
||||||
|
"(?<KEYWORD>" + KEYWORD_PATTERN + ")"
|
||||||
|
+ "|(?<KEYWORD2>" + KEYWORD_PATTERN2 + ")"
|
||||||
|
+ "|(?<PAREN>" + PAREN_PATTERN + ")"
|
||||||
|
+ "|(?<BRACE>" + BRACE_PATTERN + ")"
|
||||||
|
+ "|(?<BRACKET>" + BRACKET_PATTERN + ")"
|
||||||
|
+ "|(?<SEMICOLON>" + SEMICOLON_PATTERN + ")"
|
||||||
|
+ "|(?<STRING>" + STRING_PATTERN + ")"
|
||||||
|
+ "|(?<COMMENT>" + COMMENT_PATTERN + ")"
|
||||||
|
+ "|(?<ANNOTATION>" + ANNOTATION_PATTERN + ")"
|
||||||
|
+ "|(?<PARAMS>" + PARAMS_PATTERN + ")"
|
||||||
|
+ "|(?<METHOD>" + METHOD_PATTERN + ")"
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
public static String SAMPLE_CODE = "package com.dashidao.server.model;\n" +
|
||||||
|
"\n" +
|
||||||
|
"import java.util.Date;\n" +
|
||||||
|
"\n" +
|
||||||
|
"public class PosterGroupCouponCode extends BaseEntity<Long> {\n" +
|
||||||
|
"\n" +
|
||||||
|
"\tprivate Date addTime;\n" +
|
||||||
|
"\tprivate Boolean deleteStatus;\n" +
|
||||||
|
"\tprivate String groupCouponCode;\n" +
|
||||||
|
"\tprivate Integer groupCouponStatus;\n" +
|
||||||
|
"\tprivate Date writeOffTime;\n" +
|
||||||
|
"\tprivate Long orderFormId;\n" +
|
||||||
|
"\tprivate Long posterGoodsCartId;\n" +
|
||||||
|
"\tprivate Long tuiKuanShouHouId;\n" +
|
||||||
|
"\tprivate Long orderMealUserId;\n" +
|
||||||
|
"\tprivate String groupSkusJson;\n" +
|
||||||
|
"\n" +
|
||||||
|
"\tpublic Date getAddTime() {\n" +
|
||||||
|
"\t\treturn addTime;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setAddTime(Date addTime) {\n" +
|
||||||
|
"\t\tthis.addTime = addTime;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Boolean getDeleteStatus() {\n" +
|
||||||
|
"\t\treturn deleteStatus;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setDeleteStatus(Boolean deleteStatus) {\n" +
|
||||||
|
"\t\tthis.deleteStatus = deleteStatus;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic String getGroupCouponCode() {\n" +
|
||||||
|
"\t\treturn groupCouponCode;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setGroupCouponCode(String groupCouponCode) {\n" +
|
||||||
|
"\t\tthis.groupCouponCode = groupCouponCode;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Integer getGroupCouponStatus() {\n" +
|
||||||
|
"\t\treturn groupCouponStatus;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setGroupCouponStatus(Integer groupCouponStatus) {\n" +
|
||||||
|
"\t\tthis.groupCouponStatus = groupCouponStatus;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Date getWriteOffTime() {\n" +
|
||||||
|
"\t\treturn writeOffTime;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setWriteOffTime(Date writeOffTime) {\n" +
|
||||||
|
"\t\tthis.writeOffTime = writeOffTime;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Long getOrderFormId() {\n" +
|
||||||
|
"\t\treturn orderFormId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setOrderFormId(Long orderFormId) {\n" +
|
||||||
|
"\t\tthis.orderFormId = orderFormId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Long getPosterGoodsCartId() {\n" +
|
||||||
|
"\t\treturn posterGoodsCartId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setPosterGoodsCartId(Long posterGoodsCartId) {\n" +
|
||||||
|
"\t\tthis.posterGoodsCartId = posterGoodsCartId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Long getTuiKuanShouHouId() {\n" +
|
||||||
|
"\t\treturn tuiKuanShouHouId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setTuiKuanShouHouId(Long tuiKuanShouHouId) {\n" +
|
||||||
|
"\t\tthis.tuiKuanShouHouId = tuiKuanShouHouId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic Long getOrderMealUserId() {\n" +
|
||||||
|
"\t\treturn orderMealUserId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setOrderMealUserId(Long orderMealUserId) {\n" +
|
||||||
|
"\t\tthis.orderMealUserId = orderMealUserId;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic String getGroupSkusJson() {\n" +
|
||||||
|
"\t\treturn groupSkusJson;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\tpublic void setGroupSkusJson(String groupSkusJson) {\n" +
|
||||||
|
"\t\tthis.groupSkusJson = groupSkusJson;\n" +
|
||||||
|
"\t}\n" +
|
||||||
|
"\n" +
|
||||||
|
"}\n";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue