Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimatedBorder #353

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

AnimatedBorder #353

wants to merge 8 commits into from

Conversation

DevCharly
Copy link
Collaborator

This PR adds interface AnimatedBorder (extends javax.swing.border.Border)
that automatically animates painting on component value changes.

This is similar to AnimatedIcon (see PR #222)

The cool thing is that the animation is done in the border and it is not necessary to change anything in the UI delegates.
This is not yet used, but intended for future animates (issue #66).

The test application FlatAnimatedBorderTest includes (experimental) animated borders
for text fields and a minimal example:

animated-border-200

Same as above but using 1000ms duration to better see the animation:

animated-border-1000

Here is the code for a minimal example:

private class AnimatedMinimalTestBorder
    implements AnimatedBorder
{
    @Override
    public void paintBorderAnimated( Component c, Graphics g, int x, int y, int width, int height, float animatedValue ) {
        int lh = UIScale.scale( 2 );

        g.setColor( Color.blue );
        g.fillRect( x, y + height - lh, Math.round( width * animatedValue ), lh );
    }

    @Override
    public float getValue( Component c ) {
        return c.isFocusOwner() ? 1 : 0;
    }

    @Override
    public Insets getBorderInsets( Component c ) {
        return UIScale.scale( new Insets( 4, 4, 4, 4 ) );
    }

    @Override public boolean isBorderOpaque() { return false; }
}

// sample usage
JTextField textField = new JTextField();
textField.setBorder( new AnimatedMinimalTestBorder() );

- support repainting only necessary region while animating
- use AbstractBorder in test app and fixed insets
(checked API compatibility of AnimatedIcon with gradle task sigtestCheck)
(line chart copied from `FlatSmoothScrollingTest.LineChartPanel` in branch `smooth-scrolling` commit 331ab06)
- support synchronized line chart
- LineChartPanel: added slider to change horizontal scaling
- FlatAnimatedIconTest: added line chart panel
- FlatAnimatedBorderTest: added line chart panel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant