PageRenderTime 152ms CodeModel.GetById 109ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/InfoViewer/infoviewer/InfoViewerOptionPane2.java

#
Java | 238 lines | 166 code | 35 blank | 37 comment | 3 complexity | 98651f538b0298a47170e45bfcf664f0 MD5 | raw file
  1/*
  2 * InfoViewerOptionPane2.java - second InfoViewer options panel
  3 * Copyright (C) 2001 Dirk Moebius
  4 *
  5 * :tabSize=4:indentSize=4:noTabs=true:maxLineLen=0:
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License
  9 * as published by the Free Software Foundation; either version 2
 10 * of the License, or any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20 */
 21
 22package infoviewer;
 23
 24import java.awt.GridLayout;
 25import java.awt.event.ActionEvent;
 26import java.awt.event.ActionListener;
 27import java.util.Hashtable;
 28
 29import javax.swing.Box;
 30import javax.swing.JCheckBox;
 31import javax.swing.JLabel;
 32import javax.swing.JPanel;
 33import javax.swing.JSlider;
 34import javax.swing.JTextField;
 35
 36import org.gjt.sp.jedit.AbstractOptionPane;
 37import org.gjt.sp.jedit.jEdit;
 38
 39
 40public class InfoViewerOptionPane2 extends AbstractOptionPane implements ActionListener {
 41
 42	private static final long serialVersionUID = 8785488835232627553L;
 43	public InfoViewerOptionPane2() {
 44        super("internalBrowser");
 45    }
 46
 47
 48    public void _init() {
 49        // "Appearance"
 50        addSeparator("options.infoviewer.appearance.label");
 51
 52        // "Show ..."
 53        showFloatingMenu = new JCheckBox(
 54            jEdit.getProperty("options.infoviewer.appearance.floating.showMenu"),
 55            jEdit.getBooleanProperty("infoviewer.appearance.floating.showMenu"));
 56        showFloatingToolbar = new JCheckBox(
 57            jEdit.getProperty("options.infoviewer.appearance.floating.showToolbar"),
 58            jEdit.getBooleanProperty("infoviewer.appearance.floating.showToolbar"));
 59        showFloatingAddressbar = new JCheckBox(
 60            jEdit.getProperty("options.infoviewer.appearance.floating.showAddressbar"),
 61            jEdit.getBooleanProperty("infoviewer.appearance.floating.showAddressbar"));
 62        showFloatingStatusbar = new JCheckBox(
 63            jEdit.getProperty("options.infoviewer.appearance.floating.showStatusbar"),
 64            jEdit.getBooleanProperty("infoviewer.appearance.floating.showStatusbar"));
 65
 66        showDockedMenu = new JCheckBox(
 67            jEdit.getProperty("options.infoviewer.appearance.docked.showMenu"),
 68            jEdit.getBooleanProperty("infoviewer.appearance.docked.showMenu"));
 69        showDockedToolbar = new JCheckBox(
 70            jEdit.getProperty("options.infoviewer.appearance.docked.showToolbar"),
 71            jEdit.getBooleanProperty("infoviewer.appearance.docked.showToolbar"));
 72        showDockedAddressbar = new JCheckBox(
 73            jEdit.getProperty("options.infoviewer.appearance.docked.showAddressbar"),
 74            jEdit.getBooleanProperty("infoviewer.appearance.docked.showAddressbar"));
 75        showDockedStatusbar = new JCheckBox(
 76            jEdit.getProperty("options.infoviewer.appearance.docked.showStatusbar"),
 77            jEdit.getBooleanProperty("infoviewer.appearance.docked.showStatusbar"));
 78
 79        JPanel appearance = new JPanel(new GridLayout(0,2));
 80        appearance.add(new JLabel(jEdit.getProperty("options.infoviewer.appearance.floating.label")));
 81        appearance.add(new JLabel(jEdit.getProperty("options.infoviewer.appearance.docked.label")));
 82        appearance.add(showFloatingMenu);
 83        appearance.add(showDockedMenu);
 84        appearance.add(showFloatingToolbar);
 85        appearance.add(showDockedToolbar);
 86        appearance.add(showFloatingAddressbar);
 87        appearance.add(showDockedAddressbar);
 88        appearance.add(showFloatingStatusbar);
 89        appearance.add(showDockedStatusbar);
 90        addComponent(appearance);
 91
 92        // "Homepage:"
 93        
 94        restorePreviousPage = new JCheckBox(
 95            jEdit.getProperty("options.infoviewer.restorePreviousPage"),
 96            jEdit.getBooleanProperty("infoviewer.restorePreviousPage"));
 97        restorePreviousPage.addActionListener(this);
 98        
 99        tHome = new JTextField(jEdit.getProperty("infoviewer.homepage"), 30);
100        Box bHome = Box.createHorizontalBox();
101        bHome.add(new JLabel(jEdit.getProperty("options.infoviewer.homepage")));
102        bHome.add(tHome);
103        
104        addComponent(Box.createVerticalStrut(10));
105        addComponent(bHome);
106        addComponent(restorePreviousPage);
107
108        // "Auto-Update"
109        addComponent(Box.createVerticalStrut(15));
110        addSeparator("options.infoviewer.autoupdate.label");
111
112        autoUpdate = new JCheckBox(
113            jEdit.getProperty("options.infoviewer.autoupdate"),
114            jEdit.getBooleanProperty("infoviewer.autoupdate"));
115        autoUpdate.addActionListener(this);
116
117        autoUpdateOnSwitch = new JCheckBox(
118            jEdit.getProperty("options.infoviewer.autoupdate.onSwitch"),
119            jEdit.getBooleanProperty("infoviewer.autoupdate.onSwitch"));
120
121        autoUpdateOnSave = new JCheckBox(
122            jEdit.getProperty("options.infoviewer.autoupdate.onSave"),
123            jEdit.getBooleanProperty("infoviewer.autoupdate.onSave"));
124
125        autoUpdateOnChange = new JCheckBox(
126            jEdit.getProperty("options.infoviewer.autoupdate.onChange"),
127            jEdit.getBooleanProperty("infoviewer.autoupdate.onChange"));
128        autoUpdateOnChange.addActionListener(this);
129
130        autoUpdatePeriodically = new JCheckBox(
131            jEdit.getProperty("options.infoviewer.autoupdate.periodically"),
132            jEdit.getBooleanProperty("infoviewer.autoupdate.periodically"));
133        autoUpdatePeriodically.addActionListener(this);
134
135        int delayOnChange;
136        try { delayOnChange = Integer.parseInt(jEdit.getProperty("infoviewer.autoupdate.onChange.delay")); }
137        catch(NumberFormatException nf) { delayOnChange = 3000; }
138        delayOnChange = Math.min(Math.max(delayOnChange, 1000), 5000);
139
140        autoUpdateDelayOnChange = new JSlider(1000, 5000, delayOnChange);
141        Hashtable labelTable = new Hashtable();
142        for(int i = 1000; i <= 5000; i += 1000)
143            labelTable.put(new Integer(i), new JLabel(String.valueOf((double)i / 1000.0)));
144        autoUpdateDelayOnChange.setLabelTable(labelTable);
145        autoUpdateDelayOnChange.setPaintLabels(true);
146        autoUpdateDelayOnChange.setMajorTickSpacing(1000);
147        autoUpdateDelayOnChange.setMinorTickSpacing(100);
148        autoUpdateDelayOnChange.setPaintTicks(true);
149        autoUpdateDelayOnChange.setSnapToTicks(true);
150
151        int delayPeriodically;
152        try { delayPeriodically = Integer.parseInt(jEdit.getProperty("infoviewer.autoupdate.periodically.delay")) / 1000; }
153        catch(NumberFormatException nf) { delayPeriodically = 20; }
154        delayPeriodically = Math.min(Math.max(delayPeriodically, 10), 300);
155
156        autoUpdateDelayPeriodically = new JSlider(10, 300, delayPeriodically);
157        Hashtable labelTable2 = new Hashtable();
158        labelTable2.put(new Integer(10), new JLabel("10"));
159        for(int i = 50; i <= 300; i += 50)
160            labelTable2.put(new Integer(i), new JLabel(String.valueOf(i)));
161        autoUpdateDelayPeriodically.setLabelTable(labelTable2);
162        autoUpdateDelayPeriodically.setPaintLabels(true);
163        autoUpdateDelayPeriodically.setMinorTickSpacing(10);
164        autoUpdateDelayPeriodically.setPaintTicks(true);
165
166        addComponent(autoUpdate);
167        addComponent(autoUpdateOnSwitch);
168        addComponent(autoUpdateOnSave);
169        //addComponent(autoUpdateOnChange);    not yet...
170        addComponent(autoUpdatePeriodically);
171        //addComponent(jEdit.getProperty("options.infoviewer.autoupdate.onChange.delay"), autoUpdateDelayOnChange);
172        addComponent(jEdit.getProperty("options.infoviewer.autoupdate.periodically.delay"), autoUpdateDelayPeriodically);
173
174        // init:
175        actionPerformed(null);
176    }
177
178
179    /**
180     * Called when the options dialog's `OK' button is pressed.
181     * This saves any properties saved in this option pane.
182     */
183    public void _save()
184    {
185        jEdit.setProperty("infoviewer.homepage", tHome.getText());
186        jEdit.setBooleanProperty("infoviewer.appearance.floating.showMenu", showFloatingMenu.isSelected());
187        jEdit.setBooleanProperty("infoviewer.appearance.floating.showToolbar", showFloatingToolbar.isSelected());
188        jEdit.setBooleanProperty("infoviewer.appearance.floating.showAddressbar", showFloatingAddressbar.isSelected());
189        jEdit.setBooleanProperty("infoviewer.appearance.floating.showStatusbar", showFloatingStatusbar.isSelected());
190        jEdit.setBooleanProperty("infoviewer.appearance.docked.showMenu", showDockedMenu.isSelected());
191        jEdit.setBooleanProperty("infoviewer.appearance.docked.showToolbar", showDockedToolbar.isSelected());
192        jEdit.setBooleanProperty("infoviewer.appearance.docked.showAddressbar", showDockedAddressbar.isSelected());
193        jEdit.setBooleanProperty("infoviewer.appearance.docked.showStatusbar", showDockedStatusbar.isSelected());
194        jEdit.setBooleanProperty("infoviewer.autoupdate", autoUpdate.isSelected());
195        jEdit.setBooleanProperty("infoviewer.autoupdate.onSwitch", autoUpdateOnSwitch.isSelected());
196        jEdit.setBooleanProperty("infoviewer.restorePreviousPage", restorePreviousPage.isSelected());
197        jEdit.setBooleanProperty("infoviewer.autoupdate.onSave", autoUpdateOnSave.isSelected());
198        //jEdit.setBooleanProperty("infoviewer.autoupdate.onChange", autoUpdateOnChange.isSelected());
199        jEdit.setBooleanProperty("infoviewer.autoupdate.periodically", autoUpdatePeriodically.isSelected());
200        jEdit.setProperty("infoviewer.autoupdate.onChange.delay", String.valueOf(autoUpdateDelayOnChange.getValue()));
201        jEdit.setProperty("infoviewer.autoupdate.periodically.delay", String.valueOf(autoUpdateDelayPeriodically.getValue() * 1000));
202    }
203
204
205    /**
206     * Called when one of the radio buttons is clicked.
207     */
208    public void actionPerformed(ActionEvent e)
209    {
210    	tHome.setEnabled(!restorePreviousPage.isSelected());
211        autoUpdateOnSwitch.setEnabled(autoUpdate.isSelected());
212        autoUpdateOnSave.setEnabled(autoUpdate.isSelected());
213        //autoUpdateOnChange.setEnabled(autoUpdate.isSelected());
214        autoUpdatePeriodically.setEnabled(autoUpdate.isSelected());
215        //autoUpdateDelayOnChange.setEnabled(autoUpdate.isSelected() && autoUpdateOnChange.isSelected());
216        autoUpdateDelayPeriodically.setEnabled(autoUpdate.isSelected() && autoUpdatePeriodically.isSelected());
217    }
218
219
220    private JTextField tHome;
221    private JCheckBox showFloatingMenu;
222    private JCheckBox showFloatingToolbar;
223    private JCheckBox showFloatingAddressbar;
224    private JCheckBox showFloatingStatusbar;
225    private JCheckBox showDockedMenu;
226    private JCheckBox showDockedToolbar;
227    private JCheckBox showDockedAddressbar;
228    private JCheckBox showDockedStatusbar;
229    private JCheckBox autoUpdate;
230    private JCheckBox restorePreviousPage;
231    private JCheckBox autoUpdateOnSwitch;
232    private JCheckBox autoUpdateOnSave;
233    private JCheckBox autoUpdateOnChange;
234    private JCheckBox autoUpdatePeriodically;
235    private JSlider autoUpdateDelayOnChange;
236    private JSlider autoUpdateDelayPeriodically;
237
238}