mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
graphical progress
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.intellij.ide;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 7/21/11
|
||||
*/
|
||||
public interface StartupProgress {
|
||||
|
||||
/**
|
||||
* Displays new progress state.
|
||||
* @param message text to be shown
|
||||
* @param progress progress state from 0 to 1
|
||||
*/
|
||||
void showProgress(String message, float progress);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.ide.ClassloaderUtil;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.StartupProgress;
|
||||
import com.intellij.ide.plugins.cl.PluginClassLoader;
|
||||
import com.intellij.idea.Main;
|
||||
import com.intellij.notification.Notification;
|
||||
@@ -40,7 +41,6 @@ import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.graph.CachingSemiGraph;
|
||||
import com.intellij.util.graph.DFSTBuilder;
|
||||
@@ -119,7 +119,7 @@ public class PluginManager {
|
||||
return ourPlugins;
|
||||
}
|
||||
|
||||
public static void initPlugins(@Nullable Consumer<String> progress) {
|
||||
public static void initPlugins(@Nullable StartupProgress progress) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
initializePlugins(progress);
|
||||
@@ -203,7 +203,7 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializePlugins(Consumer<String> progress) {
|
||||
private static void initializePlugins(StartupProgress progress) {
|
||||
configureExtensions();
|
||||
|
||||
final IdeaPluginDescriptorImpl[] pluginDescriptors = loadDescriptors(progress);
|
||||
@@ -528,22 +528,29 @@ public class PluginManager {
|
||||
return classLoaders.toArray(new ClassLoader[classLoaders.size()]);
|
||||
}
|
||||
|
||||
public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable Consumer<String> progress) {
|
||||
public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable StartupProgress progress) {
|
||||
if (ClassloaderUtil.isLoadingOfExternalPluginsDisabled()) {
|
||||
return IdeaPluginDescriptorImpl.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>();
|
||||
|
||||
loadDescriptors(PathManager.getPluginsPath(), result, progress);
|
||||
int pluginsCount = countPlugins(PathManager.getPluginsPath()) + countPlugins(PathManager.getPreinstalledPluginsPath());
|
||||
loadDescriptors(PathManager.getPluginsPath(), result, progress, pluginsCount);
|
||||
Application application = ApplicationManager.getApplication();
|
||||
boolean fromSources = false;
|
||||
if (application == null || !application.isUnitTestMode()) {
|
||||
loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress);
|
||||
int size = result.size();
|
||||
loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress, pluginsCount);
|
||||
fromSources = size == result.size();
|
||||
}
|
||||
|
||||
loadDescriptorsFromProperty(result);
|
||||
|
||||
loadDescriptorsFromClassPath(result, progress);
|
||||
if (!fromSources && progress != null) {
|
||||
progress.showProgress("Loading core...", 0.5f);
|
||||
}
|
||||
loadDescriptorsFromClassPath(result, fromSources ? progress : null);
|
||||
|
||||
IdeaPluginDescriptorImpl[] pluginDescriptors = result.toArray(new IdeaPluginDescriptorImpl[result.size()]);
|
||||
try {
|
||||
@@ -557,6 +564,17 @@ public class PluginManager {
|
||||
return pluginDescriptors;
|
||||
}
|
||||
|
||||
private static int countPlugins(String pluginsPath) {
|
||||
File configuredPluginsDir = new File(pluginsPath);
|
||||
if (configuredPluginsDir.exists()) {
|
||||
String[] list = configuredPluginsDir.list();
|
||||
if (list != null) {
|
||||
return list.length;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void reportPluginError() {
|
||||
if (myPluginError != null) {
|
||||
Notifications.Bus.notify(new Notification(IdeBundle.message("title.plugin.error"), IdeBundle.message("title.plugin.error"),
|
||||
@@ -598,11 +616,13 @@ public class PluginManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"})
|
||||
private static void loadDescriptorsFromClassPath(final List<IdeaPluginDescriptorImpl> result, @Nullable Consumer<String> progress) {
|
||||
private static void loadDescriptorsFromClassPath(final List<IdeaPluginDescriptorImpl> result, @Nullable StartupProgress progress) {
|
||||
try {
|
||||
final Collection<URL> urls = getClassLoaderUrls();
|
||||
final String platformPrefix = System.getProperty("idea.platform.prefix");
|
||||
int i = 0;
|
||||
for (URL url : urls) {
|
||||
i++;
|
||||
final String protocol = url.getProtocol();
|
||||
if ("file".equals(protocol)) {
|
||||
final File file = new File(URLDecoder.decode(url.getFile()));
|
||||
@@ -630,7 +650,7 @@ public class PluginManager {
|
||||
}
|
||||
result.add(pluginDescriptor);
|
||||
if (progress != null) {
|
||||
progress.consume("Plugin loaded: " + pluginDescriptor.getName());
|
||||
progress.showProgress("Plugin loaded: " + pluginDescriptor.getName(), 0.5f * ((float)i / urls.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -797,15 +817,19 @@ public class PluginManager {
|
||||
}
|
||||
|
||||
|
||||
private static void loadDescriptors(String pluginsPath, List<IdeaPluginDescriptorImpl> result, @Nullable Consumer<String> progress) {
|
||||
private static void loadDescriptors(String pluginsPath,
|
||||
List<IdeaPluginDescriptorImpl> result,
|
||||
@Nullable StartupProgress progress,
|
||||
int pluginsCount) {
|
||||
final File pluginsHome = new File(pluginsPath);
|
||||
final File[] files = pluginsHome.listFiles();
|
||||
if (files != null) {
|
||||
int i = result.size();
|
||||
for (File file : files) {
|
||||
final IdeaPluginDescriptorImpl descriptor = loadDescriptor(file, PLUGIN_XML);
|
||||
if (descriptor == null) continue;
|
||||
if (progress != null) {
|
||||
progress.consume(descriptor.getName());
|
||||
progress.showProgress(descriptor.getName(), 0.5f * ((float)++i / pluginsCount));
|
||||
}
|
||||
int oldIndex = result.indexOf(descriptor);
|
||||
if (oldIndex >= 0) {
|
||||
|
||||
+11
-10
@@ -51,7 +51,6 @@ import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
|
||||
@@ -360,10 +359,21 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
|
||||
private void loadApplicationComponents() {
|
||||
PluginManager.initPlugins(mySplash);
|
||||
final IdeaPluginDescriptor[] plugins = PluginManager.getPlugins();
|
||||
int pluginCount = 0;
|
||||
for (IdeaPluginDescriptor plugin : plugins) {
|
||||
if (!PluginManager.shouldSkipPlugin(plugin)) pluginCount++;
|
||||
}
|
||||
int i = 0;
|
||||
for (IdeaPluginDescriptor plugin : plugins) {
|
||||
if (PluginManager.shouldSkipPlugin(plugin)) continue;
|
||||
if (mySplash != null) {
|
||||
mySplash.showProgress("Initializing " + plugin.getName() + "...", 0.5f + 0.5f * ((float)++i / pluginCount));
|
||||
}
|
||||
loadComponentsConfiguration(plugin.getAppComponents(), plugin, false);
|
||||
}
|
||||
if (mySplash != null) {
|
||||
mySplash.showProgress("Loading project...", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
protected MutablePicoContainer createPicoContainer() {
|
||||
@@ -496,15 +506,6 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
|
||||
return super.getComponentFromContainer(interfaceClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized Object createComponent(Class componentInterface) {
|
||||
Object component = super.createComponent(componentInterface);
|
||||
if (component != null && mySplash != null) {
|
||||
mySplash.consume("Component loaded: " + StringUtil.getShortName(componentInterface));
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
private static void loadComponentRoamingTypes() {
|
||||
ExtensionPoint<RoamingTypeExtensionPointBean> point = Extensions.getRootArea().getExtensionPoint("com.intellij.ComponentRoamingType");
|
||||
final RoamingTypeExtensionPointBean[] componentRoamingTypes = point.getExtensions();
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.ide.StartupProgress;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class Splash extends JDialog implements Consumer<String> {
|
||||
public class Splash extends JDialog implements StartupProgress {
|
||||
private final Icon myImage;
|
||||
private final JLabel myLabel;
|
||||
private final Color myTextColor;
|
||||
@@ -55,7 +55,7 @@ public class Splash extends JDialog implements Consumer<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume(String message) {
|
||||
public void showProgress(String message, float progress) {
|
||||
Graphics g = getGraphics();
|
||||
UIUtil.applyRenderingHints(g);
|
||||
g.setFont(new Font(UIUtil.ARIAL_FONT_NAME, Font.PLAIN, 10));
|
||||
@@ -64,7 +64,13 @@ public class Splash extends JDialog implements Consumer<String> {
|
||||
int brightness = 220;
|
||||
g.setColor(new Color(brightness, brightness, brightness));
|
||||
int x = 20;
|
||||
g.fillRect(1, y, 398, 20);
|
||||
int progressWidth = (int)(398 * progress);
|
||||
g.fillRect(1, y, progressWidth, 20);
|
||||
|
||||
brightness = 240;
|
||||
g.setColor(new Color(brightness, brightness, brightness));
|
||||
g.fillRect(1 + progressWidth, y, 398 - progressWidth, 20);
|
||||
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
// g.setXORMode(Color.WHITE);
|
||||
g.drawString(message, x, getHeight() - 8);
|
||||
|
||||
Reference in New Issue
Block a user