SplitPane: implemented one-touch buttons

This commit is contained in:
Karl Tauber
2019-09-08 18:54:25 +02:00
parent 83f88cd3a8
commit 650ce12c22
8 changed files with 185 additions and 20 deletions

View File

@@ -118,6 +118,7 @@ public class FlatArrowButton
g.fillRect( 0, 0, width, height );
}
int direction = getDirection();
boolean vert = (direction == NORTH || direction == SOUTH);
int w = scale( 9 );

View File

@@ -16,7 +16,12 @@
package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Cursor;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
@@ -33,6 +38,8 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault SplitPane.border Border
* @uiDefault SplitPaneDivider.border Border
* @uiDefault SplitPaneDivider.draggingColor Color only used if continuousLayout is false
* @uiDefault SplitPaneDivider.oneTouchArrowColor Color
* @uiDefault SplitPaneDivider.oneTouchHoverArrowColor Color
*
* @author Karl Tauber
*/
@@ -40,6 +47,8 @@ public class FlatSplitPaneUI
extends BasicSplitPaneUI
{
private Boolean continuousLayout;
private Color oneTouchArrowColor;
private Color oneTouchHoverArrowColor;
public static ComponentUI createUI( JComponent c ) {
return new FlatSplitPaneUI();
@@ -47,6 +56,11 @@ public class FlatSplitPaneUI
@Override
protected void installDefaults() {
// get one-touch colors before invoking super.installDefaults() because they are
// used in there on LaF switching
oneTouchArrowColor = UIManager.getColor( "SplitPaneDivider.oneTouchArrowColor" );
oneTouchHoverArrowColor = UIManager.getColor( "SplitPaneDivider.oneTouchHoverArrowColor" );
super.installDefaults();
continuousLayout = (Boolean) UIManager.get( "SplitPane.continuousLayout" );
@@ -64,7 +78,7 @@ public class FlatSplitPaneUI
//---- class FlatSplitPaneDivider -----------------------------------------
private static class FlatSplitPaneDivider
private class FlatSplitPaneDivider
extends BasicSplitPaneDivider
{
public FlatSplitPaneDivider( BasicSplitPaneUI ui ) {
@@ -75,5 +89,38 @@ public class FlatSplitPaneUI
public void setDividerSize( int newSize ) {
super.setDividerSize( UIScale.scale( newSize ) );
}
@Override
protected JButton createLeftOneTouchButton() {
return new FlatOneTouchButton( true );
}
@Override
protected JButton createRightOneTouchButton() {
return new FlatOneTouchButton( false );
}
//---- class FlatOneTouchButton ---------------------------------------
private class FlatOneTouchButton
extends FlatArrowButton
{
private final boolean left;
public FlatOneTouchButton( boolean left ) {
super( SwingConstants.NORTH, oneTouchArrowColor, null, oneTouchHoverArrowColor, null );
setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
this.left = left;
}
@Override
public int getDirection() {
return (orientation == JSplitPane.VERTICAL_SPLIT)
? (left ? SwingConstants.NORTH : SwingConstants.SOUTH)
: (left ? SwingConstants.WEST : SwingConstants.EAST);
}
}
}
}

View File

@@ -175,6 +175,7 @@ Slider.disabledForeground=4c5052
#---- SplitPane ----
SplitPaneDivider.draggingColor=646464
SplitPaneDivider.oneTouchHoverArrowColor=7A7D81
#---- TabbedPane ----

View File

@@ -239,7 +239,9 @@ Spinner.padding=@textComponentMargin
SplitPane.dividerSize=5
SplitPane.continuousLayout=true
SplitPane.border=null
SplitPane.centerOneTouchButtons=true
SplitPaneDivider.border=null
SplitPaneDivider.oneTouchArrowColor=@@ComboBox.buttonArrowColor
#---- TabbedPane ----

View File

@@ -175,6 +175,7 @@ Slider.disabledForeground=c0c0c0
#---- SplitPane ----
SplitPaneDivider.draggingColor=c4c4c4
SplitPaneDivider.oneTouchHoverArrowColor=333333
#---- TabbedPane ----

View File

@@ -65,6 +65,14 @@ public class FlatContainerTest
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JPanel panel9 = new JPanel();
JLabel splitPaneLabel = new JLabel();
JSplitPane splitPane3 = new JSplitPane();
JSplitPane splitPane1 = new JSplitPane();
JPanel panel10 = new JPanel();
JPanel panel11 = new JPanel();
JSplitPane splitPane2 = new JSplitPane();
JPanel panel12 = new JPanel();
JPanel panel13 = new JPanel();
JLabel tabbedPaneLabel = new JLabel();
tabbedPane1 = new JTabbedPane();
JPanel panel1 = new JPanel();
@@ -105,11 +113,64 @@ public class FlatContainerTest
{
panel9.setLayout(new FormLayout(
"70dlu:grow, $lcgap, 70dlu:grow",
"pref, 2*($lgap, fill:70dlu:grow), 2*($lgap, pref)"));
"default, $lgap, fill:70dlu, $lgap, pref, 2*($lgap, fill:70dlu:grow), 2*($lgap, pref)"));
//---- splitPaneLabel ----
splitPaneLabel.setText("JSplitPane:");
panel9.add(splitPaneLabel, cc.xy(1, 1));
//======== splitPane3 ========
{
splitPane3.setResizeWeight(0.5);
//======== splitPane1 ========
{
splitPane1.setResizeWeight(0.5);
splitPane1.setOneTouchExpandable(true);
//======== panel10 ========
{
panel10.setBackground(Color.orange);
panel10.setLayout(new FlowLayout());
}
splitPane1.setLeftComponent(panel10);
//======== panel11 ========
{
panel11.setBackground(Color.magenta);
panel11.setLayout(new FlowLayout());
}
splitPane1.setRightComponent(panel11);
}
splitPane3.setLeftComponent(splitPane1);
//======== splitPane2 ========
{
splitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPane2.setResizeWeight(0.5);
splitPane2.setOneTouchExpandable(true);
//======== panel12 ========
{
panel12.setBackground(Color.orange);
panel12.setLayout(new FlowLayout());
}
splitPane2.setTopComponent(panel12);
//======== panel13 ========
{
panel13.setBackground(Color.magenta);
panel13.setLayout(new FlowLayout());
}
splitPane2.setBottomComponent(panel13);
}
splitPane3.setRightComponent(splitPane2);
}
panel9.add(splitPane3, cc.xywh(1, 3, 3, 1));
//---- tabbedPaneLabel ----
tabbedPaneLabel.setText("JTabbedPane:");
panel9.add(tabbedPaneLabel, cc.xy(1, 1));
panel9.add(tabbedPaneLabel, cc.xy(1, 5));
//======== tabbedPane1 ========
{
@@ -135,7 +196,7 @@ public class FlatContainerTest
label2.setText("text");
tabbedPane1.addTab("Tab 3", label2);
}
panel9.add(tabbedPane1, cc.xy(1, 3));
panel9.add(tabbedPane1, cc.xy(1, 7));
//======== tabbedPane3 ========
{
@@ -162,7 +223,7 @@ public class FlatContainerTest
label6.setText("text");
tabbedPane3.addTab("Tab 3", label6);
}
panel9.add(tabbedPane3, cc.xy(3, 3));
panel9.add(tabbedPane3, cc.xy(3, 7));
//======== tabbedPane2 ========
{
@@ -190,7 +251,7 @@ public class FlatContainerTest
label4.setText("text");
tabbedPane2.addTab("Tab 3", label4);
}
panel9.add(tabbedPane2, cc.xy(1, 5));
panel9.add(tabbedPane2, cc.xy(1, 9));
//======== tabbedPane4 ========
{
@@ -217,25 +278,25 @@ public class FlatContainerTest
label8.setText("text");
tabbedPane4.addTab("Tab 3", label8);
}
panel9.add(tabbedPane4, cc.xy(3, 5));
panel9.add(tabbedPane4, cc.xy(3, 9));
//---- tabScrollCheckBox ----
tabScrollCheckBox.setText("tabLayoutPolicy = SCROLL");
tabScrollCheckBox.setMnemonic('S');
tabScrollCheckBox.addActionListener(e -> tabScrollChanged());
panel9.add(tabScrollCheckBox, cc.xy(1, 7, CellConstraints.LEFT, CellConstraints.DEFAULT));
panel9.add(tabScrollCheckBox, cc.xy(1, 11, CellConstraints.LEFT, CellConstraints.DEFAULT));
//---- hasFullBorderCheckBox ----
hasFullBorderCheckBox.setText("JTabbedPane.hasFullBorder");
hasFullBorderCheckBox.setMnemonic('F');
hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged());
panel9.add(hasFullBorderCheckBox, cc.xy(3, 7, CellConstraints.LEFT, CellConstraints.DEFAULT));
panel9.add(hasFullBorderCheckBox, cc.xy(3, 11, CellConstraints.LEFT, CellConstraints.DEFAULT));
//---- moreTabsCheckBox ----
moreTabsCheckBox.setText("more tabs");
moreTabsCheckBox.setMnemonic('M');
moreTabsCheckBox.addActionListener(e -> moreTabsChanged());
panel9.add(moreTabsCheckBox, cc.xy(1, 9, CellConstraints.LEFT, CellConstraints.DEFAULT));
panel9.add(moreTabsCheckBox, cc.xy(1, 13, CellConstraints.LEFT, CellConstraints.DEFAULT));
}
add(panel9, "cell 0 0");
// JFormDesigner - End of component initialization //GEN-END:initComponents

