org.pushingpixels.substance.internal.animation.TransitionAwareUI Java Examples

The following examples show how to use org.pushingpixels.substance.internal.animation.TransitionAwareUI. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubstanceCoreUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void paintFocus(Graphics g, Component mainComp, Component focusedComp,
        TransitionAwareUI transitionAwareUI, Shape focusShape, Rectangle textRect,
        Color focusColor, float maxAlphaCoef, float extraPadding) {
    float focusStrength = transitionAwareUI.getTransitionTracker()
            .getFocusStrength(focusedComp.hasFocus());
    if (focusStrength == 0.0f) {
        return;
    }

    FocusKind focusKind = SubstanceCoreUtilities.getFocusKind(mainComp);
    if (focusKind == FocusKind.NONE) {
        return;
    }

    Graphics2D graphics = (Graphics2D) g.create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    float alpha = maxAlphaCoef * focusStrength;
    graphics.setComposite(WidgetUtilities.getAlphaComposite(mainComp, alpha, g));

    graphics.setColor(focusColor);
    focusKind.paintFocus(mainComp, focusedComp, transitionAwareUI, graphics, focusShape,
            textRect, extraPadding);
    graphics.dispose();
}
 
Example #2
Source File: EditContextMenuWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JMenuItem getCopyItem() {
    JMenuItem result = new JMenuItem(
            SubstanceCortex.GlobalScope.getLabelBundle().getString("EditMenu.copy"));
    result.setEnabled(jcomp.isEnabled() && (jcomp.getSelectedText() != null));

    HighlightableTransitionAwareIcon icon = new HighlightableTransitionAwareIcon(result,
            () -> (TransitionAwareUI) result.getUI(),
            (SubstanceColorScheme scheme) -> SubstanceCortex.GlobalScope.getIconPack()
                    .getTextCopyActionIcon(ICON_SIZE, scheme),
            ComponentStateFacet.ARM, "substance.widget.editcontext.copy");
    result.setIcon(icon);
    result.setDisabledIcon(icon);

    result.addActionListener((ActionEvent e) -> jcomp.copy());
    return result;
}
 
Example #3
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    JSlider slider = (JSlider) c;
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI
            .getTransitionTracker();
    Icon iconToDraw = getIcon(slider, stateTransitionTracker);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(x, y);
    iconToDraw.paintIcon(c, g, 0, 0);
    g2d.dispose();
}
 
Example #4
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    JSlider slider = (JSlider) c;
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI
            .getTransitionTracker();
    Icon iconToDraw = getIcon(slider, stateTransitionTracker);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(x, y);
    iconToDraw.paintIcon(c, g, 0, 0);
    g2d.dispose();
}
 
Example #5
Source File: EditContextMenuWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JMenuItem getPasteItem() {
    JMenuItem result = new JMenuItem(
            SubstanceCortex.GlobalScope.getLabelBundle().getString("EditMenu.paste"));
    boolean isEnabled = false;
    if (jcomp.isEditable() && jcomp.isEnabled()) {
        Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(this);
        isEnabled = contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    }
    result.setEnabled(isEnabled);

    HighlightableTransitionAwareIcon icon = new HighlightableTransitionAwareIcon(result,
            () -> (TransitionAwareUI) result.getUI(),
            (SubstanceColorScheme scheme) -> SubstanceCortex.GlobalScope.getIconPack()
                    .getTextPasteActionIcon(ICON_SIZE, scheme),
            ComponentStateFacet.ARM, "substance.widget.editcontext.paste");
    result.setIcon(icon);
    result.setDisabledIcon(icon);

    result.addActionListener((ActionEvent e) -> jcomp.paste());
    return result;
}
 
Example #6
Source File: EditContextMenuWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JMenuItem getDeleteItem() {
    JMenuItem result = new JMenuItem(
            SubstanceCortex.GlobalScope.getLabelBundle().getString("EditMenu.delete"));
    result.setEnabled(
            jcomp.isEditable() && jcomp.isEnabled() && (jcomp.getSelectedText() != null));

    HighlightableTransitionAwareIcon icon = new HighlightableTransitionAwareIcon(result,
            () -> (TransitionAwareUI) result.getUI(),
            (SubstanceColorScheme scheme) -> SubstanceCortex.GlobalScope.getIconPack()
                    .getTextDeleteActionIcon(ICON_SIZE, scheme),
            ComponentStateFacet.ARM, "substance.widget.editcontext.delete");
    result.setIcon(icon);
    result.setDisabledIcon(icon);

    result.addActionListener((ActionEvent e) -> jcomp.replaceSelection(null));
    return result;
}
 
