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

Last change on this file since 2064 was 1742, checked in by stoecker, 17 years ago

fixed #2849 - patch by jttt - fix memory leak

  • Property svn:eol-style set to native
File size: 2.8 KB
RevLine 
[298]1// License: GPL. Copyright 2007 by Immanuel Scholz and others
[626]2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
[1042]6import java.awt.Dimension;
[626]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;
[1084]18import org.openstreetmap.josm.tools.Shortcut;
[626]19
20/**
21 * Open the Preferences dialog.
22 *
23 * @author imi
24 */
[1647]25public class PreferencesAction extends JosmAction implements Runnable {
[626]26
[1169]27 /**
28 * Create the preference action with "&Preferences" as label.
29 */
30 public PreferencesAction() {
[1212]31 super(tr("Preferences..."), "preference", tr("Open a preferences page for global settings."),
[1169]32 Shortcut.registerShortcut("system:preferences", tr("Preferences"), KeyEvent.VK_F12, Shortcut.GROUP_DIRECT), true);
33 }
[626]34
[1169]35 /**
36 * Launch the preferences dialog.
37 */
38 public void actionPerformed(ActionEvent e) {
[1733]39 run();
[1647]40 }
41
42 public void run() {
[1169]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));
[626]47
[1169]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));
[626]52
[1169]53// if (dlg.getWidth() > 600)
54// dlg.setSize(600, dlg.getHeight());
55// if (dlg.getHeight() > 600)
56// dlg.setSize(dlg.getWidth(),600);
[626]57
[1169]58 int JOSMWidth = Main.parent.getWidth();
59 int JOSMHeight = Main.parent.getHeight();
[1021]60
[1169]61 if (JOSMWidth > 2000 && JOSMWidth > JOSMHeight * 2)
62 // don't center on horizontal span monitor configurations (yes, can be selfish sometimes)
63 JOSMWidth /= 2;
[1021]64
[1169]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;
[1021]71
[1169]72 int targetX = Main.parent.getX() + JOSMWidth / 2 - targetWidth / 2;
73 int targetY = Main.parent.getY() + JOSMHeight / 2 - targetHeight / 2;
[1021]74
[1169]75 dlg.setBounds(targetX, targetY, targetWidth, targetHeight);
[1021]76
[1733]77 dlg.setModal(true);
[1169]78 dlg.setVisible(true);
79 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION)
80 prefDlg.ok();
[1742]81 dlg.dispose();
[1169]82 }
[626]83}
Note: See TracBrowser for help on using the repository browser.