Ejemplo n.º 1
0
 /**
  * Method called when OK button was pressed.
  *
  * @param evt Event that invoked this action.
  */
 private void btOKActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btOKActionPerformed
   AbstractTaskFilter newTaskFilter =
       (AbstractTaskFilter) cmbFilterName.getItemAt(cmbFilterName.getSelectedIndex());
   newTaskFilter.setContentRule(cmbContentRule.getSelectedIndex());
   String content = null;
   if (newTaskFilter instanceof DescriptionFilter) content = txtContent.getText();
   if (newTaskFilter instanceof KeywordFilter) content = txtContent.getText();
   if (newTaskFilter instanceof DurationFilter) {
     String text = txtContent.getText();
     long duration;
     try {
       if (text.length() != 8)
         throw new NumberFormatException("Error: invalid task duration specified: " + text);
       duration = Tools.getTime(text);
     } catch (NumberFormatException e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           this,
           Translator.getTranslation("WARNING.INVALID_DURATION"),
           Translator.getTranslation("WARNING.WARNING_TITLE"),
           JOptionPane.WARNING_MESSAGE);
       txtContent.setText(Tools.getTime(0));
       return;
     }
     content = Tools.getTime(duration);
   }
   if (newTaskFilter instanceof PriorityFilter) content = "" + cmbContent.getSelectedIndex();
   if (newTaskFilter instanceof StateFilter) content = "" + cmbContent.getSelectedIndex();
   if (newTaskFilter instanceof PrivateFilter)
     content = Boolean.toString(cmbContent.getSelectedIndex() == 0);
   newTaskFilter.setContent(content);
   if (taskFilter == null) filtersTableModel.addFilter(newTaskFilter);
   else filtersTableModel.replaceFilter(taskFilter, newTaskFilter);
   formWindowClosing(null);
 } // GEN-LAST:event_btOKActionPerformed