Example #7
Source File: EditContextMenuWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JMenuItem getSelectAllItem() {
    JMenuItem result = new JMenuItem(
            SubstanceCortex.GlobalScope.getLabelBundle().getString("EditMenu.selectAll"));
    result.setEnabled(jcomp.isEnabled() && (jcomp.getDocument().getLength() > 0));

    HighlightableTransitionAwareIcon icon = new HighlightableTransitionAwareIcon(result,
            () -> (TransitionAwareUI) result.getUI(),
            (SubstanceColorScheme scheme) -> SubstanceCortex.GlobalScope.getIconPack()
                    .getTextSelectAllActionIcon(ICON_SIZE, scheme),
            ComponentStateFacet.ARM, "substance.widget.editcontext.selectall");
    result.setIcon(icon);
    result.setDisabledIcon(icon);

    result.addActionListener((ActionEvent e) -> jcomp.selectAll());
    return result;
}
 
Example #8
Source File: MenuSearchWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void reset() {
    if (searchPanel == null)
        return;
    for (Map.Entry<Integer, JButton> entry : searchPanel.resultButtons.entrySet()) {
        int index = entry.getKey();
        JButton button = entry.getValue();

        button.setIcon(new TransitionAwareIcon(button, () -> (TransitionAwareUI) button.getUI(),
                (SubstanceColorScheme scheme) -> SubstanceImageCreator.getHexaMarker(index,
                        scheme),
                (ComponentState state) -> state.isFacetActive(ComponentStateFacet.ROLLOVER)
                        ? ColorSchemeAssociationKind.HIGHLIGHT
                        : ColorSchemeAssociationKind.MARK,
                "substance.widget.menusearch." + index));
    }
    searchPanel.updateSearchIcon();
    ResourceBundle bundle = SubstanceCortex.GlobalScope.getLabelBundle();
    searchPanel.searchButton.setToolTipText(bundle.getString("Tooltip.menuSearchButton"));
    searchPanel.searchStringField.setToolTipText(bundle.getString("Tooltip.menuSearchField"));
}
 
Example #9
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Paints the text of the specified button.
 * 
 * @param g
 *            Graphic context.
 * @param button
 *            Button
 * @param model
 *            Button model.
 * @param textRect
 *            Text rectangle
 * @param text
 *            Text to paint
 * @param mnemonicIndex
 *            Mnemonic index.
 */
public static void paintText(Graphics g, AbstractButton button, ButtonModel model,
        Rectangle textRect, String text, int mnemonicIndex) {
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) button.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();

    if (button instanceof JMenuItem) {
        // A slightly different path for menu items as we ignore the selection
        // state for visual consistency in menu content
        float menuItemAlpha = SubstanceColorSchemeUtilities.getAlpha(button,
                ComponentState.getState(button.getModel(), button, true));
        paintMenuItemText(g, (JMenuItem) button, textRect, text, mnemonicIndex,
                stateTransitionTracker.getModelStateInfo(), menuItemAlpha);
    } else {
        float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha(button,
                ComponentState.getState(button));
        paintText(g, button, textRect, text, mnemonicIndex,
                stateTransitionTracker.getModelStateInfo(), buttonAlpha);
    }
}
 
Example #10
Source File: JSliderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Icon getIcon ()
{
    // TODO Use that to get the state (-> highlight or not)
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    // stateTransitionTracker.getModelStateInfo().getCurrModelState();

    final Icon icon = super.getIcon();
    final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics iconGraphics = image.createGraphics();
    icon.paintIcon(slider, iconGraphics, 0, 0);
    // Make it brighter (very simple approach)
    final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null);
    rescaleOp.filter(image, image);

    ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    op.filter(image, image);

    return new ImageIcon(image);
}
 
Example #11
Source File: EditContextMenuWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private JMenuItem getCutItem() {
    JMenuItem result = new JMenuItem(
            SubstanceCortex.GlobalScope.getLabelBundle().getString("EditMenu.cut"));
    result.setEnabled(
            jcomp.isEditable() && jcomp.isEnabled() && (jcomp.getSelectedText() != null));

    HighlightableTransitionAwareIcon icon = new HighlightableTransitionAwareIcon(result,
            () -> (TransitionAwareUI) result.getUI(),
            (SubstanceColorScheme scheme) -> SubstanceCortex.GlobalScope.getIconPack()
                    .getTextCutActionIcon(ICON_SIZE, scheme),
            ComponentStateFacet.ARM, "substance.widget.editcontext.cut");
    result.setIcon(icon);
    result.setDisabledIcon(icon);

    result.addActionListener((ActionEvent e) -> jcomp.cut());
    return result;
}
 
