diff --git a/src/main/java/com/luoboduner/moo/tool/ui/component/RegexRTextScrollPane.java b/src/main/java/com/luoboduner/moo/tool/ui/component/RegexRTextScrollPane.java new file mode 100644 index 00000000..156003d4 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/tool/ui/component/RegexRTextScrollPane.java @@ -0,0 +1,34 @@ +package com.luoboduner.moo.tool.ui.component; + +import com.formdev.flatlaf.FlatLaf; +import com.luoboduner.moo.tool.App; +import org.fife.ui.rtextarea.Gutter; +import org.fife.ui.rtextarea.RTextScrollPane; + +import javax.swing.*; +import java.awt.*; + +public class RegexRTextScrollPane extends RTextScrollPane { + // constructor + public RegexRTextScrollPane(RegexSyntaxTextViewer textArea) { + super(textArea); + + setMaximumSize(new Dimension(-1, -1)); + setMinimumSize(new Dimension(-1, -1)); + + Color defaultBackground = App.mainFrame.getBackground(); + + Gutter gutter = getGutter(); + if (FlatLaf.isLafDark()) { + gutter.setBorderColor(gutter.getLineNumberColor().darker()); + } else { + gutter.setBorderColor(gutter.getLineNumberColor().brighter()); + } + gutter.setBackground(defaultBackground); + Font font2 = new Font(App.config.getFont(), Font.PLAIN, App.config.getFontSize()); + gutter.setLineNumberFont(font2); + gutter.setBackground(UIManager.getColor("Editor.gutter.background")); + gutter.setBorderColor(UIManager.getColor("Editor.gutter.borderColor")); + gutter.setLineNumberColor(UIManager.getColor("Editor.gutter.lineNumberColor")); + } +} diff --git a/src/main/java/com/luoboduner/moo/tool/ui/component/RegexSyntaxTextViewer.java b/src/main/java/com/luoboduner/moo/tool/ui/component/RegexSyntaxTextViewer.java index f53b5aa3..0c76ea15 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/component/RegexSyntaxTextViewer.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/component/RegexSyntaxTextViewer.java @@ -1,10 +1,68 @@ package com.luoboduner.moo.tool.ui.component; +import com.formdev.flatlaf.FlatLaf; +import com.luoboduner.moo.tool.App; +import com.luoboduner.moo.tool.ui.form.func.TimeConvertForm; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; +import org.fife.ui.rsyntaxtextarea.Theme; + +import javax.swing.*; +import java.awt.*; +import java.io.IOException; public class RegexSyntaxTextViewer extends RSyntaxTextArea { public RegexSyntaxTextViewer() { setDoubleBuffered(true); + + try { + Theme theme; + if (FlatLaf.isLafDark()) { + theme = Theme.load(RegexSyntaxTextViewer.class.getResourceAsStream( + "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml")); + } else { + theme = Theme.load(RegexSyntaxTextViewer.class.getResourceAsStream( + "/org/fife/ui/rsyntaxtextarea/themes/idea.xml")); + } + theme.apply(this); + } catch (IOException ioe) { // Never happens + ioe.printStackTrace(); + } + + setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); + setCodeFoldingEnabled(true); +// setCurrentLineHighlightColor(new Color(52, 52, 52)); +// setUseSelectedTextColor(true); +// setSelectedTextColor(new Color(50, 50, 50)); + + // 初始化背景色 +// Style.blackTextArea(this); + setBackground(TimeConvertForm.getInstance().getTimeHisTextArea().getBackground()); + // 初始化边距 + setMargin(new Insets(10, 10, 10, 10)); + + // 初始化字体 + String fontName = App.config.getJsonBeautyFontName(); + int fontSize = App.config.getJsonBeautyFontSize(); + if (fontSize == 0) { + fontSize = getFont().getSize() + 2; + } + Font font = new Font(fontName, Font.PLAIN, fontSize); + setFont(font); + + setHyperlinksEnabled(false); + + + setBackground(UIManager.getColor("Editor.background")); + setCaretColor(UIManager.getColor("Editor.caretColor")); + setSelectionColor(UIManager.getColor("Editor.selectionBackground")); + setCurrentLineHighlightColor(UIManager.getColor("Editor.currentLineHighlight")); + setMarkAllHighlightColor(UIManager.getColor("Editor.markAllHighlightColor")); + setMarkOccurrencesColor(UIManager.getColor("Editor.markOccurrencesColor")); + setMatchedBracketBGColor(UIManager.getColor("Editor.matchedBracketBackground")); + setMatchedBracketBorderColor(UIManager.getColor("Editor.matchedBracketBorderColor")); + setPaintMatchedBracketPair(true); + setAnimateBracketMatching(false); } } diff --git a/src/main/java/com/luoboduner/moo/tool/ui/component/TopMenuBar.java b/src/main/java/com/luoboduner/moo/tool/ui/component/TopMenuBar.java index 0f9b4c07..20745175 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/component/TopMenuBar.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/component/TopMenuBar.java @@ -434,7 +434,6 @@ private void changeTheme(String selectedThemeName) { HostForm.getInstance().updateTheme(); HostForm.getInstance().getScrollPane().updateUI(); - RegexForm.getInstance().updateTheme(); RegexForm.getInstance().getScrollPane().updateUI(); } diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/func/RegexForm.java b/src/main/java/com/luoboduner/moo/tool/ui/form/func/RegexForm.java index f1ff2f4d..9a4dc7a6 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/form/func/RegexForm.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/func/RegexForm.java @@ -2,8 +2,6 @@ import cn.hutool.log.Log; import cn.hutool.log.LogFactory; -import com.formdev.flatlaf.FlatLaf; -import com.formdev.flatlaf.extras.FlatSVGIcon; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; @@ -12,6 +10,7 @@ import com.luoboduner.moo.tool.domain.TFuncContent; import com.luoboduner.moo.tool.ui.FuncConsts; import com.luoboduner.moo.tool.ui.component.CustomizeIcon; +import com.luoboduner.moo.tool.ui.component.RegexRTextScrollPane; import com.luoboduner.moo.tool.ui.component.RegexSyntaxTextViewer; import com.luoboduner.moo.tool.ui.listener.func.RegexListener; import com.luoboduner.moo.tool.util.MybatisUtil; @@ -19,17 +18,12 @@ import com.luoboduner.moo.tool.util.SqliteUtil; import com.luoboduner.moo.tool.util.UndoUtil; import lombok.Getter; -import org.fife.ui.rsyntaxtextarea.SyntaxConstants; -import org.fife.ui.rsyntaxtextarea.Theme; -import org.fife.ui.rtextarea.Gutter; -import org.fife.ui.rtextarea.RTextScrollPane; import javax.swing.*; import javax.swing.border.TitledBorder; import javax.swing.plaf.FontUIResource; import javax.swing.text.StyleContext; import java.awt.*; -import java.io.IOException; import java.util.Locale; /** @@ -74,7 +68,7 @@ public class RegexForm { private JScrollPane commonRegexScrollPane; private RegexSyntaxTextViewer textArea; - private RTextScrollPane scrollPane; + private RegexRTextScrollPane scrollPane; private static RegexForm regexForm; @@ -84,82 +78,11 @@ public class RegexForm { private RegexForm() { textArea = new RegexSyntaxTextViewer(); - scrollPane = new RTextScrollPane(textArea); - - updateTheme(); + scrollPane = new RegexRTextScrollPane(textArea); UndoUtil.register(this); } - public void updateTheme() { - try { - Theme theme; - if (FlatLaf.isLafDark()) { - theme = Theme.load(RegexSyntaxTextViewer.class.getResourceAsStream( - "/org/fife/ui/rsyntaxtextarea/themes/monokai.xml")); - } else { - theme = Theme.load(RegexSyntaxTextViewer.class.getResourceAsStream( - "/org/fife/ui/rsyntaxtextarea/themes/idea.xml")); - } - theme.apply(textArea); - } catch (IOException ioe) { // Never happens - ioe.printStackTrace(); - } - - textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); - textArea.setCodeFoldingEnabled(true); -// setCurrentLineHighlightColor(new Color(52, 52, 52)); -// setUseSelectedTextColor(true); -// setSelectedTextColor(new Color(50, 50, 50)); - - // 初始化背景色 -// Style.blackTextArea(this); - textArea.setBackground(TimeConvertForm.getInstance().getTimeHisTextArea().getBackground()); - // 初始化边距 - textArea.setMargin(new Insets(10, 10, 10, 10)); - - // 初始化字体 - String fontName = App.config.getJsonBeautyFontName(); - int fontSize = App.config.getJsonBeautyFontSize(); - if (fontSize == 0) { - fontSize = textArea.getFont().getSize() + 2; - } - Font font = new Font(fontName, Font.PLAIN, fontSize); - textArea.setFont(font); - - textArea.setHyperlinksEnabled(false); - - - textArea.setBackground(UIManager.getColor("Editor.background")); - textArea.setCaretColor(UIManager.getColor("Editor.caretColor")); - textArea.setSelectionColor(UIManager.getColor("Editor.selectionBackground")); - textArea.setCurrentLineHighlightColor(UIManager.getColor("Editor.currentLineHighlight")); - textArea.setMarkAllHighlightColor(UIManager.getColor("Editor.markAllHighlightColor")); - textArea.setMarkOccurrencesColor(UIManager.getColor("Editor.markOccurrencesColor")); - textArea.setMatchedBracketBGColor(UIManager.getColor("Editor.matchedBracketBackground")); - textArea.setMatchedBracketBorderColor(UIManager.getColor("Editor.matchedBracketBorderColor")); - textArea.setPaintMatchedBracketPair(true); - textArea.setAnimateBracketMatching(false); - - scrollPane.setMaximumSize(new Dimension(-1, -1)); - scrollPane.setMinimumSize(new Dimension(-1, -1)); - - Color defaultBackground = App.mainFrame.getBackground(); - - Gutter gutter = scrollPane.getGutter(); - if (FlatLaf.isLafDark()) { - gutter.setBorderColor(gutter.getLineNumberColor().darker()); - } else { - gutter.setBorderColor(gutter.getLineNumberColor().brighter()); - } - gutter.setBackground(defaultBackground); - Font font2 = new Font(App.config.getFont(), Font.PLAIN, App.config.getFontSize()); - gutter.setLineNumberFont(font2); - gutter.setBackground(UIManager.getColor("Editor.gutter.background")); - gutter.setBorderColor(UIManager.getColor("Editor.gutter.borderColor")); - gutter.setLineNumberColor(UIManager.getColor("Editor.gutter.lineNumberColor")); - } - public static RegexForm getInstance() { if (regexForm == null) { regexForm = new RegexForm();