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