Skip to content

Commit

Permalink
InternalFrame: double-click on icon in internal frame title bar now c…
Browse files Browse the repository at this point in the history
…loses the internal frame (issue #374)
  • Loading branch information
DevCharly committed Aug 13, 2021
1 parent 268fe15 commit a613a24
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
FlatLaf Change Log
==================

## 1.6-SNAPSHOT

#### New features and improvements

- InternalFrame: Double-click on icon in internal frame title bar now closes the
internal frame. (issue #374)


## 1.5

#### New features and improvements

- SwingX: Added search and clear icons to `JXSearchField`. (issue #359)


#### Fixed bugs

- Button and TextComponent: Do not apply minimum width/height if margins are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
Expand Down Expand Up @@ -146,6 +147,19 @@ protected void updateButtonsVisibility() {
closeButton.setVisible( frame.isClosable() );
}

Rectangle getFrameIconBounds() {
Icon icon = titleLabel.getIcon();
if( icon == null )
return null;

int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
boolean leftToRight = titleLabel.getComponentOrientation().isLeftToRight();
int x = titleLabel.getX() + (leftToRight ? 0 : (titleLabel.getWidth() - iconWidth));
int y = titleLabel.getY() + ((titleLabel.getHeight() - iconHeight) / 2);
return new Rectangle( x, y, iconWidth, iconHeight );
}

/**
* Does nothing because FlatLaf internal frames do not have system menus.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.event.MouseInputAdapter;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;

Expand Down Expand Up @@ -122,6 +125,11 @@ protected FlatWindowResizer createWindowResizer() {
return new FlatWindowResizer.InternalFrameResizer( frame, this::getDesktopManager );
}

@Override
protected MouseInputAdapter createBorderListener( JInternalFrame w ) {
return new FlatBorderListener();
}

//---- class FlatInternalFrameBorder --------------------------------------

public static class FlatInternalFrameBorder
Expand Down Expand Up @@ -195,4 +203,26 @@ public void paintBorder( Component c, Graphics g, int x, int y, int width, int h
}
}
}

//---- class FlatBorderListener -------------------------------------------

protected class FlatBorderListener
extends BorderListener
{
@Override
public void mouseClicked( MouseEvent e ) {
if( e.getClickCount() == 2 && !frame.isIcon() &&
e.getSource() instanceof FlatInternalFrameTitlePane )
{
Rectangle iconBounds = ((FlatInternalFrameTitlePane)e.getSource()).getFrameIconBounds();
if( iconBounds != null && iconBounds.contains( e.getX(), e.getY() ) ) {
if( frame.isClosable() )
frame.doDefaultCloseAction();
return;
}
}

super.mouseClicked( e );
}
}
}

0 comments on commit a613a24

Please sign in to comment.