/** * Creates a font menu for use with the workspace and workspace editors * * @return a font menu * * @author Daniel Leuck */ fontMenu(component) { if ( bsh.system.desktop == void ) { print("fontMenu() only works with the bsh desktop..."); return; } JMenu fontMenu = new JMenu("Font"); sizeListener() { actionPerformed(ae) { setFont(component, Integer.parseInt(ae.actionCommand)); } return this; } this.sizeListener=sizeListener(); this.boldMenuItem = new JCheckBoxMenuItem("Bold"); this.italicMenuItem = new JCheckBoxMenuItem("Italic"); styleListener() { actionPerformed(ae) { setFont(component, null, ((boldMenuItem.selected) ? Font.BOLD : 0) | ((italicMenuItem.selected) ? Font.ITALIC : 0), -1); } return this; } this.styleListener=styleListener(); familyListener() { actionPerformed(ae) { setFont(component, ae.actionCommand, -1, -1); } return this; } this.familyListener=familyListener(); JMenu sizeMenu = new JMenu("Size"); for(int i:new int[] {9,10,12,14,16,20,24}) sizeMenu.add(new JMenuItem(""+i)).addActionListener(sizeListener); fontMenu.add(sizeMenu); JMenu styleMenu = new JMenu("Style"); //styleMenu.add(new JMenuItem("Plain")).addActionListener(this); styleMenu.add(boldMenuItem).addActionListener(styleListener); styleMenu.add(italicMenuItem).addActionListener(styleListener); fontMenu.add(styleMenu); fontMenu.addSeparator(); for(var s:new String[] {"SansSerif","Monospaced","Serif","LucidaSans"}) fontMenu.add(this.mi=new JMenuItem(s)).addActionListener(familyListener); fontMenu.addSeparator(); actionPerformed(ae) { if ( bsh.system.fonts != void ) { String family = (String)JOptionPane.showInputDialog(component, "Select a font", "Fonts", JOptionPane.QUESTION_MESSAGE, null, bsh.system.fonts, component.font.family); setFont(component, family, -1, -1); } } fontMenu.add(new JMenuItem("More...")).addActionListener(this); return fontMenu; }