| 1 |
package net.oni2.aeinstaller.gui.settings; |
| 2 |
|
| 3 |
import java.awt.event.ActionEvent; |
| 4 |
import java.awt.event.KeyEvent; |
| 5 |
import java.util.ResourceBundle; |
| 6 |
|
| 7 |
import javax.swing.AbstractAction; |
| 8 |
import javax.swing.JCheckBox; |
| 9 |
import javax.swing.JComboBox; |
| 10 |
import javax.swing.JComponent; |
| 11 |
import javax.swing.JDialog; |
| 12 |
import javax.swing.JOptionPane; |
| 13 |
import javax.swing.KeyStroke; |
| 14 |
import javax.swing.UIManager; |
| 15 |
|
| 16 |
import net.oni2.SettingsManager; |
| 17 |
|
| 18 |
import org.javabuilders.BuildResult; |
| 19 |
import org.javabuilders.swing.SwingJavaBuilder; |
| 20 |
|
| 21 |
/** |
| 22 |
* @author Christian Illy |
| 23 |
*/ |
| 24 |
public class SettingsDialog extends JDialog { |
| 25 |
private static final long serialVersionUID = -5719515325671846620L; |
| 26 |
|
| 27 |
private ResourceBundle bundle = ResourceBundle |
| 28 |
.getBundle("net.oni2.aeinstaller.localization." |
| 29 |
+ getClass().getSimpleName()); |
| 30 |
@SuppressWarnings("unused") |
| 31 |
private BuildResult result = SwingJavaBuilder.build(this, bundle); |
| 32 |
|
| 33 |
private JComboBox cmbLaF; |
| 34 |
private LaFComboModel laFModel; |
| 35 |
|
| 36 |
private JCheckBox chkNotifyOnStart; |
| 37 |
private JCheckBox chkNotifyDepsAfterInstall; |
| 38 |
private JCheckBox chkCopyIntro; |
| 39 |
private JCheckBox chkCopyOutro; |
| 40 |
|
| 41 |
/** |
| 42 |
* Open the settings |
| 43 |
*/ |
| 44 |
public SettingsDialog() { |
| 45 |
setResizable(false); |
| 46 |
|
| 47 |
AbstractAction closeAction = new AbstractAction() { |
| 48 |
|
| 49 |
private static final long serialVersionUID = 1L; |
| 50 |
|
| 51 |
public void actionPerformed(ActionEvent arg0) { |
| 52 |
dispose(); |
| 53 |
} |
| 54 |
}; |
| 55 |
KeyStroke ksCtrlW = KeyStroke |
| 56 |
.getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK); |
| 57 |
getRootPane() |
| 58 |
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) |
| 59 |
.put(ksCtrlW, "close"); |
| 60 |
getRootPane().getActionMap().put("close", closeAction); |
| 61 |
|
| 62 |
initValues(); |
| 63 |
|
| 64 |
setLocationRelativeTo(null); |
| 65 |
} |
| 66 |
|
| 67 |
private void initValues() { |
| 68 |
SettingsManager set = SettingsManager.getInstance(); |
| 69 |
|
| 70 |
laFModel = new LaFComboModel(); |
| 71 |
cmbLaF.setModel(laFModel); |
| 72 |
|
| 73 |
chkNotifyOnStart.setSelected(set.get("notifyupdates", true)); |
| 74 |
chkNotifyDepsAfterInstall.setSelected(set.get("notifyDepsAfterInstall", false)); |
| 75 |
chkCopyIntro.setSelected(set.get("copyintro", false)); |
| 76 |
chkCopyOutro.setSelected(set.get("copyoutro", true)); |
| 77 |
} |
| 78 |
|
| 79 |
@SuppressWarnings("unused") |
| 80 |
private boolean save() { |
| 81 |
SettingsManager set = SettingsManager.getInstance(); |
| 82 |
|
| 83 |
set.put("notifyupdates", chkNotifyOnStart.isSelected()); |
| 84 |
set.put("notifyDepsAfterInstall", chkNotifyDepsAfterInstall.isSelected()); |
| 85 |
set.put("copyintro", chkCopyIntro.isSelected()); |
| 86 |
set.put("copyoutro", chkCopyOutro.isSelected()); |
| 87 |
|
| 88 |
String oldLaf = set.get("lookandfeel", UIManager.getLookAndFeel() |
| 89 |
.getClass().getName()); |
| 90 |
String newLaf = laFModel.getSelectedClassName(); |
| 91 |
|
| 92 |
if (!newLaf.equals(oldLaf)) { |
| 93 |
set.put("lookandfeel", newLaf); |
| 94 |
JOptionPane.showMessageDialog(this, |
| 95 |
bundle.getString("newLaF.text"), |
| 96 |
bundle.getString("newLaF.title"), |
| 97 |
JOptionPane.INFORMATION_MESSAGE); |
| 98 |
} |
| 99 |
|
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
} |