UI defaults inspector: avoid that restored window bounds are outside of screens

This commit is contained in:
Karl Tauber
2020-09-15 15:09:03 +02:00
parent ee6a1da709
commit e292d3444c

View File

@@ -87,6 +87,7 @@ public class FlatUIDefaultsInspector
public static void show() {
if( inspector != null ) {
inspector.ensureOnScreen();
inspector.frame.toFront();
return;
}
@@ -143,9 +144,10 @@ public class FlatUIDefaultsInspector
int width = prefs.getInt( "width", UIScale.scale( 600 ) );
int height = prefs.getInt( "height", UIScale.scale( 800 ) );
frame.setSize( width, height );
if( x >= 0 && y >= 0 )
if( x != -1 && y != -1 ) {
frame.setLocation( x, y );
else
ensureOnScreen();
} else
frame.setLocationRelativeTo( null );
// restore column widths
@@ -193,6 +195,23 @@ public class FlatUIDefaultsInspector
} );
}
private void ensureOnScreen() {
Rectangle frameBounds = frame.getBounds();
boolean onScreen = false;
for( GraphicsDevice screen : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() ) {
GraphicsConfiguration gc = screen.getDefaultConfiguration();
Rectangle screenBounds = FlatUIUtils.subtractInsets( gc.getBounds(),
Toolkit.getDefaultToolkit().getScreenInsets( gc ) );
if( frameBounds.intersects( screenBounds ) ) {
onScreen = true;
break;
}
}
if( !onScreen )
frame.setLocationRelativeTo( null );
}
void lafChanged( PropertyChangeEvent e ) {
if( "lookAndFeel".equals( e.getPropertyName() ) )
refresh();