From c8fc999da30c0dbb3f5faf6ffaa8a52447ad28d0 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Mon, 23 Oct 2023 10:56:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=9A=8F=E6=89=8B=E8=AE=B0=E6=92=A4=E9=94=80=E5=A4=A7=E9=87=8F?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=9B=BF=E6=8D=A2=E6=97=B6=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +-- .../ui/listener/func/QuickNoteListener.java | 37 ++++++++++++------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index fcad4319..b0b39fa6 100644 --- a/pom.xml +++ b/pom.xml @@ -32,9 +32,9 @@ 32.1.2-jre 4.11.0 3.5.1 - 3.2.1 - 3.2.1 - 3.2.1 + 3.2.5 + 3.2.5 + 3.2.5 2.242 3.3.4 2.0.4 diff --git a/src/main/java/com/luoboduner/moo/tool/ui/listener/func/QuickNoteListener.java b/src/main/java/com/luoboduner/moo/tool/ui/listener/func/QuickNoteListener.java index 14b7a5fc..80cd7cf7 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/listener/func/QuickNoteListener.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/listener/func/QuickNoteListener.java @@ -36,6 +36,8 @@ import java.text.DecimalFormat; import java.util.Date; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** *
@@ -52,6 +54,9 @@ public class QuickNoteListener {
 
     public static String selectedName;
 
+    // 创建一个单线程的ExecutorService
+    public static ExecutorService executorService = Executors.newSingleThreadExecutor();
+
     public static void addListeners() {
         QuickNoteForm quickNoteForm = QuickNoteForm.getInstance();
         QuickNoteSyntaxTextViewerManager quickNoteSyntaxTextViewerManager = QuickNoteForm.quickNoteSyntaxTextViewerManager;
@@ -613,24 +618,28 @@ private static void deleteFiles(QuickNoteForm quickNoteForm) {
      * @param refreshModifiedTime
      */
     public static void quickSave(boolean refreshModifiedTime, boolean writeLog) {
-        String now = SqliteUtil.nowDateForSqlite();
-        if (selectedName != null) {
-            TQuickNote tQuickNote = new TQuickNote();
-            tQuickNote.setName(selectedName);
 
-            String text = QuickNoteForm.quickNoteSyntaxTextViewerManager.getTextByName(selectedName);
-            if (writeLog) {
-                log.info("save note: " + selectedName + ", content: " + text);
-            }
-            tQuickNote.setContent(text);
-            if (refreshModifiedTime) {
-                tQuickNote.setModifiedTime(now);
+        executorService.submit(() -> {
+            String now = SqliteUtil.nowDateForSqlite();
+            if (selectedName != null) {
+                TQuickNote tQuickNote = new TQuickNote();
+                tQuickNote.setName(selectedName);
+
+                String text = QuickNoteForm.quickNoteSyntaxTextViewerManager.getTextByName(selectedName);
+                if (writeLog) {
+                    log.info("save note: " + selectedName + ", content: " + text);
+                }
+                tQuickNote.setContent(text);
+                if (refreshModifiedTime) {
+                    tQuickNote.setModifiedTime(now);
+                }
+
+                quickNoteMapper.updateByName(tQuickNote);
             }
 
-            quickNoteMapper.updateByName(tQuickNote);
-        }
+            QuickNoteIndicatorTools.showTips("已保存:" + selectedName, QuickNoteIndicatorTools.TipsLevel.SUCCESS);
+        });
 
-        QuickNoteIndicatorTools.showTips("已保存:" + selectedName, QuickNoteIndicatorTools.TipsLevel.SUCCESS);
     }
 
     /**

From dcbbcf166efc98940a4df6ce1728de0998e246f0 Mon Sep 17 00:00:00 2001
From: felixnan168 
Date: Thu, 26 Oct 2023 13:36:15 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9EJava=E3=80=81Groovy?=
 =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=89=A7=E8=A1=8C=E5=99=A8=EF=BC=8C=E5=9C=A8?=
 =?UTF-8?q?MooTool=E5=B7=A5=E5=85=B7=E4=B8=AD=E5=8F=AF=E7=AE=80=E5=8D=95?=
 =?UTF-8?q?=E6=89=A7=E8=A1=8CJava=E6=88=96Groovy=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pom.xml                                       |   7 +
 .../moo/tool/ui/form/MainWindow.form          |   9 ++
 .../moo/tool/ui/form/MainWindow.java          |   7 +-
 .../tool/ui/form/func/JavaConsoleForm.form    | 102 +++++++++++++
 .../tool/ui/form/func/JavaConsoleForm.java    | 136 ++++++++++++++++++
 .../ui/listener/func/JavaConsoleListener.java | 129 +++++++++++++++++
 src/main/resources/icon/java.svg              |  20 +++
 7 files changed, 409 insertions(+), 1 deletion(-)
 create mode 100755 src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form
 create mode 100755 src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java
 create mode 100755 src/main/java/com/luoboduner/moo/tool/ui/listener/func/JavaConsoleListener.java
 create mode 100755 src/main/resources/icon/java.svg

diff --git a/pom.xml b/pom.xml
index b0b39fa6..137af251 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,6 +45,7 @@
         6.4.6
         1.2.0
         1.5.0
+		4.0.15
     
 
     
@@ -260,6 +261,12 @@
             versioncompare
             ${versioncompare.version}
         
+		
+		
+            org.apache.groovy
+            groovy
+            ${groovy.version}
+        
 
     
 
diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form
index 8b29fedb..85868c8c 100644
--- a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form
+++ b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form
@@ -154,6 +154,15 @@
             
             
           
+          
+            
+            
+              
+            
+            
+            
+            
+          
         
       
     
diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java
index eb653658..25c78ec4 100644
--- a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java
+++ b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java
@@ -39,6 +39,7 @@ public class MainWindow {
     private JPanel cronPanel;
     private JPanel regexPanel;
     private JPanel imagePanel;
+    private JPanel javaConsolePanel;
 
     private static MainWindow mainWindow;
 
@@ -76,7 +77,7 @@ public void init() {
         mainWindow.getTabbedPane().setIconAt(12, new FlatSVGIcon("icon/translate.svg"));
         mainWindow.getTabbedPane().setIconAt(13, new FlatSVGIcon("icon/schedule.svg", 15, 15));
         mainWindow.getTabbedPane().setIconAt(14, new FlatSVGIcon("icon/reg.svg"));
-
+        mainWindow.getTabbedPane().setIconAt(15, new FlatSVGIcon("icon/java.svg", 15, 15));
 
         mainWindow.getQuickNotePanel().add(QuickNoteForm.getInstance().getQuickNotePanel(), gridConstraints);
         mainWindow.getJsonBeautyPanel().add(JsonBeautyForm.getInstance().getJsonBeautyPanel(), gridConstraints);
@@ -93,6 +94,7 @@ public void init() {
         mainWindow.getCronPanel().add(CronForm.getInstance().getCronPanel(), gridConstraints);
         mainWindow.getRegexPanel().add(RegexForm.getInstance().getRegexPanel(), gridConstraints);
         mainWindow.getImagePanel().add(ImageForm.getInstance().getImagePanel(), gridConstraints);
+        mainWindow.getJavaConsolePanel().add(JavaConsoleForm.getInstance().getJavaConsolePanel(), gridConstraints);
         mainWindow.getMainPanel().updateUI();
 
         TabListener.addListeners();
@@ -163,6 +165,9 @@ public void init() {
         regexPanel = new JPanel();
         regexPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
         tabbedPane.addTab("正则", new ImageIcon(getClass().getResource("/icon/reg.png")), regexPanel);
+        javaConsolePanel = new JPanel();
+        javaConsolePanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
+        tabbedPane.addTab("java", javaConsolePanel);
     }
 
     /**
diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form
new file mode 100755
index 00000000..c406b519
--- /dev/null
+++ b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form
@@ -0,0 +1,102 @@
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java new file mode 100755 index 00000000..f6d1f145 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java @@ -0,0 +1,136 @@ +package com.luoboduner.moo.tool.ui.form.func; + +import com.alibaba.fastjson2.util.IOUtils; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; +import com.luoboduner.moo.tool.App; +import com.luoboduner.moo.tool.ui.listener.func.JavaConsoleListener; +import groovy.lang.GroovyShell; +import groovy.lang.Script; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; + +import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import javax.swing.text.StyleContext; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.*; +import java.util.Date; +import java.util.Locale; +import java.util.Objects; +import java.util.function.Supplier; + +@Getter +public class JavaConsoleForm { + private JPanel javaConsolePanel; + private JButton run; + private JButton clean; + private JTextArea codeArea; + private JTextArea resultArea; + private static JavaConsoleForm javaConsoleForm; + + public JavaConsoleForm() { + $$$setupUI$$$(); + init(); + } + + public static JavaConsoleForm getInstance() { + if (null == javaConsoleForm) { + javaConsoleForm = new JavaConsoleForm(); + } + return javaConsoleForm; + } + + private void init() { + new JavaConsoleListener(getRun(), getClean(), getCodeArea(), getResultArea()) + .addListener(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + javaConsolePanel = new JPanel(); + javaConsolePanel.setLayout(new GridLayoutManager(2, 1, new Insets(12, 12, 12, 12), -1, -1)); + final JPanel panel1 = new JPanel(); + panel1.setLayout(new GridLayoutManager(1, 4, new Insets(10, 0, 0, 0), -1, -1)); + javaConsolePanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, 1, 1, null, null, null, 0, false)); + clean = new JButton(); + clean.setText("清除"); + panel1.add(clean, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + run = new JButton(); + run.setText("执行"); + panel1.add(run, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + Font label1Font = this.$$$getFont$$$(null, -1, 14, label1.getFont()); + if (label1Font != null) label1.setFont(label1Font); + label1.setText("输入Java或groovy代码点击执行即可"); + panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + panel1.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); + final JSplitPane splitPane1 = new JSplitPane(); + splitPane1.setContinuousLayout(false); + splitPane1.setDividerLocation(500); + splitPane1.setDividerSize(3); + javaConsolePanel.add(splitPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false)); + final JScrollPane scrollPane1 = new JScrollPane(); + splitPane1.setLeftComponent(scrollPane1); + codeArea = new JTextArea(); + codeArea.setBackground(new Color(-3608620)); + Font codeAreaFont = this.$$$getFont$$$("Consolas", -1, 16, codeArea.getFont()); + if (codeAreaFont != null) codeArea.setFont(codeAreaFont); + codeArea.setText(""); + scrollPane1.setViewportView(codeArea); + final JScrollPane scrollPane2 = new JScrollPane(); + splitPane1.setRightComponent(scrollPane2); + resultArea = new JTextArea(); + resultArea.setBackground(new Color(-820)); + resultArea.setEditable(false); + Font resultAreaFont = this.$$$getFont$$$("Consolas", -1, 16, resultArea.getFont()); + if (resultAreaFont != null) resultArea.setFont(resultAreaFont); + scrollPane2.setViewportView(resultArea); + } + + /** + * @noinspection ALL + */ + private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return javaConsolePanel; + } + + private void createUIComponents() { + // TODO: place custom component creation code here + Component component = getJavaConsolePanel().getComponent(1); + ((JSplitPane) component).setDividerLocation((int) (App.mainFrame.getWidth() / 5)); + } +} diff --git a/src/main/java/com/luoboduner/moo/tool/ui/listener/func/JavaConsoleListener.java b/src/main/java/com/luoboduner/moo/tool/ui/listener/func/JavaConsoleListener.java new file mode 100755 index 00000000..04dee180 --- /dev/null +++ b/src/main/java/com/luoboduner/moo/tool/ui/listener/func/JavaConsoleListener.java @@ -0,0 +1,129 @@ +package com.luoboduner.moo.tool.ui.listener.func; + +import com.luoboduner.moo.tool.ui.form.func.TimeConvertForm; +import groovy.lang.GroovyShell; +import groovy.lang.Script; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; + +import javax.swing.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.*; +import java.util.Date; +import java.util.Objects; +import java.util.function.Supplier; + +@Getter +public class JavaConsoleListener { + + private static String TMP_FILE = System.getProperty("java.io.tmpdir") + File.separator + "temp.groovy"; + private StringBuffer log; + + private JButton run; + private JButton clean; + + private JTextArea codeArea; + private JTextArea resultArea; + + public JavaConsoleListener(JButton run, JButton clean, JTextArea codeArea, JTextArea resultArea) { + this.run = run; + this.clean = clean; + this.codeArea = codeArea; + this.resultArea = resultArea; + this.log = new StringBuffer(); + } + + public void addListener() { + this.executeClickEventListener(); + this.cleanClickEventListener(); + } + + private void cleanClickEventListener() { + this.clean.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + getResultArea().setText(""); + log = new StringBuffer(); + } + }); + } + + private void executeClickEventListener() { + run.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + String code = getCodeArea().getText(); + if (StringUtils.isBlank(code)) { + return; + } + + try { + addStr("----- 当前执行时间:" + DateFormatUtils.format(new Date(), TimeConvertForm.TIME_FORMAT) + " -----"); + Object res = compileAndExecute(code); + if (null != res) { + addStr(res.toString()); + } + } catch (Exception ex) { + logException(ex); + } + getResultArea().setText(log.toString()); + } + }); + } + + private Object compileAndExecute(String code) throws Exception { + GroovyShell shell = new GroovyShell(); + File file = new File(TMP_FILE); + if (!file.exists()) { + file.createNewFile(); + } + writeFile(file, code); + Script parse = shell.parse(new FileReader(file)); + return changeOut(() -> parse.run()); + } + + private void addStr(String str) { + if (StringUtils.isNotBlank(str)) { + log.append(str + "\r\n"); + } + } + + private void writeFile(File file, String data) throws Exception { + Objects.requireNonNull(file, "临时文件不能为空!"); + Objects.requireNonNull(data, "代码不能为空!"); + + try (FileOutputStream fileOutputStream = new FileOutputStream(file)) { + fileOutputStream.write(data.getBytes()); + } catch (Exception e) { + throw e; + } + } + + private T changeOut(Supplier supplier) { + PrintStream oldStream = System.out; + try (ByteArrayOutputStream tmpStream = new ByteArrayOutputStream(1024); + PrintStream cacheStream = new PrintStream(tmpStream)) { + System.setOut(cacheStream); + T value = supplier.get(); + String strMsg = tmpStream.toString(); + addStr(strMsg); + return value; + } catch (Exception e) { + logException(e); + } finally { + System.setOut(oldStream); + } + return null; + } + + private void logException(Throwable throwable) { + try (StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter)) { + throwable.printStackTrace(printWriter); + addStr(stringWriter.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/icon/java.svg b/src/main/resources/icon/java.svg new file mode 100755 index 00000000..fa19e3a4 --- /dev/null +++ b/src/main/resources/icon/java.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + From 0e5ed211eed32635b1265e4b7b8486d6baab5521 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Fri, 27 Oct 2023 16:30:08 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moo/tool/ui/form/MainWindow.form | 2 +- .../moo/tool/ui/form/MainWindow.java | 4 ++-- src/main/resources/icon/java.svg | 21 +------------------ 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form index 85868c8c..3df34a06 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.form @@ -157,7 +157,7 @@ - + diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java index 25c78ec4..c155251c 100644 --- a/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/MainWindow.java @@ -77,7 +77,7 @@ public void init() { mainWindow.getTabbedPane().setIconAt(12, new FlatSVGIcon("icon/translate.svg")); mainWindow.getTabbedPane().setIconAt(13, new FlatSVGIcon("icon/schedule.svg", 15, 15)); mainWindow.getTabbedPane().setIconAt(14, new FlatSVGIcon("icon/reg.svg")); - mainWindow.getTabbedPane().setIconAt(15, new FlatSVGIcon("icon/java.svg", 15, 15)); + mainWindow.getTabbedPane().setIconAt(15, new FlatSVGIcon("icon/java.svg")); mainWindow.getQuickNotePanel().add(QuickNoteForm.getInstance().getQuickNotePanel(), gridConstraints); mainWindow.getJsonBeautyPanel().add(JsonBeautyForm.getInstance().getJsonBeautyPanel(), gridConstraints); @@ -167,7 +167,7 @@ public void init() { tabbedPane.addTab("正则", new ImageIcon(getClass().getResource("/icon/reg.png")), regexPanel); javaConsolePanel = new JPanel(); javaConsolePanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); - tabbedPane.addTab("java", javaConsolePanel); + tabbedPane.addTab("Java", javaConsolePanel); } /** diff --git a/src/main/resources/icon/java.svg b/src/main/resources/icon/java.svg index fa19e3a4..7e77a1e1 100755 --- a/src/main/resources/icon/java.svg +++ b/src/main/resources/icon/java.svg @@ -1,20 +1 @@ - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file From 00b4075730d5b63326cdf5a9a36201345d90a319 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Fri, 27 Oct 2023 16:40:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/ui/form/func/JavaConsoleForm.form | 8 +++--- .../tool/ui/form/func/JavaConsoleForm.java | 27 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form index c406b519..bc937ca1 100755 --- a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form @@ -55,8 +55,8 @@ - - + + @@ -71,7 +71,7 @@ - + @@ -88,7 +88,7 @@ - + diff --git a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java index f6d1f145..4e063c6a 100755 --- a/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java +++ b/src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java @@ -1,28 +1,17 @@ package com.luoboduner.moo.tool.ui.form.func; -import com.alibaba.fastjson2.util.IOUtils; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; import com.luoboduner.moo.tool.App; import com.luoboduner.moo.tool.ui.listener.func.JavaConsoleListener; -import groovy.lang.GroovyShell; -import groovy.lang.Script; import lombok.Getter; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import javax.swing.*; import javax.swing.plaf.FontUIResource; import javax.swing.text.StyleContext; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.*; -import java.util.Date; import java.util.Locale; -import java.util.Objects; -import java.util.function.Supplier; @Getter public class JavaConsoleForm { @@ -34,7 +23,6 @@ public class JavaConsoleForm { private static JavaConsoleForm javaConsoleForm; public JavaConsoleForm() { - $$$setupUI$$$(); init(); } @@ -50,6 +38,13 @@ private void init() { .addListener(); } + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + /** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< @@ -77,14 +72,14 @@ private void init() { final Spacer spacer1 = new Spacer(); panel1.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JSplitPane splitPane1 = new JSplitPane(); - splitPane1.setContinuousLayout(false); - splitPane1.setDividerLocation(500); + splitPane1.setContinuousLayout(true); + splitPane1.setDividerLocation(463); splitPane1.setDividerSize(3); javaConsolePanel.add(splitPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false)); final JScrollPane scrollPane1 = new JScrollPane(); splitPane1.setLeftComponent(scrollPane1); codeArea = new JTextArea(); - codeArea.setBackground(new Color(-3608620)); + codeArea.setBackground(new Color(-13947600)); Font codeAreaFont = this.$$$getFont$$$("Consolas", -1, 16, codeArea.getFont()); if (codeAreaFont != null) codeArea.setFont(codeAreaFont); codeArea.setText(""); @@ -92,7 +87,7 @@ private void init() { final JScrollPane scrollPane2 = new JScrollPane(); splitPane1.setRightComponent(scrollPane2); resultArea = new JTextArea(); - resultArea.setBackground(new Color(-820)); + resultArea.setBackground(new Color(-13947600)); resultArea.setEditable(false); Font resultAreaFont = this.$$$getFont$$$("Consolas", -1, 16, resultArea.getFont()); if (resultAreaFont != null) resultArea.setFont(resultAreaFont); From fcba251de9f936d5090a6e498a2f0628d4b411c1 Mon Sep 17 00:00:00 2001 From: RememBerBer Date: Mon, 30 Oct 2023 10:17:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=A2=B3=E7=90=86SyntaxTextViewer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/component/RegexRTextScrollPane.java | 34 ++++++++ .../ui/component/RegexSyntaxTextViewer.java | 58 +++++++++++++ .../moo/tool/ui/component/TopMenuBar.java | 1 - .../moo/tool/ui/form/func/RegexForm.java | 83 +------------------ 4 files changed, 95 insertions(+), 81 deletions(-) create mode 100644 src/main/java/com/luoboduner/moo/tool/ui/component/RegexRTextScrollPane.java 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();