Example #12
Source File: SubstanceSlices.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintFocus(Component mainComp, Component focusedComp,
        TransitionAwareUI transitionAwareUI, Graphics2D graphics, Shape focusShape,
        Rectangle textRect, float extraPadding) {
    if (textRect == null)
        return;

    int fontSize = SubstanceSizeUtils.getComponentFontSize(mainComp);
    float dashLength = getDashLength(fontSize);
    float dashGap = getDashGap(fontSize);
    float dashPhase = (dashLength + dashGap)
            * (1.0f - transitionAwareUI.getTransitionTracker().getFocusLoopPosition());

    graphics.setStroke(new BasicStroke(SubstanceSizeUtils.getFocusStrokeWidth(),
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0.0f,
            new float[] {dashLength, dashGap}, dashPhase));

    graphics.translate(textRect.x - 1, textRect.y);
    graphics.drawLine(0, textRect.height - 1, textRect.width, textRect.height - 1);
    graphics.dispose();
}
 
Example #13
Source File: SubstanceSlices.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintFocus(Component mainComp, Component focusedComp,
        TransitionAwareUI transitionAwareUI, Graphics2D graphics, Shape focusShape,
        Rectangle textRect, float extraPadding) {
    if (textRect == null)
        return;
    if ((textRect.width == 0) || (textRect.height == 0))
        return;

    int fontSize = SubstanceSizeUtils.getComponentFontSize(mainComp);
    float dashLength = getDashLength(fontSize);
    float dashGap = getDashGap(fontSize);
    float dashPhase = (dashLength + dashGap)
            * (1.0f - transitionAwareUI.getTransitionTracker().getFocusLoopPosition());

    graphics.setStroke(new BasicStroke(SubstanceSizeUtils.getFocusStrokeWidth(),
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0.0f,
            new float[] {dashLength, dashGap}, dashPhase));

    int delta = ((mainComp instanceof JComboBox) || (mainComp instanceof JSpinner)) ? 0
            : 1;
    Shape contour = SubstanceOutlineUtilities.getBaseOutline(
            textRect.width + 2 * delta, textRect.height,
            SubstanceSizeUtils.getClassicButtonCornerRadius(fontSize), null);

    graphics.translate(textRect.x - delta, textRect.y);
    graphics.draw(contour);
}
 
Example #14
Source File: SubstanceScrollBarUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the scroll button state.
 * 
 * @param scrollButton
 *            Scroll button.
 * @return Scroll button state.
 */
protected ComponentState getState(JButton scrollButton) {
    if (scrollButton == null)
        return null;

    ComponentState result = ((TransitionAwareUI) scrollButton.getUI()).getTransitionTracker()
            .getModelStateInfo().getCurrModelState();
    if ((result == ComponentState.ENABLED)
            && SubstanceCoreUtilities.hasFlatAppearance(this.scrollbar, false)) {
        result = null;
    }
    if (SubstanceCoreUtilities.isButtonNeverPainted(scrollButton)) {
        result = null;
    }
    return result;
}
 
Example #15
Source File: SubstanceComboBoxUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void installDefaults() {
    super.installDefaults();

    // this icon must be created after the font has been installed
    // on the combobox
    this.uneditableArrowIcon = SubstanceCoreUtilities.getArrowIcon(this.comboBox,
            () -> (TransitionAwareUI) comboBox.getUI(),
            SubstanceCoreUtilities.getPopupFlyoutOrientation(this.comboBox));
    this.updateComboBoxBorder();
}
 
Example #16
Source File: RibbonTaskToggleButtonBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Updates background of the specified button.
 *
 * @param g      Graphic context.
 * @param button Button to update.
 */
public void updateTaskToggleButtonBackground(Graphics g, JRibbonTaskToggleButton button) {
    Graphics2D g2d = (Graphics2D) g.create();

    int width = button.getWidth();
    int height = button.getHeight();

    BufferedImage ribbonBackground = getTaskToggleButtonBackground(button, width, height);

    TransitionAwareUI ui = (TransitionAwareUI) button.getUI();
    StateTransitionTracker stateTransitionTracker = ui.getTransitionTracker();

    float extraActionAlpha = 0.0f;
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry
            : stateTransitionTracker.getModelStateInfo().getStateContributionMap().entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        if (activeState.isDisabled()) {
            continue;
        }
        if (activeState == ComponentState.ENABLED) {
            continue;
        }
        extraActionAlpha += activeEntry.getValue().getContribution();
    }

    g2d.setComposite(WidgetUtilities.getAlphaComposite(button, extraActionAlpha, g));
    NeonCortex.drawImage(g2d, ribbonBackground, 0, 0);

    g2d.dispose();
}
 
