mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 06:20:53 +03:00
Made JComboBox, JProgressBar, JSpinner and JXDatePicker non-opaque.
`JPasswordField`, `JScrollPane` and `JTextField` are non-opaque if they have an outside focus border (e.g. IntelliJ and Darcula themes). (issues #20 and #17)
This commit is contained in:
@@ -6,6 +6,10 @@ FlatLaf Change Log
|
|||||||
- CheckBox: Support painting a third state (set client property
|
- CheckBox: Support painting a third state (set client property
|
||||||
"JButton.selectedState" to "indeterminate").
|
"JButton.selectedState" to "indeterminate").
|
||||||
- `TriStateCheckBox` component added (see [FlatLaf Extras](flatlaf-extras)).
|
- `TriStateCheckBox` component added (see [FlatLaf Extras](flatlaf-extras)).
|
||||||
|
- Made `JComboBox`, `JProgressBar`, `JSpinner` and `JXDatePicker` non-opaque.
|
||||||
|
`JPasswordField`, `JScrollPane` and `JTextField` are non-opaque if they have
|
||||||
|
an outside focus border (e.g. IntelliJ and Darcula themes). (issues #20 and
|
||||||
|
#17)
|
||||||
|
|
||||||
|
|
||||||
## 0.16
|
## 0.16
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.AbstractBorder;
|
import javax.swing.border.AbstractBorder;
|
||||||
@@ -123,6 +124,8 @@ public class FlatComboBoxUI
|
|||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( comboBox, "opaque", false );
|
||||||
|
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( "Component.arc" );
|
arc = UIManager.getInt( "Component.arc" );
|
||||||
arrowType = UIManager.getString( "Component.arrowType" );
|
arrowType = UIManager.getString( "Component.arrowType" );
|
||||||
@@ -271,44 +274,44 @@ public class FlatComboBoxUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
if( c.isOpaque() ) {
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
|
if( c.isOpaque() )
|
||||||
FlatUIUtils.paintParentBackground( g, c );
|
FlatUIUtils.paintParentBackground( g, c );
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
int width = c.getWidth();
|
int width = c.getWidth();
|
||||||
int height = c.getHeight();
|
int height = c.getHeight();
|
||||||
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
||||||
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
||||||
int arrowX = arrowButton.getX();
|
int arrowX = arrowButton.getX();
|
||||||
int arrowWidth = arrowButton.getWidth();
|
int arrowWidth = arrowButton.getWidth();
|
||||||
boolean enabled = comboBox.isEnabled();
|
boolean enabled = comboBox.isEnabled();
|
||||||
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
|
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
|
||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
||||||
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
|
// paint arrow button background
|
||||||
|
if( enabled ) {
|
||||||
|
g2.setColor( comboBox.isEditable() ? buttonEditableBackground : buttonBackground );
|
||||||
|
Shape oldClip = g2.getClip();
|
||||||
|
if( isLeftToRight )
|
||||||
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
|
else
|
||||||
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
g2.setClip( oldClip );
|
||||||
|
}
|
||||||
|
|
||||||
// paint arrow button background
|
// paint vertical line between value and arrow button
|
||||||
if( enabled ) {
|
if( comboBox.isEditable() ) {
|
||||||
g2.setColor( comboBox.isEditable() ? buttonEditableBackground : buttonBackground );
|
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
||||||
Shape oldClip = g2.getClip();
|
float lw = scale( 1f );
|
||||||
if( isLeftToRight )
|
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
||||||
else
|
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
|
||||||
g2.setClip( oldClip );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( comboBox.isEditable() ) {
|
|
||||||
// paint vertical line between value and arrow button
|
|
||||||
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
|
||||||
float lw = scale( 1f );
|
|
||||||
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
|
||||||
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paint( g, c );
|
paint( g, c );
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public class FlatPasswordFieldUI
|
|||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 );
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( getComponent(), focusWidth );
|
MigLayoutVisualPadding.install( getComponent(), focusWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,8 +89,14 @@ public class FlatPasswordFieldUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintBackground( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth );
|
FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth );
|
||||||
|
super.paintSafely( g );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintBackground( Graphics g ) {
|
||||||
|
// background is painted elsewhere
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.awt.Insets;
|
|||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicProgressBarUI;
|
import javax.swing.plaf.basic.BasicProgressBarUI;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
@@ -39,6 +40,13 @@ public class FlatProgressBarUI
|
|||||||
return new FlatProgressBarUI();
|
return new FlatProgressBarUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void installDefaults() {
|
||||||
|
super.installDefaults();
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( progressBar, "opaque", false );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dimension getPreferredInnerHorizontal() {
|
protected Dimension getPreferredInnerHorizontal() {
|
||||||
return UIScale.scale( super.getPreferredInnerHorizontal() );
|
return UIScale.scale( super.getPreferredInnerHorizontal() );
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import java.beans.PropertyChangeEvent;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.ScrollPaneLayout;
|
import javax.swing.ScrollPaneLayout;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
@@ -56,7 +57,10 @@ public class FlatScrollPaneUI
|
|||||||
if( scrollpane.getLayout() instanceof UIResource )
|
if( scrollpane.getLayout() instanceof UIResource )
|
||||||
scrollpane.setLayout( new FlatScrollPaneLayout() );
|
scrollpane.setLayout( new FlatScrollPaneLayout() );
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( scrollpane, UIManager.getInt( "Component.focusWidth" ) );
|
int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
|
LookAndFeel.installProperty( c, "opaque", focusWidth == 0 );
|
||||||
|
|
||||||
|
MigLayoutVisualPadding.install( scrollpane, focusWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import java.beans.PropertyChangeListener;
|
|||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
@@ -88,6 +89,8 @@ public class FlatSpinnerUI
|
|||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( spinner, "opaque", false );
|
||||||
|
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( "Component.arc" );
|
arc = UIManager.getInt( "Component.arc" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
@@ -225,45 +228,45 @@ public class FlatSpinnerUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
if( c.isOpaque() ) {
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
|
if( c.isOpaque() )
|
||||||
FlatUIUtils.paintParentBackground( g, c );
|
FlatUIUtils.paintParentBackground( g, c );
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
int width = c.getWidth();
|
int width = c.getWidth();
|
||||||
int height = c.getHeight();
|
int height = c.getHeight();
|
||||||
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
||||||
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
||||||
Component nextButton = getHandler().nextButton;
|
Component nextButton = getHandler().nextButton;
|
||||||
int arrowX = nextButton.getX();
|
int arrowX = nextButton.getX();
|
||||||
int arrowWidth = nextButton.getWidth();
|
int arrowWidth = nextButton.getWidth();
|
||||||
boolean enabled = spinner.isEnabled();
|
boolean enabled = spinner.isEnabled();
|
||||||
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
|
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
|
||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
||||||
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
|
// paint arrow buttons background
|
||||||
|
if( enabled ) {
|
||||||
|
g2.setColor( buttonBackground );
|
||||||
|
Shape oldClip = g2.getClip();
|
||||||
|
if( isLeftToRight )
|
||||||
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
|
else
|
||||||
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
g2.setClip( oldClip );
|
||||||
// paint arrow buttons background
|
|
||||||
if( enabled ) {
|
|
||||||
g2.setColor( buttonBackground );
|
|
||||||
Shape oldClip = g2.getClip();
|
|
||||||
if( isLeftToRight )
|
|
||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
|
||||||
else
|
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
|
||||||
g2.setClip( oldClip );
|
|
||||||
}
|
|
||||||
|
|
||||||
// paint vertical line between value and arrow buttons
|
|
||||||
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
|
||||||
float lw = scale( 1f );
|
|
||||||
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
|
||||||
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// paint vertical line between value and arrow buttons
|
||||||
|
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
||||||
|
float lw = scale( 1f );
|
||||||
|
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
||||||
|
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
||||||
|
|
||||||
paint( g, c );
|
paint( g, c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.awt.event.FocusListener;
|
|||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicTextFieldUI;
|
import javax.swing.plaf.basic.BasicTextFieldUI;
|
||||||
@@ -59,6 +60,8 @@ public class FlatTextFieldUI
|
|||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( getComponent(), "opaque", focusWidth == 0 );
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( getComponent(), focusWidth );
|
MigLayoutVisualPadding.install( getComponent(), focusWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,13 +89,30 @@ public class FlatTextFieldUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintBackground( Graphics g ) {
|
protected void paintSafely( Graphics g ) {
|
||||||
paintBackground( g, getComponent(), focusWidth );
|
paintBackground( g, getComponent(), focusWidth );
|
||||||
|
super.paintSafely( g );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintBackground( Graphics g ) {
|
||||||
|
// background is painted elsewhere
|
||||||
}
|
}
|
||||||
|
|
||||||
static void paintBackground( Graphics g, JTextComponent c, int focusWidth ) {
|
static void paintBackground( Graphics g, JTextComponent c, int focusWidth ) {
|
||||||
FlatUIUtils.paintParentBackground( g, c );
|
// do not paint background if:
|
||||||
|
// - not opaque and
|
||||||
|
// - border is not a flat border and
|
||||||
|
// - opaque was explicitly set (to false)
|
||||||
|
// (same behaviour as in AquaTextFieldUI)
|
||||||
|
if( !c.isOpaque() && !(c.getBorder() instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
|
if( c.isOpaque() && focusWidth > 0 )
|
||||||
|
FlatUIUtils.paintParentBackground( g, c );
|
||||||
|
|
||||||
|
// paint background
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
try {
|
try {
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import com.formdev.flatlaf.util.JavaCompatibility;
|
import com.formdev.flatlaf.util.JavaCompatibility;
|
||||||
@@ -248,6 +249,14 @@ public class FlatUIUtils
|
|||||||
JavaCompatibility.drawStringUnderlineCharAt( c, g, text, underlinedIndex, x, y );
|
JavaCompatibility.drawStringUnderlineCharAt( c, g, text, underlinedIndex, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasOpaqueBeenExplicitlySet( JComponent c ) {
|
||||||
|
boolean oldOpaque = c.isOpaque();
|
||||||
|
LookAndFeel.installProperty( c, "opaque", !oldOpaque );
|
||||||
|
boolean explicitlySet = c.isOpaque() == oldOpaque;
|
||||||
|
LookAndFeel.installProperty( c, "opaque", oldOpaque );
|
||||||
|
return explicitlySet;
|
||||||
|
}
|
||||||
|
|
||||||
//---- class HoverListener ------------------------------------------------
|
//---- class HoverListener ------------------------------------------------
|
||||||
|
|
||||||
public static class HoverListener
|
public static class HoverListener
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ public class FlatDatePickerUI
|
|||||||
|
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
|
LookAndFeel.installProperty( datePicker, "opaque", false );
|
||||||
|
|
||||||
// hack JXDatePicker.TodayPanel colors
|
// hack JXDatePicker.TodayPanel colors
|
||||||
// (there is no need to uninstall these changes because only UIResources are used,
|
// (there is no need to uninstall these changes because only UIResources are used,
|
||||||
// which are automatically replaced when switching LaF)
|
// which are automatically replaced when switching LaF)
|
||||||
@@ -217,44 +219,44 @@ public class FlatDatePickerUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update( Graphics g, JComponent c ) {
|
public void update( Graphics g, JComponent c ) {
|
||||||
if( c.isOpaque() ) {
|
// fill background if opaque to avoid garbage if user sets opaque to true
|
||||||
|
if( c.isOpaque() )
|
||||||
FlatUIUtils.paintParentBackground( g, c );
|
FlatUIUtils.paintParentBackground( g, c );
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
int width = c.getWidth();
|
int width = c.getWidth();
|
||||||
int height = c.getHeight();
|
int height = c.getHeight();
|
||||||
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0;
|
||||||
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0;
|
||||||
int arrowX = popupButton.getX();
|
int arrowX = popupButton.getX();
|
||||||
int arrowWidth = popupButton.getWidth();
|
int arrowWidth = popupButton.getWidth();
|
||||||
boolean enabled = c.isEnabled();
|
boolean enabled = c.isEnabled();
|
||||||
boolean isLeftToRight = c.getComponentOrientation().isLeftToRight();
|
boolean isLeftToRight = c.getComponentOrientation().isLeftToRight();
|
||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
||||||
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
|
// paint arrow button background
|
||||||
|
if( enabled ) {
|
||||||
|
g2.setColor( buttonBackground );
|
||||||
|
Shape oldClip = g2.getClip();
|
||||||
|
if( isLeftToRight )
|
||||||
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
|
else
|
||||||
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
g2.setClip( oldClip );
|
||||||
// paint arrow button background
|
|
||||||
if( enabled ) {
|
|
||||||
g2.setColor( buttonBackground );
|
|
||||||
Shape oldClip = g2.getClip();
|
|
||||||
if( isLeftToRight )
|
|
||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
|
||||||
else
|
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
|
||||||
g2.setClip( oldClip );
|
|
||||||
}
|
|
||||||
|
|
||||||
// paint vertical line between value and arrow button
|
|
||||||
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
|
||||||
float lw = scale( 1f );
|
|
||||||
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
|
||||||
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// paint vertical line between value and arrow button
|
||||||
|
g2.setColor( enabled ? borderColor : disabledBorderColor );
|
||||||
|
float lw = scale( 1f );
|
||||||
|
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
|
||||||
|
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - (focusWidth * 2) ) );
|
||||||
|
|
||||||
paint( g, c );
|
paint( g, c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public class FlatInspector
|
|||||||
private Component lastComponent;
|
private Component lastComponent;
|
||||||
private int lastX;
|
private int lastX;
|
||||||
private int lastY;
|
private int lastY;
|
||||||
|
private boolean inspectParent;
|
||||||
|
|
||||||
private JComponent highlightFigure;
|
private JComponent highlightFigure;
|
||||||
private JToolTip tip;
|
private JToolTip tip;
|
||||||
@@ -70,6 +71,7 @@ public class FlatInspector
|
|||||||
public void mouseMoved( MouseEvent e ) {
|
public void mouseMoved( MouseEvent e ) {
|
||||||
lastX = e.getX();
|
lastX = e.getX();
|
||||||
lastY = e.getY();
|
lastY = e.getY();
|
||||||
|
inspectParent = e.isShiftDown();
|
||||||
inspect( lastX, lastY );
|
inspect( lastX, lastY );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -105,6 +107,8 @@ public class FlatInspector
|
|||||||
private void inspect( int x, int y ) {
|
private void inspect( int x, int y ) {
|
||||||
Container contentPane = rootPane.getContentPane();
|
Container contentPane = rootPane.getContentPane();
|
||||||
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
|
Component c = SwingUtilities.getDeepestComponentAt( contentPane, x, y );
|
||||||
|
if( inspectParent && c != null && c != contentPane )
|
||||||
|
c = c.getParent();
|
||||||
if( c == contentPane || (c != null && c.getParent() == contentPane) )
|
if( c == contentPane || (c != null && c.getParent() == contentPane) )
|
||||||
c = null;
|
c = null;
|
||||||
|
|
||||||
@@ -237,7 +241,8 @@ public class FlatInspector
|
|||||||
}
|
}
|
||||||
|
|
||||||
text += "Enabled: " + c.isEnabled() + '\n';
|
text += "Enabled: " + c.isEnabled() + '\n';
|
||||||
text += "Opaque: " + c.isOpaque() + '\n';
|
text += "Opaque: " + c.isOpaque() + (c instanceof JComponent &&
|
||||||
|
FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n';
|
||||||
text += "Focusable: " + c.isFocusable() + '\n';
|
text += "Focusable: " + c.isFocusable() + '\n';
|
||||||
text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
|
text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n';
|
||||||
text += "Parent: " + c.getParent().getClass().getName();
|
text += "Parent: " + c.getParent().getClass().getName();
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ public class FlatTestFrame
|
|||||||
c.setBackground( explicit ? Color.orange : restoreColor );
|
c.setBackground( explicit ? Color.orange : restoreColor );
|
||||||
} else {
|
} else {
|
||||||
c.setForeground( explicit ? Color.blue : restoreColor );
|
c.setForeground( explicit ? Color.blue : restoreColor );
|
||||||
c.setBackground( explicit ? Color.red : restoreColor );
|
c.setBackground( explicit ? Color.green : restoreColor );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@@ -425,6 +425,14 @@ public class FlatTestFrame
|
|||||||
contentPanel.getContentPane().remove( content );
|
contentPanel.getContentPane().remove( content );
|
||||||
content = contentFactory.get();
|
content = contentFactory.get();
|
||||||
contentPanel.getContentPane().add( content );
|
contentPanel.getContentPane().add( content );
|
||||||
|
|
||||||
|
if( rightToLeftCheckBox.isSelected() )
|
||||||
|
rightToLeftChanged();
|
||||||
|
if( !enabledCheckBox.isSelected() )
|
||||||
|
enabledChanged();
|
||||||
|
if( explicitColorsCheckBox.isSelected() )
|
||||||
|
explicitColorsChanged();
|
||||||
|
|
||||||
contentPanel.revalidate();
|
contentPanel.revalidate();
|
||||||
contentPanel.repaint();
|
contentPanel.repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,15 +29,29 @@ public class FlatTestPanel
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent( Graphics g ) {
|
protected void paintComponent( Graphics g ) {
|
||||||
super.paintComponent( g );
|
int width = getWidth();
|
||||||
|
int height = getHeight();
|
||||||
|
|
||||||
FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this );
|
g.setColor( super.getBackground() );
|
||||||
if( frame != null && frame.isPaintBackgroundPattern() ) {
|
g.fillRect( 0, 0, width, height );
|
||||||
|
|
||||||
|
if( isPaintBackgroundPattern() ) {
|
||||||
g.setColor( Color.magenta );
|
g.setColor( Color.magenta );
|
||||||
int width = getWidth();
|
|
||||||
int height = getHeight();
|
|
||||||
for( int y = 0; y < height; y += 2 )
|
for( int y = 0; y < height; y += 2 )
|
||||||
g.drawLine( 0, y, width - 1, y );
|
g.drawLine( 0, y, width - 1, y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overridden to see which components paint background with color from parent.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Color getBackground() {
|
||||||
|
return isPaintBackgroundPattern() ? Color.red : super.getBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPaintBackgroundPattern() {
|
||||||
|
FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this );
|
||||||
|
return frame != null && frame.isPaintBackgroundPattern();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user