Skip to content

Commit

Permalink
梳理SyntaxTextViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
rememberber committed Oct 30, 2023
1 parent 00b4075 commit fcba251
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ private void changeTheme(String selectedThemeName) {
HostForm.getInstance().updateTheme();
HostForm.getInstance().getScrollPane().updateUI();

RegexForm.getInstance().updateTheme();
RegexForm.getInstance().getScrollPane().updateUI();
}

Expand Down
83 changes: 3 additions & 80 deletions src/main/java/com/luoboduner/moo/tool/ui/form/func/RegexForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,24 +10,20 @@
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;
import com.luoboduner.moo.tool.util.ScrollUtil;
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;

/**
Expand Down Expand Up @@ -74,7 +68,7 @@ public class RegexForm {
private JScrollPane commonRegexScrollPane;

private RegexSyntaxTextViewer textArea;
private RTextScrollPane scrollPane;
private RegexRTextScrollPane scrollPane;

private static RegexForm regexForm;

Expand All @@ -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();
Expand Down

0 comments on commit fcba251

Please sign in to comment.