compilation supports app icon

This commit is contained in:
Kirill Kalishev
2010-05-20 15:27:45 +04:00
parent e3cd6a55af
commit ec8f951dcf
5 changed files with 62 additions and 3 deletions
@@ -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<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 +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<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);
@@ -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;
}
@@ -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();
@@ -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;
@@ -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 {