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

The following examples show how to use org.pushingpixels.substance.internal.animation.StateTransitionTracker. 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: SubstanceTabbedPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the current state for the specified tab.
 * 
 * @param tabIndex
 *            Tab index.
 * @return The current state for the specified tab.
 */
protected ComponentState getTabState(int tabIndex, boolean toAllowIgnoringSelectedState) {
    boolean isEnabled = this.tabPane.isEnabledAt(tabIndex);
    StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(tabIndex);
    boolean ignoreSelectedState = toAllowIgnoringSelectedState
            && (SubstanceCoreUtilities.getSkin(tabPane).getTabFadeEnd() <= 0.5);
    if (tracker == null) {
        boolean isRollover = this.getRolloverTabIndex() == tabIndex;
        boolean isSelected = ignoreSelectedState ? false
                : this.tabPane.getSelectedIndex() == tabIndex;
        return ComponentState.getState(isEnabled, isRollover, isSelected);
    } else {
        ComponentState fromTracker = ignoreSelectedState
                ? tracker.getModelStateInfo().getCurrModelStateNoSelection()
                : tracker.getModelStateInfo().getCurrModelState();
        return fromTracker;
        // return ComponentState.getState(isEnabled,
        // fromTracker.isFacetActive(ComponentStateFacet.ROLLOVER),
        // ignoreSelectedState ? false :
        // fromTracker.isFacetActive(ComponentStateFacet.SELECTION));
    }
}
 
Example #2
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the foreground color for the specified component.
 * 
 * @param component
 *            Component.
 * @param text
 *            Text. If empty or <code>null</code>, the result is <code>null</code>.
 * @param textAlpha
 *            Alpha channel for painting the text. If value is less than 1.0, the result is an
 *            opaque color which is an interpolation between the "real" foreground color and the
 *            background color of the component. This is done to ensure that native text
 *            rasterization will be performed on 6u10 on Windows.
 * @return The foreground color for the specified component.
 */
public static Color getForegroundColor(JComponent component, String text,
        StateTransitionTracker.ModelStateInfo modelStateInfo, float textAlpha) {
    if ((text == null) || (text.length() == 0))
        return null;

    boolean toEnforceFgColor = (SwingUtilities.getAncestorOfClass(CellRendererPane.class, component) != null)
            || Boolean.TRUE.equals(component.getClientProperty(ENFORCE_FG_COLOR));

    Color fgColor = null;
    if (toEnforceFgColor) {
        fgColor = component.getForeground();
    } else {
        fgColor = SubstanceColorUtilities.getForegroundColor(component, modelStateInfo);
    }

    if (textAlpha < 1.0f) {
        Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(component);
        fgColor = SubstanceColorUtilities.getInterpolatedColor(fgColor, bgFillColor, textAlpha);
    }
    return fgColor;
}
 
Example #3
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 #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: SubstanceTreeUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the current state for the specified path.
 * 
 * @param pathId
 *            Path index.
 * @return The current state for the specified path.
 */
public ComponentState getPathState(TreePathId pathId) {
	boolean isEnabled = this.tree.isEnabled();
	StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(pathId);
	if (tracker == null) {
		int rowIndex = this.tree.getRowForPath(pathId.path);
		boolean isRollover = (this.currRolloverPathId != null)
				&& pathId.equals(this.currRolloverPathId);
		boolean isSelected = this.tree.isRowSelected(rowIndex);
		return ComponentState.getState(isEnabled, isRollover, isSelected);
	} else {
		ComponentState fromTracker = tracker.getModelStateInfo().getCurrModelState();
		return ComponentState.getState(isEnabled,
				fromTracker.isFacetActive(ComponentStateFacet.ROLLOVER),
				fromTracker.isFacetActive(ComponentStateFacet.SELECTION));
	}
}
 
Example #6
Source File: SubstanceTextFieldUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Simple constructor.
 * 
 * @param c
 *            Component (text field).
 */
private SubstanceTextFieldUI(JComponent c) {
    super();
    this.textField = (JTextField) c;

    this.transitionModel = new DefaultButtonModel();
    this.transitionModel.setArmed(false);
    this.transitionModel.setSelected(false);
    this.transitionModel.setPressed(false);
    this.transitionModel.setRollover(false);
    this.transitionModel.setEnabled(this.textField.isEnabled());

    this.stateTransitionTracker = new StateTransitionTracker(this.textField,
            this.transitionModel);
    this.stateTransitionTracker.setRepaintCallback(
            () -> SubstanceCoreUtilities.getTextComponentRepaintCallback(textField));
}
 
Example #7
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 #8
Source File: SubstanceListUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initiates the fade out effect.
 */
