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