package wizard; import install.Main; import java.awt.BorderLayout; import java.awt.Rectangle; import java.awt.Dimension; import java.awt.Insets; import java.awt.event.ActionEvent; import java.io.File; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.AbstractAction; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; /** * The install or update options panel for GetBIRCH. * * On this panel, the user can choose whether they wish to update an existing * BIRCH installation, or install a fresh version of BIRCH. * * This is the first step in the installation process for BIRCH. ** * @author Graham Alvare * @author Dale Hamel * @author Brian Fristensky */ public class StartPanel extends WizardPanel { /** * The parent GetBIRCH wizard window to link the panel to */ private BIRCHWizard wizard; /** * This radio button is used in conjunction with 'updateButton' * for determining whether to perform an update * or fresh installation of BIRCH. * * If newInstallButton is selected, * a fresh installation of BIRCH will be performed * If updateButton is selected, * an existing BIRCH installation will be updated */ private JRadioButton newInstallButton = new JRadioButton(new AbstractAction("Create a new installation") { /** * Disables or enables options on the install or update selection panel * based on whether we are performing an install or update. This is * important because it prevents the user from changing properties * which are currently irrelevant, such as selecting an existing BIRCH * installation, when a fresh install is being performed. ** * @param evt the radio button click action event object */ public void actionPerformed(ActionEvent evt) { updateDirectoryText.setEnabled(false); updateDirectoryButton.setEnabled(false); backupBirch.setEnabled(false); wizard.setFinish(false); } }); /** * This radio button is used in conjunction with 'newInstallButton' * for determining whether to perform an update * or fresh installation of BIRCH. * * If newInstallButton is selected, * a fresh installation of BIRCH will be performed * If updateButton is selected, * an existing BIRCH installation will be updated */ private JRadioButton updateButton = new JRadioButton(new AbstractAction("Update an existing installation") { /** * Disables or enables options on the install or update selection panel * based on whether we are performing an install or update. This is * important because it prevents the user from changing properties * which are currently irrelevant, such as selecting an existing BIRCH * installation, when a fresh install is being performed. ** * @param evt the radio button click action event object */ public void actionPerformed(ActionEvent e) { File path = null; JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(null); path = fc.getSelectedFile(); if (path != null) { updateDirectoryText.setText(path.getPath()); updateDirectoryText.setEnabled(true); updateDirectoryButton.setEnabled(true); backupBirch.setEnabled(true); wizard.setFinish(true); } else { newInstallButton.setSelected(true); wizard.setFinish(false); } } }); /** * The path of an existing BIRCH installation to update. * This option is only valid if we are updating an existing * BIRCH installation. */ private JTextField updateDirectoryText = new JTextField(System.getProperty("user.home")); /** * Whether to back up the existing BIRCH installation before updating it. * This option is only valid if we are updating an existing * BIRCH installation. */ private JCheckBox backupBirch = new JCheckBox("Create a backup of existing install"); /** * The BIRCH administrator's email address for the new installation. * This option is only valid if we are installing a fresh copy of BIRCH. */ private JTextField adminEmailText = new JTextField("Enter BIRCH Administrator's email"); /** * The serialization UID for the install or update selection panel. */ private static final long serialVersionUID = 1L; /** * The "Browse" button for selecting the an existing BIRCH installation * directory to update. * This option is only valid if we are updating an existing * BIRCH installation. */ private JButton updateDirectoryButton = new JButton(new AbstractAction("Browse") { /** * Performs the "Browse" action for the existing BIRCH installation * path selection. ** * @param evt the button click action event object */ public void actionPerformed(ActionEvent evt) { File path = null; JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(null); path = fc.getSelectedFile(); if (path != null) { updateDirectoryText.setText(path.getPath()); wizard.setFinish(true); } } }); /** * Create a new install or update panel ** * @param wizard the installation wizard object to attach the panel to */ public StartPanel(BIRCHWizard wizard) { this.wizard = wizard; JLabel welcomeLabel = new JLabel("Welcome to the GetBIRCH BIRCH installer."); JLabel createInstallLabel = new JLabel("Create a new installation:"); JLabel updateLabel = new JLabel("Update an existing installation:"); JLabel iconLabel = new JLabel(new ImageIcon((URL) StartPanel.class.getResource("dna.jpg"))); JLabel emailLabel = new JLabel("Email:"); JPanel contentPanel = new JPanel(); // @jve:decl-index=0:visual-constraint="8,39" ButtonGroup bgroup = null; JTextArea jTextArea = new JTextArea("This will allow you to set up a new BIRCH installation, \neither from network or from an install disc."); JTextArea jTextArea1 = new JTextArea("Update to the newest release.\nNote: A backup is strongly recommended if you have custom changes."); // SET THE BOUNDS OF THE PANEL'S COMPONENTS emailLabel.setBounds(new Rectangle(16, 144, 75, 26)); updateLabel.setBounds(new Rectangle(4, 185, 473, 26)); createInstallLabel.setBounds(new Rectangle(4, 45, 472, 30)); welcomeLabel.setBounds(new Rectangle(4, 15, 476, 27)); newInstallButton.setBounds(new Rectangle(4, 85, 370, 17)); updateButton.setBounds(new Rectangle(4, 220, 368, 17)); updateDirectoryText.setBounds(new Rectangle(30, 310, 350, 20)); updateDirectoryButton.setBounds(new Rectangle(387, 310, 98, 23)); jTextArea.setBounds(new Rectangle(19, 105, 473, 36)); jTextArea1.setBounds(new Rectangle(17, 238, 473, 34)); backupBirch.setBounds(new Rectangle(30, 276, 338, 21)); adminEmailText.setBounds(new Rectangle(103, 145, 273, 24)); // DISABLE EDITING THE UPDATE DIRECTORY DISPLAY BOX updateDirectoryText.setEnabled(false); updateDirectoryText.setEditable(false); // DISABLE RELEVANT UPDATE FEATURES // UNLESS BIRCH UPDATE IS SELECTED updateDirectoryButton.setEnabled(false); backupBirch.setSelected(true); backupBirch.setEnabled(updateButton.isSelected()); // DISALLOW EDITING INSTRUCTORY TEXTBOXES jTextArea.setEditable(false); jTextArea1.setEditable(false); contentPanel.setLayout(null); contentPanel.setSize(new Dimension(512, 344)); contentPanel.add(newInstallButton, null); contentPanel.add(updateButton, null); contentPanel.add(updateDirectoryText, null); contentPanel.add(updateDirectoryButton, null); contentPanel.add(welcomeLabel, null); contentPanel.add(createInstallLabel, null); contentPanel.add(jTextArea, null); contentPanel.add(updateLabel, null); contentPanel.add(jTextArea1, null); contentPanel.add(backupBirch, null); contentPanel.add(adminEmailText, null); contentPanel.add(emailLabel, null); bgroup = new ButtonGroup(); bgroup.add(newInstallButton); bgroup.add(updateButton); contentPanel.setVisible(true); contentPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10))); setLayout(new java.awt.BorderLayout()); iconLabel.setBorder(new EtchedBorder(EtchedBorder.RAISED)); add(iconLabel, BorderLayout.WEST); add(contentPanel, BorderLayout.CENTER); updateDirectoryText.setEnabled(updateButton.isSelected()); updateDirectoryButton.setEnabled(updateButton.isSelected()); // DISABLE UPDATING ON WINDOWS if (Main.IS_WINDOWS) { updateButton.setEnabled(false); } // configure the action listeners to control whether the finish or next // button is displayed in the installation wizard newInstallButton.setSelected(true); updateDirectoryButton.addActionListener(wizard.changeNextToFinishAction); } /** * Returns whether the user wants GetBIRCH to perform a backup before * updating an existing BIRCH installation. * * This parameter is ONLY relevant if GetBIRCH is updating an existing BIRCH * installation. ** * @return true, if the user wants GetBIRCH to perform the backup */ public boolean makeBackup() { return backupBirch.isSelected(); } /** * Returns whether the user wants to install a fresh copy of BIRCH or update * an existing BIRCH installation. ** * @return true, if the user wants to install a fresh copy of BIRCH */ public boolean isInstall() { return newInstallButton.isSelected(); } /** * Returns the path of the existing BIRCH installation to update. * * This parameter is ONLY relevant if GetBIRCH is updating an existing BIRCH * installation. ** * @return the path of the existing BIRCH installation to update */ public String getUpdateDir() { String dir = null; if (updateButton.isSelected()) { dir = updateDirectoryText.getText(); } return dir; } /** * Returns the administrator's email address for a fresh BIRCH installation * * This parameter is ONLY relevant if GetBIRCH * is installing a fresh copy of BIRCH ** * @return the new BIRCH installation administrator's email address */ public String getEmail() { return adminEmailText.getText(); } /** * Validates the BIRCH administrator's email address. ** * @return true, if the BIRCH administrator's email address is a valid email address */ public boolean validateEmail() { //Input the string for validation String email = getEmail(); //Set the email pattern string Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); //Match the given string with the pattern Matcher m = p.matcher(email); //check whether match is found boolean matchFound = m.matches(); return matchFound; } /** * 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 */ public boolean isFinished() { return !newInstallButton.isSelected(); } }