📄 fontbutton.java
字号:
/*
* 08/10/2005
*
* FontButton.java - Button used by the Font editor/renderer.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* 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.fife.ui.propertysheet;
import java.awt.Font;
import javax.swing.UIManager;
/**
* A button that displays a font. This is used by property sheets to display
* a font.
*
* @author Robert Futrell
* @version 1.0
*/
public class FontButton extends PropertySheetButton {
/**
*
*/
private static final long serialVersionUID = -2880622977833156542L;
private Font displayedFont;
/*****************************************************************************/
/**
* Constructor.
*/
public FontButton() {
}
/*****************************************************************************/
/**
* Returns the font displayed by this button.
*
* @return The font displayed.
* @see #setFont
*/
public Font getFont() {
return displayedFont;
}
/*****************************************************************************/
/**
* Returns the text for the button.
*
* @param font The font the button is displaying.
* @return A text representation of the font.
*/
private static final String getFontString(Font font) {
String returnVal = font.getFontName() + " " + font.getSize();
switch (font.getStyle()) {
case Font.PLAIN:
returnVal += " Plain";
break;
case Font.BOLD:
returnVal += " Bold";
break;
case Font.ITALIC:
returnVal += " Italic";
break;
case Font.BOLD + Font.ITALIC:
returnVal += " Bold Italic";
break;
}
return returnVal;
}
/*****************************************************************************/
/**
* Sets the font displayed by this font button.
*
* @param font The new font.
* @see #getFont
*/
public void setFont(final Font font) {
if (!font.equals(displayedFont)) {
displayedFont = font;
setText(getFontString(displayedFont));
float size = UIManager.getFont("Label.font").getSize2D();
setFont(displayedFont.deriveFont(size));
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -