开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
JavaNotepad
/
src
/
king
/
notepad
/
view
/
FontDialog.java
JavaNotepad
/
src
/
king
/
notepad
/
view
/
FontDialog.java
FontDialog.java 8.95 KB
一键复制 编辑 原始数据 按行查看 历史
loveNight 提交于 2015年11月26日 12:03 +08:00 . Java记事本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
package king.notepad.view;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import king.notepad.actionlistener.ActionListenerFactory;
import king.notepad.itemlistener.ItemListenerFactory;
import king.notepad.listselectionlistener.ListSelectionListenerFactory;
//"字体"对话框
public class FontDialog extends JDialog {
//获取系统字体
private String[] font = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
//加入列表框
private JList fontList = new JList(font);
private JTextField fontText = new JTextField(10);
//字形
public static final String[] fontStyle = {"常规", "粗体", "倾斜", "粗偏斜体"}; //对应的字形常量值分别为0, 1, 2, 3
private JList fontStyleList = new JList(fontStyle);
private JTextField fontStyleText = new JTextField(10);
//字体大小
private Integer[] fontSize = {8, 9, 10,11,12,14,16,18,20,22,24,26,28,36,48,72};
private JList fontSizeList = new JList(fontSize);
private JTextField fontSizeText = new JTextField(10);
//示例框
private JLabel exampleLabel = new JLabel("AaBbYyZz");
//脚本
private String[] scenario = {"西欧语言", "中文 GB2312"};
private String[] example = {"AaBbYyZz", "习定凝神,惩忿窒欲"};
private JComboBox scenarioList = new JComboBox(scenario);
private NotepadFrame frame;
public FontDialog(NotepadFrame frame){
super(frame, "字体");
this.frame = frame;
//设置对话框在Frame正中
int frameX = (int)frame.getBounds().getX();
int frameY = (int)frame.getBounds().getY();
setBounds(frameX+40, frameY+80, 0, 0);
//最上面的面板
JPanel up = new JPanel();
up.add(createFontList());
up.add(createFontStyleList());
up.add(createFontSizeList());
add(up, BorderLayout.NORTH);
//下方面板
JPanel center = new JPanel();
center.add(createExamplePanel());
center.add(createScenarioPanel());
//右下
JPanel downRight = new JPanel(new GridLayout(2, 1, 0, 10));
JButton ensure = new JButton("确定");
ensure.addActionListener(ActionListenerFactory.getActionListener(this, "确定"));
JButton cancel = new JButton("取消");
cancel.addActionListener(ActionListenerFactory.getActionListener(this, "取消"));
downRight.add(ensure);
downRight.add(cancel);
center.add(downRight);
add(center);
pack();
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
}
// 设置对应的TextArea的字体
public void setTextAreaFont(Font font){
frame.setTextAreaFont(font);
}
//根据示例ComboBox的选择值返回示例文本
public String getScenarioListValue(){
String select = (String)this.scenarioList.getSelectedItem();
if("西欧语言".equals(select)){
return example[0];
}else{
return example[1];
}
}
// 设置示例JLabel的文字
public void setExampleText(String text){
this.exampleLabel.setText(text);
}
// 设置示例JLabel的字体
public void setExampleFont(Font font){
this.exampleLabel.setFont(font);
}
//设置字体大小List上方的文本框的值
public void setFontSizeTextField(int n){
this.fontSizeText.setText(String.valueOf(n));
}
//获取字体大小列表框的选择值
public int getFontSizeListValue(){
return (Integer)this.fontSizeList.getSelectedValue();
}
// 设置字形List上方的文本框的值
public void setFontStyleTextField(String text){
this.fontStyleText.setText(text);
}
//获取字形列表框的选中值,将它转化成字形常量值
public int getFontStyleListValue(){
String fontStyleName = (String)this.fontStyleList.getSelectedValue();
for(int i = 0; i < fontStyle.length; i++){
if(fontStyle[i].equals(fontStyleName)) return i;
}
return 0;
}
//设置字体JList上方的文本框的值
public void setFontTextField(String text){
this.fontText.setText(text);
}
//获取字体列表框的选择值
public String getFontListValue(){
return (String)this.fontList.getSelectedValue();
}
// 示例框用的脚本
private JPanel createScenarioPanel(){
JLabel label = new JLabel("脚本:");
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(scenarioList);
scenarioList.addItemListener(ItemListenerFactory.getListener(this, "脚本"));
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
return panel;
}
// 示例框
private JPanel createExamplePanel(){
exampleLabel.setFont(frame.getTextAreaFont());
exampleLabel.setHorizontalAlignment(SwingConstants.CENTER);
exampleLabel.setPreferredSize(new Dimension(200,40));
// exampleLabel.setBorder(BorderFactory.createEmptyBorder(10, 40, 10, 40));
JPanel panel = new JPanel();
panel.add(exampleLabel);
panel.setBorder(BorderFactory.createTitledBorder("示例"));
// panel.setBorder(BorderFactory.createTitledBorder(
// BorderFactory.createEmptyBorder(10, 10, 10, 10), "示例"));
return panel;
}
//字体大小列表框
private JPanel createFontSizeList(){
fontSizeList.setVisibleRowCount(7);
fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane jsp = new JScrollPane(fontSizeList);
//当前使用的字形
int fontSize = frame.getTextAreaFont().getSize();
fontSizeList.setSelectedValue(fontSize, true);
fontSizeText.setText(String.valueOf(fontSizeList.getSelectedValue()));
fontSizeList.addListSelectionListener(ListSelectionListenerFactory.getListener(this, "大小"));
JLabel label = new JLabel("大小:");
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(this.fontSizeText);
panel.add(jsp, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return panel;
}
//字形列表框
private JPanel createFontStyleList(){
fontStyleList.setVisibleRowCount(7);
fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane jsp = new JScrollPane(fontStyleList);
//当前使用的字形
int fontStyleConst = frame.getTextAreaFont().getStyle();
fontStyleList.setSelectedValue(fontStyle[fontStyleConst], true);
fontStyleText.setText((String)fontStyleList.getSelectedValue());
fontStyleList.addListSelectionListener(ListSelectionListenerFactory.getListener(this, "字形"));
JLabel label = new JLabel("字形:");
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(this.fontStyleText);
panel.add(jsp, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return panel;
}
// 字体列表框
private JPanel createFontList(){
// 设置自定义文本渲染器,使每条列表显示它本身的字体
// 如果用此方法,则打开字体对话框时会卡几秒,故先取消
// fontList.setCellRenderer(new MyCellRenderer());
fontList.setVisibleRowCount(7);
JScrollPane jsp = new JScrollPane(fontList); //必须写在scrollRectToVisible之前才能使后者生效
fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//当前使用的字体
String fontName = frame.getTextAreaFont().getFamily(); //文本域使用的当前字体
fontList.setSelectedValue(fontName, true); //选中字体
fontText.setText((String)fontList.getSelectedValue());
int index = fontList.getSelectedIndex(); //返回选中的索引
Rectangle rect = fontList.getCellBounds(index, index);
fontList.scrollRectToVisible(rect); //选中行显示在第一行
fontList.addListSelectionListener(ListSelectionListenerFactory.getListener(this, "字体"));
//放入滚动条
//列表框上方的标签和输入框
JLabel label = new JLabel("字体:");
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.NORTH);
panel.add(fontText);
panel.add(jsp, BorderLayout.SOUTH);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return panel;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/umdol/JavaNotepad.git
git@gitee.com:umdol/JavaNotepad.git
umdol
JavaNotepad
JavaNotepad
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /