    001    /*
    002     * SideKickOptionPane.java - SideKick options panel
    003     * :tabSize=8:indentSize=8:noTabs=false:
    004     * :folding=explicit:collapseFolds=1:
    005     *
    006     * Copyright (C) 2001, 2003 Slava Pestov
    007     *
    008     * This program is free software; you can redistribute it and/or
    009     * modify it under the terms of the GNU General Public License
    010     * as published by the Free Software Foundation; either version 2
    011     * of the License, or any later version.
    012     *
    013     * This program is distributed in the hope that it will be useful,
    014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
    015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    016     * GNU General Public License for more details.
    017     *
    018     * You should have received a copy of the GNU General Public License
    019     * along with this program; if not, write to the Free Software
    020     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    021     */
    022
    023    package sidekick;
    024
    025    //{{{ Imports
    026    import javax.swing.*;
    027    import javax.swing.border.TitledBorder;
    028
    029    import java.awt.event.*;
    030    import java.awt.*;
    031    import java.util.Hashtable;
    032    import org.gjt.sp.jedit.gui.*;
    033    import org.gjt.sp.jedit.*;
    034    //}}}
    035
    036    public class SideKickOptionPane extends AbstractOptionPane
    037    {
    038            //{{{ GeneralOptionPane constructor
    039            public SideKickOptionPane()
    040            {
    041                    super("sidekick");
    042            } //}}}
    043
    044            //{{{ _init() method
    045            protected void _init()
    046            {
    047            //      addSeparator("options.sidekick.general.label");
    048
    049                    addComponent(showToolTips = new JCheckBox(jEdit.getProperty(
    050                            "options.sidekick.showToolTips.label")));
    051                    showToolTips.setSelected(jEdit.getBooleanProperty(
    052                            "options.sidekick.showToolTips"));
    053                    addComponent(showStatusWindow = new JCheckBox(jEdit.getProperty(
    054                            "options.sidekick.showStatusWindow.label")));
    055                    showStatusWindow.setSelected(jEdit.getBooleanProperty(
    056                            "options.sidekick.showStatusWindow"));
    057                    addComponent(treeFollowsCaret = new JCheckBox(jEdit.getProperty(
    058                            "options.sidekick.tree-follows-caret")));
    059                    treeFollowsCaret.setSelected(jEdit.getBooleanProperty(
    060                            "sidekick-tree.follows-caret"));
    061                    treeFollowsCaret.addActionListener(new ActionHandler());
    062
    063                    addComponent(jEdit.getProperty("options.sidekick.auto-expand-tree-depth"),
    064                            autoExpandTreeDepth = new JComboBox());
    065                    autoExpandTreeDepth.addActionListener(new ActionHandler());
    066                    autoExpandTreeDepth.addItem("All");
    067                    for (int i = 0; i <= 10; i++)
    068                            autoExpandTreeDepth.addItem(String.valueOf(i));
    069                    String depth = String.valueOf(jEdit.getIntegerProperty(
    070                            "sidekick-tree.auto-expand-tree-depth", 1));
    071                    autoExpandTreeDepth.setSelectedItem(depth);
    072
    073
    074
    075                    JPanel parsingSettings = new JPanel();
    076                    parsingSettings.setBorder(new TitledBorder("Auto parsing Settings"));
    077                    parsingSettings.setLayout(new BorderLayout());
    078                    JPanel buttonPanel = new JPanel();
    079                    buttonPanel.setLayout(new FlowLayout());
    080                    parsingSettings.add(buttonPanel, BorderLayout.NORTH);
    081
    082                    buttonPanel.add(bufferChangeParse = new JCheckBox(jEdit.getProperty(
    083                            "options.sidekick.buffer-change-parse")));
    084                    bufferChangeParse.setSelected(jEdit.getBooleanProperty(
    085                            "buffer.sidekick.buffer-change-parse"));
    086                    bufferChangeParse.addActionListener(new ActionHandler());
    087
    088                    buttonPanel.add(bufferSaveParse = new JCheckBox(jEdit.getProperty(
    089                            "options.sidekick.buffer-save-parse")));
    090                    bufferSaveParse.setSelected(jEdit.getBooleanProperty(
    091                            "buffer.sidekick.buffer-save-parse"));
    092                    bufferSaveParse.addActionListener(new ActionHandler());
    093
    094                    buttonPanel.add(keystrokeParse = new JCheckBox(jEdit.getProperty(
    095                            "options.sidekick.keystroke-parse")));
    096                    keystrokeParse.setSelected(jEdit.getBooleanProperty(
    097                            "buffer.sidekick.keystroke-parse"));
    098                    keystrokeParse.addActionListener(new ActionHandler());
    099
    100                    int autoParseDelayValue;
    101                    try
    102                    {
    103                            autoParseDelayValue = Integer.parseInt(jEdit.getProperty("sidekick.auto-parse-delay"));
    104                    }
    105                    catch(NumberFormatException nf)
    106                    {
    107                            autoParseDelayValue = 1500;
    108                    }
    109
    110                    parsingSettings.add(new JLabel(jEdit.getProperty("options.sidekick.auto-parse-delay")), BorderLayout.CENTER);
    111                    parsingSettings.add(autoParseDelay = new JSlider(200,3000,autoParseDelayValue), BorderLayout.SOUTH);
    112                    /*addComponent(autoParseDelay = new JSlider(200,3000,autoParseDelayValue),
    113                            GridBagConstraints.BOTH); */
    114                    addComponent(parsingSettings);
    115                    Hashtable labelTable = new Hashtable();
    116                    for(int i = 500; i <= 3000; i += 500)
    117                    {
    118                            labelTable.put(new Integer(i),new JLabel(
    119                                    String.valueOf((double)i / 1000.0)));
    120                    }
    121                    autoParseDelay.setLabelTable(labelTable);
    122                    autoParseDelay.setPaintLabels(true);
    123                    autoParseDelay.setMajorTickSpacing(500);
    124                    autoParseDelay.setPaintTicks(true);
    125
    126                    autoParseDelay.setEnabled(keystrokeParse.isSelected());
    127
    128
    129                    JPanel codeCompletionsPanel = new JPanel();
    130                    codeCompletionsPanel.setBorder(new TitledBorder(jEdit.getProperty(
    131                            "options.sidekick.code-completion.label")));
    132                    codeCompletionsPanel.setLayout(new BorderLayout());
    133
    134                    // addSeparator("options.sidekick.code-completion.label");
    135                    JPanel completionsCheckboxes = new JPanel();
    136                    completionsCheckboxes.setLayout(new FlowLayout());
    137                    completionsCheckboxes.add(completeInstantToggle = new JCheckBox(jEdit.getProperty(
    138                            "options.sidekick.complete-instant.toggle")));
    139                    completeInstantToggle.setSelected(jEdit.getBooleanProperty("sidekick.complete-instant.toggle"));
    140                    completeInstantToggle.addActionListener(new ActionHandler());
    141
    142                    completionsCheckboxes.add(completeDelayToggle = new JCheckBox(jEdit.getProperty(
    143                            "options.sidekick.complete-delay.toggle")));
    144                    completeDelayToggle.setSelected(jEdit.getBooleanProperty("sidekick.complete-delay.toggle"));
    145                    completeDelayToggle.addActionListener(new ActionHandler());
    146                    codeCompletionsPanel.add(completionsCheckboxes, BorderLayout.NORTH);
    147
    148                    int completeDelayValue = jEdit.getIntegerProperty("sidekick.complete-delay",500);
    149
    150                    codeCompletionsPanel.add(new JLabel(jEdit.getProperty("options.sidekick.complete-delay")), BorderLayout.CENTER);
    151                    codeCompletionsPanel.add(completeDelay = new JSlider(0,1500,completeDelayValue), BorderLayout.SOUTH);
    152                    addComponent(codeCompletionsPanel);
    153
    154                    labelTable = new Hashtable();
    155                    for(int i = 0; i <= 1500; i += 250)
    156                    {
    157                            labelTable.put(new Integer(i),new JLabel(
    158                                    String.valueOf((double)i / 1000.0)));
    159                    }
    160                    completeDelay.setLabelTable(labelTable);
    161                    completeDelay.setPaintLabels(true);
    162                    completeDelay.setMajorTickSpacing(250);
    163                    completeDelay.setPaintTicks(true);
    164
    165                    completeDelay.setEnabled(completeDelayToggle.isSelected());
    166            } //}}}
    167
    168            //{{{ _save() method
    169            protected void _save()
    170            {
    171                    jEdit.setBooleanProperty("buffer.sidekick.buffer-change-parse",
    172                            bufferChangeParse.isSelected());
    173                    jEdit.setBooleanProperty("buffer.sidekick.buffer-save-parse",
    174                            bufferSaveParse.isSelected());
    175                    jEdit.setBooleanProperty("buffer.sidekick.keystroke-parse",
    176                            keystrokeParse.isSelected());
    177                    jEdit.setProperty("sidekick.auto-parse-delay",String.valueOf(
    178                            autoParseDelay.getValue()));
    179                    jEdit.setBooleanProperty("sidekick-tree.follows-caret",
    180                            treeFollowsCaret.isSelected());
    181                    jEdit.setBooleanProperty("options.sidekick.showToolTips", showToolTips.isSelected());
    182                    jEdit.setBooleanProperty("options.sidekick.showStatusWindow", showStatusWindow.isSelected());
    183                    int depth = 0;
    184                    String value = (String)autoExpandTreeDepth.getSelectedItem();
    185                    depth = value.equals("All") ? -1 : Integer.parseInt(value);
    186                    jEdit.setIntegerProperty("sidekick-tree.auto-expand-tree-depth",
    187                            depth);
    188                    jEdit.setBooleanProperty("sidekick.complete-instant.toggle",
    189                            completeInstantToggle.isSelected());
    190                    jEdit.setBooleanProperty("sidekick.complete-delay.toggle",
    191                            completeDelayToggle.isSelected());
    192                    jEdit.setIntegerProperty("sidekick.complete-delay",
    193                            completeDelay.getValue());
    194            } //}}}
    195
    196            //{{{ Private members
    197            private JCheckBox bufferChangeParse;
    198            private JCheckBox bufferSaveParse;
    199            private JCheckBox keystrokeParse;
    200            private JSlider autoParseDelay;
    201            private JCheckBox treeFollowsCaret;
    202            private JComboBox autoExpandTreeDepth;
    203            private JCheckBox completeInstantToggle;
    204            private JCheckBox completeDelayToggle;
    205            private JSlider completeDelay;
    206            private JCheckBox showToolTips;
    207            private JCheckBox showStatusWindow;
    208            //}}}
    209
    210            //{{{ ActionHandler class
    211            class ActionHandler implements ActionListener
    212            {
    213                    public void actionPerformed(ActionEvent evt)
    214                    {
    215                            Object source = evt.getSource();
    216                            if(source == keystrokeParse)
    217                            {
    218                                    autoParseDelay.setEnabled(keystrokeParse.isSelected());
    219                                    if(keystrokeParse.isSelected())
    220                                            bufferChangeParse.setSelected(true);
    221                                            bufferSaveParse.setSelected(true);
    222                            }
    223                            else if(source == completeDelayToggle)
    224                            {
    225                                    completeDelay.setEnabled(completeDelayToggle.isSelected());
    226                            }
    227                    }
    228            } //}}}
    229    }