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

Last change on this file since 1180 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 2.7 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 {
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 PreferenceDialog prefDlg = new PreferenceDialog();
40 prefDlg.setMinimumSize(new Dimension(400,300));
41 JPanel prefPanel = new JPanel(new GridBagLayout());
42 prefPanel.add(prefDlg, GBC.eol().fill(GBC.BOTH));
43
44 JOptionPane pane = new JOptionPane(prefPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
45 JDialog dlg = pane.createDialog(Main.parent, tr("Preferences"));
46 dlg.setResizable(true);
47 dlg.setMinimumSize(new Dimension(500,400));
48
49// if (dlg.getWidth() > 600)
50// dlg.setSize(600, dlg.getHeight());
51// if (dlg.getHeight() > 600)
52// dlg.setSize(dlg.getWidth(),600);
53
54 int JOSMWidth = Main.parent.getWidth();
55 int JOSMHeight = Main.parent.getHeight();
56
57 if (JOSMWidth > 2000 && JOSMWidth > JOSMHeight * 2)
58 // don't center on horizontal span monitor configurations (yes, can be selfish sometimes)
59 JOSMWidth /= 2;
60
61 int targetWidth = JOSMWidth / 2;
62 if (targetWidth < 600) targetWidth = 600;
63 if (targetWidth > 1200) targetWidth = 1200;
64 int targetHeight = (JOSMHeight * 3) / 4;
65 if (targetHeight < 600) targetHeight = 600;
66 if (targetHeight > 1200) targetHeight = 1200;
67
68 int targetX = Main.parent.getX() + JOSMWidth / 2 - targetWidth / 2;
69 int targetY = Main.parent.getY() + JOSMHeight / 2 - targetHeight / 2;
70
71 dlg.setBounds(targetX, targetY, targetWidth, targetHeight);
72
73 dlg.setVisible(true);
74 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION)
75 prefDlg.ok();
76 }
77}
Note: See TracBrowser for help on using the repository browser.