Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.ui.internal.progress; 12 13 import java.util.Collections ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.core.runtime.jobs.Job; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.graphics.Color; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.ui.progress.WorkbenchJob; 25 26 30 public class AnimationManager { 31 private static AnimationManager singleton; 32 33 boolean animated = false; 34 35 private IJobProgressManagerListener listener; 36 37 IAnimationProcessor animationProcessor; 38 39 WorkbenchJob animationUpdateJob; 40 41 public static AnimationManager getInstance() { 42 if (singleton == null) { 43 singleton = new AnimationManager(); 44 } 45 return singleton; 46 } 47 48 55 static Color getItemBackgroundColor(Control control) { 56 return control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND); 57 } 58 59 AnimationManager() { 60 61 animationProcessor = new ProgressAnimationProcessor(this); 62 63 animationUpdateJob = new WorkbenchJob(ProgressMessages.AnimationManager_AnimationStart) { 64 65 70 public IStatus runInUIThread(IProgressMonitor monitor) { 71 72 if (animated) { 73 animationProcessor.animationStarted(); 74 } else { 75 animationProcessor.animationFinished(); 76 } 77 return Status.OK_STATUS; 78 } 79 }; 80 animationUpdateJob.setSystem(true); 81 82 listener = getProgressListener(); 83 ProgressManager.getInstance().addListener(listener); 84 85 86 } 87 88 93 void addItem(final AnimationItem item) { 94 animationProcessor.addItem(item); 95 } 96 97 102 void removeItem(final AnimationItem item) { 103 animationProcessor.removeItem(item); 104 } 105 106 111 boolean isAnimated() { 112 return animated; 113 } 114 115 120 void setAnimated(final boolean bool) { 121 animated = bool; 122 animationUpdateJob.schedule(100); 123 } 124 125 128 void dispose() { 129 setAnimated(false); 130 ProgressManager.getInstance().removeListener(listener); 131 } 132 133 private IJobProgressManagerListener getProgressListener() { 134 return new IJobProgressManagerListener() { 135 Set jobs = Collections.synchronizedSet(new HashSet ()); 136 137 142 public void addJob(JobInfo info) { 143 incrementJobCount(info); 144 } 145 146 151 public void refreshJobInfo(JobInfo info) { 152 int state = info.getJob().getState(); 153 if (state == Job.RUNNING) { 154 addJob(info); 155 } else { 156 removeJob(info); 157 } 158 } 159 160 165 public void refreshAll() { 166 ProgressManager manager = ProgressManager.getInstance(); 167 jobs.clear(); 168 setAnimated(false); 169 JobInfo[] currentInfos = manager.getJobInfos(showsDebug()); 170 for (int i = 0; i < currentInfos.length; i++) { 171 addJob(currentInfos[i]); 172 } 173 } 174 175 180 public void removeJob(JobInfo info) { 181 decrementJobCount(info.getJob()); 182 } 183 184 189 public boolean showsDebug() { 190 return false; 191 } 192 193 private void incrementJobCount(JobInfo info) { 194 if (isNotTracked(info)) { 196 return; 197 } 198 if (jobs.isEmpty()) { 199 setAnimated(true); 200 } 201 jobs.add(info.getJob()); 202 } 203 204 207 private void decrementJobCount(Job job) { 208 jobs.remove(job); 209 if (jobs.isEmpty()) { 210 setAnimated(false); 211 } 212 } 213 214 217 private boolean isNotTracked(JobInfo info) { 218 Job job = info.getJob(); 220 return job.getState() != Job.RUNNING 221 || animationProcessor.isProcessorJob(job); 222 } 223 224 229 public void addGroup(GroupInfo info) { 230 } 232 233 238 public void removeGroup(GroupInfo group) { 239 } 241 242 247 public void refreshGroup(GroupInfo info) { 248 } 250 }; 251 } 252 253 258 int getPreferredWidth() { 259 return animationProcessor.getPreferredWidth(); 260 } 261 262 } 263
| Popular Tags
|