简体   繁体   English

如何在installanywhere中创建自定义对话框?

[英]How to create a custom dialog in installanywhere?

I want to know , how to create a custom dialog using installanywhere 2012. We are migrating our installer from installshiled to installanywhere. 我想知道,如何使用installanywhere 2012创建自定义对话框。我们正在将安装程序从installshiled迁移到installanywhere。 We have used alot of custom dialogs in installshiled. 我们在installshiled中使用了许多自定义对话框。 Now I need to change the same in IA 2013. I'm new to IA. 现在,我需要在IA 2013中进行更改。我是IA的新手。 Please help me. 请帮我。

Thanks, Thananjeyan 谢谢,Thananjeyan

All the screens in InstallAnywhere could be designed using Swings and AWT. 可以使用Swings和AWT设计InstallAnywhere中的所有屏幕。 You need to import and extend CustomCodePanel 您需要导入和扩展CustomCodePanel

Sample code is as below: 示例代码如下:

import com.zerog.ia.api.pub.CustomCodePanel;
import com.zerog.ia.api.pub.CustomCodePanelProxy;

import java.awt.*;
import java.util.Map;
import java.util.HashMap;

import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

public class JDBCParamsPanel extends CustomCodePanel{

    private boolean inited = false;
    private Font plainFont;
    private Font boldFont;
    private Map<String, TextField> varName2TextField = new HashMap<String, TextField>();
    String databaseType = "";

    @Override
    public boolean setupUI(CustomCodePanelProxy customCodePanelProxy) {
        if(!inited){
            final String fontName = "Dialog";
            LineBorder border = new LineBorder(Color.GRAY, 1, true);
            final int fontSize = System.getProperty("os.name").contains("Windows") ? 12 : 8;
            plainFont = new Font(fontName, Font.PLAIN, fontSize);
            boldFont = new Font(fontName, Font.BOLD, fontSize);
            setLayout(new BorderLayout(20, 1));
            JTextArea topPrompt = new JTextArea(
                    "Please enter the following parameters that ABC will use\n"
                            + "to connect to the database");
            topPrompt.setRows(7);
            topPrompt.setBorder(border);
            databaseType = (String) customCodePanelProxy.getVariable("$DATABASE_TYPE$");
            System.out.println("databaseType::: "+databaseType);
            topPrompt.setEditable(false);
            topPrompt.setFont(plainFont);
            Panel topPanel = new Panel() {
                public Insets getInsets() {
                    // return new Insets(10, 10, 10, 10);
                    return new Insets(7, 1, 4, 10);
                }
            };
            topPanel.setSize(1, 50);
            topPanel.setLayout(new BorderLayout());
            topPanel.add(topPrompt, BorderLayout.CENTER);
            add(topPanel, BorderLayout.NORTH);
            Panel dataEntryPanel = new Panel();
            add(dataEntryPanel, BorderLayout.CENTER);
            dataEntryPanel.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.anchor = GridBagConstraints.NORTHEAST;
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.insets = new Insets(5, 2, 8, 10);
            gbc.fill = GridBagConstraints.BOTH;
            dataEntryPanel.add(makeEntryPanel(customCodePanelProxy
                    .getValue("PromptUserConsole.Host"), "$DB_HOST$", false, 100), gbc);

            gbc.gridy = 1;
            dataEntryPanel.add(makeEntryPanel(customCodePanelProxy
                    .getValue("PromptUserConsole.Port"), "$DB_PORT$", false, 102), gbc);

            gbc.gridy = 2;
            dataEntryPanel.add(makeEntryPanel(customCodePanelProxy
                    .getValue("PromptUserConsole.Database_Name"), "$DB_NAME$", false, 36), gbc);

            gbc.gridy = 3;
            dataEntryPanel.add(makeEntryPanel(customCodePanelProxy
                    .getValue("PromptUserConsole.User"), "$DB_USER$", false, 99), gbc);

            gbc.gridy = 4;
            dataEntryPanel.add(makeEntryPanel(customCodePanelProxy
                    .getValue("PromptUserConsole.Password"), "$DB_PASSWORD$", true, 68), gbc);


            inited=true;
        }
        return true;
    }

    private Panel makeEntryPanel(String labelText, String varName, boolean useEchoChar, int hgap) {
        Panel panel = new Panel(new BorderLayout(hgap, 1));
        panel.add(makeStarLabel(labelText), BorderLayout.WEST);
        TextField tf = new TextField();
        tf.setFont(plainFont);
        tf.setCaretPosition(Integer.MAX_VALUE);
        if (useEchoChar) {
            tf.setEchoChar('*');
        }
        panel.add(tf, BorderLayout.CENTER);
        varName2TextField.put(varName, tf);
        return panel;
    }

    private Label makeLabel(String text) {
        Label label = new Label(text, Label.RIGHT);
        label.setFont(boldFont);
        return label;
    }

    private JLabel makeStarLabel(String text) {
        JLabel label = new JLabel(text, Label.RIGHT);
        label.setText("<html>" + text + "<font color=FF0000>*</font> </html>");
        label.setFont(boldFont);
        return label;
    }

    public String getTitle() {

        return "JDBC Parameters";
    }

    @Override
    public void panelIsDisplayed() {
        populate("$DB_HOST$");
        populate("$DB_PORT$");
        populate("$DB_NAME$");
        populate("$DB_USER$");
        populate("$DB_PASSWORD$");

    }

    private void populate(String varName) {
        TextField tf = varName2TextField.get(varName);
        String value = (String) customCodePanelProxy.getVariable(varName);
        tf.setText(value);
    }

    @Override
    public boolean okToContinue() {
        for (Map.Entry<String, TextField> entry : varName2TextField.entrySet()) {
            String varName = entry.getKey();
            TextField tf = entry.getValue();
            String value = tf.getText().trim();
            customCodePanelProxy.setVariable(varName, value);
        }
        return true;
    }

}

The above code constructs a panel with 5 text input fields. 上面的代码构建了一个包含5个文本输入字段的面板。 You can refer the above and write custom panels as per your requirement 您可以参考上述内容并根据需要编写自定义面板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM