背景
以往在eclipse上面开发插件,有兴致想尝试idea上玩一下插件开发。想要在idea上面访问web地址
概要
记录在idea上面访问web地址
正文
1、点击File->New->Project… 选择IntelliJ Platform Plugin
2、点击下一步后,输入Project Name,然后点击完成
3、新建Factory
package ***.demo.view;
import ***.intellij.openapi.project.Project;
import ***.intellij.openapi.wm.ToolWindow;
import ***.intellij.openapi.wm.ToolWindowFactory;
import ***.intellij.ui.content.Content;
import ***.intellij.ui.content.ContentManager;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author twilight
* @since V1.0
*/
public class MyToolWindowFactory implements ToolWindowFactory {
@Override
public void createToolWindowContent(
@NotNull Project project,
@NotNull ToolWindow toolWindow) {
ContentManager contentManager = toolWindow.getContentManager();
JFXPanel jfxPanel = new JFXPanel();
jfxPanel.setBounds(0,0,100,200);
Platform.runLater(new Runnable() {
@Override
public void run() {
WebView webView = new WebView();
jfxPanel.setScene(new Scene(webView));
webView.getEngine().load("https://m.runoob.***/maven/");
}
});
Content labelContent =
contentManager.getFactory()
.createContent(
jfxPanel,
"",
false
);
contentManager.addContent(labelContent);
}
}
4、修改plugin.xml
<idea-plugin>
<id>***.demo.view.plugin.id</id>
<name>***.jcef.***pany</name>
<version>1.0</version>
<vendor email="support1@your***pany.***" url="http://www.your***p1any.***">Your111***pany</vendor>
<description>***.demo.view.plugin.desc/***.demo.view.plugin.desc</description>
<change-notes>***.demo.view.plugin.desc***.demo.view.plugin.desc
</change-notes>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_***patibility.html
on how to target different products -->
<!-- un***ment to enable plugin in all products
<depends>***.intellij.modules.lang</depends>
-->
<!-- plugin.xml文件 -->
<extensions defaultExtensionNs="***.intellij">
<!-- Add your extensions here -->
<!-- id是必须的属性,我们进行添加 -->
<!-- anchor锚点非必须,但是为了像Gradle插件一样默认显示在右边,我们设置为right -->
<toolWindow id="web browser"
anchor="right"
factoryClass="***.demo.view.MyToolWindowFactory"
/>
</extensions>
</idea-plugin>
5、打包插件
Build->PreparePlugin Module "XXX" For Deployment
6、安装插件
File->settings...->Plugins
Restart IDE
7、运行插件