Browse Source

格式化JavaScript代码+登录接口

master
RichieJi 7 years ago
parent
commit
3ee3f35bff
  1. BIN
      designer_base/src/com/fr/design/images/edit/format.png
  2. 241
      designer_base/src/com/fr/design/javascript/JSContentPane.java
  3. 1
      designer_base/src/com/fr/design/locale/designer.properties
  4. 1
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  5. 1
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  6. 1
      designer_base/src/com/fr/design/locale/designer_ko_KR.properties
  7. 1
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  8. 1
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties

BIN
designer_base/src/com/fr/design/images/edit/format.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

241
designer_base/src/com/fr/design/javascript/JSContentPane.java

@ -1,37 +1,76 @@
package com.fr.design.javascript; package com.fr.design.javascript;
import com.fr.design.constants.KeyWords;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.gui.autocomplete.*; import com.fr.design.constants.KeyWords;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.autocomplete.AutoCompletion;
import com.fr.design.gui.autocomplete.BasicCompletion;
import com.fr.design.gui.autocomplete.CompletionProvider;
import com.fr.design.gui.autocomplete.DefaultCompletionProvider;
import com.fr.design.gui.autocomplete.ShorthandCompletion;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants;
import com.fr.design.javascript.beautify.JavaScriptFormatHelper;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.dialog.BasicPane; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.ArrayList;
public class JSContentPane extends BasicPane { public class JSContentPane extends BasicPane {
private RSyntaxTextArea contentTextArea; private RSyntaxTextArea contentTextArea;
private UILabel funNameLabel; private UILabel funNameLabel;
private int titleWidth = 180; private int titleWidth = 180;
public JSContentPane(String[] args) { public JSContentPane(String[] args) {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
funNameLabel = new UILabel(); funNameLabel = new UILabel();
this.setFunctionTitle(args); this.setFunctionTitle(args);
this.add(funNameLabel, BorderLayout.NORTH);
UILabel label = new UILabel(Inter.getLocText("FR-Designer_Format_JavaScript"), IOUtils.readIcon("com/fr/design/images/edit/format.png"), SwingConstants.LEFT);
contentTextArea = new RSyntaxTextArea(); label.setCursor(new Cursor(Cursor.HAND_CURSOR));
contentTextArea.setCloseCurlyBraces(true); label.setToolTipText(Inter.getLocText("FR-Designer_Format_JavaScript"));
contentTextArea.setLineWrap(true); label.addMouseListener(new MouseAdapter() {
contentTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); @Override
contentTextArea.setCodeFoldingEnabled(true); public void mouseReleased(MouseEvent e) {
contentTextArea.setAntiAliasingEnabled(true); new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws Exception {
return JavaScriptFormatHelper.beautify(contentTextArea.getText());
}
@Override
protected void done() {
try {
String text = get();
contentTextArea.setText(text);
} catch (Exception ignore) {
}
}
}.execute();
}
});
this.add(GUICoreUtils.createBorderLayoutPane(
funNameLabel, BorderLayout.WEST,
label, BorderLayout.EAST
), BorderLayout.NORTH);
contentTextArea = new RSyntaxTextArea();
contentTextArea.setCloseCurlyBraces(true);
contentTextArea.setLineWrap(true);
contentTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
contentTextArea.setCodeFoldingEnabled(true);
contentTextArea.setAntiAliasingEnabled(true);
CompletionProvider provider = createCompletionProvider(); CompletionProvider provider = createCompletionProvider();
@ -41,93 +80,93 @@ public class JSContentPane extends BasicPane {
ac.setTriggerKey(convert2KeyStroke(shortCuts)); ac.setTriggerKey(convert2KeyStroke(shortCuts));
ac.install(contentTextArea); ac.install(contentTextArea);
UIScrollPane sp = new UIScrollPane(contentTextArea); UIScrollPane sp = new UIScrollPane(contentTextArea);
this.add(sp, BorderLayout.CENTER); this.add(sp, BorderLayout.CENTER);
UILabel funNameLabel2 = new UILabel(); UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}"); funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH); this.add(funNameLabel2, BorderLayout.SOUTH);
} }
private KeyStroke convert2KeyStroke(String ks) { private KeyStroke convert2KeyStroke(String ks) {
return KeyStroke.getKeyStroke(ks.replace("+", "pressed")); return KeyStroke.getKeyStroke(ks.replace("+", "pressed"));
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return "JS"; return "JS";
} }
public void populate(String js) { public void populate(String js) {
this.contentTextArea.setText(js); this.contentTextArea.setText(js);
} }
public String update() { public String update() {
return this.contentTextArea.getText(); return this.contentTextArea.getText();
} }
public void setFunctionTitle(String[] args) { public void setFunctionTitle(String[] args) {
funNameLabel.setText(createFunctionTitle(args)); funNameLabel.setText(createFunctionTitle(args));
} }
public void setFunctionTitle(String[] args, String[] defaultArgs) { public void setFunctionTitle(String[] args, String[] defaultArgs) {
String[] titles; String[] titles;
if (defaultArgs == null) { if (defaultArgs == null) {
titles = args; titles = args;
} else if (args == null) { } else if (args == null) {
titles = defaultArgs; titles = defaultArgs;
} else { } else {
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
for (String s : defaultArgs) { for (String s : defaultArgs) {
list.add(s); list.add(s);
} }
for (String s : args) { for (String s : args) {
list.add(s); list.add(s);
} }
titles = (String[])list.toArray(new String[list.size()]); titles = (String[]) list.toArray(new String[list.size()]);
} }
setFunctionTitle(titles); setFunctionTitle(titles);
} }
/** /**
* 用html方便换行 * 用html方便换行
* *
* @param args * @param args
* @return * @return
*/ */
private String createFunctionTitle(String[] args) { private String createFunctionTitle(String[] args) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("<html> <body> <div style='height:16px'>function("); sb.append("<html> <body> <div style='height:16px'>function(");
int width = titleWidth; int width = titleWidth;
FontMetrics cellFM = this.getFontMetrics(this.getFont()); FontMetrics cellFM = this.getFontMetrics(this.getFont());
int tempwidth = 0; int tempwidth = 0;
if (args != null) { if (args != null) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (args[i] == null) { if (args[i] == null) {
continue; continue;
} }
if (cellFM.stringWidth(args[i]) < width) { if (cellFM.stringWidth(args[i]) < width) {
tempwidth = tempwidth + cellFM.stringWidth(args[i]); tempwidth = tempwidth + cellFM.stringWidth(args[i]);
if (tempwidth < width) { if (tempwidth < width) {
sb.append(args[i]); sb.append(args[i]);
if (i != args.length - 1) { if (i != args.length - 1) {
sb.append(","); sb.append(",");
} }
} else { } else {
tempwidth = 0; tempwidth = 0;
i = i - 1;// 后退一步 i = i - 1;// 后退一步
sb.append("</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp;"); sb.append("</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp;");
} }
} else { } else {
sb.append("</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp;"); sb.append("</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp;");
sb.append(args[i]); sb.append(args[i]);
sb.append("</p>"); sb.append("</p>");
} }
} }
} }
sb.append("){</div><body> </html>"); sb.append("){</div><body> </html>");
return sb.toString(); return sb.toString();
} }
private CompletionProvider createCompletionProvider() { private CompletionProvider createCompletionProvider() {

1
designer_base/src/com/fr/design/locale/designer.properties

@ -2148,3 +2148,4 @@ FR-Designer_Sheet_Label_Page_Display_Position=
FR-Designer_Provide_Choose_All= FR-Designer_Provide_Choose_All=
FR-Designer_Decimal_Places= FR-Designer_Decimal_Places=
FR-Designer_Env_Des_Https=If HTTPS is enabled or the HTTPS configuration (certificate path, HTTPS key) is modified, you must restart the designer to take effect. FR-Designer_Env_Des_Https=If HTTPS is enabled or the HTTPS configuration (certificate path, HTTPS key) is modified, you must restart the designer to take effect.
FR-Designer_Format_JavaScript=Format Code

1
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -2147,3 +2147,4 @@ FR-Designer_Sheet_Label_Page_Display_Position=
FR-Designer_Provide_Choose_All= FR-Designer_Provide_Choose_All=
FR-Designer_Decimal_Places= FR-Designer_Decimal_Places=
FR-Designer_Env_Des_Https=If HTTPS is enabled or the HTTPS configuration (certificate path, HTTPS key) is modified, you must restart the designer to take effect. FR-Designer_Env_Des_Https=If HTTPS is enabled or the HTTPS configuration (certificate path, HTTPS key) is modified, you must restart the designer to take effect.
FR-Designer_Format_JavaScript=Format Code

1
designer_base/src/com/fr/design/locale/designer_ja_JP.properties

@ -2148,3 +2148,4 @@ FR-Designer_Provide_Choose_All=\u5168\u9078\u629E\u53EF\u80FD
FR-Designer_Decimal_Places=\u5C0F\u6570\u67A0\u6570: FR-Designer_Decimal_Places=\u5C0F\u6570\u67A0\u6570:
FR-Base-Load_Resource_File=\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u30ED\u30FC\u30C9 FR-Base-Load_Resource_File=\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u30ED\u30FC\u30C9
FR-Designer_Env_Des_Https= FR-Designer_Env_Des_Https=
FR-Designer_Format_JavaScript=Format Code

1
designer_base/src/com/fr/design/locale/designer_ko_KR.properties

@ -2148,3 +2148,4 @@ FR-Base-Load_Resource_File=\uB85C\uB529\uAD6C\uC131\uD30C\uC77C
FR-Designer_Export_Background= FR-Designer_Export_Background=
FR-Designer_Print_Background= FR-Designer_Print_Background=
FR-Designer_Env_Des_Https= FR-Designer_Env_Des_Https=
FR-Designer_Format_JavaScript=Format Code

1
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -2148,3 +2148,4 @@ FR-Designer_Sheet_Label_Page_Display_Position=
FR-Designer_Provide_Choose_All= FR-Designer_Provide_Choose_All=
FR-Designer_Decimal_Places= FR-Designer_Decimal_Places=
FR-Designer_Env_Des_Https=\u82E5\u542F\u7528https\u6216\u4FEE\u6539https\u914D\u7F6E\uFF08\u8BC1\u4E66\u8DEF\u5F84\u3001https\u79D8\u94A5\uFF09\uFF0C\u5FC5\u987B\u91CD\u542F\u8BBE\u8BA1\u5668\u624D\u80FD\u751F\u6548\u3002 FR-Designer_Env_Des_Https=\u82E5\u542F\u7528https\u6216\u4FEE\u6539https\u914D\u7F6E\uFF08\u8BC1\u4E66\u8DEF\u5F84\u3001https\u79D8\u94A5\uFF09\uFF0C\u5FC5\u987B\u91CD\u542F\u8BBE\u8BA1\u5668\u624D\u80FD\u751F\u6548\u3002
FR-Designer_Format_JavaScript=\u683C\u5F0F\u5316\u4EE3\u7801

1
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -2147,3 +2147,4 @@ FR-Designer_Sheet_Label_Page_Display_Position=
FR-Designer_Provide_Choose_All= FR-Designer_Provide_Choose_All=
FR-Designer_Decimal_Places= FR-Designer_Decimal_Places=
FR-Designer_Env_Des_Https=\u82E5\u555F\u7528https\u6216\u4FEE\u6539https\u914D\u7F6E\uFF08\u8B49\u66F8\u8DEF\u5F91\u3001https\u7955\u9470\uFF09\uFF0C\u5FC5\u9808\u91CD\u555F\u8A2D\u8A08\u5668\u624D\u80FD\u751F\u6548\u3002 FR-Designer_Env_Des_Https=\u82E5\u555F\u7528https\u6216\u4FEE\u6539https\u914D\u7F6E\uFF08\u8B49\u66F8\u8DEF\u5F91\u3001https\u7955\u9470\uFF09\uFF0C\u5FC5\u9808\u91CD\u555F\u8A2D\u8A08\u5668\u624D\u80FD\u751F\u6548\u3002
FR-Designer_Format_JavaScript=Format Code

Loading…
Cancel
Save