package easysm.boundaries.components;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.naming.InvalidNameException;
import javax.swing.*;
import easysm.Constants;
import easysm.datatypes.Name;
/**
* @author Artur Tolstenco
*/
public class NewProjectFrame extends javax.swing.JDialog {
private static final long serialVersionUID = 1L;
private JLabel jLabel2;
private JLabel jLabel3;
private JTextField jtextfield_author;
private JPanel jPanel1;
private JButton jbutton_cancel;
private JButton jbutton_ok;
private JTextField jtextfield_version;
private JTextField jtextfield_name;
private JLabel jLabel1;
private EasySMFrame easySmFrame;
public NewProjectFrame(EasySMFrame easySmFrame) {
super();
initGUI();
this.easySmFrame=easySmFrame;
}
private void initGUI() {
try {
setModal(true);
this.setSize(317, 160);
GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
getContentPane().setLayout(thisLayout);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setTitle("Create New Project");
{
jLabel1 = new JLabel();
jLabel1.setText("Project Name");
}
{
jPanel1 = new JPanel();
{
jbutton_ok = new JButton();
jPanel1.add(jbutton_ok);
jbutton_ok.setText("Ok");
jbutton_ok.setMnemonic(KeyEvent.VK_O);
jbutton_ok.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/dialog-ok-apply.png")));
jbutton_ok.setPreferredSize(new java.awt.Dimension(101, 25));
jbutton_ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton_okActionPerformed(evt);
}
});
}
{
jbutton_cancel = new JButton();
jPanel1.add(jbutton_cancel);
jbutton_cancel.setText("Cancel");
jbutton_cancel.setMnemonic(java.awt.event.KeyEvent.VK_C);
jbutton_cancel.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/edit-delete.png")));
jbutton_cancel.setPreferredSize(new java.awt.Dimension(101, 25));
jbutton_cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton_cancelActionPerformed(evt);
}
});
}
}
{
jLabel2 = new JLabel();
jLabel2.setText("Author");
}
{
jLabel3 = new JLabel();
jLabel3.setText("Version");
}
{
jtextfield_version = new JTextField();
}
{
jtextfield_author = new JTextField();
}
{
jtextfield_name = new JTextField();
}
thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
.addContainerGap()
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jtextfield_name, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jtextfield_author, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jtextfield_version, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, 0, 37, Short.MAX_VALUE));
thisLayout.setHorizontalGroup(thisLayout.createParallelGroup()
.addComponent(jPanel1, GroupLayout.Alignment.LEADING, 0, 307, Short.MAX_VALUE)
.addGroup(thisLayout.createSequentialGroup()
.addPreferredGap(jPanel1, jLabel3, LayoutStyle.ComponentPlacement.INDENT)
.addGroup(thisLayout.createParallelGroup()
.addComponent(jLabel3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE))
.addGroup(thisLayout.createParallelGroup()
.addGroup(thisLayout.createSequentialGroup()
.addComponent(jtextfield_version, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE))
.addGroup(thisLayout.createSequentialGroup()
.addComponent(jtextfield_author, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE))
.addGroup(thisLayout.createSequentialGroup()
.addComponent(jtextfield_name, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)));
getRootPane().setDefaultButton(jbutton_ok);
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* Events Handler
*/
private void jbutton_okActionPerformed(ActionEvent evt) {
Name name=null;
try {
name = new Name(jtextfield_name.getText());
} catch (InvalidNameException e) {
JOptionPane.showMessageDialog(this,
Constants.MALFORMED_NAME,
getTitle(),
JOptionPane.ERROR_MESSAGE);
jtextfield_name.selectAll();
jtextfield_name.requestFocus();
return;
}
easySmFrame.createNewProject(name, jtextfield_author.getText(), jtextfield_version.getText());
dispose();
}
private void jbutton_cancelActionPerformed(ActionEvent evt) {
dispose();
}
}