- tuned/fixed component border painting

- HiDPIUtils.paintAtScale1x() now also works if the Graphics is scaled (as in FlatPaintingTest)
- FlatPaintingTest added
This commit is contained in:
Karl Tauber
2020-02-17 21:59:32 +01:00
parent c02f824d74
commit f736ed401f
4 changed files with 821 additions and 31 deletions

View File

@@ -167,7 +167,7 @@ public class FlatUIUtils
double systemScaleFactor = UIScale.getSystemScaleFactor( g ); double systemScaleFactor = UIScale.getSystemScaleFactor( g );
if( systemScaleFactor != 1 && systemScaleFactor != 2 ) { if( systemScaleFactor != 1 && systemScaleFactor != 2 ) {
// paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175% // paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175%
HiDPIUtils.paintAtScale1x( g, x, y, width, height, systemScaleFactor, HiDPIUtils.paintAtScale1x( g, x, y, width, height,
(g2d, x2, y2, width2, height2, scaleFactor) -> { (g2d, x2, y2, width2, height2, scaleFactor) -> {
paintComponentOuterBorderImpl( g2d, x2, y2, width2, height2, paintComponentOuterBorderImpl( g2d, x2, y2, width2, height2,
(float) (focusWidth * scaleFactor), (float) (lineWidth * scaleFactor), (float) (arc * scaleFactor) ); (float) (focusWidth * scaleFactor), (float) (lineWidth * scaleFactor), (float) (arc * scaleFactor) );
@@ -181,13 +181,22 @@ public class FlatUIUtils
private static void paintComponentOuterBorderImpl( Graphics2D g, int x, int y, int width, int height, private static void paintComponentOuterBorderImpl( Graphics2D g, int x, int y, int width, int height,
float focusWidth, float lineWidth, float arc ) float focusWidth, float lineWidth, float arc )
{ {
float outerRadius = (arc > 0) ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth;
float ow = focusWidth + lineWidth; float ow = focusWidth + lineWidth;
float innerRadius = outerRadius - ow; float outerArc = arc + (focusWidth * 2);
float innerArc = arc - (lineWidth * 2);
// reduce outer arc slightly for small arcs to make the curve slightly wider
if( arc > 0 && arc < UIScale.scale( 10 ) )
outerArc -= UIScale.scale( 2f );
if( outerArc < 0 )
outerArc = 0;
if( innerArc < 0 )
innerArc = 0;
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD ); Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( createRoundRectanglePath( x, y, width, height, outerRadius, outerRadius, outerRadius, outerRadius ), false ); path.append( new RoundRectangle2D.Float( x, y, width, height, outerArc, outerArc ), false );
path.append( createRoundRectanglePath( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerRadius, innerRadius, innerRadius, innerRadius ), false ); path.append( new RoundRectangle2D.Float( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerArc, innerArc ), false );
g.fill( path ); g.fill( path );
} }
@@ -207,7 +216,7 @@ public class FlatUIUtils
double systemScaleFactor = UIScale.getSystemScaleFactor( g ); double systemScaleFactor = UIScale.getSystemScaleFactor( g );
if( systemScaleFactor != 1 && systemScaleFactor != 2 ) { if( systemScaleFactor != 1 && systemScaleFactor != 2 ) {
// paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175% // paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175%
HiDPIUtils.paintAtScale1x( g, x, y, width, height, systemScaleFactor, HiDPIUtils.paintAtScale1x( g, x, y, width, height,
(g2d, x2, y2, width2, height2, scaleFactor) -> { (g2d, x2, y2, width2, height2, scaleFactor) -> {
paintComponentBorderImpl( g2d, x2, y2, width2, height2, paintComponentBorderImpl( g2d, x2, y2, width2, height2,
(float) (focusWidth * scaleFactor), (float) (lineWidth * scaleFactor), (float) (arc * scaleFactor) ); (float) (focusWidth * scaleFactor), (float) (lineWidth * scaleFactor), (float) (arc * scaleFactor) );
@@ -221,7 +230,12 @@ public class FlatUIUtils
private static void paintComponentBorderImpl( Graphics2D g, int x, int y, int width, int height, private static void paintComponentBorderImpl( Graphics2D g, int x, int y, int width, int height,
float focusWidth, float lineWidth, float arc ) float focusWidth, float lineWidth, float arc )
{ {
float arc2 = arc > lineWidth ? arc - lineWidth : 0f; float arc2 = arc - (lineWidth * 2);
if( arc < 0 )
arc = 0;
if( arc2 < 0 )
arc2 = 0;
RoundRectangle2D.Float r1 = new RoundRectangle2D.Float( RoundRectangle2D.Float r1 = new RoundRectangle2D.Float(
x + focusWidth, y + focusWidth, x + focusWidth, y + focusWidth,
@@ -252,7 +266,7 @@ public class FlatUIUtils
double systemScaleFactor = UIScale.getSystemScaleFactor( g ); double systemScaleFactor = UIScale.getSystemScaleFactor( g );
if( systemScaleFactor != 1 && systemScaleFactor != 2 ) { if( systemScaleFactor != 1 && systemScaleFactor != 2 ) {
// paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175% // paint at scale 1x to avoid clipping on right and bottom edges at 125%, 150% or 175%
HiDPIUtils.paintAtScale1x( g, x, y, width, height, systemScaleFactor, HiDPIUtils.paintAtScale1x( g, x, y, width, height,
(g2d, x2, y2, width2, height2, scaleFactor) -> { (g2d, x2, y2, width2, height2, scaleFactor) -> {
paintComponentBackgroundImpl( g2d, x2, y2, width2, height2, paintComponentBackgroundImpl( g2d, x2, y2, width2, height2,
(float) (focusWidth * scaleFactor), (float) (arc * scaleFactor) ); (float) (focusWidth * scaleFactor), (float) (arc * scaleFactor) );
@@ -266,6 +280,9 @@ public class FlatUIUtils
private static void paintComponentBackgroundImpl( Graphics2D g, int x, int y, int width, int height, private static void paintComponentBackgroundImpl( Graphics2D g, int x, int y, int width, int height,
float focusWidth, float arc ) float focusWidth, float arc )
{ {
if( arc < 0 )
arc = 0;
g.fill( new RoundRectangle2D.Float( g.fill( new RoundRectangle2D.Float(
x + focusWidth, y + focusWidth, x + focusWidth, y + focusWidth,
width - focusWidth * 2, height - focusWidth * 2, arc, arc ) ); width - focusWidth * 2, height - focusWidth * 2, arc, arc ) );

View File

@@ -34,10 +34,6 @@ public class HiDPIUtils
paintAtScale1x( g, 0, 0, c.getWidth(), c.getHeight(), painter ); paintAtScale1x( g, 0, 0, c.getWidth(), c.getHeight(), painter );
} }
public static void paintAtScale1x( Graphics2D g, int x, int y, int width, int height, Painter painter ) {
paintAtScale1x( g, x, y, width, height, UIScale.getSystemScaleFactor( g ), painter );
}
/** /**
* Paint at system scale factor 1x to avoid rounding issues at 125%, 150% and 175% scaling. * Paint at system scale factor 1x to avoid rounding issues at 125%, 150% and 175% scaling.
* <p> * <p>
@@ -46,38 +42,29 @@ public class HiDPIUtils
* <p> * <p>
* Uses the same scaling calculation as the JRE uses. * Uses the same scaling calculation as the JRE uses.
*/ */
public static void paintAtScale1x( Graphics2D g, int x, int y, int width, int height, public static void paintAtScale1x( Graphics2D g, int x, int y, int width, int height, Painter painter ) {
double scaleFactor, Painter painter ) // save original transform
{ AffineTransform transform = g.getTransform();
if( scaleFactor == 1 ) {
// check whether scaled
if( transform.getScaleX() == 1 && transform.getScaleY() == 1 ) {
painter.paint( g, x, y, width, height, 1 ); painter.paint( g, x, y, width, height, 1 );
return; return;
} }
// save original transform
AffineTransform transform = g.getTransform();
// scale rectangle // scale rectangle
Rectangle2D.Double scaledRect = scale( transform, x, y, width, height ); Rectangle2D.Double scaledRect = scale( transform, x, y, width, height );
try { try {
// unscale to factor 1.0 // unscale to factor 1.0 and move origin (to whole numbers)
double scale = 1.0 / scaleFactor; g.setTransform( new AffineTransform( 1, 0, 0, 1,
g.scale( scale, scale ); Math.floor( scaledRect.x ), Math.floor( scaledRect.y ) ) );
// compute origin delta x/y
double dx = Math.floor( scaledRect.x ) - transform.getTranslateX();
double dy = Math.floor( scaledRect.y ) - transform.getTranslateY();
// move origin to make sure that origin x/y are at whole numbers
if( dx != 0 || dy != 0 )
g.translate( dx, dy );
int swidth = (int) scaledRect.width; int swidth = (int) scaledRect.width;
int sheight = (int) scaledRect.height; int sheight = (int) scaledRect.height;
// paint // paint
painter.paint( g, 0, 0, swidth, sheight, scaleFactor ); painter.paint( g, 0, 0, swidth, sheight, transform.getScaleX() );
} finally { } finally {
// restore original transform // restore original transform
g.setTransform( transform ); g.setTransform( transform );

View File

@@ -0,0 +1,472 @@
/*
* Copyright 2020 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.testing;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale;
import net.miginfocom.swing.*;
/**
* @author Karl Tauber
*/
public class FlatPaintingTest
extends JScrollPane
{
public static void main( String[] args ) {
SwingUtilities.invokeLater( () -> {
FlatTestFrame frame = FlatTestFrame.create( args, "FlatPaintingTest" );
frame.showFrame( FlatPaintingTest::new );
} );
}
FlatPaintingTest() {
initComponents();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
FlatTestPanel flatTestPanel1 = new FlatTestPanel();
FlatPaintingTest.BorderPainter borderPainter9 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter1 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter6 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter13 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter17 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter21 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter29 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter10 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter2 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter7 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter14 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter18 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter22 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter28 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter11 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter3 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter5 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter15 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter19 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter23 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter27 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter12 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter4 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter8 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter16 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter20 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter24 = new FlatPaintingTest.BorderPainter();
FlatPaintingTest.BorderPainter borderPainter26 = new FlatPaintingTest.BorderPainter();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
JLabel label5 = new JLabel();
JLabel label6 = new JLabel();
JLabel label7 = new JLabel();
//======== this ========
setBorder(null);
//======== flatTestPanel1 ========
{
flatTestPanel1.setLayout(new MigLayout(
"ltr,insets dialog,hidemode 3",
// columns
"[fill]" +
"[left]" +
"[left]" +
"[fill]" +
"[fill]" +
"[fill]" +
"[fill]" +
"[fill]",
// rows
"[top]" +
"[top]" +
"[top]" +
"[top]" +
"[]"));
//---- borderPainter9 ----
borderPainter9.setScale(8.0F);
borderPainter9.setPaintBorder(false);
borderPainter9.setPaintFocus(false);
borderPainter9.setFocusWidth(0);
flatTestPanel1.add(borderPainter9, "cell 0 0");
//---- borderPainter1 ----
borderPainter1.setScale(8.0F);
borderPainter1.setPaintBorder(false);
borderPainter1.setPaintFocus(false);
flatTestPanel1.add(borderPainter1, "cell 1 0");
//---- borderPainter6 ----
borderPainter6.setScale(8.0F);
borderPainter6.setPaintBorder(false);
borderPainter6.setPaintFocus(false);
borderPainter6.setW(25);
borderPainter6.setArc(10);
flatTestPanel1.add(borderPainter6, "cell 2 0");
//---- borderPainter13 ----
borderPainter13.setScale(8.0F);
borderPainter13.setPaintBorder(false);
borderPainter13.setPaintFocus(false);
borderPainter13.setW(25);
borderPainter13.setArc(20);
flatTestPanel1.add(borderPainter13, "cell 3 0");
//---- borderPainter17 ----
borderPainter17.setScale(8.0F);
borderPainter17.setPaintBorder(false);
borderPainter17.setPaintFocus(false);
borderPainter17.setFocusWidth(0);
borderPainter17.setArc(0);
flatTestPanel1.add(borderPainter17, "cell 4 0");
//---- borderPainter21 ----
borderPainter21.setScale(8.0F);
borderPainter21.setPaintBorder(false);
borderPainter21.setPaintFocus(false);
borderPainter21.setArc(0);
flatTestPanel1.add(borderPainter21, "cell 5 0");
//---- borderPainter29 ----
borderPainter29.setScale(8.0F);
borderPainter29.setArc(3);
borderPainter29.setFocusWidth(1);
borderPainter29.setLineWidth(3);
flatTestPanel1.add(borderPainter29, "cell 7 0");
//---- borderPainter10 ----
borderPainter10.setScale(8.0F);
borderPainter10.setPaintBackground(false);
borderPainter10.setPaintFocus(false);
borderPainter10.setFocusWidth(0);
flatTestPanel1.add(borderPainter10, "cell 0 1");
//---- borderPainter2 ----
borderPainter2.setScale(8.0F);
borderPainter2.setPaintBackground(false);
borderPainter2.setPaintFocus(false);
flatTestPanel1.add(borderPainter2, "cell 1 1");
//---- borderPainter7 ----
borderPainter7.setScale(8.0F);
borderPainter7.setPaintBackground(false);
borderPainter7.setPaintFocus(false);
borderPainter7.setW(25);
borderPainter7.setArc(10);
flatTestPanel1.add(borderPainter7, "cell 2 1");
//---- borderPainter14 ----
borderPainter14.setScale(8.0F);
borderPainter14.setPaintBackground(false);
borderPainter14.setPaintFocus(false);
borderPainter14.setW(25);
borderPainter14.setArc(20);
flatTestPanel1.add(borderPainter14, "cell 3 1");
//---- borderPainter18 ----
borderPainter18.setScale(8.0F);
borderPainter18.setPaintBackground(false);
borderPainter18.setPaintFocus(false);
borderPainter18.setFocusWidth(0);
borderPainter18.setArc(0);
flatTestPanel1.add(borderPainter18, "cell 4 1");
//---- borderPainter22 ----
borderPainter22.setScale(8.0F);
borderPainter22.setPaintBackground(false);
borderPainter22.setPaintFocus(false);
borderPainter22.setArc(0);
flatTestPanel1.add(borderPainter22, "cell 5 1");
//---- borderPainter28 ----
borderPainter28.setScale(8.0F);
borderPainter28.setArc(2);
borderPainter28.setFocusWidth(1);
borderPainter28.setLineWidth(3);
flatTestPanel1.add(borderPainter28, "cell 7 1");
//---- borderPainter11 ----
borderPainter11.setScale(8.0F);
borderPainter11.setPaintBorder(false);
borderPainter11.setPaintBackground(false);
borderPainter11.setFocusWidth(0);
flatTestPanel1.add(borderPainter11, "cell 0 2");
//---- borderPainter3 ----
borderPainter3.setScale(8.0F);
borderPainter3.setPaintBorder(false);
borderPainter3.setPaintBackground(false);
flatTestPanel1.add(borderPainter3, "cell 1 2");
//---- borderPainter5 ----
borderPainter5.setScale(8.0F);
borderPainter5.setPaintBorder(false);
borderPainter5.setPaintBackground(false);
borderPainter5.setArc(10);
borderPainter5.setW(25);
flatTestPanel1.add(borderPainter5, "cell 2 2");
//---- borderPainter15 ----
borderPainter15.setScale(8.0F);
borderPainter15.setPaintBorder(false);
borderPainter15.setPaintBackground(false);
borderPainter15.setArc(20);
borderPainter15.setW(25);
flatTestPanel1.add(borderPainter15, "cell 3 2");
//---- borderPainter19 ----
borderPainter19.setScale(8.0F);
borderPainter19.setPaintBorder(false);
borderPainter19.setPaintBackground(false);
borderPainter19.setFocusWidth(0);
borderPainter19.setArc(0);
flatTestPanel1.add(borderPainter19, "cell 4 2");
//---- borderPainter23 ----
borderPainter23.setScale(8.0F);
borderPainter23.setPaintBorder(false);
borderPainter23.setPaintBackground(false);
borderPainter23.setArc(0);
flatTestPanel1.add(borderPainter23, "cell 5 2");
//---- borderPainter27 ----
borderPainter27.setScale(8.0F);
borderPainter27.setArc(1);
borderPainter27.setFocusWidth(1);
borderPainter27.setLineWidth(3);
flatTestPanel1.add(borderPainter27, "cell 7 2");
//---- borderPainter12 ----
borderPainter12.setScale(8.0F);
borderPainter12.setFocusWidth(0);
flatTestPanel1.add(borderPainter12, "cell 0 3");
//---- borderPainter4 ----
borderPainter4.setScale(8.0F);
flatTestPanel1.add(borderPainter4, "cell 1 3");
//---- borderPainter8 ----
borderPainter8.setScale(8.0F);
borderPainter8.setW(25);
borderPainter8.setArc(10);
flatTestPanel1.add(borderPainter8, "cell 2 3");
//---- borderPainter16 ----
borderPainter16.setScale(8.0F);
borderPainter16.setW(25);
borderPainter16.setArc(20);
flatTestPanel1.add(borderPainter16, "cell 3 3");
//---- borderPainter20 ----
borderPainter20.setScale(8.0F);
borderPainter20.setFocusWidth(0);
borderPainter20.setArc(0);
flatTestPanel1.add(borderPainter20, "cell 4 3");
//---- borderPainter24 ----
borderPainter24.setScale(8.0F);
borderPainter24.setArc(0);
flatTestPanel1.add(borderPainter24, "cell 5 3");
//---- borderPainter26 ----
borderPainter26.setScale(8.0F);
borderPainter26.setArc(0);
borderPainter26.setFocusWidth(1);
borderPainter26.setLineWidth(3);
flatTestPanel1.add(borderPainter26, "cell 7 3");
//---- label1 ----
label1.setText("fw 0, lw 1, arc 6");
flatTestPanel1.add(label1, "cell 0 4");
//---- label2 ----
label2.setText("fw 2, lw 1, arc 6");
flatTestPanel1.add(label2, "cell 1 4");
//---- label3 ----
label3.setText("fw 2, lw 1, arc 10");
flatTestPanel1.add(label3, "cell 2 4");
//---- label4 ----
label4.setText("fw 2, lw 1, arc 20");
flatTestPanel1.add(label4, "cell 3 4");
//---- label5 ----
label5.setText("fw 0, lw 1, arc 0");
flatTestPanel1.add(label5, "cell 4 4");
//---- label6 ----
label6.setText("fw 2, lw 1, arc 0");
flatTestPanel1.add(label6, "cell 5 4");
//---- label7 ----
label7.setText("fw 1, lw 3, arc 3,2,1,0");
flatTestPanel1.add(label7, "cell 7 4");
}
setViewportView(flatTestPanel1);
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
// JFormDesigner - End of variables declaration //GEN-END:variables
//---- class Preview ----
public static class BorderPainter
extends JComponent
{
private int w = 20;
private int h = 20;
private int focusWidth = 2;
private int lineWidth = 1;
private int arc = 6;
private float scale = 1;
private boolean paintBackground = true;
private boolean paintBorder = true;
private boolean paintFocus = true;
public BorderPainter() {
}
public int getW() {
return w;
}
public void setW( int w ) {
this.w = w;
}
public int getH() {
return h;
}
public void setH( int h ) {
this.h = h;
}
public int getFocusWidth() {
return focusWidth;
}
public void setFocusWidth( int focusWidth ) {
this.focusWidth = focusWidth;
}
public int getLineWidth() {
return lineWidth;
}
public void setLineWidth( int lineWidth ) {
this.lineWidth = lineWidth;
}
public int getArc() {
return arc;
}
public void setArc( int arc ) {
this.arc = arc;
}
public float getScale() {
return scale;
}
public void setScale( float scale ) {
this.scale = scale;
}
public boolean isPaintBackground() {
return paintBackground;
}
public void setPaintBackground( boolean paintBackground ) {
this.paintBackground = paintBackground;
}
public boolean isPaintBorder() {
return paintBorder;
}
public void setPaintBorder( boolean paintBorder ) {
this.paintBorder = paintBorder;
}
public boolean isPaintFocus() {
return paintFocus;
}
public void setPaintFocus( boolean paintFocus ) {
this.paintFocus = paintFocus;
}
@Override
public Dimension getPreferredSize() {
return UIScale.scale( new Dimension( (int) ((w + 2) * scale), (int) ((h + 2) * scale) ) );
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
@Override
protected void paintComponent( Graphics g ) {
Graphics2D g2 = (Graphics2D) g;
FlatUIUtils.setRenderingHints( g2 );
g2.scale( scale, scale );
g2.translate( 1, 1 );
int width = UIScale.scale( w );
int height = UIScale.scale( h );
float focusWidth = UIScale.scale( (float) this.focusWidth );
float lineWidth = UIScale.scale( (float) this.lineWidth );
float arc = UIScale.scale( (float) this.arc );
if( paintBackground ) {
g.setColor( Color.green );
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
}
if( paintFocus ) {
g.setColor( Color.blue );
FlatUIUtils.paintComponentOuterBorder( g2, 0, 0, width, height, focusWidth, lineWidth, arc );
}
if( paintBorder ) {
g.setColor( Color.red );
FlatUIUtils.paintComponentBorder( g2, 0, 0, width, height, focusWidth, lineWidth, arc );
}
HiDPIUtils.paintAtScale1x( g2, 0, 0, width, height,
(g2d, x2, y2, width2, height2, scaleFactor) -> {
int gap = 3;
g2d.setColor( Color.magenta );
g2d.drawRect( x2 - gap, y2 - gap, width2 + (gap * 2) - 1, height2 + (gap * 2) - 1 );
} );
}
}
}

View File

@@ -0,0 +1,314 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
root: new FormRoot {
auxiliary() {
"JavaCodeGenerator.defaultVariableLocal": true
}
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) {
name: "this"
"border": sfield com.jformdesigner.model.FormObject NULL_VALUE
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[fill][left][left][fill][fill][fill][fill][fill]"
"$rowConstraints": "[top][top][top][top][]"
} ) {
name: "flatTestPanel1"
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter9"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
"focusWidth": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter1"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter6"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
"w": 25
"arc": 10
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter13"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
"w": 25
"arc": 20
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter17"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
"focusWidth": 0
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter21"
"scale": 8.0f
"paintBorder": false
"paintFocus": false
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter29"
"scale": 8.0f
"arc": 3
"focusWidth": 1
"lineWidth": 3
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 0"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter10"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
"focusWidth": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter2"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter7"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
"w": 25
"arc": 10
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter14"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
"w": 25
"arc": 20
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter18"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
"focusWidth": 0
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter22"
"scale": 8.0f
"paintBackground": false
"paintFocus": false
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter28"
"scale": 8.0f
"arc": 2
"focusWidth": 1
"lineWidth": 3
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 1"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter11"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
"focusWidth": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter3"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter5"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
"arc": 10
"w": 25
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter15"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
"arc": 20
"w": 25
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter19"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
"focusWidth": 0
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter23"
"scale": 8.0f
"paintBorder": false
"paintBackground": false
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter27"
"scale": 8.0f
"arc": 1
"focusWidth": 1
"lineWidth": 3
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 2"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter12"
"scale": 8.0f
"focusWidth": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter4"
"scale": 8.0f
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter8"
"scale": 8.0f
"w": 25
"arc": 10
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter16"
"scale": 8.0f
"w": 25
"arc": 20
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter20"
"scale": 8.0f
"focusWidth": 0
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter24"
"scale": 8.0f
"arc": 0
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 3"
} )
add( new FormComponent( "com.formdev.flatlaf.testing.FlatPaintingTest$BorderPainter" ) {
name: "borderPainter26"
"scale": 8.0f
"arc": 0
"focusWidth": 1
"lineWidth": 3
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 3"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label1"
"text": "fw 0, lw 1, arc 6"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label2"
"text": "fw 2, lw 1, arc 6"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label3"
"text": "fw 2, lw 1, arc 10"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label4"
"text": "fw 2, lw 1, arc 20"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label5"
"text": "fw 0, lw 1, arc 0"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label6"
"text": "fw 2, lw 1, arc 0"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 4"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label7"
"text": "fw 1, lw 3, arc 3,2,1,0"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 7 4"
} )
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 1435, 880 )
} )
}
}