예제 #1
0
  private void setAppIconAndText(final State state) {
    iconPane.getChildren().clear();

    switch (state) {
      case ACTIVE:
        appIcon.setForegroundIconColor(Color.GREEN);
        iconPane.add(appIcon, 0, 0);
        observerText.setIdentifier("active");
        if (!toggleSwitch.isSelected()) {
          toggleSwitch.setSelected(true);
        }
        break;
      case DEACTIVE:
        appIcon.changeForegroundIcon(MaterialDesignIcon.POWER);
        iconPane.add(appIcon, 0, 0);
        observerText.setIdentifier("inactive");
        if (toggleSwitch.isSelected()) {
          toggleSwitch.setSelected(false);
        }
        break;
      default:
        iconPane.add(unknownBackgroundIcon, 0, 0);
        iconPane.add(unknownForegroundIcon, 0, 0);
        observerText.setIdentifier("unknown");
        break;
    }
  }
예제 #2
0
  @Override
  protected void initTitle() {
    oneClick.addListener(
        (observable, oldValue, newValue) ->
            GlobalCachedExecutorService.submit(
                new Task() {
                  @Override
                  protected Object call() {
                    if (toggleSwitch.isSelected()) {
                      sendStateToRemote(ActivationState.State.DEACTIVE);
                    } else {
                      sendStateToRemote(ActivationState.State.ACTIVE);
                    }
                    return null;
                  }
                }));

    toggleSwitch.setOnMouseClicked(
        event ->
            GlobalCachedExecutorService.submit(
                new Task() {
                  @Override
                  protected Object call() {
                    if (toggleSwitch.isSelected()) {
                      sendStateToRemote(ActivationState.State.ACTIVE);
                    } else {
                      sendStateToRemote(ActivationState.State.DEACTIVE);
                    }
                    return null;
                  }
                }));

    unknownForegroundIcon.setForegroundIconColor(Color.BLUE);
    unknownBackgroundIcon.setForegroundIconColor(Color.WHITE);

    headContent.setCenter(getUnitLabel());
    headContent.setAlignment(getUnitLabel(), Pos.CENTER_LEFT);
    headContent.prefHeightProperty().set(appIcon.getHeight() + Constants.INSETS);
  }