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 019 import java.awt.BorderLayout; 020 import java.awt.CardLayout; 021 import java.awt.GridBagConstraints; 022 import java.awt.GridBagLayout; 023 import java.awt.event.ActionEvent; 024 import java.awt.event.ActionListener; 025 import java.io.File; 026 import java.io.FilenameFilter; 027 import java.util.Locale; 028 029 import javax.swing.JButton; 030 import javax.swing.JCheckBox; 031 import javax.swing.JComboBox; 032 import javax.swing.JLabel; 033 import javax.swing.JPanel; 034 import javax.swing.JTabbedPane; 035 import javax.swing.JTextField; 036 import javax.swing.UIManager; 037 038 import sears.gui.resources.SearsResources; 039 import sears.tools.SearsProperties; 040 import sears.tools.SearsResourceBundle; 041 import sears.tools.Updater; 042 import sears.tools.player.VLCPlayer; 043 044 /** 045 * Class JDialogOptions. 046 * <br><b>Summary:</b><br> 047 * This is the dialog options that permit to change the Sears options. 048 */ 049 public class JDialogOptions extends SearsJDialog { 050 private static final long serialVersionUID = 1L; 051 052 private JTabbedPane jTabbedPaneOptions = null; 053 054 private JPanel jPanelMain = null; 055 056 private JPanel jPanelPlayer = null; 057 058 private JLabel jLabelLang = null; 059 060 private JComboBox jComboBoxLang = null; 061 062 private JLabel jLabelLookAndFeel = null; 063 064 private JComboBox jComboBoxLookAndFeel = null; 065 066 private JCheckBox jCheckBoxDOSLineSeparator = null; 067 068 private JLabel jLabelPlayer = null; 069 070 private JComboBox jComboBoxPlayer = null; 071 072 private JPanel jTabbedPanePlayerOptions = null; 073 074 private CardLayout jTabbedPanePlayerOptionsCardLayout = null; 075 076 private JPanel jPanelVLCOptions = null; 077 078 private JLabel jLabelVLCPath = null; 079 080 private JTextField jTextFieldVLCPath = null; 081 082 private JButton jButtonVLCBrowse = null; 083 084 private JPanel jPanelOtherPlayerOptions = null; 085 086 private JLabel jLabelOtherPlayerPath = null; 087 088 private JTextField jTextFieldOtherPlayerPath = null; 089 090 private JButton jButtonOtherPlayerBrowse = null; 091 092 private JCheckBox jCheckBoxCheckForUpdates = null; 093 094 private JCheckBox jCheckBoxVlcRestart = null; 095 096 private JComboBox jComboBoxIConSet = null; 097 098 private JLabel jLabelIconSet = null; 099 100 /** 101 * Constructor JDialogOptions. 102 * <br><b>Summary:</b><br> 103 * Constructor of the class. 104 */ 105 public JDialogOptions() { 106 super(SearsResourceBundle.getResource("option_title")); 107 initialize(); 108 configureSize(); 109 } 110 111 /** 112 * This method initializes this 113 * 114 * @return void 115 */ 116 private void initialize() { 117 getContentPane().add(getJPanelButtons(), BorderLayout.SOUTH); 118 getContentPane().add(getJTabbedPaneOptions(), BorderLayout.CENTER); 119 } 120 121 /** 122 * This method initializes jTabbedPaneOptions 123 * 124 * @return javax.swing.JTabbedPane 125 */ 126 private JTabbedPane getJTabbedPaneOptions() { 127 if (jTabbedPaneOptions == null) { 128 jTabbedPaneOptions = new JTabbedPane(); 129 jTabbedPaneOptions.addTab(SearsResourceBundle.getResource("option_mainTab"), null, getJPanelMain(), 130 SearsResourceBundle.getResource("option_mainTabTip")); 131 jTabbedPaneOptions.addTab(SearsResourceBundle.getResource("option_playerTab"), null, getJPanelPlayer(), 132 SearsResourceBundle.getResource("option_playerTabTip")); 133 } 134 return jTabbedPaneOptions; 135 } 136 137 /** 138 * This method initializes jPanelMain 139 * 140 * @return javax.swing.JPanel 141 */ 142 private JPanel getJPanelMain() { 143 if (jPanelMain == null) { 144 GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); 145 gridBagConstraints7.gridx = 0; 146 gridBagConstraints7.anchor = GridBagConstraints.WEST; 147 gridBagConstraints7.gridy = 2; 148 GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); 149 gridBagConstraints6.gridx = 1; 150 gridBagConstraints6.fill = GridBagConstraints.BOTH; 151 gridBagConstraints6.anchor = GridBagConstraints.WEST; 152 gridBagConstraints6.gridwidth = 1; 153 gridBagConstraints6.gridy =2; 154 GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); 155 gridBagConstraints5.gridx = 0; 156 gridBagConstraints5.anchor = GridBagConstraints.WEST; 157 gridBagConstraints5.gridwidth = 2; 158 gridBagConstraints5.gridy =4; 159 GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); 160 gridBagConstraints4.gridx = 0; 161 gridBagConstraints4.anchor = GridBagConstraints.WEST; 162 gridBagConstraints4.gridwidth = 2; 163 gridBagConstraints4.gridy = 3; 164 GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); 165 gridBagConstraints3.fill = GridBagConstraints.BOTH; 166 gridBagConstraints3.gridy = 1; 167 gridBagConstraints3.weightx = 1.0; 168 gridBagConstraints3.gridx = 1; 169 GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); 170 gridBagConstraints2.gridx = 0; 171 gridBagConstraints2.anchor = GridBagConstraints.WEST; 172 gridBagConstraints2.gridy = 1; 173 jLabelLookAndFeel = new JLabel(); 174 jLabelLookAndFeel.setText(SearsResourceBundle.getResource("option_lookAndFeelLabel")); 175 GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); 176 gridBagConstraints1.fill = GridBagConstraints.BOTH; 177 gridBagConstraints1.gridy = 0; 178 gridBagConstraints1.weightx = 1.0; 179 gridBagConstraints1.gridx = 1; 180 GridBagConstraints gridBagConstraints = new GridBagConstraints(); 181 gridBagConstraints.gridx = 0; 182 gridBagConstraints.anchor = GridBagConstraints.WEST; 183 gridBagConstraints.gridy = 0; 184 jLabelLang = new JLabel(); 185 jLabelLang.setText(SearsResourceBundle.getResource("option_languageLabel")); 186 jPanelMain = new JPanel(); 187 jPanelMain.setLayout(new GridBagLayout()); 188 jPanelMain.add(jLabelLang, gridBagConstraints); 189 jPanelMain.add(getJComboBoxLang(), gridBagConstraints1); 190 jPanelMain.add(jLabelLookAndFeel, gridBagConstraints2); 191 jPanelMain.add(getJComboBoxLookAndFeel(), gridBagConstraints3); 192 jPanelMain.add(getJLabelIconSet(), gridBagConstraints7); 193 jPanelMain.add(getJComboBoxIconSet(), gridBagConstraints6); 194 jPanelMain.add(getJCheckBoxDOSLineSeparator(), gridBagConstraints4); 195 jPanelMain.add(getJCheckBoxCheckForUpdates(), gridBagConstraints5); 196 } 197 return jPanelMain; 198 } 199 200 /** 201 * Method getJComboBoxIconSet. 202 * <br><b>Summary:</b><br> 203 * @TODO complete summary 204 * @return (<b>JComboBox</b>) A JComboBox. 205 */ 206 private JComboBox getJComboBoxIconSet() { 207 if(jComboBoxIConSet == null){ 208 //Construct the comboBox. 209 jComboBoxIConSet = new JComboBox(); 210 //To construct the combobox of the available icon set, we need to know where is the icons folder. 211 String iconFolder = SearsResources.getIconFolder(); 212 if(iconFolder != null){ 213 //Now that we have icon folder, parse the folder to retrieve all jar files in it. 214 //which are the icon sets. 215 File iconFolderFile = new File(iconFolder); 216 if( iconFolderFile.exists() && iconFolderFile.isDirectory()){ 217 String[] iconSetsArray = iconFolderFile.list(new FilenameFilter() { 218 public boolean accept(File dir, String name) { 219 return name.endsWith(".jar"); 220 } 221 }); 222 //parse them, and add them to ComboBox 223 for (int i = 0; i < iconSetsArray.length; i++) { 224 String currentIconSet = iconSetsArray[i]; 225 jComboBoxIConSet.addItem(currentIconSet); 226 } 227 } 228 //Set the current one as selected item. 229 jComboBoxIConSet.setSelectedItem(SearsProperties.getProperty(SearsProperties.ICON_SET, SearsProperties.DEFAULT_ICON_SET)); 230 } 231 } 232 return jComboBoxIConSet; 233 } 234 235 /** 236 * Method getJLabelIconSet. 237 * <br><b>Summary:</b><br> 238 * This method returns the JLabel used for the iconSets. 239 * @return (<b>JLabel</b>) the JLabel used for the iconSets. 240 */ 241 private JLabel getJLabelIconSet() { 242 if(jLabelIconSet == null){ 243 jLabelIconSet = new JLabel(SearsResourceBundle.getResource("option_iconSetLabel")); 244 jLabelIconSet.setToolTipText(SearsResourceBundle.getResource("option_iconSetLabelTip")); 245 } 246 return jLabelIconSet; 247 } 248 249 /** 250 * Method getJCheckBoxCheckForUpdates. 251 * <br><b>Summary:</b><br> 252 * Cosntruct the JCheckBox to choose wether look for updates or not. 253 * @return JCheckBox The JCheckBox of check for update. 254 */ 255 private JCheckBox getJCheckBoxCheckForUpdates() { 256 if (jCheckBoxCheckForUpdates == null) { 257 jCheckBoxCheckForUpdates = new JCheckBox(); 258 jCheckBoxCheckForUpdates.setText(SearsResourceBundle.getResource("option_checkForUpdates")); 259 jCheckBoxCheckForUpdates.setToolTipText(SearsResourceBundle.getResource("option_checkForUpdatesTip")); 260 //get the previous check box state. 261 String previousCheckForUpdates = SearsProperties.getProperty(SearsProperties.UPDATE_ADDRESS, Updater.DEFAULT_UPDATE_ADDRESS); 262 //check the box only if property is not "" 263 jCheckBoxCheckForUpdates.setSelected(!previousCheckForUpdates.equals("")); 264 } 265 return jCheckBoxCheckForUpdates; 266 } 267 268 /** 269 * This method initializes jPanelPlayer 270 * 271 * @return javax.swing.JPanel 272 */ 273 private JPanel getJPanelPlayer() { 274 if (jPanelPlayer == null) { 275 GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); 276 gridBagConstraints9.fill = GridBagConstraints.BOTH; 277 gridBagConstraints9.gridy = 4; 278 gridBagConstraints9.weightx = 1.0; 279 gridBagConstraints9.weighty = 1.0; 280 gridBagConstraints9.gridwidth = 2; 281 gridBagConstraints9.gridheight = 4; 282 gridBagConstraints9.gridx = 0; 283 GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); 284 gridBagConstraints8.gridx = 0; 285 gridBagConstraints8.fill = GridBagConstraints.BOTH; 286 gridBagConstraints8.gridy = 1; 287 GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); 288 gridBagConstraints7.fill = GridBagConstraints.BOTH; 289 gridBagConstraints7.gridy = 0; 290 gridBagConstraints7.weightx = 1.0; 291 gridBagConstraints7.gridx = 1; 292 GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); 293 gridBagConstraints6.fill = GridBagConstraints.BOTH; 294 gridBagConstraints6.gridy = 1; 295 gridBagConstraints6.weightx = 1.0; 296 gridBagConstraints6.gridx = 0; 297 GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); 298 gridBagConstraints5.gridx = 0; 299 gridBagConstraints5.anchor = GridBagConstraints.WEST; 300 gridBagConstraints5.gridy = 0; 301 jLabelPlayer = new JLabel(); 302 jLabelPlayer.setText(SearsResourceBundle.getResource("option_playerLabel")); 303 jLabelPlayer.setToolTipText(SearsResourceBundle.getResource("option_playerLabelTip")); 304 jPanelPlayer = new JPanel(); 305 jPanelPlayer.setLayout(new GridBagLayout()); 306 jPanelPlayer.add(jLabelPlayer, gridBagConstraints5); 307 //Call this method before constructing comboboxPlayer , in order to avoid NPE. 308 getJTabbedPanePlayerOptions(); 309 jPanelPlayer.add(getJComboBoxPlayer(), gridBagConstraints7); 310 jPanelPlayer.add(getJTabbedPanePlayerOptions(), gridBagConstraints9); 311 } 312 return jPanelPlayer; 313 } 314 315 /** 316 * This method initializes jComboBoxLang 317 * 318 * @return javax.swing.JComboBox 319 */ 320 private JComboBox getJComboBoxLang() { 321 if (jComboBoxLang == null) { 322 String[] languages = new String[] { "en_US", "fr_FR", "it_IT", "nl_NL" }; 323 jComboBoxLang = new JComboBox(languages); 324 //get the previous selected locale. 325 String previousLocale = SearsProperties.getProperty(SearsProperties.LANGUAGE, "en")+"_"+SearsProperties.getProperty(SearsProperties.COUNTRY, "US"); 326 jComboBoxLang.setSelectedItem(previousLocale); 327 } 328 return jComboBoxLang; 329 } 330 331 /** 332 * This method initializes jComboBoxLookAndFeel 333 * 334 * @return javax.swing.JComboBox 335 */ 336 private JComboBox getJComboBoxLookAndFeel() { 337 if (jComboBoxLookAndFeel == null) { 338 String[] lookAndFeels = new String[] { "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", 339 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel", 340 "com.sun.java.swing.plaf.motif.MotifLookAndFeel", UIManager.getSystemLookAndFeelClassName() }; 341 jComboBoxLookAndFeel = new JComboBox(lookAndFeels); 342 //Get the previous selected look and feel. 343 String previousLookAndFeel = SearsProperties.getProperty(SearsProperties.LOOK_AND_FEEL, UIManager 344 .getSystemLookAndFeelClassName()); 345 //set the comboBox with this look and feel. 346 jComboBoxLookAndFeel.setSelectedItem(previousLookAndFeel); 347 } 348 return jComboBoxLookAndFeel; 349 } 350 351 /** 352 * This method initializes jCheckBoxDOSLineSeparator 353 * 354 * @return javax.swing.JCheckBox 355 */ 356 private JCheckBox getJCheckBoxDOSLineSeparator() { 357 if (jCheckBoxDOSLineSeparator == null) { 358 jCheckBoxDOSLineSeparator = new JCheckBox(); 359 jCheckBoxDOSLineSeparator.setText(SearsResourceBundle.getResource("option_useDOSLineSeparator")); 360 jCheckBoxDOSLineSeparator.setToolTipText(SearsResourceBundle.getResource("option_useDOSLineSeparatorTip")); 361 //get the previous check box state. 362 String previousDOSLineSeparator = SearsProperties.getProperty(SearsProperties.DOS_LINE_SEPARATOR, "0"); 363 //check the box only if property is not "0" 364 jCheckBoxDOSLineSeparator.setSelected(!previousDOSLineSeparator.equals("0")); 365 } 366 return jCheckBoxDOSLineSeparator; 367 } 368 369 /** 370 * This method initializes jComboBoxPlayer 371 * 372 * @return javax.swing.JComboBox 373 */ 374 private JComboBox getJComboBoxPlayer() { 375 if (jComboBoxPlayer == null) { 376 //construct teh comboBox that permit player's choice. 377 String[] players = new String[2]; 378 players[SearsProperties.KEY_VLC] = SearsResourceBundle.getResource("option_vlcChoice"); 379 players[SearsProperties.KEY_OTHER] = SearsResourceBundle.getResource("option_otherPlayerChoice"); 380 jComboBoxPlayer = new JComboBox(players); 381 //When user choose a player, switch panels. 382 jComboBoxPlayer.addActionListener(new ActionListener() { 383 public void actionPerformed(ActionEvent e) { 384 playerChoosed(); 385 } 386 }); 387 //get the previous selected property. 388 String previousPlayer = SearsProperties.getProperty(SearsProperties.PLAYER_SELECTED, SearsResourceBundle 389 .getResource("option_vlcChoice")); 390 //select the previous player 391 try{ 392 jComboBoxPlayer.setSelectedIndex(Integer.parseInt(previousPlayer)); 393 }catch(NumberFormatException e){ 394 //There is an error in the selected player property. 395 //put VLC to correct the pb. 396 jComboBoxPlayer.setSelectedIndex(SearsProperties.KEY_VLC); 397 SearsProperties.setProperty(SearsProperties.PLAYER_SELECTED, ""+SearsProperties.KEY_VLC); 398 } 399 } 400 return jComboBoxPlayer; 401 } 402 403 /** 404 * Method playerChoosed. 405 * <br><b>Summary:</b><br> 406 * This method is called when user choose a player. 407 * It changes the upper panel, using cardPanel show feature. 408 */ 409 protected void playerChoosed() { 410 //retrieve the selected index for the player. 411 jTabbedPanePlayerOptionsCardLayout.show(jTabbedPanePlayerOptions, "" + jComboBoxPlayer.getSelectedIndex()); 412 } 413 414 /** 415 * This method initializes jTabbedPanePlayerOptions 416 * 417 * @return javax.swing.JTabbedPane 418 */ 419 private JPanel getJTabbedPanePlayerOptions() { 420 if (jTabbedPanePlayerOptions == null) { 421 jTabbedPanePlayerOptionsCardLayout = new CardLayout(); 422 jTabbedPanePlayerOptions = new JPanel(jTabbedPanePlayerOptionsCardLayout); 423 jTabbedPanePlayerOptions.add(getJPanelVLCOptions(), "" + SearsProperties.KEY_VLC); 424 jTabbedPanePlayerOptions.add(getJPanelOtherPlayerOptions(), "" + SearsProperties.KEY_OTHER); 425 } 426 return jTabbedPanePlayerOptions; 427 } 428 429 /** 430 * This method initializes jPanelVLCOptions 431 * 432 * @return javax.swing.JPanel 433 */ 434 private JPanel getJPanelVLCOptions() { 435 if (jPanelVLCOptions == null) { 436 GridBagConstraints gridBagConstraints13 = new GridBagConstraints(); 437 gridBagConstraints13.gridx = 0; 438 gridBagConstraints13.anchor = GridBagConstraints.WEST; 439 gridBagConstraints13.gridy = 3; 440 GridBagConstraints gridBagConstraints12 = new GridBagConstraints(); 441 gridBagConstraints12.gridx = 1; 442 gridBagConstraints12.anchor = GridBagConstraints.EAST; 443 gridBagConstraints12.gridy = 0; 444 GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); 445 gridBagConstraints11.fill = GridBagConstraints.BOTH; 446 gridBagConstraints11.gridy = 1; 447 gridBagConstraints11.weightx = 1.0; 448 gridBagConstraints11.gridwidth = 2; 449 gridBagConstraints11.gridx = 0; 450 GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); 451 gridBagConstraints10.gridx = 0; 452 gridBagConstraints10.anchor = GridBagConstraints.WEST; 453 gridBagConstraints10.gridy = 0; 454 jLabelVLCPath = new JLabel(); 455 jLabelVLCPath.setText(SearsResourceBundle.getResource("option_vlcPathLabel")); 456 jPanelVLCOptions = new JPanel(); 457 jPanelVLCOptions.setLayout(new GridBagLayout()); 458 jPanelVLCOptions.add(jLabelVLCPath, gridBagConstraints10); 459 jPanelVLCOptions.add(getJTextFieldVLCPath(), gridBagConstraints11); 460 jPanelVLCOptions.add(getJButtonVLCBrowse(), gridBagConstraints12); 461 jPanelVLCOptions.add(getJCheckBoxVlcRestart(), gridBagConstraints13); 462 } 463 return jPanelVLCOptions; 464 } 465 466 /** 467 * This method initializes jPanelVLCOptions 468 * 469 * @return javax.swing.JPanel 470 */ 471 private JPanel getJPanelOtherPlayerOptions() { 472 if (jPanelOtherPlayerOptions == null) { 473 GridBagConstraints gridBagConstraints12 = new GridBagConstraints(); 474 gridBagConstraints12.gridx = 1; 475 gridBagConstraints12.anchor = GridBagConstraints.EAST; 476 gridBagConstraints12.gridy = 0; 477 GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); 478 gridBagConstraints11.fill = GridBagConstraints.BOTH; 479 gridBagConstraints11.gridy = 1; 480 gridBagConstraints11.weightx = 1.0; 481 gridBagConstraints11.gridwidth = 2; 482 gridBagConstraints11.gridx = 0; 483 GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); 484 gridBagConstraints10.gridx = 0; 485 gridBagConstraints10.anchor = GridBagConstraints.WEST; 486 gridBagConstraints10.gridy = 0; 487 jLabelOtherPlayerPath = new JLabel(); 488 jLabelOtherPlayerPath.setText(SearsResourceBundle.getResource("option_otherPlayerPathLabel")); 489 jLabelOtherPlayerPath.setToolTipText(SearsResourceBundle.getResource("option_otherPlayerPathTip")); 490 jPanelOtherPlayerOptions = new JPanel(); 491 jPanelOtherPlayerOptions.setLayout(new GridBagLayout()); 492 jPanelOtherPlayerOptions.add(jLabelOtherPlayerPath, gridBagConstraints10); 493 jPanelOtherPlayerOptions.add(getJTextFieldOtherPlayerPath(), gridBagConstraints11); 494 jPanelOtherPlayerOptions.add(getJButtonOtherPlayerBrowse(), gridBagConstraints12); 495 } 496 return jPanelOtherPlayerOptions; 497 } 498 499 /** 500 * This method initializes jTextFieldOtherPlayerPath 501 * 502 * @return javax.swing.JTextField 503 */ 504 private JTextField getJTextFieldOtherPlayerPath() { 505 if (jTextFieldOtherPlayerPath == null) { 506 jTextFieldOtherPlayerPath = new JTextField(); 507 //get the previous selected PATH 508 String previousPath = SearsProperties.getProperty(SearsProperties.PLAYER_FULL_PATH, "/usr/bin/mplayer %f% -sub %s%"); 509 //set it in the text field. 510 jTextFieldOtherPlayerPath.setText(previousPath); 511 jTextFieldOtherPlayerPath.setToolTipText(SearsResourceBundle.getResource("option_otherPlayerPathTip")); 512 } 513 return jTextFieldOtherPlayerPath; 514 } 515 516 /** 517 * This method initializes jButtonOtherPlayerBrowse 518 * 519 * @return javax.swing.JButton 520 */ 521 private JButton getJButtonOtherPlayerBrowse() { 522 if (jButtonOtherPlayerBrowse == null) { 523 jButtonOtherPlayerBrowse = new JButton(SearsResources.getIcon("BrowseIcon")); 524 jButtonOtherPlayerBrowse.addActionListener(new ActionListener() { 525 public void actionPerformed(ActionEvent e) { 526 showPlayerBrowser(SearsProperties.KEY_OTHER); 527 } 528 }); 529 } 530 return jButtonOtherPlayerBrowse; 531 } 532 533 /** 534 * This method initializes jTextFieldVLCPath 535 * 536 * @return javax.swing.JTextField 537 */ 538 private JTextField getJTextFieldVLCPath() { 539 if (jTextFieldVLCPath == null) { 540 jTextFieldVLCPath = new JTextField(); 541 //get the previous selected PATH 542 String vlcPath = SearsProperties.getProperty(SearsProperties.PLAYER_FULL_PATH, ""); 543 //In order to make vlc path easy to enter, at first launch try to fill it in function of the system. 544 //At first launch vlc_path is empty 545 if(vlcPath == null || vlcPath.equals("")){ 546 String osName = System.getProperty("os.name").toLowerCase(); 547 boolean isMacOSX = osName.startsWith("mac"); 548 boolean isWindows = osName.startsWith("windows"); 549 boolean isLinux = osName.startsWith("linux"); 550 if(isMacOSX){ 551 //vlcPath = VLCPlayer.DEFAULT_VLC_PATH_MAC; 552 vlcPath = ""; 553 }else if (isLinux){ 554 vlcPath = VLCPlayer.DEFAULT_VLC_PATH_LINUX; 555 }else if (isWindows){ 556 vlcPath = VLCPlayer.DEFAULT_VLC_PATH_WINDOWS; 557 } 558 } 559 //set it in the text field. 560 jTextFieldVLCPath.setText(vlcPath); 561 } 562 return jTextFieldVLCPath; 563 } 564 565 /** 566 * This method initializes jButtonVLCBrowse 567 * 568 * @return javax.swing.JButton 569 */ 570 private JButton getJButtonVLCBrowse() { 571 if (jButtonVLCBrowse == null) { 572 jButtonVLCBrowse = new JButton(SearsResources.getIcon("BrowseIcon")); 573 jButtonVLCBrowse.addActionListener(new ActionListener() { 574 public void actionPerformed(ActionEvent e) { 575 showPlayerBrowser(SearsProperties.KEY_VLC); 576 } 577 }); 578 } 579 return jButtonVLCBrowse; 580 } 581 582 /** 583 * Method getJCheckBoxVlcRestart. 584 * <br><b>Summary:</b><br> 585 * Construct the JCheckBox to choose wether the VLC must be restart at each play command. 586 * @return JCheckBox The JCheckBox of restart VLC. 587 */ 588 private JCheckBox getJCheckBoxVlcRestart() { 589 if (jCheckBoxVlcRestart == null) { 590 jCheckBoxVlcRestart = new JCheckBox(); 591 jCheckBoxVlcRestart.setText(SearsResourceBundle.getResource("option_restartVLC")); 592 jCheckBoxVlcRestart.setToolTipText(SearsResourceBundle.getResource("option_restartVLCTip")); 593 //get the previous check box state. 594 String previousVlcRestart = SearsProperties.getProperty(SearsProperties.VLC_RESTART, VLCPlayer.DEFAULT_VLC_RESTART); 595 //check the box only if property is not "0" 596 jCheckBoxVlcRestart.setSelected(!previousVlcRestart.equals("0")); 597 } 598 return jCheckBoxVlcRestart; 599 } 600 601 /** 602 * Method showPlayerBrowser. 603 * <br><b>Summary:</b><br> 604 * This method show up a file chooser, and set the corresponding player path property. 605 * @param playerKey The key of the player. 606 */ 607 protected void showPlayerBrowser(int playerKey) { 608 //Display a fileChooser. 609 File choosenPlayer = MainWindow.instance.showBrowser(null); 610 if (choosenPlayer != null) { 611 //construct the full path to player executable. 612 String fullPath = choosenPlayer.getAbsolutePath(); 613 //now , set the property in the correct TextField. 614 //if the os system is Mac OS: 615 if(System.getProperty("mrj.version") != null){ 616 //we try to change fullPath: 617 String newFullPath; 618 try { 619 newFullPath = sears.tools.InfoPlist.getExecutablePath(fullPath); 620 } catch(Exception e){ 621 newFullPath = null; 622 } 623 624 // if we succeed: 625 if(newFullPath != null){ 626 fullPath = newFullPath; 627 } 628 //else we don't touch to fullPath, nothing more happens... 629 } 630 switch (playerKey) { 631 case SearsProperties.KEY_VLC: 632 jTextFieldVLCPath.setText(fullPath); 633 break; 634 case SearsProperties.KEY_OTHER: 635 jTextFieldOtherPlayerPath.setText(fullPath); 636 break; 637 } 638 } 639 } 640 641 /* (non-Javadoc) 642 * @see sears.gui.SearsJDialog#getDialogName() 643 */ 644 protected String getDialogName() { 645 return "options"; 646 } 647 648 /** 649 * Method getSelectedLanguage. 650 * <br><b>Summary:</b><br> 651 * Return the selected locale. 652 * @return <b>Locale</b> The selected Locale. 653 */ 654 protected Locale getSelectedLocale() { 655 //The result of the method. 656 Locale result = null; 657 //construct the locale. 658 String localeChoosen = (String) jComboBoxLang.getSelectedItem(); 659 String lang = localeChoosen.substring(0, localeChoosen.indexOf("_")); 660 String count = localeChoosen.substring(localeChoosen.indexOf("_")+1); 661 //set the result with the given language and country. 662 result = new Locale(lang, count); 663 return result; 664 } 665 666 /** 667 * Method getSelectedLookAndFeel. 668 * <br><b>Summary:</b><br> 669 * Return the selected LookAndFeel. 670 * @return <b>String</b> The selected LookAndFeel. 671 */ 672 protected String getSelectedLookAndFeel() { 673 return (String) jComboBoxLookAndFeel.getSelectedItem(); 674 } 675 676 /** 677 * Method getConfiguredPlayerPath. 678 * <br><b>Summary:</b><br> 679 * Return the configured executable. 680 * @return <b>String</b> The configured executable. 681 */ 682 protected String getConfiguredPlayerPath() { 683 //The result of the method. 684 String result = null; 685 //switch on the selected player. 686 switch (jComboBoxPlayer.getSelectedIndex()) { 687 case SearsProperties.KEY_VLC: 688 result = jTextFieldVLCPath.getText(); 689 break; 690 case SearsProperties.KEY_OTHER: 691 result = jTextFieldOtherPlayerPath.getText(); 692 break; 693 } 694 //return the result. 695 return result; 696 } 697 698 /** 699 * Method getSelectedPlayer. 700 * <br><b>Summary:</b><br> 701 * Return the configured player. 702 * @return <b>int</b> The configured player. 703 */ 704 protected int getSelectedPlayer() { 705 //return the result 706 return jComboBoxPlayer.getSelectedIndex(); 707 } 708 709 /** 710 * Method getSelectedDOSLineSeparator. 711 * <br><b>Summary:</b><br> 712 * return "0" if DOSLineSeparator has been checked, "1" otherwise. 713 * @return <b>String</b> "0" if DOSLineSeparator has been checked, "1" otherwise. 714 */ 715 public String getSelectedDOSLineSeparator() { 716 //The result of the method. 717 String result = null; 718 if(jCheckBoxDOSLineSeparator.isSelected()){ 719 result = "1"; 720 }else{ 721 result = "0"; 722 } 723 //return the result 724 return result; 725 } 726 727 /** 728 * Method getSelectedCheckForUpdates. 729 * <br><b>Summary:</b><br> 730 * return true if need to check for updates, false otherwise. 731 * @return <b>boolean</b> true if need to check for updates, false otherwise. 732 */ 733 public boolean getSelectedCheckForUpdates() { 734 return getJCheckBoxCheckForUpdates().isSelected(); 735 } 736 737 /** 738 * Method getSelectedVlcRestart. 739 * <br><b>Summary:</b><br> 740 * return "1" if VlcRestart has been checked, "0" otherwise. 741 * @return <b>String</b> "1" if VlcRestart has been checked, "0" otherwise. 742 */ 743 public String getSelectedVlcRestart() { 744 //The result of the method. 745 String result = null; 746 if(jCheckBoxVlcRestart.isSelected()){ 747 result = "1"; 748 }else{ 749 result = "0"; 750 } 751 //return the result 752 return result; 753 } 754 755 /** 756 * Method getSelectedIconSet. 757 * <br><b>Summary:</b><br> 758 * return the selected icon set jar file. 759 * @return String the selected icon set jarFile. 760 */ 761 public String getSelectedIconSet() { 762 return (String) jComboBoxIConSet.getSelectedItem(); 763 } 764 }