📄 nimrodborders.java
字号:
/*
* (C) Copyright 2005 Nilo J. Gonzalez
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser Gereral Public Licence as published by the Free
* Software Foundation; either version 2 of the Licence, or (at your opinion) any
* later version.
*
* This library is distributed in the hope that it will be usefull, but WITHOUT ANY
* WARRANTY; without even the implied warranty of merchantability or fitness for a
* particular purpose. See the GNU Lesser General Public Licence for more details.
*
* You should have received a copy of the GNU Lesser General Public Licence along
* with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, Ma 02111-1307 USA.
*
* http://www.gnu.org/licenses/lgpl.html (English)
* http://gugs.sindominio.net/gnu-gpl/lgpl-es.html (Espa駉l)
*
*
* Original author: Nilo J. Gonz醠ez
*/
/**
* Esta clase se utiliza como repositorio de borders. Esa es su unica utilidad.
* @author Nilo J. Gonzalez
*/
package com.nilo.plaf.nimrod;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.metal.*;
public class NimRODBorders extends MetalBorders {
private static Border butBorder;
private static Border popupMenuBorder;
private static Border rolloverButtonBorder;
private static Border scrollPaneBorder;
private static Border internalFrameBorder;
private static Border menuBarBorder;
public static Border getInternalFrameBorder() {
if ( internalFrameBorder == null) {
internalFrameBorder = new NimRODInternalFrameBorder();
}
return internalFrameBorder;
}
public static Border getPopupMenuBorder() {
if ( popupMenuBorder == null) {
popupMenuBorder = new NimRODPopupMenuBorder();
}
return popupMenuBorder;
}
public static Border getButtonBorder() {
if ( butBorder == null) {
butBorder = new BorderUIResource.CompoundBorderUIResource( new NimRODBorders.NimRODButtonBorder(),
new BasicBorders.MarginBorder());
}
return butBorder;
}
public static Border getRolloverButtonBorder() {
if ( rolloverButtonBorder == null) {
rolloverButtonBorder = new NimRODBorders.NimRODRolloverButtonBorder();
}
return rolloverButtonBorder;
}
public static Border getScrollPaneBorder() {
if ( scrollPaneBorder == null) {
scrollPaneBorder = new NimRODScrollPaneBorder();
}
return scrollPaneBorder;
}
public static Border getMenuBarBorder() {
if ( menuBarBorder == null) {
menuBarBorder = new NimRODMenuBarBorder();
}
return menuBarBorder;
}
public static class NimRODButtonBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = -2083885266582056467L;
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h) {
if ( !((AbstractButton)c).isBorderPainted() ) {
return;
}
g.translate( x, y);
g.setColor( NimRODLookAndFeel.getControlDarkShadow() );
g.drawRoundRect( 0,0, w-1,h-1, 8,8);
if ( c instanceof JButton ) {
JButton button = (JButton)c;
//ButtonModel model = button.getModel();
if ( button.isDefaultButton() ) {
g.setColor( NimRODLookAndFeel.getControlDarkShadow().darker());
g.drawRoundRect( 1,1, w-3,h-3, 7,7);
}
/*else if ( model.isPressed() && model.isArmed() ) {
g.translate( x, y);
g.setColor( NimRODLookAndFeel.getControlDarkShadow() );
g.drawRoundRect( 0,0, w-1,h-1, 8,8);
}*/
}
}
}
public static class NimRODPopupMenuBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = -2083885266582056468L;
protected static Insets borderInsets = new Insets( 1,1, 5,5);
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
g.translate( x, y);
g.setColor( NimRODLookAndFeel.getControlDarkShadow());
g.drawRect( 0, 0, w-5, h-5);
Icon icono = UIManager.getIcon( "BorderPopupMenu.SombraEsqIcon");
icono.paintIcon( c, g, w-5,h-5);
icono = UIManager.getIcon( "BorderPopupMenu.SombraUpIcon");
icono.paintIcon( c, g, w-5,0);
icono = UIManager.getIcon( "BorderPopupMenu.SombraIzqIcon");
icono.paintIcon( c, g, 0,h-5);
icono = UIManager.getIcon( "BorderPopupMenu.SombraBajIcon");
for ( int xi = 5; xi < w-5; xi++) {
icono.paintIcon( c, g, xi, h-5);
}
icono = UIManager.getIcon( "BorderPopupMenu.SombraDerIcon");
for ( int yi = 5; yi < h-5; yi++) {
icono.paintIcon( c, g, w-5, yi);
}
g.translate( -x, -y);
}
public Insets getBorderInsets( Component c ) {
return borderInsets;
}
public Insets getBorderInsets( Component c, Insets newInsets) {
newInsets.top = borderInsets.top;
newInsets.left = borderInsets.left;
newInsets.bottom = borderInsets.bottom;
newInsets.right = borderInsets.right;
return newInsets;
}
}
public static class NimRODRolloverButtonBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = -2083885266582056469L;
protected static Insets borderInsets = new Insets( 3,3, 3,3);
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h) {
if ( !((AbstractButton)c).isBorderPainted() ) {
return;
}
ButtonModel model = ((AbstractButton)c).getModel();
if ( model.isRollover() ) { //&& !( model.isPressed() && !model.isArmed() ) ) {
g.setColor( NimRODLookAndFeel.getControlDarkShadow());
g.drawRoundRect( 0,0, w-1,h-1, 8,8);
RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
boton.x = 0;
boton.y = 0;
boton.width = c.getWidth();
boton.height = c.getHeight();
boton.arcwidth = 8;
boton.archeight = 8;
GradientPaint grad = null;
if ( model.isPressed() ) {
grad = new GradientPaint( 0,0, NimRODUtils.sombra,
0,c.getHeight()/2, NimRODUtils.brillo);
}
else {
grad = new GradientPaint( 0,0, NimRODUtils.brillo,
0,c.getHeight(), NimRODUtils.sombra);
}
Graphics2D g2D = (Graphics2D)g;
g2D.setPaint( grad);
g2D.fill( boton);
}
}
public Insets getBorderInsets( Component c ) {
return borderInsets;
}
public Insets getBorderInsets( Component c, Insets newInsets) {
newInsets.top = borderInsets.top;
newInsets.left = borderInsets.left;
newInsets.bottom = borderInsets.bottom;
newInsets.right = borderInsets.right;
return newInsets;
}
}
public static class NimRODScrollPaneBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = -6416636693876853556L;
private static final Insets insets = new Insets(1, 1, 2, 2);
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h) {
g.translate( x, y);
g.setColor( NimRODLookAndFeel.getControlDarkShadow());
g.drawRect( 0, 0, w - 2, h - 2);
g.setColor( NimRODLookAndFeel.getControlHighlight());
g.drawLine( w - 1, 1, w - 1, h - 1);
g.drawLine( 1, h - 1, w - 1, h - 1);
g.translate( -x, -y);
}
public Insets getBorderInsets(Component c) {
return insets;
}
}
public static class NimRODInternalFrameBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = -4691959764241705857L;
private static final int grosor = 4;
protected static Insets ins = new Insets( 0,grosor, 5+grosor, 5+grosor);
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
g.translate( x, y);
Graphics2D g2D = (Graphics2D)g.create();
g2D.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, NimRODUtils.getFrameOpacityFloat()));
// Elegimos el color del borde
Color colIzq, colDer;
GradientPaint grad;
if ( ((JInternalFrame)c).isSelected() ) {
grad = new GradientPaint( 0,0, NimRODLookAndFeel.getPrimaryControlDarkShadow(),
w,0, NimRODLookAndFeel.getPrimaryControl());
colIzq = NimRODLookAndFeel.getPrimaryControlDarkShadow();
colDer = NimRODLookAndFeel.getPrimaryControl();
}
else {
grad = new GradientPaint( 0,0, NimRODLookAndFeel.getControl(),
w,0, NimRODLookAndFeel.getControlDarkShadow());
colIzq = NimRODLookAndFeel.getControl();
colDer = NimRODLookAndFeel.getControlDarkShadow();
}
g2D.setColor( colIzq);
g2D.fillRect( 0, 0, grosor,h-ins.bottom);
g2D.setPaint( grad);
g2D.fillRect( 0, h-ins.bottom, w-ins.right+grosor, grosor);
g2D.setColor( colDer);
g2D.fillRect( w-ins.right, 0, grosor, h-ins.bottom);
g2D.dispose();
g.setColor( NimRODLookAndFeel.getControlDarkShadow());
g.drawRect( 0, 0, w-5, h-5);
Icon icono = UIManager.getIcon( "BorderPopupMenu.SombraEsqIcon");
icono.paintIcon( c, g, w-5,h-5);
icono = UIManager.getIcon( "BorderPopupMenu.SombraUpIcon");
icono.paintIcon( c, g, w-5,0);
icono = UIManager.getIcon( "BorderPopupMenu.SombraIzqIcon");
icono.paintIcon( c, g, 0,h-5);
icono = UIManager.getIcon( "BorderPopupMenu.SombraBajIcon");
for ( int xi = 5; xi < w-5; xi++) {
icono.paintIcon( c, g, xi, h-5);
}
icono = UIManager.getIcon( "BorderPopupMenu.SombraDerIcon");
for ( int yi = 5; yi < h-5; yi++) {
icono.paintIcon( c, g, w-5, yi);
}
g.translate( -x, -y);
}
public Insets getBorderInsets( Component c ) {
return ins;
}
public Insets getBorderInsets( Component c, Insets newInsets) {
newInsets.top = ins.top;
newInsets.left = ins.left;
newInsets.bottom = ins.bottom;
newInsets.right = ins.right;
return newInsets;
}
}
public static class NimRODMenuBarBorder extends AbstractBorder implements UIResource {
private static final long serialVersionUID = 116001977502172752L;
protected static Insets ins = new Insets( 0,10, 0, 10);
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height) {}
public Insets getBorderInsets( Component c) {
return ins;
}
public Insets getBorderInsets( Component c, Insets insets) {
insets.top = ins.top;
insets.left = ins.left;
insets.bottom = ins.bottom;
insets.right = ins.right;
return insets;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -