source: josm/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java@ 81

Last change on this file since 81 was 81, checked in by imi, 18 years ago
  • fixed Exception when downloading empty data and auto-open dialogs
  • fixed Exception when download finished before "Please Wait" appeared
  • added new selection modificator options to search dialog
  • added upload of timestamp
File size: 1.8 KB
Line 
1package org.openstreetmap.josm.gui.dialogs;
2
3import java.awt.BorderLayout;
4import java.awt.EventQueue;
5import java.awt.event.ActionEvent;
6import java.awt.event.KeyEvent;
7
8import javax.swing.AbstractButton;
9import javax.swing.BorderFactory;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12import javax.swing.KeyStroke;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.JosmAction;
16
17/**
18 * This class is a toggle dialog that can be turned on and off. It is attached
19 * to a ButtonModel.
20 *
21 * @author imi
22 */
23public class ToggleDialog extends JPanel {
24
25 /**
26 * The action to toggle this dialog.
27 */
28 public JosmAction action;
29
30 /**
31 * Create a new ToggleDialog.
32 * @param title The title of the dialog.
33 * @param prefName Name of the base preference setting string (prefix)
34 * with the final . (e.g.: "layerlist.")
35 */
36 public ToggleDialog(String title, String name, String iconName, String tooltip, String shortCutName, int shortCut, final String prefName) {
37 action = new JosmAction(name, "dialogs/"+iconName, tooltip, "Alt-"+shortCutName, KeyStroke.getKeyStroke(shortCut, KeyEvent.ALT_MASK)){
38 public void actionPerformed(ActionEvent e) {
39 boolean show = !isVisible();
40 if (e != null && e.getSource() instanceof AbstractButton)
41 show = ((AbstractButton)e.getSource()).isSelected();
42 setVisible(show);
43 Main.pref.put(prefName+"visible", show);
44 }
45 };
46 setLayout(new BorderLayout());
47 add(new JLabel(title), BorderLayout.NORTH);
48 setVisible(false);
49 setBorder(BorderFactory.createEtchedBorder());
50 if (Main.pref.getBoolean(prefName+"visible")) {
51 EventQueue.invokeLater(new Runnable(){
52 public void run() {
53 action.putValue("active", true);
54 action.actionPerformed(null);
55 }
56 });
57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.