private void fadeOutRolloverIndication() {
    if (rolledOverIndex < 0)
        return;

    StateTransitionTracker tracker = getTracker(rolledOverIndex, true,
            list.isSelectedIndex(rolledOverIndex));
    tracker.getModel().setRollover(false);
}
 
Example #9
Source File: SubstanceTabbedPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private StateTransitionTracker.ModelStateInfo getModelStateInfo(int tabIndex) {
    if (this.stateTransitionMultiTracker.size() == 0)
        return null;
    StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(tabIndex);
    if (tracker == null) {
        return null;
    } else {
        return tracker.getModelStateInfo();
    }
}
 
Example #10
Source File: SubstanceListUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handles various mouse move events and initiates the fade animation if necessary.
 *
 * @param e Mouse event.
 */
private void handleMove(MouseEvent e) {
    // no rollover effects on non-Substance renderers
    ListCellRenderer cellRenderer = list.getCellRenderer();
    boolean isSubstanceRenderer =
            (cellRenderer instanceof SubstanceDefaultListCellRenderer) ||
                    (cellRenderer instanceof SubstancePanelListCellRenderer);
    if (!isSubstanceRenderer) {
        fadeOutRolloverIndication();
        resetRolloverIndex();
        return;
    }

    int roIndex = list.locationToIndex(e.getPoint());
    if ((roIndex >= 0) && (roIndex < list.getModel().getSize())) {
        // test actual hit
        if (!list.getCellBounds(roIndex, roIndex).contains(e.getPoint())) {
            roIndex = -1;
        }
    }
    if ((roIndex < 0) || (roIndex >= list.getModel().getSize())) {
        fadeOutRolloverIndication();
        // System.out.println("Nulling RO index");
        resetRolloverIndex();
    } else {
        // check if this is the same index
        if ((rolledOverIndex >= 0) && (rolledOverIndex == roIndex))
            return;

        fadeOutRolloverIndication();

        // rollover on a new row
        StateTransitionTracker tracker = getTracker(roIndex, false,
                list.isSelectedIndex(roIndex));
        tracker.getModel().setRollover(true);
        rolledOverIndex = roIndex;
    }
}
 
Example #11
Source File: SubstancePasswordFieldUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates the UI delegate for the specified component (password field).
 *
 * @param c Component.
 */
private SubstancePasswordFieldUI(JComponent c) {
    super();
    this.passwordField = (JPasswordField) c;

    this.transitionModel = new DefaultButtonModel();
    this.transitionModel.setArmed(false);
    this.transitionModel.setSelected(false);
    this.transitionModel.setPressed(false);
    this.transitionModel.setRollover(false);
    this.transitionModel.setEnabled(this.passwordField.isEnabled());

    this.stateTransitionTracker = new StateTransitionTracker(this.passwordField,
            this.transitionModel);
}
 
Example #12
Source File: SubstanceTableHeaderUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public StateTransitionTracker.ModelStateInfo getModelStateInfo(int columnIndex) {
    if (this.stateTransitionMultiTracker.size() == 0)
        return null;
    StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(columnIndex);
    if (tracker == null) {
        return null;
    } else {
        return tracker.getModelStateInfo();
    }
}
 
Example #13
Source File: SubstanceListUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public StateTransitionTracker.ModelStateInfo getModelStateInfo(int row,
        Component rendererComponent) {
    if (this.stateTransitionMultiTracker.size() == 0)
        return null;
    StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(row);
    if (tracker == null) {
        return null;
    } else {
        return tracker.getModelStateInfo();
    }
}
 
Example #14
Source File: SubstanceTabbedPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void paintIcon(Graphics g, int tabPlacement, int tabIndex, Icon icon,
        Rectangle iconRect, boolean isSelected) {
    if (icon == null)
        return;

    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(iconRect.x, iconRect.y);
    if (SubstanceCoreUtilities.useThemedDefaultIcon(this.tabPane)) {
        ComponentState currState = this.getTabState(tabIndex, true);
        StateTransitionTracker tabTracker = stateTransitionMultiTracker.getTracker(tabIndex);

        if (tabTracker == null) {
            if (currState.isFacetActive(ComponentStateFacet.ROLLOVER)
                    || currState.isFacetActive(ComponentStateFacet.SELECTION)
                    || currState.isDisabled()) {
                // use the original (full color or disabled) icon
                icon.paintIcon(this.tabPane, g2d, 0, 0);
                return;
            }
        }

        Icon themed = SubstanceCoreUtilities.getThemedIcon(this.tabPane, tabIndex, icon);
        if (tabTracker == null) {
            themed.paintIcon(this.tabPane, g2d, 0, 0);
        } else {
            icon.paintIcon(this.tabPane, g2d, 0, 0);
            g2d.setComposite(WidgetUtilities.getAlphaComposite(this.tabPane,
                    1.0f - tabTracker.getFacetStrength(ComponentStateFacet.ROLLOVER), g2d));
            themed.paintIcon(this.tabPane, g2d, 0, 0);
        }
    } else {
        icon.paintIcon(this.tabPane, g2d, 0, 0);
    }
    g2d.dispose();
}
 
