/** * 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; }
/* * (non-Javadoc) * * @seeorg.jvnet.flamingo.common.ui.BasicCommandButtonUI# * paintButtonVerticalSeparator(java.awt.Graphics, int) */ @Override protected void paintButtonVerticalSeparator(Graphics graphics, Rectangle separatorArea) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.translate(separatorArea.x, 0); SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ColorSchemeAssociationKind.SEPARATOR, ComponentState.getState(this.commandButton.getActionModel(), this.commandButton)); float fadeAlpha = this.getSeparatorAlpha(); g2d.setComposite(AlphaComposite.SrcOver.derive(fadeAlpha)); SeparatorPainterUtils.paintSeparator( this.commandButton, g2d, colorScheme, 1, this.commandButton.getHeight(), JSlider.VERTICAL, true, 4, 4, true); g2d.dispose(); }
/** * Returns the color scheme to be used for painting the specified visual area of the component * under the specified component state. * * @param comp Component. * @param associationKind Color scheme association kind. * @param componentState Component state. * @return Color scheme to be used for painting the specified visual area of the component under * the specified component state. * @see #registerColorScheme(SubstanceColorScheme, ComponentState...) * @since version 5.1 */ public SubstanceColorScheme getColorScheme( ColorSchemeAssociationKind associationKind, ComponentState componentState) { if (associationKind == ColorSchemeAssociationKind.FILL) return this.getColorScheme(componentState); SubstanceColorScheme registered = this.colorSchemeMap.get(associationKind).get(componentState); if (registered != null) return registered; // if (componentState.isActive()) { // for now look for the best fit only on active states Map<ComponentState, ComponentState> bestFitForState = this.bestFillMap.get(associationKind); if (!bestFitForState.containsKey(componentState)) { Collection<ComponentState> registeredStates = this.colorSchemeMap.get(associationKind).keySet(); bestFitForState.put(componentState, componentState.bestFit(registeredStates)); } ComponentState bestFit = bestFitForState.get(componentState); if (bestFit != null) { registered = this.colorSchemeMap.get(associationKind).get(bestFit); if (registered != null) return registered; } // } ColorSchemeAssociationKind fallback = associationKind.getFallback(); if (fallback == null) return null; return getColorScheme(fallback, componentState); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paintButtonBackground * (java.awt.Graphics, java.awt.Rectangle) */ @Override protected void paintButtonBackground(Graphics graphics, Rectangle toFill) { if (SubstanceCoreUtilities.isButtonNeverPainted(this.commandButton)) return; ButtonModel actionModel = this.commandButton.getActionModel(); PopupButtonModel popupModel = ((JCommandButton) this.commandButton).getPopupModel(); Rectangle actionArea = this.getLayoutInfo().actionClickArea; Rectangle popupArea = this.getLayoutInfo().popupClickArea; BufferedImage fullAlphaBackground = CommandButtonBackgroundDelegate.getCombinedCommandButtonBackground( this.commandButton, actionModel, actionArea, popupModel, popupArea); // Two special cases here: // 1. Button has flat appearance and doesn't show the popup // 2. Button is disabled. // For both cases, we need to set custom translucency. boolean isFlat = this.commandButton.isFlat() && !((JCommandButton) this.commandButton).getPopupModel().isPopupShowing(); boolean isSpecial = isFlat || !this.commandButton.isEnabled(); float extraAlpha = 1.0f; if (isSpecial) { if (isFlat) { float extraActionAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getActionTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraActionAlpha += activeEntry.getValue().getContribution(); } float extraPopupAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getPopupTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraPopupAlpha += activeEntry.getValue().getContribution(); } extraAlpha = Math.max(extraActionAlpha, extraPopupAlpha); } else { ComponentState actionAreaState = ComponentState.getState(actionModel, this.commandButton); if (actionAreaState.isDisabled()) { extraAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, actionAreaState); } } } // System.out.println(extraAlpha); extraAlpha = Math.min(1.0f, extraAlpha); if (extraAlpha > 0.0f) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.setComposite( LafWidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics)); g2d.drawImage(fullAlphaBackground, 0, 0, null); g2d.dispose(); } }
/** * Registers a highlight color scheme for the specific component state if the component state is * not <code>null</code>, or a global highlight color scheme otherwise. * * @param highlightScheme Highlight color scheme for the specified component states. * @param alpha Alpha channel for the highlight color scheme. * @param states Component states. If <code>null</code>, the specified color scheme will be * applied for all states left unspecified. */ public void registerHighlightColorScheme( SubstanceColorScheme highlightScheme, float alpha, ComponentState... states) { if (highlightScheme == null) { throw new IllegalArgumentException("Cannot pass null color scheme"); } if ((states == null) || (states.length == 0)) { for (ComponentState state : ComponentState.getAllStates()) { if (state.isDisabled()) continue; if (state == ComponentState.ENABLED) continue; if (!this.colorSchemeMap.get(ColorSchemeAssociationKind.HIGHLIGHT).containsKey(state)) this.colorSchemeMap.get(ColorSchemeAssociationKind.HIGHLIGHT).put(state, highlightScheme); if (!this.stateHighlightSchemeAlphaMap.containsKey(state)) this.stateHighlightSchemeAlphaMap.put(state, alpha); } } else { for (ComponentState state : states) { this.colorSchemeMap.get(ColorSchemeAssociationKind.HIGHLIGHT).put(state, highlightScheme); this.stateHighlightSchemeAlphaMap.put(state, alpha); } } }
/** * Registers a highlight color scheme for the specific component state if the component state is * not <code>null</code>, or a global highlight color scheme otherwise. * * @param stateHighlightScheme Highlight color scheme for the specified component state. * @param states Component states. If <code>null</code>, the specified color scheme will be * applied for all states left unspecified. */ public void registerHighlightColorScheme( SubstanceColorScheme stateHighlightScheme, ComponentState... states) { if ((states == null) || (states.length == 0)) { for (ComponentState state : ComponentState.getAllStates()) { if (this.colorSchemeMap.get(ColorSchemeAssociationKind.HIGHLIGHT).containsKey(state)) continue; if (state.isDisabled()) continue; if (state == ComponentState.ENABLED) continue; // this.stateHighlightColorSchemeMap.put(state, // stateHighlightScheme); this.colorSchemeMap .get(ColorSchemeAssociationKind.HIGHLIGHT) .put(state, stateHighlightScheme); } } else { for (ComponentState state : states) { this.colorSchemeMap .get(ColorSchemeAssociationKind.HIGHLIGHT) .put(state, stateHighlightScheme); } } }
/** * Registers the color scheme to be used for the specified visual area of controls under the * specified states. For example, if the light orange scheme has to be used for gradient fill of * rollover selected and rollover controls, the parameters would be: * * <ul> * <li><code>scheme</code>=light orange scheme * <li><code>associationKind</code>={@link ColorSchemeAssociationKind#FILL} * <li><code>states</code>={@link ComponentState#ROLLOVER_SELECTED}, {@link * ComponentState#ROLLOVER_UNSELECTED} * </ul> * * @param scheme Color scheme. * @param associationKind Color scheme association kind that specifies the visual areas of * controls to be painted with this color scheme. * @param states Component states that further restrict the usage of the specified color scheme. * @since version 5.1 */ public void registerColorScheme( SubstanceColorScheme scheme, ColorSchemeAssociationKind associationKind, ComponentState... states) { if (scheme == null) { throw new IllegalArgumentException("Cannot pass null color scheme"); } if ((states == null) || (states.length == 0)) { for (ComponentState state : ComponentState.getAllStates()) { if (this.colorSchemeMap.get(associationKind).containsKey(state)) continue; this.colorSchemeMap.get(associationKind).put(state, scheme); } } else { for (ComponentState state : states) { this.colorSchemeMap.get(associationKind).put(state, scheme); } } }
public void requestStop() { state.requestStop(this); }
public void requestStart() throws CoreException { state.requestStart(this); }
public void requestClose() { state.requestClose(this); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paint(java.awt.Graphics * , javax.swing.JComponent) */ @Override public void paint(Graphics g, JComponent c) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setFont( FlamingoUtilities.getFont(this.commandButton, "Ribbon.font", "Button.font", "Panel.font")); this.layoutInfo = this.layoutManager.getLayoutInfo(this.commandButton, g); commandButton.putClientProperty("icon.bounds", layoutInfo.iconRect); commandButton.putClientProperty("icon", commandButton.getIcon()); if (this.isPaintingBackground()) { this.paintButtonBackground(g2d, new Rectangle(0, 0, c.getWidth(), c.getHeight())); } // decide which command button model should be used to // compute the foreground color of the command button's text boolean useActionAreaForFg = layoutInfo.isTextInActionArea; StateTransitionTracker transitionTrackerForFg = useActionAreaForFg ? this.getActionTransitionTracker() : this.getPopupTransitionTracker(); ModelStateInfo modelStateInfoForFg = transitionTrackerForFg.getModelStateInfo(); ComponentState currStateForFg = modelStateInfoForFg.getCurrModelState(); Color fgColor = this.commandButton.getForeground(); if (fgColor instanceof UIResource) { float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, currStateForFg); fgColor = SubstanceTextUtilities.getForegroundColor( this.commandButton, this.commandButton.getText(), modelStateInfoForFg, buttonAlpha); } if (layoutInfo.textLayoutInfoList != null) { for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : layoutInfo.textLayoutInfoList) { if (mainTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, mainTextLayoutInfo.textRect, mainTextLayoutInfo.text, -1, g2d.getFont(), fgColor, g2d.getClipBounds()); } } } if (layoutInfo.extraTextLayoutInfoList != null) { Color disabledFgColor = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ComponentState.DISABLED_UNSELECTED) .getForegroundColor(); float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha( this.commandButton, ComponentState.DISABLED_UNSELECTED); if (buttonAlpha < 1.0f) { Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(this.commandButton); disabledFgColor = SubstanceColorUtilities.getInterpolatedColor(disabledFgColor, bgFillColor, buttonAlpha); } if (currStateForFg.isDisabled()) { disabledFgColor = SubstanceColorUtilities.getInterpolatedColor( disabledFgColor, SubstanceColorUtilities.getBackgroundFillColor(c), 0.5); } for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : layoutInfo.extraTextLayoutInfoList) { if (extraTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, extraTextLayoutInfo.textRect, extraTextLayoutInfo.text, -1, g2d.getFont(), disabledFgColor, g2d.getClipBounds()); } } } if (layoutInfo.iconRect != null) { this.paintButtonIcon(g2d, layoutInfo.iconRect); } if (layoutInfo.popupActionRect.getWidth() > 0) { paintPopupActionIcon(g2d, layoutInfo.popupActionRect); } if (this.isPaintingSeparators() && (layoutInfo.separatorArea != null)) { if (layoutInfo.separatorOrientation == CommandButtonSeparatorOrientation.HORIZONTAL) { this.paintButtonHorizontalSeparator(g2d, layoutInfo.separatorArea); } else { this.paintButtonVerticalSeparator(g2d, layoutInfo.separatorArea); } } // g2d.setColor(Color.red); // g2d.draw(layoutInfo.iconRect); // g2d.setColor(Color.blue); // if (layoutInfo.textLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : // layoutInfo.textLayoutInfoList) { // if (mainTextLayoutInfo.text != null) { // g2d.draw(mainTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.magenta); // if (layoutInfo.extraTextLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : // layoutInfo.extraTextLayoutInfoList) { // if (extraTextLayoutInfo.text != null) { // g2d.draw(extraTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.green); // g2d.draw(layoutInfo.popupActionRect); g2d.dispose(); }