📄 smoothgradientborders.java
字号:
/* * SmoothGradientBorders.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.underworldlabs.swing.plaf.smoothgradient;import java.awt.Color;import java.awt.Component;import java.awt.Dialog;import java.awt.Graphics;import java.awt.Insets;import java.awt.Window;import javax.swing.AbstractButton;import javax.swing.ButtonModel;import javax.swing.JButton;import javax.swing.JInternalFrame;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JToggleButton;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.border.AbstractBorder;import javax.swing.border.Border;import javax.swing.border.CompoundBorder;import javax.swing.plaf.BorderUIResource;import javax.swing.plaf.UIResource;import javax.swing.plaf.basic.BasicBorders;import javax.swing.plaf.metal.MetalBorders;import javax.swing.plaf.metal.MetalLookAndFeel;import javax.swing.text.JTextComponent;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author Takis Diakoumis * @version $Revision: 1.4 $ * @date $Date: 2006/05/14 06:56:07 $ */final class SmoothGradientBorders { // Accessing and Creating Borders *************************************** private static Border buttonBorder; private static Border comboBoxEditorBorder; private static Border comboBoxArrowButtonBorder; private static Border etchedBorder; private static Border flush3DBorder; private static Border menuBarHeaderBorder; private static Border menuBorder; private static Border menuItemBorder; private static Border popupMenuBorder; private static Border rolloverButtonBorder; private static Border scrollPaneBorder; private static Border separatorBorder; private static Border textFieldBorder; private static Border thinLoweredBorder; private static Border thinRaisedBorder; private static Border toggleButtonBorder; private static Border toolBarHeaderBorder; /** * Returns a border instance for a <code>JButton</code>. */ static Border getButtonBorder() { if (buttonBorder == null) { buttonBorder = new BorderUIResource.CompoundBorderUIResource( new ButtonBorder(), new BasicBorders.MarginBorder()); } return buttonBorder; } /** * Returns a border for a <code>JComboBox</code>'s editor. */ static Border getComboBoxEditorBorder() { if (comboBoxEditorBorder == null) { comboBoxEditorBorder = new CompoundBorder( // No UIResource new ComboBoxEditorBorder(), new BasicBorders.MarginBorder()); } return comboBoxEditorBorder; } /** * Returns a border for a <code>JComboBox</code>'s button. */ static Border getComboBoxArrowButtonBorder() { if (comboBoxArrowButtonBorder == null) { comboBoxArrowButtonBorder = new CompoundBorder( // No UIResource new ComboBoxArrowButtonBorder(), new BasicBorders.MarginBorder()); } return comboBoxArrowButtonBorder; } /** * Returns an etched border instance for <code>JMenuBar</code> or * <code>JToolBar</code>. */ static Border getEtchedBorder() { if (etchedBorder == null) { etchedBorder = new BorderUIResource.CompoundBorderUIResource( new EtchedBorder(), new BasicBorders.MarginBorder()); } return etchedBorder; } /** * Returns a flushed 3D border. */ static Border getFlush3DBorder() { if (flush3DBorder == null) { flush3DBorder = new Flush3DBorder(); } return flush3DBorder; } /** * Returns a border for a <code>JInternalFrame</code>. */ static Border getInternalFrameBorder() { return new InternalFrameBorder(); } /** * Returns a special border for a <code>JMenuBar</code> that * is used in a header just above a <code>JToolBar</code>. */ static Border getMenuBarHeaderBorder() { if (menuBarHeaderBorder == null) { menuBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource( new MenuBarHeaderBorder(), new BasicBorders.MarginBorder()); } return menuBarHeaderBorder; } /** * Returns a border instance for a <code>JMenu</code>. */ static Border getMenuBorder() { if (menuBorder == null) { menuBorder = new BorderUIResource.CompoundBorderUIResource( new MenuBorder(), new BasicBorders.MarginBorder()); } return menuBorder; } /** * Returns a border instance for a <code>JMenuItem</code>. */ static Border getMenuItemBorder() { if (menuItemBorder == null) { menuItemBorder = new BorderUIResource(new BasicBorders.MarginBorder()); } return menuItemBorder; } /** * Returns a border instance for a <code>JPopupMenu</code>. */ static Border getPopupMenuBorder() { if (popupMenuBorder == null) { popupMenuBorder = new PopupMenuBorder(); } return popupMenuBorder; } /** * Returns a border for a <code>JInternalFrame</code>'s palette. */ static Border getPaletteBorder() { return new PaletteBorder(); } /** * Returns a rollover border for buttons in a <code>JToolBar</code>. */ static Border getRolloverButtonBorder() { if (rolloverButtonBorder == null) { rolloverButtonBorder = new BorderUIResource.CompoundBorderUIResource( new RolloverButtonBorder(), new BasicBorders.MarginBorder()); } return rolloverButtonBorder; } /** * Returns a separator border instance for <code>JScrollPane</code>. */ static Border getScrollPaneBorder() { if (scrollPaneBorder == null) { scrollPaneBorder = new ScrollPaneBorder(); } return scrollPaneBorder; } /** * Returns a separator border instance for <code>JMenuBar</code> or * <code>JToolBar</code>. */ static Border getSeparatorBorder() { if (separatorBorder == null) { separatorBorder = new BorderUIResource.CompoundBorderUIResource( new SeparatorBorder(), new BasicBorders.MarginBorder()); } return separatorBorder; } /** * Returns a border instance for a JTextField. */ static Border getTextFieldBorder() { if (textFieldBorder == null) { textFieldBorder = new BorderUIResource.CompoundBorderUIResource( new TextFieldBorder(), new BasicBorders.MarginBorder()); } return textFieldBorder; } /** * Returns a thin lowered border. */ static Border getThinLoweredBorder() { if (thinLoweredBorder == null) { thinLoweredBorder = new ThinLoweredBorder(); } return thinLoweredBorder; } /** * Returns a thin raised border. */ static Border getThinRaisedBorder() { if (thinRaisedBorder == null) { thinRaisedBorder = new ThinRaisedBorder(); } return thinRaisedBorder; } /** * Returns a border instance for a JToggleButton. */ static Border getToggleButtonBorder() { if (toggleButtonBorder == null) { toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource( new ToggleButtonBorder(), new BasicBorders.MarginBorder()); } return toggleButtonBorder; } /** * Returns a special border for a <code>JToolBar</code> that * is used in a header just below a <code>JMenuBar</code>. */ static Border getToolBarHeaderBorder() { if (toolBarHeaderBorder == null) { toolBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource( new ToolBarHeaderBorder(), new BasicBorders.MarginBorder()); } return toolBarHeaderBorder; } private static Border optionDialogBorder; static Border getOptionDialogBorder() { if (optionDialogBorder == null) { optionDialogBorder = new OptionDialogBorder(); } return optionDialogBorder; } private static class OptionDialogBorder extends AbstractBorder implements UIResource { private static final Insets insets = new Insets(3, 3, 3, 3); int titleHeight = 0; public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate(x,y); int messageType = JOptionPane.PLAIN_MESSAGE; if (c instanceof JInternalFrame) { Object obj = ((JInternalFrame) c).getClientProperty( "JInternalFrame.messageType"); if (obj != null && (obj instanceof Integer)) { messageType = ((Integer) obj).intValue(); } } Color borderColor; switch (messageType) { case(JOptionPane.ERROR_MESSAGE): borderColor = UIManager.getColor( "OptionPane.errorDialog.border.background"); break; case(JOptionPane.QUESTION_MESSAGE): borderColor = UIManager.getColor(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -