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