Example #17
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Color getTextBackgroundFillColor(JComponent comp) {
    Color backgroundFillColor = SubstanceColorUtilities.getBackgroundFillColor(comp);

    JTextComponent componentForTransitions = SubstanceCoreUtilities
            .getTextComponentForTransitions(comp);

    if (componentForTransitions != null) {
        ComponentUI ui = componentForTransitions.getUI();
        if (ui instanceof TransitionAwareUI) {
            TransitionAwareUI trackable = (TransitionAwareUI) ui;
            StateTransitionTracker stateTransitionTracker = trackable.getTransitionTracker();

            Color lighterFill = SubstanceColorUtilities.getLighterColor(backgroundFillColor,
                    0.4f);
            lighterFill = SubstanceColorUtilities.getInterpolatedColor(lighterFill,
                    backgroundFillColor, 0.6);

            float selectionStrength = stateTransitionTracker
                    .getFacetStrength(ComponentStateFacet.SELECTION);
            float rolloverStrength = stateTransitionTracker
                    .getFacetStrength(ComponentStateFacet.ROLLOVER);
            backgroundFillColor = SubstanceColorUtilities.getInterpolatedColor(lighterFill,
                    backgroundFillColor, Math.max(selectionStrength, rolloverStrength) / 4.0f);
        }
    }
    return backgroundFillColor;
}
 
Example #18
Source File: SubstanceIconFactory.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    JSlider slider = (JSlider) c;
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    Icon iconToDraw = getIcon(slider, stateTransitionTracker);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(x, y);
    iconToDraw.paintIcon(c, g, 0, 0);
    g2d.dispose();
}
 
Example #19
Source File: RolloverTextControlListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple constructor.
 * 
 * @param trackableUI
 *            Object that is queried for mouse events.
 * @param model
 *            Surrogate model for tracking control status.
 */
public RolloverTextControlListener(JComponent component,
		TransitionAwareUI trackableUI, ButtonModel model) {
	this.component = component;
	this.trackableUI = trackableUI;
	this.model = model;
	this.isMouseInside = false;
	this.stateTransitionTracker = this.trackableUI.getTransitionTracker();
}
 
Example #20
Source File: SubstanceCoreUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Paints the focus ring on the specified component.
 *
 * @param g            Graphics context.
 * @param mainComp     The main component for the focus painting.
 * @param focusedComp  The actual component that has the focus. For example, the main component can be a
 *                     {@link JSpinner}, while the focused component is a text field inside the the
 *                     spinner editor.
 * @param focusShape   Focus shape. May be <code>null</code> - in this case, the bounds of
 *                     <code>mainComp</code> will be used.
 * @param textRect     Text rectangle (if relevant).
 * @param maxAlphaCoef Maximum alpha coefficient for painting the focus. Values lower than 1.0 will
 *                     result in a translucent focus ring (can be used to paint a focus ring that doesn't
 *                     draw too much attention away from the content, for example on text components).
 * @param extraPadding Extra padding between the component bounds and the focus ring painting.
 */
public static void paintFocus(Graphics g, Component mainComp, Component focusedComp,
        TransitionAwareUI transitionAwareUI, Shape focusShape, Rectangle textRect,
        float maxAlphaCoef, float extraPadding) {
    float focusStrength = transitionAwareUI.getTransitionTracker()
            .getFocusStrength(focusedComp.hasFocus());
    if (focusStrength == 0.0f) {
        return;
    }

    FocusKind focusKind = SubstanceCoreUtilities.getFocusKind(mainComp);
    if (focusKind == FocusKind.NONE) {
        return;
    }

    Graphics2D graphics = (Graphics2D) g.create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    float alpha = maxAlphaCoef * focusStrength;
    graphics.setComposite(WidgetUtilities.getAlphaComposite(mainComp, alpha, g));

    Color color = SubstanceColorUtilities.getFocusColor(mainComp, transitionAwareUI);
    graphics.setColor(color);
    focusKind.paintFocus(mainComp, focusedComp, transitionAwareUI, graphics, focusShape,
            textRect, extraPadding);
    graphics.dispose();
}
 
