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.GridLayout;
021    import java.awt.event.ActionEvent;
022    import java.awt.event.ActionListener;
023    
024    import javax.swing.BorderFactory;
025    import javax.swing.JButton;
026    import javax.swing.JPanel;
027    import javax.swing.JRadioButton;
028    
029    import sears.tools.SearsResourceBundle;
030    
031    /**
032     * Class JDialogChainRepair.
033     * <br><b>Summary:</b><br>
034     * This class represent the dialog wich permit to apply various repair actions at once. 
035     */
036    public class JDialogChainRepair extends SearsJDialog {
037        private static final long serialVersionUID = -917472366618451891L;
038        private static final int ACTION_NUMBER = 4;
039        private JPanel jContentPane = null;
040        private JPanel jPanelCenter = null;
041        private JRadioButton jRadioAccentRepair = null;
042        private JRadioButton jRadioHtmlRepair = null;
043        private JRadioButton jRadioOrderRepair = null;
044        private JRadioButton jRadioTimeRepair = null;
045    
046        private JButton jButtonSelectAll = null;
047        private JButton jButtonApply = null;
048    
049    
050        /**
051         * This is the default constructor
052         */
053        public JDialogChainRepair() {
054            super(SearsResourceBundle.getResource("chainRepair_title"));
055            setContentPane(getJContentPane());
056            configureSize();
057        }
058        
059        /**
060         * This method initializes jContentPane
061         * 
062         * @return javax.swing.JPanel
063         */
064        private JPanel getJContentPane() {
065            if (jContentPane == null) {
066                jContentPane = new JPanel();
067                jContentPane.setLayout(new BorderLayout());
068                jContentPane.setBorder(super.createEmptyBorder());
069                jContentPane.add(getJPanelCenter(), java.awt.BorderLayout.CENTER);
070                jContentPane.add(getJPanelButtons(), java.awt.BorderLayout.SOUTH);
071            }
072            return jContentPane;
073        }
074    
075        /**
076         * This method initializes jPanel   
077         *  
078         * @return javax.swing.JPanel       
079         */
080        private JPanel getJPanelCenter() {
081            if (jPanelCenter == null) {
082                jPanelCenter = new JPanel();
083                jPanelCenter.setLayout(new GridLayout(2,2));
084                jPanelCenter.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), SearsResourceBundle.getResource("chainRepair_borderTitle")));
085                jPanelCenter.add(getJRadioAccentRepair(), null);
086                jPanelCenter.add(getJRadioHtmlRepair(), null);
087                jPanelCenter.add(getJRadioOrderRepair(), null);
088                jPanelCenter.add(getJRadioTimeRepair(), null);
089            }
090            return jPanelCenter;
091        }
092    
093        /**
094         * This method initializes jRadioButton     
095         *  
096         * @return javax.swing.JRadioButton 
097         */
098        private JRadioButton getJRadioAccentRepair() {
099            if (jRadioAccentRepair == null) {
100                jRadioAccentRepair = new JRadioButton();
101                jRadioAccentRepair.setText(SearsResourceBundle.getResource("AccentRepairName"));
102                jRadioAccentRepair.setToolTipText(SearsResourceBundle.getResource("AccentRepairTip"));
103            }
104            return jRadioAccentRepair;
105        }
106    
107        /**
108         * This method initializes jRadioButton     
109         *  
110         * @return javax.swing.JRadioButton 
111         */
112        private JRadioButton getJRadioHtmlRepair() {
113            if (jRadioHtmlRepair == null) {
114                jRadioHtmlRepair = new JRadioButton();
115                jRadioHtmlRepair.setText(SearsResourceBundle.getResource("HtmlRepairName"));
116                jRadioHtmlRepair.setToolTipText(SearsResourceBundle.getResource("HtmlRepairTip"));
117            }
118            return jRadioHtmlRepair;
119        }
120    
121        /**
122         * This method initializes jRadioButton     
123         *  
124         * @return javax.swing.JRadioButton 
125         */
126        private JRadioButton getJRadioOrderRepair() {
127            if (jRadioOrderRepair == null) {
128                jRadioOrderRepair = new JRadioButton();
129                jRadioOrderRepair.setText(SearsResourceBundle.getResource("OrderRepairName"));
130                jRadioOrderRepair.setToolTipText(SearsResourceBundle.getResource("OrderRepairTip"));
131            }
132            return jRadioOrderRepair;
133        }
134    
135        /**
136         * This method initializes jRadioButton     
137         *  
138         * @return javax.swing.JRadioButton 
139         */
140        private JRadioButton getJRadioTimeRepair() {
141            if (jRadioTimeRepair == null) {
142                jRadioTimeRepair = new JRadioButton();
143                jRadioTimeRepair.setText(SearsResourceBundle.getResource("TimeRepairName"));
144                jRadioTimeRepair.setToolTipText(SearsResourceBundle.getResource("TimeRepairTip"));
145            }
146            return jRadioTimeRepair;
147        }
148    
149        /**
150         * This method initializes jPanel   
151         *  
152         * @return javax.swing.JPanel       
153         */
154        protected JPanel getJPanelButtons() {
155            if (jPanelButtons == null) {
156                jPanelButtons = new JPanel();
157                jPanelButtons.add(getJButtonSelectAll(), null);
158                jPanelButtons.add(getJButtonApply(), null);
159                jPanelButtons.add(getJButtonCancel(), null);
160            }
161            return jPanelButtons;
162        }
163    
164        /**
165         * This method initializes jButton  
166         *  
167         * @return javax.swing.JButton      
168         */
169        private JButton getJButtonSelectAll() {
170            if (jButtonSelectAll == null) {
171                jButtonSelectAll = new JButton();
172                jButtonSelectAll.setText(SearsResourceBundle.getResource("button_selectAll"));
173                jButtonSelectAll.addActionListener(new ActionListener() {
174                    public void actionPerformed(ActionEvent e) {
175                        selectAllAction();
176                    }
177                });
178            }
179            return jButtonSelectAll;
180        }
181    
182        /**
183         * Method selectAllAction.
184         * <br><b>Summary:</b><br>
185         * Select all actions.
186         */
187        protected void selectAllAction() {
188            //Just select the radioButtons.
189            boolean[] selection = new boolean[ACTION_NUMBER];
190            for (int i = 0; i < selection.length; i++) {
191                selection[i] = true;
192            }
193            selectActions(selection);
194        }
195    
196        /**
197         * Method selectActions.
198         * <br><b>Summary:</b><br>
199         * This method select the action, using the given boolean array.
200         * @param selection     A boolean array which represent: [Accent, Html, Order, Time] 
201         */
202        private void selectActions(boolean[] selection) {
203            getJRadioAccentRepair().setSelected(selection[0]);
204            getJRadioHtmlRepair().setSelected(selection[1]);
205            getJRadioOrderRepair().setSelected(selection[2]);
206            getJRadioTimeRepair().setSelected(selection[3]);
207        }
208    
209        /**
210         * This method initializes jButton  
211         *  
212         * @return javax.swing.JButton      
213         */
214        private JButton getJButtonApply() {
215            if (jButtonApply == null) {
216                jButtonApply = new JButton();
217                jButtonApply.setText(SearsResourceBundle.getResource("button_apply"));
218                jButtonApply.addActionListener(new ActionListener() {
219                    public void actionPerformed(ActionEvent e) {
220                        okAction();
221                    }
222                });
223            }
224            return jButtonApply;
225        }
226    
227    
228        /**
229         * Method getResult.
230         * <br><b>Summary:</b><br>
231         * This method return the repair actions array that has been choosen
232         *  [Accent, Html, Order, Time] 
233         * @return <b>boolean[]</b>     The repair actions array that has been choosen [Accent, Html, Order, Time] 
234         */
235        public boolean[] getResult() {
236            //The result
237            boolean[] result = new boolean[ACTION_NUMBER];
238            //set false by default.
239            for (int i = 0; i < result.length; i++) {
240                result[i] = false;
241            }
242            //check if user validates result.
243            if(validationStatus){
244                result[0] = getJRadioAccentRepair().isSelected();
245                result[1] = getJRadioHtmlRepair().isSelected();
246                result[2] = getJRadioOrderRepair().isSelected();
247                result[3] = getJRadioTimeRepair().isSelected();
248            }
249            return result;
250        }
251        
252        /* (non-Javadoc)
253         * @see sears.gui.SearsJDialog#getDialogName()
254         */
255        protected String getDialogName() {
256            return "chainRepair";
257        }
258    }