001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/warp/WarpEditorDialog.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.DefaultListModel;
021: import javax.swing.event.ListSelectionListener;
022: import javax.media.j3d.TransformGroup;
023: import javax.media.j3d.Transform3D;
024:
025: /**
026: * Dialog box for editing Warps
027: *
028: * @author Paul Byrne
029: * @version 1.6, 01/18/02
030: */
031: public class WarpEditorDialog extends javax.swing.JDialog implements
032: ListSelectionListener {
033:
034: private WarpSet warpSet;
035: private TransformGroup viewTG;
036: private DefaultListModel listModel;
037:
038: /** Creates new form WarpEditorDialog */
039: public WarpEditorDialog(java.awt.Frame parent, boolean modal,
040: WarpSet warpSet, TransformGroup viewTG) {
041: super (parent, modal);
042: this .warpSet = warpSet;
043: this .viewTG = viewTG;
044: listModel = new DefaultListModel();
045: String[] warpName = warpSet.getNames();
046: for (int i = 0; i < warpName.length; i++)
047: listModel.addElement(warpName[i]);
048: initComponents();
049: pack();
050:
051: warpList.addListSelectionListener(this );
052:
053: int x = parent.getWidth() / 2 - this .getWidth() / 2;
054: int y = parent.getHeight() / 2 - this .getHeight() / 2;
055:
056: setLocation(x, y);
057: }
058:
059: /** This method is called from within the constructor to
060: * initialize the form.
061: * WARNING: Do NOT modify this code. The content of this method is
062: * always regenerated by the FormEditor.
063: */
064: private void initComponents() {//GEN-BEGIN:initComponents
065: jPanel1 = new javax.swing.JPanel();
066: createWarpB = new javax.swing.JButton();
067: deleteWarpB = new javax.swing.JButton();
068: makeDefaultB = new javax.swing.JButton();
069: jScrollPane1 = new javax.swing.JScrollPane();
070: warpList = new javax.swing.JList();
071: jPanel2 = new javax.swing.JPanel();
072: okB = new javax.swing.JButton();
073: addWindowListener(new java.awt.event.WindowAdapter() {
074: public void windowClosing(java.awt.event.WindowEvent evt) {
075: closeDialog(evt);
076: }
077: });
078:
079: jPanel1.setLayout(new java.awt.GridBagLayout());
080: java.awt.GridBagConstraints gridBagConstraints1;
081:
082: createWarpB
083: .setToolTipText("Create a Warp for the current View");
084: createWarpB.setLabel("Create Warp");
085: createWarpB
086: .addActionListener(new java.awt.event.ActionListener() {
087: public void actionPerformed(
088: java.awt.event.ActionEvent evt) {
089: createWarpBActionPerformed(evt);
090: }
091: });
092: gridBagConstraints1 = new java.awt.GridBagConstraints();
093: gridBagConstraints1.gridx = 0;
094: gridBagConstraints1.gridy = 1;
095: jPanel1.add(createWarpB, gridBagConstraints1);
096:
097: deleteWarpB.setToolTipText("Delete the selected Warp");
098: deleteWarpB.setText("Delete");
099: deleteWarpB.setEnabled(false);
100: deleteWarpB
101: .addActionListener(new java.awt.event.ActionListener() {
102: public void actionPerformed(
103: java.awt.event.ActionEvent evt) {
104: deleteWarpBActionPerformed(evt);
105: }
106: });
107: gridBagConstraints1 = new java.awt.GridBagConstraints();
108: gridBagConstraints1.gridx = 1;
109: gridBagConstraints1.gridy = 1;
110: jPanel1.add(deleteWarpB, gridBagConstraints1);
111:
112: makeDefaultB
113: .setToolTipText("Make the selected warp the default (initial) warp for this file");
114: makeDefaultB.setText("Make Default");
115: makeDefaultB.setEnabled(false);
116: makeDefaultB
117: .addActionListener(new java.awt.event.ActionListener() {
118: public void actionPerformed(
119: java.awt.event.ActionEvent evt) {
120: makeDefaultBActionPerformed(evt);
121: }
122: });
123: gridBagConstraints1 = new java.awt.GridBagConstraints();
124: gridBagConstraints1.gridx = 2;
125: gridBagConstraints1.gridy = 1;
126: jPanel1.add(makeDefaultB, gridBagConstraints1);
127:
128: jScrollPane1.setMinimumSize(new java.awt.Dimension(250, 100));
129:
130: warpList.setPreferredSize(new java.awt.Dimension(250, 100));
131: warpList.setModel(listModel);
132: warpList
133: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
134: jScrollPane1.setViewportView(warpList);
135:
136: gridBagConstraints1 = new java.awt.GridBagConstraints();
137: gridBagConstraints1.gridwidth = 3;
138: jPanel1.add(jScrollPane1, gridBagConstraints1);
139:
140: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
141:
142: okB.setText("OK");
143: okB.addActionListener(new java.awt.event.ActionListener() {
144: public void actionPerformed(java.awt.event.ActionEvent evt) {
145: okBActionPerformed(evt);
146: }
147: });
148: jPanel2.add(okB);
149:
150: getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
151:
152: }//GEN-END:initComponents
153:
154: private void okBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBActionPerformed
155: // Add your handling code here:
156: setVisible(false);
157: }//GEN-LAST:event_okBActionPerformed
158:
159: private void makeDefaultBActionPerformed(
160: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_makeDefaultBActionPerformed
161: // Add your handling code here:
162: warpSet.setDefaultWarp((String) warpList.getSelectedValue());
163: }//GEN-LAST:event_makeDefaultBActionPerformed
164:
165: private void deleteWarpBActionPerformed(
166: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWarpBActionPerformed
167: // Add your handling code here:
168: warpSet
169: .deleteWarpPosition((String) warpList
170: .getSelectedValue());
171: listModel.removeElement(warpList.getSelectedValue());
172: }//GEN-LAST:event_deleteWarpBActionPerformed
173:
174: private void createWarpBActionPerformed(
175: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createWarpBActionPerformed
176: // Add your handling code here:
177: Transform3D trans = new Transform3D();
178: viewTG.getTransform(trans);
179:
180: String name = warpSet.createWarp(trans, this );
181:
182: listModel.addElement(name);
183:
184: }//GEN-LAST:event_createWarpBActionPerformed
185:
186: /** Closes the dialog */
187: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
188: setVisible(false);
189: viewTG = null;
190: dispose();
191: }//GEN-LAST:event_closeDialog
192:
193: /**
194: * List Selection Listener
195: */
196: public void valueChanged(
197: final javax.swing.event.ListSelectionEvent p1) {
198: makeDefaultB.setEnabled(true);
199: deleteWarpB.setEnabled(true);
200: }
201:
202: // Variables declaration - do not modify//GEN-BEGIN:variables
203: private javax.swing.JPanel jPanel1;
204: private javax.swing.JButton createWarpB;
205: private javax.swing.JButton deleteWarpB;
206: private javax.swing.JButton makeDefaultB;
207: private javax.swing.JScrollPane jScrollPane1;
208: private javax.swing.JList warpList;
209: private javax.swing.JPanel jPanel2;
210: private javax.swing.JButton okB;
211: // End of variables declaration//GEN-END:variables
212:
213: }
|