Example #21
Source File: SubstanceSlices.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paintFocus(Component mainComp, Component focusedComp,
        TransitionAwareUI transitionAwareUI, Graphics2D graphics, Shape focusShape,
        Rectangle textRect, float extraPadding) {
    if (textRect == null)
        return;

    graphics.setStroke(new BasicStroke(1.5f * SubstanceSizeUtils.getFocusStrokeWidth(),
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    graphics.translate(textRect.x - 1, textRect.y);
    graphics.drawLine(0, textRect.height - 1, textRect.width, textRect.height - 1);
}
 
Example #22
Source File: SubstanceGeminiLookAndFeel2.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isInside(MouseEvent me) {
  return ((TransitionAwareUI)myDelegateUI).isInside(me);
}
 
Example #23
Source File: SubstanceGeminiLookAndFeel2.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public StateTransitionTracker getTransitionTracker() {
  return ((TransitionAwareUI)myDelegateUI).getTransitionTracker();
}
 
Example #24
Source File: SubstanceComboBoxUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void propertyChange(final PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();

    if (propertyName.equals("componentOrientation")) {
        SwingUtilities.invokeLater(() -> {
            if (SubstanceComboBoxUI.this.comboBox == null)
                return;
            final ComponentOrientation newOrientation = (ComponentOrientation) e
                    .getNewValue();
            final ListCellRenderer cellRenderer = SubstanceComboBoxUI.this.comboBox
                    .getRenderer();
            final ComboBoxEditor editor = SubstanceComboBoxUI.this.comboBox.getEditor();
            if (SubstanceComboBoxUI.this.popup instanceof Component) {
                final Component cPopup = (Component) SubstanceComboBoxUI.this.popup;
                cPopup.applyComponentOrientation(newOrientation);
                cPopup.doLayout();
            }
            if (cellRenderer instanceof Component) {
                ((Component) cellRenderer).applyComponentOrientation(newOrientation);
            }
            if ((editor != null) && (editor.getEditorComponent() != null)) {
                (editor.getEditorComponent()).applyComponentOrientation(newOrientation);
            }
            if (SubstanceComboBoxUI.this.comboBox != null)
                SubstanceComboBoxUI.this.comboBox.repaint();
        });
    }

    if (SubstanceSynapse.COMBO_BOX_POPUP_FLYOUT_ORIENTATION.equals(propertyName)) {
        SubstanceDropDownButton dropDownButton = (SubstanceDropDownButton) arrowButton;
        dropDownButton.setIcon(getCurrentIcon(dropDownButton));
        uneditableArrowIcon = SubstanceCoreUtilities.getArrowIcon(comboBox,
                () -> (TransitionAwareUI) comboBox.getUI(),
                SubstanceCoreUtilities.getPopupFlyoutOrientation(comboBox));
    }

    if ("font".equals(propertyName)) {
        SwingUtilities.invokeLater(() -> {
            if (comboBox != null) {
                comboBox.updateUI();
            }
        });
    }

    if ("background".equals(propertyName)) {
        if (comboBox.isEditable()) {
            comboBox.getEditor().getEditorComponent()
                    .setBackground(comboBox.getBackground());
            popup.getList().setBackground(comboBox.getBackground());
        }
    }

    if ("editable".equals(propertyName)) {
        updateComboBoxBorder();
        isMinimumSizeDirty = true;
    }

    if ("enabled".equals(propertyName)) {
        SubstanceComboBoxUI.this.transitionModel.setEnabled(comboBox.isEnabled());
    }
    // Do not call super - fix for bug 63
}
 
Example #25
Source File: ArrowButtonTransitionAwareIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ArrowButtonTransitionAwareIcon(final AbstractButton button,
		int orientation) {
	this(button, () -> (TransitionAwareUI) button.getUI(), orientation);
}
 
Example #26
Source File: ComboBoxBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void updateBackground(Graphics g, JComboBox combo, ButtonModel comboModel) {
    // failsafe for LAF change
    if (!SubstanceCoreUtilities.isCurrentLookAndFeel())
        return;

    int width = combo.getWidth();
    int height = combo.getHeight();
    int y = 0;

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(combo);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(combo);

    BufferedImage bgImage = getFullAlphaBackground(combo, comboModel, fillPainter,
            borderPainter, width, height);

    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) combo.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    // Two special cases here:
    // 1. Combobox has flat appearance.
    // 2. Combobox is disabled.
    // For both cases, we need to set custom translucency.
    boolean isFlat = SubstanceCoreUtilities.hasFlatAppearance(combo, false);
    boolean isSpecial = isFlat || !combo.isEnabled();
    float extraAlpha = 1.0f;
    if (isSpecial) {
        if (isFlat) {
            // Special handling of flat combos
            extraAlpha = 0.0f;
            for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
                    .entrySet()) {
                ComponentState activeState = activeEntry.getKey();
                if (activeState.isDisabled())
                    continue;
                if (activeState == ComponentState.ENABLED)
                    continue;
                extraAlpha += activeEntry.getValue().getContribution();
            }
        } else {
            if (!combo.isEnabled()) {
                extraAlpha = SubstanceColorSchemeUtilities.getAlpha(combo,
                        modelStateInfo.getCurrModelState());
            }
        }
    }
    if (extraAlpha > 0.0f) {
        Graphics2D graphics = (Graphics2D) g.create();
        graphics.setComposite(WidgetUtilities.getAlphaComposite(combo, extraAlpha, g));
        graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        NeonCortex.drawImage(graphics, bgImage, 0, y);
        graphics.dispose();
    }
}
 
