Esempio n. 1
0
  /**
   * Returns the alpha channel of the highlight color scheme of the component.
   *
   * @param comp Component.
   * @param componentState Component state.
   * @return Highlight color scheme alpha channel.
   */
  public final float getHighlightAlpha(Component comp, ComponentState componentState) {
    // small optimization - lookup the decoration area only if there
    // are decoration-specific scheme bundles.
    if (this.colorSchemeBundleMap.size() > 1) {
      DecorationAreaType decorationAreaType = SubstanceLookAndFeel.getDecorationType(comp);
      if (this.colorSchemeBundleMap.containsKey(decorationAreaType)) {
        Float registered =
            this.colorSchemeBundleMap
                .get(decorationAreaType)
                .getHighlightAlpha(comp, componentState);
        if (registered >= 0.0) return registered;
      }
    }

    Float registered =
        this.colorSchemeBundleMap
            .get(DecorationAreaType.NONE)
            .getHighlightAlpha(comp, componentState);
    if (registered >= 0.0) return registered;

    boolean isRollover = componentState.isFacetActive(ComponentStateFacet.ROLLOVER);
    boolean isSelected = componentState.isFacetActive(ComponentStateFacet.SELECTION);
    boolean isArmed = componentState.isFacetActive(ComponentStateFacet.ARM);

    if (isRollover && isSelected) return 0.9f;
    if (isRollover && isArmed) return 0.8f;
    if (isSelected) return 0.7f;
    if (isArmed) return 0.6f;
    if (isRollover) return 0.4f;
    return 0.0f;
  }
  /**
   * Returns the color scheme of the specified component in the specified component state.
   *
   * @param comp Component.
   * @param componentState Component state.
   * @return The color scheme of the component in the specified component state.
   */
  public SubstanceColorScheme getColorScheme(ComponentState componentState) {
    SubstanceColorScheme registered =
        this.colorSchemeMap.get(ColorSchemeAssociationKind.FILL).get(componentState);
    if (registered != null) return registered;

    // if (componentState.isActive()) {
    // for now look for the best fit only on active states
    Map<ComponentState, ComponentState> bestFitForFill =
        this.bestFillMap.get(ColorSchemeAssociationKind.FILL);
    if (!bestFitForFill.containsKey(componentState)) {
      Collection<ComponentState> registeredStates =
          this.colorSchemeMap.get(ColorSchemeAssociationKind.FILL).keySet();
      bestFitForFill.put(componentState, componentState.bestFit(registeredStates));
    }
    ComponentState bestFit = bestFitForFill.get(componentState);
    if (bestFit != null) {
      registered = this.colorSchemeMap.get(ColorSchemeAssociationKind.FILL).get(bestFit);
      if (registered != null) return registered;
    }
    // }

    if (componentState.isFacetActive(ComponentStateFacet.PRESS)) {
      if (this.pressedScheme == null) {
        this.pressedScheme = this.activeColorScheme.shade(0.2).saturate(0.1);
      }
      return this.pressedScheme;
    }
    if (componentState == ComponentState.DISABLED_SELECTED) {
      if (this.disabledSelectedScheme == null) {
        this.disabledSelectedScheme =
            new BlendBiColorScheme(this.activeColorScheme, this.disabledColorScheme, 0.25);
      }
      return this.disabledSelectedScheme;
    }
    if (componentState == ComponentState.SELECTED) {
      if (this.selectedScheme == null) {
        this.selectedScheme = this.activeColorScheme.saturate(0.2);
      }
      return this.selectedScheme;
    }
    if (componentState == ComponentState.ROLLOVER_SELECTED) {
      if (this.rolloverSelectedScheme == null) {
        this.rolloverSelectedScheme = this.activeColorScheme.tint(0.1).saturate(0.1);
      }
      return this.rolloverSelectedScheme;
    }

    ComponentState hardFallback = componentState.getHardFallback();
    if (hardFallback != null) return this.getColorScheme(hardFallback);

    if (componentState == ComponentState.ENABLED) return this.enabledColorScheme;
    if (componentState.isDisabled()) return this.disabledColorScheme;
    return this.activeColorScheme;
  }
  /**
   * Computes the alpha value for painting the separators.
   *
   * @return Alpha value for painting the separators.
   */
  private float getSeparatorAlpha() {
    ComponentState actionAreaState =
        this.getActionTransitionTracker().getModelStateInfo().getCurrModelState();

    if (!actionAreaState.isFacetActive(ComponentStateFacet.SELECTION)
        && !actionAreaState.isDisabled()) {
      float actionRolloverCycle =
          this.getActionTransitionTracker().getFacetStrength(ComponentStateFacet.ROLLOVER);
      float popupRolloverCycle =
          this.getPopupTransitionTracker().getFacetStrength(ComponentStateFacet.ROLLOVER);
      return Math.min(1.0f, actionRolloverCycle + popupRolloverCycle);
    }
    return 1.0f;
  }