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

时间:2013-10-15 06:28:46

标签: installation installanywhere

我想知道如何使用installanywhere 2012创建自定义对话框。我们正在将安装程序从installshiled迁移到installanywhere。我们在installshiled中使用了很多自定义对话框。现在我需要在IA 2013中改变它。我是IA的新手。 请帮我。

谢谢, Thananjeyan

1 个答案:

答案 0 :(得分:0)

InstallAnywhere的所有屏幕都可以使用Swings和AWT进行设计。您需要导入和扩展CustomCodePanel

示例代码如下:

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;
    }

}

上面的代码构造了一个包含5个文本输入字段的面板。 您可以参考上面的内容并根据您的要求编写自定义面板