1 files modified
9 files added
| | |
| | | |
| | | <actions> |
| | | <!-- Add your actions here --> |
| | | |
| | | <!-- Add your actions here --> |
| | | <group id="runtMethod" text="Runt项目" description="Runt的android项目开发插件" popup="true"> |
| | | <add-to-group group-id="NewGroup" anchor="first"/> |
| | | |
| | | <!-- Add your actions here --> |
| | | <group id="BeanMethod" text="数据bean类" description="数据bean类" popup="true"> |
| | | <add-to-group group-id="runtMethod" anchor="first"/> |
| | | <action id="CreateNormalResult" class="com.runt.android.actions.CreateNormalResult" text="创建普通数据类" |
| | | description="创建普通数据类"> |
| | | <keyboard-shortcut keymap="$default" first-keystroke="alt shift v"/> |
| | | </action> |
| | | </group> |
| | | </group> |
| | | |
| | | </actions> |
| | | |
| | | </idea-plugin> |
| New file |
| | |
| | | package com.runt.android.actions; |
| | | |
| | | import com.intellij.openapi.actionSystem.AnAction; |
| | | |
| | | import org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.io.BufferedWriter; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * My father is Object, ites purpose of |
| | | * |
| | | * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-10-27. |
| | | */ |
| | | |
| | | public abstract class BaseAction extends AnAction { |
| | | |
| | | protected final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd"); |
| | | |
| | | /** |
| | | * 生成参数变量代码 |
| | | * @param args |
| | | * @return |
| | | */ |
| | | public String getFields(String[] args, String keyWord){ |
| | | StringBuilder fieldStr = new StringBuilder(); |
| | | for(String field : args){ |
| | | fieldStr.append(keyWord+" String "+humpName(field)+";\n");//创建参数变量,默认string |
| | | } |
| | | return fieldStr.toString(); |
| | | } |
| | | /** |
| | | * 生成参数变量代码 |
| | | * @param jsonStr json格式对象 |
| | | * @return |
| | | */ |
| | | public String getFields(String jsonStr ){ |
| | | return getFields(new JSONObject(jsonStr),"public"); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 生成参数变量代码 |
| | | * @param jsonStr json格式对象 |
| | | * @param keyWord 关键字 public,private,protect等 |
| | | * @return |
| | | */ |
| | | public String getFields(String jsonStr , String keyWord){ |
| | | return getFields(new JSONObject(jsonStr),keyWord); |
| | | |
| | | } |
| | | |
| | | public String getFields(JSONObject jsonObject ) { |
| | | return getFields(jsonObject,"public"); |
| | | } |
| | | public String getFields(JSONObject jsonObject , String keyWord){ |
| | | StringBuilder fieldStr = new StringBuilder(); |
| | | Map<String , Object> fieldMap = getFieldNormalMap(jsonObject); |
| | | for(String clssName : fieldMap.keySet()){ |
| | | if(fieldMap.get(clssName) instanceof List){ |
| | | //创建参数变量, |
| | | fieldStr.append(keyWord+" " + (clssName.toLowerCase().equals("null") ? "String":clssName) + " " ); |
| | | List<String> fields= (List<String>) fieldMap.get(clssName); |
| | | for(String field : fields){ |
| | | if(fields.indexOf(field) == fields.size() -1 ){ |
| | | fieldStr.append( field + ";\n"); |
| | | }else{ |
| | | fieldStr.append( field + ","); |
| | | } |
| | | } |
| | | }else { |
| | | //创建参数变量, |
| | | fieldStr.append(keyWord+" " + (clssName.toLowerCase().equals("null") ? "String":clssName) + " " + fieldMap.get(clssName) + " ;\n"); |
| | | } |
| | | } |
| | | return fieldStr.toString(); |
| | | |
| | | } |
| | | /** |
| | | * 获取json中解析的普通变量集合 |
| | | * @param jsonStr |
| | | * @return |
| | | */ |
| | | protected Map<String,Object> getFieldNormalMap(String jsonStr){ |
| | | return getFieldNormalMap(new JSONObject(jsonStr)); |
| | | } |
| | | |
| | | /** |
| | | * 获取json中解析的普通变量集合 |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | protected Map<String,Object> getFieldNormalMap(JSONObject jsonObject){ |
| | | Map<String , Object> fieldMap = new HashMap<>(); |
| | | for(String key: jsonObject.keySet()){ |
| | | Object obj = jsonObject.get(key); |
| | | key = humpName(key); |
| | | String clssName = obj.getClass().getSimpleName();//声明变量的数据类型 |
| | | if(obj instanceof JSONArray){ |
| | | clssName = "List"; |
| | | }else if(obj instanceof JSONObject){ |
| | | clssName = "Map"; |
| | | } |
| | | //将key作为声明的变量名 |
| | | if(fieldMap.get(clssName) == null){//没有同数据类型的变量 |
| | | fieldMap.put(clssName,key); |
| | | }else if(fieldMap.get(clssName) instanceof List){//已有同数据类型的变量 |
| | | List vlus = (List) fieldMap.get(clssName); |
| | | vlus.add(key);//追加 |
| | | }else {//已有同数据类型的变量,转变为集合 |
| | | List vlus = new ArrayList(); |
| | | String field = fieldMap.get(clssName).toString(); |
| | | vlus.add(field); |
| | | vlus.add(key);//追加 |
| | | fieldMap.replace(clssName,vlus);//替换为集合 |
| | | } |
| | | } |
| | | return fieldMap; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建api返回类文件 |
| | | */ |
| | | protected void createApiFile(String filePath,String name, String fieldsStr,String packageName,String fileName,String[] fields ){ |
| | | createApiFile(filePath,name,fieldsStr,packageName,fileName,fields,""); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 创建api返回类文件 |
| | | * @param filePath 文件路径 |
| | | * @param name 文件名称 |
| | | * @param fieldsStr 声明变量字符串 |
| | | * @param packageName 包名 |
| | | * @param fileName 模版文件 |
| | | * @param fields 变量名集合 |
| | | * @param classStr 内部类代码字符 |
| | | */ |
| | | protected void createApiFile(String filePath,String name, String fieldsStr,String packageName,String fileName,String[] fields,String classStr){ |
| | | createFile(filePath,name,fieldsStr,packageName,fileName,fields,classStr,"Result"); |
| | | } |
| | | |
| | | /** |
| | | * 创建数据类文件 |
| | | * @param suffix 文件名后缀 |
| | | */ |
| | | protected void createFile(String filePath,String name, String fieldsStr,String packageName,String fileName,String[] fields,String classStr,String suffix){ |
| | | try { |
| | | String desc = name; |
| | | if(name.indexOf(",")>-1){ |
| | | desc = name.split(",")[1]; |
| | | name = name.split(",")[0]; |
| | | } |
| | | name = toUperFirst(name); |
| | | Properties prop = System.getProperties(); |
| | | String template = getTemplateString(fileName) |
| | | .replace("{desc}", desc) |
| | | .replace("{date}", dateFormat.format(new Date())) |
| | | .replace("{author}", prop.getProperty( "user.name" )+" "+prop.getProperty("os.name")) |
| | | .replace("{fields}", fieldsStr) |
| | | .replace("{name}", name) |
| | | .replace("{class}",classStr) |
| | | .replace("{package}",packageName) |
| | | .replace("{toString}",getToString(name,fields)); |
| | | File viewFile = new File(filePath, name+suffix+".java"); |
| | | if (!viewFile.exists()) { |
| | | viewFile.createNewFile(); |
| | | } |
| | | FileWriter fw = new FileWriter(viewFile.getAbsoluteFile()); |
| | | BufferedWriter bw = new BufferedWriter(fw); |
| | | bw.write(template); |
| | | bw.close(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 重写 toString |
| | | * @param name |
| | | * @param fields |
| | | * @return |
| | | */ |
| | | protected String getToString(String name,String[] fields){ |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append("@Override\n"); |
| | | sb.append("public String toString() {\n"); |
| | | sb.append("return \""+name+"{\" + \n"); |
| | | for(String field : fields){ |
| | | sb.append(" \""+humpName(field)+"=\" + "+humpName(field)+(field.equals(fields[fields.length-1])?"+":"+\",\"+")+"\n"); |
| | | } |
| | | sb.append("'}';\n"); |
| | | sb.append("}\n"); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 驼峰命名 |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public String humpName(String name){ |
| | | String[] strings = name.split("_"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(strings[0]); |
| | | for(int i = 1 ; i < strings.length ; i ++){ |
| | | sb.append(toUperFirst(strings[i])); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 首字母大写 |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public String toUperFirst(String name){ |
| | | return name.substring(0,1).toUpperCase()+name.substring(1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取模板字符串 |
| | | */ |
| | | public String getTemplateString(String fileName) { |
| | | InputStream in = null; |
| | | in = this.getClass().getResourceAsStream("/template/" + fileName); |
| | | String content = ""; |
| | | try { |
| | | content = new String(readStream(in)); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return content; |
| | | } |
| | | private byte[] readStream(InputStream inputStream) throws IOException { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024]; |
| | | int len; |
| | | try { |
| | | while ((len = inputStream.read(buffer)) != -1){ |
| | | outputStream.write(buffer, 0, len); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | outputStream.close(); |
| | | inputStream.close(); |
| | | } |
| | | return outputStream.toByteArray(); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.runt.android.actions; |
| | | |
| | | import com.intellij.ide.IdeView; |
| | | import com.intellij.openapi.actionSystem.AnActionEvent; |
| | | import com.intellij.openapi.actionSystem.LangDataKeys; |
| | | import com.intellij.openapi.project.Project; |
| | | import com.intellij.openapi.wm.WindowManager; |
| | | import com.intellij.psi.PsiDirectory; |
| | | import com.runt.android.dialogs.DoubleInputDialog; |
| | | import com.runt.android.utils.Util; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * My father is Object, ites purpose of |
| | | * |
| | | * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-10-28. |
| | | */ |
| | | |
| | | public abstract class BaseCreateApiResult extends BaseAction { |
| | | |
| | | @Override |
| | | public void actionPerformed(AnActionEvent actionEvent) { |
| | | Project project = actionEvent.getProject(); |
| | | //选择的路径 |
| | | IdeView ideView = actionEvent.getRequiredData(LangDataKeys.IDE_VIEW); |
| | | PsiDirectory directory = ideView.getOrChooseDirectory(); |
| | | String packageName = Util.getPackageDir(project,directory.toString()); |
| | | String filePath = directory.toString().split("PsiDirectory:")[1];//选择的路径 |
| | | //根据包名截取末尾路径 |
| | | String path = filePath.substring(filePath.indexOf(packageName.replace(".","\\"))+packageName.replace(".","\\").length()); |
| | | //转换并合并成包名 |
| | | final String packageN = packageName+ path.replace("\\","."); |
| | | // TODO: insert action logic here |
| | | DoubleInputDialog dialog = createDoubleDialog(filePath,packageN,actionEvent); |
| | | dialog.pack(); |
| | | //设置对话框跟随当前windows窗口 |
| | | dialog.setLocationRelativeTo(WindowManager.getInstance().getFrame(project)); |
| | | dialog.setVisible(true); |
| | | } |
| | | |
| | | /** |
| | | * 创建弹框 |
| | | * @param filePath |
| | | * @param packageN |
| | | * @param actionEvent |
| | | * @return |
| | | */ |
| | | protected DoubleInputDialog createDoubleDialog(String filePath,String packageN,AnActionEvent actionEvent){ |
| | | return new DoubleInputDialog(new DoubleInputDialog.DialogListener() { |
| | | @Override |
| | | public void Ok(String[] object) { |
| | | |
| | | //弹框确认 |
| | | /*Messages.showMessageDialog(project,packageN+" "+object[1], |
| | | "文件为空", |
| | | Messages.getInformationIcon());*/ |
| | | //去除换行 |
| | | object[1] = object[1].replace("\"\n","\"") |
| | | .replace(",\n",",") |
| | | .replace("\n,",",") |
| | | .replace("\n}","}") |
| | | .replace("}\n","}") |
| | | .replace("{\n","{"); |
| | | if(object[1].indexOf("{")==0){//是否为json字符串 |
| | | createResultFile(filePath, packageN,object); |
| | | }else{ |
| | | createResultFile(filePath,object[0],getFields(object[1].split(","),"public"),packageN,object[1].split(",")); |
| | | } |
| | | actionEvent.getProject().getBaseDir().refresh(false, true);//刷新项目 |
| | | } |
| | | |
| | | @Override |
| | | public void cancel(Object object) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 创建文件 |
| | | * @param filePath 文件路径 |
| | | */ |
| | | public void createResultFile(String filePath, String packageName, String[] object){ |
| | | |
| | | Map<String, Object> fieldMap = getFieldNormalMap(object[1]); |
| | | List<String> list = new ArrayList<>(); |
| | | for(String key: fieldMap.keySet()){ |
| | | if(fieldMap.get(key) instanceof List){ |
| | | list.addAll((List)fieldMap.get(key)); |
| | | }else{ |
| | | list.add(fieldMap.get(key).toString()); |
| | | } |
| | | } |
| | | createResultFile(filePath,object[0],getFields(object[1],"public"),packageName,list.toArray(new String[0])); |
| | | } |
| | | |
| | | /** |
| | | * 创建文件 |
| | | * @param filePath 文件路径 |
| | | * @param name 文件名称 |
| | | * @param fieldsStr 声明变量代码 |
| | | * @param packageName 包名 |
| | | * @param fields 变量名称集合 |
| | | */ |
| | | public abstract void createResultFile(String filePath, String name, String fieldsStr, String packageName, String[] fields ); |
| | | |
| | | } |
| New file |
| | |
| | | package com.runt.android.actions; |
| | | |
| | | import org.json.JSONArray; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * My father is Object, ites purpose of |
| | | * |
| | | * @purpose Created by Runt (qingingrunt2010@qq.com) on 2020-11-10. |
| | | */ |
| | | |
| | | public class CreateNormalResult extends BaseCreateApiResult { |
| | | |
| | | |
| | | /** |
| | | * 获取json中解析的变量集合 |
| | | * @param jsonStr |
| | | * @return |
| | | */ |
| | | @Override |
| | | protected Map<String,Object> getFieldNormalMap(String jsonStr){ |
| | | return getFieldNormalMap(new JSONObject(jsonStr)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取json中解析的变量集合 |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | @Override |
| | | protected Map<String,Object> getFieldNormalMap(JSONObject jsonObject){ |
| | | Map<String , Object> fieldMap = new HashMap<>(); |
| | | for(String key: jsonObject.keySet()){ |
| | | Object obj = jsonObject.get(key); |
| | | key = humpName(key);//驼峰命名 |
| | | String clssName = obj.getClass().getSimpleName();//声明变量的数据类型 |
| | | if(obj instanceof JSONArray){ |
| | | Object val = ((JSONArray)obj).get(0); |
| | | if(val instanceof JSONObject){ |
| | | //将声明的变量定义为变量数据类型 |
| | | String name = replaseS(key);//去复数 |
| | | clssName ="java.util.List<"+toUperFirst(name)+">"; |
| | | }else { |
| | | clssName ="java.util.List<"+val.getClass().getSimpleName()+">"; |
| | | } |
| | | }else if(obj instanceof JSONObject){ |
| | | //将声明的变量定义为变量数据类型 |
| | | clssName = toUperFirst(key); |
| | | } |
| | | //将key作为声明的变量名 |
| | | if(fieldMap.get(clssName) == null){//没有同数据类型的变量 |
| | | fieldMap.put(clssName,key); |
| | | }else if(fieldMap.get(clssName) instanceof List){//已有同数据类型的变量 |
| | | List vlus = (List) fieldMap.get(clssName); |
| | | vlus.add(key);//追加 |
| | | }else {//已有同数据类型的变量,转变为集合 |
| | | List vlus = new ArrayList(); |
| | | String field = fieldMap.get(clssName).toString(); |
| | | vlus.add(field); |
| | | vlus.add(key);//追加 |
| | | fieldMap.replace(clssName,vlus);//替换为集合 |
| | | } |
| | | } |
| | | return fieldMap; |
| | | } |
| | | |
| | | |
| | | protected String getClassStr (String json){ |
| | | return getClassStr(new JSONObject(json)); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 遍历json 创建内部类代码 |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | protected String getClassStr ( JSONObject jsonObject){ |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(String key: jsonObject.keySet()){//遍历 |
| | | Object obj = jsonObject.get(key); |
| | | if(obj instanceof JSONArray){ |
| | | Object val = ((JSONArray)obj).get(0); |
| | | if(val instanceof JSONObject){//判断值是否为object |
| | | String name = replaseS(key);//去复数 |
| | | sb.append(getClassStr(name,(JSONObject)val));//创建类代码 |
| | | } |
| | | }else if(obj instanceof JSONObject){//判断值是否为object |
| | | String name = replaseS(key);//去复数 |
| | | sb.append(getClassStr(name,(JSONObject)obj));//创建类代码 |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 生成内部类 |
| | | * @param name |
| | | * @param jsonObject |
| | | * @return |
| | | */ |
| | | private String getClassStr(String name,JSONObject jsonObject){ |
| | | |
| | | Map<String, Object> fieldMap = getFieldNormalMap(jsonObject); |
| | | List<String> list = new ArrayList<>(); |
| | | for(String key: fieldMap.keySet()){ |
| | | if(fieldMap.get(key) instanceof List){ |
| | | list.addAll((List)fieldMap.get(key)); |
| | | }else{ |
| | | list.add(fieldMap.get(key).toString()); |
| | | } |
| | | } |
| | | String classStr = getClassStr(jsonObject);//是否含有内部类 |
| | | |
| | | name = toUperFirst(name); |
| | | String template = getTemplateString("NormalClass") |
| | | .replace("{fields}", getFields(jsonObject))//替换写入声明变量 |
| | | .replace("{name}", name)//类名 |
| | | .replace("{class}",classStr)//内部类 |
| | | .replace("{toString}",getToString(name,list.toArray(new String[0]))); |
| | | return template; |
| | | } |
| | | |
| | | @Override |
| | | public void createResultFile(String filePath, String packageName, String[] object) { |
| | | |
| | | Map<String, Object> fieldMap = getFieldNormalMap(object[1]); |
| | | List<String> list = new ArrayList<>(); |
| | | for(String key: fieldMap.keySet()){ |
| | | if(fieldMap.get(key) instanceof List){ |
| | | list.addAll((List)fieldMap.get(key)); |
| | | }else{ |
| | | list.add(fieldMap.get(key).toString()); |
| | | } |
| | | } |
| | | createFile(filePath,object[0],getFields(object[1]),packageName,"NormalResult",list.toArray(new String[0]),getClassStr(object[1]),""); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void createResultFile(String filePath, String name, String fieldsStr, String packageName, String[] fields) { |
| | | createFile(filePath,name,fieldsStr,packageName,"NormalResult",fields,"",""); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 去掉复数形式 |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static String replaseS(String str){ |
| | | if( replaseS(str,"ves")){ |
| | | return str.replace("ves","f"); |
| | | |
| | | }else if( replaseS(str,"ies")){ |
| | | return str.replace("ies","y"); |
| | | |
| | | }else if( replaseS(str,"es")){ |
| | | return str.replace("es",""); |
| | | |
| | | }else if( replaseS(str,"s" ) ){ |
| | | return str.replace("s",""); |
| | | |
| | | }else if( replaseS(str,"men")){ |
| | | return str.replace("men","man"); |
| | | } |
| | | return str; |
| | | } |
| | | public static boolean replaseS(String str,String Sstr ){ |
| | | if(str.lastIndexOf(Sstr) == str.length()-Sstr.length()){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.zhenfei.plugin.dialogs.DoubleInputDialog"> |
| | | <grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> |
| | | <margin top="10" left="10" bottom="10" right="10"/> |
| | | <constraints> |
| | | <xy x="48" y="54" width="436" height="297"/> |
| | | </constraints> |
| | | <properties/> |
| | | <border type="none"/> |
| | | <children> |
| | | <grid id="94766" 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> |
| | | <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> |
| | | </constraints> |
| | | <properties/> |
| | | <border type="none"/> |
| | | <children> |
| | | <hspacer id="98af6"> |
| | | <constraints> |
| | | <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> |
| | | </constraints> |
| | | </hspacer> |
| | | <grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1"> |
| | | <margin top="0" left="0" bottom="0" right="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> |
| | | <component id="e7465" class="javax.swing.JButton" binding="buttonOK"> |
| | | <constraints> |
| | | <grid row="0" column="0" 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="OK"/> |
| | | </properties> |
| | | </component> |
| | | <component id="5723f" class="javax.swing.JButton" binding="buttonCancel"> |
| | | <constraints> |
| | | <grid row="0" column="1" 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="Cancel"/> |
| | | </properties> |
| | | </component> |
| | | </children> |
| | | </grid> |
| | | </children> |
| | | </grid> |
| | | <grid id="e3588" layout-manager="GridLayoutManager" row-count="5" 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> |
| | | <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> |
| | | <vspacer id="8d275"> |
| | | <constraints> |
| | | <grid row="0" column="0" row-span="5" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> |
| | | </constraints> |
| | | </vspacer> |
| | | <component id="d4082" class="javax.swing.JTextField" binding="textField1" default-binding="true"> |
| | | <constraints> |
| | | <grid row="1" 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> |
| | | </constraints> |
| | | <properties> |
| | | <text value=""/> |
| | | </properties> |
| | | </component> |
| | | <component id="f7553" class="javax.swing.JLabel"> |
| | | <constraints> |
| | | <grid row="0" column="1" 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="6beb2" class="javax.swing.JLabel"> |
| | | <constraints> |
| | | <grid row="2" column="1" 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="参数声明(json数据或英文“,”分隔)"/> |
| | | </properties> |
| | | </component> |
| | | <scrollpane id="5cadd"> |
| | | <constraints> |
| | | <grid row="3" column="1" row-span="2" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> |
| | | </constraints> |
| | | <properties/> |
| | | <border type="none"/> |
| | | <children> |
| | | <component id="9f376" class="javax.swing.JTextArea" binding="textArea1" default-binding="true"> |
| | | <constraints/> |
| | | <properties> |
| | | <text value=""/> |
| | | </properties> |
| | | </component> |
| | | </children> |
| | | </scrollpane> |
| | | </children> |
| | | </grid> |
| | | </children> |
| | | </grid> |
| | | </form> |
| New file |
| | |
| | | package com.runt.android.dialogs; |
| | | |
| | | import java.awt.Color; |
| | | import java.awt.event.ActionEvent; |
| | | import java.awt.event.ActionListener; |
| | | import java.awt.event.KeyEvent; |
| | | import java.awt.event.WindowAdapter; |
| | | import java.awt.event.WindowEvent; |
| | | |
| | | import javax.swing.JButton; |
| | | import javax.swing.JComponent; |
| | | import javax.swing.JDialog; |
| | | import javax.swing.JPanel; |
| | | import javax.swing.JTextArea; |
| | | import javax.swing.JTextField; |
| | | import javax.swing.KeyStroke; |
| | | |
| | | /** |
| | | * 输入弹框 |
| | | */ |
| | | public class DoubleInputDialog extends JDialog { |
| | | private JPanel contentPane; |
| | | private JButton buttonOK; |
| | | private JButton buttonCancel; |
| | | private JTextField textField1; |
| | | private JTextArea textArea1; |
| | | DialogListener listener; |
| | | |
| | | public DoubleInputDialog(DialogListener listener){ |
| | | this(); |
| | | this.listener = listener; |
| | | } |
| | | |
| | | public DoubleInputDialog() { |
| | | setContentPane(contentPane); |
| | | setModal(true); |
| | | getRootPane().setDefaultButton(buttonOK); |
| | | buttonOK.addActionListener(new ActionListener() { |
| | | public void actionPerformed(ActionEvent e) { |
| | | onOK(); |
| | | } |
| | | }); |
| | | |
| | | buttonCancel.addActionListener(new ActionListener() { |
| | | public void actionPerformed(ActionEvent e) { |
| | | onCancel(); |
| | | } |
| | | }); |
| | | |
| | | // call onCancel() when cross is clicked |
| | | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
| | | addWindowListener(new WindowAdapter() { |
| | | public void windowClosing(WindowEvent e) { |
| | | onCancel(); |
| | | } |
| | | }); |
| | | textArea1.setSize(300,400); |
| | | textArea1.setRows(10); |
| | | textArea1.setColumns(11); |
| | | textArea1.setTabSize(4); |
| | | textArea1.setSelectedTextColor(Color.RED); |
| | | textArea1.setSelectionColor(Color.BLACK); |
| | | textArea1.setLineWrap(true); //激活自动换行功能 |
| | | //textAreaOutput.setEnabled(false); |
| | | textArea1.setWrapStyleWord(true); |
| | | |
| | | contentPane.registerKeyboardAction(new ActionListener() { |
| | | public void actionPerformed(ActionEvent e) { |
| | | onCancel(); |
| | | } |
| | | }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); |
| | | } |
| | | |
| | | private void onOK() { |
| | | // add your code here |
| | | dispose(); |
| | | if(listener != null){ |
| | | listener.Ok(new String[]{textField1.getText(),textArea1.getText()}); |
| | | } |
| | | } |
| | | |
| | | private void onCancel() { |
| | | // add your code here if necessary |
| | | dispose(); |
| | | } |
| | | |
| | | public interface DialogListener{ |
| | | |
| | | public void Ok(String[] object); |
| | | |
| | | public void cancel(Object object); |
| | | |
| | | } |
| | | public static void main(String[] args) { |
| | | DoubleInputDialog dialog = new DoubleInputDialog(); |
| | | dialog.pack(); |
| | | dialog.setVisible(true); |
| | | System.exit(0); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.runt.android.utils; |
| | | |
| | | import com.intellij.openapi.project.Project; |
| | | |
| | | import org.w3c.dom.Document; |
| | | import org.w3c.dom.Element; |
| | | import org.w3c.dom.Node; |
| | | import org.w3c.dom.NodeList; |
| | | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import javax.xml.parsers.DocumentBuilder; |
| | | import javax.xml.parsers.DocumentBuilderFactory; |
| | | |
| | | /** |
| | | * Created by 赵振良 on 2020/8/6 |
| | | */ |
| | | public class Util { |
| | | private static Pattern humpPattern = Pattern.compile("[A-Z]"); |
| | | |
| | | /** |
| | | * 获取路径名 |
| | | */ |
| | | public static String getPackageDir(Project project, String dir) { |
| | | String packageName = ""; |
| | | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| | | try { |
| | | DocumentBuilder db = dbf.newDocumentBuilder(); |
| | | Document doc = db.parse(project.getBasePath() + "/app/src/main/AndroidManifest.xml"); |
| | | NodeList nodeList = doc.getElementsByTagName("manifest"); |
| | | for (int i = 0; i < nodeList.getLength(); i++) { |
| | | Node node = nodeList.item(i); |
| | | Element element = (Element) node; |
| | | packageName = element.getAttribute("package"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String split = packageName.replace(".","/"); |
| | | String dirs[] = dir.split(split); |
| | | if(dirs.length < 2){ |
| | | return packageName; |
| | | }else{ |
| | | String resultPackage = packageName+(dirs[1].replace("/",".")); |
| | | return resultPackage; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取包名 |
| | | * @param project |
| | | * @return |
| | | */ |
| | | public static String getPackageId(Project project){ |
| | | String packageName = ""; |
| | | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| | | try { |
| | | DocumentBuilder db = dbf.newDocumentBuilder(); |
| | | Document doc = db.parse(project.getBasePath() + "/app/src/main/AndroidManifest.xml"); |
| | | NodeList nodeList = doc.getElementsByTagName("manifest"); |
| | | for (int i = 0; i < nodeList.getLength(); i++) { |
| | | Node node = nodeList.item(i); |
| | | Element element = (Element) node; |
| | | packageName = element.getAttribute("package"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return packageName; |
| | | } |
| | | |
| | | /** |
| | | * 驼峰命名转下划线命名 |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static String humpToLine(String str) { |
| | | Matcher matcher = humpPattern.matcher(str); |
| | | StringBuffer sb = new StringBuffer(); |
| | | while (matcher.find()) { |
| | | matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase()); |
| | | } |
| | | matcher.appendTail(sb); |
| | | String result = sb.toString(); |
| | | int length = result.length(); |
| | | if(result.startsWith("_")){ |
| | | result = result.substring(1,length); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| New file |
| | |
| | | public class {name} { |
| | | |
| | | //以下为声明的参数 |
| | | {fields} |
| | | |
| | | |
| | | {toString} |
| | | |
| | | |
| | | {class} |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package {package}; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {desc} 说明 |
| | | * Created by {author} on {date} |
| | | */ |
| | | public class {name} { |
| | | |
| | | //以下为声明的参数 |
| | | {fields} |
| | | |
| | | |
| | | {toString} |
| | | |
| | | |
| | | {class} |
| | | |
| | | } |