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