- swap margins if orientation changes when floating
- include toolbar margin in grip position calculation
This commit is contained in:
Karl Tauber
2019-09-08 12:13:08 +02:00
parent c69e9e12c6
commit 7b1eda45cd
4 changed files with 32 additions and 5 deletions

View File

@@ -63,12 +63,24 @@ public class FlatToolBarBorder
int gapSize = dotSize;
int gripSize = (dotSize * DOT_COUNT) + ((gapSize * (DOT_COUNT - 1)));
boolean horizontal = ((JToolBar)c).getOrientation() == SwingConstants.HORIZONTAL;
if( horizontal && !c.getComponentOrientation().isLeftToRight() )
x += width - scale( GRIP_WIDTH );
x += horizontal ? dotSize : Math.round( (width - gripSize) / 2f );
y += horizontal ? Math.round( (height - gripSize) / 2f ) : dotSize;
// include toolbar margin in grip position calculation
Insets insets = getBorderInsets( c );
// calculate grip position
boolean horizontal = ((JToolBar)c).getOrientation() == SwingConstants.HORIZONTAL;
if( horizontal ) {
if( c.getComponentOrientation().isLeftToRight() )
x += insets.left - (dotSize * 2);
else
x += width - insets.right + dotSize;
y += Math.round( (height - gripSize) / 2f );
} else {
// vertical
x += Math.round( (width - gripSize) / 2f );
y += insets.top - (dotSize * 2);
}
// paint dots
for( int i = 0; i < DOT_COUNT; i++ ) {
g.fillOval( x, y, dotSize, dotSize );
if( horizontal )

View File

@@ -74,6 +74,19 @@ public class FlatToolBarUI
return rolloverBorder;
}
@Override
public void setOrientation( int orientation ) {
if( orientation != toolBar.getOrientation() ) {
// swap margins if orientation changes when floating
Insets margin = toolBar.getMargin();
Insets newMargin = new Insets( margin.left, margin.top, margin.right, margin.bottom );
if( !newMargin.equals( margin ) )
toolBar.setMargin( newMargin );
}
super.setOrientation( orientation );
}
//---- class FlatRolloverMarginBorder -------------------------------------
/**

View File

@@ -204,6 +204,7 @@ class DemoFrame
//======== toolBar1 ========
{
toolBar1.setMargin(new Insets(3, 3, 3, 3));
toolBar1.add(backButton);
toolBar1.add(forwardButton);
toolBar1.addSeparator();

View File

@@ -14,6 +14,7 @@ new FormModel {
"$sizePolicy": 2
add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) {
name: "toolBar1"
"margin": new java.awt.Insets( 3, 3, 3, 3 )
add( new FormComponent( "javax.swing.JButton" ) {
name: "backButton"
} )