001 ///////////////////////////////////////////////// 002 // This file is part of Sears project. 003 // Subtitle Editor And Re-Synch 004 // A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 // at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 //////////////////////////////////////////////// 017 package sears.gui; 018 import java.awt.GridBagConstraints; 019 import java.awt.GridBagLayout; 020 import java.awt.Insets; 021 import java.util.Hashtable; 022 023 import javax.swing.BorderFactory; 024 import javax.swing.JButton; 025 import javax.swing.JCheckBox; 026 import javax.swing.JLabel; 027 import javax.swing.JPanel; 028 import javax.swing.JSlider; 029 import javax.swing.JSpinner; 030 import javax.swing.SpinnerNumberModel; 031 import javax.swing.event.ChangeListener; 032 033 import sears.tools.Utils; 034 035 036 /** 037 * Class JPanelVideoControler. 038 * <br><b>Summary:</b><br> 039 * This is the panel that permits to control the video player. 040 */ 041 public class JPanelVideoControler extends JPanel { 042 private static final long serialVersionUID = 1L; 043 private JButton jButtonOpenVideo = null; 044 private JButton jButtonStop = null; 045 private JButton jButtonPlay = null; 046 private JButton jButtonPrevious = null; 047 private JSpinner jSpinnerTimeStep = null; 048 private JButton jButtonNext = null; 049 private JSlider jSliderSearch = null; 050 private JCheckBox jCheckBoxTrackMode = null; 051 private JPanel jPanelStopPlay = null; 052 private JPanel jPanelPreviousNext = null; 053 private JButton jButtonPause = null; 054 private JLabel jLabelTime = null; 055 056 /** 057 * This is the default constructor 058 */ 059 public JPanelVideoControler() { 060 super(); 061 initialize(); 062 } 063 064 /** 065 * This method initializes this 066 */ 067 private void initialize() { 068 GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); 069 gridBagConstraints9.gridx = 4; 070 gridBagConstraints9.anchor = GridBagConstraints.EAST; 071 gridBagConstraints9.gridy = 0; 072 073 GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); 074 gridBagConstraints7.gridx = 0; 075 gridBagConstraints7.gridy = 0; 076 gridBagConstraints7.fill = GridBagConstraints.NONE; 077 gridBagConstraints7.anchor = GridBagConstraints.WEST; 078 079 gridBagConstraints7.insets = new Insets(5, 0, 5, 0); 080 gridBagConstraints7.gridwidth = 2; 081 082 GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); 083 gridBagConstraints6.gridx = 5; 084 gridBagConstraints6.anchor = GridBagConstraints.EAST; 085 gridBagConstraints6.gridy = 0; 086 GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); 087 gridBagConstraints5.fill = GridBagConstraints.BOTH; 088 gridBagConstraints5.gridy = 2; 089 gridBagConstraints5.weightx = 1.0; 090 gridBagConstraints5.gridwidth = 7; 091 gridBagConstraints5.gridx = 0; 092 GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); 093 gridBagConstraints8.fill = GridBagConstraints.VERTICAL; 094 gridBagConstraints8.gridy = 0; 095 gridBagConstraints8.weightx = 1.0; 096 gridBagConstraints8.gridwidth = 3; 097 gridBagConstraints8.anchor = GridBagConstraints.CENTER; 098 gridBagConstraints8.gridx = 2; 099 this.setSize(563, 62); 100 this.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); 101 this.setLayout(new GridBagLayout()); 102 this.add(getJSliderSearch(), gridBagConstraints5); 103 this.add(getJCheckBoxTrackMode(), gridBagConstraints6); 104 this.add(getJPanelStopPlay(), gridBagConstraints7); 105 this.add(getJPanelPreviousNext(), gridBagConstraints8); 106 this.add(getJLabelTime(), gridBagConstraints9); 107 108 } 109 110 /** 111 * This method initializes jButtonOpenVideo 112 * 113 * @return javax.swing.JButton 114 */ 115 private JButton getJButtonOpenVideo() { 116 if (jButtonOpenVideo == null) { 117 jButtonOpenVideo = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_SELECT_VIDEO)); 118 jButtonOpenVideo.setText(""); 119 } 120 return jButtonOpenVideo; 121 } 122 123 /** 124 * This method initializes jButtonStop 125 * 126 * @return javax.swing.JButton 127 */ 128 private JButton getJButtonStop() { 129 if (jButtonStop == null) { 130 jButtonStop = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_STOP)); 131 jButtonStop.setText(""); 132 } 133 return jButtonStop; 134 } 135 136 /** 137 * This method initializes jButtonPlay 138 * 139 * @return javax.swing.JButton 140 */ 141 private JButton getJButtonPlay() { 142 if (jButtonPlay == null) { 143 jButtonPlay = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_PLAY)); 144 jButtonPlay.setText(""); 145 } 146 return jButtonPlay; 147 } 148 149 /** 150 * This method initializes jButtonPrevious 151 * 152 * @return javax.swing.JButton 153 */ 154 private JButton getJButtonPrevious() { 155 if (jButtonPrevious == null) { 156 jButtonPrevious = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_PREVIOUS)); 157 jButtonPrevious.setText(""); 158 } 159 return jButtonPrevious; 160 } 161 162 /** 163 * This method initializes jSpinner 164 * 165 * @return javax.swing.jSpinner 166 */ 167 private JSpinner getJSpinnerTimeStep() { 168 if (jSpinnerTimeStep == null) { 169 jSpinnerTimeStep = new JSpinner(new SpinnerNumberModel(10, 1, 200, 1)); 170 } 171 return jSpinnerTimeStep; 172 } 173 174 /** 175 * This method initializes jButtonNext 176 * 177 * @return javax.swing.JButton 178 */ 179 private JButton getJButtonNext() { 180 if (jButtonNext == null) { 181 jButtonNext = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_NEXT)); 182 jButtonNext.setText(""); 183 } 184 return jButtonNext; 185 } 186 187 /** 188 * This method initializes JLabelTime 189 * 190 * @return javax.swing.JLabel 191 */ 192 private JLabel getJLabelTime() { 193 if (jLabelTime == null) { 194 jLabelTime = new JLabel("00:00:00"); 195 } 196 return jLabelTime; 197 } 198 199 /** 200 * This method initializes JLabelTime 201 * 202 */ 203 protected void setJLabelTime(String time) { 204 if (jLabelTime != null) { 205 jLabelTime.setText(time); 206 } 207 } 208 209 /** 210 * This method initializes jSliderSearch 211 * 212 * @return javax.swing.JSlider 213 */ 214 private JSlider getJSliderSearch() { 215 if (jSliderSearch == null) { 216 jSliderSearch = new JSlider(); 217 setJSliderSearchLength(0); 218 } 219 return jSliderSearch; 220 } 221 222 /** 223 * Method setJSliderSearchLength. 224 * <br><b>Summary:</b><br> 225 * Set the slider graduation according to the video length. 226 * @param videoLength The <b>int</b> video time in second 227 */ 228 protected void setJSliderSearchLength(int videoLength) { 229 if (jSliderSearch != null) { 230 jSliderSearch.setMaximum(videoLength); 231 jSliderSearch.setMajorTickSpacing(videoLength/4); 232 jSliderSearch.setMinorTickSpacing(videoLength/16); 233 jSliderSearch.setPaintTicks(true); 234 jSliderSearch.setPaintLabels(true); 235 // Create the label table 236 Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); 237 labelTable.put( new Integer( 0 ), new JLabel("00:00:00") ); 238 labelTable.put( new Integer( videoLength / 4 ), new JLabel(Utils.formatTime(videoLength / 4)) ); 239 labelTable.put( new Integer( videoLength / 2 ), new JLabel(Utils.formatTime(videoLength / 2)) ); 240 labelTable.put( new Integer( (videoLength / 4) * 3 ), new JLabel(Utils.formatTime((videoLength / 4) * 3)) ); 241 labelTable.put( new Integer( videoLength ), new JLabel(Utils.formatTime(videoLength)) ); 242 jSliderSearch.setLabelTable( labelTable ); 243 } 244 } 245 246 /** 247 * Method setJSliderSearchListener. 248 * <br><b>Summary:</b><br> 249 * Permits to add a change listener to the JSlider. 250 * @param listener The changeListener to add to the JSlider. 251 */ 252 protected void setJSliderSearchListener(ChangeListener listener) { 253 if (jSliderSearch != null) { 254 jSliderSearch.addChangeListener(listener); 255 } 256 } 257 258 /** 259 * Method setJSliderSearchPosition. 260 * <br><b>Summary:</b><br> 261 * Set the slider position according to the video position. 262 * @param position The <b>int</b> video position in second 263 */ 264 protected void setJSliderSearchPosition(int position) { 265 if (jSliderSearch != null) { 266 jSliderSearch.setValue(position); 267 } 268 } 269 270 /** 271 * This method initializes jCheckBoxTrackMode 272 * 273 * @return javax.swing.JCheckBox 274 */ 275 private JCheckBox getJCheckBoxTrackMode() { 276 if (jCheckBoxTrackMode == null) { 277 jCheckBoxTrackMode = new JCheckBox(MainWindow.instance.getAction(MainWindow.ACTION_KEY_TRACKER_TRIGGER)); 278 } 279 return jCheckBoxTrackMode; 280 } 281 282 /** 283 * This method initializes jCheckBoxTrackMode 284 * 285 * @return javax.swing.JCheckBox 286 */ 287 protected boolean jCheckBoxTrackModeIsSelected() { 288 boolean isSelected = false; 289 if (jCheckBoxTrackMode != null) { 290 isSelected = jCheckBoxTrackMode.isSelected(); 291 } 292 return isSelected; 293 } 294 295 /** 296 * This method initializes jPanelStopPlay 297 * 298 * @return javax.swing.JPanel 299 */ 300 private JPanel getJPanelStopPlay() { 301 if (jPanelStopPlay == null) { 302 GridBagConstraints gridBagConstraints111 = new GridBagConstraints(); 303 gridBagConstraints111.gridx = 0; 304 gridBagConstraints111.gridy = 0; 305 GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); 306 gridBagConstraints11.gridx = 2; 307 gridBagConstraints11.gridy = 0; 308 GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); 309 gridBagConstraints1.gridx = 3; 310 gridBagConstraints1.ipadx = 0; 311 gridBagConstraints1.anchor = GridBagConstraints.EAST; 312 gridBagConstraints1.fill = GridBagConstraints.NONE; 313 gridBagConstraints1.gridy = -1; 314 GridBagConstraints gridBagConstraints = new GridBagConstraints(); 315 gridBagConstraints.gridx = -1; 316 gridBagConstraints.anchor = GridBagConstraints.WEST; 317 gridBagConstraints.gridy = -1; 318 jPanelStopPlay = new JPanel(); 319 jPanelStopPlay.setLayout(new GridBagLayout()); 320 jPanelStopPlay.add(getJButtonOpenVideo(), gridBagConstraints111); 321 jPanelStopPlay.add(getJButtonStop(), gridBagConstraints); 322 jPanelStopPlay.add(getJButtonPlay(), gridBagConstraints1); 323 jPanelStopPlay.add(getJButtonPause(), gridBagConstraints11); 324 } 325 return jPanelStopPlay; 326 } 327 328 /** 329 * This method initializes jPanelPreviousNext 330 * 331 * @return javax.swing.JPanel 332 */ 333 private JPanel getJPanelPreviousNext() { 334 if (jPanelPreviousNext == null) { 335 GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); 336 gridBagConstraints4.gridx = -1; 337 gridBagConstraints4.anchor = GridBagConstraints.WEST; 338 gridBagConstraints4.fill = GridBagConstraints.NONE; 339 gridBagConstraints4.gridy = -1; 340 GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); 341 gridBagConstraints3.fill = GridBagConstraints.VERTICAL; 342 gridBagConstraints3.gridy = -1; 343 gridBagConstraints3.weightx = 1.0; 344 gridBagConstraints3.anchor = GridBagConstraints.WEST; 345 gridBagConstraints3.gridx = -1; 346 GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); 347 gridBagConstraints2.gridx = -1; 348 gridBagConstraints2.anchor = GridBagConstraints.WEST; 349 gridBagConstraints2.gridy = -1; 350 jPanelPreviousNext = new JPanel(); 351 jPanelPreviousNext.setLayout(new GridBagLayout()); 352 jPanelPreviousNext.add(getJButtonPrevious(), gridBagConstraints2); 353 jPanelPreviousNext.add(getJSpinnerTimeStep(), gridBagConstraints3); 354 jPanelPreviousNext.add(getJButtonNext(), gridBagConstraints4); 355 } 356 return jPanelPreviousNext; 357 } 358 359 /** 360 * This method initializes jButtonPause 361 * 362 * @return javax.swing.JButton 363 */ 364 private JButton getJButtonPause() { 365 if (jButtonPause == null) { 366 jButtonPause = new JButton(MainWindow.instance.getAction(MainWindow.ACTION_KEY_PAUSE)); 367 jButtonPause.setText(""); 368 } 369 return jButtonPause; 370 } 371 372 /** 373 * Method getTimeStep. 374 * <br><b>Summary:</b><br> 375 * This method return the selected time step. 376 * @return int The selected time step. 377 */ 378 protected int getTimeStep(){ 379 //The result of the method. 380 int result = 10; 381 //get the selected value in the JSPinner. 382 result = ((Integer) getJSpinnerTimeStep().getValue()).intValue(); 383 //return the result 384 return result; 385 } 386 }