mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 06:20:53 +03:00
TabbedPane: support specifying hiddenTabsNavigation type per tabbedpane via client property (issue #40)
This commit is contained in:
@@ -240,6 +240,30 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String TABBED_PANE_TAB_HEIGHT = "JTabbedPane.tabHeight";
|
String TABBED_PANE_TAB_HEIGHT = "JTabbedPane.tabHeight";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies how to navigate to hidden tabs.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JTabbedPane}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.String}
|
||||||
|
* <strong>Allowed Values</strong> {@link #TABBED_PANE_HIDDEN_TABS_NAVIGATION_MORE_TABS_BUTTON}
|
||||||
|
* or {@link #TABBED_PANE_HIDDEN_TABS_NAVIGATION_ARROW_BUTTONS}
|
||||||
|
*/
|
||||||
|
String TABBED_PANE_HIDDEN_TABS_NAVIGATION = "JTabbedPane.hiddenTabsNavigation";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use "more tabs" button for navigation to hidden tabs.
|
||||||
|
*
|
||||||
|
* @see #TABBED_PANE_HIDDEN_TABS_NAVIGATION
|
||||||
|
*/
|
||||||
|
String TABBED_PANE_HIDDEN_TABS_NAVIGATION_MORE_TABS_BUTTON = "moreTabsButton";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use forward/backward buttons for navigation to hidden tabs.
|
||||||
|
*
|
||||||
|
* @see #TABBED_PANE_HIDDEN_TABS_NAVIGATION
|
||||||
|
*/
|
||||||
|
String TABBED_PANE_HIDDEN_TABS_NAVIGATION_ARROW_BUTTONS = "arrowButtons";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether all text is selected when the text component gains focus.
|
* Specifies whether all text is selected when the text component gains focus.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -268,13 +268,27 @@ public class FlatTabbedPaneUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize here because used in installHiddenTabsNavigation() before installDefaults() was invoked
|
|
||||||
hiddenTabsNavigation = parseHiddenTabsNavigation( UIManager.getString( "TabbedPane.hiddenTabsNavigation" ) );
|
|
||||||
|
|
||||||
installHiddenTabsNavigation();
|
installHiddenTabsNavigation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installHiddenTabsNavigation() {
|
@Override
|
||||||
|
protected void uninstallComponents() {
|
||||||
|
// uninstall hidden tabs navigation before invoking super.uninstallComponents() for
|
||||||
|
// correct uninstallation of BasicTabbedPaneUI tab scroller support
|
||||||
|
uninstallHiddenTabsNavigation();
|
||||||
|
|
||||||
|
super.uninstallComponents();
|
||||||
|
|
||||||
|
tabViewport = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void installHiddenTabsNavigation() {
|
||||||
|
// initialize here because used in installHiddenTabsNavigation() before installDefaults() was invoked
|
||||||
|
String hiddenTabsNavigationStr = (String) tabPane.getClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION );
|
||||||
|
if( hiddenTabsNavigationStr == null )
|
||||||
|
hiddenTabsNavigationStr = UIManager.getString( "TabbedPane.hiddenTabsNavigation" );
|
||||||
|
hiddenTabsNavigation = parseHiddenTabsNavigation( hiddenTabsNavigationStr );
|
||||||
|
|
||||||
if( hiddenTabsNavigation != MORE_TABS_BUTTON ||
|
if( hiddenTabsNavigation != MORE_TABS_BUTTON ||
|
||||||
!isScrollTabLayout() ||
|
!isScrollTabLayout() ||
|
||||||
tabViewport == null )
|
tabViewport == null )
|
||||||
@@ -293,21 +307,16 @@ public class FlatTabbedPaneUI
|
|||||||
tabPane.add( moreTabsButton );
|
tabPane.add( moreTabsButton );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void uninstallHiddenTabsNavigation() {
|
||||||
protected void uninstallComponents() {
|
|
||||||
// restore layout manager before invoking super.uninstallComponents() for
|
// restore layout manager before invoking super.uninstallComponents() for
|
||||||
// correct uninstallation of BasicTabbedPaneUI tab scroller support
|
// correct uninstallation of BasicTabbedPaneUI tab scroller support
|
||||||
if( tabPane.getLayout() instanceof FlatTabbedPaneScrollLayout )
|
if( tabPane.getLayout() instanceof FlatTabbedPaneScrollLayout )
|
||||||
tabPane.setLayout( ((FlatTabbedPaneScrollLayout)tabPane.getLayout()).delegate );
|
tabPane.setLayout( ((FlatTabbedPaneScrollLayout)tabPane.getLayout()).delegate );
|
||||||
|
|
||||||
super.uninstallComponents();
|
|
||||||
|
|
||||||
if( moreTabsButton != null ) {
|
if( moreTabsButton != null ) {
|
||||||
tabPane.remove( moreTabsButton );
|
tabPane.remove( moreTabsButton );
|
||||||
moreTabsButton = null;
|
moreTabsButton = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
tabViewport = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1276,6 +1285,12 @@ public class FlatTabbedPaneUI
|
|||||||
tabPane.revalidate();
|
tabPane.revalidate();
|
||||||
tabPane.repaint();
|
tabPane.repaint();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TABBED_PANE_HIDDEN_TABS_NAVIGATION:
|
||||||
|
uninstallHiddenTabsNavigation();
|
||||||
|
installHiddenTabsNavigation();
|
||||||
|
tabPane.repaint();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.testing;
|
package com.formdev.flatlaf.testing;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER;
|
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||||
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_CONTENT_SEPARATOR;
|
|
||||||
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_TAB_SEPARATORS;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.*;
|
import javax.swing.border.*;
|
||||||
@@ -230,6 +228,19 @@ public class FlatContainerTest
|
|||||||
tabbedPane4.setTabPlacement( (tabPlacement >= 0) ? tabPlacement : SwingConstants.RIGHT );
|
tabbedPane4.setTabPlacement( (tabPlacement >= 0) ? tabPlacement : SwingConstants.RIGHT );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void hiddenTabsNavigationChanged() {
|
||||||
|
String value = null;
|
||||||
|
switch( (String) hiddenTabsNavigationField.getSelectedItem() ) {
|
||||||
|
case "moreTabsButton": value = TABBED_PANE_HIDDEN_TABS_NAVIGATION_MORE_TABS_BUTTON; break;
|
||||||
|
case "arrowButtons": value = TABBED_PANE_HIDDEN_TABS_NAVIGATION_ARROW_BUTTONS; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tabbedPane1.putClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION, value );
|
||||||
|
tabbedPane2.putClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION, value );
|
||||||
|
tabbedPane3.putClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION, value );
|
||||||
|
tabbedPane4.putClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION, value );
|
||||||
|
}
|
||||||
|
|
||||||
private void tabBackForegroundChanged() {
|
private void tabBackForegroundChanged() {
|
||||||
boolean enabled = tabBackForegroundCheckBox.isSelected();
|
boolean enabled = tabBackForegroundCheckBox.isSelected();
|
||||||
tabbedPane1.setBackgroundAt( 0, enabled ? Color.red : null );
|
tabbedPane1.setBackgroundAt( 0, enabled ? Color.red : null );
|
||||||
@@ -267,6 +278,8 @@ public class FlatContainerTest
|
|||||||
hasFullBorderCheckBox = new JCheckBox();
|
hasFullBorderCheckBox = new JCheckBox();
|
||||||
JLabel tabPlacementLabel = new JLabel();
|
JLabel tabPlacementLabel = new JLabel();
|
||||||
tabPlacementField = new JComboBox<>();
|
tabPlacementField = new JComboBox<>();
|
||||||
|
JLabel hiddenTabsNavigationLabel = new JLabel();
|
||||||
|
hiddenTabsNavigationField = new JComboBox<>();
|
||||||
tabBackForegroundCheckBox = new JCheckBox();
|
tabBackForegroundCheckBox = new JCheckBox();
|
||||||
CellConstraints cc = new CellConstraints();
|
CellConstraints cc = new CellConstraints();
|
||||||
|
|
||||||
@@ -452,6 +465,19 @@ public class FlatContainerTest
|
|||||||
tabPlacementField.addActionListener(e -> tabPlacementChanged());
|
tabPlacementField.addActionListener(e -> tabPlacementChanged());
|
||||||
panel14.add(tabPlacementField, "cell 1 2");
|
panel14.add(tabPlacementField, "cell 1 2");
|
||||||
|
|
||||||
|
//---- hiddenTabsNavigationLabel ----
|
||||||
|
hiddenTabsNavigationLabel.setText("Hidden tabs navigation:");
|
||||||
|
panel14.add(hiddenTabsNavigationLabel, "cell 2 2");
|
||||||
|
|
||||||
|
//---- hiddenTabsNavigationField ----
|
||||||
|
hiddenTabsNavigationField.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||||
|
"default",
|
||||||
|
"moreTabsButton",
|
||||||
|
"arrowButtons"
|
||||||
|
}));
|
||||||
|
hiddenTabsNavigationField.addActionListener(e -> hiddenTabsNavigationChanged());
|
||||||
|
panel14.add(hiddenTabsNavigationField, "cell 3 2");
|
||||||
|
|
||||||
//---- tabBackForegroundCheckBox ----
|
//---- tabBackForegroundCheckBox ----
|
||||||
tabBackForegroundCheckBox.setText("Tab back/foreground");
|
tabBackForegroundCheckBox.setText("Tab back/foreground");
|
||||||
tabBackForegroundCheckBox.addActionListener(e -> tabBackForegroundChanged());
|
tabBackForegroundCheckBox.addActionListener(e -> tabBackForegroundChanged());
|
||||||
@@ -479,6 +505,7 @@ public class FlatContainerTest
|
|||||||
private JCheckBox customTabsCheckBox;
|
private JCheckBox customTabsCheckBox;
|
||||||
private JCheckBox hasFullBorderCheckBox;
|
private JCheckBox hasFullBorderCheckBox;
|
||||||
private JComboBox<String> tabPlacementField;
|
private JComboBox<String> tabPlacementField;
|
||||||
|
private JComboBox<String> hiddenTabsNavigationField;
|
||||||
private JCheckBox tabBackForegroundCheckBox;
|
private JCheckBox tabBackForegroundCheckBox;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,28 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 2"
|
"value": "cell 1 2"
|
||||||
} )
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
|
name: "hiddenTabsNavigationLabel"
|
||||||
|
"text": "Hidden tabs navigation:"
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 2 2"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||||
|
name: "hiddenTabsNavigationField"
|
||||||
|
"model": new javax.swing.DefaultComboBoxModel {
|
||||||
|
selectedItem: "default"
|
||||||
|
addElement( "default" )
|
||||||
|
addElement( "moreTabsButton" )
|
||||||
|
addElement( "arrowButtons" )
|
||||||
|
}
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
"JavaCodeGenerator.typeParameters": "String"
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hiddenTabsNavigationChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 3 2"
|
||||||
|
} )
|
||||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
name: "tabBackForegroundCheckBox"
|
name: "tabBackForegroundCheckBox"
|
||||||
"text": "Tab back/foreground"
|
"text": "Tab back/foreground"
|
||||||
|
|||||||
Reference in New Issue
Block a user