Skip to content

Commit

Permalink
页面优化
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryZy committed Jul 12, 2024
1 parent 1536621 commit 59bb5e7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 51 deletions.
16 changes: 14 additions & 2 deletions src/main/java/cn/memoryzy/json/actions/JsonToJavaBeanAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -39,7 +40,6 @@ public void actionPerformed(@NotNull AnActionEvent event) {
// 文件夹(包)
PsiDirectory directory = ideView.getOrChooseDirectory();
if (Objects.isNull(directory)) {
LOG.error(JsonAssistantBundle.messageOnSystem("json.to.javabean.null.directory.text"));
return;
}

Expand All @@ -62,8 +62,20 @@ private boolean isAvailable(DataContext dataContext) {
return false;
}

boolean enabled = false;
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
return project != null && view != null && view.getDirectories().length != 0;
if (project != null && view != null && view.getDirectories().length != 0) {
PsiDirectory chooseDirectory = view.getOrChooseDirectory();
if (Objects.nonNull(chooseDirectory)) {
VirtualFile virtualFile = chooseDirectory.getVirtualFile();

// todo 未找到解决方案
String path = virtualFile.getPath();
enabled = path.contains("/test/java") || path.contains("/main/java") || path.contains("/test/kotlin") || path.contains("/main/kotlin");
}
}

return enabled;
}
}
2 changes: 2 additions & 0 deletions src/main/java/cn/memoryzy/json/constant/PluginConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public class PluginConstant {

public static final String PLUGIN_ID = "cn.memoryzy.json.Json-Assistant";

public static final String JSON_EXAMPLE = "{\"name\": \"王铁柱\", \"age\": 18}";

}
6 changes: 3 additions & 3 deletions src/main/java/cn/memoryzy/json/ui/JsonStructureWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean sel
nodeTypeStr = "object";
squareBracketsEnd = "]";
sizeStrPre = " (";
sizeStr = size + " " + JsonAssistantBundle.message("json.structure.window.size.obj.text");
sizeStr = size + " " + JsonAssistantBundle.messageOnSystem("json.structure.window.size.obj.text");
sizeStrPost = ")";

icon = JsonAssistantIcons.Structure.JSON_OBJECT;
Expand All @@ -235,7 +235,7 @@ public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean sel
nodeTypeStr = "array";
squareBracketsEnd = "]";
sizeStrPre = " (";
sizeStr = size + " " + JsonAssistantBundle.message("json.structure.window.size.array.text");
sizeStr = size + " " + JsonAssistantBundle.messageOnSystem("json.structure.window.size.array.text");
sizeStrPost = ")";

icon = JsonAssistantIcons.Structure.JSON_ARRAY;
Expand All @@ -247,7 +247,7 @@ public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean sel
nodeTypeStr = "array_object";
squareBracketsEnd = "]";
sizeStrPre = " (";
sizeStr = size + " " + JsonAssistantBundle.message("json.structure.window.size.obj.text");
sizeStr = size + " " + JsonAssistantBundle.messageOnSystem("json.structure.window.size.obj.text");
sizeStrPost = ")";

icon = JsonAssistantIcons.Structure.JSON_OBJECT_ITEM;
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/cn/memoryzy/json/ui/JsonToJavaBeanWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,49 @@
<properties/>
<border type="none"/>
<children>
<grid id="c0616" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<grid id="c0616" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="4" bottom="0" right="0"/>
<constraints border-constraint="North"/>
<properties/>
<border type="none"/>
<children>
<component id="742d0" class="javax.swing.JLabel" binding="label">
<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=""/>
</properties>
</component>
<component id="767a9" class="javax.swing.JTextField" binding="classNameTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<grid id="caa4f" 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="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="1bc85" 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="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="f7b6e" class="javax.swing.JLabel" binding="label">
<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=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="8625d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="0" bottom="0" right="0"/>
<margin top="5" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cn/memoryzy/json/ui/JsonToJavaBeanWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.memoryzy.json.bundles.JsonAssistantBundle;
import cn.memoryzy.json.constant.PluginConstant;
import cn.memoryzy.json.enums.LombokAnnotationEnum;
import cn.memoryzy.json.ui.basic.MultiRowLanguageTextField;
import cn.memoryzy.json.ui.basic.TextFieldErrorPopupDecorator;
Expand Down Expand Up @@ -91,7 +92,7 @@ private void createUIComponents() {
// 声明 Json 类型编辑器
jsonTextField = new MultiRowLanguageTextField(Json5Language.INSTANCE, project, "", true);
jsonTextField.setFont(new Font("Consolas", Font.PLAIN, 15));
jsonTextField.setPlaceholder(JsonAssistantBundle.messageOnSystem("json.window.placeholder.text"));
jsonTextField.setPlaceholder(JsonAssistantBundle.messageOnSystem("json.window.placeholder.text") + PluginConstant.JSON_EXAMPLE);
}

