Separator implemented

This commit is contained in:
Karl Tauber
2019-08-25 23:16:20 +02:00
parent 7ea5e11ee7
commit f0fb5f54c0
7 changed files with 120 additions and 10 deletions

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2019 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
*
* http://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.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSeparatorUI;
/**
* Provides the Flat LaF UI delegate for {@link javax.swing.JSeparator}.
*
* @author Karl Tauber
*/
public class FlatSeparatorUI
extends BasicSeparatorUI
{
private static final int WIDTH = 2;
private static ComponentUI instance;
public static ComponentUI createUI( JComponent c ) {
if( instance == null )
instance = new FlatSeparatorUI();
return instance;
}
@Override
public void paint( Graphics g, JComponent c ) {
g.setColor( c.getForeground() );
if( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
((Graphics2D)g).fill( new Rectangle2D.Float( 0, 0, scale( (float) WIDTH ), c.getHeight() ) );
else
((Graphics2D)g).fill( new Rectangle2D.Float( 0, 0, c.getWidth(), scale( (float) WIDTH ) ) );
}
@Override
public Dimension getPreferredSize( JComponent c ) {
if( ((JSeparator) c).getOrientation() == JSeparator.VERTICAL )
return new Dimension( scale( WIDTH ), 0 );
else
return new Dimension( 0, WIDTH );
}
}

View File

@@ -112,3 +112,8 @@ ProgressBar.selectionBackground=@foreground
ScrollBar.track=3F4244
ScrollBar.thumb=47A6A6A6
#---- Separator ----
Separator.foreground=515151

View File

@@ -27,6 +27,7 @@ ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
ScrollBarUI=com.formdev.flatlaf.ui.FlatScrollBarUI
ScrollPaneUI=com.formdev.flatlaf.ui.FlatScrollPaneUI
SeparatorUI=com.formdev.flatlaf.ui.FlatSeparatorUI
TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI
TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI
TextPaneUI=com.formdev.flatlaf.ui.FlatTextPaneUI

View File

@@ -112,3 +112,8 @@ ProgressBar.selectionBackground=@foreground
ScrollBar.track=F5F5F5
ScrollBar.thumb=33737373
#---- Separator ----
Separator.foreground=cdcdcd