mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Tree: Tree.expandedIcon and Tree.collapsedIcon icons added
This commit is contained in:
@@ -234,7 +234,7 @@ public abstract class FlatLaf
|
|||||||
return parseBorder( value );
|
return parseBorder( value );
|
||||||
|
|
||||||
// icons
|
// icons
|
||||||
if( key.endsWith( ".icon" ) )
|
if( key.endsWith( ".icon" ) || key.endsWith( "Icon" ) )
|
||||||
return parseInstance( value );
|
return parseInstance( value );
|
||||||
|
|
||||||
// insets
|
// insets
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.icons;
|
||||||
|
|
||||||
|
import static com.formdev.flatlaf.util.UIScale.*;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for icons that scales width and height, creates and initializes
|
||||||
|
* a scaled graphics context for icon painting.
|
||||||
|
*
|
||||||
|
* Subclasses do not need to scale icon painting.
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public abstract class FlatAbstractIcon
|
||||||
|
implements Icon, UIResource
|
||||||
|
{
|
||||||
|
protected final int width;
|
||||||
|
protected final int height;
|
||||||
|
protected final Color color;
|
||||||
|
|
||||||
|
public FlatAbstractIcon( int width, int height, Color color ) {
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
try {
|
||||||
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
|
// for testing
|
||||||
|
// g2.setColor( Color.blue );
|
||||||
|
// g2.drawRect( x, y, getIconWidth() - 1, getIconHeight() - 1 );
|
||||||
|
|
||||||
|
g2.translate( x, y );
|
||||||
|
UIScale.scaleGraphics( g2 );
|
||||||
|
|
||||||
|
if( color != null )
|
||||||
|
g2.setColor( color );
|
||||||
|
|
||||||
|
paintIcon( g2 );
|
||||||
|
} finally {
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void paintIcon( Graphics2D g2 );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return scale( width );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return scale( height );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.icons;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "collapsed" icon for {@link javax.swing.JTree}.
|
||||||
|
*
|
||||||
|
* @uiDefault Tree.icon.collapsedColor Color
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class FlatTreeCollapsedIcon
|
||||||
|
extends FlatAbstractIcon
|
||||||
|
{
|
||||||
|
public FlatTreeCollapsedIcon() {
|
||||||
|
super( 11, 11, UIManager.getColor( "Tree.icon.collapsedColor" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintIcon( Graphics2D g ) {
|
||||||
|
Path2D arrow = new Path2D.Float();
|
||||||
|
arrow.moveTo( 2, 1 );
|
||||||
|
arrow.lineTo( 2, 10 );
|
||||||
|
arrow.lineTo( 10, 5.5 );
|
||||||
|
arrow.closePath();
|
||||||
|
|
||||||
|
g.fill( arrow );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.icons;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "expanded" icon for {@link javax.swing.JTree}.
|
||||||
|
*
|
||||||
|
* @uiDefault Tree.icon.expandedColor Color
|
||||||
|
*
|
||||||
|
* @author Karl Tauber
|
||||||
|
*/
|
||||||
|
public class FlatTreeExpandedIcon
|
||||||
|
extends FlatAbstractIcon
|
||||||
|
{
|
||||||
|
public FlatTreeExpandedIcon() {
|
||||||
|
super( 11, 11, UIManager.getColor( "Tree.icon.expandedColor" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintIcon( Graphics2D g ) {
|
||||||
|
Path2D arrow = new Path2D.Float();
|
||||||
|
arrow.moveTo( 1, 2 );
|
||||||
|
arrow.lineTo( 10, 2 );
|
||||||
|
arrow.lineTo( 5.5, 10 );
|
||||||
|
arrow.closePath();
|
||||||
|
|
||||||
|
g.fill( arrow );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -140,3 +140,9 @@ TabbedPane.disabledUnderlineColor=7a7a7a
|
|||||||
TabbedPane.hoverColor=2e3133
|
TabbedPane.hoverColor=2e3133
|
||||||
TabbedPane.focusColor=3d4b5c
|
TabbedPane.focusColor=3d4b5c
|
||||||
TabbedPane.contentAreaColor=323232
|
TabbedPane.contentAreaColor=323232
|
||||||
|
|
||||||
|
|
||||||
|
#---- Tree ----
|
||||||
|
|
||||||
|
Tree.icon.expandedColor=adadad
|
||||||
|
Tree.icon.collapsedColor=adadad
|
||||||
|
|||||||
@@ -168,3 +168,9 @@ TextField.margin=@textComponentMargin
|
|||||||
TextPane.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
TextPane.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
||||||
TextPane.background=@textComponentBackground
|
TextPane.background=@textComponentBackground
|
||||||
TextPane.margin=@textComponentMargin
|
TextPane.margin=@textComponentMargin
|
||||||
|
|
||||||
|
|
||||||
|
#---- Tree ----
|
||||||
|
|
||||||
|
Tree.expandedIcon=com.formdev.flatlaf.icons.FlatTreeExpandedIcon
|
||||||
|
Tree.collapsedIcon=com.formdev.flatlaf.icons.FlatTreeCollapsedIcon
|
||||||
|
|||||||
@@ -140,3 +140,9 @@ TabbedPane.disabledUnderlineColor=ababab
|
|||||||
TabbedPane.hoverColor=d9d9d9
|
TabbedPane.hoverColor=d9d9d9
|
||||||
TabbedPane.focusColor=dae4ed
|
TabbedPane.focusColor=dae4ed
|
||||||
TabbedPane.contentAreaColor=bfbfbf
|
TabbedPane.contentAreaColor=bfbfbf
|
||||||
|
|
||||||
|
|
||||||
|
#---- Tree ----
|
||||||
|
|
||||||
|
Tree.icon.expandedColor=afafaf
|
||||||
|
Tree.icon.collapsedColor=afafaf
|
||||||
|
|||||||
@@ -134,3 +134,9 @@ TabbedPane.disabledUnderlineColor=7a7a7a
|
|||||||
TabbedPane.hoverColor=eeeeee
|
TabbedPane.hoverColor=eeeeee
|
||||||
TabbedPane.focusColor=dddddd
|
TabbedPane.focusColor=dddddd
|
||||||
TabbedPane.contentAreaColor=bbbbbb
|
TabbedPane.contentAreaColor=bbbbbb
|
||||||
|
|
||||||
|
|
||||||
|
#---- Tree ----
|
||||||
|
|
||||||
|
Tree.icon.expandedColor=ad00ad
|
||||||
|
Tree.icon.collapsedColor=00adad
|
||||||
|
|||||||
Reference in New Issue
Block a user