SwingX: JXHeader support (#8)

This commit is contained in:
Karl Tauber
2019-10-18 10:33:05 +02:00
parent 212ff012d6
commit 8b5e3e344a
8 changed files with 122 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ FlatLaf Change Log
- ComboBox: Use small border if used as table editor.
- ToolBar: Disable focusability of buttons in toolbar.
- SwingX: Support `JXHeader`, `JXHyperlink`, `JXTaskPaneContainer` and
`JXTaskPane`. (issue #8)
## 0.13

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2019 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.formdev.flatlaf.swingx.ui;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.LayoutManager;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import org.jdesktop.swingx.JXHeader;
import org.jdesktop.swingx.plaf.basic.BasicHeaderUI;
import com.formdev.flatlaf.util.UIScale;
/**
* Provides the Flat LaF UI delegate for {@link org.jdesktop.swingx.JXHeader}.
*
* @author Karl Tauber
*/
public class FlatHeaderUI
extends BasicHeaderUI
{
public static ComponentUI createUI( JComponent c ) {
return new FlatHeaderUI();
}
@Override
protected void installComponents( JXHeader header ) {
super.installComponents( header );
scaleLayout( header );
}
@Override
protected void onPropertyChange( JXHeader h, String propertyName, Object oldValue, Object newValue ) {
super.onPropertyChange( h, propertyName, oldValue, newValue );
if( "iconPosition".equals( propertyName ) )
scaleLayout( h );
}
private void scaleLayout( JXHeader header ) {
if( UIScale.getUserScaleFactor() == 1f )
return;
LayoutManager layout = header.getLayout();
if( !(layout instanceof GridBagLayout) )
return;
GridBagLayout gbl = (GridBagLayout) layout;
for( Component c : header.getComponents() ) {
GridBagConstraints cons = gbl.getConstraints( c );
cons.insets = UIScale.scale( cons.insets );
gbl.setConstraints( c, cons );
}
}
}

View File

@@ -14,6 +14,12 @@
# limitations under the License.
#
#---- Header ----
JXHeader.background=@background
JXHeader.startBackground=4c5052
#---- Hyperlink ----
Hyperlink.linkColor=589df6

View File

@@ -16,5 +16,6 @@
#---- UI delegates ----
HeaderUI=com.formdev.flatlaf.swingx.ui.FlatHeaderUI
HyperlinkUI=com.formdev.flatlaf.swingx.ui.FlatHyperlinkUI
swingx/TaskPaneUI=com.formdev.flatlaf.swingx.ui.FlatTaskPaneUI

View File

@@ -14,6 +14,12 @@
# limitations under the License.
#
#---- Header ----
JXHeader.background=@background
JXHeader.startBackground=ffffff
#---- Hyperlink ----
Hyperlink.linkColor=4a78c2

View File

@@ -59,6 +59,8 @@ public class FlatSwingXTest
JXTaskPane xTaskPane6 = new JXTaskPane();
JXHyperlink xHyperlink9 = new JXHyperlink();
JXHyperlink xHyperlink10 = new JXHyperlink();
JLabel headerLabel = new JLabel();
JXHeader xHeader1 = new JXHeader();
//======== this ========
setLayout(new MigLayout(
@@ -69,6 +71,7 @@ public class FlatSwingXTest
"[]",
// rows
"[]" +
"[]" +
"[]"));
//---- hyperlinkLabel ----
@@ -176,6 +179,16 @@ public class FlatSwingXTest
scrollPane1.setViewportView(xTaskPaneContainer1);
}
add(scrollPane1, "cell 1 1,width 150,height 350");
//---- headerLabel ----
headerLabel.setText("JXHeader:");
add(headerLabel, "cell 0 2");
//---- xHeader1 ----
xHeader1.setTitle("Title");
xHeader1.setDescription("Description\nMore description");
xHeader1.setIcon(new ImageIcon(getClass().getResource("/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png")));
add(xHeader1, "cell 1 2 2 1,width 200");
// JFormDesigner - End of component initialization //GEN-END:initComponents
}

View File

@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "hidemode 3,ltr"
"$columnConstraints": "[left][][]"
"$rowConstraints": "[][]"
"$rowConstraints": "[][][]"
} ) {
name: "this"
add( new FormComponent( "javax.swing.JLabel" ) {
@@ -111,6 +111,20 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1,width 150,height 350"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "headerLabel"
"text": "JXHeader:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
add( new FormComponent( "org.jdesktop.swingx.JXHeader" ) {
name: "xHeader1"
"title": "Title"
"description": "Description\nMore description"
"icon": new com.jformdesigner.model.SwingIcon( 0, "/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png" )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2 2 1,width 200"
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 645, 600 )

View File

@@ -14,6 +14,14 @@
# limitations under the License.
#
#---- Header ----
JXHeader.background=ff8888
JXHeader.startBackground=ffcccc
JXHeader.titleForeground=0000ff
JXHeader.descriptionForeground=ff0000
#---- Hyperlink ----
Hyperlink.linkColor=ff0000