Browse Source

Merge pull request #45 in BA/design from ~VITO/design:dev to dev

* commit '33b0cb649654912278a66ec7d09264c29d877973':
  防止出现null
  使用sitecenter
  添加国际化 换新的api命名以区分重载防止js调用时冲突
  1、自动检测下载商店脚本 2、详情点击可以使用
  屏蔽右键
master
richie 9 years ago
parent
commit
c6922f787c
  1. 4
      designer_base/src/com/fr/design/extra/PluginHelper.java
  2. 71
      designer_base/src/com/fr/design/extra/PluginManagerPane.java
  3. 5
      designer_base/src/com/fr/design/extra/PluginTask.java
  4. 18
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  5. 24
      designer_base/src/com/fr/design/extra/PluginWebPane.java

4
designer_base/src/com/fr/design/extra/PluginHelper.java

@ -31,8 +31,8 @@ import java.util.concurrent.ExecutionException;
*/ */
public class PluginHelper { public class PluginHelper {
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp";
private static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download";
private static final String TEMP_FILE = "temp.zip"; public static final String TEMP_FILE = "temp.zip";
/** /**
* 下载插件 * 下载插件

71
designer_base/src/com/fr/design/extra/PluginManagerPane.java

@ -1,10 +1,18 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.general.GeneralUtils;
import com.fr.general.IOUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.stable.StableUtils;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.net.URL; import java.net.URL;
/** /**
@ -24,9 +32,27 @@ public class PluginManagerPane extends BasicPane {
public PluginManagerPane() { public PluginManagerPane() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
if (System.getProperty("java.version").startsWith("1.8")) { if (System.getProperty("java.version").startsWith("1.8")) {
URL url = ClassLoader.getSystemResource(""); String installHome;
String installHome = url.getPath(); if (StableUtils.isDebug()) {
PluginWebPane webPane = new PluginWebPane(installHome); URL url = ClassLoader.getSystemResource("");
installHome = url.getPath();
} else {
installHome = StableUtils.getInstallHome();
File file = new File(StableUtils.pathJoin(installHome, "scripts"));
if (!file.exists()) {
int rv = JOptionPane.showConfirmDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE
);
if (rv == JOptionPane.OK_OPTION) {
downloadShopScripts();
}
}
}
PluginWebPane webPane = new PluginWebPane(new File(installHome).getAbsolutePath());
add(webPane, BorderLayout.CENTER); add(webPane, BorderLayout.CENTER);
} else { } else {
initTraditionalStore(); initTraditionalStore();
@ -42,6 +68,45 @@ public class PluginManagerPane extends BasicPane {
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane));
} }
private void downloadShopScripts() {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
String id = "shop_scripts";
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
}
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
return null;
}
@Override
protected void done() {
IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome());
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Shop_Installed"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
}
}.execute();
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer-Plugin_Manager"); return Inter.getLocText("FR-Designer-Plugin_Manager");

5
designer_base/src/com/fr/design/extra/PluginTask.java

@ -71,6 +71,9 @@ public class PluginTask<T> extends Task<T> {
* @return 处理之后的字符串 * @return 处理之后的字符串
*/ */
private String changText(String old) { private String changText(String old) {
return old.replaceAll("\"", "\\\\\"").replaceAll("\n", ""); if(StringUtils.isNotBlank(old)){
return old.replaceAll("\"", "\\\\\"").replaceAll("\n", "");
}
return StringUtils.EMPTY;
} }
} }

18
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -6,6 +6,7 @@ import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*; import com.fr.design.extra.exe.*;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.plugin.Plugin; import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader; import com.fr.plugin.PluginLoader;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
@ -33,7 +34,7 @@ public class PluginWebBridge {
private UIDialog uiDialog; private UIDialog uiDialog;
public static final String PLUGIN_SHOP = "http://192.168.101.20/ShopServer?pg=plist"; public static final String PLUGIN_SHOP = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
public static PluginWebBridge getHelper() { public static PluginWebBridge getHelper() {
if (helper != null) { if (helper != null) {
@ -261,6 +262,17 @@ public class PluginWebBridge {
} }
} }
/**
* 在本地浏览器里打开url
* tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑)
* 所以最好的是不要重载在js可以访问的接口文件中
*
* @param url 要打开的地址
*/
public void openShopUrlAtWebBrowser(String url) {
openUrlAtLocalWebBrowser(webEngine, url);
}
/** /**
* 在本地浏览器里打开url * 在本地浏览器里打开url
* *
@ -289,10 +301,6 @@ public class PluginWebBridge {
} }
} }
public void openUrlAtLocalWebBrowser(String url) {
openUrlAtLocalWebBrowser(webEngine, url);
}
/** /**
* 从硬盘升级 * 从硬盘升级
* *

24
designer_base/src/com/fr/design/extra/PluginWebPane.java

@ -1,9 +1,6 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.general.FRLogger;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel; import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -39,33 +36,14 @@ public class PluginWebPane extends JFXPanel {
showAlert(event.getData()); showAlert(event.getData());
} }
}); });
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
disableLink(webEngine);
PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue);
}
});
JSObject obj = (JSObject) webEngine.executeScript("window"); JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView); root.setCenter(webView);
} }
}); });
} }
private void disableLink(final WebEngine webEngine) {
try {
Platform.runLater(new Runnable() {
@Override
public void run() {
webEngine.executeScript("history.go(0)");
}
});
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
private void showAlert(final String message) { private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

Loading…
Cancel
Save