vito
8 years ago
13 changed files with 931 additions and 699 deletions
@ -0,0 +1,53 @@
|
||||
package com.fr.design.actions.server; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.extra.ShopDialog; |
||||
import com.fr.design.extra.PluginWebBridge; |
||||
import com.fr.design.extra.WebManagerPaneFactory; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/27. |
||||
*/ |
||||
public class ReuseManagerAction extends UpdateAction { |
||||
|
||||
public ReuseManagerAction() { |
||||
this.setMenuKeySet(REUSE_MANAGER); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/server/plugin.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
BasicPane managerPane = new WebManagerPaneFactory().createReusePane(); |
||||
UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); |
||||
PluginWebBridge.getHelper().setDialogHandle(dlg); |
||||
dlg.setVisible(true); |
||||
} |
||||
|
||||
public static final MenuKeySet REUSE_MANAGER = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'R'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return Inter.getLocText("FR-Designer-Reuse_Manager"); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return null; |
||||
} |
||||
}; |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import javafx.scene.web.WebEngine; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public class ReuseWebBridge { |
||||
public static ReuseWebBridge helper; |
||||
private WebEngine webEngine; |
||||
|
||||
public static ReuseWebBridge getHelper() { |
||||
if (helper != null) { |
||||
return helper; |
||||
} |
||||
synchronized (ReuseWebBridge.class) { |
||||
if (helper == null) { |
||||
helper = new ReuseWebBridge(); |
||||
} |
||||
return helper; |
||||
} |
||||
} |
||||
|
||||
public static ReuseWebBridge getHelper(WebEngine webEngine) { |
||||
getHelper(); |
||||
helper.setEngine(webEngine); |
||||
return helper; |
||||
} |
||||
|
||||
private ReuseWebBridge() { |
||||
} |
||||
|
||||
public void setEngine(WebEngine webEngine) { |
||||
this.webEngine = webEngine; |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import javafx.application.Platform; |
||||
import javafx.embed.swing.JFXPanel; |
||||
import javafx.event.EventHandler; |
||||
import javafx.scene.Scene; |
||||
import javafx.scene.layout.BorderPane; |
||||
import javafx.scene.web.WebEngine; |
||||
import javafx.scene.web.WebEvent; |
||||
import javafx.scene.web.WebView; |
||||
import netscape.javascript.JSObject; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public class ReuseWebPane extends JFXPanel { |
||||
private WebEngine webEngine; |
||||
|
||||
public ReuseWebPane(final String mainJs) { |
||||
Platform.setImplicitExit(false); |
||||
Platform.runLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
BorderPane root = new BorderPane(); |
||||
Scene scene = new Scene(root); |
||||
ReuseWebPane.this.setScene(scene); |
||||
WebView webView = new WebView(); |
||||
webEngine = webView.getEngine(); |
||||
webEngine.load("file:///" + mainJs); |
||||
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { |
||||
@Override |
||||
public void handle(WebEvent<String> event) { |
||||
showAlert(event.getData()); |
||||
} |
||||
}); |
||||
JSObject obj = (JSObject) webEngine.executeScript("window"); |
||||
obj.setMember("ReuseHelper", ReuseWebBridge.getHelper(webEngine)); |
||||
webView.setContextMenuEnabled(false);//屏蔽右键
|
||||
root.setCenter(webView); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void showAlert(final String message) { |
||||
SwingUtilities.invokeLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
JOptionPane.showMessageDialog(ReuseWebPane.this, message); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import javafx.embed.swing.JFXPanel; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public abstract class ShopPaneConfig { |
||||
private String mainJS; |
||||
private String scriptsId; |
||||
private JFXPanel webPane; |
||||
|
||||
public ShopPaneConfig() { |
||||
this.mainJS = getMainJS(); |
||||
this.scriptsId = getScriptsId(); |
||||
this.webPane = getWebPane(); |
||||
} |
||||
|
||||
abstract String getMainJS(); |
||||
|
||||
abstract String getScriptsId(); |
||||
|
||||
abstract JFXPanel getWebPane(); |
||||
} |
@ -0,0 +1,99 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.frpane.UITabbedPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import javafx.embed.swing.JFXPanel; |
||||
|
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.net.URL; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public class WebManagerPaneFactory { |
||||
private String installHome; |
||||
|
||||
public WebManagerPaneFactory() { |
||||
if (StableUtils.isDebug()) { |
||||
URL url = ClassLoader.getSystemResource(""); |
||||
this.installHome = url.getPath(); |
||||
} else { |
||||
this.installHome = StableUtils.getInstallHome(); |
||||
} |
||||
} |
||||
|
||||
public BasicPane createPluginPane() { |
||||
if (StableUtils.getMajorJavaVersion() == 8) { |
||||
return new ShopManagerPane(new ShopPaneConfig() { |
||||
@Override |
||||
String getMainJS() { |
||||
String relativePath = "/scripts/store/web/index.html"; |
||||
return StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); |
||||
} |
||||
|
||||
@Override |
||||
String getScriptsId() { |
||||
return "shop_scripts"; |
||||
} |
||||
|
||||
@Override |
||||
JFXPanel getWebPane() { |
||||
return new PluginWebPane(getMainJS()); |
||||
} |
||||
|
||||
}); |
||||
} else { |
||||
BasicPane traditionalStorePane = new BasicPane() { |
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer-Plugin_Manager"); |
||||
} |
||||
}; |
||||
traditionalStorePane.setLayout(new BorderLayout()); |
||||
traditionalStorePane.add(initTraditionalStore(), BorderLayout.CENTER); |
||||
return traditionalStorePane; |
||||
} |
||||
} |
||||
|
||||
public BasicPane createReusePane() { |
||||
return new ShopManagerPane(new ShopPaneConfig() { |
||||
@Override |
||||
String getMainJS() { |
||||
String relativePath = "/scripts/store/reuse/index.html"; |
||||
return StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); |
||||
} |
||||
|
||||
@Override |
||||
String getScriptsId() { |
||||
return "reuse_scripts"; |
||||
} |
||||
|
||||
@Override |
||||
JFXPanel getWebPane() { |
||||
return new ReuseWebPane(getMainJS()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 以关键词打开设计器商店 |
||||
* |
||||
* @param keyword 关键词 |
||||
*/ |
||||
public BasicPane createPluginPane(String keyword) { |
||||
PluginWebBridge.getHelper().openWithSearch(keyword); |
||||
return createPluginPane(); |
||||
} |
||||
|
||||
private Component initTraditionalStore() { |
||||
UITabbedPane tabbedPane = new UITabbedPane(); |
||||
PluginInstalledPane installedPane = new PluginInstalledPane(); |
||||
tabbedPane.addTab(installedPane.tabTitle(), installedPane); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); |
||||
return tabbedPane; |
||||
} |
||||
} |
Loading…
Reference in new issue