1 19 20 package org.netbeans.modules.tasklist.usertasks.options; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.text.DateFormat ; 25 import java.text.SimpleDateFormat ; 26 import java.util.Calendar ; 27 import java.util.prefs.Preferences ; 28 import javax.swing.JLabel ; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 31 import javax.swing.event.ListDataEvent ; 32 import javax.swing.event.ListDataListener ; 33 import org.jdesktop.layout.GroupLayout; 34 import org.netbeans.modules.tasklist.core.checklist.CheckList; 35 import org.netbeans.modules.tasklist.core.checklist.DefaultCheckListModel; 36 import org.netbeans.modules.tasklist.usertasks.util.TimeComboBox; 37 import org.openide.DialogDisplayer; 38 import org.openide.NotifyDescriptor; 39 import org.openide.util.NbBundle; 40 41 46 public class UTOptionsPanel extends javax.swing.JPanel implements ActionListener , 47 ListDataListener { 48 private TimeComboBox cbDayStart; 49 private TimeComboBox cbPauseStart; 50 private TimeComboBox cbPauseEnd; 51 private TimeComboBox cbDayEnd; 52 private CheckList clWorkingDays; 53 private boolean changed; 54 55 61 private static String i18n(String key) { 62 return NbBundle.getMessage(UTOptionsPanel.class, key); 63 } 64 65 68 public UTOptionsPanel() { 69 initComponents(); 70 jTextFieldFile.getDocument().addDocumentListener(new DocumentListener () { 71 public void changedUpdate(DocumentEvent e) { 72 fileChanged(); 73 } 74 public void insertUpdate(DocumentEvent e) { 75 fileChanged(); 76 } 77 public void removeUpdate(DocumentEvent e) { 78 fileChanged(); 79 } 80 }); 81 GroupLayout layout = new GroupLayout(jPanelWorkingHours); 82 jPanelWorkingHours.setLayout(layout); 83 layout.setAutocreateContainerGaps(true); 84 layout.setAutocreateGaps(true); 85 JLabel lDayStart = new JLabel (i18n("StartWorkingDay")); JLabel lPauseStart = new JLabel (i18n("StartPause")); JLabel lPauseEnd = new JLabel (i18n("EndPause")); JLabel lDayEnd = new JLabel (i18n("EndWorkingDay")); JLabel lWorkingDays = new JLabel (i18n("WorkingDays")); cbDayStart = new TimeComboBox(); 91 cbDayStart.addActionListener(this); 92 cbPauseStart = new TimeComboBox(); 93 cbPauseStart.addActionListener(this); 94 cbPauseEnd = new TimeComboBox(); 95 cbPauseEnd.addActionListener(this); 96 cbDayEnd = new TimeComboBox(); 97 cbDayEnd.addActionListener(this); 98 Calendar c = Calendar.getInstance(); 99 c.set(2006, 0, 2); String [] days = new String [7]; 101 DateFormat df = new SimpleDateFormat ("EEEE"); for (int i = 0; i < days.length; i++) { 103 days[i] = df.format(c.getTime()); 104 c.add(Calendar.DAY_OF_YEAR, 1); 105 } 106 DefaultCheckListModel m = new DefaultCheckListModel( 107 new boolean[7], days); 108 m.addListDataListener(this); 109 clWorkingDays = new CheckList(m); 110 GroupLayout.ParallelGroup hpg1 = layout.createParallelGroup(). 111 add(lDayStart).add(lPauseStart).add(lPauseEnd).add(lDayEnd). 112 add(lWorkingDays); 113 GroupLayout.ParallelGroup hpg2 = layout.createParallelGroup(). 114 add(cbDayStart).add(cbPauseStart).add(cbPauseEnd).add(cbDayEnd). 115 add(clWorkingDays); 116 GroupLayout.SequentialGroup hsg1 = layout.createSequentialGroup(). 117 add(hpg1).add(hpg2); 118 layout.setHorizontalGroup(hsg1); 119 GroupLayout.ParallelGroup vpg1 = 120 layout.createParallelGroup(GroupLayout.BASELINE). 121 add(lDayStart).add(cbDayStart); 122 GroupLayout.ParallelGroup vpg2 = 123 layout.createParallelGroup(GroupLayout.BASELINE). 124 add(lPauseStart).add(cbPauseStart); 125 GroupLayout.ParallelGroup vpg3 = 126 layout.createParallelGroup(GroupLayout.BASELINE). 127 add(lPauseEnd).add(cbPauseEnd); 128 GroupLayout.ParallelGroup vpg4 = 129 layout.createParallelGroup(GroupLayout.BASELINE). 130 add(lDayEnd).add(cbDayEnd); 131 GroupLayout.ParallelGroup vpg5 = 132 layout.createParallelGroup(GroupLayout.LEADING). 133 add(lWorkingDays).add(clWorkingDays); 134 GroupLayout.SequentialGroup vsg = layout.createSequentialGroup(). 135 add(vpg1).add(vpg2).add(vpg3).add(vpg4).add(vpg5); 136 layout.setVerticalGroup(vsg); 137 } 138 139 142 public void update() { 143 Settings s = Settings.getDefault(); 144 jCheckBoxAppend.setSelected(s.getAppend()); 145 jCheckBoxCollectWorkPeriods.setSelected(s.getCollectWorkPeriods()); 146 jTextFieldFile.setText(s.getFilename()); 147 jCheckBoxDetectInactivity.setSelected(s.getDetectInactivity()); 148 jCheckBoxAutoSwitchToComputed.setSelected(s.getAutoSwitchToComputed()); 149 cbDayStart.setTime(s.getWorkingDayStart()); 150 cbPauseStart.setTime(s.getPauseStart()); 151 cbPauseEnd.setTime(s.getPauseEnd()); 152 cbDayEnd.setTime(s.getWorkingDayEnd()); 153 boolean[] wd = s.getWorkingDays(); 154 DefaultCheckListModel m = 155 (DefaultCheckListModel) clWorkingDays.getModel(); 156 for (int i = 0; i < 7; i++) { 157 m.setChecked(i, wd[i]); 158 } 159 changed = false; 160 } 161 162 165 public void applyChanges() { 166 if (!changed) 167 return; 168 169 if (!isContentValid()) { 170 DialogDisplayer.getDefault().notify( 171 new NotifyDescriptor.Message(i18n( 172 "SettingValidationError"))); return; 174 } 175 176 Settings s = Settings.getDefault(); 177 s.setAppend(jCheckBoxAppend.isSelected()); 178 s.setCollectWorkPeriods(jCheckBoxCollectWorkPeriods.isSelected()); 179 s.setFilename(jTextFieldFile.getText()); 180 s.setDetectInactivity(jCheckBoxDetectInactivity.isSelected()); 181 s.setAutoSwitchToComputed(jCheckBoxAutoSwitchToComputed.isSelected()); 182 s.setWorkingDayStart(cbDayStart.getTime()); 183 s.setPauseStart(cbPauseStart.getTime()); 184 s.setPauseEnd(cbPauseEnd.getTime()); 185 s.setWorkingDayEnd(cbDayEnd.getTime()); 186 DefaultCheckListModel m = 187 (DefaultCheckListModel) clWorkingDays.getModel(); 188 for (int i = 0; i < 7; i++) { 189 s.setWorkingDay(i, m.isChecked(i)); 190 } 191 } 192 193 196 public void cancel() { 197 198 } 199 200 203 private void fileChanged() { 204 changed = true; 205 } 206 207 212 public boolean isChanged() { 213 return changed; 214 } 215 216 222 private void initComponents() { 224 225 jCheckBoxAppend = new javax.swing.JCheckBox (); 226 jCheckBoxCollectWorkPeriods = new javax.swing.JCheckBox (); 227 jLabel3 = new javax.swing.JLabel (); 228 jTextFieldFile = new javax.swing.JTextField (); 229 jPanelWorkingHours = new javax.swing.JPanel (); 230 jCheckBoxDetectInactivity = new javax.swing.JCheckBox (); 231 jCheckBoxAutoSwitchToComputed = new javax.swing.JCheckBox (); 232 233 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxAppend, org.openide.util.NbBundle.getMessage(UTOptionsPanel.class, "AppendVsPrepend")); jCheckBoxAppend.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 235 jCheckBoxAppend.setMargin(new java.awt.Insets (0, 0, 0, 0)); 236 jCheckBoxAppend.setOpaque(false); 237 jCheckBoxAppend.addActionListener(new java.awt.event.ActionListener () { 238 public void actionPerformed(java.awt.event.ActionEvent evt) { 239 jCheckBoxAppendActionPerformed(evt); 240 } 241 }); 242 243 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxCollectWorkPeriods, org.openide.util.NbBundle.getMessage(UTOptionsPanel.class, "CollectWorkPeriods")); jCheckBoxCollectWorkPeriods.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 245 jCheckBoxCollectWorkPeriods.setMargin(new java.awt.Insets (0, 0, 0, 0)); 246 jCheckBoxCollectWorkPeriods.setOpaque(false); 247 jCheckBoxCollectWorkPeriods.addActionListener(new java.awt.event.ActionListener () { 248 public void actionPerformed(java.awt.event.ActionEvent evt) { 249 jCheckBoxCollectWorkPeriodsActionPerformed(evt); 250 } 251 }); 252 253 jLabel3.setLabelFor(jTextFieldFile); 254 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(UTOptionsPanel.class, "DefaultUserTasksFile")); 256 jPanelWorkingHours.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(UTOptionsPanel.class, "Work"))); jPanelWorkingHours.setOpaque(false); 258 259 org.jdesktop.layout.GroupLayout jPanelWorkingHoursLayout = new org.jdesktop.layout.GroupLayout(jPanelWorkingHours); 260 jPanelWorkingHours.setLayout(jPanelWorkingHoursLayout); 261 jPanelWorkingHoursLayout.setHorizontalGroup( 262 jPanelWorkingHoursLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 263 .add(0, 237, Short.MAX_VALUE) 264 ); 265 jPanelWorkingHoursLayout.setVerticalGroup( 266 jPanelWorkingHoursLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 267 .add(0, 194, Short.MAX_VALUE) 268 ); 269 270 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxDetectInactivity, org.openide.util.NbBundle.getBundle(UTOptionsPanel.class).getString("DetectInactivity")); jCheckBoxDetectInactivity.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 272 jCheckBoxDetectInactivity.setMargin(new java.awt.Insets (0, 0, 0, 0)); 273 jCheckBoxDetectInactivity.setOpaque(false); 274 jCheckBoxDetectInactivity.addActionListener(new java.awt.event.ActionListener () { 275 public void actionPerformed(java.awt.event.ActionEvent evt) { 276 jCheckBoxDetectInactivityActionPerformed(evt); 277 } 278 }); 279 280 org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxAutoSwitchToComputed, org.openide.util.NbBundle.getBundle(UTOptionsPanel.class).getString("AutoSwithToComputed")); jCheckBoxAutoSwitchToComputed.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 282 jCheckBoxAutoSwitchToComputed.setMargin(new java.awt.Insets (0, 0, 0, 0)); 283 jCheckBoxAutoSwitchToComputed.setOpaque(false); 284 jCheckBoxAutoSwitchToComputed.addActionListener(new java.awt.event.ActionListener () { 285 public void actionPerformed(java.awt.event.ActionEvent evt) { 286 jCheckBoxAutoSwitchToComputedActionPerformed(evt); 287 } 288 }); 289 290 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 291 this.setLayout(layout); 292 layout.setHorizontalGroup( 293 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 294 .add(layout.createSequentialGroup() 295 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 296 .add(jCheckBoxAppend) 297 .add(jCheckBoxCollectWorkPeriods) 298 .add(jCheckBoxDetectInactivity) 299 .add(jCheckBoxAutoSwitchToComputed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 664, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 300 .add(layout.createSequentialGroup() 301 .add(jLabel3) 302 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 303 .add(jTextFieldFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 504, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 304 .add(jPanelWorkingHours, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 305 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 306 ); 307 layout.setVerticalGroup( 308 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 309 .add(layout.createSequentialGroup() 310 .add(jCheckBoxAppend) 311 .add(11, 11, 11) 312 .add(jCheckBoxCollectWorkPeriods) 313 .add(11, 11, 11) 314 .add(jCheckBoxDetectInactivity) 315 .add(11, 11, 11) 316 .add(jCheckBoxAutoSwitchToComputed) 317 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 318 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 319 .add(jLabel3) 320 .add(jTextFieldFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 321 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 322 .add(jPanelWorkingHours, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 323 ); 324 } 326 private void jCheckBoxAutoSwitchToComputedActionPerformed(java.awt.event.ActionEvent evt) { changed = true; 328 } 330 private void jCheckBoxDetectInactivityActionPerformed(java.awt.event.ActionEvent evt) { changed = true; 332 } 334 private void jCheckBoxCollectWorkPeriodsActionPerformed(java.awt.event.ActionEvent evt) { changed = true; 336 } 338 private void jCheckBoxAppendActionPerformed(java.awt.event.ActionEvent evt) { changed = true; 340 } 342 347 public boolean isContentValid() { 348 if (jTextFieldFile.getText().trim().length() == 0) 349 return false; 350 int a = cbDayStart.getTime(); 351 int b = cbPauseStart.getTime(); 352 int c = cbPauseEnd.getTime(); 353 int d = cbDayEnd.getTime(); 354 if (b < a || c < b || d < c) 355 return false; 356 boolean all = false; 357 DefaultCheckListModel m = (DefaultCheckListModel) 358 clWorkingDays.getModel(); 359 for (int i = 0; i < m.getSize(); i++) { 360 all |= m.isChecked(i); 361 } 362 if (!all) 363 return false; 364 return true; 365 } 366 367 public void actionPerformed(ActionEvent e) { 368 changed = true; 369 } 370 371 public void intervalAdded(ListDataEvent e) { 372 changed = true; 373 } 374 375 public void intervalRemoved(ListDataEvent e) { 376 changed = true; 377 } 378 379 public void contentsChanged(ListDataEvent e) { 380 changed = true; 381 } 382 383 public javax.swing.JCheckBox jCheckBoxAppend; 385 public javax.swing.JCheckBox jCheckBoxAutoSwitchToComputed; 386 public javax.swing.JCheckBox jCheckBoxCollectWorkPeriods; 387 public javax.swing.JCheckBox jCheckBoxDetectInactivity; 388 public javax.swing.JLabel jLabel3; 389 public javax.swing.JPanel jPanelWorkingHours; 390 public javax.swing.JTextField jTextFieldFile; 391 } 393 | Popular Tags |