PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/bsh/commands/fontMenu.bsh

#
Unknown | 76 lines | 59 code | 17 blank | 0 comment | 0 complexity | 13ef52e74ffe751799c977167df3ddc5 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. */
  8. fontMenu(component) {
  9. if ( bsh.system.desktop == void ) {
  10. print("fontMenu() only works with the bsh desktop...");
  11. return;
  12. }
  13. JMenu fontMenu = new JMenu("Font");
  14. sizeListener() {
  15. actionPerformed(ae) {
  16. setFont(component, Integer.parseInt(ae.actionCommand));
  17. }
  18. return this;
  19. }
  20. this.sizeListener=sizeListener();
  21. this.boldMenuItem = new JCheckBoxMenuItem("Bold");
  22. this.italicMenuItem = new JCheckBoxMenuItem("Italic");
  23. styleListener() {
  24. actionPerformed(ae) {
  25. setFont(component, null, ((boldMenuItem.selected) ? Font.BOLD : 0) |
  26. ((italicMenuItem.selected) ? Font.ITALIC : 0), -1);
  27. }
  28. return this;
  29. }
  30. this.styleListener=styleListener();
  31. familyListener() {
  32. actionPerformed(ae) {
  33. setFont(component, ae.actionCommand, -1, -1);
  34. }
  35. return this;
  36. }
  37. this.familyListener=familyListener();
  38. JMenu sizeMenu = new JMenu("Size");
  39. for(int i:new int[] {9,10,12,14,16,20,24})
  40. sizeMenu.add(new JMenuItem(""+i)).addActionListener(sizeListener);
  41. fontMenu.add(sizeMenu);
  42. JMenu styleMenu = new JMenu("Style");
  43. //styleMenu.add(new JMenuItem("Plain")).addActionListener(this);
  44. styleMenu.add(boldMenuItem).addActionListener(styleListener);
  45. styleMenu.add(italicMenuItem).addActionListener(styleListener);
  46. fontMenu.add(styleMenu);
  47. fontMenu.addSeparator();
  48. for(var s:new String[] {"SansSerif","Monospaced","Serif","LucidaSans"})
  49. fontMenu.add(this.mi=new JMenuItem(s)).addActionListener(familyListener);
  50. fontMenu.addSeparator();
  51. actionPerformed(ae) {
  52. String family = (String)JOptionPane.showInputDialog(component,
  53. "Select a font", "Fonts", JOptionPane.QUESTION_MESSAGE,
  54. null, bsh.system.fonts, component.font.family);
  55. setFont(component, family, -1, -1);
  56. }
  57. fontMenu.add(new JMenuItem("More...")).addActionListener(this);
  58. return fontMenu;
  59. }