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