Example #15
Source File: SubstanceTableUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initiates the fade out effect.
 */
private void fadeOutRollover(TableCellId tableCellId) {
    if (rolledOverIndices.contains(tableCellId)) {
        // System.out
        // .println("Getting rollover/out tracker for " + cellId);
        StateTransitionTracker tracker = getTracker(tableCellId, true,
                getCellState(tableCellId).isFacetActive(ComponentStateFacet.SELECTION));
        tracker.getModel().setRollover(false);
    }
}
 
Example #16
Source File: SubstanceTableUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the current state for the specified cell.
 * 
 * @param cellIndex
 *            Cell index.
 * @return The current state for the specified cell.
 */
public ComponentState getCellState(TableCellId cellIndex) {
    boolean isEnabled = this.table.isEnabled();

    StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(cellIndex);
    if (tracker == null) {
        int row = cellIndex.row;
        int column = cellIndex.column;
        TableCellId cellId = this.getId(row, column);
        boolean isRollover = _hasRolloverAnimations() ? rolledOverIndices.contains(cellId) :
                (row == rolledOverRow);
        boolean isSelected = false;
        boolean hasSelectionAnimations = (this.updateInfo != null)
                ? this.updateInfo.hasSelectionAnimations
                : this._hasSelectionAnimations();
        if (hasSelectionAnimations && AnimationConfigurationManager.getInstance()
                .isAnimationAllowed(AnimationFacet.SELECTION, table))
            isSelected = this.selectedIndices.containsKey(cellId);
        else {
            isSelected = this.table.isCellSelected(row, column);
        }
        return ComponentState.getState(isEnabled, isRollover, isSelected);
    } else {
        ComponentState fromTracker = tracker.getModelStateInfo().getCurrModelState();
        return ComponentState.getState(isEnabled,
                fromTracker.isFacetActive(ComponentStateFacet.ROLLOVER),
                fromTracker.isFacetActive(ComponentStateFacet.SELECTION));
    }
}
 
Example #17
Source File: ColorSliderUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Creates a new instance. */
public ColorSliderUI(JSlider b) {
	super(b);
	this.thumbModel = new DefaultButtonModel();
	this.thumbModel.setArmed(false);
	this.thumbModel.setSelected(false);
	this.thumbModel.setPressed(false);
	this.thumbModel.setRollover(false);
	this.thumbModel.setEnabled(b.isEnabled());

	this.stateTransitionTracker = new StateTransitionTracker(b, this.thumbModel);
	// b.setLabelTable(new Hashtable());
}
 
Example #18
Source File: SubstanceTableUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handles various mouse move events and initiates the fade animation if necessary.
 * 
 * @param e
 *            Mouse event.
 */
private void handleMoveForHeader(MouseEvent e) {
    if (!SubstanceTableUI.this.table.getColumnSelectionAllowed())
        return;
    JTableHeader header = SubstanceTableUI.this.table.getTableHeader();
    if ((header == null) || (!header.isVisible()))
        return;

    TableHeaderUI ui = header.getUI();
    if (!(ui instanceof SubstanceTableHeaderUI))
        return;

    SubstanceTableHeaderUI sthui = (SubstanceTableHeaderUI) ui;

    // synchronized (SubstanceTableUI.this.table) {
    int row = SubstanceTableUI.this.table.rowAtPoint(e.getPoint());
    int column = SubstanceTableUI.this.table.columnAtPoint(e.getPoint());
    if ((row < 0) || (row >= SubstanceTableUI.this.table.getRowCount()) || (column < 0)
            || (column >= SubstanceTableUI.this.table.getColumnCount())) {
        this.fadeOutTableHeader();
        // System.out.println("Nulling RO column index");
        SubstanceTableUI.this.rolledOverColumn = -1;
    } else {
        // check if this is the same column
        if (SubstanceTableUI.this.rolledOverColumn == column)
            return;

        this.fadeOutTableHeader();

        TableColumnModel columnModel = header.getColumnModel();
        StateTransitionTracker columnTransitionTracker = sthui.getTracker(column, false,
                columnModel.getColumnSelectionAllowed()
                        && columnModel.getSelectionModel().isSelectedIndex(column));
        columnTransitionTracker.getModel().setRollover(true);

        SubstanceTableUI.this.rolledOverColumn = column;
    }
    // }
}
 
