Skip to content

Commit

Permalink
[contribs] Better UI for SEI results.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 13, 2017
2 parents 52d7913 + a237a97 commit 725aaae
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 17 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -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 {
}
Expand Down
Expand Up @@ -21,16 +21,13 @@

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
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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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
}

}
@@ -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<Image>

/** 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)
}

}
@@ -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}
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)
Expand Up @@ -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;
}
Expand Down

0 comments on commit 725aaae

Please sign in to comment.