public void setupAutoRefresh() {
   if (refreshTask == null) {
     refreshTask =
         rp.create(
             new Runnable() {
               @Override
               public void run() {
                 String selection = comp.getSelectedText();
                 if (selection != null && !isKeyword(selection)) {
                   Pattern p = Pattern.compile(selection);
                   Matcher m = p.matcher(comp.getText());
                   // for some reason the matcher skips the \n chars
                   // so i am finding them all and subtracting them
                   // from the resulting start and end offset.
                   while (m.find() == true) {
                     int startOffset = m.start();
                     int numberOfLineFeed =
                         comp.getText().substring(0, startOffset).split("\n").length - 1;
                     startOffset = startOffset - numberOfLineFeed;
                     int endOffset = m.end() - numberOfLineFeed;
                     bag.addHighlight(startOffset, endOffset, defaultColors);
                   }
                 }
               }
             });
     refreshTask.setPriority(Thread.MIN_PRIORITY);
   }
   refreshTask.schedule(DELAY);
 }
Exemplo n.º 2
0
  /**
   * Creates a task that will execute the given command.
   *
   * @param cmd command to schedule
   * @param globalOptions options to use when running the command
   * @param mgr listener for command events
   * @return RequestProcessor.Task a task ready to execute the command
   * @throws IllegalCommandException if the command is not valid, e.g. it contains files that cannot
   *     be processed by a single command (they do not have a common filesystem root OR their CVS
   *     Roots differ)
   */
  public RequestProcessor.Task createTask(
      Command cmd, GlobalOptions globalOptions, final ExecutorSupport mgr)
      throws IllegalCommandException {

    File[] files = getCommandFiles(cmd);
    if ((cmd instanceof CheckoutCommand) == false && !(cmd instanceof RlogCommand)) { // XXX
      ensureValidCommand(files);
    }

    if (globalOptions.getCVSRoot() == null) {
      globalOptions = (GlobalOptions) globalOptions.clone();
      globalOptions.setCVSRoot(cvsRoot);
    }

    Client client = createClient();
    if ((cmd instanceof RlogCommand)) { // XXX
    } else if ((cmd instanceof CheckoutCommand)) { // XXX
      BasicCommand bc = (BasicCommand) cmd;
      if (bc.getFiles() != null) {
        String path = bc.getFiles()[0].getAbsolutePath();
        client.setLocalPath(path);
      } else {
        // #67315: use some default working dir
        client.setLocalPath(System.getProperty("user.dir")); // NOI18N
      }
    } else if (cmd instanceof ImportCommand) {
      client.setLocalPath(((ImportCommand) cmd).getImportDirectory());
    } else {
      setLocalDirectory(client, files);
    }

    client.getEventManager().addCVSListener(mgr);
    final CommandRunnable cr = new CommandRunnable(client, globalOptions, cmd, mgr);
    mgr.commandEnqueued(cr);
    RequestProcessor.Task task = requestProcessor.create(cr);
    task.addTaskListener(
        new TaskListener() {
          public void taskFinished(Task task) {
            try {
              // There are times when 'commandTerminated()' is not the last method called, therefore
              // I introduced
              // this event that really marks the very end of a command (thread end)
              mgr.commandTerminated(new TerminationEvent(new Result(cr)));
            } catch (Throwable e) {
              ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
            } finally {
              flushLog();
            }
          }
        });
    return task;
  }
 public void setupAutoRefresh() {
   if (lastRefreshTask == null) {
     lastRefreshTask =
         rp.create(
             new Runnable() {
               @Override
               public void run() {
                 String selection = comp.getSelectedText();
                 if (selection != null) {
                   Pattern p = Pattern.compile(selection);
                   Matcher m = p.matcher(comp.getText());
                   while (m.find() == true) {
                     int startOffset = m.start();
                     int endOffset = m.end();
                     bag.addHighlight(startOffset, endOffset, defaultColors);
                   }
                 }
               }
             });
   }
   lastRefreshTask.schedule(REFRESH_DELAY);
 }
 @Override
 public void actionPerformed(ActionEvent ev) {
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           cssMinify();
         }
       };
   final RequestProcessor.Task theTask = RP.create(runnable);
   final ProgressHandle ph =
       ProgressHandleFactory.createHandle(
           "Minifying CSS " + context.getPrimaryFile().getName(), theTask);
   theTask.addTaskListener(
       new TaskListener() {
         @Override
         public void taskFinished(org.openide.util.Task task) {
           // JOptionPane.showMessageDialog(null, "Image Compressed Successfully");
           ph.finish();
         }
       });
   ph.start();
   theTask.schedule(0);
 }
Exemplo n.º 5
0
 /**
  * Posts a task which will be run with exclusive access at some time in the future and returns
  * immediately.
  *
  * @param run the task.
  */
 public AsyncTask createAsyncTask(Runnable run) {
   return new AsyncTask(rp.create(new TaskWrapper(run), true));
 }