View File

@@ -14,15 +14,65 @@ new FormModel {
name: "this"
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jgoodies.forms.layout.FormLayout ) {
"$columnSpecs": "70dlu:grow, labelcompgap, 70dlu:grow"
"$rowSpecs": "pref, linegap, fill:70dlu:grow, linegap, fill:70dlu:grow, linegap, pref, linegap, pref"
"$rowSpecs": "default, linegap, fill:70dlu, linegap, pref, linegap, fill:70dlu:grow, linegap, fill:70dlu:grow, linegap, pref, linegap, pref"
} ) {
name: "panel9"
add( new FormComponent( "javax.swing.JLabel" ) {
name: "splitPaneLabel"
"text": "JSplitPane:"
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) )
add( new FormContainer( "javax.swing.JSplitPane", new FormLayoutManager( class javax.swing.JSplitPane ) ) {
name: "splitPane3"
"resizeWeight": 0.5
add( new FormContainer( "javax.swing.JSplitPane", new FormLayoutManager( class javax.swing.JSplitPane ) ) {
name: "splitPane1"
"resizeWeight": 0.5
"oneTouchExpandable": true
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.FlowLayout ) ) {
name: "panel10"
"background": sfield java.awt.Color orange
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "left"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.FlowLayout ) ) {
name: "panel11"
"background": sfield java.awt.Color magenta
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "right"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "left"
} )
add( new FormContainer( "javax.swing.JSplitPane", new FormLayoutManager( class javax.swing.JSplitPane ) ) {
name: "splitPane2"
"orientation": 0
"resizeWeight": 0.5
"oneTouchExpandable": true
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.FlowLayout ) ) {
name: "panel12"
"background": sfield java.awt.Color orange
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "left"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.FlowLayout ) ) {
name: "panel13"
"background": sfield java.awt.Color magenta
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "right"
} )
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "right"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 3
"gridWidth": 3
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "tabbedPaneLabel"
"text": "JTabbedPane:"
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 1
"gridY": 1
"gridY": 5
} )
add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) {
name: "tabbedPane1"
@@ -52,7 +102,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 1
"gridY": 3
"gridY": 7
} )
add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) {
name: "tabbedPane3"
@@ -83,7 +133,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 3
"gridY": 3
"gridY": 7
} )
add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) {
name: "tabbedPane2"
@@ -114,7 +164,7 @@ new FormModel {
"title": "Tab 3"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 5
"gridY": 9
} )
add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) {
name: "tabbedPane4"
@@ -145,7 +195,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 3
"gridY": 5
"gridY": 9
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "tabScrollCheckBox"
@@ -157,7 +207,7 @@ new FormModel {
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabScrollChanged", false ) )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 1
"gridY": 7
"gridY": 11
"hAlign": sfield com.jgoodies.forms.layout.CellConstraints LEFT
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
@@ -170,7 +220,7 @@ new FormModel {
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hasFullBorderChanged", false ) )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 3
"gridY": 7
"gridY": 11
"hAlign": sfield com.jgoodies.forms.layout.CellConstraints LEFT
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
@@ -183,7 +233,7 @@ new FormModel {
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "moreTabsChanged", false ) )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridX": 1
"gridY": 9
"gridY": 13
"hAlign": sfield com.jgoodies.forms.layout.CellConstraints LEFT
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
@@ -191,7 +241,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 400, 400 )
"size": new java.awt.Dimension( 405, 515 )
} )
}
}

View File

@@ -181,6 +181,8 @@ Slider.disabledForeground=000088
#---- SplitPane ----
SplitPaneDivider.draggingColor=880000
SplitPaneDivider.oneTouchArrowColor=00ff00
SplitPaneDivider.oneTouchHoverArrowColor=ff0000
#---- TabbedPane ----