source: josm/trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java@ 2198

Last change on this file since 2198 was 1742, checked in by stoecker, 15 years ago

fixed #2849 - patch by jttt - fix memory leak

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10
11import javax.swing.JDialog;
12import javax.swing.JOptionPane;
13import javax.swing.JPanel;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
17import org.openstreetmap.josm.tools.GBC;
18import org.openstreetmap.josm.tools.Shortcut;
19
20/**
21 * Open the Preferences dialog.
22 *
23 * @author imi
24 */
25public class PreferencesAction extends JosmAction implements Runnable {
26
27 /**
28 * Create the preference action with "&Preferences" as label.
29 */
30 public PreferencesAction() {
31 super(tr("Preferences..."), "preference", tr("Open a preferences page for global settings."),
32 Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.GROUP_DIRECT), true);
33 }
34
35 /**
36 * Launch the preferences dialog.
37 */
38 public void actionPerformed(ActionEvent e) {
39 run();
40 }
41
42 public void run() {
43 PreferenceDialog prefDlg = new PreferenceDialog();
44 prefDlg.setMinimumSize(new Dimension(400,300));
45 JPanel prefPanel = new JPanel(new GridBagLayout());
46 prefPanel.add(prefDlg, GBC.eol().fill(GBC.BOTH));
47
48 JOptionPane pane = new JOptionPane(prefPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
49 JDialog dlg = pane.createDialog(Main.parent, tr("Preferences"));
50 dlg.setResizable(true);
51 dlg.setMinimumSize(new Dimension(500,400));
52
53// if (dlg.getWidth() > 600)
54// dlg.setSize(600, dlg.getHeight());
55// if (dlg.getHeight() > 600)
56// dlg.setSize(dlg.getWidth(),600);
57
58 int JOSMWidth = Main.parent.getWidth();
59 int JOSMHeight = Main.parent.getHeight();
60
61 if (JOSMWidth > 2000 && JOSMWidth > JOSMHeight * 2)
62 // don't center on horizontal span monitor configurations (yes, can be selfish sometimes)
63 JOSMWidth /= 2;
64
65 int targetWidth = JOSMWidth / 2;
66 if (targetWidth < 600) targetWidth = 600;
67 if (targetWidth > 1200) targetWidth = 1200;
68 int targetHeight = (JOSMHeight * 3) / 4;
69 if (targetHeight < 600) targetHeight = 600;
70 if (targetHeight > 1200) targetHeight = 1200;
71
72 int targetX = Main.parent.getX() + JOSMWidth / 2 - targetWidth / 2;
73 int targetY = Main.parent.getY() + JOSMHeight / 2 - targetHeight / 2;
74
75 dlg.setBounds(targetX, targetY, targetWidth, targetHeight);
76
77 dlg.setModal(true);
78 dlg.setVisible(true);
79 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION)
80 prefDlg.ok();
81 dlg.dispose();
82 }
83}
Note: See TracBrowser for help on using the repository browser.