Hi,
Install-anywhere panel: custom code working fine with Window and Linux UI but unfortunately, installing on Mac OS, the content of custom code panel not visible.
I am using installanywhere version 2017.
Please see the attached code:
package com.installer.panels;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import org.apache.commons.io.IOUtils;
import com.installer.utils.InstallerUtils;
import com.zerog.ia.api.pub.CustomCodePanel;
import com.zerog.ia.api.pub.CustomCodePanelProxy;
import com.zerog.ia.api.pub.CustomError;
public class InstallSetSelectionPanel extends CustomCodePanel {
private JToggleButton customButton;
JToggleButton expressButton;
private JLabel customFrstLabel, customScndLabel, expressFrstLabel,
expressScndLabel;
private JPanel upperPanel, lowerPanel;
private String chosenInstallSet;
private Color backgroundColor;
private boolean isSetup = false;
private Icon expressIcon, customIcon;
public static void main(String args[]) {
JFrame frame = new JFrame("");
frame.setSize(500, 500);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
InstallSetSelectionPanel obj = new InstallSetSelectionPanel();
obj.upperPanel = new JPanel();
obj.lowerPanel = new JPanel();
obj.initializeGUI();
frame.add(obj.upperPanel, BorderLayout.NORTH);
frame.add(obj.lowerPanel, BorderLayout.CENTER);
// frame.add(BorderLayout.CENTER, lowerPanel);
frame.setVisible(true);
}
private void initializeGUI() {
InputStream in = null;
try {
upperPanel = new JPanel();
upperPanel.setLayout(new GridBagLayout());
in = InstallSetSelectionPanel.class
.getResourceAsStream("/expressIcon.png");
expressIcon = new ImageIcon(IOUtils.toByteArray(in));
GridBagConstraints gBC = new GridBagConstraints();
gBC.fill = GridBagConstraints.HORIZONTAL;
ButtonGroup buttonGroup = new ButtonGroup();
expressButton = new JToggleButton("");
expressButton.setActionCommand("Express");
gBC.gridx = 0;
gBC.gridy = 0;
expressButton.setIcon(expressIcon);
expressButton.setPreferredSize(new Dimension(40, 40));
expressButton.setBorderPainted(true);
buttonGroup.add(expressButton);
expressButton.setSelected(true);
InstallSetSelectionListener listener = new InstallSetSelectionListener();
expressButton.addActionListener(listener);
upperPanel.add(expressButton, gBC);
expressFrstLabel = new JLabel(
" Express (Recommended only to evaluate the product)");
expressFrstLabel.setFont(new Font("", Font.BOLD, 13));
gBC.gridx = 2;
gBC.gridy = 0;
gBC.insets = new Insets(0, 0, 0, 32);
upperPanel.add(expressFrstLabel, gBC);
expressScndLabel = new JLabel(
"<html><font size =3 face=\"Dialog\">  Uses default configuration for installation</font><br><font size =3 face=\"Dialog\">  "
+ "<b>•</b> Uses embedded database for Log</font><br><font size =3 face=\"Dialog\">  <b>•</b> "
+ "Uses Host: localhost,HTTP port: 8080, HTTPS port: 8443</font></html>");
gBC.gridx = 2;
gBC.gridy = 1;
upperPanel.add(expressScndLabel, gBC);
lowerPanel = new JPanel();
lowerPanel.setLayout(new GridBagLayout());
GridBagConstraints gBCLower = new GridBagConstraints();
gBCLower.fill = GridBagConstraints.HORIZONTAL;
in = InstallSetSelectionPanel.class
.getResourceAsStream("/customIcon.png");
customIcon = new ImageIcon(IOUtils.toByteArray(in));
customButton = new JToggleButton("");
customButton.setActionCommand("Custom");
gBCLower.gridx = 0;
gBCLower.gridy = 0;
customButton.setIcon(customIcon);
customButton.setPreferredSize(new Dimension(40, 40));
customButton.setBorderPainted(true);
buttonGroup.add(customButton);
customButton.addActionListener(listener);
gBCLower.insets = new Insets(0, 15, 0, 0);
lowerPanel.add(customButton, gBCLower);
customFrstLabel = new JLabel(
" Custom (Recommended for Development, QA and Production)");
customFrstLabel.setFont(new Font("", Font.BOLD, 13));
gBCLower.gridx = 2;
gBCLower.gridy = 0;
gBCLower.insets = new Insets(0, 0, 0, 0);
lowerPanel.add(customFrstLabel, gBCLower);
customScndLabel = new JLabel(
"<html><font size =3 face=\"Dialog\">  Allows user defined configuration for "
+ "installation</font><br><font size =3 face=\"Dialog\">  <b>•</b> Configuration for Log "
+ "Database</font><br><font size =3 face=\"Dialog\">  <b>•</b> Configuration of host and port "
+ "for web interface</font><br><font size =3 face=\"Dialog\">  <b>•</b> Configuration to install"
+ " as Windows Service</font></html>");
gBCLower.gridx = 2;
gBCLower.gridy = 1;
lowerPanel.add(customScndLabel, gBCLower);
//set color of label according to the selection of install set
if (chosenInstallSet == null) {
expressFrstLabel.setForeground(Color.BLUE);
} else {
if (chosenInstallSet.equals("Express")) {
expressFrstLabel.setForeground(Color.BLUE);
} else {
customFrstLabel.setForeground(Color.BLUE);
}
}
backgroundColor = InstallerUtils.getCurrentUISpecificColor();
final JScrollPane expressScrollpane = new JScrollPane(upperPanel);
expressScrollpane.setBorder(BorderFactory.createEmptyBorder());
add(expressScrollpane, BorderLayout.NORTH);
final JScrollPane customScrollpane = new JScrollPane(lowerPanel);
customScrollpane.setBorder(BorderFactory.createEmptyBorder());
add(customScrollpane, BorderLayout.CENTER);
if (System.getProperty("os.name").startsWith("Windows")) {
upperPanel.setBackground(Color.WHITE);
lowerPanel.setBackground(Color.WHITE);
} else {
upperPanel.setBackground(backgroundColor);
lowerPanel.setBackground(backgroundColor);
}
} catch (Exception e) {
}
}
@Override
public boolean setupUI(CustomCodePanelProxy arg0) {
try {
if (isSetup) {
removeAll();
}
initializeGUI();
isSetup = true;
} catch (Exception e) {
CustomError error = (CustomError) customCodePanelProxy
.getService(CustomError.class);
error.appendError(InstallerUtils.getNotNullErrorMessage(e),
CustomError.ERROR);
error.log();
return false;
}
return true;
}
public boolean okToContinue() {
//set the value of variable to the chosen install set
customCodePanelProxy.setVariable("$CHOSEN_INSTALL_SET$",
chosenInstallSet);
return true;
}
public void panelIsDisplayed() {
}
public String getTitle() {
return "Choose Install Set";
}
private class InstallSetSelectionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (actionCommand.equalsIgnoreCase("Express")) {
//change the color of selected button text to blue
expressFrstLabel.setForeground(Color.BLUE);
customFrstLabel.setForeground(Color.BLACK);
expressButton.setPressedIcon(expressIcon);
} else if (actionCommand.equalsIgnoreCase("Custom")) {
customFrstLabel.setForeground(Color.BLUE);
expressFrstLabel.setForeground(Color.BLACK);
customButton.setPressedIcon(customIcon);
}
// repaint();
//set install set
chosenInstallSet = actionCommand;
}
}
}
Any guess of it.
Thanks,
Prashant Rathi