Example #27
Source File: ComboBoxBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static BufferedImage getFullAlphaBackground(JComboBox combo, ButtonModel model,
        SubstanceFillPainter fillPainter, SubstanceBorderPainter borderPainter, int width,
        int height) {
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) combo.getUI();
    StateTransitionTracker.ModelStateInfo modelStateInfo = transitionAwareUI
            .getTransitionTracker().getModelStateInfo();
    ComponentState currState = modelStateInfo.getCurrModelState();

    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    ClassicButtonShaper shaper = ClassicButtonShaper.INSTANCE;
    int comboFontSize = SubstanceSizeUtils.getComponentFontSize(combo);
    float radius = SubstanceSizeUtils.getClassicButtonCornerRadius(comboFontSize);

    SubstanceColorScheme baseFillScheme = SubstanceColorSchemeUtilities.getColorScheme(combo,
            currState);
    SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities.getColorScheme(combo,
            ColorSchemeAssociationKind.BORDER, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(width, height,
            baseFillScheme.getDisplayName(), baseBorderScheme.getDisplayName(),
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            combo.getClass().getName(), radius, comboFontSize);
    BufferedImage layerBase = regularBackgrounds.get(keyBase);
    if (layerBase == null) {
        layerBase = createBackgroundImage(combo, shaper, fillPainter, borderPainter, width,
                height, baseFillScheme, baseBorderScheme, radius);
        regularBackgrounds.put(keyBase, layerBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return layerBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(layerBase);
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    g2d.drawImage(layerBase, 0, 0, layerBase.getWidth(), layerBase.getHeight(), null);
    // System.out.println("\nPainting base state " + currState);

    // draw the other active layers
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        // System.out.println("Painting state " + activeState + "[curr is "
        // + currState + "] with " + activeEntry.getValue());
        if (activeState == currState)
            continue;

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));

            SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(combo, activeState);
            SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(combo, ColorSchemeAssociationKind.BORDER, activeState);
            HashMapKey key = SubstanceCoreUtilities.getHashKey(width, height,
                    fillScheme.getDisplayName(), borderScheme.getDisplayName(),
                    fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    combo.getClass().getName(), radius, comboFontSize);
            BufferedImage layer = regularBackgrounds.get(key);
            if (layer == null) {
                layer = createBackgroundImage(combo, shaper, fillPainter, borderPainter, width,
                        height, fillScheme, borderScheme, radius);
                regularBackgrounds.put(key, layer);
            }
            g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
        }
    }
    g2d.dispose();
    return result;
}
 
Example #28
Source File: SubstanceMenuBackgroundDelegate.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Paints menu highlights.
 * 
 * @param g
 *            Graphics context.
 * @param menuItem
 *            Menu item.
 * @param borderAlpha
 *            Alpha channel for painting the border.
 */
