package net.qingruan.editor; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.font.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.*; import javax.swing.event.*; //這是一個(gè)字體選擇器,選擇好字體,字形,字號(hào)后點(diǎn)擊確定會(huì)創(chuàng)建一個(gè)字體,字體給TextFont.font public class FontChooser { // 聲明字體選擇器的各個(gè)控件 private JLabel fontTypeFace = null;// 字體標(biāo)簽 private JLabel fontStyle = null;// 字形標(biāo)簽 private JLabel fontSize = null;// 字體大小標(biāo)簽 private JLabel demonstrationLabel = null;// 文本示例標(biāo)簽 private JTextField fontTypeFaceText = null;// 字體顯示區(qū) private JTextField fontStyleText = null;// 字形顯示區(qū) private JTextField fontSizeText = null;// 字體大小顯示區(qū) private JList fontTypeFaceList = null;// 字體列表 private JScrollPane fontTypeFaceListScrollPane = null;// 字體列表滾動(dòng)條 private JList fontStyleList = null;// 字形列表 private JList fontSizeList = null;// 字體大小列表 private JScrollPane fontSizeListScrollPane = null;// 字體大小列表滾動(dòng)條 private JButton sure = null;// 確定按鈕 private JButton cancle = null;// 取消按鈕 private Map sizeMap = null; private String returnFontTypeFace = null;// 存儲(chǔ)字體 private int returnFontStyle;// 存儲(chǔ)字形 private int returnFontSize;// 存儲(chǔ)字體大小 private JDialog jd; private Font old; // 初始化字體選擇器的各個(gè)控件 public void init(JFrame f, Font font) { this.old = font; // 得到當(dāng)前字體的信息,用于顯示在字體預(yù)覽區(qū) returnFontTypeFace = font.getFamily(); returnFontStyle = font.getStyle(); returnFontSize = font.getSize(); jd = new JDialog(f, true); fontTypeFace = new JLabel("字體:"); fontStyle = new JLabel("字形:"); fontSize = new JLabel("大?。?); demonstrationLabel = new JLabel("示例文本W(wǎng)elcome"); fontTypeFaceText = new JTextField("宋體"); fontTypeFaceText.setEditable(false); fontStyleText = new JTextField("常規(guī)"); fontStyleText.setEditable(false); fontSizeText = new JTextField("12"); fontSizeText.setEditable(false); GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); String[] fontTypeFaceStr = ge.getAvailableFontFamilyNames();// 獲得系統(tǒng)字體 fontTypeFaceList = new JList(fontTypeFaceStr);// 初始化字體列表 fontTypeFaceListScrollPane = new JScrollPane(fontTypeFaceList); fontStyleList = new JList(new String[] { "常規(guī)", "斜體", "粗體", "粗斜體" })