mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
PopupMenuSeparator implementation
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JPopupMenu.Separator}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatPopupMenuSeparatorUI
|
||||
extends FlatSeparatorUI
|
||||
{
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
if( instance == null )
|
||||
instance = new FlatPopupMenuSeparatorUI();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPropertyPrefix() {
|
||||
return "PopupMenuSeparator";
|
||||
}
|
||||
}
|
||||
@@ -23,18 +23,27 @@ import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicSeparatorUI;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JSeparator}.
|
||||
*
|
||||
* @uiDefault Separator.background Color unused
|
||||
* @uiDefault Separator.foreground Color
|
||||
* @uiDefault Separator.height int height (or width) of the component; may be larger than stripe
|
||||
* @uiDefault Separator.stripeWidth int width of the stripe
|
||||
* @uiDefault Separator.stripeIndent int indent of stripe from top (or left); allows positioning of stripe within component
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatSeparatorUI
|
||||
extends BasicSeparatorUI
|
||||
{
|
||||
private static final int WIDTH = 2;
|
||||
protected int height;
|
||||
protected int stripeWidth;
|
||||
protected int stripeIndent;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
@@ -45,20 +54,43 @@ public class FlatSeparatorUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
g.setColor( c.getForeground() );
|
||||
protected void installDefaults( JSeparator s ) {
|
||||
super.installDefaults( s );
|
||||
|
||||
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 ) ) );
|
||||
String prefix = getPropertyPrefix();
|
||||
height = UIManager.getInt( prefix + ".height" );
|
||||
stripeWidth = UIManager.getInt( prefix + ".stripeWidth" );
|
||||
stripeIndent = UIManager.getInt( prefix + ".stripeIndent" );
|
||||
}
|
||||
|
||||
protected String getPropertyPrefix() {
|
||||
return "Separator";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
try {
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
g2.setColor( c.getForeground() );
|
||||
|
||||
float width = scale( (float) stripeWidth );
|
||||
float indent = scale( (float) stripeIndent );
|
||||
|
||||
if( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
|
||||
g2.fill( new Rectangle2D.Float( indent, 0, width, c.getHeight() ) );
|
||||
else
|
||||
g2.fill( new Rectangle2D.Float( 0, indent, c.getWidth(), width ) );
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize( JComponent c ) {
|
||||
if( ((JSeparator) c).getOrientation() == JSeparator.VERTICAL )
|
||||
return new Dimension( scale( WIDTH ), 0 );
|
||||
return new Dimension( scale( height ), 0 );
|
||||
else
|
||||
return new Dimension( 0, scale( WIDTH ) );
|
||||
return new Dimension( 0, scale( height ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ MenuUI=com.formdev.flatlaf.ui.FlatMenuUI
|
||||
MenuBarUI=com.formdev.flatlaf.ui.FlatMenuBarUI
|
||||
MenuItemUI=com.formdev.flatlaf.ui.FlatMenuItemUI
|
||||
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
|
||||
PopupMenuSeparatorUI=com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI
|
||||
ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI
|
||||
RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI
|
||||
RadioButtonMenuItemUI=com.formdev.flatlaf.ui.FlatRadioButtonMenuItemUI
|
||||
@@ -123,6 +124,13 @@ PasswordField.background=@textComponentBackground
|
||||
PasswordField.margin=@textComponentMargin
|
||||
|
||||
|
||||
#---- PopupMenuSeparator ----
|
||||
|
||||
PopupMenuSeparator.height=9
|
||||
PopupMenuSeparator.stripeWidth=1
|
||||
PopupMenuSeparator.stripeIndent=4
|
||||
|
||||
|
||||
#---- ProgressBar ----
|
||||
|
||||
ProgressBar.border=com.formdev.flatlaf.ui.FlatEmptyBorder
|
||||
@@ -154,6 +162,13 @@ ScrollPane.border=com.formdev.flatlaf.ui.FlatBorder
|
||||
ScrollPane.background=@@ScrollBar.track
|
||||
|
||||
|
||||
#---- Separator ----
|
||||
|
||||
Separator.height=3
|
||||
Separator.stripeWidth=1
|
||||
Separator.stripeIndent=1
|
||||
|
||||
|
||||
#---- Slider ----
|
||||
|
||||
Slider.focusInsets=0,0,0,0
|
||||
|
||||
Reference in New Issue
Block a user