package tk.amberide.ide.gui.dialogs;
import java.awt.EventQueue;
/**
* A generic 'New' dialog.
*
* @author Tudor
*/
public class TNewDialog extends javax.swing.JDialog {
private String title;
/**
* Creates new form TNewDialog
*/
public TNewDialog(java.awt.Frame parent, String title) {
super(parent);
this.title = title;
initComponents();
}
public String showDialog() {
setVisible(true);
return nameField.getText();
}
/**
* 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() {
nameGroup = new javax.swing.JPanel();
nameLabel = new javax.swing.JLabel();
nameField = new tk.amberide.ide.swing.textbox.HintTextField();
createButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("New " + this.title.toLowerCase() + "...");
setModal(true);
nameGroup.setBorder(javax.swing.BorderFactory.createTitledBorder(this.title));
nameLabel.setText("Name:");
nameField.setHint("Type in a name...");
nameField.setRequestFocusEnabled(false);
nameField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nameFieldActionPerformed(evt);
}
});
javax.swing.GroupLayout nameGroupLayout = new javax.swing.GroupLayout(nameGroup);
nameGroup.setLayout(nameGroupLayout);
nameGroupLayout.setHorizontalGroup(
nameGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, nameGroupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(nameLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
nameGroupLayout.setVerticalGroup(
nameGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(nameGroupLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addGroup(nameGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
createButton.setText("Create");
createButton.setEnabled(false);
createButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
createButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(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)
.addGroup(layout.createSequentialGroup()
.addGap(148, 148, 148)
.addComponent(createButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addComponent(nameGroup, 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()
.addComponent(nameGroup, 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(cancelButton)
.addComponent(createButton))
.addGap(6, 6, 6))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed
dispose();
}//GEN-LAST:event_createButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
nameField.setText(null);
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameFieldActionPerformed
EventQueue.invokeLater(new Runnable() {
public void run() {
createButton.setEnabled(nameField.getText().length() > 0);
getRootPane().setDefaultButton(createButton);
}
});
}//GEN-LAST:event_nameFieldActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton createButton;
private tk.amberide.ide.swing.textbox.HintTextField nameField;
private javax.swing.JPanel nameGroup;
private javax.swing.JLabel nameLabel;
// End of variables declaration//GEN-END:variables
}