@Override
Expand Down
41 changes: 20 additions & 21 deletions src/main/resources/messages/JsonAssistantBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,37 @@ json.to.javabean.invalid.json.text=Invalid Json
json.to.javabean.already.exists.text=The ''{0}'' class already exists
json.to.javabean.illegal.class.name.text=Illegal class name
json.to.javabean.not.applicable.class.name.text=''{0}'' cannot be used for class names
json.to.javabean.null.directory.text=Please select the package to open the window!
json.window.label.text= Class Name:
json.window.placeholder.text=Please enter json...
action.json.processing.text=_Json Processing
action.json.processing.description=Perform various Json processing.
action.json.format.text=Json Formatting
action.json.format.description=Beautify json.
action.json.compress.text=Json Compressing
action.json.compress.description=Compress the Json into a single line.
action.json.structure.text=Json Structuring
action.json.structure.description=Convert Json to tree.
json.window.label.text=Class Name:
json.window.placeholder.text=Examples:
action.json.processing.text=Json Pr_ocessing
action.json.processing.description=Perform various Json processing
action.json.format.text=Json Beautify
action.json.format.description=Beautify JSON.
action.json.compress.text=Json Minify
action.json.compress.description=Compress the Json into a single line
action.json.structure.text=Json Tree Structure
action.json.structure.description=Convert Json to a tree structure
action.collapse.all.text=Collapse All
action.collapse.all.description=Collapse all nodes.
action.collapse.all.description=Collapse all nodes
action.expand.all.text=Expand All
action.expand.all.description=Expand all nodes
action.json.structure.window.copy.key.text=Copy Key
action.json.structure.window.copy.key.description=Copy keys to clipboard.
action.json.structure.window.copy.key.description=Copy keys to clipboard
action.json.structure.window.copy.value.text=Copy Value
action.json.structure.window.copy.value.description=Copy values to the clipboard.
action.json.structure.window.copy.key.value.text=Copy Key-Value
action.json.structure.window.copy.key.value.description=Copy key-value to the clipboard.
action.json.structure.window.copy.key.value.description=Copy key-value to the clipboard
action.json.structure.window.expand.multi.text=Expand
action.json.structure.window.expand.multi.description=Expand the node and its children.
action.json.structure.window.expand.multi.description=Expand the node and its children
action.json.structure.window.collapse.multi.text=Collapse
action.json.structure.window.collapse.multi.description=Collapses the node and its children.
action.json.structure.window.collapse.multi.description=Collapses the node and its children
action.json.structure.window.remove.text=Remove...
action.json.structure.window.remove.description=Remove the node.
action.json.structure.window.remove.description=Remove the node
action.javabean.to.json.text=_Convert to JSON
action.javabean.to.json.description=Convert JavaBean To Json.
action.to.json.javabean.text=_Java Class from Json
action.to.json.javabean.description=Convert Json To JavaBean.
action.javabean.to.json.description=Convert JavaBean To Json
action.to.json.javabean.text=Java Class _from Json
action.to.json.javabean.description=Convert Json To JavaBean
action.donate.text=Donate
action.donate.description=If you find the plugin helpful to you, please consider donating to support me, your support will be my motivation to continue to work hard!
action.kt.class.property.to.json.text=_Convert to JSON
action.kt.class.property.to.json.description=Convert the data class to json.
action.kt.class.property.to.json.description=Convert the kotlin property to Json
17 changes: 8 additions & 9 deletions src/main/resources/messages/JsonAssistantBundle_zh.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
json.window.title=\u004a\u0073\u006f\u006e\u0020\u7a97\u53e3
ok.button.text=\u786e\u5b9a
popup.json.processing.title=\u529f\u80fd
json.structure.window.title=\u004a\u0073\u006f\u006e\u0020\u7ed3\u6784
json.structure.window.title=\u004a\u0073\u006f\u006e\u0020\u6811
json.structure.window.size.obj.text=\u5c5e\u6027
json.structure.window.size.array.text=\u5143\u7d20
notify.javabean.to.json.tip.recursion=\u8be5\u7c7b\u5c5e\u6027\u9012\u5f52\u65f6\u6df1\u5ea6\u8fc7\u5927\uff0c\u65e0\u6cd5\u7ee7\u7eed\uff01
notify.javabean.to.json.tip.recursion=\u8be5\u7c7b\u5c5e\u6027\u9012\u5f52\u8fc7\u6df1\uff0c\u65e0\u6cd5\u7ee7\u7eed\uff01
notify.javabean.to.json.tip.copy=\u5df2\u62f7\u8d1d\u81f3\u526a\u8d34\u677f\uff01
json.to.javabean.title=\u004a\u0073\u006f\u006e\u0020\u8f6c\u4e3a\u0020\u004a\u0061\u0076\u0061\u0042\u0065\u0061\u006e
json.to.javabean.ok.button.text=\u751f\u6210
Expand All @@ -13,17 +13,16 @@ json.to.javabean.invalid.json.text=\u65e0\u6548\u0020\u004a\u0053\u004f\u004e
json.to.javabean.already.exists.text=''{0}''\u0020\u7c7b\u5df2\u5b58\u5728
json.to.javabean.illegal.class.name.text=\u975e\u6cd5\u7c7b\u540d
json.to.javabean.not.applicable.class.name.text=''{0}''\u0020\u4e0d\u80fd\u7528\u4e8e\u7c7b\u540d
json.to.javabean.null.directory.text=\u8bf7\u9009\u4e2d\u5305\u4ee5\u6253\u5f00\u7a97\u53e3\uff01
json.window.label.text=\u0020\u0020\u7c7b\u540d\uff1a
json.window.placeholder.text=\u8bf7\u8f93\u5165\u0020\u004a\u0073\u006f\u006e\u002e\u002e\u002e
json.window.label.text=\u7c7b\u540d\u003a
json.window.placeholder.text=\u793a\u4f8b\uff1a
action.json.processing.text=\u004a\u0073\u006f\u006e\u0020\u5904\u7406
action.json.processing.description=\u8fdb\u884c\u0020\u004a\u0073\u006f\u006e\u0020\u7684\u5404\u79cd\u5904\u7406
action.json.format.text=\u004a\u0073\u006f\u006e\u0020\u683c\u5f0f\u5316
action.json.format.text=\u7f8e\u5316\u0020\u004a\u0073\u006f\u006e
action.json.format.description=\u7f8e\u5316\u0020\u004a\u0073\u006f\u006e
action.json.compress.text=\u004a\u0073\u006f\u006e\u0020\u538b\u7f29
action.json.compress.text=\u538b\u7f29\u0020\u004a\u0073\u006f\u006e
action.json.compress.description=\u5c06\u0020\u004a\u0073\u006f\u006e\u0020\u538b\u7f29\u6210\u4e00\u884c
action.json.structure.text=\u004a\u0073\u006f\u006e\u0020\u7ed3\u6784\u5316
action.json.structure.description=\u5c06\u0020\u004a\u0073\u006f\u006e\u0020\u8f6c\u4e3a\u6811
action.json.structure.text=\u6811\u5316\u0020\u004a\u0073\u006f\u006e
action.json.structure.description=\u5c06\u0020\u004a\u0073\u006f\u006e\u0020\u8f6c\u4e3a\u6811\u7ed3\u6784
action.collapse.all.text=\u6298\u53e0\u6240\u6709
action.collapse.all.description=\u6298\u53e0\u5168\u90e8\u8282\u70b9
action.expand.all.text=\u5c55\u5f00\u6240\u6709
Expand Down

0 comments on commit 59bb5e7

Please sign in to comment.