Class BottomStatusBar
java.lang.Object
com.amalgamasimulation.desktop.appelements.parts.BottomStatusBar
Status bar at the bottom of the main window. By default it shows the active
perspective, the application version and the memory in use. A subclass adds
its own labels, for example the license or the cursor coordinates.
How to use
Register the class or its subclass as aToolControl in the bottom
TrimBar of the window (side="Bottom") in
Application.e4xmi. e4 creates the bar, injects the fields and calls
createControls(Composite, MToolControl). To add or move labels,
override createLabels().
Label positions
A label is placed by two bounds: the distance from the left edge of the bar to the left edge and to the right edge of the label, in percent of the bar width. For example, (20, 65) means the label starts at 20% of the width and ends at 65%. By default the perspective takes (0, 20), the version (65, 75) and the memory (75, 100). The bar does not check whether labels overlap. Create all labels increateLabels(): after it the bar gives them the
height of the tallest label, and a label created later does not get this
height.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.amalgamasimulation.desktop.utils.IAppInfoprotected org.eclipse.swt.widgets.Compositeprotected org.eclipse.e4.core.services.events.IEventBrokerprotected org.eclipse.e4.ui.workbench.modeling.EModelServiceprotected org.eclipse.e4.ui.model.application.ui.menu.MToolControl -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateControls(org.eclipse.swt.widgets.Composite parent, org.eclipse.e4.ui.model.application.ui.menu.MToolControl mToolControl) Creates the bar in the bottom trim of the window and callscreateLabels().protected org.eclipse.swt.widgets.LabelcreateLabel(int startPercentFromLeft, int endPercentFromLeft) Creates an empty label between two bounds, 5 pixels in from each of them.protected voidCreates the labels of the bar: the perspective at (0, 20), the version at (65, 75) and the memory at (75, 100).protected org.eclipse.swt.widgets.LabelcreateLicenseLabel(int startPercentFromLeft, int endPercentFromLeft, Supplier<String> licenseText) Creates a label with the license text.protected org.eclipse.swt.widgets.LabelcreateMemoryLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a right-aligned label with the used and maximum heap memory in megabytes.protected org.eclipse.swt.widgets.LabelcreatePerspectiveLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a label with the name of the active perspective of the window, updated onPlatformTopics.PERSPECTIVE_CHANGED.protected org.eclipse.swt.widgets.LabelcreateVersionLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a right-aligned label with the application version fromIAppInfo.getVersion(), read once when the label is created.voiddispose()Removes the subscriptions made withsubscribe(String, EventHandler).protected org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveReturns the active perspective of the window that holds the bar.protected voidSubscribes the handler to the topic througheventBrokerand remembers it;dispose()removes the subscription.
-
Field Details
-
eventBroker
@Inject protected org.eclipse.e4.core.services.events.IEventBroker eventBroker -
modelService
@Inject protected org.eclipse.e4.ui.workbench.modeling.EModelService modelService -
appInfo
@Inject protected com.amalgamasimulation.desktop.utils.IAppInfo appInfo -
mToolControl
protected org.eclipse.e4.ui.model.application.ui.menu.MToolControl mToolControl -
childComposite
protected org.eclipse.swt.widgets.Composite childComposite
-
-
Constructor Details
-
BottomStatusBar
public BottomStatusBar()
-
-
Method Details
-
createLabels
protected void createLabels()Creates the labels of the bar: the perspective at (0, 20), the version at (65, 75) and the memory at (75, 100). A subclass can callsuper.createLabels()and add its own labels in the free range (20, 65). It can also skipsuperand create all labels itself with other bounds, the perspective, version and memory labels included. -
createLabel
protected org.eclipse.swt.widgets.Label createLabel(int startPercentFromLeft, int endPercentFromLeft) Creates an empty label between two bounds, 5 pixels in from each of them. The caller sets the text and updates it.- Parameters:
startPercentFromLeft- distance from the left edge of the bar to the left edge of the label, in percent of the bar widthendPercentFromLeft- distance from the left edge of the bar to the right edge of the label, in percent of the bar width- Returns:
- the created label
-
createPerspectiveLabel
protected org.eclipse.swt.widgets.Label createPerspectiveLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a label with the name of the active perspective of the window, updated onPlatformTopics.PERSPECTIVE_CHANGED. By defaultcreateLabels()places it at (0, 20).- Parameters:
startPercentFromLeft- distance from the left edge of the bar to the left edge of the label, in percent of the bar widthendPercentFromLeft- distance from the left edge of the bar to the right edge of the label, in percent of the bar width- Returns:
- the created label
-
createLicenseLabel
protected org.eclipse.swt.widgets.Label createLicenseLabel(int startPercentFromLeft, int endPercentFromLeft, Supplier<String> licenseText) Creates a label with the license text. The text is taken fromlicenseTextwhen the label is created and on eachPlatformTopics.LICENSE_CHANGED.- Parameters:
startPercentFromLeft- distance from the left edge of the bar to the left edge of the label, in percent of the bar widthendPercentFromLeft- distance from the left edge of the bar to the right edge of the label, in percent of the bar widthlicenseText- returns the text to show- Returns:
- the created label
-
createVersionLabel
protected org.eclipse.swt.widgets.Label createVersionLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a right-aligned label with the application version fromIAppInfo.getVersion(), read once when the label is created. By defaultcreateLabels()places it at (65, 75).- Parameters:
startPercentFromLeft- distance from the left edge of the bar to the left edge of the label, in percent of the bar widthendPercentFromLeft- distance from the left edge of the bar to the right edge of the label, in percent of the bar width- Returns:
- the created label
-
createMemoryLabel
protected org.eclipse.swt.widgets.Label createMemoryLabel(int startPercentFromLeft, int endPercentFromLeft) Creates a right-aligned label with the used and maximum heap memory in megabytes. The label is updated every 5 seconds until it is disposed. A click runs the garbage collector and updates the label at once. By defaultcreateLabels()places it at (75, 100).- Parameters:
startPercentFromLeft- distance from the left edge of the bar to the left edge of the label, in percent of the bar widthendPercentFromLeft- distance from the left edge of the bar to the right edge of the label, in percent of the bar width- Returns:
- the created label
-
subscribe
Subscribes the handler to the topic througheventBrokerand remembers it;dispose()removes the subscription. The handler should check that its label is not disposed.- Parameters:
topic- event topichandler- handler of the topic events
-
dispose
@PreDestroy public void dispose()Removes the subscriptions made withsubscribe(String, EventHandler). e4 calls it when the bar is closed. -
getActivePerspective
protected org.eclipse.e4.ui.model.application.ui.advanced.MPerspective getActivePerspective()Returns the active perspective of the window that holds the bar.- Returns:
- active perspective