mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
ToolBar:
- swap margins if orientation changes when floating - include toolbar margin in grip position calculation
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -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 -------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -204,6 +204,7 @@ class DemoFrame
|
||||
|
||||
//======== toolBar1 ========
|
||||
{
|
||||
toolBar1.setMargin(new Insets(3, 3, 3, 3));
|
||||
toolBar1.add(backButton);
|
||||
toolBar1.add(forwardButton);
|
||||
toolBar1.addSeparator();
|
||||
|
||||
@@ -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"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user