diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei.png b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei.png index 469ea567b7..ca00f111cc 100644 Binary files a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei.png and b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei.png differ diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei_background.png b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei_background.png new file mode 100644 index 0000000000..6acbd9b27d Binary files /dev/null and b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/icons/sei_background.png differ diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/Messages.sarl b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/Messages.sarl index 6ee333b162..80a7c40c7b 100644 --- a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/Messages.sarl +++ b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/Messages.sarl @@ -41,8 +41,9 @@ final class Messages extends NLS { } public static var SarlExperienceIndexEvaluatorHandler_0 : String - public static var SarlExperienceIndexEvaluatorHandler_1 : String - public static var SarlExperienceIndexEvaluatorHandler_2 : String + public static var SarlExperienceIndexResultDialog_0 : String + public static var SarlExperienceIndexResultDialog_1 : String + public static var SarlExperienceIndexResultDialog_2 : String private new { } diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexEvaluatorHandler.sarl b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexEvaluatorHandler.sarl index d317cc6af4..a4f32e94e3 100644 --- a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexEvaluatorHandler.sarl +++ b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexEvaluatorHandler.sarl @@ -21,8 +21,6 @@ package io.sarl.experienceindex.eclipse -import java.text.MessageFormat - import org.eclipse.core.commands.AbstractHandler import org.eclipse.core.commands.ExecutionEvent import org.eclipse.core.commands.ExecutionException @@ -30,7 +28,6 @@ import org.eclipse.core.runtime.IProgressMonitor import org.eclipse.core.runtime.IStatus import org.eclipse.core.runtime.Status import org.eclipse.core.runtime.jobs.Job -import org.eclipse.jface.dialogs.MessageDialog import org.eclipse.ui.PlatformUI import io.sarl.experienceindex.SarlExperienceIndex @@ -64,16 +61,10 @@ class SarlExperienceIndexEvaluatorHandler extends AbstractHandler { override run(monitor : IProgressMonitor) : IStatus { val experienceIndex = SarlExperienceIndex::getJanusExperienceIndex [ monitor.canceled ] if (!monitor.canceled) { - val message = MessageFormat::format(Messages::SarlExperienceIndexEvaluatorHandler_2, - experienceIndex.baseScore, - experienceIndex.cpuScore, - experienceIndex.memoryScore, - experienceIndex.diskScore) PlatformUI::workbench.display.asyncExec [ - MessageDialog::openInformation( + SarlExperienceIndexResultDialog::open( null, - Messages::SarlExperienceIndexEvaluatorHandler_1, - message) + experienceIndex) ] } Status::OK_STATUS diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexPlugin.sarl b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexPlugin.sarl index d1fbe8a9b0..5623b662b7 100644 --- a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexPlugin.sarl +++ b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexPlugin.sarl @@ -22,7 +22,8 @@ package io.sarl.experienceindex.eclipse import org.eclipse.ui.plugin.AbstractUIPlugin - +import org.eclipse.jface.resource.ImageDescriptor +import org.eclipse.swt.graphics.Image /** * Plugin. @@ -37,7 +38,7 @@ class SarlExperienceIndexPlugin extends AbstractUIPlugin { /** Identifier of the plugin. */ - public static val PLUGIN_ID = "io.sarl.experienceindex" + public static val PLUGIN_ID = "io.sarl.experienceindex.plugin" static var instance : SarlExperienceIndexPlugin @@ -63,4 +64,38 @@ class SarlExperienceIndexPlugin extends AbstractUIPlugin { instance } + /** Replies the image descriptor for the given image path. + * + * @param imagePath - path of the image. + * @return the image descriptor. + */ + def getImageDescriptor(imagePath : String) : ImageDescriptor { + var descriptor = this.imageRegistry.getDescriptor(imagePath) + if (descriptor === null) { + descriptor = AbstractUIPlugin::imageDescriptorFromPlugin(PLUGIN_ID, imagePath) + if (descriptor !== null) { + this.imageRegistry.put(imagePath, descriptor) + } + } + return descriptor + } + + /** Replies the image for the given image path. + * + * @param imagePath - path of the image. + * @return the image. + */ + def getImage(imagePath : String) : Image { + var descriptor = this.imageRegistry.getDescriptor(imagePath) + if (descriptor === null) { + descriptor = AbstractUIPlugin::imageDescriptorFromPlugin(PLUGIN_ID, imagePath) + if (descriptor !== null) { + var img = descriptor.createImage + this.imageRegistry.put(imagePath, img) + return img + } + } + return null + } + } diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexResultDialog.sarl b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexResultDialog.sarl new file mode 100644 index 0000000000..9e3ab6dd0b --- /dev/null +++ b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/SarlExperienceIndexResultDialog.sarl @@ -0,0 +1,145 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2017 the original authors or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.sarl.experienceindex.eclipse + +import java.lang.ref.SoftReference +import java.text.MessageFormat + +import org.eclipse.jface.dialogs.Dialog +import org.eclipse.jface.dialogs.IDialogConstants +import org.eclipse.jface.dialogs.IconAndMessageDialog +import org.eclipse.swt.SWT +import org.eclipse.swt.graphics.Color +import org.eclipse.swt.graphics.Font +import org.eclipse.swt.graphics.GC +import org.eclipse.swt.graphics.Image +import org.eclipse.swt.widgets.Composite +import org.eclipse.swt.widgets.Control +import org.eclipse.swt.widgets.Shell + +import io.sarl.experienceindex.SarlExperienceIndex.SEI + +/** + * Dialog that shows the results for the SARL experience index. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.6 + */ +class SarlExperienceIndexResultDialog extends IconAndMessageDialog { + + static val GLOBAL_ICON_SIZE = 256 + + static val BACKGROUND_IMAGE = "icons/sei_background.png" + + static val ICON = "icons/sei.png" + + static val SEI_FONT = "arial" + + static val SEI_FONT_SIZE = 110 + + static val SEI_FONT_STYLE = SWT::BOLD + + static val SEI_FONT_COLOR_RED = 94 + static val SEI_FONT_COLOR_GREEN = 105 + static val SEI_FONT_COLOR_BLUE = 114 + + val sei : SEI + + var globalImage : SoftReference + + /** Construct the dialog. + * + * @param parentShell the parent shell. + * @param sei the Sarl experience index. + */ + new (parentShell : Shell, sei : SEI) { + super(parentShell) + this.sei = sei + this.message = MessageFormat::format( + Messages::SarlExperienceIndexResultDialog_0, + sei.baseScore, + sei.cpuScore, + sei.memoryScore, + sei.diskScore) + } + + /** + * Opens a SEI dialog to display the results of the SEI computation. + * + * @param parent the parent shell of the dialog, or {@code null} if none. + * @param sei the Sarl experience index. + * @return the code of the button that was pressed that resulted in this + * dialog closing. This will be {@link Dialog#OK} if the OK + * button was pressed, or {@link Dialog#CANCEL} if this + * dialog's close window decoration or the ESC key was used. + */ + static def open(parent : Shell, sei : SEI) : int { + val dialog = new SarlExperienceIndexResultDialog(parent, sei) + dialog.open + } + + protected override createDialogArea(parent : Composite) : Control { + var composite = super.createDialogArea(parent) as Composite + composite.createMessageArea + return composite + } + + protected override getImage : Image { + var img = this.globalImage?.get + if (img === null) { + var display = this.shell.display + img = new Image(display, GLOBAL_ICON_SIZE, GLOBAL_ICON_SIZE) + var gc = new GC(img) + var backimg = SarlExperienceIndexPlugin::^default.getImage(BACKGROUND_IMAGE) + gc.antialias = SWT::ON + gc.drawImage(backimg, 0, 0) + backimg.dispose + gc.foreground = new Color(display, SEI_FONT_COLOR_RED, SEI_FONT_COLOR_GREEN, SEI_FONT_COLOR_BLUE) + var newFont = new Font(display, SEI_FONT, SEI_FONT_SIZE, SEI_FONT_STYLE) + gc.font = newFont + var text = MessageFormat::format(Messages::SarlExperienceIndexResultDialog_1, this.sei.baseScore) + var size = gc.textExtent(text) + gc.drawText(text, + (GLOBAL_ICON_SIZE - size.x) / 2, + (GLOBAL_ICON_SIZE - size.y) / 2, + SWT::DRAW_TRANSPARENT) + newFont.dispose + gc.dispose + this.globalImage = new SoftReference(img) + } + return img + } + + protected override configureShell(shell : Shell) { + super.configureShell(shell) + shell.text = Messages::SarlExperienceIndexResultDialog_2 + shell.setImage(SarlExperienceIndexPlugin.getDefault().getImage(ICON)); + } + + protected override createButtonsForButtonBar(parent : Composite) { + createButton(parent, IDialogConstants::OK_ID, IDialogConstants::OK_LABEL, true) + } + +} diff --git a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/messages.properties b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/messages.properties index 1924a3d3a0..471db55a4a 100644 --- a/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/messages.properties +++ b/contribs/io.sarl.experienceindex/io.sarl.experienceindex.plugin/src/io/sarl/experienceindex/eclipse/messages.properties @@ -1,3 +1,4 @@ SarlExperienceIndexEvaluatorHandler_0 = Computing the SARL experience index... -SarlExperienceIndexEvaluatorHandler_1 = SARL Experience Index -SarlExperienceIndexEvaluatorHandler_2 = The SARL experience index was computed. Results are:\n- Base Score: {0}\n- CPU Score: {1}\n- Memory Score: {2}\n- Disk Score: {3} \ No newline at end of file +SarlExperienceIndexResultDialog_0 = The SARL Experience index for your system is described below.\n- Global Score: {0,number,#0.0}\n- Processor Score: {1,number,#0.0}\n- Memory Score: {2,number,#0.0}\n- Hard-disk Score: {3,number,#0.0} +SarlExperienceIndexResultDialog_1 = {0,number,#0.0} +SarlExperienceIndexResultDialog_2 = SARL Experience Index (SEI) \ No newline at end of file diff --git a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/SARLEclipsePlugin.java b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/SARLEclipsePlugin.java index df04a08865..edbcb8ac6b 100644 --- a/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/SARLEclipsePlugin.java +++ b/main/coreplugins/io.sarl.eclipse/src/io/sarl/eclipse/SARLEclipsePlugin.java @@ -125,6 +125,9 @@ public ImageDescriptor getImageDescriptor(String imagePath) { ImageDescriptor descriptor = getImageRegistry().getDescriptor(imagePath); if (descriptor == null) { descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(SARLEclipsePlugin.PLUGIN_ID, imagePath); + if (descriptor != null) { + getImageRegistry().put(imagePath, descriptor); + } } return descriptor; }