package wizard;
import install.BIRCHIO;
import install.Main;
import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.io.File;
import java.net.URL;
import java.util.EnumSet;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
/**
* The advanced install options panel for GetBIRCH.
* GetBIRCH supports the following advanced options:
*
* 1. Installation path
* 2. Whether to install a developmental or stable release of BIRCH
* 3. Whether to install MiniBIRCH or regular/full BIRCH
* 4. Which platform binaries to install with BIRCH
* 5. Where to write the GetBIRCH log file.
*
* This advanced options panel will only be displayed if the user
* chooses to perform an advanced installation of BIRCH.
**
* @author Graham Alvare
* @author Dale Hamel
* @author Brian Fristensky
*/
public class AdvancedPanel extends WizardPanel {
/**
* The parent GetBIRCH wizard window to link the panel to
*/
private BIRCHWizard wizard;
/**
* A label to describe the install directory entry field.
* This is made a class variable, so it can be hidden in
* the case of a BIRCH update.
*/
private JLabel installdirLabel = new JLabel("Install directory:");
/**
* Specifies the subdirectory to create for installing BIRCH.
*
* The full path of BIRCH is determined by:
* installDirTextArea + File.separator + pathSuffix
*/
private JTextField pathSuffix = new JTextField("BIRCH");
/**
* A label to display the path separator between the installDirTextArea
* field and the pathSuffix field. This is made a class variable, so it
* can be hidden in the case of a BIRCH update
*/
private JLabel suffixLabel = new JLabel(File.separator);
/**
* Specifies the destination directory to install BIRCH.
*
* The full path of BIRCH is determined by:
* installDirTextArea + File.separator + pathSuffix
*/
private JTextField installDirTextArea = new JTextField(BIRCHIO.DEFAULT_HOME.getAbsolutePath());
/**
* Specifies the destination directory to write the GetBIRCH log.
*
* The full path of the log file is determined by:
* installLogText + File.separator + "getbirch.log"
*/
private JTextField installLogText = new JTextField(BIRCHIO.DEFAULT_HOME.getAbsolutePath());
/**
* A checkbox for determining whether to download full BIRCH or MiniBIRCH.
* If this checkbox is selected, GetBIRCH should download the MiniBIRCH
* framework.
*/
private JCheckBox miniBirchCheckBox = new JCheckBox("miniBirch");
/**
* This radio button is used in conjunction with 'releaseRadioButton'
* for determining whether to download the current stable BIRCH release,
* or the development version of BIRCH.
*
* If releasedRadioButton is selected,
* download the current stable BIRCH release
* If developmentRadioButton is selected,
* download the current development version of BIRCH
*/
private JRadioButton developmentRadioButton = new JRadioButton("Development Version");
/**
* This checkbox is used to determine whether the old binaries of a current
* BIRCH installation should be replaced with new binaries, when updating
* an old BIRCH installation.
*/
private JCheckBox updateBinaries = new JCheckBox("", true);
/**
* This label is used for the updateBinaries checkbox.
* If update binaries is selected, when a BIRCH installation is updated,
* the old binaries will be replaced with new ones.
*/
private JLabel updateBinLabel = new JLabel("Update binaries:");
/**
* This radio button is used in conjunction with 'developmentRadioButton'
* for determining whether to download the current stable BIRCH release,
* or the development version of BIRCH.
*
* If releasedRadioButton is selected,
* download the current stable BIRCH release
* If developmentRadioButton is selected,
* download the current development version of BIRCH
*/
private JRadioButton releaseRadioButton = new JRadioButton("Current ");
/**
* The checkbox to decide whether to download
* 64-bit Intel Linux BIRCH binaries.
*/
private JCheckBox linux64CheckBox = new JCheckBox("bin-linux-x86_64");
/**
* The checkbox to decide whether to download
* 64-bit Intel Mac OS X BIRCH binaries.
*/
private JCheckBox osxCheckBox = new JCheckBox("bin-osx-x86_64");
/**
* NOT YET SUPPORTED
* The checkbox to decide whether to download
* 64-bit Arm Mac OS X BIRCH binaries.
*/
private JCheckBox MacosArm64CheckBox = new JCheckBox("bin-macos-arm64");
/**
* The serialization UID for the advanced installation options panel.
*/
private static final long serialVersionUID = 1L;
/**
* The "Browse" button for selecting the installation directory.
* This button can be used to search for a different directory
* to install BIRCH.
*/
private JButton browseButton = new JButton(new AbstractAction("Browse") {
/**
* Used to prevent double clicking
*/
private long lastcalled = -1;
/**
* Performs the "Browse" action for the installation path selection.
**
* @param evt the button click action event object
*/
public void actionPerformed(ActionEvent evt) {
if (evt.getWhen() != lastcalled) {
JFileChooser fc = new JFileChooser(installDirTextArea.getText());
lastcalled = evt.getWhen();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(null);
String path = fc.getSelectedFile().getPath();
// update the current installation directory to
// that selected in the file chooser
installDirTextArea.setText(path);
}
}
});
/**
* The "Browse" button for selecting the GetBIRCH log directory.
* This button can be used to search for a different directory
* to write the GetBIRCH log file to.
*/
private JButton logBrowseButton = new JButton(new AbstractAction("Browse") {
/**
* Performs the "Browse" action for the log directory selection.
**
* @param evt the button click action event object
*/
public void actionPerformed(ActionEvent evt) {
JFileChooser fc = new JFileChooser(installLogText.getText());
// display a file chooser
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(null);
String path = fc.getSelectedFile().getPath();
// update the current log directory to
// that selected in the file chooser
installLogText.setText(path);
}
});
/**
* Used to limit GetBIRCH from installing a non-development version.
*/
private boolean develOnly = false;
/**
* This checkbox is used to determine whether to call Install.SendStatsToBirch
* at the end of a successful install or update. This will call a CGI script
* that records basic install information.
*/
private JCheckBox SendStatsCheckBox = new JCheckBox("", true);
/**
* This label is used for the SendStats checkbox.
* If update binaries is selected, when a BIRCH installation is updated,
* the old binaries will be replaced with new ones.
*/
private JLabel SendStatsLabel = new JLabel("Send install stats to BIRCH Home:");
/**
* Create a new BIRCH advanced install options installation panel.
**
* @param wizard the installation wizard object to attach the panel to
*/
public AdvancedPanel(BIRCHWizard wizard) {
// copy the parameters to class variables
this.wizard = wizard;
// create the main display panel
JPanel contentPanel = new JPanel(); // @jve:decl-index=0:visual-constraint="-35,34"
// create all of the labels for the main panel
JLabel logdirLabel = new JLabel("Install/update log directory:");
JLabel advinstLabel = new JLabel("Advanced Install/update.");
JLabel frameworkTypeLbl = new JLabel("Framework Type:");
JLabel autodetectLabel = new JLabel("* - Automatically detected, recommended.");
JLabel iconLabel = new JLabel(new ImageIcon((URL) AdvancedPanel.class.getResource("dna.jpg")));
//JLabel iconLabel = new JLabel(new ImageIcon((URL) AdvancedPanel.class.getResource("birch_black.jpg")));
JLabel binariesLabel = new JLabel("Binaries:");
// SET THE BOUNDARIES FOR EACH WIDGET (ordered from top to bottom)
advinstLabel.setBounds ( 11, 2, 394, 26 );
installdirLabel.setBounds ( 11, 28, 131, 17 );
suffixLabel.setBounds ( 220, 48, 10, 21 );
pathSuffix.setBounds ( 233, 48, 61, 21 );
browseButton.setBounds ( 312, 45, 98, 23 );
installDirTextArea.setBounds ( 13, 49, 206, 21 );
logdirLabel.setBounds ( 11, 72, 218, 19 );
installLogText.setBounds ( 12, 91, 290, 20 );
logBrowseButton.setBounds ( 310, 90, 98, 23 );
frameworkTypeLbl.setBounds ( 11, 115, 127, 21 );
miniBirchCheckBox.setBounds ( 268, 137, 149, 19 );
releaseRadioButton.setBounds ( 13, 140, 214, 16 );
developmentRadioButton.setBounds ( 13, 160, 231, 23 );
binariesLabel.setBounds ( 18, 190, 132, 18 );
//linux64CheckBox.setBounds ( 211, 235, 193, 22 );
linux64CheckBox.setBounds ( 211, 210, 190, 22 );
//osxCheckBox.setBounds ( 18, 260, 180, 22 );
osxCheckBox.setBounds ( 18, 210, 188, 22 );
// To be supported in a future release
MacosArm64CheckBox.setBounds ( 18, 235, 183, 22 );
autodetectLabel.setBounds ( 22, 286, 312, 20 );
updateBinLabel.setBounds ( 11, 320, 200, 20 );
updateBinaries.setBounds ( 201, 320, 250, 20 );
SendStatsLabel.setBounds ( 11, 345, 365, 20 );
String SendStatsToolTip = "" + "Sends install information to the BIRCH Home site.
"
+ "Only the following data is sent:
" + "Date and Time, Version, Platform, New install or Update.
" +
"These data are important for future funding applications." + "";
// GADZOOKS! It appears that setToolTipText inactivates checkboxes, so that
// you can't change them, and they don't change appearance on mouseover.
// This sounds like a bug in Java. We are currently compiling for Java 1.5. This
// should be revisited when we recompile for target 1.6.
//SendStatsLabel.setToolTipText(SendStatsToolTip);
SendStatsCheckBox.setBounds ( 280, 345, 250, 22 );
//SendStatsCheckBox.setToolTipText(SendStatsToolTip);
SendStatsCheckBox.setEnabled(true);
// set the default install selection
releaseRadioButton.setSelected(true);
// DISABLE EDITING IN TEXT FIELDS
installLogText.setEditable(false);
installDirTextArea.setEditable(false);
// Hide the update binaries option until the user has selected to update BIRCH
updateBinLabel.setVisible(false);
updateBinaries.setVisible(false);
// ADD THE COMPONENTS TO THE MAIN CONTENT PANEL
contentPanel.setLayout(null);
//contentPanel.setSize(464, 376);
contentPanel.setSize(464, 396);
contentPanel.add(installdirLabel, null);
contentPanel.add(browseButton, null);
contentPanel.add(installDirTextArea, null);
contentPanel.add(suffixLabel, null);
contentPanel.add(pathSuffix, null);
contentPanel.add(frameworkTypeLbl, null);
contentPanel.add(miniBirchCheckBox, null);
contentPanel.add(developmentRadioButton, null);
contentPanel.add(binariesLabel, null);
contentPanel.add(linux64CheckBox, null);
contentPanel.add(osxCheckBox, null);
contentPanel.add(MacosArm64CheckBox, null);
contentPanel.add(installLogText, null);
contentPanel.add(logBrowseButton, null);
contentPanel.add(autodetectLabel, null);
contentPanel.add(releaseRadioButton, null);
contentPanel.add(advinstLabel, null);
contentPanel.add(logdirLabel, null);
contentPanel.add(updateBinLabel, null);
contentPanel.add(updateBinaries, null);
contentPanel.add(SendStatsLabel, null);
contentPanel.add(SendStatsCheckBox, null);
// FORM A RADIO BUTTON GROUP FOR SELECTING WHETHER TO INSTALL
// A STABLE RELEASE, DEVELOPMENT RELEASE, OR INSTALL FROM GIT
ButtonGroup group = new ButtonGroup();
group.add(releaseRadioButton);
group.add(developmentRadioButton);
// CONFIGURE THE ICON LABEL AND THE MAIN CONTENT PAIN FOR DISPLAYING
iconLabel.setBorder(new EtchedBorder(EtchedBorder.RAISED));
contentPanel.setVisible(true);
contentPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));
setLayout(new java.awt.BorderLayout());
add(iconLabel, BorderLayout.WEST);
add(contentPanel, BorderLayout.CENTER);
// ADJUST THE CHECK BOXES BASED ON THE PLATFORM SELECTED
switch (Main.PLATFORM) {
case LINUX_64:
linux64CheckBox.setSelected(true);
linux64CheckBox.setText(linux64CheckBox.getText() + "*");
break;
case OSX_64:
osxCheckBox.setSelected(true);
osxCheckBox.setText(osxCheckBox.getText() + "*");
break;
case MACOS_ARM64:
MacosArm64CheckBox.setSelected(true);
MacosArm64CheckBox.setText(MacosArm64CheckBox.getText() + "*");
break;
}
// ADJUST THE CONFIGURATION BASED ON THE BIRCH VERSION SELECTED
releaseRadioButton.setText(releaseRadioButton.getText() + " Version: " + Main.VERSION);
// DISABLE MINIBIRCH AND DEVELOPMENT VERSION INSTALL, IF WE ARE
// INSTALLING OFF OF A COMPACT DISC (OR THE LIKE)
if (Main.DISC_INSTALL) {
miniBirchCheckBox.setEnabled(false);
developmentRadioButton.setEnabled(false);
}
}
/**
* Returns where the user wants to install BIRCH (which directory).
**
* @return the destination directory to install BIRCH
*/
public String getInstallDir() {
String installDir = "ERROR DETECTING INSTALL/UPDATE DIR!";
if (wizard.START_PANEL.isInstall()) {
installDir = installDirTextArea.getText() + File.separator + pathSuffix.getText();
} else {
installDir = wizard.START_PANEL.getUpdateDir();
}
return installDir;
}
/**
* Returns the framework version of BIRCH to install.
**
* @return the framework version of BIRCH to install
*/
public String getFrameworkVersion() {
String version = Main.VERSION;
if (miniBirchCheckBox.isSelected()) {
version += "M";
}
if (developmentRadioButton.isSelected()) {
version += "D";
}
return version;
}
/**
* Returns whether to install the development version of BIRCH
**
* @return true, if the user wants to install the development version of BIRCH
*/
public boolean isDevelopment() {
return develOnly || developmentRadioButton.isSelected();
}
/**
* Returns the directory to write the log file to
**
* @return the directory to write the log to
*/
public String getLogDir() {
return installLogText.getText();
}
/**
* Returns a set object containing all of the platforms/binaries for BIRCH
* to install.
**
* @return the set of all binaries for BIRCH to install.
*/
public Set getBinariesSelected() {
//Set binaries = new HashSet();
Set binaries = EnumSet.noneOf(Main.ArchSys.class);
if (linux64CheckBox.isSelected()) {
binaries.add(Main.PLATFORM.LINUX_64);
}
if (osxCheckBox.isSelected()) {
binaries.add(Main.PLATFORM.OSX_64);
}
/**
* 2023 - As part of the transition from macos from the Intel
* architecture to the arm64 architecture, we need binaries
* for both platforms. bin-macos-arm64.tar.gz contains both
* binaries and libraries for both platforms.
* Once arm64 native binaries exist for
* all programs, we can eliminate the OSX_X64 binaries. This
* will undoubtedly take years.
*/
if (MacosArm64CheckBox.isSelected()) {
binaries.add(Main.PLATFORM.MACOS_ARM64);
}
return binaries;
}
/**
* Returns a string representation of the current
* installation options - this contains:
* 1. the installation directory selected
* 2. the directory to write the log file
* 3. the list of binaries selected for installation
**
* @return a string array containing various install information
*/
public String getInstallInfo() {
return "Install/update directory " + getInstallDir() + "\n"
+ "Log File directory" + getLogDir() + "\n"
+ "Binaries:" + binariesToString() + "\n"
+ "Version: " + getFrameworkVersion();
}
/**
* Converts the list object of binaries selected for installation into
* a comma separated list string.
**
* @return a comma separated list string of binaries selected for installation
*/
private String binariesToString() {
boolean first = true;
Set binaries = getBinariesSelected();
StringBuilder binString = new StringBuilder();
for (Main.ArchSys binary : binaries) {
if (!first) {
binString.append(",");
}
binString.append(binary);
first = false;
}
return binString.toString();
}
/**
* Returns whether the user has selected to install MiniBIRCH
**
* @return true if the user has selected to install MiniBIRCH
*/
public boolean isMiniBIRCH() {
return miniBirchCheckBox.isSelected();
}
/**
* Returns whether the user agrees to send install stats to BIRCH Home
**
* @return true if the user has selected SendStats
*/
public boolean doSendStats() {
return SendStatsCheckBox.isSelected();
}
/**
* Determines whether this step is sufficient to complete the install wizard
* Returns whether or not to display the "Finish" button for this step of
* the installation (as opposed to the "Next" button)
**
* @return whether to complete the install process
*/
@Override
public boolean isFinished() {
return true;
}
/**
* This method checks for errors in the current install wizard panel
**
* @return true if there are no errors in the current panel
*/
@Override
public boolean errorCheck() {
return true;
}
/**
* Adjusts the advanced panel to change the options displayed to
* those necessary for either a BIRCH update or a fresh BIRCH install.
**
* This function is used by StartPanel for communication. For instance,
* if the update option is selected and a BIRCH installation to update
* is specified, the advanced settings panel should NOT show the install
* location textbox used for the install process.
**
* @param install whether to perform a fresh BIRCH installation (true) or BIRCH update (false)
*/
public void setInstall(boolean install) {
installDirTextArea.setVisible(install);
pathSuffix.setVisible(install);
installdirLabel.setVisible(install);
suffixLabel.setVisible(install);
browseButton.setVisible(install);
updateBinLabel.setVisible(!install);
updateBinaries.setVisible(!install);
if (!install && wizard.START_PANEL.getUpdateDir().toLowerCase().contains("birchbindev")) {
updateBinaries.setEnabled(false);
updateBinaries.setSelected(false);
} else {
updateBinaries.setEnabled(true);
}
}
/**
* Whether to keep binaries when performing an update of BIRCH.
**
* @return false if the current binaries are to be deleted and replace with new binaries on an update
*/
public boolean isKeepBinariesUpdate() {
return !updateBinaries.isSelected();
}
public void setDevelopmentOnly(boolean develOnly) {
this.develOnly = develOnly;
if (develOnly) {
developmentRadioButton.setSelected(true);
}
releaseRadioButton.setEnabled(!develOnly);
developmentRadioButton.setEnabled(!develOnly);
}
}