summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Kriese2010-08-19 03:00:21 (EDT)
committerSteffen Kriese2010-08-19 03:00:21 (EDT)
commit51db977b44a8d5ad959afdfe49ad74317af48ce9 (patch)
treee1415eb60910629aef805632b958510d9d0953a9
parenta7042935a6099dfe3356b7983bfa9549483372a6 (diff)
downloadorg.eclipse.riena-51db977b44a8d5ad959afdfe49ad74317af48ce9.zip
org.eclipse.riena-51db977b44a8d5ad959afdfe49ad74317af48ce9.tar.gz
org.eclipse.riena-51db977b44a8d5ad959afdfe49ad74317af48ce9.tar.bz2
Applying Patch #323002 StatusMeterRidget
-rw-r--r--org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TableSubModuleController.java43
-rw-r--r--org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TraverseSubModuleController.java40
-rw-r--r--org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TableSubModuleView.java3
-rw-r--r--org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TraverseSubModuleView.java23
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IStatusMeterRidget.java46
-rw-r--r--org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeter.java346
-rw-r--r--org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeterWidget.java157
-rw-r--r--org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/LnfKeyConstants.java37
-rw-r--r--org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/rienadefault/RienaDefaultTheme.java7
-rw-r--r--org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/utils/UIControlsFactory.java29
10 files changed, 725 insertions, 6 deletions
diff --git a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TableSubModuleController.java b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TableSubModuleController.java
index e0f741a..cbfd3fa 100644
--- a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TableSubModuleController.java
+++ b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TableSubModuleController.java
@@ -21,7 +21,11 @@ import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.riena.beans.common.TypedComparator;
@@ -37,7 +41,9 @@ import org.eclipse.riena.ui.ridgets.ITableRidget;
import org.eclipse.riena.ui.ridgets.IToggleButtonRidget;
import org.eclipse.riena.ui.ridgets.listener.ISelectionListener;
import org.eclipse.riena.ui.ridgets.listener.SelectionEvent;
+import org.eclipse.riena.ui.ridgets.swt.ColumnFormatter;
import org.eclipse.riena.ui.ridgets.swt.NumberColumnFormatter;
+import org.eclipse.riena.ui.swt.StatusMeter;
/**
* Controller for the {@link TableSubModuleView} example.
@@ -48,8 +54,15 @@ public class TableSubModuleController extends SubModuleController {
private ITableRidget table;
private List<WordNode> input;
+ private Color green;
+ private Color darkGreen;
+
public TableSubModuleController() {
this(null);
+
+ final Display display = Display.getCurrent();
+ green = display.getSystemColor(SWT.COLOR_GREEN);
+ darkGreen = display.getSystemColor(SWT.COLOR_DARK_GREEN);
}
public TableSubModuleController(final ISubModuleNode navigationNode) {
@@ -67,21 +80,39 @@ public class TableSubModuleController extends SubModuleController {
private void bindModel() {
input = createInput();
- final String[] columnPropertyNames = { "word", "upperCase", "ACount", "AQuota" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- final String[] columnHeaders = { "Word", "Uppercase", "A Count", "A Quota [%]" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ final String[] columnPropertyNames = { "AQuota", "word", "upperCase", "ACount", "AQuota" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ final String[] columnHeaders = { "S", "Word", "Uppercase", "A Count", "A Quota [%]" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
table.bindToModel(new WritableList(input, WordNode.class), WordNode.class, columnPropertyNames, columnHeaders);
table.updateFromModel();
- table.setComparator(0, new TypedComparator<String>());
- table.setComparator(1, new TypedComparator<Boolean>());
- table.setColumnFormatter(3, new NumberColumnFormatter(Float.class, 2) {
+ table.setComparator(1, new TypedComparator<String>());
+ table.setComparator(2, new TypedComparator<Boolean>());
+ table.setColumnFormatter(4, new NumberColumnFormatter(Float.class, 2) {
@Override
protected Number getValue(final Object element) {
return ((WordNode) element).getAQuota();
}
});
- table.setColumnSortable(2, false);
+ table.setColumnSortable(3, false);
table.setSelectionType(ISelectableRidget.SelectionType.SINGLE);
table.setSelection(0);
+
+ table.setColumnFormatter(0, new ColumnFormatter() {
+ @Override
+ public String getText(final Object element) {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Image getImage(final Object element) {
+ if (((WordNode) element).isUpperCase()) {
+ return StatusMeter.imageFinished().width(16).gradientStartColor(green)
+ .gradientEndColor(darkGreen).getImage();
+ } else {
+ final int value = (int) ((WordNode) element).getAQuota();
+ return StatusMeter.imageDefault().width(16).value(value).getImage();
+ }
+ }
+ });
}
/**
diff --git a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TraverseSubModuleController.java b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TraverseSubModuleController.java
index f7d66e3..59babea 100644
--- a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TraverseSubModuleController.java
+++ b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/controllers/TraverseSubModuleController.java
@@ -11,11 +11,13 @@
package org.eclipse.riena.example.client.controllers;
import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.riena.beans.common.AbstractBean;
import org.eclipse.riena.navigation.ui.controllers.SubModuleController;
import org.eclipse.riena.ui.ridgets.IActionListener;
import org.eclipse.riena.ui.ridgets.ISpinnerRidget;
+import org.eclipse.riena.ui.ridgets.IStatusMeterRidget;
import org.eclipse.riena.ui.ridgets.ITraverseRidget;
/**
@@ -24,7 +26,9 @@ import org.eclipse.riena.ui.ridgets.ITraverseRidget;
*/
public class TraverseSubModuleController extends SubModuleController {
+ private static final int RANKINE_MAX = 582;
private final Temperature temperature;
+ private IStatusMeterRidget rankineStatusMeter;
/**
* Creates a new instance of {@code TraverseSubModuleController} and
@@ -67,6 +71,16 @@ public class TraverseSubModuleController extends SubModuleController {
kelvinProgressBar.bindToModel(BeansObservables.observeValue(temperature, Temperature.PROPERTY_KELVIN));
kelvinProgressBar.updateFromModel();
+ rankineStatusMeter = (IStatusMeterRidget) getRidget("rankineStatusMeter"); //$NON-NLS-1$
+ rankineStatusMeter.bindToModel(BeansObservables.observeValue(temperature, Temperature.PROPERTY_RANKINE));
+ rankineStatusMeter.setMaximum(RANKINE_MAX);
+ rankineStatusMeter.setMinimum(491);
+ // set custom colors
+ // rankineStatusMeter.setBackgroundColor(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW));
+ // rankineStatusMeter.setGradientStartColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
+ // rankineStatusMeter.setGradientEndColor(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
+ // rankineStatusMeter.setBorderColor(Display.getDefault().getSystemColor(SWT.COLOR_CYAN));
+ rankineStatusMeter.updateFromModel();
}
/**
@@ -77,10 +91,12 @@ public class TraverseSubModuleController extends SubModuleController {
static final String PROPERTY_DEGREE_CELSIUS = "degreeCelsius"; //$NON-NLS-1$
static final String PROPERTY_DEGREE_FAHRENHEITN = "degreeFahrenheit"; //$NON-NLS-1$
static final String PROPERTY_KELVIN = "kelvin"; //$NON-NLS-1$
+ static final String PROPERTY_RANKINE = "rankine"; //$NON-NLS-1$
private float kelvin;
private int degreeCelsius;
private int degreeFahrenheit;
+ private int rankine;
@SuppressWarnings("unused")
public void setDegreeCelsius(final int degreeCelsius) {
@@ -94,6 +110,7 @@ public class TraverseSubModuleController extends SubModuleController {
final float k = degreeCelsius + 273.15f;
setKelvin(k);
updateFahrenheit();
+ updateRankine();
}
firePropertyChanged(PROPERTY_DEGREE_CELSIUS, oldValue, degreeCelsius);
}
@@ -116,6 +133,7 @@ public class TraverseSubModuleController extends SubModuleController {
final float k = c + 273.15f;
setKelvin(k);
updateCelsius();
+ updateRankine();
}
firePropertyChanged(PROPERTY_DEGREE_FAHRENHEITN, oldValue, degreeFahrenheit);
}
@@ -134,6 +152,23 @@ public class TraverseSubModuleController extends SubModuleController {
return kelvin;
}
+ public void setRankine(final int rankine) {
+ this.rankine = rankine;
+
+ if (rankine == RANKINE_MAX) {
+ rankineStatusMeter.setGradientStartColor(new Color(null, 0, 255, 0));
+ rankineStatusMeter.setGradientEndColor(new Color(null, 0, 128, 0));
+ } else {
+ rankineStatusMeter.setGradientStartColor(new Color(null, 255, 255, 255));
+ rankineStatusMeter.setGradientEndColor(new Color(null, 0, 0, 128));
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public int getRankine() {
+ return rankine;
+ }
+
private void updateCelsius() {
final int c = Math.round(getKelvin() - 273.15f);
setDegreeCelsius(c, false);
@@ -145,6 +180,11 @@ public class TraverseSubModuleController extends SubModuleController {
setDegreeFahrenheit(f, false);
}
+ private void updateRankine() {
+ final int r = Math.round(getKelvin() * 9 / 5.0f);
+ setRankine(r);
+ }
+
}
private class TemperatureListener implements IActionListener {
diff --git a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TableSubModuleView.java b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TableSubModuleView.java
index 25453a2..39f8d4d 100644
--- a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TableSubModuleView.java
+++ b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TableSubModuleView.java
@@ -13,6 +13,7 @@ package org.eclipse.riena.example.client.views;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
@@ -59,12 +60,14 @@ public class TableSubModuleView extends SubModuleView {
table.setLinesVisible(true);
table.setHeaderVisible(true);
+ final TableColumn columnState = new TableColumn(table, SWT.CENTER);
final TableColumn columnWord = new TableColumn(table, SWT.LEFT);
final TableColumn columnUppercase = new TableColumn(table, SWT.LEFT);
final TableColumn columnACount = new TableColumn(table, SWT.LEFT);
final TableColumn columnAQuota = new TableColumn(table, SWT.LEFT);
final TableColumnLayout layout = new TableColumnLayout();
+ layout.setColumnData(columnState, new ColumnPixelData(30));
layout.setColumnData(columnWord, new ColumnWeightData(25));
layout.setColumnData(columnUppercase, new ColumnWeightData(25));
layout.setColumnData(columnACount, new ColumnWeightData(25));
diff --git a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TraverseSubModuleView.java b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TraverseSubModuleView.java
index 8d0ca70..8d18c03 100644
--- a/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TraverseSubModuleView.java
+++ b/org.eclipse.riena.example.client/src/org/eclipse/riena/example/client/views/TraverseSubModuleView.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.riena.example.client.views;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -18,6 +19,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.riena.navigation.ui.swt.views.SubModuleView;
+import org.eclipse.riena.ui.swt.StatusMeterWidget;
import org.eclipse.riena.ui.swt.utils.UIControlsFactory;
/**
@@ -88,6 +90,27 @@ public class TraverseSubModuleView extends SubModuleView {
final Label lbl300 = new Label(compositeKelvin, SWT.NONE);
lbl300.setText("323"); //$NON-NLS-1$
+ // Rankine (StatusMeter demo)
+ UIControlsFactory.createLabel(parent, "Rankine:"); //$NON-NLS-1$
+
+ final StatusMeterWidget statusMeter = UIControlsFactory.createStatusMeter(parent, "rankineStatusMeter"); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 24).applyTo(statusMeter);
+
+ new Label(parent, SWT.NONE);
+
+ final Composite compositeRankine = new Composite(parent, SWT.NONE);
+ compositeRankine.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ compositeRankine.setLayout(new GridLayout(3, false));
+
+ final Label lblRankineStart = new Label(compositeRankine, SWT.NONE);
+ lblRankineStart.setText("491"); //$NON-NLS-1$
+
+ final Label labelDummy3 = new Label(compositeRankine, SWT.NONE);
+ labelDummy3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
+
+ final Label lblRankineEnd = new Label(compositeRankine, SWT.NONE);
+ lblRankineEnd.setText("582"); //$NON-NLS-1$
+
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IStatusMeterRidget.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IStatusMeterRidget.java
new file mode 100644
index 0000000..041384e
--- /dev/null
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IStatusMeterRidget.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.ui.ridgets;
+
+/**
+ * Interface that reflects the extended possibilities of a
+ * {@link StatusMeterRidget} over a normal {@link ITraverseRidget}.
+ */
+public interface IStatusMeterRidget extends ITraverseRidget {
+
+ /**
+ * Set the border color of the StatusMeter.
+ *
+ * @param color
+ */
+ void setBorderColor(Object color);
+
+ /**
+ * Set the background color of the StatusMeter.
+ *
+ * @param color
+ */
+ void setBackgroundColor(Object color);
+
+ /**
+ * Set the gradient start color of the bar in the StatusMeter.
+ *
+ * @param color
+ */
+ void setGradientStartColor(Object color);
+
+ /**
+ * Set the gradient end color of the bar in the StatusMeter.
+ *
+ * @param color
+ */
+ void setGradientEndColor(Object color);
+}
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeter.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeter.java
new file mode 100644
index 0000000..e56b17c
--- /dev/null
+++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeter.java
@@ -0,0 +1,346 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.ui.swt;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.riena.ui.swt.lnf.LnfKeyConstants;
+import org.eclipse.riena.ui.swt.lnf.LnfManager;
+import org.eclipse.riena.ui.swt.lnf.rienadefault.RienaDefaultLnf;
+
+/**
+ * The StatusMeter is intended to visualize processes that run for much longer
+ * periods than those that are usually visualized by a <code>ProgressBar</code>.
+ * In difference to the <code>ProgressBar</code>, it offers the ability to
+ * change colors and it can be used in tables.
+ * <p>
+ * <b>NOTE:</b> This is an image factory for use in {@link ColumnFormatter} and
+ * alike. See {@link StatusMeterWidget} for an actual widget implementation.
+ * </p>
+ * <p>
+ * StatusMeter uses a builder pattern. Use one of the static methods to create a
+ * builder.
+ *
+ * @since 2.1
+ */
+public class StatusMeter {
+
+ protected StatusMeter() {
+ }
+
+ /**
+ * Creates an empty builder instance.
+ *
+ * @return A builder instance
+ */
+ public static StatusMeterBuilder empty() {
+ return new StatusMeterBuilder();
+ }
+
+ /**
+ * Creates a builder instance with the following values
+ * <ul>
+ * <li>maximum = 100
+ * <li>width = 100
+ * <li>height = 16
+ * <li>leftIndent = 1
+ * <li>margin = 1
+ * </ul>
+ *
+ * @return A builder instance
+ */
+ public static StatusMeterBuilder imageDefault() {
+ return new StatusMeterBuilder().maximum(100).width(100).height(16).leftIndent(1).margin(1);
+ }
+
+ /**
+ * Creates a builder instance with the following values
+ * <ul>
+ * <li>value = 100
+ * <li>maximum = 100
+ * <li>width = 100
+ * <li>height = 16
+ * <li>leftIndent = 1
+ * <li>margin = 1
+ * </ul>
+ *
+ * @return A builder instance
+ */
+ public static StatusMeterBuilder imageFinished() {
+ return new StatusMeterBuilder().value(100).maximum(100).width(100).height(16).leftIndent(1).margin(1);
+ }
+
+ /**
+ * Creates a builder instance with the following values
+ * <ul>
+ * <li>maximum = 100
+ * <li>width = 100
+ * <li>height = 16
+ * <li>leftIndent = 0
+ * <li>margin = 0
+ * </ul>
+ *
+ * @return A builder instance
+ */
+ public static StatusMeterBuilder widgetDefault() {
+ return StatusMeter.imageDefault().leftIndent(0).margin(0);
+ }
+
+ /**
+ * Creates a builder instance with the following values
+ * <ul>
+ * <li>value = 100
+ * <li>maximum = 100
+ * <li>width = 100
+ * <li>height = 16
+ * <li>leftIndent = 0
+ * <li>margin = 0
+ * </ul>
+ *
+ * @return A builder instance
+ */
+ public static StatusMeterBuilder widgetFinished() {
+ return StatusMeter.imageFinished().leftIndent(0).margin(0);
+ }
+
+ /**
+ * Builder for StatusMeter
+ *
+ * @see StatusMeter
+ */
+ public static final class StatusMeterBuilder {
+ private int value = 0;
+ private int maximum = 100;
+ private int minimum = 0;
+ private int width = 0;
+ private int height = 0;
+ private int indent = 0;
+ private int margin = 0;
+
+ private Color borderColor;
+ private Color gradientStartColor;
+ private Color gradientEndColor;
+ private Color backgroundColor;
+ private final Color transparentColor;
+
+ private static final int BORDER_WIDTH = 1;
+
+ private StatusMeterBuilder() {
+ final RienaDefaultLnf lnf = LnfManager.getLnf();
+ borderColor = lnf.getColor(LnfKeyConstants.STATUS_METER_BORDER_COLOR);
+ gradientStartColor = lnf.getColor(LnfKeyConstants.STATUS_METER_GRADIENT_START_COLOR);
+ gradientEndColor = lnf.getColor(LnfKeyConstants.STATUS_METER_GRADIENT_END_COLOR);
+ backgroundColor = lnf.getColor(LnfKeyConstants.STATUS_METER_BACKGROUND_COLOR);
+ transparentColor = lnf.getColor(LnfKeyConstants.STATUS_METER_TRANSPARENT_COLOR);
+ }
+
+ /**
+ * Returns a StatusMeter as image.
+ *
+ * @return An image according to the values set to the builder
+ * @throws IllegalArgumentException
+ * if conditions that are described in the setter methods
+ * are violated
+ */
+ public Image getImage() {
+ if (width <= 0 || height <= 0) {
+ throw new IllegalArgumentException("Width and height must be values greater than 0 to draw."); //$NON-NLS-1$
+ }
+ if (value < 0 || value > maximum) {
+ throw new IllegalArgumentException("Value must be positive and smaller or equal to the maximum value."); //$NON-NLS-1$
+ }
+ if (minimum < 0) {
+ throw new IllegalArgumentException("Minimum must be positive."); //$NON-NLS-1$
+ }
+ if (margin < 0 || margin > (height / 2) || margin > (width / 2)) {
+ throw new IllegalArgumentException(
+ "Margin must be positive and must not be greater than half of the height and half of the width."); //$NON-NLS-1$
+ }
+ if (indent < 0 || indent > width) {
+ throw new IllegalArgumentException(
+ "Indentation must be positive and must not be greater than the total width."); //$NON-NLS-1$
+ }
+
+ // TODO sma@2010-08-17 Is this the Riena way?
+ final Display display = Display.getCurrent();
+
+ final Image image = new Image(display, width, height);
+ final GC gc = new GC(image);
+
+ final int start = margin + indent + BORDER_WIDTH;
+ final int end = width - (margin * 2) - BORDER_WIDTH - 1;
+ final int barHeight = height - (margin * 2) - (BORDER_WIDTH * 2);
+
+ final int actualWidth = end - start + 1;
+ final float scale = (float) actualWidth / (maximum - minimum);
+ final int actualValue = (int) ((value - minimum) * scale);
+
+ // Background
+ gc.setBackground(transparentColor);
+ gc.fillRectangle(0, 0, width, height);
+
+ // Progress
+ gc.setForeground(gradientStartColor);
+ gc.setBackground(gradientEndColor);
+ gc.fillGradientRectangle(start, margin + BORDER_WIDTH, actualValue, barHeight, true);
+
+ // Background
+ gc.setBackground(backgroundColor);
+ gc.fillRectangle(start + actualValue, margin + BORDER_WIDTH, actualWidth - actualValue, barHeight);
+
+ // Border
+ gc.setForeground(borderColor);
+ final int bottom = height - margin - 1;
+ // horizontal lines
+ gc.drawLine(start, margin, end, margin);
+ gc.drawLine(start, bottom, end, bottom);
+ // vertical lines
+ gc.drawLine(start - BORDER_WIDTH, margin + BORDER_WIDTH, start - BORDER_WIDTH, bottom - BORDER_WIDTH);
+ gc.drawLine(end + BORDER_WIDTH, margin + BORDER_WIDTH, end + BORDER_WIDTH, bottom - BORDER_WIDTH);
+
+ gc.dispose();
+
+ final ImageData imageData = image.getImageData();
+ imageData.transparentPixel = imageData.palette.getPixel(transparentColor.getRGB());
+ return new Image(display, imageData);
+ }
+
+ /**
+ * Value must be positive and must not exceed the set maximum.
+ *
+ * @param value
+ * @return The builder
+ */
+ public StatusMeterBuilder value(final int value) {
+ this.value = value;
+ return this;
+ }
+
+ /**
+ * Maximum must be positive and greater or equal to the set value.
+ *
+ * @param max
+ * @return The builder
+ */
+ public StatusMeterBuilder maximum(final int max) {
+ this.maximum = max;
+ return this;
+ }
+
+ /**
+ * Minimum must be positive.
+ *
+ * @param min
+ * @return The builder
+ */
+ public StatusMeterBuilder minimum(final int min) {
+ this.minimum = min;
+ return this;
+ }
+
+ /**
+ * Width must be greater than 0.
+ *
+ * @param width
+ * @return The builder
+ */
+ public StatusMeterBuilder width(final int width) {
+ this.width = width;
+ return this;
+ }
+
+ /**
+ * Height must be greater than 0.
+ *
+ * @param height
+ * @return The builder
+ */
+ public StatusMeterBuilder height(final int height) {
+ this.height = height;
+ return this;
+ }
+
+ /**
+ * Indent must be positive and smaller than the set width.
+ *
+ * @param indent
+ * @return The builder
+ */
+ public StatusMeterBuilder leftIndent(final int indent) {
+ this.indent = indent;
+ return this;
+ }
+
+ /**
+ * Margin must be positive and smaller than half of the set height and
+ * half of the set width.
+ *
+ * @param margin
+ * @return The builder
+ */
+ public StatusMeterBuilder margin(final int margin) {
+ this.margin = margin;
+ return this;
+ }
+
+ /**
+ * The color that is used for the border. Default is set in
+ * {@link RienaDefaultLnf}.
+ *
+ * @param color
+ * @return The builder
+ */
+ public StatusMeterBuilder borderColor(final Color color) {
+ this.borderColor = color;
+ return this;
+ }
+
+ /**
+ * The color that is used for the background area that is not filed with
+ * the bar. Default is set in {@link RienaDefaultLnf}.
+ *
+ * @param color
+ * @return The builder
+ */
+ public StatusMeterBuilder backgroundColor(final Color color) {
+ this.backgroundColor = color;
+ return this;
+ }
+
+ /**
+ * The start color that makes the gradient of the bar. Default is set in
+ * {@link RienaDefaultLnf}.
+ *
+ * @param color
+ * @return The builder
+ */
+ public StatusMeterBuilder gradientStartColor(final Color color) {
+ this.gradientStartColor = color;
+ return this;
+ }
+
+ /**
+ * The end color that makes the gradient of the bar. Default is set in
+ * {@link RienaDefaultLnf}.
+ *
+ * @param color
+ * @return The builder
+ */
+ public StatusMeterBuilder gradientEndColor(final Color color) {
+ this.gradientEndColor = color;
+ return this;
+ }
+ }
+}
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeterWidget.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeterWidget.java
new file mode 100644
index 0000000..a41b294
--- /dev/null
+++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/StatusMeterWidget.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 compeople AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.riena.ui.swt;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+
+import org.eclipse.riena.ui.swt.StatusMeter.StatusMeterBuilder;
+
+/**
+ * A widget displaying a StatusMeter image.
+ *
+ * @see StatusMeter
+ * @since 2.1
+ */
+public final class StatusMeterWidget extends Composite {
+ private int value = 0;
+ private int maximum = 100;
+ private int minimum = 0;
+
+ private final StatusMeterBuilder builder = StatusMeter.widgetDefault();
+
+ /**
+ * Creates a {@link StatusMeterWidget} without a style.
+ *
+ * @param parent
+ */
+ public StatusMeterWidget(final Composite parent) {
+ this(parent, SWT.NONE);
+ }
+
+ /**
+ * Create a {@link StatusMeterWidget}. The style is equal to the style of
+ * {@link Composite}.
+ *
+ * @see Composite
+ * @param parent
+ * @param style
+ */
+ public StatusMeterWidget(final Composite parent, final int style) {
+ super(parent, style);
+
+ this.addPaintListener(new PaintListener() {
+ public void paintControl(final PaintEvent e) {
+ final Rectangle bounds = getBounds();
+
+ if (bounds.width != 0 && bounds.height != 0) {
+ e.gc.drawImage(builder.width(bounds.width).height(bounds.height).getImage(), 0, 0);
+ }
+ }
+ });
+ }
+
+ /**
+ * Set the value.
+ *
+ * @see StatusMeterBuilder#value(int)
+ * @param value
+ */
+ public void setValue(final int value) {
+ this.value = value;
+ builder.value(value);
+ redraw();
+ }
+
+ /**
+ * @return The value
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Set the maximum value.
+ *
+ * @see StatusMeterBuilder#maximum(int)
+ * @param max
+ */
+ public void setMaximum(final int max) {
+ this.maximum = max;
+ builder.maximum(max);
+ }
+
+ /**
+ * @return The maximum value
+ */
+ public int getMaximum() {
+ return maximum;
+ }
+
+ /**
+ * Set the minimum.
+ *
+ * @see StatusMeterBuilder#minimum(int)
+ * @param min
+ */
+ public void setMinimum(final int min) {
+ this.minimum = min;
+ builder.minimum(min);
+ }
+
+ /**
+ * @return The minimum value
+ */
+ public int getMinimum() {
+ return minimum;
+ }
+
+ /**
+ * Set the border color.
+ *
+ * @see StatusMeterBuilder#borderColor(Color)
+ * @param color
+ */
+ public void setBorderColor(final Color color) {
+ builder.borderColor(color);
+ }
+
+ /**
+ * Set the background color.
+ *
+ * @see StatusMeterBuilder#backgroundColor(Color)
+ * @param color
+ */
+ public void setBackgroundColor(final Color color) {
+ builder.backgroundColor(color);
+ }
+
+ /**
+ * Set the gradient start color.
+ *
+ * @see StatusMeterBuilder#gradientStartColor(Color)
+ * @param color
+ */
+ public void setGradientStartColor(final Color color) {
+ builder.gradientStartColor(color);
+ }
+
+ /**
+ * Set the gradient end color.
+ *
+ * @see StatusMeterBuilder#gradientEndColor(Color)
+ * @param color
+ */
+ public void setGradientEndColor(final Color color) {
+ builder.gradientEndColor(color);
+ }
+}
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/LnfKeyConstants.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/LnfKeyConstants.java
index e8e5188..b44bc7d 100644
--- a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/LnfKeyConstants.java
+++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/LnfKeyConstants.java
@@ -16,6 +16,7 @@ import org.eclipse.riena.ui.core.marker.ErrorMarker;
import org.eclipse.riena.ui.core.marker.MandatoryMarker;
import org.eclipse.riena.ui.core.marker.UIProcessFinishedMarker;
import org.eclipse.riena.ui.swt.InfoFlyout;
+import org.eclipse.riena.ui.swt.StatusMeter;
/**
* Keys of the look and feel of riena.
@@ -1074,6 +1075,42 @@ public final class LnfKeyConstants {
*/
public static final String TITLEBAR_SEPARATOR_SECOND_LINE_FOREGROUND = "titlebar.separator.secondtline.color"; //$NON-NLS-1$
+ /**
+ * The border color for {@link StatusMeter}.
+ *
+ * @since 2.1
+ */
+ public static final String STATUS_METER_BORDER_COLOR = "StatusMeter.borderColor"; //$NON-NLS-1$
+
+ /**
+ * The background color for {@link StatusMeter}.
+ *
+ * @since 2.1
+ */
+ public static final String STATUS_METER_BACKGROUND_COLOR = "StatusMeter.backgroundColor"; //$NON-NLS-1$
+
+ /**
+ * The gradient start color for the bar in {@link StatusMeter}.
+ *
+ * @since 2.1
+ */
+ public static final String STATUS_METER_GRADIENT_START_COLOR = "StatusMeter.gradientStartColor"; //$NON-NLS-1$
+
+ /**
+ * The gradient end color for the bar in {@link StatusMeter}.
+ *
+ * @since 2.1
+ */
+ public static final String STATUS_METER_GRADIENT_END_COLOR = "StatusMeter.gradientEndColor"; //$NON-NLS-1$
+
+ /**
+ * The color used to create a transparent background around the bar of
+ * {@link StatusMeter}.
+ *
+ * @since 2.1
+ */
+ public static final String STATUS_METER_TRANSPARENT_COLOR = "StatusMeter.transperentColor"; //$NON-NLS-1$
+
private LnfKeyConstants() {
super();
}
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/rienadefault/RienaDefaultTheme.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/rienadefault/RienaDefaultTheme.java
index 6b34dc9..de90d36 100644
--- a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/rienadefault/RienaDefaultTheme.java
+++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/lnf/rienadefault/RienaDefaultTheme.java
@@ -207,6 +207,13 @@ public class RienaDefaultTheme implements ILnfTheme {
new ColorLnfResource(212, 208, 200));
lnf.putLnfResource(LnfKeyConstants.TITLEBAR_SEPARATOR_SECOND_LINE_FOREGROUND, new ColorLnfResource(245, 245,
245));
+
+ // StatusMeter
+ lnf.putLnfResource(LnfKeyConstants.STATUS_METER_BORDER_COLOR, new ColorLnfResource(128, 128, 128));
+ lnf.putLnfResource(LnfKeyConstants.STATUS_METER_BACKGROUND_COLOR, new ColorLnfResource(255, 255, 255));
+ lnf.putLnfResource(LnfKeyConstants.STATUS_METER_GRADIENT_START_COLOR, new ColorLnfResource(255, 255, 255));
+ lnf.putLnfResource(LnfKeyConstants.STATUS_METER_GRADIENT_END_COLOR, new ColorLnfResource(0, 0, 128));
+ lnf.putLnfResource(LnfKeyConstants.STATUS_METER_TRANSPARENT_COLOR, new ColorLnfResource(255, 0, 255));
}
private void customizeSWTControls(final ILnfCustomizer lnf) {
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/utils/UIControlsFactory.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/utils/UIControlsFactory.java
index b5ccdc3..576c36d 100644
--- a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/utils/UIControlsFactory.java
+++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/utils/UIControlsFactory.java
@@ -51,6 +51,7 @@ import org.eclipse.riena.ui.swt.ImageButton;
import org.eclipse.riena.ui.swt.InfoFlyout;
import org.eclipse.riena.ui.swt.MasterDetailsComposite;
import org.eclipse.riena.ui.swt.MessageBox;
+import org.eclipse.riena.ui.swt.StatusMeterWidget;
import org.eclipse.riena.ui.swt.facades.SWTFacade;
import org.eclipse.riena.ui.swt.lnf.LnfKeyConstants;
import org.eclipse.riena.ui.swt.lnf.LnfManager;
@@ -1610,6 +1611,34 @@ public class UIControlsFactory {
}
/**
+ * Create a {@link StatusMeterWidget} control.
+ *
+ * @param parent
+ * the parent composite; never null
+ */
+ public static StatusMeterWidget createStatusMeter(final Composite parent) {
+ return new StatusMeterWidget(parent);
+ }
+
+ /**
+ * Create a {@link StatusMeterWidget} control.
+ *
+ * @param parent
+ * the parent composite; never null
+ * @param bindingId
+ * the binding property; never null; must not be empty. The given
+ * value will also be assigned to the Ridget that is paired to
+ * this control.
+ *
+ * @wbp.factory.parameter.source bindingId "myStatusMeterId"
+ */
+ public static StatusMeterWidget createStatusMeter(final Composite parent, final String bindingId) {
+ final StatusMeterWidget statusMeter = createStatusMeter(parent);
+ SWTBindingPropertyLocator.getInstance().setBindingProperty(statusMeter, bindingId);
+ return statusMeter;
+ }
+
+ /**
* Create a {@link Slider} control.
*
* @param parent