Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Eugene Kudelevsky
2010-05-20 16:17:11 +04:00
5 changed files with 114 additions and 43 deletions
@@ -47,12 +47,12 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.*;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.peer.PeerFactory;
import com.intellij.pom.Navigatable;
import com.intellij.problems.WolfTheProblemSolver;
import com.intellij.ui.AppIcon;
import com.intellij.ui.content.*;
import com.intellij.util.Alarm;
import com.intellij.util.ArrayUtil;
@@ -73,6 +73,7 @@ public class CompilerTask extends Task.Backgroundable {
private static final boolean IS_UNIT_TEST_MODE = ApplicationManager.getApplication().isUnitTestMode();
private static final int UPDATE_INTERVAL = 50; //msec. 20 frames per second.
private static final Key<Key<?>> CONTENT_ID_KEY = Key.create("CONTENT_ID");
private static final String APP_ICON_ID = "compiler";
private Key<Key<?>> myContentIdKey = CONTENT_ID_KEY;
private final Key<Key<?>> myContentId = Key.create("compile_content");
private CompilerProgressDialog myDialog;
@@ -90,12 +91,14 @@ public class CompilerTask extends Task.Backgroundable {
private Runnable myCompileWork;
private final AtomicBoolean myMessageViewWasPrepared = new AtomicBoolean(false);
private Runnable myRestartWork;
private IdeFrame myIdeFrame;
public CompilerTask(@NotNull Project project, boolean compileInBackground, String contentName, final boolean headlessMode) {
super(project, contentName);
myIsBackgroundMode = compileInBackground;
myContentName = contentName;
myHeadlessMode = headlessMode || IS_UNIT_TEST_MODE;
myIdeFrame = (IdeFrame)WindowManager.getInstance().getFrame(myProject);
}
public void setContentIdKey(Key<Key<?>> contentIdKey) {
@@ -179,6 +182,7 @@ public class CompilerTask extends Task.Backgroundable {
public void cancel() {
super.cancel();
closeUI();
stopAppIconProgress();
}
public void stop() {
@@ -186,6 +190,19 @@ public class CompilerTask extends Task.Backgroundable {
if (!isCanceled()) {
closeUI();
}
stopAppIconProgress();
}
private void stopAppIconProgress() {
AppIcon appIcon = AppIcon.getInstance();
if (appIcon.hideProgress(APP_ICON_ID)) {
if (myErrorCount > 0) {
appIcon.setBadge(String.valueOf(myErrorCount));
appIcon.requestAttention(true);
} else {
appIcon.setBadge(null);
}
}
}
public void setText(final String text) {
@@ -198,6 +215,7 @@ public class CompilerTask extends Task.Backgroundable {
public void setFraction(final double fraction) {
updateProgressText();
AppIcon.getInstance().setProgress(APP_ICON_ID, AppIconScheme.Progress.BUILD, fraction, true);
}
protected void onProgressChange() {
@@ -559,6 +577,9 @@ public class CompilerTask extends Task.Backgroundable {
if (myIndicator.isRunning()) {
cancel();
}
if (AppIcon.getInstance().hideProgress("compiler")) {
AppIcon.getInstance().setBadge(null);
}
}
}
myContentManager.removeContentManagerListener(this);
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui;
package com.intellij.openapi.wm;
import java.awt.*;
@@ -41,6 +41,16 @@ public class AppIconScheme {
}
};
static final Progress INDEXING = new Progress() {
public Color getOkColor() {
return Color.yellow;
}
public Color getErrorColor() {
return Color.red;
}
};
Color getOkColor();
Color getErrorColor();
@@ -22,13 +22,17 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.*;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.BalloonHandler;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.wm.AppIconScheme;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.openapi.wm.ex.StatusBarEx;
import com.intellij.ui.AppIcon;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.containers.Queue;
import com.intellij.util.io.storage.HeavyProcessLatch;
@@ -264,6 +268,24 @@ public class DumbServiceImpl extends DumbService {
// /*no override for interfaces in jdk 1.5 */ @Override
public void run(@NotNull final ProgressIndicator indicator) {
if (indicator instanceof ProgressIndicatorEx) {
((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() {
@Override
public void setFraction(double fraction) {
AppIcon.getInstance().setProgress("indexUpdate", AppIconScheme.Progress.INDEXING, fraction, true);
}
@Override
public void finish(@NotNull TaskInfo task) {
AppIcon appIcon = AppIcon.getInstance();
if (appIcon.hideProgress("indexUpdate")) {
appIcon.requestAttention(false);
}
}
});
}
final ProgressIndicator proxy =
(ProgressIndicator)Proxy.newProxyInstance(indicator.getClass().getClassLoader(), new Class[]{ProgressIndicator.class}, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -17,7 +17,7 @@ package com.intellij.ui;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.AppIconScheme;
import java.awt.*;
import java.awt.image.BufferedImage;
@@ -31,9 +31,9 @@ public abstract class AppIcon {
static AppIcon ourMacImpl;
static AppIcon ourEmptyImpl;
public abstract void setProgress(IdeFrame frame, Object processId, AppIconScheme.Progress scheme, double value, boolean isOk);
public abstract boolean setProgress(Object processId, AppIconScheme.Progress scheme, double value, boolean isOk);
public abstract void hideProgress(IdeFrame frame, Object processId);
public abstract boolean hideProgress(Object processId);
public abstract void setBadge(String text);
@@ -60,7 +60,6 @@ public abstract class AppIcon {
private Object myCurrentProcessId;
private double myUpdateFraction = 0.05d;
private double myLastValue;
private BufferedImage getAppImage() {
@@ -80,6 +79,9 @@ public abstract class AppIcon {
myAppImage = img;
}
catch (NoSuchMethodException e) {
return null;
}
catch (Exception e) {
LOG.error(e);
}
@@ -92,6 +94,9 @@ public abstract class AppIcon {
try {
getAppMethod("setDockIconBadge", String.class).invoke(getApp(), text);
}
catch (NoSuchMethodException e) {
return;
}
catch (Exception e) {
LOG.error(e);
}
@@ -100,46 +105,43 @@ public abstract class AppIcon {
@Override
public void requestAttention(boolean critical) {
try {
getAppMethod("requestUserAttention", Boolean.class).invoke(getApp(), Boolean.valueOf(critical));
getAppMethod("requestUserAttention", boolean.class).invoke(getApp(), critical);
}
catch (NoSuchMethodException e) {
return;
} catch (Exception e) {
}
catch (Exception e) {
LOG.error(e);
}
}
@Override
public void hideProgress(IdeFrame frame, Object processId) {
if (getAppImage() == null) return;
public boolean hideProgress(Object processId) {
if (getAppImage() == null) return false;
if (myCurrentProcessId != null && !myCurrentProcessId.equals(processId)) return false;
try {
if (myCurrentProcessId != null && myCurrentProcessId.equals(processId)) {
setDockIcon(getAppImage());
}
}
finally {
myCurrentProcessId = null;
myLastValue = 0;
}
setDockIcon(getAppImage());
myCurrentProcessId = null;
myLastValue = 0;
return true;
}
public void setProgress(IdeFrame frame, Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) {
if (getAppImage() == null) return;
if (myCurrentProcessId != null && !myCurrentProcessId.equals(processId)) return;
public boolean setProgress(Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) {
if (getAppImage() == null) return false;
if (myCurrentProcessId != null && !myCurrentProcessId.equals(processId)) return false;
myCurrentProcessId = processId;
if (Math.abs(myLastValue - value) < myUpdateFraction) return;
if (Math.abs(myLastValue - value) < 0.02d) return true;
try {
int progressHeight = 65;
int xInset = 30;
int yInset = 25;
int arc = 25;
int progressHeight = 20;
int xInset = 15;
int yInset = 10;
int bound = 2;
Rectangle progressRec = new Rectangle(new Point(xInset, myAppImage.getHeight() - yInset - progressHeight),
Rectangle progressRec = new Rectangle(new Point(xInset, myAppImage.getHeight() - progressHeight - yInset),
new Dimension(myAppImage.getWidth() - xInset * 2, progressHeight));
BufferedImage current = new BufferedImage(myAppImage.getWidth(), myAppImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
@@ -148,14 +150,20 @@ public abstract class AppIcon {
g.drawImage(getAppImage(), null, null);
Rectangle bgRec = new Rectangle(progressRec.x - bound, progressRec.y - bound, progressRec.width + bound * 2, progressRec.height + bound * 2);
g.setColor(Color.white);
g.fillRect(bgRec.x, bgRec.y, bgRec.width, bgRec.height);
g.setColor(Color.black);
g.fillRoundRect(progressRec.x, progressRec.y, progressRec.width, progressRec.height, arc, arc);
g.fillRect(progressRec.x, progressRec.y, progressRec.width, progressRec.height);
g.setColor(isOk ? scheme.getOkColor() : scheme.getErrorColor());
int currentWidth = (int)Math.ceil(progressRec.width * value);
g.fillRoundRect(progressRec.x, progressRec.y, currentWidth, progressRec.height, arc, arc);
g.fillRect(progressRec.x, progressRec.y, currentWidth, progressRec.height);
setDockIcon(current);
@@ -163,9 +171,12 @@ public abstract class AppIcon {
}
catch (Exception e) {
LOG.error(e);
} finally {
}
finally {
myCurrentProcessId = null;
}
return true;
}
private void setDockIcon(BufferedImage image) {
@@ -188,16 +199,18 @@ public abstract class AppIcon {
private Class<?> getAppClass() throws ClassNotFoundException {
return Class.forName("com.apple.eawt.Application");
}
}
private static class EmptyIcon extends AppIcon {
@Override
public void setProgress(IdeFrame frame, Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) {
public boolean setProgress(Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) {
return false;
}
@Override
public void hideProgress(IdeFrame frame, Object processId) {
public boolean hideProgress(Object processId) {
return false;
}
@Override
@@ -31,7 +31,7 @@ import com.intellij.rt.execution.junit.states.PoolOfTestStates;
import javax.swing.*;
import com.intellij.ui.AppIcon;
import com.intellij.ui.AppIconScheme;
import com.intellij.openapi.wm.AppIconScheme;
import org.jetbrains.annotations.NonNls;
public class TestProgress extends DefaultBoundedRangeModel implements Disposable {
@@ -130,18 +130,23 @@ public class TestProgress extends DefaultBoundedRangeModel implements Disposable
super.setValue(n);
AppIcon icon = AppIcon.getInstance();
if (n < getMaximum()) {
icon.setProgress(null, TESTS, AppIconScheme.Progress.TESTS, (double)n / (double)getMaximum(), myProblemsCounter == 0);
if (icon.setProgress(TESTS, AppIconScheme.Progress.TESTS, (double)n / (double)getMaximum(), myProblemsCounter == 0)) {
if (myProblemsCounter > 0) {
icon.setBadge(String.valueOf(myProblemsCounter));
}
}
} else {
icon.hideProgress(null, TESTS);
if (myProblemsCounter > 0) {
icon.setBadge(String.valueOf(myProblemsCounter));
icon.requestAttention(false);
if (icon.hideProgress(TESTS)) {
if (myProblemsCounter > 0) {
icon.setBadge(String.valueOf(myProblemsCounter));
icon.requestAttention(true);
}
}
}
}
public void dispose() {
AppIcon.getInstance().hideProgress(null, TESTS);
AppIcon.getInstance().hideProgress(TESTS);
AppIcon.getInstance().setBadge(null);
}
}