-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c37f84
commit ca0e766
Showing
3 changed files
with
343 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.liuzhihang.toolkit.ui.ToolkitForm"> | ||
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<xy x="20" y="20" width="500" height="400"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="a188c" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="bf012" 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> | ||
<text value="Label"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
<tabbedpane id="46993" binding="tabbedPane" default-binding="true"> | ||
<constraints> | ||
<grid row="0" 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/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="868f8" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<tabbedpane title="JSON"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="3cc61" binding="jsonLeftPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="f252c" class="javax.swing.JTextPane" binding="jsonLeftTextPane" default-binding="true"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> | ||
<preferred-size width="150" height="50"/> | ||
</grid> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<grid id="d1280" binding="jsonLeftToolBarPane" layout-manager="BorderLayout" hgap="3" vgap="0"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children/> | ||
</grid> | ||
</children> | ||
</grid> | ||
<grid id="1b22a" binding="jsonRightPanel" layout-manager="BorderLayout" hgap="0" vgap="0"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="c78f1" binding="jsonEditorPane" layout-manager="BorderLayout" hgap="0" vgap="0"> | ||
<constraints border-constraint="Center"/> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="f8ff6" binding="jsonRightToolBarPane" layout-manager="BorderLayout" hgap="3" vgap="0"> | ||
<constraints border-constraint="Center"/> | ||
<properties/> | ||
<border type="none"/> | ||
<children/> | ||
</grid> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</children> | ||
</tabbedpane> | ||
</children> | ||
</grid> | ||
</form> |
242 changes: 242 additions & 0 deletions
242
src/main/java/com/liuzhihang/toolkit/ui/ToolkitForm.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,242 @@ | ||
package com.liuzhihang.toolkit.ui; | ||
|
||
import com.intellij.find.editorHeaderActions.Utils; | ||
import com.intellij.icons.AllIcons; | ||
import com.intellij.ide.highlighter.HighlighterFactory; | ||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.actionSystem.*; | ||
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.editor.EditorFactory; | ||
import com.intellij.openapi.editor.EditorSettings; | ||
import com.intellij.openapi.editor.colors.EditorColorsManager; | ||
import com.intellij.openapi.editor.ex.EditorEx; | ||
import com.intellij.openapi.editor.highlighter.EditorHighlighter; | ||
import com.intellij.openapi.fileTypes.FileType; | ||
import com.intellij.openapi.fileTypes.FileTypeManager; | ||
import com.intellij.openapi.options.ShowSettingsUtil; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.DialogWrapper; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.ui.components.JBScrollBar; | ||
import com.intellij.ui.components.JBScrollPane; | ||
import com.intellij.util.ui.JBUI; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.awt.datatransfer.StringSelection; | ||
|
||
/** | ||
* @author liuzhihang | ||
* @date 2020/12/24 10:36 | ||
*/ | ||
public class ToolkitForm extends DialogWrapper { | ||
private JPanel rootPanel; | ||
private JTabbedPane tabbedPane; | ||
|
||
private JPanel jsonLeftPanel; | ||
private JPanel jsonRightPanel; | ||
private JPanel jsonLeftToolBarPane; | ||
private JPanel jsonRightToolBarPane; | ||
private JTextPane jsonLeftTextPane; | ||
private JPanel jsonEditorPane; | ||
private EditorEx jsonEditor; | ||
private Document jsonDocument = EditorFactory.getInstance().createDocument(""); | ||
|
||
private Project project; | ||
private PsiFile psiFile; | ||
private Editor editor; | ||
private PsiClass psiClass; | ||
|
||
public ToolkitForm(@Nullable Project project, PsiFile psiFile, Editor editor, PsiClass psiClass) { | ||
super(project, true, IdeModalityType.MODELESS); | ||
this.project = project; | ||
this.psiFile = psiFile; | ||
this.editor = editor; | ||
this.psiClass = psiClass; | ||
|
||
|
||
init(); | ||
setTitle("Toolkit"); | ||
} | ||
|
||
|
||
private void initJsonEditor() { | ||
|
||
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension("json"); | ||
|
||
final EditorHighlighter editorHighlighter = | ||
HighlighterFactory.createHighlighter(fileType, EditorColorsManager.getInstance().getGlobalScheme(), project); | ||
|
||
jsonEditor = (EditorEx) EditorFactory.getInstance().createEditor(jsonDocument, project, fileType, true); | ||
|
||
EditorSettings editorSettings = jsonEditor.getSettings(); | ||
editorSettings.setAdditionalLinesCount(0); | ||
editorSettings.setAdditionalColumnsCount(0); | ||
editorSettings.setLineMarkerAreaShown(false); | ||
editorSettings.setLineNumbersShown(false); | ||
editorSettings.setVirtualSpace(false); | ||
editorSettings.setFoldingOutlineShown(false); | ||
|
||
editorSettings.setLanguageSupplier(() -> Language.findLanguageByID("Json")); | ||
|
||
jsonEditor.setHighlighter(editorHighlighter); | ||
jsonEditor.setBorder(JBUI.Borders.emptyLeft(5)); | ||
|
||
JBScrollPane templateScrollPane = new JBScrollPane(jsonEditor.getComponent()); | ||
|
||
JBScrollBar jbScrollBar = new JBScrollBar(); | ||
jbScrollBar.setBackground(jsonEditor.getBackgroundColor()); | ||
|
||
templateScrollPane.setHorizontalScrollBar(jbScrollBar); | ||
jsonRightPanel.add(templateScrollPane, BorderLayout.CENTER); | ||
} | ||
|
||
private void initJsonLeftToolbar() { | ||
|
||
DefaultActionGroup leftGroup = new DefaultActionGroup(); | ||
|
||
leftGroup.add(new AnAction("Search", "Search", AllIcons.Actions.RemoveMulticaret) { | ||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
|
||
} | ||
}); | ||
|
||
|
||
ActionToolbarImpl toolbar = (ActionToolbarImpl) ActionManager.getInstance() | ||
.createActionToolbar("ToolkitJsonLeftToolbar", leftGroup, true); | ||
toolbar.setTargetComponent(jsonLeftToolBarPane); | ||
|
||
toolbar.setForceMinimumSize(true); | ||
toolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); | ||
Utils.setSmallerFontForChildren(toolbar); | ||
|
||
jsonLeftToolBarPane.add(toolbar.getComponent(), BorderLayout.WEST); | ||
} | ||
|
||
private void initJsonRightToolbar() { | ||
|
||
DefaultActionGroup leftGroup = new DefaultActionGroup(); | ||
|
||
leftGroup.add(new AnAction("Search", "Search", AllIcons.Actions.RemoveMulticaret) { | ||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
|
||
} | ||
}); | ||
|
||
|
||
ActionToolbarImpl toolbar = (ActionToolbarImpl) ActionManager.getInstance() | ||
.createActionToolbar("ToolkitJsonLeftToolbar", leftGroup, true); | ||
toolbar.setTargetComponent(jsonLeftPanel); | ||
|
||
toolbar.setForceMinimumSize(true); | ||
toolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); | ||
Utils.setSmallerFontForChildren(toolbar); | ||
|
||
jsonLeftPanel.add(toolbar.getComponent(), BorderLayout.EAST); | ||
} | ||
|
||
|
||
|
||
private void initEditorLeftToolbar() { | ||
|
||
DefaultActionGroup leftGroup = new DefaultActionGroup(); | ||
|
||
leftGroup.add(new AnAction("Search", "Search", AllIcons.Actions.RemoveMulticaret) { | ||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
|
||
} | ||
}); | ||
|
||
leftGroup.addSeparator(); | ||
|
||
leftGroup.add(new AnAction("Editor", "Editor doc", AllIcons.Actions.Search) { | ||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
} | ||
}); | ||
|
||
ActionToolbarImpl toolbar = (ActionToolbarImpl) ActionManager.getInstance() | ||
.createActionToolbar("DocViewEditorLeftToolbar", leftGroup, true); | ||
toolbar.setTargetComponent(jsonRightPanel); | ||
toolbar.getComponent().setBackground(jsonEditor.getBackgroundColor()); | ||
|
||
toolbar.setForceMinimumSize(true); | ||
toolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); | ||
Utils.setSmallerFontForChildren(toolbar); | ||
|
||
jsonRightPanel.setBackground(jsonEditor.getBackgroundColor()); | ||
jsonRightPanel.add(toolbar.getComponent(), BorderLayout.WEST); | ||
} | ||
|
||
private void initEditorRightToolbar() { | ||
DefaultActionGroup rightGroup = new DefaultActionGroup(); | ||
|
||
rightGroup.add(new AnAction("Generate", "Generate field", AllIcons.Actions.EditScheme) { | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
} | ||
}); | ||
|
||
rightGroup.add(new AnAction("Copy", "Copy to clipboard", AllIcons.Actions.Copy) { | ||
|
||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
String text = jsonDocument.getText(); | ||
|
||
if (StringUtils.isBlank(text)) { | ||
|
||
} else { | ||
StringSelection selection = new StringSelection(text); | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(selection, selection); | ||
} | ||
|
||
} | ||
}); | ||
|
||
// init toolbar | ||
// ActionToolbarImpl toolbar = (ActionToolbarImpl) ActionManager.getInstance() | ||
// .createActionToolbar("DocViewEditorRightToolbar", rightGroup, true); | ||
// toolbar.setTargetComponent(previewEditorPane); | ||
// toolbar.getComponent().setBackground(markdownEditor.getBackgroundColor()); | ||
// | ||
// toolbar.setForceMinimumSize(true); | ||
// toolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); | ||
// Utils.setSmallerFontForChildren(toolbar); | ||
// | ||
// previewEditorPane.setBackground(markdownEditor.getBackgroundColor()); | ||
// previewEditorPane.add(toolbar.getComponent(), BorderLayout.EAST); | ||
|
||
} | ||
|
||
@NotNull | ||
@Override | ||
protected Action[] createActions() { | ||
// 覆盖默认的 确认和撤销 | ||
return new Action[]{}; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected JComponent createCenterPanel() { | ||
return rootPanel; | ||
} | ||
} |
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