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