PageRenderTime 55ms CodeModel.GetById 52ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/fontMenu.bsh

#
Unknown | 76 lines | 59 code | 17 blank | 0 comment | 0 complexity | 13ef52e74ffe751799c977167df3ddc5 MD5 | raw file
 1/**
 2 * Creates a font menu for use with the workspace and workspace editors
 3 *
 4 * @return a font menu
 5 *
 6 * @author Daniel Leuck
 7 */
 8fontMenu(component) {
 9	if ( bsh.system.desktop == void ) {
10		print("fontMenu() only works with the bsh desktop...");
11		return;
12	}
13	
14	JMenu fontMenu = new JMenu("Font");
15	
16	sizeListener() {
17		actionPerformed(ae) {
18			setFont(component, Integer.parseInt(ae.actionCommand));
19		}
20	
21		return this;	
22	}
23	this.sizeListener=sizeListener();
24	
25	
26	this.boldMenuItem = new JCheckBoxMenuItem("Bold");
27	this.italicMenuItem = new JCheckBoxMenuItem("Italic");
28	
29	styleListener() {
30		actionPerformed(ae) {
31			setFont(component, null, ((boldMenuItem.selected) ? Font.BOLD : 0) |
32				((italicMenuItem.selected) ? Font.ITALIC : 0), -1);
33		}
34	
35		return this;	
36	}
37	this.styleListener=styleListener();
38	
39	familyListener() {
40		actionPerformed(ae) {
41			setFont(component, ae.actionCommand, -1, -1);
42		}
43	
44		return this;	
45	}
46	this.familyListener=familyListener();	
47	
48	JMenu sizeMenu = new JMenu("Size");
49	for(int i:new int[] {9,10,12,14,16,20,24})
50		sizeMenu.add(new JMenuItem(""+i)).addActionListener(sizeListener);
51	fontMenu.add(sizeMenu);
52	
53	JMenu styleMenu = new JMenu("Style");
54	//styleMenu.add(new JMenuItem("Plain")).addActionListener(this);
55	styleMenu.add(boldMenuItem).addActionListener(styleListener);
56	styleMenu.add(italicMenuItem).addActionListener(styleListener);
57	fontMenu.add(styleMenu);
58	
59	fontMenu.addSeparator();
60	
61	for(var s:new String[] {"SansSerif","Monospaced","Serif","LucidaSans"})
62		fontMenu.add(this.mi=new JMenuItem(s)).addActionListener(familyListener);
63	
64	fontMenu.addSeparator();
65	
66	actionPerformed(ae) {
67		String family = (String)JOptionPane.showInputDialog(component,
68			"Select a font", "Fonts", JOptionPane.QUESTION_MESSAGE,
69				null, bsh.system.fonts, component.font.family);
70		setFont(component, family, -1, -1);
71	}
72	
73	fontMenu.add(new JMenuItem("More...")).addActionListener(this);
74	
75	return fontMenu;
76}