InternalFrame: icons implemented (issue #11)

This commit is contained in:
Karl Tauber
2019-12-19 17:37:36 +01:00
parent 2399e54a4b
commit af962b99be
5 changed files with 198 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/*
* 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.BasicStroke;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import javax.swing.UIManager;
/**
* "close" icon for {@link javax.swing.JInternalFrame}.
*
* @uiDefault InternalFrame.iconColor Color
*
* @author Karl Tauber
*/
public class FlatInternalFrameCloseIcon
extends FlatAbstractIcon
{
public FlatInternalFrameCloseIcon() {
super( 16, 16, UIManager.getColor( "InternalFrame.iconColor" ) );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
float mx = 8;
float my = 8;
float r = 3.25f;
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new Line2D.Float( mx - r, my - r, mx + r, my + r ), false );
path.append( new Line2D.Float( mx - r, my + r, mx + r, my - r ), false );
g.setStroke( new BasicStroke( 1f ) );
g.draw( path );
}
}

View File

@@ -0,0 +1,41 @@
/*
* 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.Component;
import java.awt.Graphics2D;
import javax.swing.UIManager;
/**
* "iconify" icon for {@link javax.swing.JInternalFrame}.
*
* @uiDefault InternalFrame.iconColor Color
*
* @author Karl Tauber
*/
public class FlatInternalFrameIconifyIcon
extends FlatAbstractIcon
{
public FlatInternalFrameIconifyIcon() {
super( 16, 16, UIManager.getColor( "InternalFrame.iconColor" ) );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
g.fillRect( 3, 8, 10, 1 );
}
}

View File

@@ -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.icons;
import java.awt.Component;
import java.awt.Graphics2D;
import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* "maximize" icon for {@link javax.swing.JInternalFrame}.
*
* @uiDefault InternalFrame.iconColor Color
*
* @author Karl Tauber
*/
public class FlatInternalFrameMaximizeIcon
extends FlatAbstractIcon
{
public FlatInternalFrameMaximizeIcon() {
super( 16, 16, UIManager.getColor( "InternalFrame.iconColor" ) );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
g.fill( FlatUIUtils.createRectangle( 3, 3, 10, 10, 1 ) );
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.Component;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* "minimize" (actually "restore") icon for {@link javax.swing.JInternalFrame}.
*
* @uiDefault InternalFrame.iconColor Color
*
* @author Karl Tauber
*/
public class FlatInternalFrameMinimizeIcon
extends FlatAbstractIcon
{
public FlatInternalFrameMinimizeIcon() {
super( 16, 16, UIManager.getColor( "InternalFrame.iconColor" ) );
}
@Override
protected void paintIcon( Component c, Graphics2D g ) {
Path2D r1 = FlatUIUtils.createRectangle( 5, 3, 8, 8, 1 );
Path2D r2 = FlatUIUtils.createRectangle( 3, 5, 8, 8, 1 );
Area area = new Area( r1 );
area.subtract( new Area( new Rectangle2D.Float( 3, 5, 8, 8 ) ) );
g.fill( area );
g.fill( r2 );
}
}

View File

@@ -278,6 +278,17 @@ public class FlatUIUtils
return null; return null;
} }
/**
* Creates a not-filled rectangle shape with the given line width.
*/
public static Path2D createRectangle( float x, float y, float width, float height, float lineWidth ) {
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
path.append( new Rectangle2D.Float( x, y, width, height ), false );
path.append( new Rectangle2D.Float( x + lineWidth, y + lineWidth,
width - (lineWidth * 2), height - (lineWidth * 2) ), false );
return path;
}
/** /**
* Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius or each corner. * Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius or each corner.
*/ */