Popup: made Popup.show(), hide() and component listener more robust when used in unusual ways (issue #106)

This commit is contained in:
Karl Tauber
2020-06-07 15:25:11 +02:00
parent 049dae6584
commit e18e8e3158

View File

@@ -153,6 +153,7 @@ public class FlatPopupFactory
@Override
public void show() {
if( delegate != null )
delegate.show();
}
@@ -185,6 +186,7 @@ public class FlatPopupFactory
private boolean oldOpaque;
// medium weight
private boolean mediumWeightShown;
private Panel mediumWeightPanel;
private JPanel dropShadowPanel;
private ComponentListener mediumPanelListener;
@@ -311,6 +313,11 @@ public class FlatPopupFactory
}
private void showMediumWeightDropShadow() {
if( mediumWeightShown )
return;
mediumWeightShown = true;
Window window = SwingUtilities.windowForComponent( owner );
if( window == null )
return;
@@ -326,23 +333,28 @@ public class FlatPopupFactory
mediumPanelListener = new ComponentListener() {
@Override
public void componentShown( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setVisible( true );
}
@Override
public void componentHidden( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setVisible( false );
}
@Override
public void componentMoved( ComponentEvent e ) {
if( dropShadowPanel != null && mediumWeightPanel != null ) {
Point location = mediumWeightPanel.getLocation();
Insets insets = dropShadowPanel.getInsets();
dropShadowPanel.setLocation( location.x - insets.left, location.y - insets.top );
}
}
@Override
public void componentResized( ComponentEvent e ) {
if( dropShadowPanel != null )
dropShadowPanel.setSize( FlatUIUtils.addInsets( mediumWeightPanel.getSize(), dropShadowPanel.getInsets() ) );
}
};