From 92e02557716f99f1327f0824a7e47dd7a2f81386 Mon Sep 17 00:00:00 2001 From: javas <634464916@qq.com> Date: Thu, 11 Jan 2018 12:55:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=A8=A1=E6=9D=BF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ConfigServiceImpl.java | 6 +- src/com/sjhy/plugin/ui/EditTemplatePanel.form | 18 ++- src/com/sjhy/plugin/ui/EditTemplatePanel.java | 39 +++--- src/com/sjhy/plugin/ui/TemplateSetting.java | 122 +++++++++++++++++- 4 files changed, 158 insertions(+), 27 deletions(-) diff --git a/src/com/sjhy/plugin/service/impl/ConfigServiceImpl.java b/src/com/sjhy/plugin/service/impl/ConfigServiceImpl.java index 6df5460..ac8c2be 100644 --- a/src/com/sjhy/plugin/service/impl/ConfigServiceImpl.java +++ b/src/com/sjhy/plugin/service/impl/ConfigServiceImpl.java @@ -11,6 +11,7 @@ import com.sjhy.plugin.entity.TypeMapperGroup; import com.sjhy.plugin.service.ConfigService; import org.jetbrains.annotations.Nullable; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -110,11 +111,10 @@ public class ConfigServiceImpl implements ConfigService { private String loadTemplate(String name) { try { - return FileUtil.loadTextAndClose(getClass().getResourceAsStream("/template/"+name+".vm")); + return FileUtil.loadFile(new File(getClass().getResource("/template/"+name+".vm").getFile()), "UTF-8").replaceAll("\r", ""); } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } - return ""; } //GET SET diff --git a/src/com/sjhy/plugin/ui/EditTemplatePanel.form b/src/com/sjhy/plugin/ui/EditTemplatePanel.form index 2ee3cc3..f8fc922 100644 --- a/src/com/sjhy/plugin/ui/EditTemplatePanel.form +++ b/src/com/sjhy/plugin/ui/EditTemplatePanel.form @@ -1,6 +1,6 @@
diff --git a/src/com/sjhy/plugin/ui/EditTemplatePanel.java b/src/com/sjhy/plugin/ui/EditTemplatePanel.java index 5104b78..e93fc47 100644 --- a/src/com/sjhy/plugin/ui/EditTemplatePanel.java +++ b/src/com/sjhy/plugin/ui/EditTemplatePanel.java @@ -3,34 +3,41 @@ package com.sjhy.plugin.ui; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.uiDesigner.core.GridConstraints; +import com.sjhy.plugin.entity.Template; import javax.swing.*; import java.awt.*; public class EditTemplatePanel { - private JTextArea textArea; private JPanel mainPanel; - private Editor editor; + private JPanel editPanel; + private Template template; - public EditTemplatePanel() { - addVmEditor("test"); + EditTemplatePanel(Template template) { + this.template = template; + init(); } - private void addVmEditor(String template) { + private FileType getVelocityFileType() { + return FileTypeManager.getInstance().getFileTypeByExtension("vm"); + } + + private GridConstraints getGridConstraints() { + return new GridConstraints(0, 0, 1, 1, + GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, + null, new Dimension(600, 400), null, + 0, true); + } + + private void init() { + //初始化系统编辑器 EditorFactory factory = EditorFactory.getInstance(); - Document velocityTemplate = factory.createDocument(template); - editor = factory.createEditor(velocityTemplate, null, FileTypeManager.getInstance() - .getFileTypeByExtension("vm"), false); - GridConstraints constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, - GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, - GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(300, 300), null, 0, true); - mainPanel.add(editor.getComponent(), constraints); - } - - public JTextArea getTextArea() { - return textArea; + Document velocityTemplate = factory.createDocument(template.getCode()); + Editor editor = factory.createEditor(velocityTemplate, null, getVelocityFileType(), false); + editPanel.add(editor.getComponent(), getGridConstraints()); } public JPanel getMainPanel() { diff --git a/src/com/sjhy/plugin/ui/TemplateSetting.java b/src/com/sjhy/plugin/ui/TemplateSetting.java index 109f2af..dfd4af9 100644 --- a/src/com/sjhy/plugin/ui/TemplateSetting.java +++ b/src/com/sjhy/plugin/ui/TemplateSetting.java @@ -1,11 +1,15 @@ package com.sjhy.plugin.ui; import com.intellij.openapi.options.Configurable; +import com.sjhy.plugin.entity.Template; +import com.sjhy.plugin.entity.TemplateGroup; import com.sjhy.plugin.service.ConfigService; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.LinkedHashMap; +import java.util.Map; public class TemplateSetting implements Configurable { private JPanel mainPanel; @@ -16,15 +20,123 @@ public class TemplateSetting implements Configurable { private JButton addButton; private JButton removeButton; + private Map