refactored some anonymous classes into nested classes for easier extending/subclassing

This commit is contained in:
Karl Tauber
2020-06-30 17:02:48 +02:00
parent 14c837ad05
commit 19fcb6a82c
5 changed files with 93 additions and 55 deletions

View File

@@ -202,13 +202,7 @@ public class FlatButtonUI
@Override @Override
protected BasicButtonListener createButtonListener( AbstractButton b ) { protected BasicButtonListener createButtonListener( AbstractButton b ) {
return new BasicButtonListener( b ) { return new FlatButtonListener( b );
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
FlatButtonUI.this.propertyChange( b, e );
}
};
} }
protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) { protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
@@ -475,4 +469,23 @@ public class FlatButtonUI
return prefSize; return prefSize;
} }
//---- class FlatButtonListener -------------------------------------------
protected class FlatButtonListener
extends BasicButtonListener
{
private final AbstractButton b;
protected FlatButtonListener( AbstractButton b ) {
super( b );
this.b = b;
}
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
FlatButtonUI.this.propertyChange( b, e );
}
}
} }

View File

@@ -119,7 +119,7 @@ public class FlatComboBoxUI
protected Color buttonHoverArrowColor; protected Color buttonHoverArrowColor;
private MouseListener hoverListener; private MouseListener hoverListener;
private boolean hover; protected boolean hover;
private WeakReference<Component> lastRendererComponent; private WeakReference<Component> lastRendererComponent;
@@ -332,14 +332,7 @@ public class FlatComboBoxUI
@Override @Override
protected JButton createArrowButton() { protected JButton createArrowButton() {
return new FlatArrowButton( SwingConstants.SOUTH, arrowType, buttonArrowColor, return new FlatComboBoxButton();
buttonDisabledArrowColor, buttonHoverArrowColor, null )
{
@Override
protected boolean isHover() {
return super.isHover() || (!comboBox.isEditable() ? hover : false);
}
};
} }
@Override @Override
@@ -507,6 +500,27 @@ public class FlatComboBoxUI
} }
} }
//---- class FlatComboBoxButton -------------------------------------------
protected class FlatComboBoxButton
extends FlatArrowButton
{
protected FlatComboBoxButton() {
this( SwingConstants.SOUTH, arrowType, buttonArrowColor, buttonDisabledArrowColor, buttonHoverArrowColor, null, null );
}
protected FlatComboBoxButton( int direction, String type, Color foreground, Color disabledForeground,
Color hoverForeground, Color hoverBackground, Color pressedBackground )
{
super( direction, type, foreground, disabledForeground, hoverForeground, hoverBackground, pressedBackground );
}
@Override
protected boolean isHover() {
return super.isHover() || (!comboBox.isEditable() ? hover : false);
}
}
//---- class FlatComboPopup ----------------------------------------------- //---- class FlatComboPopup -----------------------------------------------
@SuppressWarnings( { "rawtypes", "unchecked" } ) @SuppressWarnings( { "rawtypes", "unchecked" } )

View File

@@ -150,7 +150,7 @@ public class FlatInternalFrameTitlePane
//---- class FlatPropertyChangeHandler ------------------------------------ //---- class FlatPropertyChangeHandler ------------------------------------
private class FlatPropertyChangeHandler protected class FlatPropertyChangeHandler
extends PropertyChangeHandler extends PropertyChangeHandler
{ {
@Override @Override

View File

@@ -198,46 +198,12 @@ public class FlatScrollBarUI
@Override @Override
protected JButton createDecreaseButton( int orientation ) { protected JButton createDecreaseButton( int orientation ) {
return createArrowButton( orientation ); return new FlatScrollBarButton( orientation );
} }
@Override @Override
protected JButton createIncreaseButton( int orientation ) { protected JButton createIncreaseButton( int orientation ) {
return createArrowButton( orientation ); return new FlatScrollBarButton( orientation );
}
private JButton createArrowButton( int orientation ) {
FlatArrowButton button = new FlatArrowButton( orientation, arrowType, buttonArrowColor,
buttonDisabledArrowColor, null, hoverButtonBackground, pressedButtonBackground )
{
@Override
protected Color deriveBackground( Color background ) {
return FlatUIUtils.deriveColor( background, scrollbar.getBackground() );
}
@Override
public Dimension getPreferredSize() {
if( isShowButtons() ) {
int w = UIScale.scale( scrollBarWidth );
return new Dimension( w, w );
} else
return new Dimension();
}
@Override
public Dimension getMinimumSize() {
return isShowButtons() ? super.getMinimumSize() : new Dimension();
}
@Override
public Dimension getMaximumSize() {
return isShowButtons() ? super.getMaximumSize() : new Dimension();
}
};
button.setArrowWidth( FlatArrowButton.DEFAULT_ARROW_WIDTH - 2 );
button.setFocusable( false );
button.setRequestFocusEnabled( false );
return button;
} }
protected boolean isShowButtons() { protected boolean isShowButtons() {
@@ -377,4 +343,49 @@ public class FlatScrollBarUI
scrollbar.repaint(); scrollbar.repaint();
} }
} }
//---- class FlatScrollBarButton ------------------------------------------
protected class FlatScrollBarButton
extends FlatArrowButton
{
protected FlatScrollBarButton( int direction ) {
this( direction, arrowType, buttonArrowColor, buttonDisabledArrowColor,
null, hoverButtonBackground, pressedButtonBackground );
}
protected FlatScrollBarButton( int direction, String type, Color foreground, Color disabledForeground,
Color hoverForeground, Color hoverBackground, Color pressedBackground )
{
super( direction, type, foreground, disabledForeground, hoverForeground, hoverBackground, pressedBackground );
setArrowWidth( FlatArrowButton.DEFAULT_ARROW_WIDTH - 2 );
setFocusable( false );
setRequestFocusEnabled( false );
}
@Override
protected Color deriveBackground( Color background ) {
return FlatUIUtils.deriveColor( background, scrollbar.getBackground() );
}
@Override
public Dimension getPreferredSize() {
if( isShowButtons() ) {
int w = UIScale.scale( scrollBarWidth );
return new Dimension( w, w );
} else
return new Dimension();
}
@Override
public Dimension getMinimumSize() {
return isShowButtons() ? super.getMinimumSize() : new Dimension();
}
@Override
public Dimension getMaximumSize() {
return isShowButtons() ? super.getMaximumSize() : new Dimension();
}
}
} }

View File

@@ -87,10 +87,10 @@ public class FlatSplitPaneUI
//---- class FlatSplitPaneDivider ----------------------------------------- //---- class FlatSplitPaneDivider -----------------------------------------
private class FlatSplitPaneDivider protected class FlatSplitPaneDivider
extends BasicSplitPaneDivider extends BasicSplitPaneDivider
{ {
public FlatSplitPaneDivider( BasicSplitPaneUI ui ) { protected FlatSplitPaneDivider( BasicSplitPaneUI ui ) {
super( ui ); super( ui );
} }