-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!47 新增Java、Groovy代码编译执行器,在MooTool工具中可简单执行Java或Groovy代码
Merge pull request !47 from felixnan168/develop
- Loading branch information
Showing
7 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.luoboduner.moo.tool.ui.form.func.JavaConsoleForm"> | ||
<grid id="27dc6" binding="javaConsolePanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="12" left="12" bottom="12" right="12"/> | ||
<constraints> | ||
<xy x="26" y="46" width="494" height="567"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="5956" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="804be" class="javax.swing.JButton" binding="clean"> | ||
<constraints> | ||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="清除"/> | ||
</properties> | ||
</component> | ||
<component id="54894" class="javax.swing.JButton" binding="run"> | ||
<constraints> | ||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="执行"/> | ||
</properties> | ||
</component> | ||
<component id="8d9f4" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<font size="14"/> | ||
<text value="输入Java或groovy代码点击执行即可"/> | ||
</properties> | ||
</component> | ||
<hspacer id="73c3d"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</hspacer> | ||
</children> | ||
</grid> | ||
<splitpane id="76c59"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> | ||
<preferred-size width="200" height="200"/> | ||
</grid> | ||
</constraints> | ||
<properties> | ||
<continuousLayout value="false"/> | ||
<dividerLocation value="500"/> | ||
<dividerSize value="3"/> | ||
</properties> | ||
<border type="none"/> | ||
<children> | ||
<scrollpane id="7a589"> | ||
<constraints> | ||
<splitpane position="left"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="61044" class="javax.swing.JTextArea" binding="codeArea"> | ||
<constraints/> | ||
<properties> | ||
<background color="-3608620"/> | ||
<font name="Consolas" size="16"/> | ||
<text value=""/> | ||
</properties> | ||
</component> | ||
</children> | ||
</scrollpane> | ||
<scrollpane id="8cb4d"> | ||
<constraints> | ||
<splitpane position="right"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="286fe" class="javax.swing.JTextArea" binding="resultArea"> | ||
<constraints/> | ||
<properties> | ||
<background color="-820"/> | ||
<editable value="false"/> | ||
<font name="Consolas" size="16"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</scrollpane> | ||
</children> | ||
</splitpane> | ||
</children> | ||
</grid> | ||
</form> |
136 changes: 136 additions & 0 deletions
136
src/main/java/com/luoboduner/moo/tool/ui/form/func/JavaConsoleForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
Oops, something went wrong.