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