SwingX: JXBusyLabel support (#8)

This commit is contained in:
Karl Tauber
2019-10-18 13:26:30 +02:00
parent 3f7215c602
commit c1a9f48e6b
8 changed files with 180 additions and 12 deletions

View File

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

View File

@@ -0,0 +1,79 @@
/*
* 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.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.plaf.basic.BasicBusyLabelUI;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.ui.FlatUIUtils;
//TODO scale busy spinner
/**
* Provides the Flat LaF UI delegate for {@link org.jdesktop.swingx.JXBusyLabel}.
*
* @author Karl Tauber
*/
public class FlatBusyLabelUI
extends BasicBusyLabelUI
{
private Color disabledForeground;
public static ComponentUI createUI( JComponent c ) {
return new FlatBusyLabelUI( (JXBusyLabel) c );
}
public FlatBusyLabelUI( JXBusyLabel busyLabel ) {
super( busyLabel );
}
@Override
protected void installDefaults( JLabel c ) {
super.installDefaults( c );
disabledForeground = UIManager.getColor( "Label.disabledForeground" );
// force recreation of busy painter for correct colors when switching LaF
if( c.getIcon() != null ) {
JXBusyLabel busyLabel = (JXBusyLabel) c;
boolean oldBusy = busyLabel.isBusy();
busyLabel.setBusy( false );
busyLabel.setBusyPainter( null );
busyLabel.setBusy( oldBusy );
}
}
@Override
protected void uninstallDefaults( JLabel c ) {
super.uninstallDefaults( c );
disabledForeground = null;
}
@Override
protected void paintDisabledText( JLabel l, Graphics g, String s, int textX, int textY ) {
int mnemIndex = FlatLaf.isShowMnemonics() ? l.getDisplayedMnemonicIndex() : -1;
g.setColor( disabledForeground );
FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY );
}
}

View File

@@ -14,6 +14,12 @@
# limitations under the License. # limitations under the License.
# #
#---- BusyLabel ----
JXBusyLabel.baseColor=777777
JXBusyLabel.highlightColor=e0e0e0
#---- Header ---- #---- Header ----
JXHeader.background=@background JXHeader.background=@background

View File

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

View File

@@ -14,6 +14,12 @@
# limitations under the License. # limitations under the License.
# #
#---- BusyLabel ----
JXBusyLabel.baseColor=c4c4c4
JXBusyLabel.highlightColor=808080
#---- Header ---- #---- Header ----
JXHeader.background=@background JXHeader.background=@background

View File

@@ -37,11 +37,21 @@ public class FlatSwingXTest
initComponents(); initComponents();
} }
private void busyChanged() {
boolean busy = busyCheckBox.isSelected();
xBusyLabel1.setBusy( busy );
xBusyLabel2.setBusy( busy );
}
private void initComponents() { private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JLabel hyperlinkLabel = new JLabel(); JLabel hyperlinkLabel = new JLabel();
JXHyperlink xHyperlink1 = new JXHyperlink(); JXHyperlink xHyperlink1 = new JXHyperlink();
JXHyperlink xHyperlink2 = new JXHyperlink(); JXHyperlink xHyperlink2 = new JXHyperlink();
JLabel label2 = new JLabel();
xBusyLabel1 = new JXBusyLabel();
xBusyLabel2 = new JXBusyLabel();
busyCheckBox = new JCheckBox();
JPanel panel1 = new JPanel(); JPanel panel1 = new JPanel();
JLabel taskPaneContainerLabel = new JLabel(); JLabel taskPaneContainerLabel = new JLabel();
JLabel taskPaneLabel = new JLabel(); JLabel taskPaneLabel = new JLabel();
@@ -68,10 +78,12 @@ public class FlatSwingXTest
// columns // columns
"[left]" + "[left]" +
"[]" + "[]" +
"[]" +
"[]", "[]",
// rows // rows
"[]" + "[]" +
"[]" + "[]" +
"[]" +
"[]")); "[]"));
//---- hyperlinkLabel ---- //---- hyperlinkLabel ----
@@ -87,6 +99,25 @@ public class FlatSwingXTest
xHyperlink2.setEnabled(false); xHyperlink2.setEnabled(false);
add(xHyperlink2, "cell 2 0"); add(xHyperlink2, "cell 2 0");
//---- label2 ----
label2.setText("JXBusyLabel:");
add(label2, "cell 0 1");
//---- xBusyLabel1 ----
xBusyLabel1.setText("enabled");
add(xBusyLabel1, "cell 1 1");
//---- xBusyLabel2 ----
xBusyLabel2.setText("disabled");
xBusyLabel2.setEnabled(false);
add(xBusyLabel2, "cell 2 1");
//---- busyCheckBox ----
busyCheckBox.setText("busy");
busyCheckBox.setMnemonic('B');
busyCheckBox.addActionListener(e -> busyChanged());
add(busyCheckBox, "cell 3 1");
//======== panel1 ======== //======== panel1 ========
{ {
panel1.setLayout(new MigLayout( panel1.setLayout(new MigLayout(
@@ -105,7 +136,7 @@ public class FlatSwingXTest
taskPaneLabel.setText("JXTaskPane:"); taskPaneLabel.setText("JXTaskPane:");
panel1.add(taskPaneLabel, "cell 0 1"); panel1.add(taskPaneLabel, "cell 0 1");
} }
add(panel1, "cell 0 1,aligny top,growy 0"); add(panel1, "cell 0 2,aligny top,growy 0");
//======== scrollPane1 ======== //======== scrollPane1 ========
{ {
@@ -178,20 +209,23 @@ public class FlatSwingXTest
} }
scrollPane1.setViewportView(xTaskPaneContainer1); scrollPane1.setViewportView(xTaskPaneContainer1);
} }
add(scrollPane1, "cell 1 1,width 150,height 350"); add(scrollPane1, "cell 1 2,width 150,height 350");
//---- headerLabel ---- //---- headerLabel ----
headerLabel.setText("JXHeader:"); headerLabel.setText("JXHeader:");
add(headerLabel, "cell 0 2"); add(headerLabel, "cell 0 3");
//---- xHeader1 ---- //---- xHeader1 ----
xHeader1.setTitle("Title"); xHeader1.setTitle("Title");
xHeader1.setDescription("Description\nMore description"); xHeader1.setDescription("Description\nMore description");
xHeader1.setIcon(new ImageIcon(getClass().getResource("/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png"))); xHeader1.setIcon(new ImageIcon(getClass().getResource("/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png")));
add(xHeader1, "cell 1 2 2 1,width 200"); add(xHeader1, "cell 1 3 2 1,width 200");
// JFormDesigner - End of component initialization //GEN-END:initComponents // JFormDesigner - End of component initialization //GEN-END:initComponents
} }
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JXBusyLabel xBusyLabel1;
private JXBusyLabel xBusyLabel2;
private JCheckBox busyCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables // JFormDesigner - End of variables declaration //GEN-END:variables
} }

