| 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
|---|
| 2 | package org.openstreetmap.josm.tools;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.Container;
|
|---|
| 7 | import java.awt.GridBagLayout;
|
|---|
| 8 |
|
|---|
| 9 | import javax.swing.JCheckBox;
|
|---|
| 10 | import javax.swing.JLabel;
|
|---|
| 11 | import javax.swing.JOptionPane;
|
|---|
| 12 | import javax.swing.JPanel;
|
|---|
| 13 |
|
|---|
| 14 | import org.openstreetmap.josm.Main;
|
|---|
| 15 |
|
|---|
| 16 | public class DontShowAgainInfo {
|
|---|
| 17 |
|
|---|
| 18 | public static boolean show(String prefKey, String msg) {
|
|---|
| 19 | return show(prefKey, new JLabel(msg), true, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION);
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | public static boolean show(String prefKey, String msg, Boolean state) {
|
|---|
| 23 | return show(prefKey, new JLabel(msg), state, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION);
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | public static boolean show(String prefKey, Container msg) {
|
|---|
| 27 | return show(prefKey, msg, true, JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_OPTION);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | public static boolean show(String prefKey, Container msg, Boolean state, int options, int true_option) {
|
|---|
| 31 | if (!Main.pref.getBoolean("message."+prefKey)) {
|
|---|
| 32 | JCheckBox dontshowagain = new JCheckBox(tr("Do not show again"));
|
|---|
| 33 | dontshowagain.setSelected(Main.pref.getBoolean("message."+prefKey, state));
|
|---|
| 34 | JPanel all = new JPanel(new GridBagLayout());
|
|---|
| 35 | all.add(msg, GBC.eop());
|
|---|
| 36 | all.add(dontshowagain, GBC.eol());
|
|---|
| 37 | int answer = JOptionPane.showConfirmDialog(Main.parent, all, tr("Information"), options);
|
|---|
| 38 | if (answer != true_option)
|
|---|
| 39 | return false;
|
|---|
| 40 | Main.pref.put("message."+prefKey, dontshowagain.isSelected());
|
|---|
| 41 | }
|
|---|
| 42 | return true;
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|