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 public void windowClosed(java.awt.event.WindowEvent evt) 100 { 101 formWindowClosed(evt); 102 } 103 }); 104 105 bn_playBack.setText("<"); 106 bn_playBack.setToolTipText("Play backwards"); 107 bn_playBack.addActionListener(new java.awt.event.ActionListener() 108 { 109 public void actionPerformed(java.awt.event.ActionEvent evt) 110 { 111 bn_playBackActionPerformed(evt); 112 } 113 }); 114 115 jPanel1.add(bn_playBack); 116 117 bn_stop.setText("||"); 118 bn_stop.setToolTipText("Stop playback"); 119 bn_stop.addActionListener(new java.awt.event.ActionListener() 120 { 121 public void actionPerformed(java.awt.event.ActionEvent evt) 122 { 123 bn_stopActionPerformed(evt); 124 } 125 }); 126 127 jPanel1.add(bn_stop); 128 129 bn_playFwd.setText(">"); 130 bn_playFwd.setToolTipText("Play Forwards"); 131 bn_playFwd.addActionListener(new java.awt.event.ActionListener() 132 { 133 public void actionPerformed(java.awt.event.ActionEvent evt) 134 { 135 bn_playFwdActionPerformed(evt); 136 } 137 }); 138 139 jPanel1.add(bn_playFwd); 140 141 getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); 142 143 jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS)); 144 145 jLabel1.setText("Cur Time"); 146 jPanel3.add(jLabel1); 147 148 text_curTime.setHorizontalAlignment(javax.swing.JTextField.LEFT); 149 text_curTime.setText("0"); 150 text_curTime.setPreferredSize(new java.awt.Dimension(100, 21)); 151 text_curTime.addActionListener(new java.awt.event.ActionListener() 152 { 153 public void actionPerformed(java.awt.event.ActionEvent evt) 154 { 155 text_curTimeActionPerformed(evt); 156 } 157 }); 158 text_curTime.addFocusListener(new java.awt.event.FocusAdapter() 159 { 160 public void focusLost(java.awt.event.FocusEvent evt) 161 { 162 text_curTimeFocusLost(evt); 163 } 164 }); 165 166 jPanel3.add(text_curTime); 167 168 bn_time0.setText("Time 0"); 169 bn_time0.setToolTipText("Reset time to first frame"); 170 bn_time0.addActionListener(new java.awt.event.ActionListener() 171 { 172 public void actionPerformed(java.awt.event.ActionEvent evt) 173 { 174 bn_time0ActionPerformed(evt); 175 } 176 }); 177 178 jPanel3.add(bn_time0); 179 180 jPanel2.add(jPanel3); 181 182 jLabel2.setText("Frames Per Second"); 183 jPanel4.add(jLabel2); 184 185 text_timeStep.setHorizontalAlignment(javax.swing.JTextField.RIGHT); 186 text_timeStep.setText("60"); 187 text_timeStep.setPreferredSize(new java.awt.Dimension(100, 21)); 188 text_timeStep.addActionListener(new java.awt.event.ActionListener() 189 { 190 public void actionPerformed(java.awt.event.ActionEvent evt) 191 { 192 text_timeStepActionPerformed(evt); 193 } 194 }); 195 text_timeStep.addFocusListener(new java.awt.event.FocusAdapter() 196 { 197 public void focusLost(java.awt.event.FocusEvent evt) 198 { 199 text_timeStepFocusLost(evt); 200 } 201 }); 202 203 jPanel4.add(text_timeStep); 204 205 jPanel2.add(jPanel4); 206 207 getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER); 208 209 pack(); 210 }// </editor-fold>//GEN-END:initComponents 211 212 private void bn_time0ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_time0ActionPerformed 213 {//GEN-HEADEREND:event_bn_time0ActionPerformed 214 thread.setCurTime(0); 215 }//GEN-LAST:event_bn_time0ActionPerformed 216 217 private void bn_playFwdActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playFwdActionPerformed 218 {//GEN-HEADEREND:event_bn_playFwdActionPerformed 219 thread.setPlayState(PlayerThread.PS_PLAY_FWD); 220 }//GEN-LAST:event_bn_playFwdActionPerformed 221 222 private void bn_stopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_stopActionPerformed 223 {//GEN-HEADEREND:event_bn_stopActionPerformed 224 thread.setPlayState(PlayerThread.PS_STOP); 225 }//GEN-LAST:event_bn_stopActionPerformed 226 227 private void bn_playBackActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bn_playBackActionPerformed 228 {//GEN-HEADEREND:event_bn_playBackActionPerformed 229 thread.setPlayState(PlayerThread.PS_PLAY_BACK); 230 }//GEN-LAST:event_bn_playBackActionPerformed 231 232 private void formWindowClosed(java.awt.event.WindowEvent evt)//GEN-FIRST:event_formWindowClosed 233 {//GEN-HEADEREND:event_formWindowClosed 234// thread.exit(); 235 }//GEN-LAST:event_formWindowClosed 236 237 private void text_timeStepFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_timeStepFocusLost 238 {//GEN-HEADEREND:event_text_timeStepFocusLost 239 text_timeStepActionPerformed(null); 240 }//GEN-LAST:event_text_timeStepFocusLost 241 242 private void text_timeStepActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_timeStepActionPerformed 243 {//GEN-HEADEREND:event_text_timeStepActionPerformed 244 try 245 { 246 int val = Integer.parseInt(text_timeStep.getText()); 247 thread.setTimeStep(1.0 / val); 248 } 249 catch (Exception e) 250 { 251 } 252 253 double d = thread.getTimeStep(); 254 String newStrn = "" + (int)(1f / d); 255 if (newStrn.equals(text_timeStep.getText())) return; 256 text_timeStep.setText(newStrn); 257 258// text_timeStepActionPerformed(null); 259 }//GEN-LAST:event_text_timeStepActionPerformed 260 261 private void text_curTimeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_text_curTimeActionPerformed 262 {//GEN-HEADEREND:event_text_curTimeActionPerformed 263 try 264 { 265 double val = Double.parseDouble(text_curTime.getText()); 266 thread.setCurTime(val); 267 } 268 catch (Exception e) 269 { 270 } 271 272 double d = thread.getCurTime(); 273 text_curTime.setText("" + (float)d); 274 275 text_timeStepActionPerformed(null); 276 }//GEN-LAST:event_text_curTimeActionPerformed 277 278 private void text_curTimeFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_text_curTimeFocusLost 279 {//GEN-HEADEREND:event_text_curTimeFocusLost 280 text_curTimeActionPerformed(null); 281 }//GEN-LAST:event_text_curTimeFocusLost 282 283 // Variables declaration - do not modify//GEN-BEGIN:variables 284 private javax.swing.JButton bn_playBack; 285 private javax.swing.JButton bn_playFwd; 286 private javax.swing.JButton bn_stop; 287 private javax.swing.JButton bn_time0; 288 private javax.swing.JLabel jLabel1; 289 private javax.swing.JLabel jLabel2; 290 private javax.swing.JPanel jPanel1; 291 private javax.swing.JPanel jPanel2; 292 private javax.swing.JPanel jPanel3; 293 private javax.swing.JPanel jPanel4; 294 private javax.swing.JTextField text_curTime; 295 private javax.swing.JTextField text_timeStep; 296 // End of variables declaration//GEN-END:variables 297 298}