001/*
002 * SVG Salamander
003 * Copyright (c) 2004, Mark McKay
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or 
007 * without modification, are permitted provided that the following
008 * conditions are met:
009 *
010 *   - Redistributions of source code must retain the above 
011 *     copyright notice, this list of conditions and the following
012 *     disclaimer.
013 *   - Redistributions in binary form must reproduce the above
014 *     copyright notice, this list of conditions and the following
015 *     disclaimer in the documentation and/or other materials 
016 *     provided with the distribution.
017 *
018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
029 * OF THE POSSIBILITY OF SUCH DAMAGE. 
030 * 
031 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
032 * projects can be found at http://www.kitfox.com
033 *
034 * Created on September 28, 2004, 9:56 PM
035 */
036
037package com.kitfox.svg.app;
038
039/**
040 *
041 * @author  kitfox
042 */
043public class PlayerDialog extends javax.swing.JDialog implements PlayerThreadListener
044{
045    public static final long serialVersionUID = 1;
046    
047    PlayerThread thread;
048    
049    final SVGPlayer parent;
050    
051    /** Creates new form PlayerDialog */
052    public PlayerDialog(SVGPlayer parent)
053    {
054        super(parent, false);
055        initComponents();
056        
057        this.parent = parent;
058        
059        thread = new PlayerThread();
060        thread.addListener(this);
061        
062        text_timeStepActionPerformed(null);
063    }
064    
065    public void updateTime(double curTime, double timeStep, int playState)
066    {
067        if (playState == PlayerThread.PS_STOP) return;
068        
069        text_curTime.setText("" + (float)curTime);
070        parent.updateTime(curTime);
071//        text_timeStep.setText("" + (int)(1.0 / timeStep));
072    }
073    
074    /** This method is called from within the constructor to
075     * initialize the form.
076     * WARNING: Do NOT modify this code. The content of this method is
077     * always regenerated by the Form Editor.
078     */
079    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
080    private void initComponents()
081    {
082        jPanel1 = new javax.swing.JPanel();
083        bn_playBack = new javax.swing.JButton();
084        bn_stop = new javax.swing.JButton();
085        bn_playFwd = new javax.swing.JButton();
086        jPanel2 = new javax.swing.JPanel();
087        jPanel3 = new javax.swing.JPanel();
088        jLabel1 = new javax.swing.JLabel();
089        text_curTime = new javax.swing.JTextField();
090        bn_time0 = new javax.swing.JButton();
091        jPanel4 = new javax.swing.JPanel();
092        jLabel2 = new javax.swing.JLabel();
093        text_timeStep = new javax.swing.JTextField();
094
095        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
096        setTitle("Player");
097        addWindowListener(new java.awt.event.WindowAdapter()
098        {
099            @Override
100            public void windowClosed(java.awt.event.WindowEvent evt)
101            {
102                formWindowClosed(evt);
103            }
104        });
105
106        bn_playBack.setText("<");
107        bn_playBack.setToolTipText("Play backwards");
108        bn_playBack.addActionListener(new java.awt.event.ActionListener()
109        {
110            public void actionPerformed(java.awt.event.ActionEvent evt)
111            {
112                bn_playBackActionPerformed(evt);
113            }
114        });
115
116        jPanel1.add(bn_playBack);
117
118        bn_stop.setText("||");
119        bn_stop.setToolTipText("Stop playback");
120        bn_stop.addActionListener(new java.awt.event.ActionListener()
121        {
122            public void actionPerformed(java.awt.event.ActionEvent evt)
123            {
124                bn_stopActionPerformed(evt);
125            }
126        });
127
128        jPanel1.add(bn_stop);
129
130        bn_playFwd.setText(">");
131        bn_playFwd.setToolTipText("Play Forwards");
132        bn_playFwd.addActionListener(new java.awt.event.ActionListener()
133        {
134            public void actionPerformed(java.awt.event.ActionEvent evt)
135            {
136                bn_playFwdActionPerformed(evt);
137            }
138        });
139
140        jPanel1.add(bn_playFwd);
141
142        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
143
144        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
145
146        jLabel1.setText("Cur Time");
147        jPanel3.add(jLabel1);
148
149        text_curTime.setHorizontalAlignment(javax.swing.JTextField.LEFT);
150        text_curTime.setText("0");
151        text_curTime.setPreferredSize(new java.awt.Dimension(100, 21));
152        text_curTime.addActionListener(new java.awt.event.ActionListener()
153        {
154            public void actionPerformed(java.awt.event.ActionEvent evt)
155            {
156                text_curTimeActionPerformed(evt);
157            }
158        });
159        text_curTime.addFocusListener(new java.awt.event.FocusAdapter()
160        {
161            @Override
162            public void focusLost(java.awt.event.FocusEvent evt)
163            {
164                text_curTimeFocusLost(evt);
165            }
166        });
167
168        jPanel3.add(text_curTime);
169
170        bn_time0.setText("Time 0");
171        bn_time0.setToolTipText("Reset time to first frame");
172        bn_time0.addActionListener(new java.awt.event.ActionListener()
173        {
174            public void actionPerformed(java.awt.event.ActionEvent evt)
175            {
176                bn_time0ActionPerformed(evt);
177            }
178        });
179
180        jPanel3.add(bn_time0);
181
182        jPanel2.add(jPanel3);
183
184        jLabel2.setText("Frames Per Second");
185        jPanel4.add(jLabel2);
186
187        text_timeStep.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
188        text_timeStep.setText("60");
189        text_timeStep.setPreferredSize(new java.awt.Dimension(100, 21));
190        text_timeStep.addActionListener(new java.awt.event.ActionListener()
191        {
192            public void actionPerformed(java.awt.event.ActionEvent evt)
193            {
194                text_timeStepActionPerformed(evt);
195            }
196        });
197        text_timeStep.addFocusListener(new java.awt.event.FocusAdapter()
198        {
199            @Override
200            public void focusLost(java.awt.event.FocusEvent evt)
201            {
202                text_timeStepFocusLost(evt);
203            }
204        });
205
206        jPanel4.add(text_timeStep);
207
208        jPanel2.add(jPanel4);
209
210        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
211
212        pack();
213    }// </editor-fold>//GEN-END:initComponents
214
215    private void bn_time0ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_time0ActionPerformed
216    {//GEN-HEADEREND:event_bn_time0ActionPerformed
217        thread.setCurTime(0);
218    }//GEN-LAST:event_bn_time0ActionPerformed
219
220    private void bn_playFwdActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playFwdActionPerformed
221    {//GEN-HEADEREND:event_bn_playFwdActionPerformed
222        thread.setPlayState(PlayerThread.PS_PLAY_FWD);
223    }//GEN-LAST:event_bn_playFwdActionPerformed
224
225    private void bn_stopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_stopActionPerformed
226    {//GEN-HEADEREND:event_bn_stopActionPerformed
227        thread.setPlayState(PlayerThread.PS_STOP);
228    }//GEN-LAST:event_bn_stopActionPerformed
229
230    private void bn_playBackActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playBackActionPerformed
231    {//GEN-HEADEREND:event_bn_playBackActionPerformed
232        thread.setPlayState(PlayerThread.PS_PLAY_BACK);
233    }//GEN-LAST:event_bn_playBackActionPerformed
234
235    private void formWindowClosed(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosed
236    {//GEN-HEADEREND:event_formWindowClosed
237//        thread.exit();
238    }//GEN-LAST:event_formWindowClosed
239
240    private void text_timeStepFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_timeStepFocusLost
241    {//GEN-HEADEREND:event_text_timeStepFocusLost
242        text_timeStepActionPerformed(null);
243    }//GEN-LAST:event_text_timeStepFocusLost
244
245    private void text_timeStepActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_timeStepActionPerformed
246    {//GEN-HEADEREND:event_text_timeStepActionPerformed
247        try
248        {
249            int val = Integer.parseInt(text_timeStep.getText());
250            thread.setTimeStep(1.0 / val);
251        }
252        catch (Exception e)
253        {
254        }
255        
256        double d = thread.getTimeStep();
257        String newStrn = "" + (int)(1f / d);
258        if (newStrn.equals(text_timeStep.getText())) return;
259        text_timeStep.setText(newStrn);
260        
261//        text_timeStepActionPerformed(null);
262    }//GEN-LAST:event_text_timeStepActionPerformed
263
264    private void text_curTimeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_curTimeActionPerformed
265    {//GEN-HEADEREND:event_text_curTimeActionPerformed
266        try
267        {
268            double val = Double.parseDouble(text_curTime.getText());
269            thread.setCurTime(val);
270        }
271        catch (Exception e)
272        {
273        }
274        
275        double d = thread.getCurTime();
276        text_curTime.setText("" + (float)d);
277        
278        text_timeStepActionPerformed(null);
279    }//GEN-LAST:event_text_curTimeActionPerformed
280
281    private void text_curTimeFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_curTimeFocusLost
282    {//GEN-HEADEREND:event_text_curTimeFocusLost
283        text_curTimeActionPerformed(null);
284    }//GEN-LAST:event_text_curTimeFocusLost
285    
286    // Variables declaration - do not modify//GEN-BEGIN:variables
287    private javax.swing.JButton bn_playBack;
288    private javax.swing.JButton bn_playFwd;
289    private javax.swing.JButton bn_stop;
290    private javax.swing.JButton bn_time0;
291    private javax.swing.JLabel jLabel1;
292    private javax.swing.JLabel jLabel2;
293    private javax.swing.JPanel jPanel1;
294    private javax.swing.JPanel jPanel2;
295    private javax.swing.JPanel jPanel3;
296    private javax.swing.JPanel jPanel4;
297    private javax.swing.JTextField text_curTime;
298    private javax.swing.JTextField text_timeStep;
299    // End of variables declaration//GEN-END:variables
300    
301}