📄 nimrodbuttonui.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 implementa los botones.
* @author Nilo J. Gonzalez
*/
package com.nilo.plaf.nimrod;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.event.*;
public class NimRODButtonUI extends MetalButtonUI {
protected MiML miml;
static private NimRODButtonUI ui;
public static ComponentUI createUI( JComponent c) {
//return new NimRODButtonUI( c);
if ( ui == null ) {
ui = new NimRODButtonUI();
}
return ui;
}
public void installDefaults( AbstractButton button) {
super.installDefaults( button);
button.setBorder( NimRODBorders.getButtonBorder());
}
public void unsinstallDefaults( AbstractButton button) {
super.uninstallDefaults( button);
button.setBorder( MetalBorders.getButtonBorder());
}
public void installListeners( AbstractButton b) {
super.installListeners( b);
miml = new MiML( b);
b.addMouseListener( miml);
}
protected void uninstallListeners( AbstractButton b) {
b.removeMouseListener( miml);
}
protected void paintButtonPressed( Graphics g, AbstractButton b) {
if ( !b.isOpaque()) {
return;
}
if ( b.isContentAreaFilled() ) {
Graphics2D g2D = (Graphics2D)g;
g2D.setColor( selectColor);
RoundRectangle2D.Float boton = hazBoton( b);
g2D.fill( boton);
}
}
protected void paintFocus( Graphics g, AbstractButton b,
Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
if ( !b.isFocusPainted() || !b.isOpaque() ) {
return;
}
if ( b.getParent() instanceof JToolBar ) {
return; // No se pinta el foco cuando estamos en una barra
}
g.setColor( getFocusColor());
g.drawRoundRect( 2,2, b.getWidth()-6,b.getHeight()-6, 5,5);
g.drawRoundRect( 3,3, b.getWidth()-6,b.getHeight()-6, 4,4);
}
public void paint( Graphics g, JComponent c) {
ButtonModel mod = ((AbstractButton)c).getModel();
if ( c.isOpaque() ) {
Graphics2D g2D = (Graphics2D)g;
RoundRectangle2D.Float boton = hazBoton( c);
if ( c.getParent() instanceof JToolBar ) {
if ( mod.isRollover() ) {
c.setBorder( NimRODBorders.getGenBorder());
}
else {
c.setBorder( NimRODBorders.getEmptyGenBorder());
}
if ( mod.isPressed() || mod.isSelected() ) {
g2D.setColor( NimRODLookAndFeel.getFocusColor());
g2D.fill( boton);
}
}
else {
GradientPaint grad = null;
if ( mod.isPressed() || mod.isSelected() ) {
grad = new GradientPaint( 0,0, NimRODUtils.getSombra(),
0,c.getHeight(), NimRODUtils.getBrillo());
}
else {
grad = new GradientPaint( 0,0, NimRODUtils.getBrillo(),
0,c.getHeight(), NimRODUtils.getSombra());
}
g2D.setPaint( grad);
g2D.fill( boton);
if ( mod.isRollover() ) {
g2D.setColor( NimRODUtils.getRolloverColor());
g2D.fill( boton);
}
}
}
super.paint( g, c);
}
private RoundRectangle2D.Float hazBoton( JComponent c) {
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;
return boton;
}
/////////////////////////////////////
public class MiML extends MouseInputAdapter {
private AbstractButton papi;
MiML( AbstractButton b) {
papi = b;
}
public void mouseEntered( MouseEvent e) {
papi.getModel().setRollover( true);
papi.repaint();
}
public void mouseExited( MouseEvent e) {
papi.getModel().setRollover( false);
papi.repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -