Custom launcher for SuperMap iDesktopX 11i extension development

Author: Yin

1. Background

  SuperMap iDesktopXIt is SuperMap iObjects Javaan enterprise-level, plug-in, cross-platform desktop GIS application and development platform built through the core library and Java SE Development Kit (JDK), which can be extended and developed in Windows or Linux systems based on the Java language.

  SuperMap iDesktopXThe application program is built based on the plug-in mechanism, and each function is realized by loading the plug-in corresponding to the function, and the interface configuration is the plug-in + configuration file. At present, it mainly includes 2 extension development methods: 1. Custom launcher extension; 2. Function plug-in extension.

  When the program starts, the background needs a certain amount of time to operate. During this period, for a better user experience, the program's startup interface can be friendly to improve the user experience. This article mainly introduces how to SuperMap iDesktopXextend development based on custom launcher.

2. Environment preparation

  Based on SuperMap iDesktopXextended development, the required environment dependencies are provided by iDesktopX, so the development environment only needs iDesktopX and IDEA to meet the requirements.

software Version download link illustrate
SuperMap DesktopX 11i and above SuperMap iDesktopX download address SuperMap iDesktopX provides two types of installation package and simplified green package, and you can download the appropriate version package according to the actual project requirements
I understand the idea 2020.3.x and above IntelliJ IDEA download address IntelliJ IDEA is an integrated development environment for the java programming language and is recognized as the best Java development tool in the industry

3. Create a new project

  SuperMap iDesktopXThere are two ways to create the startup program:

3.1. Created by SuperMap iDesktopX extension template

  • SuperMap iDesktopX 11i The New Secondary Development Project function is provided in the View menu bar , which can quickly create a secondary development project directly based on the iDesktopX extended development template.
    New iDesktopX extension development project.png

  • The project structure based on the iDesktopX extended development template is as follows:
    New extension development project structure from iDesktopX 11i.png

  The newly created project based on the iDesktopX extension development template has already configured the environment dependencies required for iDesktopX extension development in the template, so there is no need to additionally configure the environment dependencies for the project and can be used directly.

3.2. IDEA creates a new iDesktopX extension development project

  • IDEA creates a new Java empty project

    • New Project
      IDEA new project.png

    • Configure the Java version
      IDEA new Java project.png

    • Create an empty project without selecting a template
      IDEA New Java Empty Project.png

    • empty project structure
      IDEA New Java Empty Project Structure.png

    • Create a new custom package
      Create a new package.png in the src directory

    • New entry class
      Create a new entry class in the package.png

    • New entry function
      Add the entry function main.png to the entry class

  • Configure iDesktopX extension development environment dependencies

    • Configure iDesktopX extension development dependency library

        SuperMap iDesktopXExtended development requires a total of 4 dependent library configurations, which are:

      • %SuperMap iDesktopX%\bin
      • %SuperMap iDesktopX%\lib
      • %SuperMap iDesktopX%\bundles\desktop_bundles
      • %SuperMap iDesktopX%\bundles\require_bundles

      Configure iDesktopX extension development environment dependencies.png

    • Configurator packaging

        Since it is an iDesktopX startup program extension development, the jar package can be directly output to the root directory of %SuperMap iDesktopX% when packaging, instead of outputting to the iDesktopX plugin directory (%SuperMap iDesktopX%\bundles\plugin_bundles)
      Custom launcher packaging configuration.png

4. Customize the startup interface

  SuperMap iDesktopXThe corresponding interface is provided to facilitate the user to customize the program startup interface to meet the actual project needs, such as the following code, where the CStartupDialog class is a customized startup interface

// 设置自定义启动界面
SplashScreenUtilities splashScreenUtilitiesInstance = SplashScreenUtilities.getSplashScreenUtilitiesInstance();
splashScreenUtilitiesInstance.setStartupDialog(new CStartupDialog());
package com.supermap.startup;

import com.supermap.desktop.core.StartupDialogParameters;
import com.supermap.desktop.core.startup.IStartupDialog;
import com.supermap.desktop.core.utilties.FontUtilities;
import com.supermap.desktop.core.utilties.PathUtilities;
import com.supermap.desktop.core.utilties.ThreadUtilties;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 自定义 iDesktopX 11i 启动面板
 */
public class CStartupDialog extends JDialog implements IStartupDialog {
    
    

    private final JTextArea textArea;
    private boolean isDisposed = false;

    public CStartupDialog() {
    
    
        // 设置启动界面关闭功能
        addWindowListener(new WindowAdapter() {
    
    
            @Override
            public void windowClosed(WindowEvent e) {
    
    
                super.windowClosed(e);
                if (!isDisposed) {
    
    
                    System.exit(0);
                }
            }
        });
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        setTitle("自定义启动界面");
        setBounds(0, 0, 600, 500);

        // 启动界面布局
        setLayout(new GridLayout(1, 2, 0, 0));
        JPanel leftPanel = new JPanel();
        add(leftPanel);
        JPanel rightPanel = new JPanel() {
    
    
            @Override
            protected void paintComponent(Graphics g) {
    
    
                super.paintComponent(g);

                // 绘制启动界面动画背景
                String iconPath = PathUtilities.getFullPathName("../resources/Frame/StartupIcon/Startup_Right100.gif");
                ImageIcon imageIcon = new ImageIcon(iconPath);
                Image image = imageIcon.getImage();
                g.drawImage(image, 0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight(), this);
            }
        };
        add(rightPanel);

        // 设置启动界面图标
        String iconPath = PathUtilities.getFullPathName("../resources/Frame/StartupIcon/Logo_32.png");
        ImageIcon imageIcon = new ImageIcon(iconPath);
        Image iconImage = imageIcon.getImage();
        setIconImage(iconImage);

        // 显示启动界面位置
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        this.setLocation(screenSize.width / 2 - this.getWidth() / 2, screenSize.height / 2 - this.getHeight() / 2);

        // 设置启动界面日志输出文本框
        Font defaultFont = FontUtilities.getDefaultFont();
        textArea = new JTextArea();
        textArea.setForeground(Color.BLACK);
        textArea.setOpaque(false);
        textArea.setEditable(false);
        textArea.setFont(defaultFont);
        textArea.setLineWrap(false);
        textArea.setWrapStyleWord(false);

        if (StartupDialogParameters.isPluginInfoVisible()) {
    
    
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(280, 450));
            leftPanel.add(scrollPane);
        }
    }

    @Override
    public void update(String text) {
    
    
        textArea.append(text + "\n");
        textArea.setCaretPosition(textArea.getText().length());
    }

    @Override
    public void showDialog() {
    
    
        setVisible(true);
        ThreadUtilties.executeAfterDesktopVisible(this::doDispose, 1);
    }

    @Override
    public void dispose() {
    
    
        super.dispose();
    }

    public void doDispose() {
    
    
        isDisposed = true;
        dispose();
    }
}

  The effect of the custom startup interface implemented by the above code is as follows. The implementation of the custom startup interface is only an example, and the user can customize it according to the actual project situation.
iDesktopX custom startup interface.png

5. Customize post-launch actions

  When SuperMap iDesktopXthe interface is loaded, the event bound to ThreadUtilties.executeAfterDesktopVisible will be triggered, and the user can directly implement the specified logic execution in this event, as shown below, when iDesktopX starts, load the specified workspace and open the scene

ThreadUtilties.executeAfterDesktopVisible(() -> {
    
    
    // 打开默认工作空间
    Application activeApplication = Application.getActiveApplication();
    Workspace workspace = activeApplication.getWorkspace();
    WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
    workspaceConnectionInfo.setServer("sampleData/3D/CBDDataset/CBD.smwu");
    workspaceConnectionInfo.setType(WorkspaceType.SMWU);
    workspace.open(workspaceConnectionInfo);

    // 默认打开当前工作空间中的第一个场景
    Scenes scenes = workspace.getScenes();
    String sceneName = scenes.get(0);
    SwingUtilities.invokeLater(() -> {
    
    
        IFormScene sceneForm = (IFormScene) FormUtilities.fireNewWindowEvent(WindowType.SCENE, sceneName);
        sceneForm.openScene(sceneName);
    });
});

Automatically open the specified workspace scene after iDesktopX starts.gif

6. Modify the startup method

  SuperMap iDesktopXProvides 2 startup methods: 1. bat (Windows) / sh (Linux) script startup; 2. exe (Windows) executable program startup. Taking the Windows operating system as an example, the following describes the application of the custom startup program in the two startup methods.

  • Modify iDesktopX startup script

    The startup.bat startup script   is provided in the root directory of iDesktopX . The default configuration in the script is to use the iDesktop.jar in the same directory as the startup entry. Therefore, after the custom startup program CStartup.jar is packaged, you can directly modify the startup.bat startup script content.

      You only need to modify the startup jar package of CLASSPATH and the java command to start the entry class configuration, as shown in the following figure:

    Modify iDesktopX startup script.png

  • Package a custom launcher into an exe executable

      There are many ways to package the jar package into an exe executable file, and the user can choose the appropriate way according to the actual situation of the project. A lightweight packaging tool Launch4j is selected here for introduction.

      The provided Launch4j download address contains the launch4j.zip program compression package and the launch4j.xml configuration template.

    Launch4j download package structure.png

    • Put the launch4j.xml file into the root directory of %SuperMap iDesktopX%

    • Double-click to run the launch4j.exe executable program

    • Import the launch4j.xml file in the root directory of %SuperMap iDesktopX%

    • Modify Output file , Jar runtime path , Icon parameter configuration

      Modify Launch4j parameter configuration.png

    • After Launch4j generates the exe executable file, it can be executed by double-clicking in the root directory of iDesktopX

      exe executable file generated by Launch4j.png

7. Summary

  This article introduces in detail how to SuperMap iDesktopXdevelop a custom launcher based on the extension, the complete process from new extension development to final packaging and use, which can be used as a reference for users to get started with iDesktopX extension development custom launcher.

  In addition, this tutorial also provides a custom startup program CStartup developed based on the above tutorial for SuperMap iDesktopX 11i extension development . You can also directly download the sample code to compile and package it with IDEA and Launch4j , and then debug and run it.

Guess you like

Origin blog.csdn.net/supermapsupport/article/details/131593343