0

I want to know , how to create a custom dialog using installanywhere 2012. We are migrating our installer from installshiled to installanywhere. We have used alot of custom dialogs in installshiled. Now I need to change the same in IA 2013. I'm new to IA. Please help me.

Thanks, Thananjeyan

4

1 回答 1

1

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 个文本输入字段的面板。您可以参考上述内容并根据您的要求编写自定义面板

于 2013-12-11T12:26:22.373 回答