/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* JDialogTextLineInput.java
*
* Created on 20.05.2009, 22:03:07
*/
package xplanetconfigurator.gui;
import java.awt.Dimension;
import xplanetconfigurator.util.OwnPreferences;
/**
*
* @author tom
*/
public class JDialogTextLineInput extends javax.swing.JDialog {
private static String FRAME_X = "dialog_user_text_line_x";
private static String FRAME_Y = "dialog_user_text_line_y";
private static String FRAME_HEIGHT = "dialog_user_text_line_h";
private static String FRAME_WITH = "dialog_user_text_line_w";
private IAskForUserTextLine caller;
/** Creates new form JDialogTextLineInput */
public JDialogTextLineInput(String description, IAskForUserTextLine caller) {
initComponents();
this.jLabelDescription.setText(description);
this.caller = caller;
this.loadUserPrefs();
this.getRootPane().setDefaultButton(this.jButtonOK);
}
/** 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() {
java.awt.GridBagConstraints gridBagConstraints;
jPanelMain = new javax.swing.JPanel();
jPanelInput = new javax.swing.JPanel();
jLabelDescription = new javax.swing.JLabel();
jTextFieldInput = new javax.swing.JTextField();
jPanelButtons = new javax.swing.JPanel();
jButtonOK = new javax.swing.JButton();
jButtonCancel = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jPanelMain.setName("jPanelMain"); // NOI18N
jPanelMain.setLayout(new java.awt.GridBagLayout());
jPanelInput.setName("jPanelInput"); // NOI18N
jPanelInput.setLayout(new java.awt.GridBagLayout());
jLabelDescription.setName("jLabelDescription"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 1.0;
jPanelInput.add(jLabelDescription, gridBagConstraints);
jTextFieldInput.setName("jTextFieldInput"); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
jPanelInput.add(jTextFieldInput, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 1.0;
jPanelMain.add(jPanelInput, gridBagConstraints);
jPanelButtons.setName("jPanelButtons"); // NOI18N
jPanelButtons.setLayout(new java.awt.GridBagLayout());
jButtonOK.setText("OK");
jButtonOK.setName("jButtonOK"); // NOI18N
jButtonOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOKActionPerformed(evt);
}
});
jPanelButtons.add(jButtonOK, new java.awt.GridBagConstraints());
jButtonCancel.setText("Cancel");
jButtonCancel.setName("jButtonCancel"); // NOI18N
jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
}
});
jPanelButtons.add(jButtonCancel, new java.awt.GridBagConstraints());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
jPanelMain.add(jPanelButtons, gridBagConstraints);
getContentPane().add(jPanelMain, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
String s = this.jTextFieldInput.getText();
this.caller.receiveUserTextLine(s);
this.closeMySelf();
}//GEN-LAST:event_jButtonOKActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
this.closeMySelf();
}//GEN-LAST:event_formWindowClosing
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
this.closeMySelf();
}//GEN-LAST:event_jButtonCancelActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JDialogTextLineInput("Test", null).setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonCancel;
private javax.swing.JButton jButtonOK;
private javax.swing.JLabel jLabelDescription;
private javax.swing.JPanel jPanelButtons;
private javax.swing.JPanel jPanelInput;
private javax.swing.JPanel jPanelMain;
private javax.swing.JTextField jTextFieldInput;
// End of variables declaration//GEN-END:variables
private void storeUserPrefs() {
int x = this.getX();
int y = this.getY();
Dimension d = this.getSize();
int h = (int) d.getHeight();
int w = (int) d.getWidth();
OwnPreferences prefs =
OwnPreferences.userNodeForPackage(this.getClass());
prefs.putInt(FRAME_X, x);
prefs.putInt(FRAME_Y, y);
prefs.putInt(FRAME_HEIGHT, h);
prefs.putInt(FRAME_WITH, w);
}
private void loadUserPrefs() {
OwnPreferences prefs =
OwnPreferences.userNodeForPackage(this.getClass());
int x = prefs.getInt(FRAME_X, 10);
int y = prefs.getInt(FRAME_Y, 10);
int h = prefs.getInt(FRAME_HEIGHT, 130);
int w = prefs.getInt(FRAME_WITH, 500);
this.setSize(new Dimension(w, h));
// System.out.println("Start info = " + info);
if (x == 10 && y == 10) // First use
{
// System.out.println("Start info in if() = " + info);
this.setLocationRelativeTo(null); //center it
} else {
this.setLocation(x, y);
}
}
private void closeMySelf() {
this.storeUserPrefs();
this.setVisible(false);
this.dispose();
}
}