mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-27 03:46:17 -06:00
JIDE: support JideSplitButton and JideSplitToggleButton
This commit is contained in:
@@ -9,8 +9,10 @@ Following JIDE Common Layer components are currently supported by this addon:
|
||||
- `JideButton`
|
||||
- `JideLabel`
|
||||
- `JidePopupMenu`
|
||||
- `JideSplitButton`
|
||||
- `JideTabbedPane`
|
||||
- `JideToggleButton`
|
||||
- `JideToggleSplitButton`
|
||||
- `RangeSlider`
|
||||
- `TristateCheckBox`
|
||||
|
||||
|
||||
@@ -104,6 +104,9 @@ public class FlatJideOssDefaultsAddon
|
||||
// painter
|
||||
UIDefaultsLookup.put( defaults, "Theme.painter", FlatJidePainter.getInstance() );
|
||||
|
||||
// avoid that JideButton and JideSplitButton shift icon on hover/selection
|
||||
defaults.put( "Icon.floating", false );
|
||||
|
||||
// fonts
|
||||
ActiveValue font = FlatLaf.createActiveFontValue( 1f );
|
||||
defaults.put( "JideButton.font", font );
|
||||
|
||||
@@ -20,13 +20,17 @@ import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.jidesoft.plaf.basic.BasicPainter;
|
||||
import com.jidesoft.plaf.basic.ThemePainter;
|
||||
import com.jidesoft.swing.JideButton;
|
||||
import com.jidesoft.swing.JideSplitButton;
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
@@ -41,17 +45,61 @@ public class FlatJidePainter
|
||||
return new FlatJidePainter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installDefaults() {
|
||||
// avoid white background in arrow area of selected split button
|
||||
if( _bk0 == null )
|
||||
_bk0 = UIManager.getColor( "Panel.background" );
|
||||
|
||||
super.installDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintBackground( JComponent c, Graphics g, Rectangle rect,
|
||||
Color borderColor, Color background, int orientation )
|
||||
{
|
||||
if( c instanceof JideButton && ((JideButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE ) {
|
||||
if( (c instanceof JideButton && ((JideButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE) ||
|
||||
(c instanceof JideSplitButton && ((JideSplitButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE) )
|
||||
{
|
||||
Color oldColor = g.getColor();
|
||||
g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) );
|
||||
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g );
|
||||
|
||||
FlatUIUtils.paintComponentBackground( (Graphics2D) g, rect.x, rect.y,
|
||||
rect.width, rect.height, 0, UIScale.scale( (float) arc ) );
|
||||
if( c instanceof JideSplitButton ) {
|
||||
// For split buttons, this method is invoked twice:
|
||||
// - first for main button
|
||||
// - second for arrow button
|
||||
// To show a single rounded rectangle for the whole button we always paint
|
||||
// the rounded rectangle with component bounds, but clip to the passed rectangle.
|
||||
|
||||
boolean horizontal = (((JideSplitButton)c).getOrientation() == SwingConstants.HORIZONTAL);
|
||||
|
||||
// for vertical orientation, the graphics context is rotated, but 1px wrong
|
||||
if( !horizontal )
|
||||
g.translate( 0, -1 );
|
||||
|
||||
Shape oldClip = g.getClip();
|
||||
g.clipRect( rect.x, rect.y, rect.width, rect.height );
|
||||
|
||||
FlatUIUtils.paintComponentBackground( (Graphics2D) g, 0, 0,
|
||||
horizontal ? c.getWidth() : c.getHeight(),
|
||||
horizontal ? c.getHeight() : c.getWidth(),
|
||||
0, UIScale.scale( (float) arc ) );
|
||||
|
||||
g.setClip( oldClip );
|
||||
|
||||
// paint separator line
|
||||
if( rect.x > 0 ) {
|
||||
g.setColor( borderColor );
|
||||
((Graphics2D)g).fill( new Rectangle2D.Float( rect.x, rect.y, UIScale.scale( 1f ), rect.height ) );
|
||||
}
|
||||
|
||||
if( !horizontal )
|
||||
g.translate( 0, 1 );
|
||||
} else {
|
||||
FlatUIUtils.paintComponentBackground( (Graphics2D) g, rect.x, rect.y,
|
||||
rect.width, rect.height, 0, UIScale.scale( (float) arc ) );
|
||||
}
|
||||
|
||||
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
||||
g.setColor( oldColor );
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2021 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
|
||||
*
|
||||
* https://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.jideoss.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.jidesoft.plaf.LookAndFeelFactory;
|
||||
import com.jidesoft.plaf.UIDefaultsLookup;
|
||||
import com.jidesoft.plaf.basic.BasicJideSplitButtonUI;
|
||||
import com.jidesoft.swing.JideSplitButton;
|
||||
import com.jidesoft.swing.JideSwingUtilities;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link com.jidesoft.swing.JideSplitButton}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatJideSplitButtonUI
|
||||
extends BasicJideSplitButtonUI
|
||||
{
|
||||
protected String arrowType;
|
||||
protected Color buttonArrowColor;
|
||||
protected Color buttonDisabledArrowColor;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
// usually JIDE would invoke this in JideSplitButton.updateUI(),
|
||||
// but it does not because FlatLaf already has added the UI class to the UI defaults
|
||||
LookAndFeelFactory.installJideExtension();
|
||||
|
||||
return new FlatJideSplitButtonUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
arrowType = UIManager.getString( "Component.arrowType" );
|
||||
buttonArrowColor = UIManager.getColor( "JideSplitButton.buttonArrowColor" );
|
||||
buttonDisabledArrowColor = UIManager.getColor( "JideSplitButton.buttonDisabledArrowColor" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightMargin() {
|
||||
// scale margins
|
||||
_splitButtonMargin = UIScale.scale( 14 );
|
||||
_splitButtonMarginOnMenu = UIScale.scale( 20 );
|
||||
|
||||
return super.getRightMargin();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rectangle getButtonRect( JComponent c, int orientation, int width, int height ) {
|
||||
return c.getComponentOrientation().isLeftToRight()
|
||||
? new Rectangle( 0, 0, width - _splitButtonMargin + 1, height )
|
||||
: new Rectangle( _splitButtonMargin - 1, 0, width - _splitButtonMargin + 1, height );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rectangle getDropDownRect( JComponent c, int orientation, int width, int height ) {
|
||||
return c.getComponentOrientation().isLeftToRight()
|
||||
? new Rectangle( width - _splitButtonMargin, 0, _splitButtonMargin, height )
|
||||
: new Rectangle( 0, 0, _splitButtonMargin, height );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) {
|
||||
ButtonModel model = menuItem.getModel();
|
||||
if( !model.isEnabled() ||
|
||||
(menuItem instanceof JideSplitButton && !((JideSplitButton)menuItem).isButtonEnabled()) )
|
||||
{
|
||||
FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() );
|
||||
|
||||
if( !menuItem.getComponentOrientation().isLeftToRight() &&
|
||||
menuItem.getComponentOrientation().isHorizontal() )
|
||||
{
|
||||
Rectangle2D rectText = fm.getStringBounds( text, g );
|
||||
textRect.x = (int) (menuItem.getWidth() - textRect.x - rectText.getWidth() + (4 + menuItem.getHeight() / 2 - 1));
|
||||
}
|
||||
|
||||
g.setColor( UIDefaultsLookup.getColor( "Button.disabledForeground" ) );
|
||||
drawStringUnderlineCharAt( menuItem, g, text, -1, textRect.x, textRect.y + fm.getAscent() );
|
||||
} else
|
||||
super.paintText( g, menuItem, textRect, text );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintArrow( JMenuItem menuItem, Graphics g ) {
|
||||
g.setColor( menuItem.isEnabled() ? buttonArrowColor : buttonDisabledArrowColor );
|
||||
|
||||
int orientation = JideSwingUtilities.getOrientationOf( menuItem );
|
||||
int menuWidth = (orientation == SwingConstants.HORIZONTAL) ? menuItem.getWidth() : menuItem.getHeight();
|
||||
int menuHeight = (orientation == SwingConstants.HORIZONTAL) ? menuItem.getHeight() : menuItem.getWidth();
|
||||
Rectangle r = getDropDownRect( menuItem, orientation, menuWidth, menuHeight );
|
||||
|
||||
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g );
|
||||
FlatUIUtils.paintArrow( (Graphics2D) g, r.x, r.y, r.width, r.height,
|
||||
SwingConstants.SOUTH, FlatUIUtils.isChevron( arrowType ), 6, 0, 0 );
|
||||
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
JideButtonUI = com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI
|
||||
JideLabelUI = com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI
|
||||
JidePopupMenuUI = com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI
|
||||
JideSplitButtonUI = com.formdev.flatlaf.jideoss.ui.FlatJideSplitButtonUI
|
||||
JideTabbedPaneUI = com.formdev.flatlaf.jideoss.ui.FlatJideTabbedPaneUI
|
||||
RangeSliderUI = com.formdev.flatlaf.jideoss.ui.FlatRangeSliderUI
|
||||
|
||||
@@ -56,6 +57,17 @@ JideLabel.disabledForeground = $Label.disabledForeground
|
||||
Resizable.resizeBorder = 4,4,4,4,$PopupMenu.borderColor
|
||||
|
||||
|
||||
#---- JideSplitButton and JideToggleSplitButton ----
|
||||
|
||||
JideSplitButton.border = com.formdev.flatlaf.ui.FlatMarginBorder
|
||||
JideSplitButton.margin = $Button.toolbar.margin
|
||||
JideSplitButton.textIconGap = {scaledInteger}4
|
||||
|
||||
JideSplitButton.selectionForeground = $Button.foreground
|
||||
JideSplitButton.buttonArrowColor = @buttonArrowColor
|
||||
JideSplitButton.buttonDisabledArrowColor = @buttonDisabledArrowColor
|
||||
|
||||
|
||||
#---- JideTabbedPane ----
|
||||
|
||||
JideTabbedPane.background = @background
|
||||
|
||||
Reference in New Issue
Block a user