From ec8f951dcfeff2edee71dd9c7c7af25be5ba2c08 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Thu, 20 May 2010 15:27:45 +0400 Subject: [PATCH] compilation supports app icon --- .../compiler/progress/CompilerTask.java | 33 +++++++++++++++++++ .../com/intellij/openapi/progress/Task.java | 9 +++++ .../intellij/openapi/wm}/AppIconScheme.java | 12 ++++++- .../src/com/intellij/ui/AppIcon.java | 9 ++++- .../execution/junit2/ui/TestProgress.java | 2 +- 5 files changed, 62 insertions(+), 3 deletions(-) rename platform/{platform-impl/src/com/intellij/ui => platform-api/src/com/intellij/openapi/wm}/AppIconScheme.java (82%) diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index 5112ef7a29dd..79e546a1b1cd 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -47,12 +47,15 @@ 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.IdeFrame; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.openapi.wm.WindowManager; 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 +76,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> CONTENT_ID_KEY = Key.create("CONTENT_ID"); + private static final String APP_ICON_ID = "compiler"; private Key> myContentIdKey = CONTENT_ID_KEY; private final Key> myContentId = Key.create("compile_content"); private CompilerProgressDialog myDialog; @@ -90,12 +94,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> contentIdKey) { @@ -115,6 +121,11 @@ public class CompilerTask extends Task.Backgroundable { return myIsBackgroundMode; } + @Override + public boolean isAppIconProcess() { + return true; + } + public ProgressIndicator getIndicator() { return myIndicator; } @@ -179,6 +190,7 @@ public class CompilerTask extends Task.Backgroundable { public void cancel() { super.cancel(); closeUI(); + stopAppIconProgress(); } public void stop() { @@ -186,6 +198,21 @@ public class CompilerTask extends Task.Backgroundable { if (!isCanceled()) { closeUI(); } + stopAppIconProgress(); + } + + private void stopAppIconProgress() { + if (isAppIconProcess()) { + AppIcon appIcon = AppIcon.getInstance(); + if (appIcon.hideProgress(myIdeFrame, 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 +225,9 @@ public class CompilerTask extends Task.Backgroundable { public void setFraction(final double fraction) { updateProgressText(); + if (isAppIconProcess()) { + AppIcon.getInstance().setProgress(myIdeFrame, APP_ICON_ID, getAppIconScheme(), fraction, true); + } } protected void onProgressChange() { @@ -559,6 +589,9 @@ public class CompilerTask extends Task.Backgroundable { if (myIndicator.isRunning()) { cancel(); } + if (AppIcon.getInstance().hideProgress(myIdeFrame, "compiler")) { + AppIcon.getInstance().setBadge(null); + } } } myContentManager.removeContentManagerListener(this); diff --git a/platform/platform-api/src/com/intellij/openapi/progress/Task.java b/platform/platform-api/src/com/intellij/openapi/progress/Task.java index 18983b7321a3..95b7659ce96c 100644 --- a/platform/platform-api/src/com/intellij/openapi/progress/Task.java +++ b/platform/platform-api/src/com/intellij/openapi/progress/Task.java @@ -19,6 +19,7 @@ import com.intellij.CommonBundle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.DumbModeAction; +import com.intellij.openapi.wm.AppIconScheme; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,6 +77,14 @@ public abstract class Task implements TaskInfo, Progressive { return this; } + public boolean isAppIconProcess() { + return false; + } + + public AppIconScheme.Progress getAppIconScheme() { + return AppIconScheme.Progress.BUILD; + } + public final String getCancelText() { return myCancelText; } diff --git a/platform/platform-impl/src/com/intellij/ui/AppIconScheme.java b/platform/platform-api/src/com/intellij/openapi/wm/AppIconScheme.java similarity index 82% rename from platform/platform-impl/src/com/intellij/ui/AppIconScheme.java rename to platform/platform-api/src/com/intellij/openapi/wm/AppIconScheme.java index 75e342a8a9a4..0ef08736f3b7 100644 --- a/platform/platform-impl/src/com/intellij/ui/AppIconScheme.java +++ b/platform/platform-api/src/com/intellij/openapi/wm/AppIconScheme.java @@ -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(); diff --git a/platform/platform-impl/src/com/intellij/ui/AppIcon.java b/platform/platform-impl/src/com/intellij/ui/AppIcon.java index 94cd52668cd4..920a559d2625 100644 --- a/platform/platform-impl/src/com/intellij/ui/AppIcon.java +++ b/platform/platform-impl/src/com/intellij/ui/AppIcon.java @@ -17,6 +17,7 @@ package com.intellij.ui; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.wm.AppIconScheme; import com.intellij.openapi.wm.IdeFrame; import java.awt.*; @@ -133,7 +134,7 @@ public abstract class AppIcon { int progressHeight = 20; int xInset = 15; int yInset = 10; - int arc = 25; + int bound = 2; Rectangle progressRec = new Rectangle(new Point(xInset, myAppImage.getHeight() - progressHeight - yInset), new Dimension(myAppImage.getWidth() - xInset * 2, progressHeight)); @@ -144,6 +145,11 @@ 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.fillRect(progressRec.x, progressRec.y, progressRec.width, progressRec.height); @@ -153,6 +159,7 @@ public abstract class AppIcon { g.fillRect(progressRec.x, progressRec.y, currentWidth, progressRec.height); + setDockIcon(current); myLastValue = value; diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/TestProgress.java b/plugins/junit/src/com/intellij/execution/junit2/ui/TestProgress.java index c8d6a308704b..b2c4caea4c8e 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/TestProgress.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/TestProgress.java @@ -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 {