コード例 #1
0
 @Override
 public boolean runProcessWithProgressSynchronously(
     @NotNull final Task task, @Nullable final JComponent parentComponent) {
   final long start = System.currentTimeMillis();
   final boolean result = super.runProcessWithProgressSynchronously(task, parentComponent);
   if (result) {
     final long end = System.currentTimeMillis();
     final Task.NotificationInfo notificationInfo = task.notifyFinished();
     long time = end - start;
     if (notificationInfo != null
         && time > 5000) { // show notification only if process took more than 5 secs
       final JFrame frame = WindowManager.getInstance().getFrame(task.getProject());
       if (frame != null && !frame.hasFocus()) {
         systemNotify(notificationInfo);
       }
     }
   }
   return result;
 }
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("addTask")) {
      taskList.add(new Task("new Task"));
      /// @todo A new created task should be editable right away.
      table.editCellAt(taskList.getRowCount() - 1, 0);
    }
    if (e.getActionCommand().equals("deleteTask") && (table.getSelectedRow() != -1)) {
      taskList.remove(table.getSelectedRow());
    }
    if (e.getActionCommand().equals("cross") && (table.getSelectedRow() != -1)) {
      taskList.get(table.getSelectedRow()).setState(State.crossed);
    }
    if (e.getActionCommand().equals("dismiss") && (table.getSelectedRow() != -1)) {
      taskList.get(table.getSelectedRow()).setState(State.dismissed);
    }
    if (e.getActionCommand().equals("workedOn") && (table.getSelectedRow() != -1)) {
      Task task = taskList.get(table.getSelectedRow());
      task.setState(State.crossed);
      taskList.add(new Task(task.getName()));
    }

    // File handling
    File file = null;
    Writer writer = null;
    JAXBContext context;

    if (e.getActionCommand().equals("save")) {
      Marshaller m = null;
      int returnVal = fileChooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fileChooser.getSelectedFile();
        if (!file.getName().endsWith(".xml")) {
          /// @TODO Append automaticly .xml
        }

        try {
          context = JAXBContext.newInstance(TaskList.class);
          m = context.createMarshaller();
          m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
          writer = new FileWriter(file);
          m.marshal(taskList, writer);

        } catch (JAXBException exeption) {
          exeption.printStackTrace();
        } catch (IOException exeption) {
          exeption.printStackTrace();
        } finally {
          try {
            writer.close();
          } catch (Exception exeption) {
          }
        }
      }
    }
    if (e.getActionCommand().equals("open")) {
      Unmarshaller um = null;
      int returnVal = fileChooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fileChooser.getSelectedFile();
        // if(!file.getName().endsWith(".xml")){
        /// @TODO Append automaticly .xml
        // }

        try {
          context = JAXBContext.newInstance(TaskList.class);
          um = context.createUnmarshaller();
          taskList = (TaskList) um.unmarshal(file);
          table.setModel(taskList);
          table.getColumnModel().getColumn(0).setCellRenderer(new TaskRenderer());

        } catch (JAXBException exeption) {
          exeption.printStackTrace();

        } finally {
          try {
            writer.close();
          } catch (Exception exeption) {
          }
        }
      }
    }
    taskList.fireTableDataChanged();
  }
コード例 #3
0
  /** Invoked when the user presses the start button. */
  public void actionPerformed(ActionEvent evt) {
    if (evt.getActionCommand().equals("start")) {
      StartButton.setEnabled(false);
      cancelButton.setEnabled(true);
      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      // Instances of javax.swing.SwingWorker are not reusuable, so
      // we create new instances as needed.
      DownloadMessage theMessage =
          new DownloadMessage() {
            public void setProgress(int Progress) {
              if (myState.equals("SPLIT")) {
                progressBar.setValue(Progress);

              } else if (myState.equals("DOWNLOADREMOTE")) {
                progressBar.setValue(Progress);

              } else if (myState.equals("DOWNLOADLOCALBASE")) {
                progressBar3.setValue(Progress);

              } else if (myState.equals("TOTAL")) {
                progressBar4.setValue(Progress);
                progressBar3.setValue(0);
                progressBar2.setValue(0);
                progressBar.setValue(0);
              }
            }

            public void messageChanged(int Progress, String message) {
              setProgress(Progress);

              taskOutput.append(message + "\n");
              taskOutput.setCaretPosition(taskOutput.getDocument().getLength());

              // TODO Auto-generated method stub

            }

            public void stateChanged(String theState) {

              myState = theState;
              // TODO Auto-generated method stub

            }

            public void messageChanged(String theMessage) {
              taskOutput.append(theMessage + "\n");
              taskOutput.setCaretPosition(taskOutput.getDocument().getLength());
              // TODO Auto-generated method stub
              // TODO Auto-generated method stub

            }
          };

      task = new Task(theMessage, (String) myDownloadOptions.getSelectedItem());
      task.addPropertyChangeListener(this);
      task.execute();
    } else if (evt.getActionCommand().equals("cancel")) {
      task.cancel(false);
      //	startButton.setEnabled(true);
      //	cancelButton.setEnabled(false);

    }
  }