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

Last change on this file since 1021 was 1021, checked in by stoecker, 16 years ago

close bug #1606 - preferences display now centered

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