Example #19
Source File: SubstanceColorUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the foreground text color of the specified menu component.
 *
 * @param menuComponent  Menu component.
 * @param modelStateInfo Model state info for the component.
 * @return The foreground text color of the specified menu component.
 */
public static Color getMenuComponentForegroundColor(JMenuItem menuComponent,
        StateTransitionTracker.ModelStateInfo modelStateInfo) {
    ComponentState currState = modelStateInfo.getCurrModelStateNoSelection();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates =
            modelStateInfo.getStateNoSelectionContributionMap();

    ColorSchemeAssociationKind currAssocKind = ColorSchemeAssociationKind.FILL;
    // use HIGHLIGHT on active menu items
    if (!currState.isDisabled() && (currState != ComponentState.ENABLED))
        currAssocKind = ColorSchemeAssociationKind.HIGHLIGHT;
    SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities
            .getColorScheme(menuComponent, currAssocKind, currState);
    if (currState.isDisabled() || (activeStates == null)
            || (activeStates.size() == 1)) {
        return colorScheme.getForegroundColor();
    }

    float aggrRed = 0;
    float aggrGreen = 0;
    float aggrBlue = 0;
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry :
            activeStates.entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        float alpha = activeEntry.getValue().getContribution();
        ColorSchemeAssociationKind assocKind = ColorSchemeAssociationKind.FILL;
        // use HIGHLIGHT on active menu items
        if (!activeState.isDisabled()
                && (activeState != ComponentState.ENABLED))
            assocKind = ColorSchemeAssociationKind.HIGHLIGHT;
        SubstanceColorScheme activeColorScheme = SubstanceColorSchemeUtilities
                .getColorScheme(menuComponent, assocKind, activeState);
        Color activeForeground = activeColorScheme.getForegroundColor();
        aggrRed += alpha * activeForeground.getRed();
        aggrGreen += alpha * activeForeground.getGreen();
        aggrBlue += alpha * activeForeground.getBlue();
    }
    return new Color((int) aggrRed, (int) aggrGreen, (int) aggrBlue);
}
 
Example #20
Source File: RolloverButtonListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple constructor.
 * 
 * @param b
 *            The associated button.
 */
public RolloverButtonListener(AbstractButton b,
		StateTransitionTracker stateTransitionTracker) {
	super(b);
	this.button = b;
	this.isMouseInside = false;
	this.stateTransitionTracker = stateTransitionTracker;
}
 
Example #21
Source File: SubstanceEditorPaneUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple constructor.
 * 
 * @param c
 *            Component (editor pane).
 */
private SubstanceEditorPaneUI(JComponent c) {
    super();
    this.editorPane = (JEditorPane) c;

    this.transitionModel = new DefaultButtonModel();
    this.transitionModel.setArmed(false);
    this.transitionModel.setSelected(false);
    this.transitionModel.setPressed(false);
    this.transitionModel.setRollover(false);
    this.transitionModel.setEnabled(this.editorPane.isEnabled());

    this.stateTransitionTracker = new StateTransitionTracker(this.editorPane,
            this.transitionModel);
}
 
Example #22
Source File: SubstanceCommandButtonUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Color getMenuButtonForegroundColor(AbstractCommandButton menuButton,
        StateTransitionTracker.ModelStateInfo modelStateInfo) {
    ComponentState currState = modelStateInfo.getCurrModelStateNoSelection();
    Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
            .getStateNoSelectionContributionMap();

    SubstanceSlices.ColorSchemeAssociationKind currAssocKind = SubstanceSlices.ColorSchemeAssociationKind.FILL;
    // use HIGHLIGHT on active and non-rollover menu items
    if (!currState.isDisabled() && (currState != ComponentState.ENABLED)
            && !currState.isFacetActive(SubstanceSlices.ComponentStateFacet.ROLLOVER))
        currAssocKind = SubstanceSlices.ColorSchemeAssociationKind.HIGHLIGHT;
    SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.getColorScheme(menuButton,
            currAssocKind, currState);
    if (currState.isDisabled() || (activeStates == null) || (activeStates.size() == 1)) {
        return colorScheme.getForegroundColor();
    }

    float aggrRed = 0;
    float aggrGreen = 0;
    float aggrBlue = 0;
    for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
            .entrySet()) {
        ComponentState activeState = activeEntry.getKey();
        float alpha = activeEntry.getValue().getContribution();
        SubstanceSlices.ColorSchemeAssociationKind assocKind = SubstanceSlices.ColorSchemeAssociationKind.FILL;
        // use HIGHLIGHT on active and non-rollover menu items
        if (!activeState.isDisabled() && (activeState != ComponentState.ENABLED)
                && !activeState.isFacetActive(SubstanceSlices.ComponentStateFacet.ROLLOVER))
            assocKind = SubstanceSlices.ColorSchemeAssociationKind.HIGHLIGHT;
        SubstanceColorScheme activeColorScheme = SubstanceColorSchemeUtilities
                .getColorScheme(menuButton, assocKind, activeState);
        Color activeForeground = activeColorScheme.getForegroundColor();
        aggrRed += alpha * activeForeground.getRed();
        aggrGreen += alpha * activeForeground.getGreen();
        aggrBlue += alpha * activeForeground.getBlue();
    }
    return new Color((int) aggrRed, (int) aggrGreen, (int) aggrBlue);
}
 
