mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
TextComponents: reduced duplicate code; fixed parameter order
This commit is contained in:
@@ -85,20 +85,20 @@ public class FlatEditorPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getPreferredSize( c ) );
|
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getMinimumSize( c ) );
|
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dimension applyMinimumWidth( Dimension size ) {
|
static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
|
||||||
// Assume that text area is in a scroll pane (that displays the border)
|
// Assume that text area is in a scroll pane (that displays the border)
|
||||||
// and subtract 1px border line width.
|
// and subtract 1px border line width.
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
||||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
||||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
minimumWidth = FlatUIUtils.minimumWidth( c, minimumWidth );
|
||||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,11 +174,11 @@ public class FlatPasswordFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return FlatTextFieldUI.applyMinimumWidth( super.getPreferredSize( c ), minimumWidth, c );
|
return FlatTextFieldUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return FlatTextFieldUI.applyMinimumWidth( super.getMinimumSize( c ), minimumWidth, c );
|
return FlatTextFieldUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@@ -100,25 +99,19 @@ public class FlatTextAreaUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getPreferredSize( c ), c );
|
return applyMinimumWidth( c, super.getPreferredSize( c ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getMinimumSize( c ), c );
|
return applyMinimumWidth( c, super.getMinimumSize( c ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dimension applyMinimumWidth( Dimension size, JComponent c ) {
|
private Dimension applyMinimumWidth( JComponent c, Dimension size ) {
|
||||||
// do not apply minimum width if JTextArea.columns is set
|
// do not apply minimum width if JTextArea.columns is set
|
||||||
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
|
if( c instanceof JTextArea && ((JTextArea)c).getColumns() > 0 )
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
// Assume that text area is in a scroll pane (that displays the border)
|
return FlatEditorPaneUI.applyMinimumWidth( c, size, minimumWidth );
|
||||||
// and subtract 1px border line width.
|
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
|
||||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
|
||||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
|
||||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,15 +213,15 @@ public class FlatTextFieldUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getPreferredSize( c ), minimumWidth, c );
|
return applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getMinimumSize( c ), minimumWidth, c );
|
return applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dimension applyMinimumWidth( Dimension size, int minimumWidth, JComponent c ) {
|
static Dimension applyMinimumWidth( JComponent c, Dimension size, int minimumWidth ) {
|
||||||
// do not apply minimum width if JTextField.columns is set
|
// do not apply minimum width if JTextField.columns is set
|
||||||
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
|
if( c instanceof JTextField && ((JTextField)c).getColumns() > 0 )
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -85,22 +84,12 @@ public class FlatTextPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getPreferredSize( c ) );
|
return FlatEditorPaneUI.applyMinimumWidth( c, super.getPreferredSize( c ), minimumWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getMinimumSize( JComponent c ) {
|
public Dimension getMinimumSize( JComponent c ) {
|
||||||
return applyMinimumWidth( super.getMinimumSize( c ) );
|
return FlatEditorPaneUI.applyMinimumWidth( c, super.getMinimumSize( c ), minimumWidth );
|
||||||
}
|
|
||||||
|
|
||||||
private Dimension applyMinimumWidth( Dimension size ) {
|
|
||||||
// Assume that text area is in a scroll pane (that displays the border)
|
|
||||||
// and subtract 1px border line width.
|
|
||||||
// Using "(scale( 1 ) * 2)" instead of "scale( 2 )" to deal with rounding
|
|
||||||
// issues. E.g. at scale factor 1.5 the first returns 4, but the second 3.
|
|
||||||
int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth );
|
|
||||||
size.width = Math.max( size.width, scale( minimumWidth ) - (scale( 1 ) * 2) );
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user