PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 1ms

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

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