美文网首页
(十)IntelliJ 插件开发—— JBSplitter(分离

(十)IntelliJ 插件开发—— JBSplitter(分离

作者: 秋水畏寒 | 来源:发表于2020-03-08 15:38 被阅读0次

    官方文档

    https://www.jetbrains.org/intellij/sdk/docs/user_interface_components/misc_swing_components.html

    Github

    https://github.com/kungyutucheng/my_gradle_plugin

    运行环境

    macOS 10.14.5
    IntelliJ idea 2019.2.4

    效果

    初始效果 拖动效果(proportion设置为0.3F)

    Demo

    JBSplitterAction

    package com.kungyu.jbsplitter;
    
    import com.intellij.openapi.actionSystem.AnAction;
    import com.intellij.openapi.actionSystem.AnActionEvent;
    import org.jetbrains.annotations.NotNull;
    
    /**
     * @author wengyongcheng
     * @since 2020/3/8 2:39 下午
     */
    public class JBSplitterAction extends AnAction {
        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            new JBSplitterDialogWrapper().showAndGet();
        }
    }
    
    

    注册Action

    <action id="com.kungyu.jbsplitter.JBSplitterAction" class="com.kungyu.jbsplitter.JBSplitterAction"
                    text="JBSplitterAction" description="JBSplitterAction">
        <add-to-group group-id="ToolsMenu" anchor="after" relative-to-action="com.kungyu.tree.TreeAction"/>
    </action>
    

    JBSplitterDialogWrapper

    package com.kungyu.jbsplitter;
    
    import com.intellij.openapi.ui.DialogWrapper;
    import com.intellij.openapi.wm.ToolWindow;
    import com.intellij.ui.JBSplitter;
    import javafx.scene.layout.BorderPane;
    import org.jetbrains.annotations.Nullable;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     * @author wengyongcheng
     * @since 2020/3/8 2:40 下午
     */
    public class JBSplitterDialogWrapper extends DialogWrapper {
    
        private JBSplitter splitter;
    
        public JBSplitterDialogWrapper() {
            super(true);
            init();
            setTitle("JBSplitter");
        }
    
        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            splitter = new JBSplitter();
            JPanel firstPanel = new JPanel();
            firstPanel.add(new JLabel("First Panel"));
            firstPanel.setBorder(BorderFactory.createTitledBorder("First Panel"));
            splitter.setFirstComponent(firstPanel);
    
            JPanel secondPanel = new JPanel();
            secondPanel.add(new JLabel("Second Panel"));
            secondPanel.setBorder(BorderFactory.createTitledBorder("Second Panel"));
            splitter.setSecondComponent(secondPanel);
    
            // 记录当前俩个组件的比例,存放到map中,key即为该值
            splitter.setSplitterProportionKey("customProportionKey");
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            panel.add(splitter, BorderLayout.CENTER);
            return panel;
        }
    }
    
    

    相关文章

      网友评论

          本文标题:(十)IntelliJ 插件开发—— JBSplitter(分离

          本文链接:https://www.haomeiwen.com/subject/lugddhtx.html