From c98ec041d4aac48430b4ac06b9a1b7a1a61881f5 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 13 Nov 2020 22:26:14 +0100 Subject: [PATCH] Demo: "Tabs" tab: added "Scroll buttons policy", "Scroll buttons placement" and "Tabs popup policy" configuration for PR #211 --- .../com/formdev/flatlaf/demo/TabsPanel.java | 171 +++++++++++++++++- .../com/formdev/flatlaf/demo/TabsPanel.jfd | 125 ++++++++++++- 2 files changed, 285 insertions(+), 11 deletions(-) diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.java index 128b1ebb..ae59d89b 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.java @@ -280,6 +280,25 @@ class TabsPanel tabbedPane.addTab( "C", null ); } + private void tabsPopupPolicyChanged() { + String tabsPopupPolicy = popupNeverButton.isSelected() ? TABBED_PANE_POLICY_NEVER : null; + putTabbedPanesClientProperty( TABBED_PANE_TABS_POPUP_POLICY, tabsPopupPolicy ); + } + + private void scrollButtonsPolicyChanged() { + String scrollButtonsPolicy = scrollAsNeededButton.isSelected() + ? TABBED_PANE_POLICY_AS_NEEDED + : (scrollNeverButton.isSelected() + ? TABBED_PANE_POLICY_NEVER + : null); + putTabbedPanesClientProperty( TABBED_PANE_SCROLL_BUTTONS_POLICY, scrollButtonsPolicy ); + } + + private void scrollButtonsPlacementChanged() { + String scrollButtonsPlacement = scrollTrailingButton.isSelected() ? TABBED_PANE_PLACEMENT_TRAILING : null; + putTabbedPanesClientProperty( TABBED_PANE_SCROLL_BUTTONS_PLACEMENT, scrollButtonsPlacement ); + } + private void showTabSeparatorsChanged() { Boolean showTabSeparators = showTabSeparatorsCheckBox.isSelected() ? true : null; putTabbedPanesClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators ); @@ -362,7 +381,21 @@ class TabsPanel tabAlignVerticalTabbedPane = new JTabbedPane(); tabAlignCenterTabbedPane = new JTabbedPane(); tabAlignTrailingTabbedPane = new JTabbedPane(); + separator2 = new JSeparator(); JPanel panel4 = new JPanel(); + scrollButtonsPolicyLabel = new JLabel(); + scrollButtonsPolicyToolBar = new JToolBar(); + scrollAsNeededSingleButton = new JToggleButton(); + scrollAsNeededButton = new JToggleButton(); + scrollNeverButton = new JToggleButton(); + scrollButtonsPlacementLabel = new JLabel(); + scrollButtonsPlacementToolBar = new JToolBar(); + scrollBothButton = new JToggleButton(); + scrollTrailingButton = new JToggleButton(); + tabsPopupPolicyLabel = new JLabel(); + tabsPopupPolicyToolBar = new JToolBar(); + popupAsNeededButton = new JToggleButton(); + popupNeverButton = new JToggleButton(); showTabSeparatorsCheckBox = new JCheckBox(); //======== this ======== @@ -374,7 +407,8 @@ class TabsPanel "[fill]para" + "[fill]", // rows - "[grow,fill]" + + "[grow,fill]para" + + "[]" + "[]")); //======== panel1 ======== @@ -822,23 +856,122 @@ class TabsPanel } add(panel3, "cell 2 0"); + //---- separator2 ---- + separator2.setName("separator2"); + add(separator2, "cell 0 1 3 1"); + //======== panel4 ======== { panel4.setName("panel4"); panel4.setLayout(new MigLayout( "insets 0,hidemode 3", // columns - "[]", + "[]" + + "[fill]para" + + "[fill]" + + "[fill]para", // rows + "[]" + "[center]")); + //---- scrollButtonsPolicyLabel ---- + scrollButtonsPolicyLabel.setText("Scroll buttons policy:"); + scrollButtonsPolicyLabel.setName("scrollButtonsPolicyLabel"); + panel4.add(scrollButtonsPolicyLabel, "cell 0 0"); + + //======== scrollButtonsPolicyToolBar ======== + { + scrollButtonsPolicyToolBar.setFloatable(false); + scrollButtonsPolicyToolBar.setBorder(BorderFactory.createEmptyBorder()); + scrollButtonsPolicyToolBar.setName("scrollButtonsPolicyToolBar"); + + //---- scrollAsNeededSingleButton ---- + scrollAsNeededSingleButton.setText("asNeededSingle"); + scrollAsNeededSingleButton.setFont(scrollAsNeededSingleButton.getFont().deriveFont(scrollAsNeededSingleButton.getFont().getSize() - 2f)); + scrollAsNeededSingleButton.setSelected(true); + scrollAsNeededSingleButton.setName("scrollAsNeededSingleButton"); + scrollAsNeededSingleButton.addActionListener(e -> scrollButtonsPolicyChanged()); + scrollButtonsPolicyToolBar.add(scrollAsNeededSingleButton); + + //---- scrollAsNeededButton ---- + scrollAsNeededButton.setText("asNeeded"); + scrollAsNeededButton.setFont(scrollAsNeededButton.getFont().deriveFont(scrollAsNeededButton.getFont().getSize() - 2f)); + scrollAsNeededButton.setName("scrollAsNeededButton"); + scrollAsNeededButton.addActionListener(e -> scrollButtonsPolicyChanged()); + scrollButtonsPolicyToolBar.add(scrollAsNeededButton); + + //---- scrollNeverButton ---- + scrollNeverButton.setText("never"); + scrollNeverButton.setFont(scrollNeverButton.getFont().deriveFont(scrollNeverButton.getFont().getSize() - 2f)); + scrollNeverButton.setName("scrollNeverButton"); + scrollNeverButton.addActionListener(e -> scrollButtonsPolicyChanged()); + scrollButtonsPolicyToolBar.add(scrollNeverButton); + } + panel4.add(scrollButtonsPolicyToolBar, "cell 1 0"); + + //---- scrollButtonsPlacementLabel ---- + scrollButtonsPlacementLabel.setText("Scroll buttons placement:"); + scrollButtonsPlacementLabel.setName("scrollButtonsPlacementLabel"); + panel4.add(scrollButtonsPlacementLabel, "cell 2 0"); + + //======== scrollButtonsPlacementToolBar ======== + { + scrollButtonsPlacementToolBar.setFloatable(false); + scrollButtonsPlacementToolBar.setBorder(BorderFactory.createEmptyBorder()); + scrollButtonsPlacementToolBar.setName("scrollButtonsPlacementToolBar"); + + //---- scrollBothButton ---- + scrollBothButton.setText("both"); + scrollBothButton.setFont(scrollBothButton.getFont().deriveFont(scrollBothButton.getFont().getSize() - 2f)); + scrollBothButton.setSelected(true); + scrollBothButton.setName("scrollBothButton"); + scrollBothButton.addActionListener(e -> scrollButtonsPlacementChanged()); + scrollButtonsPlacementToolBar.add(scrollBothButton); + + //---- scrollTrailingButton ---- + scrollTrailingButton.setText("trailing"); + scrollTrailingButton.setFont(scrollTrailingButton.getFont().deriveFont(scrollTrailingButton.getFont().getSize() - 2f)); + scrollTrailingButton.setName("scrollTrailingButton"); + scrollTrailingButton.addActionListener(e -> scrollButtonsPlacementChanged()); + scrollButtonsPlacementToolBar.add(scrollTrailingButton); + } + panel4.add(scrollButtonsPlacementToolBar, "cell 3 0"); + + //---- tabsPopupPolicyLabel ---- + tabsPopupPolicyLabel.setText("Tabs popup policy:"); + tabsPopupPolicyLabel.setName("tabsPopupPolicyLabel"); + panel4.add(tabsPopupPolicyLabel, "cell 0 1"); + + //======== tabsPopupPolicyToolBar ======== + { + tabsPopupPolicyToolBar.setFloatable(false); + tabsPopupPolicyToolBar.setBorder(BorderFactory.createEmptyBorder()); + tabsPopupPolicyToolBar.setName("tabsPopupPolicyToolBar"); + + //---- popupAsNeededButton ---- + popupAsNeededButton.setText("asNeeded"); + popupAsNeededButton.setFont(popupAsNeededButton.getFont().deriveFont(popupAsNeededButton.getFont().getSize() - 2f)); + popupAsNeededButton.setSelected(true); + popupAsNeededButton.setName("popupAsNeededButton"); + popupAsNeededButton.addActionListener(e -> tabsPopupPolicyChanged()); + tabsPopupPolicyToolBar.add(popupAsNeededButton); + + //---- popupNeverButton ---- + popupNeverButton.setText("never"); + popupNeverButton.setFont(popupNeverButton.getFont().deriveFont(popupNeverButton.getFont().getSize() - 2f)); + popupNeverButton.setName("popupNeverButton"); + popupNeverButton.addActionListener(e -> tabsPopupPolicyChanged()); + tabsPopupPolicyToolBar.add(popupNeverButton); + } + panel4.add(tabsPopupPolicyToolBar, "cell 1 1"); + //---- showTabSeparatorsCheckBox ---- showTabSeparatorsCheckBox.setText("Show tab separators"); showTabSeparatorsCheckBox.setName("showTabSeparatorsCheckBox"); showTabSeparatorsCheckBox.addActionListener(e -> showTabSeparatorsChanged()); - panel4.add(showTabSeparatorsCheckBox, "cell 0 0"); + panel4.add(showTabSeparatorsCheckBox, "cell 2 1 2 1"); } - add(panel4, "cell 0 1 3 1"); + add(panel4, "cell 0 2 3 1"); //---- tabPlacementButtonGroup ---- ButtonGroup tabPlacementButtonGroup = new ButtonGroup(); @@ -857,6 +990,22 @@ class TabsPanel closableTabsButtonGroup.add(squareCloseButton); closableTabsButtonGroup.add(circleCloseButton); closableTabsButtonGroup.add(redCrossCloseButton); + + //---- scrollButtonsPolicyButtonGroup ---- + ButtonGroup scrollButtonsPolicyButtonGroup = new ButtonGroup(); + scrollButtonsPolicyButtonGroup.add(scrollAsNeededSingleButton); + scrollButtonsPolicyButtonGroup.add(scrollAsNeededButton); + scrollButtonsPolicyButtonGroup.add(scrollNeverButton); + + //---- scrollButtonsPlacementButtonGroup ---- + ButtonGroup scrollButtonsPlacementButtonGroup = new ButtonGroup(); + scrollButtonsPlacementButtonGroup.add(scrollBothButton); + scrollButtonsPlacementButtonGroup.add(scrollTrailingButton); + + //---- tabsPopupPolicyButtonGroup ---- + ButtonGroup tabsPopupPolicyButtonGroup = new ButtonGroup(); + tabsPopupPolicyButtonGroup.add(popupAsNeededButton); + tabsPopupPolicyButtonGroup.add(popupNeverButton); // JFormDesigner - End of component initialization //GEN-END:initComponents } @@ -903,6 +1052,20 @@ class TabsPanel private JTabbedPane tabAlignVerticalTabbedPane; private JTabbedPane tabAlignCenterTabbedPane; private JTabbedPane tabAlignTrailingTabbedPane; + private JSeparator separator2; + private JLabel scrollButtonsPolicyLabel; + private JToolBar scrollButtonsPolicyToolBar; + private JToggleButton scrollAsNeededSingleButton; + private JToggleButton scrollAsNeededButton; + private JToggleButton scrollNeverButton; + private JLabel scrollButtonsPlacementLabel; + private JToolBar scrollButtonsPlacementToolBar; + private JToggleButton scrollBothButton; + private JToggleButton scrollTrailingButton; + private JLabel tabsPopupPolicyLabel; + private JToolBar tabsPopupPolicyToolBar; + private JToggleButton popupAsNeededButton; + private JToggleButton popupNeverButton; private JCheckBox showTabSeparatorsCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables } diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.jfd index e14e73ef..3f634b86 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/TabsPanel.jfd @@ -7,7 +7,7 @@ new FormModel { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "insets dialog,hidemode 3" "$columnConstraints": "[grow,fill]para[fill]para[fill]" - "$rowConstraints": "[grow,fill][]" + "$rowConstraints": "[grow,fill]para[][]" } ) { name: "this" add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { @@ -98,7 +98,7 @@ new FormModel { add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) { name: "tabLayoutToolBar" "floatable": false - "border": new javax.swing.border.EmptyBorder( 0, 0, 0, 0 ) + "border": &EmptyBorder0 new javax.swing.border.EmptyBorder( 0, 0, 0, 0 ) add( new FormComponent( "javax.swing.JToggleButton" ) { name: "scrollTabLayoutButton" "text": "scroll" @@ -450,15 +450,111 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 2 0" } ) + add( new FormComponent( "javax.swing.JSeparator" ) { + name: "separator2" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1 3 1" + } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "insets 0,hidemode 3" - "$columnConstraints": "[]" - "$rowConstraints": "[center]" + "$columnConstraints": "[][fill]para[fill][fill]para" + "$rowConstraints": "[][center]" } ) { name: "panel4" auxiliary() { "JavaCodeGenerator.variableLocal": true } + add( new FormComponent( "javax.swing.JLabel" ) { + name: "scrollButtonsPolicyLabel" + "text": "Scroll buttons policy:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) { + name: "scrollButtonsPolicyToolBar" + "floatable": false + "border": #EmptyBorder0 + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "scrollAsNeededSingleButton" + "text": "asNeededSingle" + "font": #SwingDerivedFont2 + "selected": true + "$buttonGroup": new FormReference( "scrollButtonsPolicyButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scrollButtonsPolicyChanged", false ) ) + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "scrollAsNeededButton" + "text": "asNeeded" + "font": #SwingDerivedFont2 + "$buttonGroup": new FormReference( "scrollButtonsPolicyButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scrollButtonsPolicyChanged", false ) ) + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "scrollNeverButton" + "text": "never" + "font": #SwingDerivedFont2 + "$buttonGroup": new FormReference( "scrollButtonsPolicyButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scrollButtonsPolicyChanged", false ) ) + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 0" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "scrollButtonsPlacementLabel" + "text": "Scroll buttons placement:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 0" + } ) + add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) { + name: "scrollButtonsPlacementToolBar" + "floatable": false + "border": #EmptyBorder0 + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "scrollBothButton" + "text": "both" + "font": #SwingDerivedFont2 + "selected": true + "$buttonGroup": new FormReference( "scrollButtonsPlacementButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scrollButtonsPlacementChanged", false ) ) + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "scrollTrailingButton" + "text": "trailing" + "font": #SwingDerivedFont2 + "$buttonGroup": new FormReference( "scrollButtonsPlacementButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "scrollButtonsPlacementChanged", false ) ) + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 0" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "tabsPopupPolicyLabel" + "text": "Tabs popup policy:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) + add( new FormContainer( "javax.swing.JToolBar", new FormLayoutManager( class javax.swing.JToolBar ) ) { + name: "tabsPopupPolicyToolBar" + "floatable": false + "border": #EmptyBorder0 + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "popupAsNeededButton" + "text": "asNeeded" + "font": #SwingDerivedFont2 + "selected": true + "$buttonGroup": new FormReference( "tabsPopupPolicyButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabsPopupPolicyChanged", false ) ) + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "popupNeverButton" + "text": "never" + "font": #SwingDerivedFont2 + "$buttonGroup": new FormReference( "tabsPopupPolicyButtonGroup" ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabsPopupPolicyChanged", false ) ) + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 1" + } ) add( new FormComponent( "javax.swing.JCheckBox" ) { name: "showTabSeparatorsCheckBox" "text": "Show tab separators" @@ -467,14 +563,14 @@ new FormModel { } addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTabSeparatorsChanged", false ) ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 0" + "value": "cell 2 1 2 1" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 1 3 1" + "value": "cell 0 2 3 1" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) - "size": new java.awt.Dimension( 1075, 860 ) + "size": new java.awt.Dimension( 1075, 895 ) } ) add( new FormNonVisual( "javax.swing.ButtonGroup" ) { name: "tabPlacementButtonGroup" @@ -491,5 +587,20 @@ new FormModel { }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 5, 1020 ) } ) + add( new FormNonVisual( "javax.swing.ButtonGroup" ) { + name: "tabsPopupPolicyButtonGroup" + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 200, 915 ) + } ) + add( new FormNonVisual( "javax.swing.ButtonGroup" ) { + name: "scrollButtonsPolicyButtonGroup" + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 200, 965 ) + } ) + add( new FormNonVisual( "javax.swing.ButtonGroup" ) { + name: "scrollButtonsPlacementButtonGroup" + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 200, 1020 ) + } ) } }