/bundles/plugins-trunk/XML/sidekick/css/CSSModeToolBar.java

# · Java · 85 lines · 60 code · 16 blank · 9 comment · 0 complexity · 6dba24fcac7822fd5b143335a57688ac MD5 · raw file

  1. package sidekick.css;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import javax.swing.*;
  5. import org.gjt.sp.jedit.jEdit;
  6. import org.gjt.sp.jedit.EditBus;
  7. import org.gjt.sp.jedit.EBComponent;
  8. import org.gjt.sp.jedit.msg.PropertiesChanged;
  9. /**
  10. * This is a toolbar to be added to SideKick. It provides the ability to sort
  11. * by line or name and toggle line numbers on and off without having to open
  12. * the plugin option panes.
  13. */
  14. public class CSSModeToolBar extends JPanel {
  15. private JMenuItem byLine;
  16. private JMenuItem byName;
  17. private JCheckBoxMenuItem toggleLineNumbers;
  18. private EBComponent parent;
  19. public static final int SORT_BY_LINE = 0;
  20. public static final int SORT_BY_NAME = 1;
  21. /**
  22. * @param parent An EBComponent to include with PropertyChanged messages.
  23. * This will be a JavaParser.
  24. */
  25. public CSSModeToolBar( EBComponent parent ) {
  26. this.parent = parent;
  27. installComponents();
  28. installListeners();
  29. }
  30. private void installComponents() {
  31. JMenuBar menuBar = new JMenuBar();
  32. JMenu sortMenu = new JMenu( jEdit.getProperty("options.sidekick.css.sortBy", "Sorting") );
  33. byLine = new JMenuItem( jEdit.getProperty("options.sidekick.css.sortByLine", "Line") );
  34. byName = new JMenuItem( jEdit.getProperty("options.sidekick.css.sortByName", "Name") );
  35. toggleLineNumbers = new JCheckBoxMenuItem( jEdit.getProperty("options.sidekick.css.showLineNums", "Line Numbers") );
  36. toggleLineNumbers.setSelected( jEdit.getBooleanProperty( "sidekick.css.showLineNums", false ) );
  37. add( menuBar );
  38. menuBar.add( sortMenu );
  39. sortMenu.add( byLine );
  40. sortMenu.add( byName );
  41. menuBar.add( toggleLineNumbers );
  42. }
  43. private void installListeners() {
  44. byLine.addActionListener(
  45. new ActionListener() {
  46. public void actionPerformed( ActionEvent ae ) {
  47. jEdit.setIntegerProperty( "sidekick.css.sortBy", SORT_BY_LINE );
  48. EditBus.send( new PropertiesChanged( parent ) );
  49. }
  50. }
  51. );
  52. byName.addActionListener(
  53. new ActionListener() {
  54. public void actionPerformed( ActionEvent ae ) {
  55. jEdit.setIntegerProperty( "sidekick.css.sortBy", SORT_BY_NAME );
  56. EditBus.send( new PropertiesChanged( parent ) );
  57. }
  58. }
  59. );
  60. toggleLineNumbers.addActionListener(
  61. new ActionListener() {
  62. public void actionPerformed( ActionEvent ae ) {
  63. jEdit.setBooleanProperty( "sidekick.css.showLineNums", toggleLineNumbers.isSelected() );
  64. EditBus.send( new PropertiesChanged( parent ) );
  65. }
  66. }
  67. );
  68. }
  69. }