Class BottomStatusBar

java.lang.Object
com.amalgamasimulation.desktop.appelements.parts.BottomStatusBar

public class BottomStatusBar extends Object
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 a ToolControl 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 in createLabels(): after it the bar gives them the height of the tallest label, and a label created later does not get this height.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.amalgamasimulation.desktop.utils.IAppInfo
     
    protected org.eclipse.swt.widgets.Composite
     
    protected org.eclipse.e4.core.services.events.IEventBroker
     
    protected org.eclipse.e4.ui.workbench.modeling.EModelService
     
    protected org.eclipse.e4.ui.model.application.ui.menu.MToolControl
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    createControls(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 calls createLabels().
    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.
    protected void
    Creates 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.Label
    createLicenseLabel(int startPercentFromLeft, int endPercentFromLeft, Supplier<String> licenseText)
    Creates a label with the license text.
    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.
    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 on PlatformTopics.PERSPECTIVE_CHANGED.
    protected org.eclipse.swt.widgets.Label
    createVersionLabel(int startPercentFromLeft, int endPercentFromLeft)
    Creates a right-aligned label with the application version from IAppInfo.getVersion(), read once when the label is created.
    void
    Removes the subscriptions made with subscribe(String, EventHandler).
    protected org.eclipse.e4.ui.model.application.ui.advanced.MPerspective
    Returns the active perspective of the window that holds the bar.
    protected void
    subscribe(String topic, org.osgi.service.event.EventHandler handler)
    Subscribes the handler to the topic through eventBroker and remembers it; dispose() removes the subscription.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

    • createControls

      @PostConstruct public void createControls(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 calls createLabels(). Then gives all labels the height of the tallest one, so that the bar does not get lower while the labels are empty. e4 calls it once.
      Parameters:
      parent - composite of the bottom trim bar of the window
      mToolControl - tool control of the bar in the application model
    • 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 call super.createLabels() and add its own labels in the free range (20, 65). It can also skip super and 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 width
      endPercentFromLeft - 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 on PlatformTopics.PERSPECTIVE_CHANGED. By default createLabels() 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 width
      endPercentFromLeft - 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 from licenseText when the label is created and on each PlatformTopics.LICENSE_CHANGED.
      Parameters:
      startPercentFromLeft - distance from the left edge of the bar to the left edge of the label, in percent of the bar width
      endPercentFromLeft - distance from the left edge of the bar to the right edge of the label, in percent of the bar width
      licenseText - 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 from IAppInfo.getVersion(), read once when the label is created. By default createLabels() 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 width
      endPercentFromLeft - 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 default createLabels() 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 width
      endPercentFromLeft - 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

      protected void subscribe(String topic, org.osgi.service.event.EventHandler handler)
      Subscribes the handler to the topic through eventBroker and remembers it; dispose() removes the subscription. The handler should check that its label is not disposed.
      Parameters:
      topic - event topic
      handler - handler of the topic events
    • dispose

      @PreDestroy public void dispose()
      Removes the subscriptions made with subscribe(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