001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/warp/CreateWarpDialog.java,v 1.1 2005/04/20 21:05:19 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dfly.warp;
019:
020: import javax.swing.JDialog;
021:
022: /**
023: * Dialog box for creating new warp objects
024: *
025: * @author Paul Byrne
026: * @version 1.5, 01/18/02
027: */
028: public class CreateWarpDialog extends javax.swing.JDialog {
029:
030: private WarpSet warpSet;
031: private boolean isValid; // Do we have a valid warp name
032: private JDialog parent;
033:
034: /** Creates new form CreateWarpDialog */
035: public CreateWarpDialog(JDialog parent, boolean modal,
036: WarpSet warpSet) {
037: super (parent, modal);
038: this .parent = parent;
039: this .warpSet = warpSet;
040: isValid = false;
041: initComponents();
042: pack();
043: centerOnParent();
044: }
045:
046: /** This method is called from within the constructor to
047: * initialize the form.
048: * WARNING: Do NOT modify this code. The content of this method is
049: * always regenerated by the FormEditor.
050: */
051: private void initComponents() {//GEN-BEGIN:initComponents
052: jPanel1 = new javax.swing.JPanel();
053: duplicateLabel = new javax.swing.JLabel();
054: jLabel2 = new javax.swing.JLabel();
055: jLabel3 = new javax.swing.JLabel();
056: nameTF = new javax.swing.JTextField();
057: jScrollPane1 = new javax.swing.JScrollPane();
058: descriptionTF = new javax.swing.JTextField();
059: jPanel2 = new javax.swing.JPanel();
060: okB = new javax.swing.JButton();
061: cancelB = new javax.swing.JButton();
062: setModal(true);
063: setTitle("Create Warp");
064: addWindowListener(new java.awt.event.WindowAdapter() {
065: public void windowClosing(java.awt.event.WindowEvent evt) {
066: closeDialog(evt);
067: }
068: });
069:
070: jPanel1.setLayout(new java.awt.GridBagLayout());
071: java.awt.GridBagConstraints gridBagConstraints1;
072:
073: duplicateLabel.setFont(new java.awt.Font("Dialog", 1, 11));
074: gridBagConstraints1 = new java.awt.GridBagConstraints();
075: jPanel1.add(duplicateLabel, gridBagConstraints1);
076:
077: jLabel2.setText("Name");
078: gridBagConstraints1 = new java.awt.GridBagConstraints();
079: gridBagConstraints1.gridx = 0;
080: gridBagConstraints1.gridy = 1;
081: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 4);
082: gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
083: jPanel1.add(jLabel2, gridBagConstraints1);
084:
085: jLabel3.setText("Description");
086: gridBagConstraints1 = new java.awt.GridBagConstraints();
087: gridBagConstraints1.gridx = 0;
088: gridBagConstraints1.gridy = 2;
089: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 4);
090: gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
091: jPanel1.add(jLabel3, gridBagConstraints1);
092:
093: nameTF.setPreferredSize(new java.awt.Dimension(100, 21));
094: nameTF.setToolTipText("Name for the warp");
095: nameTF.setMinimumSize(new java.awt.Dimension(100, 21));
096: gridBagConstraints1 = new java.awt.GridBagConstraints();
097: gridBagConstraints1.gridx = 1;
098: gridBagConstraints1.gridy = 1;
099: jPanel1.add(nameTF, gridBagConstraints1);
100:
101: jScrollPane1.setMinimumSize(new java.awt.Dimension(22, 39));
102:
103: descriptionTF
104: .setToolTipText("Optional description of the warp");
105: jScrollPane1.setViewportView(descriptionTF);
106:
107: gridBagConstraints1 = new java.awt.GridBagConstraints();
108: gridBagConstraints1.gridx = 1;
109: gridBagConstraints1.gridy = 2;
110: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
111: jPanel1.add(jScrollPane1, gridBagConstraints1);
112:
113: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
114:
115: okB.setText("OK");
116: okB.addActionListener(new java.awt.event.ActionListener() {
117: public void actionPerformed(java.awt.event.ActionEvent evt) {
118: okBActionPerformed(evt);
119: }
120: });
121: jPanel2.add(okB);
122:
123: cancelB.setText("Cancel");
124: cancelB.addActionListener(new java.awt.event.ActionListener() {
125: public void actionPerformed(java.awt.event.ActionEvent evt) {
126: cancelBActionPerformed(evt);
127: }
128: });
129: jPanel2.add(cancelB);
130:
131: getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
132:
133: }//GEN-END:initComponents
134:
135: private void cancelBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBActionPerformed
136: // Add your handling code here:
137: isValid = false;
138: setVisible(false);
139: }//GEN-LAST:event_cancelBActionPerformed
140:
141: private void okBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBActionPerformed
142: // Add your handling code here:
143: if (warpSet.nameExists(nameTF.getText())) {
144: duplicateLabel.setText("Warp Name is not unique");
145: pack();
146: } else {
147: isValid = true;
148: setVisible(false);
149: }
150: }//GEN-LAST:event_okBActionPerformed
151:
152: /** Closes the dialog */
153: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
154: setVisible(false);
155: dispose();
156: }//GEN-LAST:event_closeDialog
157:
158: /**
159: * Return true if the user has entered a valid warp name and
160: * pressed OK
161: */
162: public boolean isValid() {
163: return isValid;
164: }
165:
166: public String getName() {
167: return nameTF.getText();
168: }
169:
170: public String getDescription() {
171: return descriptionTF.getText();
172: }
173:
174: private void centerOnParent() {
175: int parentW = parent.getWidth();
176: int parentH = parent.getHeight();
177:
178: setLocation(parentW / 2 - getWidth() / 2, parentH / 2
179: - getHeight() / 2);
180: }
181:
182: // Variables declaration - do not modify//GEN-BEGIN:variables
183: private javax.swing.JPanel jPanel1;
184: private javax.swing.JLabel duplicateLabel;
185: private javax.swing.JLabel jLabel2;
186: private javax.swing.JLabel jLabel3;
187: private javax.swing.JTextField nameTF;
188: private javax.swing.JScrollPane jScrollPane1;
189: private javax.swing.JTextField descriptionTF;
190: private javax.swing.JPanel jPanel2;
191: private javax.swing.JButton okB;
192: private javax.swing.JButton cancelB;
193: // End of variables declaration//GEN-END:variables
194:
195: }
|