public static void paintHighlights(Graphics g, JMenuItem menuItem,
		float borderAlpha) {
	Graphics2D graphics = (Graphics2D) g.create();

	TransitionAwareUI transitionAwareUI = (TransitionAwareUI) menuItem
			.getUI();
	StateTransitionTracker stateTransitionTracker = transitionAwareUI
			.getTransitionTracker();
	ModelStateInfo modelStateInfo = stateTransitionTracker
			.getModelStateInfo();

	ComponentState currState = modelStateInfo
			.getCurrModelStateNoSelection();

	if (currState.isDisabled()) {
		// no highlights on disabled menus
		return;
	}
	Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
			.getStateNoSelectionContributionMap();
	// if ("Check enabled unselected".equals(menuItem.getText())) {
	// System.out.println("New contribution map");
	// for (Map.Entry<ComponentState,
	// StateTransitionTracker.StateContributionInfo> existing : activeStates
	// .entrySet()) {
	// System.out.println("\t" + existing.getKey() + " in ["
	// + existing.getValue().start + ":"
	// + existing.getValue().end + "] -> "
	// + existing.getValue().curr);
	// }
	// }

	if ((currState == ComponentState.ENABLED) && (activeStates.size() == 1)) {
		// default state - no highlights
		return;
	}

	for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> stateEntry : activeStates
			.entrySet()) {
		ComponentState activeState = stateEntry.getKey();
		float alpha = SubstanceColorSchemeUtilities.getHighlightAlpha(
				menuItem, activeState)
				* stateEntry.getValue().getContribution();
		if (alpha == 0.0f)
			continue;

		SubstanceColorScheme fillScheme = SubstanceColorSchemeUtilities
				.getColorScheme(menuItem,
						ColorSchemeAssociationKind.HIGHLIGHT, activeState);
		SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities
				.getColorScheme(menuItem,
						ColorSchemeAssociationKind.HIGHLIGHT_BORDER,
						activeState);
		graphics.setComposite(WidgetUtilities.getAlphaComposite(
				menuItem, alpha, g));
           HighlightPainterUtils.paintHighlight(graphics, null, menuItem,
                   new Rectangle(0, 0, menuItem.getWidth(), menuItem.getHeight()), borderAlpha,
                   null, fillScheme, borderScheme);
		graphics.setComposite(WidgetUtilities.getAlphaComposite(
				menuItem, g));
	}

	graphics.dispose();
}
 
Example #29
Source File: CheckBoxMenuItemIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the current icon to paint.
 * 
 * @return Icon to paint.
 */
private ImageWrapperIcon getIconToPaint() {
    if (this.menuItem == null)
        return null;

    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) this.menuItem.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();

    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(this.menuItem);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities
            .getBorderPainter(this.menuItem);
    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseFillColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK_BOX, currState);
    SubstanceColorScheme baseMarkColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK, currState);
    SubstanceColorScheme baseBorderColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER, currState);
    float visibility = stateTransitionTracker.getFacetStrength(ComponentStateFacet.SELECTION);
    boolean isCheckMarkFadingOut = !currState.isFacetActive(ComponentStateFacet.SELECTION);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(this.menuItem, currState);

    int fontSize = SubstanceSizeUtils.getComponentFontSize(this.menuItem);
    int checkMarkSize = this.size + 3;

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
            fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, isCheckMarkFadingOut,
            alpha);
    ImageWrapperIcon iconBase = iconMap.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(
                SubstanceImageCreator.getCheckBox(this.menuItem, fillPainter, borderPainter,
                        checkMarkSize, currState, baseFillColorScheme, baseMarkColorScheme,
                        baseBorderColorScheme, visibility, isCheckMarkFadingOut, alpha));
        iconMap.put(keyBase, iconBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return iconBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iconBase.getIconWidth(),
            iconBase.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    iconBase.paintIcon(this.menuItem, g2d, 0, 0);

    // draw other active layers
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        // System.out.println("Painting state " + activeState + "[curr is "
        // + currState + "] with " + activeEntry.getValue());
        if (activeState == currState)
            continue;

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));
            SubstanceColorScheme fillColorScheme = SubstanceColorSchemeUtilities.getColorScheme(
                    this.menuItem, ColorSchemeAssociationKind.MARK_BOX, activeState);
            SubstanceColorScheme markColorScheme = SubstanceColorSchemeUtilities.getColorScheme(
                    this.menuItem, ColorSchemeAssociationKind.MARK, activeState);
            SubstanceColorScheme borderColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER,
                            activeState);

            HashMapKey keyLayer = SubstanceCoreUtilities.getHashKey(fontSize, checkMarkSize,
                    fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    fillColorScheme.getDisplayName(), markColorScheme.getDisplayName(),
                    borderColorScheme.getDisplayName(), visibility, alpha);
            ImageWrapperIcon iconLayer = iconMap.get(keyLayer);
            if (iconLayer == null) {
                iconLayer = new ImageWrapperIcon(SubstanceImageCreator.getCheckBox(
                        this.menuItem, fillPainter, borderPainter, checkMarkSize, currState,
                        fillColorScheme, markColorScheme, borderColorScheme, visibility,
                        isCheckMarkFadingOut, alpha));
                iconMap.put(keyLayer, iconLayer);
            }

            iconLayer.paintIcon(this.menuItem, g2d, 0, 0);
        }
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}
 