Example #23
Source File: RolloverMenuItemListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple constructor.
 * 
 * @param item
 *            The associated menu item.
 */
public RolloverMenuItemListener(JMenuItem item,
		StateTransitionTracker stateTransitionTracker) {
	this.item = item;
	this.stateTransitionTracker = stateTransitionTracker;
	this.isMouseInside = false;
}
 
Example #24
Source File: SubstanceTreeUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public StateTransitionTracker.ModelStateInfo getModelStateInfo(TreePathId pathId) {
	if (this.stateTransitionMultiTracker.size() == 0)
		return null;
	StateTransitionTracker tracker = this.stateTransitionMultiTracker.getTracker(pathId);
	if (tracker == null) {
		return null;
	} else {
		return tracker.getModelStateInfo();
	}
}
 
Example #25
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 #26
Source File: SubstanceTreeUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initiates the fade out effect.
 */
private void fadeOut() {
	if (currRolloverPathId == null)
		return;

	StateTransitionTracker tracker = getTracker(currRolloverPathId, true,
			selectedPaths.containsKey(currRolloverPathId));
	tracker.getModel().setRollover(false);
}
 
Example #27
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void paintText(Graphics g, JComponent component, Rectangle textRect, String text,
        int mnemonicIndex, StateTransitionTracker.ModelStateInfo modelStateInfo,
        float textAlpha) {
    Color fgColor = getForegroundColor(component, text, modelStateInfo, textAlpha);

    SubstanceTextUtilities.paintText(g, component, textRect, text, mnemonicIndex,
            component.getFont(), fgColor, null);
}
 
Example #28
Source File: SubstanceTextUtilities.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void paintMenuItemText(Graphics g, JMenuItem menuItem, Rectangle textRect,
        String text, int mnemonicIndex, StateTransitionTracker.ModelStateInfo modelStateInfo,
        float textAlpha) {
    Color fgColor = getMenuComponentForegroundColor(menuItem, text, modelStateInfo, textAlpha);

    SubstanceTextUtilities.paintText(g, menuItem, textRect, text, mnemonicIndex,
            menuItem.getFont(), fgColor, null);
}
 
Example #29
Source File: SubstanceTreeUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handles various mouse move events and initiates the fade animation if
 * necessary.
 * 
 * @param e
 *            Mouse event.
 */
private void handleMove(MouseEvent e) {
	TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e.getY());
	Rectangle bounds = tree.getPathBounds(closestPath);
	if (bounds == null) {
		this.fadeOut();
		currRolloverPathId = null;
		return;
	}
	if ((e.getY() < bounds.y) || (e.getY() > (bounds.y + bounds.height))) {
		this.fadeOut();
		currRolloverPathId = null;
		return;
	}
	// check if this is the same index
	TreePathId newPathId = new TreePathId(closestPath);
	if ((currRolloverPathId != null) && newPathId.equals(currRolloverPathId)) {
		// System.out.println("Same location " +
		// System.currentTimeMillis());
		// System.out.print("Current : ");
		// for (Object o1 : currPathId.path.getPath()) {
		// System.out.print(o1);
		// }
		// System.out.println("");
		// System.out.print("Closest : ");
		// for (Object o2 : newPathId.path.getPath()) {
		// System.out.print(o2);
		// }
		// System.out.println("");
		return;
	}

	this.fadeOut();

	StateTransitionTracker tracker = getTracker(newPathId, false,
			selectedPaths.containsKey(newPathId));
	tracker.getModel().setRollover(true);

	currRolloverPathId = newPathId;
}
 
Example #30
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;
}