001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.progress;
011:
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.List;
015:
016: import org.eclipse.core.runtime.Assert;
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.core.runtime.jobs.Job;
019: import org.eclipse.ui.PlatformUI;
020:
021: /**
022: * The ProgressAnimationProcessor is the processor for the animation using the
023: * system progress.
024: */
025: class ProgressAnimationProcessor implements IAnimationProcessor {
026:
027: AnimationManager manager;
028:
029: /**
030: * Create a new instance of the receiver and listen to the animation
031: * manager.
032: *
033: * @param animationManager
034: */
035: ProgressAnimationProcessor(AnimationManager animationManager) {
036: manager = animationManager;
037: }
038:
039: List items = Collections.synchronizedList(new ArrayList());
040:
041: /*
042: * (non-Javadoc)
043: *
044: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#startAnimation(org.eclipse.core.runtime.IProgressMonitor)
045: */
046: public void startAnimationLoop(IProgressMonitor monitor) {
047:
048: // Create an off-screen image to draw on, and a GC to draw with.
049: // Both are disposed after the animation.
050: if (items.size() == 0) {
051: return;
052: }
053: if (!PlatformUI.isWorkbenchRunning()) {
054: return;
055: }
056:
057: while (manager.isAnimated() && !monitor.isCanceled()) {
058: //Do nothing while animation is happening
059: }
060:
061: ProgressAnimationItem[] animationItems = getAnimationItems();
062: for (int i = 0; i < animationItems.length; i++) {
063: animationItems[i].animationDone();
064: }
065:
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#addItem(org.eclipse.ui.internal.progress.AnimationItem)
072: */
073: public void addItem(AnimationItem item) {
074: Assert.isTrue(item instanceof ProgressAnimationItem);
075: items.add(item);
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#removeItem(org.eclipse.ui.internal.progress.AnimationItem)
082: */
083: public void removeItem(AnimationItem item) {
084: Assert.isTrue(item instanceof ProgressAnimationItem);
085: items.remove(item);
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#hasItems()
092: */
093: public boolean hasItems() {
094: return items.size() > 0;
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#itemsInactiveRedraw()
101: */
102: public void itemsInactiveRedraw() {
103: //Nothing to do here as SWT handles redraw
104:
105: }
106:
107: /*
108: * (non-Javadoc)
109: *
110: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#animationStarted(org.eclipse.core.runtime.IProgressMonitor)
111: */
112: public void animationStarted() {
113: AnimationItem[] animationItems = getAnimationItems();
114: for (int i = 0; i < animationItems.length; i++) {
115: animationItems[i].animationStart();
116: }
117:
118: }
119:
120: /*
121: * (non-Javadoc)
122: *
123: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#getPreferredWidth()
124: */
125: public int getPreferredWidth() {
126: return 30;
127: }
128:
129: /**
130: * Get the animation items currently registered for the receiver.
131: *
132: * @return ProgressAnimationItem[]
133: */
134: private ProgressAnimationItem[] getAnimationItems() {
135: ProgressAnimationItem[] animationItems = new ProgressAnimationItem[items
136: .size()];
137: items.toArray(animationItems);
138: return animationItems;
139: }
140:
141: /* (non-Javadoc)
142: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#animationFinished()
143: */
144: public void animationFinished() {
145: AnimationItem[] animationItems = getAnimationItems();
146: for (int i = 0; i < animationItems.length; i++) {
147: animationItems[i].animationDone();
148: }
149:
150: }
151:
152: /* (non-Javadoc)
153: * @see org.eclipse.ui.internal.progress.IAnimationProcessor#isProcessorJob(org.eclipse.core.runtime.jobs.Job)
154: */
155: public boolean isProcessorJob(Job job) {
156: // We have no jobs
157: return false;
158: }
159:
160: }
|