View File

@@ -8,8 +8,8 @@ new FormModel {
} }
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "hidemode 3,ltr" "$layoutConstraints": "hidemode 3,ltr"
"$columnConstraints": "[left][][]" "$columnConstraints": "[left][][][]"
"$rowConstraints": "[][][]" "$rowConstraints": "[][][][]"
} ) { } ) {
name: "this" name: "this"
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
@@ -31,6 +31,42 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 0" "value": "cell 2 0"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label2"
"text": "JXBusyLabel:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
add( new FormComponent( "org.jdesktop.swingx.JXBusyLabel" ) {
name: "xBusyLabel1"
"text": "enabled"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1"
} )
add( new FormComponent( "org.jdesktop.swingx.JXBusyLabel" ) {
name: "xBusyLabel2"
"text": "disabled"
"enabled": false
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "busyCheckBox"
"text": "busy"
"mnemonic": 66
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "busyChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 1"
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$columnConstraints": "[left]" "$columnConstraints": "[left]"
"$rowConstraints": "[][]" "$rowConstraints": "[][]"
@@ -50,7 +86,7 @@ new FormModel {
"value": "cell 0 1" "value": "cell 0 1"
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1,aligny top,growy 0" "value": "cell 0 2,aligny top,growy 0"
} ) } )
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "scrollPane1" name: "scrollPane1"
@@ -109,13 +145,13 @@ new FormModel {
} ) } )
} ) } )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1,width 150,height 350" "value": "cell 1 2,width 150,height 350"
} ) } )
add( new FormComponent( "javax.swing.JLabel" ) { add( new FormComponent( "javax.swing.JLabel" ) {
name: "headerLabel" name: "headerLabel"
"text": "JXHeader:" "text": "JXHeader:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2" "value": "cell 0 3"
} ) } )
add( new FormComponent( "org.jdesktop.swingx.JXHeader" ) { add( new FormComponent( "org.jdesktop.swingx.JXHeader" ) {
name: "xHeader1" name: "xHeader1"
@@ -123,7 +159,7 @@ new FormModel {
"description": "Description\nMore description" "description": "Description\nMore description"
"icon": new com.jformdesigner.model.SwingIcon( 0, "/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png" ) "icon": new com.jformdesigner.model.SwingIcon( 0, "/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png" )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2 2 1,width 200" "value": "cell 1 3 2 1,width 200"
} ) } )
}, new FormLayoutConstraints( null ) { }, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 ) "location": new java.awt.Point( 0, 0 )

View File

@@ -14,6 +14,12 @@
# limitations under the License. # limitations under the License.
# #
#---- BusyLabel ----
JXBusyLabel.baseColor=00ff00
JXBusyLabel.highlightColor=ff0000
#---- Header ---- #---- Header ----
JXHeader.background=ff8888 JXHeader.background=ff8888