Example #30
Source File: RadioButtonMenuItemIcon.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the current icon to paint.
 *
 * @return Icon to paint.
 */
private ImageWrapperIcon getIconToPaint() {
    if (this.menuItem == null)
        return null;
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) this.menuItem
            .getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI
            .getTransitionTracker();

    StateTransitionTracker.ModelStateInfo modelStateInfo = stateTransitionTracker
            .getModelStateInfo();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateContributionMap();

    int fontSize = SubstanceSizeUtils.getComponentFontSize(this.menuItem);
    int checkMarkSize = this.size;

    SubstanceFillPainter fillPainter = SubstanceCoreUtilities.getFillPainter(this.menuItem);
    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(this.menuItem);
    ComponentState currState = modelStateInfo.getCurrModelState();

    SubstanceColorScheme baseFillColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK_BOX, currState);
    SubstanceColorScheme baseMarkColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK, currState);
    SubstanceColorScheme baseBorderColorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER, currState);
    float visibility = stateTransitionTracker.getFacetStrength(ComponentStateFacet.SELECTION);
    float alpha = SubstanceColorSchemeUtilities.getAlpha(this.menuItem, currState);

    HashMapKey keyBase = SubstanceCoreUtilities.getHashKey(fontSize,
            checkMarkSize, fillPainter.getDisplayName(), borderPainter.getDisplayName(),
            baseFillColorScheme.getDisplayName(), baseMarkColorScheme.getDisplayName(),
            baseBorderColorScheme.getDisplayName(), visibility, alpha);
    ImageWrapperIcon iconBase = iconMap.get(keyBase);
    if (iconBase == null) {
        iconBase = new ImageWrapperIcon(SubstanceImageCreator.getRadioButton(
                this.menuItem, fillPainter, borderPainter, checkMarkSize,
                currState, 0, baseFillColorScheme, baseMarkColorScheme,
                baseBorderColorScheme, visibility, alpha));
        iconMap.put(keyBase, iconBase);
    }
    if (currState.isDisabled() || (activeStates.size() == 1)) {
        return iconBase;
    }

    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iconBase
            .getIconWidth(), iconBase.getIconHeight());
    Graphics2D g2d = result.createGraphics();
    // draw the base layer
    iconBase.paintIcon(this.menuItem, g2d, 0, 0);

    // draw other active layers
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        // System.out.println("Painting state " + activeState + "[curr is "
        // + currState + "] with " + activeEntry.getValue());
        if (activeState == currState)
            continue;

        float stateContribution = activeEntry.getValue().getContribution();
        if (stateContribution > 0.0f) {
            g2d.setComposite(AlphaComposite.SrcOver.derive(stateContribution));
            SubstanceColorScheme fillColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK_BOX, activeState);
            SubstanceColorScheme markColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.menuItem, ColorSchemeAssociationKind.MARK, activeState);
            SubstanceColorScheme borderColorScheme = SubstanceColorSchemeUtilities
                    .getColorScheme(this.menuItem, ColorSchemeAssociationKind.BORDER, activeState);

            HashMapKey keyLayer = SubstanceCoreUtilities.getHashKey(
                    fontSize, checkMarkSize, fillPainter.getDisplayName(), borderPainter.getDisplayName(),
                    fillColorScheme.getDisplayName(), markColorScheme.getDisplayName(),
                    borderColorScheme.getDisplayName(), visibility, alpha);
            ImageWrapperIcon iconLayer = iconMap.get(keyLayer);
            if (iconLayer == null) {
                iconLayer = new ImageWrapperIcon(SubstanceImageCreator
                        .getRadioButton(this.menuItem, fillPainter,
                                borderPainter, checkMarkSize, currState, 0,
                                fillColorScheme, markColorScheme,
                                borderColorScheme, visibility, alpha));
                iconMap.put(keyLayer, iconLayer);
            }

            iconLayer.paintIcon(this.menuItem, g2d, 0, 0);
        }
    }

    g2d.dispose();
    return new ImageWrapperIcon(result);
}