Package GUI

Source Code of GUI.SaveAndFinishDlg

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* SelectProject.java
*
* Created on Sep 7, 2009, 9:29:29 AM
*/
package GUI;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author M Shakeer Anver
*/
public class SaveAndFinishDlg extends javax.swing.JDialog {

   
    JDialog previousDialog;
    String filePath;
    mainForm mainForm;

    /**
     * Gets the main program window
     * @return main program window
     */
    public JFrame getMainForm() {
        return mainForm;
    }

    /**
     * Sets the main program window
     * @param mainForm Main program window
     */
    public void setMainForm(mainForm mainForm) {
        this.mainForm = mainForm;
    }

    /**
     * Returns the selected file's path
     * @return Selected file's path
     */
    public String getFilePath() {
        return filePath;
    }

    /**
     * Sets the path of the file to be used
     * @param filePath Pathe of the file to be used
     */
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    /**
     * Gets the previously shown dialog
     * @return Previously shown dialog
     */
    public JDialog getPreviousDialog() {
        return previousDialog;
    }

    /**
     * Sets the previously shown dialog
     * @param previousDialog Previously shown dialog
     */
    public void setPreviousDialog(JDialog previousDialog) {
        this.previousDialog = previousDialog;
    }



    /** Creates new form SelectProject
     * @param parent Parent window
     * @param modal Determines the modalirty of the window
     */
    public SaveAndFinishDlg(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
       
        filePath = "null";
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        stepsPnl = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        saveAndFinishPnl = new javax.swing.JPanel();
        whereToSaveLbl = new javax.swing.JLabel();
        whereToSaveTxtFld = new javax.swing.JTextField();
        whereToSaveBrowseBtn = new javax.swing.JButton();
        helpBtn = new javax.swing.JButton();
        finishBtn = new javax.swing.JButton();
        backBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("WinSIS START UP WIZARD - Save and Finish");
        setModal(true);
        setResizable(false);

        stepsPnl.setBackground(new java.awt.Color(255, 255, 255));
        stepsPnl.setPreferredSize(new java.awt.Dimension(150, 250));

        jTextField1.setEditable(false);
        jTextField1.setFont(new java.awt.Font("Verdana", 1, 11));
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField1.setText("Steps");
        jTextField1.setBorder(null);

        jTextField4.setFont(new java.awt.Font("Verdana", 0, 11));
        jTextField4.setText("1 - Select Project");
        jTextField4.setBorder(null);
        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        jTextField5.setFont(new java.awt.Font("Verdana", 1, 11));
        jTextField5.setText("2 - Save and Finish");
        jTextField5.setBorder(null);
        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout stepsPnlLayout = new javax.swing.GroupLayout(stepsPnl);
        stepsPnl.setLayout(stepsPnlLayout);
        stepsPnlLayout.setHorizontalGroup(
            stepsPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(stepsPnlLayout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(61, Short.MAX_VALUE))
            .addGroup(stepsPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
            .addGroup(stepsPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(50, Short.MAX_VALUE))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
        );
        stepsPnlLayout.setVerticalGroup(
            stepsPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(stepsPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(145, Short.MAX_VALUE))
        );

        saveAndFinishPnl.setPreferredSize(new java.awt.Dimension(320, 250));

        whereToSaveLbl.setFont(new java.awt.Font("Verdana", 0, 11));
        whereToSaveLbl.setText("Where do you want to save your new project?");

        whereToSaveBrowseBtn.setText("...");
        whereToSaveBrowseBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                whereToSaveBrowseBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout saveAndFinishPnlLayout = new javax.swing.GroupLayout(saveAndFinishPnl);
        saveAndFinishPnl.setLayout(saveAndFinishPnlLayout);
        saveAndFinishPnlLayout.setHorizontalGroup(
            saveAndFinishPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(saveAndFinishPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(saveAndFinishPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(whereToSaveLbl)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, saveAndFinishPnlLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(whereToSaveTxtFld, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(whereToSaveBrowseBtn)))
                .addContainerGap())
        );
        saveAndFinishPnlLayout.setVerticalGroup(
            saveAndFinishPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(saveAndFinishPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(whereToSaveLbl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(saveAndFinishPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(whereToSaveTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(whereToSaveBrowseBtn))
                .addContainerGap(190, Short.MAX_VALUE))
        );

        helpBtn.setText("Help");
        helpBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpBtnActionPerformed(evt);
            }
        });

        finishBtn.setText("Finish");
        finishBtn.setEnabled(false);
        finishBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finishBtnActionPerformed(evt);
            }
        });

        backBtn.setText("<< Back");
        backBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backBtnActionPerformed(evt);
            }
        });

        cancelBtn.setText("Cancel");
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(helpBtn)
                    .addComponent(stepsPnl, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(backBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(finishBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
                        .addComponent(cancelBtn))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveAndFinishPnl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(stepsPnl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(saveAndFinishPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(helpBtn)
                    .addComponent(backBtn)
                    .addComponent(finishBtn)
                    .addComponent(cancelBtn))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void backBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBtnActionPerformed
       
        this.setVisible(false);
        previousDialog.setVisible(true);


    }//GEN-LAST:event_backBtnActionPerformed

    private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
        this.dispose();

    }//GEN-LAST:event_cancelBtnActionPerformed

    private void whereToSaveBrowseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_whereToSaveBrowseBtnActionPerformed
        FileNameExtensionFilter wssFilter = new FileNameExtensionFilter("WinSIS Project", "wss");
        JFileChooser saveProjectDialog = new JFileChooser("./");
        saveProjectDialog.addChoosableFileFilter(wssFilter);
        String newProjectPath = new String();
        int answer = saveProjectDialog.showSaveDialog(this);
        if (answer == JFileChooser.APPROVE_OPTION) {
            newProjectPath = saveProjectDialog.getSelectedFile().getAbsolutePath();
            if(!newProjectPath.endsWith(".wss"))
                newProjectPath = newProjectPath.concat(".wss");
            File projectFile = new File(newProjectPath);
            try {
                projectFile.createNewFile();
                filePath = projectFile.getAbsolutePath();
                finishBtn.setEnabled(true);
                whereToSaveTxtFld.setText(filePath);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,"An error occured while " +
                        "trying to create the the project file.\nDecription:\n"+
                        ex.getMessage(), "WinSIS", JOptionPane.ERROR_MESSAGE);
            }


        }
    }//GEN-LAST:event_whereToSaveBrowseBtnActionPerformed

    private void finishBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishBtnActionPerformed
        mainForm.changeTilte(filePath);
        mainForm.setProjectIsSaved(true);
        this.setVisible(false);

    }//GEN-LAST:event_finishBtnActionPerformed

    private void helpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpBtnActionPerformed
        try {
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + "help.pdf" + "\"");
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Unable to find the help file!", "WinSIS", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_helpBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backBtn;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton cancelBtn;
    private javax.swing.JButton finishBtn;
    private javax.swing.JButton helpBtn;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JPanel saveAndFinishPnl;
    private javax.swing.JPanel stepsPnl;
    private javax.swing.JButton whereToSaveBrowseBtn;
    private javax.swing.JLabel whereToSaveLbl;
    private javax.swing.JTextField whereToSaveTxtFld;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of GUI.SaveAndFinishDlg

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.