001    /*
002     * PlayerDialog.java
003     *
004     *
005     *  The Salamander Project - 2D and 3D graphics libraries in Java
006     *  Copyright (C) 2004 Mark McKay
007     *
008     *  This library is free software; you can redistribute it and/or
009     *  modify it under the terms of the GNU Lesser General Public
010     *  License as published by the Free Software Foundation; either
011     *  version 2.1 of the License, or (at your option) any later version.
012     *
013     *  This library is distributed in the hope that it will be useful,
014     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
015     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016     *  Lesser General Public License for more details.
017     *
018     *  You should have received a copy of the GNU Lesser General Public
019     *  License along with this library; if not, write to the Free Software
020     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021     *
022     *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
023     *  projects can be found at http://www.kitfox.com
024     *
025     * Created on September 28, 2004, 9:56 PM
026     */
027    
028    package com.kitfox.svg.app;
029    
030    /**
031     *
032     * @author  kitfox
033     */
034    public class PlayerDialog extends javax.swing.JDialog implements PlayerThreadListener
035    {
036        public static final long serialVersionUID = 1;
037        
038        PlayerThread thread;
039        
040        final SVGPlayer parent;
041        
042        /** Creates new form PlayerDialog */
043        public PlayerDialog(SVGPlayer parent)
044        {
045            super(parent, false);
046            initComponents();
047            
048            this.parent = parent;
049            
050            thread = new PlayerThread();
051            thread.addListener(this);
052            
053            text_timeStepActionPerformed(null);
054        }
055        
056        public void updateTime(double curTime, double timeStep, int playState)
057        {
058            if (playState == PlayerThread.PS_STOP) return;
059            
060            text_curTime.setText("" + (float)curTime);
061            parent.updateTime(curTime);
062    //        text_timeStep.setText("" + (int)(1.0 / timeStep));
063        }
064        
065        /** This method is called from within the constructor to
066         * initialize the form.
067         * WARNING: Do NOT modify this code. The content of this method is
068         * always regenerated by the Form Editor.
069         */
070        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
071        private void initComponents()
072        {
073            jPanel1 = new javax.swing.JPanel();
074            bn_playBack = new javax.swing.JButton();
075            bn_stop = new javax.swing.JButton();
076            bn_playFwd = new javax.swing.JButton();
077            jPanel2 = new javax.swing.JPanel();
078            jPanel3 = new javax.swing.JPanel();
079            jLabel1 = new javax.swing.JLabel();
080            text_curTime = new javax.swing.JTextField();
081            bn_time0 = new javax.swing.JButton();
082            jPanel4 = new javax.swing.JPanel();
083            jLabel2 = new javax.swing.JLabel();
084            text_timeStep = new javax.swing.JTextField();
085    
086            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
087            setTitle("Player");
088            addWindowListener(new java.awt.event.WindowAdapter()
089            {
090                public void windowClosed(java.awt.event.WindowEvent evt)
091                {
092                    formWindowClosed(evt);
093                }
094            });
095    
096            bn_playBack.setText("<");
097            bn_playBack.setToolTipText("Play backwards");
098            bn_playBack.addActionListener(new java.awt.event.ActionListener()
099            {
100                public void actionPerformed(java.awt.event.ActionEvent evt)
101                {
102                    bn_playBackActionPerformed(evt);
103                }
104            });
105    
106            jPanel1.add(bn_playBack);
107    
108            bn_stop.setText("||");
109            bn_stop.setToolTipText("Stop playback");
110            bn_stop.addActionListener(new java.awt.event.ActionListener()
111            {
112                public void actionPerformed(java.awt.event.ActionEvent evt)
113                {
114                    bn_stopActionPerformed(evt);
115                }
116            });
117    
118            jPanel1.add(bn_stop);
119    
120            bn_playFwd.setText(">");
121            bn_playFwd.setToolTipText("Play Forwards");
122            bn_playFwd.addActionListener(new java.awt.event.ActionListener()
123            {
124                public void actionPerformed(java.awt.event.ActionEvent evt)
125                {
126                    bn_playFwdActionPerformed(evt);
127                }
128            });
129    
130            jPanel1.add(bn_playFwd);
131    
132            getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
133    
134            jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
135    
136            jLabel1.setText("Cur Time");
137            jPanel3.add(jLabel1);
138    
139            text_curTime.setHorizontalAlignment(javax.swing.JTextField.LEFT);
140            text_curTime.setText("0");
141            text_curTime.setPreferredSize(new java.awt.Dimension(100, 21));
142            text_curTime.addActionListener(new java.awt.event.ActionListener()
143            {
144                public void actionPerformed(java.awt.event.ActionEvent evt)
145                {
146                    text_curTimeActionPerformed(evt);
147                }
148            });
149            text_curTime.addFocusListener(new java.awt.event.FocusAdapter()
150            {
151                public void focusLost(java.awt.event.FocusEvent evt)
152                {
153                    text_curTimeFocusLost(evt);
154                }
155            });
156    
157            jPanel3.add(text_curTime);
158    
159            bn_time0.setText("Time 0");
160            bn_time0.setToolTipText("Reset time to first frame");
161            bn_time0.addActionListener(new java.awt.event.ActionListener()
162            {
163                public void actionPerformed(java.awt.event.ActionEvent evt)
164                {
165                    bn_time0ActionPerformed(evt);
166                }
167            });
168    
169            jPanel3.add(bn_time0);
170    
171            jPanel2.add(jPanel3);
172    
173            jLabel2.setText("Frames Per Second");
174            jPanel4.add(jLabel2);
175    
176            text_timeStep.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
177            text_timeStep.setText("60");
178            text_timeStep.setPreferredSize(new java.awt.Dimension(100, 21));
179            text_timeStep.addActionListener(new java.awt.event.ActionListener()
180            {
181                public void actionPerformed(java.awt.event.ActionEvent evt)
182                {
183                    text_timeStepActionPerformed(evt);
184                }
185            });
186            text_timeStep.addFocusListener(new java.awt.event.FocusAdapter()
187            {
188                public void focusLost(java.awt.event.FocusEvent evt)
189                {
190                    text_timeStepFocusLost(evt);
191                }
192            });
193    
194            jPanel4.add(text_timeStep);
195    
196            jPanel2.add(jPanel4);
197    
198            getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
199    
200            pack();
201        }// </editor-fold>//GEN-END:initComponents
202    
203        private void bn_time0ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_time0ActionPerformed
204        {//GEN-HEADEREND:event_bn_time0ActionPerformed
205            thread.setCurTime(0);
206        }//GEN-LAST:event_bn_time0ActionPerformed
207    
208        private void bn_playFwdActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playFwdActionPerformed
209        {//GEN-HEADEREND:event_bn_playFwdActionPerformed
210            thread.setPlayState(PlayerThread.PS_PLAY_FWD);
211        }//GEN-LAST:event_bn_playFwdActionPerformed
212    
213        private void bn_stopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_stopActionPerformed
214        {//GEN-HEADEREND:event_bn_stopActionPerformed
215            thread.setPlayState(PlayerThread.PS_STOP);
216        }//GEN-LAST:event_bn_stopActionPerformed
217    
218        private void bn_playBackActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playBackActionPerformed
219        {//GEN-HEADEREND:event_bn_playBackActionPerformed
220            thread.setPlayState(PlayerThread.PS_PLAY_BACK);
221        }//GEN-LAST:event_bn_playBackActionPerformed
222    
223        private void formWindowClosed(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosed
224        {//GEN-HEADEREND:event_formWindowClosed
225    //        thread.exit();
226        }//GEN-LAST:event_formWindowClosed
227    
228        private void text_timeStepFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_timeStepFocusLost
229        {//GEN-HEADEREND:event_text_timeStepFocusLost
230            text_timeStepActionPerformed(null);
231        }//GEN-LAST:event_text_timeStepFocusLost
232    
233        private void text_timeStepActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_timeStepActionPerformed
234        {//GEN-HEADEREND:event_text_timeStepActionPerformed
235            try
236            {
237                int val = Integer.parseInt(text_timeStep.getText());
238                thread.setTimeStep(1.0 / val);
239            }
240            catch (Exception e)
241            {
242            }
243            
244            double d = thread.getTimeStep();
245            String newStrn = "" + (int)(1f / d);
246            if (newStrn.equals(text_timeStep.getText())) return;
247            text_timeStep.setText(newStrn);
248            
249    //        text_timeStepActionPerformed(null);
250        }//GEN-LAST:event_text_timeStepActionPerformed
251    
252        private void text_curTimeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_curTimeActionPerformed
253        {//GEN-HEADEREND:event_text_curTimeActionPerformed
254            try
255            {
256                double val = Double.parseDouble(text_curTime.getText());
257                thread.setCurTime(val);
258            }
259            catch (Exception e)
260            {
261            }
262            
263            double d = thread.getCurTime();
264            text_curTime.setText("" + (float)d);
265            
266            text_timeStepActionPerformed(null);
267        }//GEN-LAST:event_text_curTimeActionPerformed
268    
269        private void text_curTimeFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_curTimeFocusLost
270        {//GEN-HEADEREND:event_text_curTimeFocusLost
271            text_curTimeActionPerformed(null);
272        }//GEN-LAST:event_text_curTimeFocusLost
273        
274        // Variables declaration - do not modify//GEN-BEGIN:variables
275        private javax.swing.JButton bn_playBack;
276        private javax.swing.JButton bn_playFwd;
277        private javax.swing.JButton bn_stop;
278        private javax.swing.JButton bn_time0;
279        private javax.swing.JLabel jLabel1;
280        private javax.swing.JLabel jLabel2;
281        private javax.swing.JPanel jPanel1;
282        private javax.swing.JPanel jPanel2;
283        private javax.swing.JPanel jPanel3;
284        private javax.swing.JPanel jPanel4;
285        private javax.swing.JTextField text_curTime;
286        private javax.swing.JTextField text_timeStep;
287        // End of variables declaration//GEN-END:variables
288        
289    }