updated CHANGELOG.md for PR #595 and added tab context menu test

This commit is contained in:
Karl Tauber
2022-09-30 15:33:37 +02:00
parent 0699454df8
commit 6e7c2a616b
3 changed files with 72 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ FlatLaf Change Log
- ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero. - ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero.
Minimum width of arrow buttons is 3/4 of default width. Minimum width of arrow buttons is 3/4 of default width.
- TabbedPane: Switch and close tabs on left mouse click only. (PR #595)
## 2.5 ## 2.5

View File

@@ -19,7 +19,9 @@ package com.formdev.flatlaf.testing;
import static com.formdev.flatlaf.FlatClientProperties.*; import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelListener;
import javax.swing.*; import javax.swing.*;
@@ -430,14 +432,14 @@ public class FlatContainerTest
} }
private void customWheelScrollingChanged() { private void customWheelScrollingChanged() {
if( custoMouseWheelScroller != null ) { if( customMouseWheelScroller != null ) {
for( FlatTabbedPane tabbedPane : allTabbedPanes ) for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.removeMouseWheelListener( custoMouseWheelScroller ); tabbedPane.removeMouseWheelListener( customMouseWheelScroller );
custoMouseWheelScroller = null; customMouseWheelScroller = null;
} }
if( customWheelScrollingCheckBox.isSelected() ) { if( customWheelScrollingCheckBox.isSelected() ) {
custoMouseWheelScroller = new MouseWheelListener() { customMouseWheelScroller = new MouseWheelListener() {
@Override @Override
public void mouseWheelMoved( MouseWheelEvent e ) { public void mouseWheelMoved( MouseWheelEvent e ) {
if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ) { if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ) {
@@ -451,7 +453,45 @@ public class FlatContainerTest
} }
}; };
for( FlatTabbedPane tabbedPane : allTabbedPanes ) for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.addMouseWheelListener( custoMouseWheelScroller ); tabbedPane.addMouseWheelListener( customMouseWheelScroller );
}
}
private void contextMenuChanged() {
if( contextMenuListener != null ) {
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.removeMouseListener( contextMenuListener );
contextMenuListener = null;
}
if( contextMenuCheckBox.isSelected() ) {
contextMenuListener = new MouseAdapter() {
@Override
public void mousePressed( MouseEvent e ) {
popupMenu( e );
}
@Override
public void mouseReleased( MouseEvent e ) {
popupMenu( e );
}
private void popupMenu( MouseEvent e ) {
if( !e.isPopupTrigger() )
return;
JTabbedPane tabbedPane = (JTabbedPane) e.getComponent();
int tabIndex = tabbedPane.indexAtLocation( e.getX(), e.getY() );
if( tabIndex < 0 )
return;
JPopupMenu popupMenu = new JPopupMenu();
popupMenu.add( "item 1" );
popupMenu.add( "item 2" );
popupMenu.add( "item 3" );
popupMenu.show( tabbedPane, e.getX(), e.getY() );
}
};
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabbedPane.addMouseListener( contextMenuListener );
} }
} }
@@ -515,6 +555,7 @@ public class FlatContainerTest
secondTabWiderCheckBox = new JCheckBox(); secondTabWiderCheckBox = new JCheckBox();
hideTabAreaWithOneTabCheckBox = new JCheckBox(); hideTabAreaWithOneTabCheckBox = new JCheckBox();
customWheelScrollingCheckBox = new JCheckBox(); customWheelScrollingCheckBox = new JCheckBox();
contextMenuCheckBox = new JCheckBox();
CellConstraints cc = new CellConstraints(); CellConstraints cc = new CellConstraints();
//======== this ======== //======== this ========
@@ -546,11 +587,11 @@ public class FlatContainerTest
splitPane1.setOneTouchExpandable(true); splitPane1.setOneTouchExpandable(true);
//---- panel15 ---- //---- panel15 ----
panel15.setBackground(new Color(217, 163, 67)); panel15.setBackground(new Color(0xd9a343));
splitPane1.setLeftComponent(panel15); splitPane1.setLeftComponent(panel15);
//---- panel21 ---- //---- panel21 ----
panel21.setBackground(new Color(98, 181, 67)); panel21.setBackground(new Color(0x62b543));
splitPane1.setRightComponent(panel21); splitPane1.setRightComponent(panel21);
} }
splitPane3.setLeftComponent(splitPane1); splitPane3.setLeftComponent(splitPane1);
@@ -563,7 +604,7 @@ public class FlatContainerTest
//======== panel12 ======== //======== panel12 ========
{ {
panel12.setBackground(new Color(242, 101, 34)); panel12.setBackground(new Color(0xf26522));
panel12.setLayout(new BorderLayout()); panel12.setLayout(new BorderLayout());
//---- label3 ---- //---- label3 ----
@@ -576,7 +617,7 @@ public class FlatContainerTest
//======== panel13 ======== //======== panel13 ========
{ {
panel13.setBackground(new Color(64, 182, 224)); panel13.setBackground(new Color(0x40b6e0));
panel13.setLayout(new BorderLayout()); panel13.setLayout(new BorderLayout());
//---- label4 ---- //---- label4 ----
@@ -636,6 +677,7 @@ public class FlatContainerTest
"[]para" + "[]para" +
"[]" + "[]" +
"[]" + "[]" +
"[]" +
"[]")); "[]"));
//---- tabScrollCheckBox ---- //---- tabScrollCheckBox ----
@@ -828,6 +870,11 @@ public class FlatContainerTest
customWheelScrollingCheckBox.setText("Custom wheel scrolling"); customWheelScrollingCheckBox.setText("Custom wheel scrolling");
customWheelScrollingCheckBox.addActionListener(e -> customWheelScrollingChanged()); customWheelScrollingCheckBox.addActionListener(e -> customWheelScrollingChanged());
tabbedPaneControlPanel.add(customWheelScrollingCheckBox, "cell 2 11"); tabbedPaneControlPanel.add(customWheelScrollingCheckBox, "cell 2 11");
//---- contextMenuCheckBox ----
contextMenuCheckBox.setText("Context menu on tabs");
contextMenuCheckBox.addActionListener(e -> contextMenuChanged());
tabbedPaneControlPanel.add(contextMenuCheckBox, "cell 2 12");
} }
panel9.add(tabbedPaneControlPanel, cc.xywh(1, 11, 3, 1)); panel9.add(tabbedPaneControlPanel, cc.xywh(1, 11, 3, 1));
} }
@@ -875,10 +922,12 @@ public class FlatContainerTest
private JCheckBox secondTabWiderCheckBox; private JCheckBox secondTabWiderCheckBox;
private JCheckBox hideTabAreaWithOneTabCheckBox; private JCheckBox hideTabAreaWithOneTabCheckBox;
private JCheckBox customWheelScrollingCheckBox; private JCheckBox customWheelScrollingCheckBox;
private JCheckBox contextMenuCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables
private FlatTabbedPane[] allTabbedPanes; private FlatTabbedPane[] allTabbedPanes;
private MouseWheelListener custoMouseWheelScroller; private MouseWheelListener customMouseWheelScroller;
private MouseListener contextMenuListener;
//---- enum TabPlacement -------------------------------------------------- //---- enum TabPlacement --------------------------------------------------

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8" JFDML JFormDesigner: "8.0.0.0.194" Java: "17.0.2" encoding: "UTF-8"
new FormModel { new FormModel {
contentType: "form/swing" contentType: "form/swing"
@@ -132,7 +132,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestFrame$NoRightToLeftPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestFrame$NoRightToLeftPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3" "$layoutConstraints": "insets 0,hidemode 3"
"$columnConstraints": "[][fill][]" "$columnConstraints": "[][fill][]"
"$rowConstraints": "[center][][][][][][]para[][]para[][][]" "$rowConstraints": "[center][][][][][][]para[][]para[][][][]"
} ) { } ) {
name: "tabbedPaneControlPanel" name: "tabbedPaneControlPanel"
"opaque": false "opaque": false
@@ -529,6 +529,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 11" "value": "cell 2 11"
} ) } )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "contextMenuCheckBox"
"text": "Context menu on tabs"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "contextMenuChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 12"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 11 "gridY": 11
"gridWidth": 3 "gridWidth": 3