Window decorations:

- double-click on icon closes window
- after switching LaF is was not possible to move window when running in JetBrains Runtime
This commit is contained in:
Karl Tauber
2020-06-26 10:49:49 +02:00
parent 7720d42584
commit 7e8aaffb92

View File

@@ -122,6 +122,9 @@ class FlatTitlePane
addMouseListener( handler );
addMouseMotionListener( handler );
// necessary for closing window with double-click on icon
iconLabel.addMouseListener( handler );
}
private void addSubComponents() {
@@ -258,6 +261,8 @@ class FlatTitlePane
if( hasImages )
iconLabel.setIcon( FlatTitlePaneIcon.create( images, iconSize ) );
updateJBRHitTestSpotsAndTitleBarHeightLater();
}
@Override
@@ -275,7 +280,7 @@ class FlatTitlePane
installWindowListeners();
}
updateJBRHitTestSpotsAndTitleBarHeight();
updateJBRHitTestSpotsAndTitleBarHeightLater();
}
@Override
@@ -446,11 +451,17 @@ class FlatTitlePane
}
private boolean hasJBRCustomDecoration() {
return window != null &&
FlatRootPaneUI.canUseJBRCustomDecorations &&
return FlatRootPaneUI.canUseJBRCustomDecorations &&
window != null &&
JBRCustomDecorations.hasCustomDecoration( window );
}
private void updateJBRHitTestSpotsAndTitleBarHeightLater() {
EventQueue.invokeLater( () -> {
updateJBRHitTestSpotsAndTitleBarHeight();
} );
}
private void updateJBRHitTestSpotsAndTitleBarHeight() {
if( !isDisplayable() )
return;
@@ -459,8 +470,10 @@ class FlatTitlePane
return;
List<Rectangle> hitTestSpots = new ArrayList<>();
if( iconLabel.isVisible() )
addJBRHitTestSpot( iconLabel, false, hitTestSpots );
addJBRHitTestSpot( buttonPanel, false, hitTestSpots );
addJBRHitTestSpot( menuBarPlaceholder, true, hitTestSpots );//TOOD
addJBRHitTestSpot( menuBarPlaceholder, true, hitTestSpots );
int titleBarHeight = getHeight();
// slightly reduce height so that component receives mouseExit events
@@ -548,9 +561,7 @@ class FlatTitlePane
break;
case "componentOrientation":
EventQueue.invokeLater( () -> {
updateJBRHitTestSpotsAndTitleBarHeight();
} );
updateJBRHitTestSpotsAndTitleBarHeightLater();
break;
}
}
@@ -588,20 +599,21 @@ class FlatTitlePane
@Override
public void mouseClicked( MouseEvent e ) {
if( hasJBRCustomDecoration() )
return; // do nothing if running in JBR
if( e.getClickCount() == 2 &&
SwingUtilities.isLeftMouseButton( e ) &&
window instanceof Frame &&
((Frame)window).isResizable() )
{
// maximize/restore on double-click
Frame frame = (Frame) window;
if( (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
restore();
else
maximize();
if( e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton( e ) ) {
if( e.getSource() == iconLabel ) {
// double-click on icon closes window
close();
} else if( !hasJBRCustomDecoration() &&
window instanceof Frame &&
((Frame)window).isResizable() )
{
// maximize/restore on double-click
Frame frame = (Frame) window;
if( (frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 )
restore();
else
maximize();
}
}
}
@@ -667,9 +679,7 @@ class FlatTitlePane
@Override
public void componentResized( ComponentEvent e ) {
EventQueue.invokeLater( () -> {
updateJBRHitTestSpotsAndTitleBarHeight();
} );
updateJBRHitTestSpotsAndTitleBarHeightLater();
}
@Override public void componentMoved( ComponentEvent e ) {}