1 19 package org.netbeans.modules.ruby.rubyproject.execution; 20 21 import java.awt.event.ActionEvent ; 22 import java.io.Reader ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.Action ; 27 import javax.swing.ImageIcon ; 28 import org.openide.util.NbBundle; 29 import org.openide.util.RequestProcessor; 30 31 39 final class StopAction extends AbstractAction { 40 public List <RequestProcessor.Task> processorTasks = new ArrayList <RequestProcessor.Task>(); 41 private List <Reader > readers = new ArrayList <Reader >(); 42 public Process process; 43 44 public StopAction() { 45 setEnabled(false); } 47 48 public void addReader(Reader reader) { 49 readers.add(reader); 50 } 51 52 @Override 53 public Object getValue(String key) { 54 if (key.equals(Action.SMALL_ICON)) { 55 return new ImageIcon (ExecutionService.class.getResource( 56 "/org/netbeans/modules/ruby/rubyproject/execution/stop.gif")); } else if (key.equals(Action.SHORT_DESCRIPTION)) { 58 return NbBundle.getMessage(ExecutionService.class, "Stop"); 59 } else { 60 return super.getValue(key); 61 } 62 } 63 64 public void notifyDone(RequestProcessor.Task task) { 65 if (processorTasks.contains(task)) { 66 processorTasks.remove(task); 67 68 if (processorTasks.size() == 0) { 70 if (process != null) { 71 process.destroy(); 72 process = null; 73 } 74 } 75 } 76 } 77 78 public void actionPerformed(ActionEvent e) { 79 setEnabled(false); 81 for (RequestProcessor.Task task : processorTasks) { 82 task.cancel(); 83 } 84 } 85 } 86 | Popular Tags |